From 8bafedbf4a6889b20e119a667fc243909d283f85 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 25 Aug 2009 10:07:16 -0400 Subject: [PATCH] tune2fs: Fix "tune2fs -j " for extent-enabled filesystems 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" --- lib/ext2fs/mkjournal.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 412f50b..2cf9e41 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -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) && -- 1.8.3.1