Changeset a927398 in mainline


Ignore:
Timestamp:
2017-07-02T17:03:58Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
58fa3e6
Parents:
f4ae95a
Message:

Fix FAT size computation for auto-detected FAT32.

File:
1 edited

Legend:

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

    rf4ae95a ra927398  
    213213        }
    214214
    215         printf(NAME ": Creating FAT%d filesystem on device %s.\n", cfg.fat_type, dev_path);
     215        printf(NAME ": Creating FAT filesystem on device %s.\n", dev_path);
    216216
    217217        rc = fat_params_compute(&cfg);
     
    220220                return 2;
    221221        }
     222
     223        printf(NAME ": Filesystem type FAT%d.\n", cfg.fat_type);
    222224
    223225        rc = fat_blocks_write(&cfg, service_id);
     
    274276{
    275277        uint32_t fat_bytes;
     278        uint32_t non_data_sectors_lb_16;
    276279        uint32_t non_data_sectors_lb;
     280        uint32_t rd_sectors;
     281        uint32_t tot_clust_16;
    277282
    278283        /*
     
    280285         * system. The optimum could be potentially smaller since we
    281286         * do not subtract size of the FAT itself when computing the
    282          * size of the data region.
     287         * size of the data region. Also the root dir area might not
     288         * need FAT entries if we decide to make a FAT32.
    283289         */
    284290
    285291        cfg->reserved_sectors = 1 + cfg->addt_res_sectors;
    286         if (cfg->fat_type != FAT32) {
    287                 cfg->rootdir_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE,
    288                         cfg->sector_size);
    289         } else
    290                 cfg->rootdir_sectors = cfg->sectors_per_cluster;
    291         non_data_sectors_lb = cfg->reserved_sectors + cfg->rootdir_sectors;
    292 
    293         cfg->total_clusters = div_round_up(cfg->total_sectors - non_data_sectors_lb,
     292
     293        /* Only correct for FAT12/16 (FAT32 has root dir stored in clusters */
     294        rd_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE,
     295                cfg->sector_size);
     296        non_data_sectors_lb_16 = cfg->reserved_sectors + rd_sectors;
     297
     298        /* Only correct for FAT12/16 */
     299        tot_clust_16 = div_round_up(cfg->total_sectors - non_data_sectors_lb_16,
    294300            cfg->sectors_per_cluster);
    295301
    296         if (cfg->total_clusters <= FAT12_CLST_MAX) {
     302        /* Now detect FAT type */
     303        if (tot_clust_16 <= FAT12_CLST_MAX) {
    297304                if (cfg->fat_type == FATAUTO)
    298305                        cfg->fat_type = FAT12;
    299306                else if (cfg->fat_type != FAT12)
    300307                        return EINVAL;
    301         } else if (cfg->total_clusters <= FAT16_CLST_MAX) {
     308        } else if (tot_clust_16 <= FAT16_CLST_MAX) {
    302309                if (cfg->fat_type == FATAUTO)
    303310                        cfg->fat_type = FAT16;
     
    310317                        return EINVAL;
    311318        }
     319
     320        /* Actual root directory size, non-data sectors */
     321        if (cfg->fat_type != FAT32) {
     322                cfg->rootdir_sectors = div_round_up(cfg->root_ent_max * DIRENT_SIZE,
     323                        cfg->sector_size);
     324                non_data_sectors_lb = cfg->reserved_sectors + cfg->rootdir_sectors;
     325
     326        } else {
     327                /* We create a single-cluster root dir */
     328                cfg->rootdir_sectors = cfg->sectors_per_cluster;
     329                non_data_sectors_lb = cfg->reserved_sectors;
     330        }
     331
     332        /* Actual total number of clusters */
     333        cfg->total_clusters = div_round_up(cfg->total_sectors - non_data_sectors_lb,
     334            cfg->sectors_per_cluster);
    312335
    313336        fat_bytes = div_round_up((cfg->total_clusters + 2) *
Note: See TracChangeset for help on using the changeset viewer.