]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
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 3b9e7df17271556d0642329f7ab6b3581253ecf4..db5d0bf0afb3b5a8e643c6c9d9bf48b242647605 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 9fa85cb3de50ca1e3aa6c8daacff429851bfc9f9..6d18ef96dc00b19197d6b72ca0b0a5c629190243 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 b54f860152efc71052e839bdd28373becc5e4353..56fa3a978e1624281368bf86ca6f16ba317b46cd 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 b74a7bd2195b55be3aec72957e39d094d66f5da7..ce1a2f3a9cabd472ddb6121c572624d98385781b 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 096f79e20c1cdab3886fd577b6b42310ff349d68..7a0d705320a85240d9b4f613ea756b752f50b146 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 6ae87a4ffe5f3814337542830a5287fb096bddfb..a92c8904c03c0095458f084d54295781c23e5f73 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 35bd6c8b66cd4c073d73c5a549feb7bb4f7761b1..414ecec34eba955b121c966d70c0191187fa7466 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 a25c7284e9bf4b7125e4bd1f6f674095ff4a7bbb..0832bc2864e5e1024b0c8fc6db4e7a9cc7c32764 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 2517d67330ac7caf6b815aae772c6268574acf33..0e0a52c869ceeed1d885b4f811932e3fb63c3af2 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 b9129e3c0f4ee9d0d3e2f0651ba0119c7b910ecc..81e7aea58c5db927e8e83ef717c85ca03185f564 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;