Whamcloud - gitweb
mkjournal.c (ext2fs_add_journal_inode): When creating a .journal
authorTheodore Ts'o <tytso@mit.edu>
Fri, 9 Nov 2001 22:34:54 +0000 (17:34 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 9 Nov 2001 22:34:54 +0000 (17:34 -0500)
file on adding a journal to an already-mounted filesystem,
try to clear the ext2 file attributes on an already
existing .journal file so that we don't fail if on a
partially added journal to the filesystem.

lib/ext2fs/ChangeLog
lib/ext2fs/mkjournal.c

index 07ad68e..903b4a2 100644 (file)
@@ -1,5 +1,11 @@
 2001-11-05  Theodore Tso  <tytso@valinux.com>
 
+       * mkjournal.c (ext2fs_add_journal_inode): When creating a .journal
+               file on adding a journal to an already-mounted filesystem,
+               try to clear the ext2 file attributes on an already
+               existing .journal file so that we don't fail if on a
+               partially added journal to the filesystem.
+
        * ext2_fs.h: Define a new ext2 file attribute, EXT2_NOTAIL_FL,
                which signals that a particular inode should not have the
                last bits of data (the "tail") be merged with another
index 606501d..ae25841 100644 (file)
@@ -327,6 +327,23 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags)
        if (mount_flags & EXT2_MF_MOUNTED) {
                strcat(jfile, "/.journal");
 
+               /*
+                * If .../.journal already exists, make sure any 
+                * immutable or append-only flags are cleared.
+                */
+#if defined(HAVE_CHFLAGS) && defined(UF_NODUMP)
+               (void) chflags (jfile, 0);
+#else
+#if HAVE_EXT2_IOCTLS
+               fd = open(jfile, O_RDONLY);
+               if (fd >= 0) {
+                       f = 0;
+                       ioctl(fd, EXT2_IOC_SETFLAGS, &f);
+                       close(fd);
+               }
+#endif
+#endif
+
                /* Create the journal file */
                if ((fd = open(jfile, O_CREAT|O_WRONLY, 0600)) < 0)
                        return errno;
@@ -342,7 +359,7 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags)
                retval = fchflags (fd, UF_NODUMP|UF_IMMUTABLE);
 #else
 #if HAVE_EXT2_IOCTLS
-               f = EXT2_NODUMP_FL | EXT2_IMMUTABLE_FL;;
+               f = EXT2_NODUMP_FL | EXT2_IMMUTABLE_FL;
                retval = ioctl(fd, EXT2_IOC_SETFLAGS, &f);
 #endif
 #endif