summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-06-18 18:42:08 +0200
committerCarl Hetherington <cth@carlh.net>2022-06-18 23:02:43 +0200
commit0774773de51df37d7af0d6ac920d304790a610c6 (patch)
tree3a9fd33a480ef2072374f12729c4bb7f4b156f1e /src
parentcce3730330bd5621a94ec813934ba4f41254910d (diff)
Revert "Don't initialise inode tables during format."
I think the flag which we were using here (to ask the OS to fill in the inode tables when the drive is first mounted) is only supported by ext4, so will be ignored when the disk is mounted as ext2. This means that e2fsck gives a long list of errors (DoM bug #2274). This reverts commit 6d34064b3a4b07218b01f6cc7700ee2ce68a7542.
Diffstat (limited to 'src')
-rw-r--r--src/ext4_fs.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/ext4_fs.c b/src/ext4_fs.c
index bc19e7f..8e229ef 100644
--- a/src/ext4_fs.c
+++ b/src/ext4_fs.c
@@ -57,7 +57,6 @@
#include <ext4_extent.h>
#include <string.h>
-#include <stdlib.h>
int ext4_fs_init(struct ext4_fs *fs, struct ext4_blockdev *bdev,
bool read_only)
@@ -423,12 +422,11 @@ static int ext4_fs_init_inode_bitmap(struct ext4_block_group_ref *bg_ref)
return ext4_block_set(bg_ref->fs->bdev, &b);
}
-
/**@brief Initialize i-node table in block group.
* @param bg_ref Reference to block group
* @return Error code
*/
-static int ext4_fs_init_inode_table(struct ext4_block_group_ref *bg_ref, int lazy)
+static int ext4_fs_init_inode_table(struct ext4_block_group_ref *bg_ref)
{
struct ext4_sblock *sb = &bg_ref->fs->sb;
struct ext4_bgroup *bg = bg_ref->block_group;
@@ -436,7 +434,6 @@ static int ext4_fs_init_inode_table(struct ext4_block_group_ref *bg_ref, int laz
uint32_t inode_size = ext4_get16(sb, inode_size);
uint32_t block_size = ext4_sb_get_block_size(sb);
uint32_t inodes_per_block = block_size / inode_size;
- uint32_t inodes_per_group = ext4_get32(sb, inodes_per_group);
uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bg_ref->index);
uint32_t table_blocks = inodes_in_group / inodes_per_block;
ext4_fsblk_t fblock;
@@ -446,15 +443,25 @@ static int ext4_fs_init_inode_table(struct ext4_block_group_ref *bg_ref, int laz
/* Compute initialization bounds */
ext4_fsblk_t first_block = ext4_bg_get_inode_table_first_block(bg, sb);
+
ext4_fsblk_t last_block = first_block + table_blocks - 1;
- void* zeros = calloc(table_blocks, block_size);
- if (!zeros) {
- return ENOMEM;
+ /* Initialization of all itable blocks */
+ for (fblock = first_block; fblock <= last_block; ++fblock) {
+ struct ext4_block b;
+ int rc = ext4_trans_block_get_noread(bg_ref->fs->bdev, &b, fblock);
+ if (rc != EOK)
+ return rc;
+
+ memset(b.data, 0, block_size);
+ ext4_trans_set_block_dirty(b.buf);
+
+ rc = ext4_block_set(bg_ref->fs->bdev, &b);
+ if (rc != EOK)
+ return rc;
}
- int rc = ext4_block_writebytes(bg_ref->fs->bdev, first_block * block_size, zeros, table_blocks * block_size);
- free(zeros);
- return rc;
+
+ return EOK;
}
static ext4_fsblk_t ext4_fs_get_descriptor_block(struct ext4_sblock *s,
@@ -610,21 +617,13 @@ int ext4_fs_get_block_group_ref(struct ext4_fs *fs, uint32_t bgid,
ext4_bg_clear_flag(bg, EXT4_BLOCK_GROUP_INODE_UNINIT);
if (!ext4_bg_has_flag(bg, EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
- /* mke2fs does not initialize inode table blocks to zero,
- * unless explicitly set otherwise with the lazy_itable_init
- * option being set to 0. It seems that if EXT4_BLOCK_GROUP_ITABLE_ZEROED
- * is not set the kernel will zero out these blocks on the first
- * mount. Zeroing the blocks takes a long time, so we'll try
- * not doing it.
- */
-#if 0
- rc = ext4_fs_init_inode_table(ref, lazy);
+ rc = ext4_fs_init_inode_table(ref);
if (rc != EOK) {
ext4_block_set(fs->bdev, &ref->block);
return rc;
}
+
ext4_bg_set_flag(bg, EXT4_BLOCK_GROUP_ITABLE_ZEROED);
-#endif
}
ref->dirty = true;