aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/e2fs.h11
-rw-r--r--toys/mke2fs.c10
2 files changed, 16 insertions, 5 deletions
diff --git a/toys/e2fs.h b/toys/e2fs.h
index b50a8817..49eb4c40 100644
--- a/toys/e2fs.h
+++ b/toys/e2fs.h
@@ -64,6 +64,17 @@ struct ext2_superblock {
uint32_t reserved[172]; // Padding to the end of the block
};
+struct ext2_group
+{
+ uint32_t block_bitmap; // Block number of block bitmap
+ uint32_t inode_bitmap; // Block number of inode bitmap
+ uint32_t inode_table; // Block number of inode table
+ uint16_t free_blocks_count; // How many free blocks in this group?
+ uint16_t free_inodes_count; // How many free inodes in this group?
+ uint16_t used_dirs_count; // How many directories?
+ uint16_t reserved[7]; // pad to 256 bits.
+};
+
struct ext2_dentry {
uint32_t inode; // Inode number
uint16_t rec_len; // Directory entry length
diff --git a/toys/mke2fs.c b/toys/mke2fs.c
index 0c71da87..b50068a0 100644
--- a/toys/mke2fs.c
+++ b/toys/mke2fs.c
@@ -79,13 +79,11 @@ int mke2fs_main(void)
// Determine appropriate block size, set log_block_size and log_frag_size.
if (!TT.blocksize) TT.blocksize = (length && length < 1<<29) ? 1024 : 4096;
- if (TT.blocksize == 1024) temp = 0;
- else if (TT.blocksize == 2048) temp = 1;
- else if (TT.blocksize == 4096) temp = 2;
- else error_exit("bad blocksize");
+ for (temp = 0; temp < 7; temp++) if (TT.blocksize == 1024<<temp) break;
+ if (temp==7) error_exit("bad blocksize");
sb->log_block_size = sb->log_frag_size = SWAP_LE32(temp);
- // Fill out blocks_count and r_blocks_count
+ // Fill out blocks_count, r_blocks_count, first_data_block
if (!TT.blocks) TT.blocks = length/TT.blocksize;
sb->blocks_count = SWAP_LE32(TT.blocks);
@@ -94,6 +92,8 @@ int mke2fs_main(void)
temp = (TT.blocks * (uint64_t)TT.reserved_percent) /100;
sb->r_blocks_count = SWAP_LE32(temp);
+ sb->first_data_block = TT.blocksize == 1024 ? 1 : 0;
+
// Set blocks_per_group and frags_per_group, which is the size of an
// allocation bitmap that fits in one block (I.E. how many bits per block)?