From 5bc28df0fa2544a08b65d9091fdc9fb23bdbce68 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 9 Nov 2001 17:34:54 -0500 Subject: [PATCH] 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. --- lib/ext2fs/ChangeLog | 6 ++++++ lib/ext2fs/mkjournal.c | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 07ad68e..903b4a2 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,5 +1,11 @@ 2001-11-05 Theodore Tso + * 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 diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 606501d..ae25841 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -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 -- 1.8.3.1