summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2005-03-20 20:05:22 -0500
committerTheodore Ts'o <tytso@mit.edu>2005-03-20 20:05:22 -0500
commit030970ed750b6a169c32ffb8b19bce3150198629 (patch)
treeb02d1738b6786d0d9c2bbf2f246a2f8eb31ab2c4 /lib
parentea822eeba373bd0bed6e58a35ce123a9f2768113 (diff)
downloade2fsprogs-030970ed750b6a169c32ffb8b19bce3150198629.tar.gz
Fix e2fsck, debugfs, and the ext2fs_mkdir function so that when we create
a new inode we make sure that the extra information in the inode (any extra fields in a large inode and any ea-in-inode information) is cleared. This can happen when e2fsck creates a new root inode or a new lost+found directory, or when the user uses the debugfs write, mknod, or mkdir commands. Otherwise, the newly create inode could inherit garbage (or old EA information) from a previously deleted inode.
Diffstat (limited to 'lib')
-rw-r--r--lib/ext2fs/ChangeLog10
-rw-r--r--lib/ext2fs/ext2fs.h2
-rw-r--r--lib/ext2fs/inode.c26
-rw-r--r--lib/ext2fs/mkdir.c2
4 files changed, 39 insertions, 1 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 35bd6c8b..414ecec3 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,13 @@
+2005-03-20 Theodore Ts'o <tytso@mit.edu>
+
+ * mkdir.c (ext2fs_mkdir): Call ext2fs_write_new_inode() instead of
+ ext2fs_write_inode().
+
+ * inode.c (ext2fs_write_new_inode): New function which should be
+ used when the caller is writing an inode for the first
+ time. It makes sure that the extra portion of the large
+ inode is cleared.
+
2005-03-18 Theodore Ts'o <tytso@mit.edu>
* Makefile.in: Fix clean target to remove tst_getsectsize.
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index a25c7284..0832bc28 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -816,6 +816,8 @@ extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
int bufsize);
extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
struct ext2_inode * inode);
+extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
+ struct ext2_inode * inode);
extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
index 2517d673..0e0a52c8 100644
--- a/lib/ext2fs/inode.c
+++ b/lib/ext2fs/inode.c
@@ -715,6 +715,32 @@ errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
return ext2fs_write_inode_full(fs, ino, inode,
sizeof(struct ext2_inode));
}
+
+/*
+ * This function should be called when writing a new inode. It makes
+ * sure that extra part of large inodes is cleared.
+ */
+errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
+ struct ext2_inode *inode)
+{
+ struct ext2_inode *buf;
+ errcode_t retval;
+ int size = EXT2_INODE_SIZE(fs->super);
+
+ if (size == sizeof(struct ext2_inode))
+ return ext2fs_write_inode_full(fs, ino, inode,
+ sizeof(struct ext2_inode));
+
+ buf = malloc(size);
+ if (!buf)
+ return ENOMEM;
+
+ memset(buf, 0, size);
+ *buf = *inode;
+
+ retval = ext2fs_write_inode_full(fs, ino, buf, size);
+}
+
errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks)
{
diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c
index b9129e3c..81e7aea5 100644
--- a/lib/ext2fs/mkdir.c
+++ b/lib/ext2fs/mkdir.c
@@ -94,7 +94,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
retval = ext2fs_write_dir_block(fs, blk, block);
if (retval)
goto cleanup;
- retval = ext2fs_write_inode(fs, ino, &inode);
+ retval = ext2fs_write_new_inode(fs, ino, &inode);
if (retval)
goto cleanup;