Changeset 8367d1d in mainline
- Timestamp:
- 2011-10-08T13:01:15Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d7ff048
- Parents:
- ee6d9dd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkmfs/mkmfs.c
ree6d9dd r8367d1d 55 55 #define USED 1 56 56 57 #define UPPER(n, size) 58 #define NEXT_DENTRY(p, dirsize) 57 #define UPPER(n, size) (((n) / (size)) + (((n) % (size)) != 0)) 58 #define NEXT_DENTRY(p, dirsize) (p += (dirsize)) 59 59 60 60 typedef enum { … … 63 63 } help_level_t; 64 64 65 /* Generic MFS superblock*/65 /* Generic MFS superblock */ 66 66 struct mfs_sb_info { 67 67 uint64_t n_inodes; … … 117 117 struct mfs_sb_info sb; 118 118 119 /* Default is MinixFS V3*/119 /* Default is MinixFS V3 */ 120 120 sb.magic = MFS_MAGIC_V3; 121 121 sb.fs_version = 3; 122 122 123 /* Default block size is 4Kb*/123 /* Default block size is 4Kb */ 124 124 sb.block_size = MFS_MAX_BLOCKSIZE; 125 125 sb.dirsize = MFS3_DIRSIZE; … … 135 135 136 136 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); 138 139 switch (c) { 139 140 case 'h': … … 168 169 169 170 if (sb.block_size < MFS_MIN_BLOCKSIZE || 170 171 sb.block_size > MFS_MAX_BLOCKSIZE) { 171 172 printf(NAME ":Error! Invalid block size.\n"); 172 173 exit(0); 173 174 } 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. */ 175 176 printf(NAME ":Error! Invalid block size.\n"); 176 177 exit(0); 177 178 } 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"); 180 182 exit(0); 181 183 } 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"); 183 186 exit(0); 184 187 } … … 220 223 rc = block_get_nblocks(service_id, &sb.dev_nblocks); 221 224 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"); 223 227 } else { 224 228 printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n", 225 229 sb.dev_nblocks); 226 230 } 227 231 … … 231 235 } 232 236 233 /* Minimum block size is 1 Kb*/237 /* Minimum block size is 1 Kb */ 234 238 sb.dev_nblocks /= 2; 235 239 … … 237 241 printf(NAME ": Writing superblock\n"); 238 242 239 /* Initialize superblock*/243 /* Initialize superblock */ 240 244 if (init_superblock(&sb) != EOK) { 241 245 printf(NAME ": Error. Superblock initialization failed\n"); … … 245 249 printf(NAME ": Initializing bitmaps\n"); 246 250 247 /* Initialize bitmaps*/251 /* Initialize bitmaps */ 248 252 if (init_bitmaps(&sb) != EOK) { 249 253 printf(NAME ": Error. Bitmaps initialization failed\n"); … … 253 257 printf(NAME ": Initializing the inode table\n"); 254 258 255 /* Init inode table*/259 /* Init inode table */ 256 260 if (init_inode_table(&sb) != EOK) { 257 261 printf(NAME ": Error. Inode table initialization failed\n"); … … 261 265 printf(NAME ": Creating the root directory inode\n"); 262 266 263 /* Make the root inode*/267 /* Make the root inode */ 264 268 if (sb.fs_version == 1) 265 269 rc = make_root_ino(&sb); … … 272 276 } 273 277 274 /* Insert directory entries . and ..*/278 /* Insert directory entries . and .. */ 275 279 if (insert_dentries(&sb) != EOK) { 276 280 printf(NAME ": Error. Root directory initialization failed\n"); … … 305 309 306 310 if (sb->fs_version != 3) { 307 /* Directory entries for V1/V2 filesystem*/311 /* Directory entries for V1/V2 filesystem */ 308 312 struct mfs_dentry *dentry = root_block; 309 313 … … 312 316 313 317 dentry = (struct mfs_dentry *) NEXT_DENTRY(dentry_ptr, 314 318 sb->dirsize); 315 319 316 320 dentry->d_inum = MFS_ROOT_INO; 317 321 memcpy(dentry->d_name, "..\0", 3); 318 322 } else { 319 /* Directory entries for V3 filesystem*/323 /* Directory entries for V3 filesystem */ 320 324 struct mfs3_dentry *dentry = root_block; 321 325 … … 324 328 325 329 dentry = (struct mfs3_dentry *) NEXT_DENTRY(dentry_ptr, 326 330 sb->dirsize); 327 331 328 332 dentry->d_inum = MFS_ROOT_INO; … … 395 399 ino_buf[MFS_ROOT_INO - 1].i_gid = 0; 396 400 ino_buf[MFS_ROOT_INO - 1].i_size = (sb->longnames ? MFSL_DIRSIZE : 397 MFS_DIRSIZE) * 2;401 MFS_DIRSIZE) * 2; 398 402 ino_buf[MFS_ROOT_INO - 1].i_mtime = sec; 399 403 ino_buf[MFS_ROOT_INO - 1].i_nlinks = 2; … … 417 421 int rc; 418 422 419 /* Compute offset of the first inode table block*/423 /* Compute offset of the first inode table block */ 420 424 const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2; 421 425 … … 460 464 461 465 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 */ 465 470 466 471 if (sb->fs_version == 1) { 467 /* Valid only for MFS V1*/472 /* Valid only for MFS V1 */ 468 473 sb->n_zones = sb->dev_nblocks > UINT16_MAX ? 469 474 UINT16_MAX : sb->dev_nblocks; 470 475 ind = MFS_BLOCKSIZE / sizeof(uint16_t); 471 476 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; 473 479 } else { 474 480 /*Valid for MFS V2/V3*/ … … 478 484 else 479 485 ptrsize = sizeof(uint32_t); 486 480 487 ind = sb->block_size / ptrsize; 481 488 ind2 = ind * ind; … … 483 490 sb->max_file_size = zones * sb->block_size; 484 491 sb->n_zones = sb->dev_nblocks > UINT32_MAX ? 485 492 UINT32_MAX : sb->dev_nblocks; 486 493 487 494 if (sb->fs_version == 3) { … … 493 500 } 494 501 495 /* Round up the number of inodes to fill block size*/502 /* Round up the number of inodes to fill block size */ 496 503 if (sb->n_inodes == 0) 497 504 inodes = sb->dev_nblocks / 3; … … 500 507 501 508 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; 503 511 504 512 if (sb->fs_version < 3) … … 507 515 sb->n_inodes = inodes > UINT32_MAX ? UINT32_MAX : inodes; 508 516 509 /* Compute inode bitmap size in blocks*/517 /* Compute inode bitmap size in blocks */ 510 518 sb->ibmap_blocks = UPPER(sb->n_inodes, sb->block_size * 8); 511 519 512 /* Compute inode table size*/520 /* Compute inode table size */ 513 521 sb->itable_size = sb->n_inodes / sb->ino_per_block; 514 522 515 /* Compute zone bitmap size in blocks*/523 /* Compute zone bitmap size in blocks */ 516 524 sb->zbmap_blocks = UPPER(sb->n_zones, sb->block_size * 8); 517 525 518 /* Compute first data zone position*/526 /* Compute first data zone position */ 519 527 sb->first_data_zone = 2 + sb->itable_size + 520 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 */ 523 531 sb->log2_zone_size = 0; 524 532 525 /* Check for errors*/533 /* Check for errors */ 526 534 if (sb->first_data_zone >= sb->n_zones) { 527 535 printf(NAME ": Error! Insufficient disk space"); … … 529 537 } 530 538 531 /* Superblock is now ready to be written on disk*/539 /* Superblock is now ready to be written on disk */ 532 540 printf(NAME ": %d block size\n", sb->block_size); 533 541 printf(NAME ": %d inodes\n", (uint32_t) sb->n_inodes); … … 536 544 printf(NAME ": inode bitmap blocks = %ld\n", sb->ibmap_blocks); 537 545 printf(NAME ": zone bitmap blocks = %ld\n", sb->zbmap_blocks); 538 printf(NAME ": first data zone = %d\n", (uint32_t) 546 printf(NAME ": first data zone = %d\n", (uint32_t)sb->first_data_zone); 539 547 printf(NAME ": max file size = %u\n", sb->max_file_size); 540 548 printf(NAME ": long fnames = %s\n", sb->longnames ? "Yes" : "No"); … … 651 659 for (i = 0; i < ibmap_nblocks; ++i) { 652 660 if ((rc = write_block(start_block + i, 653 661 1, (ibmap_buf8 + i * sb->block_size))) != EOK) 654 662 return rc; 655 663 } … … 659 667 for (i = 0; i < zbmap_nblocks; ++i) { 660 668 if ((rc = write_block(start_block + i, 661 669 1, (zbmap_buf8 + i * sb->block_size))) != EOK) 662 670 return rc; 663 671 } … … 698 706 uint8_t *data_ptr = (uint8_t *) data; 699 707 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); 701 710 702 711 if (rc != EOK) … … 706 715 tmp_off++; 707 716 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); 711 722 } 712 723 … … 717 728 } else { 718 729 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 */ 728 747 static bool is_power_of_two(uint32_t n) 729 748 {
Note:
See TracChangeset
for help on using the changeset viewer.