aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mkfs_ext2.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-20 22:12:11 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-20 22:12:11 +0200
commit5e1dbd5bc3c609c73037a41546c5ead240821558 (patch)
tree272c8328e8bbcae97c7487b6a9efc99b98b8f536 /util-linux/mkfs_ext2.c
parente707a3000b2f6e2f684b6e85cd60590318d157c4 (diff)
downloadbusybox-w32-5e1dbd5bc3c609c73037a41546c5ead240821558.tar.gz
busybox-w32-5e1dbd5bc3c609c73037a41546c5ead240821558.tar.bz2
busybox-w32-5e1dbd5bc3c609c73037a41546c5ead240821558.zip
mkfs_ext2: another update by Vladimir
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mkfs_ext2.c')
-rw-r--r--util-linux/mkfs_ext2.c147
1 files changed, 95 insertions, 52 deletions
diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c
index 3f4f5c6e3..be9e36332 100644
--- a/util-linux/mkfs_ext2.c
+++ b/util-linux/mkfs_ext2.c
@@ -75,8 +75,8 @@ static unsigned int_log2(unsigned arg)
75} 75}
76 76
77// taken from mkfs_minix.c. libbb candidate? 77// taken from mkfs_minix.c. libbb candidate?
78// why "uint64_t size"? we never use it for anything >32 bits 78// "uint32_t size", since we never use it for anything >32 bits
79static uint32_t div_roundup(uint64_t size, uint32_t n) 79static uint32_t div_roundup(uint32_t size, uint32_t n)
80{ 80{
81 // Overflow-resistant 81 // Overflow-resistant
82 uint32_t res = size / n; 82 uint32_t res = size / n;
@@ -176,12 +176,15 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
176 unsigned blocksize, blocksize_log2; 176 unsigned blocksize, blocksize_log2;
177 unsigned reserved_percent = 5; 177 unsigned reserved_percent = 5;
178 unsigned long long kilobytes; 178 unsigned long long kilobytes;
179 uint32_t nblocks, nblocks_full, nreserved; 179 uint32_t nblocks, nblocks_full;
180 uint32_t nreserved;
180 uint32_t ngroups; 181 uint32_t ngroups;
181 uint32_t bytes_per_inode; 182 uint32_t bytes_per_inode;
182 uint32_t first_block; 183 uint32_t first_block;
183 uint32_t inodes_per_group; 184 uint32_t inodes_per_group;
184 uint32_t gdtsz, itsz; 185 uint32_t group_desc_blocks;
186 uint32_t inode_table_blocks;
187 uint32_t lost_and_found_blocks;
185 time_t timestamp; 188 time_t timestamp;
186 unsigned opts; 189 unsigned opts;
187 const char *label = ""; 190 const char *label = "";
@@ -245,6 +248,8 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
245 ) { 248 ) {
246 bb_error_msg_and_die("blocksize %u is bad", blocksize); 249 bb_error_msg_and_die("blocksize %u is bad", blocksize);
247 } 250 }
251 if ((int32_t)bytes_per_inode < blocksize)
252 bb_error_msg_and_die("-%c is bad", 'i');
248 // number of bits in one block, i.e. 8*blocksize 253 // number of bits in one block, i.e. 8*blocksize
249#define blocks_per_group (8 * blocksize) 254#define blocks_per_group (8 * blocksize)
250 first_block = (EXT2_MIN_BLOCK_SIZE == blocksize); 255 first_block = (EXT2_MIN_BLOCK_SIZE == blocksize);
@@ -266,7 +271,6 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
266 // How many reserved blocks? 271 // How many reserved blocks?
267 if (reserved_percent > 50) 272 if (reserved_percent > 50)
268 bb_error_msg_and_die("-%c is bad", 'm'); 273 bb_error_msg_and_die("-%c is bad", 'm');
269 //nreserved = div_roundup((uint64_t) nblocks * reserved_percent, 100);
270 nreserved = (uint64_t)nblocks * reserved_percent / 100; 274 nreserved = (uint64_t)nblocks * reserved_percent / 100;
271 275
272 // N.B. killing e2fsprogs feature! Unused blocks don't account in calculations 276 // N.B. killing e2fsprogs feature! Unused blocks don't account in calculations
@@ -279,10 +283,8 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
279 retry: 283 retry:
280 // N.B. a block group can have no more than blocks_per_group blocks 284 // N.B. a block group can have no more than blocks_per_group blocks
281 ngroups = div_roundup(nblocks - first_block, blocks_per_group); 285 ngroups = div_roundup(nblocks - first_block, blocks_per_group);
282 if (0 == ngroups)
283 bb_error_msg_and_die("ngroups");
284 286
285 gdtsz = div_roundup(ngroups, blocksize / sizeof(*gd)); 287 group_desc_blocks = div_roundup(ngroups, blocksize / sizeof(*gd));
286 // TODO: reserved blocks must be marked as such in the bitmaps, 288 // TODO: reserved blocks must be marked as such in the bitmaps,
287 // or resulting filesystem is corrupt 289 // or resulting filesystem is corrupt
288 if (ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT) { 290 if (ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT) {
@@ -294,15 +296,15 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
294 * We set it at 1024x the current filesystem size, or 296 * We set it at 1024x the current filesystem size, or
295 * the upper block count limit (2^32), whichever is lower. 297 * the upper block count limit (2^32), whichever is lower.
296 */ 298 */
297 uint32_t rgdtsz = 0xFFFFFFFF; // maximum block number 299 uint32_t reserved_group_desc_blocks = 0xFFFFFFFF; // maximum block number
298 if (nblocks < rgdtsz / 1024) 300 if (nblocks < reserved_group_desc_blocks / 1024)
299 rgdtsz = nblocks * 1024; 301 reserved_group_desc_blocks = nblocks * 1024;
300 rgdtsz = div_roundup(rgdtsz - first_block, blocks_per_group); 302 reserved_group_desc_blocks = div_roundup(reserved_group_desc_blocks - first_block, blocks_per_group);
301 rgdtsz = div_roundup(rgdtsz, blocksize / sizeof(*gd)) - gdtsz; 303 reserved_group_desc_blocks = div_roundup(reserved_group_desc_blocks, blocksize / sizeof(*gd)) - group_desc_blocks;
302 if (rgdtsz > blocksize / sizeof(uint32_t)) 304 if (reserved_group_desc_blocks > blocksize / sizeof(uint32_t))
303 rgdtsz = blocksize / sizeof(uint32_t); 305 reserved_group_desc_blocks = blocksize / sizeof(uint32_t);
304 //TODO: STORE_LE(sb->s_reserved_gdt_blocks, rgdtsz); 306 //TODO: STORE_LE(sb->s_reserved_gdt_blocks, reserved_group_desc_blocks);
305 gdtsz += rgdtsz; 307 group_desc_blocks += reserved_group_desc_blocks;
306 } 308 }
307 309
308 { 310 {
@@ -324,13 +326,25 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
324 inodes_per_group = (div_roundup(inodes_per_group * sizeof(*inode), blocksize) * blocksize) / sizeof(*inode); 326 inodes_per_group = (div_roundup(inodes_per_group * sizeof(*inode), blocksize) * blocksize) / sizeof(*inode);
325 // make sure the number of inodes per group is a multiple of 8 327 // make sure the number of inodes per group is a multiple of 8
326 inodes_per_group &= ~7; 328 inodes_per_group &= ~7;
327 itsz = div_roundup(inodes_per_group * sizeof(*inode), blocksize); 329 inode_table_blocks = div_roundup(inodes_per_group * sizeof(*inode), blocksize);
330
331 // to be useful, lost+found should occupy at least 2 blocks (but not exceeding 16*1024 bytes),
332 // and at most EXT2_NDIR_BLOCKS. So reserve these blocks right now
333 /* Or e2fsprogs comment verbatim (what does it mean?):
334 * Ensure that lost+found is at least 2 blocks, so we always
335 * test large empty blocks for big-block filesystems. */
336 lost_and_found_blocks = MIN(EXT2_NDIR_BLOCKS, 16 >> (blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE));
328 337
329 // the last group needs more attention: isn't it too small for possible overhead? 338 // the last group needs more attention: isn't it too small for possible overhead?
330 overhead = (has_super(ngroups - 1) ? (1/*sb*/ + gdtsz) : 0) + 1/*bbmp*/ + 1/*ibmp*/ + itsz; 339 overhead = (has_super(ngroups - 1) ? (1/*sb*/ + group_desc_blocks) : 0) + 1/*bbmp*/ + 1/*ibmp*/ + inode_table_blocks;
331 remainder = (nblocks - first_block) % blocks_per_group; 340 remainder = (nblocks - first_block) % blocks_per_group;
332 if ((1 == ngroups) && remainder && (remainder < overhead)) 341 ////can't happen, nblocks >= 60 guarantees this
333 bb_error_msg_and_die("way small device"); 342 ////if ((1 == ngroups)
343 //// && remainder
344 //// && (remainder < overhead + 1/* "/" */ + lost_and_found_blocks)
345 ////) {
346 //// bb_error_msg_and_die("way small device");
347 ////}
334 // Standard mke2fs uses 50. Looks like a bug in our calculation 348 // Standard mke2fs uses 50. Looks like a bug in our calculation
335 // of "remainder" or "overhead" - we don't match standard mke2fs 349 // of "remainder" or "overhead" - we don't match standard mke2fs
336 // when we transition from one group to two groups 350 // when we transition from one group to two groups
@@ -363,7 +377,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
363 , inodes_per_group * ngroups, nblocks 377 , inodes_per_group * ngroups, nblocks
364 , nreserved, reserved_percent 378 , nreserved, reserved_percent
365 , first_block 379 , first_block
366 , gdtsz * (blocksize / sizeof(*gd)) * blocks_per_group 380 , group_desc_blocks * (blocksize / sizeof(*gd)) * blocks_per_group
367 , ngroups 381 , ngroups
368 , blocks_per_group, blocks_per_group 382 , blocks_per_group, blocks_per_group
369 , inodes_per_group 383 , inodes_per_group
@@ -382,9 +396,11 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
382 } 396 }
383 bb_putchar('\n'); 397 bb_putchar('\n');
384 398
385 // dry run? -> we are done 399 if (opts & OPT_n) {
386 if (opts & OPT_n) 400 if (ENABLE_FEATURE_CLEAN_UP)
387 goto done; 401 close(fd);
402 return EXIT_SUCCESS;
403 }
388 404
389 // TODO: 3/5 refuse if mounted 405 // TODO: 3/5 refuse if mounted
390 // TODO: 4/5 compat options 406 // TODO: 4/5 compat options
@@ -395,7 +411,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
395 // TODO: 3/5 dir_index? 411 // TODO: 3/5 dir_index?
396 412
397 // fill the superblock 413 // fill the superblock
398 sb = xzalloc(blocksize); 414 sb = xzalloc(1024);
399 STORE_LE(sb->s_rev_level, 1); // revision 1 filesystem 415 STORE_LE(sb->s_rev_level, 1); // revision 1 filesystem
400 STORE_LE(sb->s_magic, EXT2_SUPER_MAGIC); 416 STORE_LE(sb->s_magic, EXT2_SUPER_MAGIC);
401 STORE_LE(sb->s_inode_size, sizeof(*inode)); 417 STORE_LE(sb->s_inode_size, sizeof(*inode));
@@ -444,49 +460,61 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
444 * don't check all the filesystems at the same time. We use a 460 * don't check all the filesystems at the same time. We use a
445 * kludgy hack of using the UUID to derive a random jitter value. 461 * kludgy hack of using the UUID to derive a random jitter value.
446 */ 462 */
447 STORE_LE(sb->s_max_mnt_count, EXT2_DFL_MAX_MNT_COUNT 463 STORE_LE(sb->s_max_mnt_count,
464 EXT2_DFL_MAX_MNT_COUNT
448 + (sb->s_uuid[ARRAY_SIZE(sb->s_uuid)-1] % EXT2_DFL_MAX_MNT_COUNT)); 465 + (sb->s_uuid[ARRAY_SIZE(sb->s_uuid)-1] % EXT2_DFL_MAX_MNT_COUNT));
449 466
450 // write the label 467 // write the label
451 safe_strncpy((char *)sb->s_volume_name, label, sizeof(sb->s_volume_name)); 468 safe_strncpy((char *)sb->s_volume_name, label, sizeof(sb->s_volume_name));
452 469
453 // fill group descriptors 470 // calculate filesystem skeleton structures
454 gd = xzalloc(gdtsz * blocksize); 471 gd = xzalloc(group_desc_blocks * blocksize);
455 buf = xmalloc(blocksize); 472 buf = xmalloc(blocksize);
456 sb->s_free_blocks_count = 0; 473 sb->s_free_blocks_count = 0;
457 for (i = 0, pos = first_block, n = nblocks - first_block; 474 for (i = 0, pos = first_block, n = nblocks - first_block;
458 i < ngroups; 475 i < ngroups;
459 i++, pos += blocks_per_group, n -= blocks_per_group 476 i++, pos += blocks_per_group, n -= blocks_per_group
460 ) { 477 ) {
461 uint32_t overhead = pos + (has_super(i) ? (1/*sb*/ + gdtsz) : 0); 478 uint32_t overhead = pos + (has_super(i) ? (1/*sb*/ + group_desc_blocks) : 0);
462 uint32_t fb; 479 uint32_t free_blocks;
480 // fill group descriptors
463 STORE_LE(gd[i].bg_block_bitmap, overhead + 0); 481 STORE_LE(gd[i].bg_block_bitmap, overhead + 0);
464 STORE_LE(gd[i].bg_inode_bitmap, overhead + 1); 482 STORE_LE(gd[i].bg_inode_bitmap, overhead + 1);
465 STORE_LE(gd[i].bg_inode_table, overhead + 2); 483 STORE_LE(gd[i].bg_inode_table, overhead + 2);
466 overhead = overhead - pos + 1/*bbmp*/ + 1/*ibmp*/ + itsz; 484 overhead = overhead - pos + 1/*bbmp*/ + 1/*ibmp*/ + inode_table_blocks;
467 gd[i].bg_free_inodes_count = inodes_per_group; 485 gd[i].bg_free_inodes_count = inodes_per_group;
468 //STORE_LE(gd[i].bg_used_dirs_count, 0); 486 //STORE_LE(gd[i].bg_used_dirs_count, 0);
469 // N.B. both root and lost+found dirs are within the first block group, thus +2 487 // N.B. both "/" and "/lost+found" are within the first block group
488 // "/" occupies 1 block, "/lost+found" occupies lost_and_found_blocks...
470 if (0 == i) { 489 if (0 == i) {
471 overhead += 2; 490 // ... thus increased overhead for the first block group ...
491 overhead += 1 + lost_and_found_blocks;
492 // ... and 2 used directories
472 STORE_LE(gd[i].bg_used_dirs_count, 2); 493 STORE_LE(gd[i].bg_used_dirs_count, 2);
494 // well known reserved inodes belong to the first block too
473 gd[i].bg_free_inodes_count -= EXT2_GOOD_OLD_FIRST_INO; 495 gd[i].bg_free_inodes_count -= EXT2_GOOD_OLD_FIRST_INO;
474 } 496 }
475 497
498 // cache free block count of the group
499 free_blocks = (n < blocks_per_group ? n : blocks_per_group) - overhead;
500
476 // mark preallocated blocks as allocated 501 // mark preallocated blocks as allocated
477 fb = (n < blocks_per_group ? n : blocks_per_group) - overhead; 502//bb_info_msg("ALLOC: [%u][%u][%u]", blocksize, overhead, blocks_per_group - (free_blocks + overhead));
478//bb_info_msg("ALLOC: [%u][%u][%u]", blocksize, overhead, blocks_per_group - (fb + overhead));
479 allocate(buf, blocksize, 503 allocate(buf, blocksize,
504 // reserve "overhead" blocks
480 overhead, 505 overhead,
481 blocks_per_group - (fb + overhead) 506 // mark unused trailing blocks
507 blocks_per_group - (free_blocks + overhead)
482 ); 508 );
483 // dump block bitmap 509 // dump block bitmap
484 PUT((uint64_t)(FETCH_LE32(gd[i].bg_block_bitmap)) * blocksize, buf, blocksize); 510 PUT((uint64_t)(FETCH_LE32(gd[i].bg_block_bitmap)) * blocksize, buf, blocksize);
485 STORE_LE(gd[i].bg_free_blocks_count, fb); 511 STORE_LE(gd[i].bg_free_blocks_count, free_blocks);
486 512
487 // mark preallocated inodes as allocated 513 // mark preallocated inodes as allocated
488 allocate(buf, blocksize, 514 allocate(buf, blocksize,
515 // mark reserved inodes
489 inodes_per_group - gd[i].bg_free_inodes_count, 516 inodes_per_group - gd[i].bg_free_inodes_count,
517 // mark unused trailing inodes
490 blocks_per_group - inodes_per_group 518 blocks_per_group - inodes_per_group
491 ); 519 );
492 // dump inode bitmap 520 // dump inode bitmap
@@ -496,7 +524,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
496 STORE_LE(gd[i].bg_free_inodes_count, gd[i].bg_free_inodes_count); 524 STORE_LE(gd[i].bg_free_inodes_count, gd[i].bg_free_inodes_count);
497 525
498 // count overall free blocks 526 // count overall free blocks
499 sb->s_free_blocks_count += fb; 527 sb->s_free_blocks_count += free_blocks;
500 } 528 }
501 STORE_LE(sb->s_free_blocks_count, sb->s_free_blocks_count); 529 STORE_LE(sb->s_free_blocks_count, sb->s_free_blocks_count);
502 530
@@ -506,8 +534,10 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
506 // dump superblock and group descriptors and their backups 534 // dump superblock and group descriptors and their backups
507 if (has_super(i)) { 535 if (has_super(i)) {
508 // N.B. 1024 byte blocks are special 536 // N.B. 1024 byte blocks are special
509 PUT(((uint64_t)pos * blocksize) + ((0 == i && 0 == first_block) ? 1024 : 0), sb, 1024);//blocksize); 537 PUT(((uint64_t)pos * blocksize) + ((0 == i && 1024 != blocksize) ? 1024 : 0),
510 PUT(((uint64_t)pos * blocksize) + blocksize, gd, gdtsz * blocksize); 538 sb, 1024);
539 PUT(((uint64_t)pos * blocksize) + blocksize,
540 gd, group_desc_blocks * blocksize);
511 } 541 }
512 } 542 }
513 543
@@ -516,8 +546,9 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
516 PUT(0, buf, 1024); // N.B. 1024 <= blocksize, so buf[0..1023] contains zeros 546 PUT(0, buf, 1024); // N.B. 1024 <= blocksize, so buf[0..1023] contains zeros
517 // zero inode tables 547 // zero inode tables
518 for (i = 0; i < ngroups; ++i) 548 for (i = 0; i < ngroups; ++i)
519 for (n = 0; n < itsz; ++n) 549 for (n = 0; n < inode_table_blocks; ++n)
520 PUT((uint64_t)(FETCH_LE32(gd[i].bg_inode_table) + n) * blocksize, buf, blocksize); 550 PUT((uint64_t)(FETCH_LE32(gd[i].bg_inode_table) + n) * blocksize,
551 buf, blocksize);
521 552
522 // prepare directory inode 553 // prepare directory inode
523 inode = (struct ext2_inode *)buf; 554 inode = (struct ext2_inode *)buf;
@@ -526,21 +557,34 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
526 STORE_LE(inode->i_atime, timestamp); 557 STORE_LE(inode->i_atime, timestamp);
527 STORE_LE(inode->i_ctime, timestamp); 558 STORE_LE(inode->i_ctime, timestamp);
528 STORE_LE(inode->i_size, blocksize); 559 STORE_LE(inode->i_size, blocksize);
529 // N.B. inode->i_blocks stores the number of 512 byte data blocks. Why on Earth?! 560 // inode->i_blocks stores the number of 512 byte data blocks
561 // (512, because it goes directly to struct stat without scaling)
530 STORE_LE(inode->i_blocks, blocksize / 512); 562 STORE_LE(inode->i_blocks, blocksize / 512);
531 563
532 // dump root dir inode 564 // dump root dir inode
533 STORE_LE(inode->i_links_count, 3); // "/.", "/..", "/lost+found/.." point to this inode 565 STORE_LE(inode->i_links_count, 3); // "/.", "/..", "/lost+found/.." point to this inode
534 STORE_LE(inode->i_block[0], FETCH_LE32(gd[0].bg_inode_table) + itsz); 566 STORE_LE(inode->i_block[0], FETCH_LE32(gd[0].bg_inode_table) + inode_table_blocks);
535 PUT(((uint64_t)FETCH_LE32(gd[0].bg_inode_table) * blocksize) + (EXT2_ROOT_INO-1) * sizeof(*inode), buf, sizeof(*inode)); 567 PUT(((uint64_t)FETCH_LE32(gd[0].bg_inode_table) * blocksize) + (EXT2_ROOT_INO-1) * sizeof(*inode),
568 buf, sizeof(*inode));
536 569
537 // dump lost+found dir inode 570 // dump lost+found dir inode
538 STORE_LE(inode->i_links_count, 2); // both "/lost+found" and "/lost+found/." point to this inode 571 STORE_LE(inode->i_links_count, 2); // both "/lost+found" and "/lost+found/." point to this inode
539 STORE_LE(inode->i_block[0], inode->i_block[0]+1); // use next block 572 STORE_LE(inode->i_size, lost_and_found_blocks * blocksize);
540 PUT(((uint64_t)FETCH_LE32(gd[0].bg_inode_table) * blocksize) + (EXT2_GOOD_OLD_FIRST_INO-1) * sizeof(*inode), buf, sizeof(*inode)); 573 STORE_LE(inode->i_blocks, (lost_and_found_blocks * blocksize) / 512);
574 n = FETCH_LE32(inode->i_block[0]) + 1;
575 for (i = 0; i < lost_and_found_blocks; ++i)
576 STORE_LE(inode->i_block[i], i + n); // use next block
577//bb_info_msg("LAST BLOCK USED[%u]", i + n);
578 PUT(((uint64_t)FETCH_LE32(gd[0].bg_inode_table) * blocksize) + (EXT2_GOOD_OLD_FIRST_INO-1) * sizeof(*inode),
579 buf, sizeof(*inode));
580
581 // zero the blocks for "/lost+found"
582 memset(buf, 0, blocksize);
583 for (i = 1; i < lost_and_found_blocks; ++i)
584 PUT((uint64_t)(FETCH_LE32(gd[0].bg_inode_table) + inode_table_blocks + 1+i) * blocksize,
585 buf, blocksize);
541 586
542 // dump directories 587 // dump directories
543 memset(buf, 0, blocksize);
544 dir = (struct ext2_dir *)buf; 588 dir = (struct ext2_dir *)buf;
545 589
546 // dump lost+found dir block 590 // dump lost+found dir block
@@ -554,7 +598,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
554 STORE_LE(dir->name_len2, 2); 598 STORE_LE(dir->name_len2, 2);
555 STORE_LE(dir->file_type2, EXT2_FT_DIR); 599 STORE_LE(dir->file_type2, EXT2_FT_DIR);
556 dir->name2[0] = '.'; dir->name2[1] = '.'; 600 dir->name2[0] = '.'; dir->name2[1] = '.';
557 PUT((uint64_t)(FETCH_LE32(gd[0].bg_inode_table) + itsz + 1) * blocksize, buf, blocksize); 601 PUT((uint64_t)(FETCH_LE32(gd[0].bg_inode_table) + inode_table_blocks + 1) * blocksize, buf, blocksize);
558 602
559 // dump root dir block 603 // dump root dir block
560 STORE_LE(dir->inode1, EXT2_ROOT_INO); 604 STORE_LE(dir->inode1, EXT2_ROOT_INO);
@@ -564,9 +608,8 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
564 STORE_LE(dir->name_len3, 10); 608 STORE_LE(dir->name_len3, 10);
565 STORE_LE(dir->file_type3, EXT2_FT_DIR); 609 STORE_LE(dir->file_type3, EXT2_FT_DIR);
566 strcpy(dir->name3, "lost+found"); 610 strcpy(dir->name3, "lost+found");
567 PUT((uint64_t)(FETCH_LE32(gd[0].bg_inode_table) + itsz + 0) * blocksize, buf, blocksize); 611 PUT((uint64_t)(FETCH_LE32(gd[0].bg_inode_table) + inode_table_blocks + 0) * blocksize, buf, blocksize);
568 612
569 done:
570 // cleanup 613 // cleanup
571 if (ENABLE_FEATURE_CLEAN_UP) { 614 if (ENABLE_FEATURE_CLEAN_UP) {
572 free(buf); 615 free(buf);