Skip to content

Commit 6e776e8

Browse files
committed
libext2fs: don't truncate the orphan file inode if it is newly allocated
In ext2fs_create_orphan_file(), don't try truncating inode for the orphan file if ext2fs_create_orphan_file() allocated the inode. This avoids problems where the newly allocated inode in the inode table might contain garbage; if the metadata checksum feature is enabled, this will generally result in the function failing with a checksum invalid error, but this can cause mke2fs (which calls ext2fs_create_orphan_file) to fail. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent fe93a29 commit 6e776e8

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/ext2fs/orphan.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,21 @@ errcode_t ext2fs_create_orphan_file(ext2_filsys fs, blk_t num_blocks)
127127
struct mkorphan_info oi;
128128
struct ext4_orphan_block_tail *ob_tail;
129129

130-
if (!ino) {
130+
if (ino) {
131+
err = ext2fs_read_inode(fs, ino, &inode);
132+
if (err)
133+
return err;
134+
if (EXT2_I_SIZE(&inode)) {
135+
err = ext2fs_truncate_orphan_file(fs);
136+
if (err)
137+
return err;
138+
}
139+
} else {
131140
err = ext2fs_new_inode(fs, EXT2_ROOT_INO, LINUX_S_IFREG | 0600,
132141
0, &ino);
133142
if (err)
134143
return err;
135144
ext2fs_inode_alloc_stats2(fs, ino, +1, 0);
136-
ext2fs_mark_ib_dirty(fs);
137-
}
138-
139-
err = ext2fs_read_inode(fs, ino, &inode);
140-
if (err)
141-
return err;
142-
if (EXT2_I_SIZE(&inode)) {
143-
err = ext2fs_truncate_orphan_file(fs);
144-
if (err)
145-
return err;
146145
}
147146

148147
memset(&inode, 0, sizeof(struct ext2_inode));

0 commit comments

Comments
 (0)