Changeset 9744f2d in mainline for uspace/app/mkexfat/mkexfat.c


Ignore:
Timestamp:
2012-02-16T22:14:42Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
39aa8ce
Parents:
acb866ae
Message:

mkexfat:

  • Get the total number of blocks of the device.
  • Add function to initialize the Volume Boot Record structure.
File:
1 edited

Legend:

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

    racb866ae r9744f2d  
    4242#define NAME    "mkexfat"
    4343
     44/** First sector of the FAT */
     45#define FAT_SECTOR_START 128
     46
     47/** Divide and round up. */
     48#define div_round_up(a, b) (((a) + (b) - 1) / (b))
     49
     50typedef struct exfat_cfg {
     51        uint64_t volume_start;
     52        uint64_t volume_count;
     53        uint32_t fat_sector_count;
     54        uint32_t data_start_sector;
     55        uint32_t data_cluster;
     56        uint32_t rootdir_cluster;
     57        unsigned bytes_per_sector;
     58        unsigned sec_per_cluster;
     59} exfat_cfg_t;
     60
    4461static void usage(void)
    4562{
     
    4764}
    4865
     66/** Initialize the exFAT params structure.
     67 *
     68 * @param cfg Pointer to the exFAT params structure to initialize.
     69 */
     70static void
     71cfg_params_initialize(exfat_cfg_t *cfg)
     72{
     73}
     74
     75/** Initialize the Volume Boot Record fields.
     76 *
     77 * @param vbr Pointer to the Volume Boot Record structure.
     78 * @param cfg Pointer to the exFAT configuration structure.
     79 */
     80static void
     81vbr_initialize(exfat_bs_t *vbr, exfat_cfg_t *cfg)
     82{
     83        /* Fill the structure with zeroes */
     84        memset(vbr, 0, sizeof(exfat_bs_t));
     85
     86        /* Init Jump Boot section */
     87        vbr->jump[0] = 0xEB;
     88        vbr->jump[1] = 0x76;
     89        vbr->jump[2] = 0x90;
     90
     91        /* Set the filesystem name */
     92        memcpy(vbr->oem_name, "EXFAT   ", sizeof(vbr->oem_name));
     93
     94        vbr->volume_start = host2uint64_t_le(cfg->volume_start);
     95        vbr->volume_count = host2uint64_t_le(cfg->volume_count);
     96        vbr->fat_sector_start = host2uint32_t_le(FAT_SECTOR_START);
     97        vbr->fat_sector_count = host2uint32_t_le(cfg->fat_sector_count);
     98        vbr->version.major = 1;
     99        vbr->version.minor = 0;
     100        vbr->volume_flags = host2uint16_t_le(0);
     101        vbr->bytes_per_sector = cfg->bytes_per_sectors;
     102        vbr->sec_per_cluster = cfg->sec_per_cluster;
     103        vbr->fat_count = 1;
     104        vbr->drive_no = 0x80;
     105        vbr->allocated_percent = 0;
     106        vbr->signature = host2uint16_t_le(0xAA55);
     107}
     108
    49109int main (int argc, char **argv)
    50110{
     111        exfat_cfg_t cfg;
    51112        aoff64_t dev_nblocks;
    52113        char *dev_path;
     
    60121                return 1;
    61122        }
     123
     124        /* The fist sector of the partition is zero */
     125        cfg.volume_start = 0;
    62126
    63127        /* TODO: Add parameters */
     
    86150        }
    87151
     152        rc = block_get_nblocks(service_id, &dev_nblocks);
     153        if (rc != EOK) {
     154                printf(NAME ": Warning, failed to obtain device block size.\n");
     155                /* FIXME: the user should specify the filesystem size */
     156                return 1;
     157        } else {
     158                printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
     159                    dev_nblocks);
     160
     161                cfg.volume_count = dev_nblocks;
     162        }
     163
     164        cfg_params_initialize(&cfg);
     165
    88166
    89167        return 0;
    90168}
     169
Note: See TracChangeset for help on using the changeset viewer.