Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset da34d61d in mainline


Ignore:
Timestamp:
2012-02-25T14:53:21Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
ff415f62
Parents:
392bd67c
Message:

mkexfat: Write the root directory entries to disk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkexfat/mkexfat.c

    r392bd67c rda34d61d  
    4747#include <sys/typefmt.h>
    4848#include <bool.h>
     49#include <str.h>
    4950#include "exfat.h"
    5051#include "upcase.h"
     
    8889        unsigned long rootdir_cluster;
    8990        unsigned long upcase_table_cluster;
     91        unsigned long bitmap_cluster;
    9092        unsigned long total_clusters;
    9193        unsigned long allocated_clusters;
     
    111113bitmap_write(service_id_t service_id, exfat_cfg_t *cfg);
    112114
     115static uint32_t
     116upcase_table_checksum(void const *data, size_t nbytes);
     117
    113118static void usage(void)
    114119{
     
    168173        /* Will be set later */
    169174        cfg->rootdir_cluster = 0;
     175
     176        /* Bitmap always starts at the first free cluster */
     177        cfg->bitmap_cluster = FIRST_FREE_CLUSTER;
    170178
    171179        /* The first sector of the partition is zero */
     
    524532}
    525533
     534/** Initialize and write the root directory entries to disk.
     535 *
     536 * @param service_id   The service id.
     537 * @param cfg   Pointer to the exFAT configuration structure.
     538 * @return   EOK on success or a negative error code.
     539 */
     540static int
     541root_dentries_write(service_id_t service_id, exfat_cfg_t *cfg)
     542{
     543        exfat_dentry_t *d;
     544        aoff64_t rootdir_sec;
     545        int rc;
     546        uint8_t *data;
     547
     548        data = calloc(cfg->sector_size, 1);
     549        if (!data)
     550                return ENOMEM;
     551
     552        d = (exfat_dentry_t *) data;
     553
     554        /* Initialize the volume label dentry */
     555        d->type = EXFAT_TYPE_VOLLABEL;
     556        str_to_utf16(d->vollabel.label, 7, "HELENOS");
     557        d->vollabel.size = 7;
     558
     559        d++;
     560
     561        /* Initialize the allocation bitmap dentry */
     562        d->type = EXFAT_TYPE_BITMAP;
     563        d->bitmap.flags = 0; /* First FAT */
     564        d->bitmap.firstc = host2uint32_t_le(cfg->bitmap_cluster);
     565        d->bitmap.size = host2uint64_t_le(cfg->bitmap_size);
     566
     567        d++;
     568
     569        /* Initialize the upcase table dentry */
     570        d->type = EXFAT_TYPE_UCTABLE;
     571        d->uctable.checksum = host2uint32_t_le(upcase_table_checksum(
     572            upcase_table, sizeof(upcase_table)));
     573        d->uctable.firstc = host2uint32_t_le(cfg->upcase_table_cluster);
     574        d->uctable.size = host2uint64_t_le(sizeof(upcase_table));
     575
     576        /* Compute the number of the sector where the rootdir resides */
     577
     578        rootdir_sec = cfg->data_start_sector;
     579        rootdir_sec += ((cfg->rootdir_cluster - 2) * cfg->cluster_size) /
     580            cfg->sector_size;
     581
     582        rc = block_write_direct(service_id, rootdir_sec, 1, data);
     583
     584        free(data);
     585        return rc;
     586}
     587
    526588/** Given a number (n), returns the result of log2(n).
    527589 *
     
    655717
    656718        /* Allocate clusters for the bitmap */
    657         rc = fat_allocate_clusters(service_id, &cfg, FIRST_FREE_CLUSTER,
     719        rc = fat_allocate_clusters(service_id, &cfg, cfg.bitmap_cluster,
    658720            div_round_up(cfg.bitmap_size, cfg.cluster_size));
    659721        if (rc != EOK) {
     
    662724        }
    663725
    664         next_cls = FIRST_FREE_CLUSTER +
     726        next_cls = cfg.bitmap_cluster +
    665727            div_round_up(cfg.bitmap_size, cfg.cluster_size);
    666728        cfg.upcase_table_cluster = next_cls;
     
    699761        }
    700762
     763        rc = root_dentries_write(service_id, &cfg);
     764        if (rc != EOK) {
     765                printf(NAME ": Error, failed to write the root directory" \
     766                    " entries to disk.\n");
     767                return 2;
     768        }
     769
    701770        rc = bootsec_write(service_id, &cfg);
    702771        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.