Whamcloud - gitweb
Fix e2fsck, debugfs, and the ext2fs_mkdir function so that when we create
authorTheodore Ts'o <tytso@mit.edu>
Mon, 21 Mar 2005 01:05:22 +0000 (20:05 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 21 Mar 2005 01:05:22 +0000 (20:05 -0500)
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.

debugfs/ChangeLog
debugfs/debugfs.c
debugfs/debugfs.h
debugfs/util.c
e2fsck/ChangeLog
e2fsck/pass3.c
lib/ext2fs/ChangeLog
lib/ext2fs/ext2fs.h
lib/ext2fs/inode.c
lib/ext2fs/mkdir.c

index 3b9e7df..db5d0bf 100644 (file)
@@ -1,5 +1,10 @@
 2005-03-20  Theodore Ts'o  <tytso@mit.edu>
 
+       * util.c (debugfs_write_new_inode): New function
+
+       * debgufs.c (do_write, do_mknod): Call ext2fs_write_new_inode()
+               instead of ext2fs_write_inode().
+
        * debugfs.c (do_stat): Add support for dumping extended attributes
                which are stored in the inode body.
 
index 9fa85cb..6d18ef9 100644 (file)
@@ -1294,7 +1294,7 @@ void do_write(int argc, char *argv[])
        inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL);
        inode.i_links_count = 1;
        inode.i_size = statbuf.st_size;
-       if (debugfs_write_inode(newfile, &inode, argv[0])) {
+       if (debugfs_write_new_inode(newfile, &inode, argv[0])) {
                close(fd);
                return;
        }
@@ -1387,7 +1387,7 @@ void do_mknod(int argc, char *argv[])
                inode.i_block[1] = (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
        }
        inode.i_links_count = 1;
-       if (debugfs_write_inode(newfile, &inode, argv[0]))
+       if (debugfs_write_new_inode(newfile, &inode, argv[0]))
                return;
 }
 
index b54f860..56fa3a9 100644 (file)
@@ -45,6 +45,8 @@ extern int debugfs_read_inode(ext2_ino_t ino, struct ext2_inode * inode,
                              const char *cmd);
 extern int debugfs_write_inode(ext2_ino_t ino, struct ext2_inode * inode,
                               const char *cmd);
+extern int debugfs_write_new_inode(ext2_ino_t ino, struct ext2_inode * inode,
+                                  const char *cmd);
 
 /* ss command functions */
 
index b74a7bd..ce1a2f3 100644 (file)
@@ -346,3 +346,15 @@ int debugfs_write_inode(ext2_ino_t ino, struct ext2_inode * inode,
        return 0;
 }
 
+int debugfs_write_new_inode(ext2_ino_t ino, struct ext2_inode * inode,
+                           const char *cmd)
+{
+       int retval;
+
+       retval = ext2fs_write_new_inode(current_fs, ino, inode);
+       if (retval) {
+               com_err(cmd, retval, "while creating inode %u", ino);
+               return 1;
+       }
+       return 0;
+}
index 096f79e..7a0d705 100644 (file)
@@ -1,5 +1,8 @@
 2005-03-20  Theodore Ts'o  <tytso@mit.edu>
 
+       * pass3.c (check_root, e2fsck_get_lost_and_found): Call
+               ext2fs_write_new_inode() instead of ext2fs_write_inode().
+
        * pass1.c (check_blocks): Move counting the extended attribute
                block earlier so that we don't have to worry about
                num_blocks wrapping for files which are too big.
index 6ae87a4..a92c890 100644 (file)
@@ -230,7 +230,7 @@ static void check_root(e2fsck_t ctx)
        /*
         * Write out the inode.
         */
-       pctx.errcode = ext2fs_write_inode(fs, EXT2_ROOT_INO, &inode);
+       pctx.errcode = ext2fs_write_new_inode(fs, EXT2_ROOT_INO, &inode);
        if (pctx.errcode) {
                pctx.str = "ext2fs_write_inode";
                fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
@@ -478,7 +478,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        /*
         * Next, write out the inode.
         */
-       pctx.errcode = ext2fs_write_inode(fs, ino, &inode);
+       pctx.errcode = ext2fs_write_new_inode(fs, ino, &inode);
        if (pctx.errcode) {
                pctx.str = "ext2fs_write_inode";
                fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
index 35bd6c8..414ecec 100644 (file)
@@ -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.
index a25c728..0832bc2 100644 (file)
@@ -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);
 
index 2517d67..0e0a52c 100644 (file)
@@ -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)
 {
index b9129e3..81e7aea 100644 (file)
@@ -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;