Whamcloud - gitweb
e2fsck.h, journal.c (e2fsck_move_ext3_journal): Add new function
authorTheodore Ts'o <tytso@mit.edu>
Sun, 7 Oct 2001 01:26:27 +0000 (21:26 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 7 Oct 2001 01:26:27 +0000 (21:26 -0400)
which will automatically relocate the ext3 journal from a
visible file to an invisible journal file if the
filesystem has been opened read/write.

super.c (check_super_block): Add call to e2fsck_move_ext3_journal

problem.c, problem.h (PR_0_MOVE_JOURNAL, PR_0_ERR_MOVE_JOURNAL):
Add new problem codes.

e2fsck/ChangeLog
e2fsck/e2fsck.h
e2fsck/journal.c
e2fsck/problem.c
e2fsck/problem.h
e2fsck/super.c

index 2a0481c..ad944da 100644 (file)
@@ -1,3 +1,15 @@
+2001-09-20  Theodore Tso  <tytso@valinux.com>
+
+       * e2fsck.h, journal.c (e2fsck_move_ext3_journal): Add new function
+               which will automatically relocate the ext3 journal from a
+               visible file to an invisible journal file if the
+               filesystem has been opened read/write.
+
+       * super.c (check_super_block): Add call to e2fsck_move_ext3_journal
+
+       * problem.c, problem.h (PR_0_MOVE_JOURNAL, PR_0_ERR_MOVE_JOURNAL):
+               Add new problem codes.
+
 2001-09-20  Theodore Tso  <tytso@thunk.org>
 
        * Release of E2fsprogs 1.25
index 0541ab1..35de50b 100644 (file)
@@ -314,6 +314,7 @@ extern void ehandler_init(io_channel channel);
 /* journal.c */
 extern int e2fsck_check_ext3_journal(e2fsck_t ctx);
 extern int e2fsck_run_ext3_journal(e2fsck_t ctx);
+extern void e2fsck_move_ext3_journal(e2fsck_t ctx);
 
 /* pass1.c */
 extern void e2fsck_use_inode_shortcuts(e2fsck_t ctx, int bool);
index fd71921..0bff025 100644 (file)
@@ -706,3 +706,103 @@ int e2fsck_run_ext3_journal(e2fsck_t ctx)
        e2fsck_clear_recover(ctx, recover_retval);
        return recover_retval;
 }
+
+/*
+ * This function will move the journal inode from a visible file in
+ * the filesystem directory hierarchy to the reserved inode if necessary.
+ */
+const static char * const journal_names[] = {
+       ".journal", "journal", ".journal.dat", "journal.dat", 0 };
+
+void e2fsck_move_ext3_journal(e2fsck_t ctx)
+{
+       struct ext2_super_block *sb = ctx->fs->super;
+       struct problem_context  pctx;
+       struct ext2_inode       inode;
+       ext2_filsys             fs = ctx->fs;
+       ext2_ino_t              ino;
+       errcode_t               retval;
+       const char * const *    cpp;
+       int                     group, mount_flags;
+       
+       /*
+        * If the filesystem is opened read-only, or there is no
+        * journal, or the journal is already in the hidden inode,
+        * then do nothing.
+        */
+       if ((ctx->options & E2F_OPT_READONLY) ||
+           (sb->s_journal_inum == 0) ||
+           (sb->s_journal_inum == EXT2_JOURNAL_INO) ||
+           !(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL))
+               return;
+
+       /*
+        * If the filesystem is mounted, or we can't tell whether
+        * or not it's mounted, do nothing.
+        */
+       retval = ext2fs_check_if_mounted(ctx->filesystem_name, &mount_flags);
+       if (retval || (mount_flags & EXT2_MF_MOUNTED))
+               return;
+
+       /*
+        * If we can't find the name of the journal inode, then do
+        * nothing.
+        */
+       for (cpp = journal_names; *cpp; cpp++) {
+               retval = ext2fs_lookup(fs, EXT2_ROOT_INO, *cpp,
+                                      strlen(*cpp), 0, &ino);
+               if ((retval == 0) && (ino == sb->s_journal_inum))
+                       break;
+       }
+       if (*cpp == 0)
+               return;
+
+       /*
+        * The inode had better have only one link and not be readable.
+        */
+       if (ext2fs_read_inode(fs, ino, &inode) != 0)
+               return;
+       if (inode.i_links_count != 1)
+               return;
+
+       /* We need the inode bitmap to be loaded */
+       retval = ext2fs_read_bitmaps(fs);
+       if (retval)
+               return;
+
+       clear_problem_context(&pctx);
+       pctx.str = *cpp;
+       if (!fix_problem(ctx, PR_0_MOVE_JOURNAL, &pctx))
+               return;
+               
+       /*
+        * OK, we've done all the checks, let's actually move the
+        * journal inode.  Errors at this point mean we need to force
+        * an ext2 filesystem check.
+        */
+       if ((retval = ext2fs_unlink(fs, EXT2_ROOT_INO, *cpp, ino, 0)) != 0)
+               goto err_out;
+       if ((retval = ext2fs_write_inode(fs, EXT2_JOURNAL_INO, &inode)) != 0)
+               goto err_out;
+       sb->s_journal_inum = EXT2_JOURNAL_INO;
+       ext2fs_mark_super_dirty(fs);
+       inode.i_links_count = 0;
+       inode.i_dtime = time(0);
+       if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0)
+               goto err_out;
+
+       group = ext2fs_group_of_ino(fs, ino);
+       ext2fs_unmark_inode_bitmap(fs->inode_map, ino);
+       ext2fs_mark_ib_dirty(fs);
+       fs->group_desc[group].bg_free_inodes_count++;
+       fs->super->s_free_inodes_count++;
+       return;
+
+err_out:
+       pctx.errcode = retval;
+       fix_problem(ctx, PR_0_ERR_MOVE_JOURNAL, &pctx);
+       fs->super->s_state &= ~EXT2_VALID_FS;
+       ext2fs_mark_super_dirty(fs);
+       return;
+}
+
index 8044e67..34f4f30 100644 (file)
@@ -276,7 +276,17 @@ static const struct e2fsck_problem problem_table[] = {
        { PR_0_JOURNAL_UNSUPP_VERSION,
          N_("@j version not supported by this e2fsck.\n"),
          PROMPT_ABORT, 0 },
+
+       /* Moving journal to hidden file */
+       { PR_0_MOVE_JOURNAL,
+         N_("Moving @j from /%s to hidden inode.\n\n"),
+         PROMPT_NONE, 0 },
+
+       /* Error moving journal to hidden file */
+       { PR_0_ERR_MOVE_JOURNAL,
+         N_("Error moving @j: %m\n\n"),
+         PROMPT_NONE, 0 },
+
        /* Pass 1 errors */
        
        /* Pass 1: Checking inodes, blocks, and sizes */
index 6792ecb..e7ddf76 100644 (file)
@@ -155,6 +155,12 @@ struct problem_context {
 /* Journal has unsupported version number */
 #define PR_0_JOURNAL_UNSUPP_VERSION            0x000027
 
+/* Moving journal to hidden file */
+#define        PR_0_MOVE_JOURNAL                       0x000028
+
+/* Error moving journal */
+#define        PR_0_ERR_MOVE_JOURNAL                   0x000029
+
 /*
  * Pass 1 errors
  */
index ceac78b..43773ae 100644 (file)
@@ -509,6 +509,10 @@ void check_super_block(e2fsck_t ctx)
                ext2fs_mark_super_dirty(fs);
        }
 
+       /*
+        * Move the ext3 journal file, if necessary.
+        */
+       e2fsck_move_ext3_journal(ctx);
        return;
 }