]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
tune2fs: Fix "tune2fs -j <dev>" for extent-enabled filesystems
authorTheodore Ts'o <tytso@mit.edu>
Tue, 25 Aug 2009 14:07:16 +0000 (10:07 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 25 Aug 2009 14:07:16 +0000 (10:07 -0400)
For filesystms that have the extent feature enabled, we need to grab
the use EXT2_IOC_GETFLAGS so that we don't accidentally end up trying
to request clearing the EXT2_EXTENT_FL, which is not supported and
causes the tune2fs -j error out.

Also fix the error returning in ext2fs_add_journal_inode() so it
returns a proper error code if the fstat() or ioctl() calls fail.

Addresses-Launchpad-bug: #416648

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/mkjournal.c

index 412f50b00c34ec5c65bc2b09c6a8bd9d62799791..2cf9e416664f365cac5dab5d74d8b610f498c93d 100644 (file)
@@ -494,21 +494,33 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags)
                        goto errout;
 
                /* Get inode number of the journal file */
-               if (fstat(fd, &st) < 0)
+               if (fstat(fd, &st) < 0) {
+                       retval = errno;
                        goto errout;
+               }
 
 #if defined(HAVE_CHFLAGS) && defined(UF_NODUMP)
                retval = fchflags (fd, UF_NODUMP|UF_IMMUTABLE);
 #else
 #if HAVE_EXT2_IOCTLS
-               f = EXT2_NODUMP_FL | EXT2_IMMUTABLE_FL;
+               if (ioctl(fd, EXT2_IOC_GETFLAGS, &f) < 0) {
+                       retval = errno;
+                       goto errout;
+               }
+               f |= EXT2_NODUMP_FL | EXT2_IMMUTABLE_FL;
                retval = ioctl(fd, EXT2_IOC_SETFLAGS, &f);
 #endif
 #endif
-               if (retval)
+               if (retval) {
+                       retval = errno;
                        goto errout;
+               }
 
-               close(fd);
+               if (close(fd) < 0) {
+                       retval = errno;
+                       fd = -1;
+                       goto errout;
+               }
                journal_ino = st.st_ino;
        } else {
                if ((mount_flags & EXT2_MF_BUSY) &&