Changeset 8367d1d in mainline


Ignore:
Timestamp:
2011-10-08T13:01:15Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d7ff048
Parents:
ee6d9dd
Message:

cstyle

File:
1 edited

Legend:

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

    ree6d9dd r8367d1d  
    5555#define USED    1
    5656
    57 #define UPPER(n, size)                  (((n) / (size)) + (((n) % (size)) != 0))
    58 #define NEXT_DENTRY(p, dirsize)         (p += (dirsize))
     57#define UPPER(n, size)          (((n) / (size)) + (((n) % (size)) != 0))
     58#define NEXT_DENTRY(p, dirsize) (p += (dirsize))
    5959
    6060typedef enum {
     
    6363} help_level_t;
    6464
    65 /*Generic MFS superblock*/
     65/* Generic MFS superblock */
    6666struct mfs_sb_info {
    6767        uint64_t n_inodes;
     
    117117        struct mfs_sb_info sb;
    118118
    119         /*Default is MinixFS V3*/
     119        /* Default is MinixFS V3 */
    120120        sb.magic = MFS_MAGIC_V3;
    121121        sb.fs_version = 3;
    122122
    123         /*Default block size is 4Kb*/
     123        /* Default block size is 4Kb */
    124124        sb.block_size = MFS_MAX_BLOCKSIZE;
    125125        sb.dirsize = MFS3_DIRSIZE;
     
    135135
    136136        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
    137                 c = getopt_long(argc, argv, "lh12b:i:", long_options, &opt_ind);
     137                c = getopt_long(argc, argv, "lh12b:i:",
     138                    long_options, &opt_ind);
    138139                switch (c) {
    139140                case 'h':
     
    168169
    169170        if (sb.block_size < MFS_MIN_BLOCKSIZE ||
    170                         sb.block_size > MFS_MAX_BLOCKSIZE) {
     171            sb.block_size > MFS_MAX_BLOCKSIZE) {
    171172                printf(NAME ":Error! Invalid block size.\n");
    172173                exit(0);
    173174        } else if (!is_power_of_two(sb.block_size)) {
    174                 /*Block size must be a power of 2.*/
     175                /* Block size must be a power of 2. */
    175176                printf(NAME ":Error! Invalid block size.\n");
    176177                exit(0);
    177178        } else if (sb.block_size > MFS_BLOCKSIZE &&
    178                         sb.fs_version != 3) {
    179                 printf(NAME ":Error! Block size > 1024 is supported by V3 filesystem only.\n");
     179            sb.fs_version != 3) {
     180                printf(NAME ":Error! Block size > 1024 is "
     181                    "supported by V3 filesystem only.\n");
    180182                exit(0);
    181183        } else if (sb.fs_version == 3 && sb.longnames) {
    182                 printf(NAME ":Error! Long filenames are supported by V1/V2 filesystem only.\n");
     184                printf(NAME ":Error! Long filenames are supported "
     185                    "by V1/V2 filesystem only.\n");
    183186                exit(0);
    184187        }
     
    220223        rc = block_get_nblocks(service_id, &sb.dev_nblocks);
    221224        if (rc != EOK) {
    222                 printf(NAME ": Warning, failed to obtain block device size.\n");
     225                printf(NAME ": Warning, failed to obtain "
     226                    "block device size.\n");
    223227        } else {
    224228                printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
    225                                 sb.dev_nblocks);
     229                    sb.dev_nblocks);
    226230        }
    227231
     
    231235        }
    232236
    233         /*Minimum block size is 1 Kb*/
     237        /* Minimum block size is 1 Kb */
    234238        sb.dev_nblocks /= 2;
    235239
     
    237241        printf(NAME ": Writing superblock\n");
    238242
    239         /*Initialize superblock*/
     243        /* Initialize superblock */
    240244        if (init_superblock(&sb) != EOK) {
    241245                printf(NAME ": Error. Superblock initialization failed\n");
     
    245249        printf(NAME ": Initializing bitmaps\n");
    246250
    247         /*Initialize bitmaps*/
     251        /* Initialize bitmaps */
    248252        if (init_bitmaps(&sb) != EOK) {
    249253                printf(NAME ": Error. Bitmaps initialization failed\n");
     
    253257        printf(NAME ": Initializing the inode table\n");
    254258
    255         /*Init inode table*/
     259        /* Init inode table */
    256260        if (init_inode_table(&sb) != EOK) {
    257261                printf(NAME ": Error. Inode table initialization failed\n");
     
    261265        printf(NAME ": Creating the root directory inode\n");
    262266
    263         /*Make the root inode*/
     267        /* Make the root inode */
    264268        if (sb.fs_version == 1)
    265269                rc = make_root_ino(&sb);
     
    272276        }
    273277
    274         /*Insert directory entries . and ..*/
     278        /* Insert directory entries . and .. */
    275279        if (insert_dentries(&sb) != EOK) {
    276280                printf(NAME ": Error. Root directory initialization failed\n");
     
    305309
    306310        if (sb->fs_version != 3) {
    307                 /*Directory entries for V1/V2 filesystem*/
     311                /* Directory entries for V1/V2 filesystem */
    308312                struct mfs_dentry *dentry = root_block;
    309313
     
    312316
    313317                dentry = (struct mfs_dentry *) NEXT_DENTRY(dentry_ptr,
    314                                 sb->dirsize);
     318                    sb->dirsize);
    315319
    316320                dentry->d_inum = MFS_ROOT_INO;
    317321                memcpy(dentry->d_name, "..\0", 3);
    318322        } else {
    319                 /*Directory entries for V3 filesystem*/
     323                /* Directory entries for V3 filesystem */
    320324                struct mfs3_dentry *dentry = root_block;
    321325
     
    324328
    325329                dentry = (struct mfs3_dentry *) NEXT_DENTRY(dentry_ptr,
    326                                 sb->dirsize);
     330                    sb->dirsize);
    327331
    328332                dentry->d_inum = MFS_ROOT_INO;
     
    395399        ino_buf[MFS_ROOT_INO - 1].i_gid = 0;
    396400        ino_buf[MFS_ROOT_INO - 1].i_size = (sb->longnames ? MFSL_DIRSIZE :
    397         MFS_DIRSIZE) * 2;
     401            MFS_DIRSIZE) * 2;
    398402        ino_buf[MFS_ROOT_INO - 1].i_mtime = sec;
    399403        ino_buf[MFS_ROOT_INO - 1].i_nlinks = 2;
     
    417421        int rc;
    418422
    419         /*Compute offset of the first inode table block*/
     423        /* Compute offset of the first inode table block */
    420424        const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2;
    421425
     
    460464
    461465        if (sb->longnames)
    462                 sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L : MFS_MAGIC_V2L;
    463 
    464         /*Compute the number of zones on disk*/
     466                sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L :
     467                    MFS_MAGIC_V2L;
     468
     469        /* Compute the number of zones on disk */
    465470
    466471        if (sb->fs_version == 1) {
    467                 /*Valid only for MFS V1*/
     472                /* Valid only for MFS V1 */
    468473                sb->n_zones = sb->dev_nblocks > UINT16_MAX ?
    469                                 UINT16_MAX : sb->dev_nblocks;
     474                    UINT16_MAX : sb->dev_nblocks;
    470475                ind = MFS_BLOCKSIZE / sizeof(uint16_t);
    471476                ind2 = ind * ind;
    472                 sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) * MFS_BLOCKSIZE;
     477                sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) *
     478                    MFS_BLOCKSIZE;
    473479        } else {
    474480                /*Valid for MFS V2/V3*/
     
    478484                else
    479485                        ptrsize = sizeof(uint32_t);
     486
    480487                ind = sb->block_size / ptrsize;
    481488                ind2 = ind * ind;
     
    483490                sb->max_file_size = zones * sb->block_size;
    484491                sb->n_zones = sb->dev_nblocks > UINT32_MAX ?
    485                                 UINT32_MAX : sb->dev_nblocks;
     492                    UINT32_MAX : sb->dev_nblocks;
    486493
    487494                if (sb->fs_version == 3) {
     
    493500        }
    494501
    495         /*Round up the number of inodes to fill block size*/
     502        /* Round up the number of inodes to fill block size */
    496503        if (sb->n_inodes == 0)
    497504                inodes = sb->dev_nblocks / 3;
     
    500507
    501508        if (inodes % sb->ino_per_block)
    502                 inodes = ((inodes / sb->ino_per_block) + 1) * sb->ino_per_block;
     509                inodes = ((inodes / sb->ino_per_block) + 1) *
     510                    sb->ino_per_block;
    503511
    504512        if (sb->fs_version < 3)
     
    507515                sb->n_inodes = inodes > UINT32_MAX ? UINT32_MAX : inodes;
    508516
    509         /*Compute inode bitmap size in blocks*/
     517        /* Compute inode bitmap size in blocks */
    510518        sb->ibmap_blocks = UPPER(sb->n_inodes, sb->block_size * 8);
    511519
    512         /*Compute inode table size*/
     520        /* Compute inode table size */
    513521        sb->itable_size = sb->n_inodes / sb->ino_per_block;
    514522
    515         /*Compute zone bitmap size in blocks*/
     523        /* Compute zone bitmap size in blocks */
    516524        sb->zbmap_blocks = UPPER(sb->n_zones, sb->block_size * 8);
    517525
    518         /*Compute first data zone position*/
     526        /* Compute first data zone position */
    519527        sb->first_data_zone = 2 + sb->itable_size +
    520                         sb->zbmap_blocks + sb->ibmap_blocks;
    521 
    522         /*Set log2 of zone to block ratio to zero*/
     528            sb->zbmap_blocks + sb->ibmap_blocks;
     529
     530        /* Set log2 of zone to block ratio to zero */
    523531        sb->log2_zone_size = 0;
    524532
    525         /*Check for errors*/
     533        /* Check for errors */
    526534        if (sb->first_data_zone >= sb->n_zones) {
    527535                printf(NAME ": Error! Insufficient disk space");
     
    529537        }
    530538
    531         /*Superblock is now ready to be written on disk*/
     539        /* Superblock is now ready to be written on disk */
    532540        printf(NAME ": %d block size\n", sb->block_size);
    533541        printf(NAME ": %d inodes\n", (uint32_t) sb->n_inodes);
     
    536544        printf(NAME ": inode bitmap blocks = %ld\n", sb->ibmap_blocks);
    537545        printf(NAME ": zone bitmap blocks = %ld\n", sb->zbmap_blocks);
    538         printf(NAME ": first data zone = %d\n", (uint32_t) sb->first_data_zone);
     546        printf(NAME ": first data zone = %d\n", (uint32_t)sb->first_data_zone);
    539547        printf(NAME ": max file size = %u\n", sb->max_file_size);
    540548        printf(NAME ": long fnames = %s\n", sb->longnames ? "Yes" : "No");
     
    651659        for (i = 0; i < ibmap_nblocks; ++i) {
    652660                if ((rc = write_block(start_block + i,
    653                                 1, (ibmap_buf8 + i * sb->block_size))) != EOK)
     661                    1, (ibmap_buf8 + i * sb->block_size))) != EOK)
    654662                        return rc;
    655663        }
     
    659667        for (i = 0; i < zbmap_nblocks; ++i) {
    660668                if ((rc = write_block(start_block + i,
    661                                 1, (zbmap_buf8 + i * sb->block_size))) != EOK)
     669                    1, (zbmap_buf8 + i * sb->block_size))) != EOK)
    662670                        return rc;
    663671        }
     
    698706                uint8_t *data_ptr = (uint8_t *) data;
    699707
    700                 rc = block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr);
     708                rc = block_write_direct(service_id, tmp_off << 2,
     709                    size << 2, data_ptr);
    701710
    702711                if (rc != EOK)
     
    706715                tmp_off++;
    707716
    708                 return block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr);
    709         }
    710         return block_write_direct(service_id, off << shift, size << shift, data);
     717                return block_write_direct(service_id, tmp_off << 2,
     718                    size << 2, data_ptr);
     719        }
     720        return block_write_direct(service_id, off << shift,
     721            size << shift, data);
    711722}
    712723
     
    717728        } else {
    718729                printf("Usage: [options] device\n"
    719                                 "-1         Make a Minix version 1 filesystem\n"
    720                                 "-2         Make a Minix version 2 filesystem\n"
    721                                 "-b ##      Specify the block size in bytes (V3 only),\n"
    722                                 "           valid block size values are 1024, 2048 and 4096 bytes per block\n"
    723                                 "-i ##      Specify the number of inodes for the filesystem\n"
    724                                 "-l         Use 30-char long filenames (V1/V2 only)\n");
    725         }
    726 }
    727 
     730                    "-1         Make a Minix version 1 filesystem\n"
     731                    "-2         Make a Minix version 2 filesystem\n"
     732                    "-b ##      Specify the block size in bytes (V3 only),\n"
     733                    "           valid block size values are 1024, 2048 and"
     734                                " 4096 bytes per block\n"
     735                    "-i ##      Specify the number of inodes"
     736                                " for the filesystem\n"
     737                    "-l         Use 30-char long filenames (V1/V2 only)\n");
     738        }
     739}
     740
     741/** Check if a given number is a power of two.
     742 *
     743 * @param n     The number to check.
     744 *
     745 * @return      true if it is a power of two, false otherwise.
     746 */
    728747static bool is_power_of_two(uint32_t n)
    729748{
Note: See TracChangeset for help on using the changeset viewer.