tune2fs: Fix "tune2fs -j <dev>" 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" <tytso@mit.edu>
bitmap-optimize
Theodore Ts'o 2009-08-25 10:07:16 -04:00
parent 31b5a2b961
commit 8bafedbf4a
1 changed files with 16 additions and 4 deletions

View 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) &&