OSDN Git Service

ChangeLog, e2fsck.h, pass1.c, pass2.c, pass3.c, problem.c, problem.h, util.c:
authorTheodore Ts'o <tytso@mit.edu>
Wed, 10 Nov 1999 13:34:40 +0000 (13:34 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 10 Nov 1999 13:34:40 +0000 (13:34 +0000)
  pass1.c (e2fsck_pass1): If the filesystem does not support imagic
   inodes, if an inode has the imagic flag set, offer to clear the imagic
   flag.  If a valid device/fifo/socket has the immutable flag set, call
   the new helper function check_immutable() to offerto clear the
   immutable flag.
  pass2.c (check_filetype): Use the new ext2_file_type() helper function
   instead of calculating the file_type information manually.
  pass3.c (e2fsck_reconnect_file): When adding a link to lost+found,
   calculate the filetype information so that ext2fs_link() can use the
   information if applicable.  (get_lost_and_found): Create the
   /lost+found directory with the correct filetype information if
   applicable.
  util.c (ext2_file_type), e2fsck.h: New function which returns the
   directory entry file type information given the inode's mode bits.
  problem.c, problem.h: Added new problem codes PR_1_SET_IMAGIC and
   PR_1_SET_IMMUTABLE.
ChangeLog, mke2fs.8.in:
  mke2fs.8.in: Update manual page so that the sparse_option filesystem
   option is properly named.

e2fsck/ChangeLog
e2fsck/e2fsck.h
e2fsck/pass1.c
e2fsck/pass2.c
e2fsck/pass3.c
e2fsck/problem.c
e2fsck/problem.h
e2fsck/util.c
misc/ChangeLog
misc/mke2fs.8.in

index 18a628b..83caab8 100644 (file)
@@ -1,3 +1,28 @@
+1999-11-09    <tytso@valinux.com>
+
+       * pass1.c (e2fsck_pass1): If the filesystem does not support
+               imagic inodes, if an inode has the imagic flag set, offer
+               to clear the imagic flag.  If a valid device/fifo/socket
+               has the immutable flag set, call the new helper function
+               check_immutable() to offerto clear the immutable flag.
+
+       * pass2.c (check_filetype): Use the new ext2_file_type() helper
+               function instead of calculating the file_type information
+               manually.
+
+       * pass3.c (e2fsck_reconnect_file): When adding a link to
+               lost+found, calculate the filetype information so that
+               ext2fs_link() can use the information if applicable.
+               (get_lost_and_found): Create the /lost+found directory
+               with the correct filetype information if applicable.
+
+       * util.c (ext2_file_type), e2fsck.h: New function which returns
+               the directory entry file type information given the
+               inode's mode bits.
+
+       * problem.c, problem.h: Added new problem codes PR_1_SET_IMAGIC
+               and PR_1_SET_IMMUTABLE.
+
 1999-11-07    <tytso@valinux.com>
 
        * pass4.c (e2fsck_pass4): Clear inode_imagic_map after freeing it,
index 83f0889..dd24d59 100644 (file)
@@ -304,6 +304,7 @@ extern void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
 extern void mtrace_print(char *mesg);
 #endif
 extern blk_t get_backup_sb(ext2_filsys fs);
+extern int ext2_file_type(unsigned int mode);
 
 /* unix.c */
 extern void e2fsck_clear_progbar(e2fsck_t ctx);
index c7475f9..cf821ee 100644 (file)
@@ -141,6 +141,22 @@ int e2fsck_pass1_check_device_inode(struct ext2_inode *inode)
        return 1;
 }
 
+/*
+ * If the immutable flag is set on the inode, offer to clear it.
+ */
+static void check_immutable(e2fsck_t ctx, struct problem_context *pctx)
+{
+       if (!(pctx->inode->i_flags & EXT2_IMMUTABLE_FL))
+               return;
+
+       if (!fix_problem(ctx, PR_1_SET_IMMUTABLE, pctx))
+               return;
+
+       pctx->inode->i_flags &= ~EXT2_IMMUTABLE_FL;
+       e2fsck_write_inode(ctx, pctx->ino, pctx->inode, "pass1");
+}
+
+
 void e2fsck_pass1(e2fsck_t ctx)
 {
        int     i;
@@ -157,6 +173,7 @@ void e2fsck_pass1(e2fsck_t ctx)
        struct          problem_context pctx;
        struct          scan_callback_struct scan_struct;
        struct ext2fs_sb *sb;
+       int             imagic_fs;
        
 #ifdef RESOURCE_TRACK
        init_resource_track(&rtrack);
@@ -182,7 +199,10 @@ void e2fsck_pass1(e2fsck_t ctx)
                ext2_max_sizes[i] = max_sizes;
        }
 #undef EXT2_BPP
-       
+
+       sb = (struct ext2fs_sb *) fs->super;
+       imagic_fs = (sb->s_feature_compat & EXT2_FEATURE_COMPAT_IMAGIC_INODES);
+
        /*
         * Allocate bitmaps structures
         */
@@ -418,9 +438,18 @@ void e2fsck_pass1(e2fsck_t ctx)
                        ext2fs_mark_inode_bitmap(ctx->inode_bad_map, ino);
                }
                if (inode.i_flags & EXT2_IMAGIC_FL) {
-                       if (!ctx->inode_imagic_map)
-                               alloc_imagic_map(ctx);
-                       ext2fs_mark_inode_bitmap(ctx->inode_imagic_map, ino);
+                       if (imagic_fs) {
+                               if (!ctx->inode_imagic_map)
+                                       alloc_imagic_map(ctx);
+                               ext2fs_mark_inode_bitmap(ctx->inode_imagic_map,
+                                                        ino);
+                       } else {
+                               if (fix_problem(ctx, PR_1_SET_IMAGIC, &pctx)) {
+                                       inode.i_flags &= ~EXT2_IMAGIC_FL;
+                                       e2fsck_write_inode(ctx, ino,
+                                                          &inode, "pass1");
+                               }
+                       }
                }
                
                if (LINUX_S_ISDIR(inode.i_mode)) {
@@ -431,12 +460,14 @@ void e2fsck_pass1(e2fsck_t ctx)
                        ext2fs_mark_inode_bitmap(ctx->inode_reg_map, ino);
                        ctx->fs_regular_count++;
                } else if (LINUX_S_ISCHR (inode.i_mode) &&
-                        e2fsck_pass1_check_device_inode(&inode))
+                          e2fsck_pass1_check_device_inode(&inode)) {
+                       check_immutable(ctx, &pctx);
                        ctx->fs_chardev_count++;
-               else if (LINUX_S_ISBLK (inode.i_mode) &&
-                        e2fsck_pass1_check_device_inode(&inode))
+               } else if (LINUX_S_ISBLK (inode.i_mode) &&
+                          e2fsck_pass1_check_device_inode(&inode)) {
+                       check_immutable(ctx, &pctx);
                        ctx->fs_blockdev_count++;
-               else if (LINUX_S_ISLNK (inode.i_mode)) {
+               else if (LINUX_S_ISLNK (inode.i_mode)) {
                        ctx->fs_symlinks_count++;
                        if (!inode.i_blocks) {
                                ctx->fs_fast_symlinks_count++;
@@ -444,12 +475,14 @@ void e2fsck_pass1(e2fsck_t ctx)
                        }
                }
                else if (LINUX_S_ISFIFO (inode.i_mode) &&
-                         e2fsck_pass1_check_device_inode(&inode))
+                        e2fsck_pass1_check_device_inode(&inode)) {
+                       check_immutable(ctx, &pctx);
                        ctx->fs_fifo_count++;
-               else if ((LINUX_S_ISSOCK (inode.i_mode)) &&
-                        e2fsck_pass1_check_device_inode(&inode))
+               } else if ((LINUX_S_ISSOCK (inode.i_mode)) &&
+                          e2fsck_pass1_check_device_inode(&inode)) {
+                       check_immutable(ctx, &pctx);
                        ctx->fs_sockets_count++;
-               else {
+               else {
                        if (!ctx->inode_bad_map)
                                alloc_bad_map(ctx);
                        ext2fs_mark_inode_bitmap(ctx->inode_bad_map, ino);
@@ -529,7 +562,6 @@ endit:
        ext2fs_free_block_bitmap(ctx->block_illegal_map);
        ctx->block_illegal_map = 0;
 
-       sb = (struct ext2fs_sb *) fs->super;
        if (ctx->large_files && 
            !(sb->s_feature_ro_compat & 
              EXT2_FEATURE_RO_COMPAT_LARGE_FILE)) {
index e6a434c..826c0dc 100644 (file)
@@ -311,16 +311,7 @@ static _INLINE_ int check_filetype(e2fsck_t ctx,
        else {
                e2fsck_read_inode(ctx, dirent->inode, &inode,
                                  "check_filetype");
-               if (LINUX_S_ISCHR (inode.i_mode))
-                       should_be = EXT2_FT_CHRDEV;
-               else if (LINUX_S_ISBLK (inode.i_mode))
-                       should_be = EXT2_FT_BLKDEV;
-               else if (LINUX_S_ISLNK (inode.i_mode))
-                       should_be = EXT2_FT_SYMLINK;
-               else if (LINUX_S_ISFIFO (inode.i_mode))
-                       should_be = EXT2_FT_FIFO;
-               else if (LINUX_S_ISSOCK (inode.i_mode))
-                       should_be = EXT2_FT_SOCK;
+               should_be = ext2_file_type(inode.i_mode);
        }
        if (filetype == should_be)
                return 0;
index a336835..949e488 100644 (file)
@@ -451,7 +451,7 @@ ino_t get_lost_and_found(e2fsck_t ctx)
        /*
         * Finally, create the directory link
         */
-       pctx.errcode = ext2fs_link(fs, EXT2_ROOT_INO, name, ino, 0);
+       pctx.errcode = ext2fs_link(fs, EXT2_ROOT_INO, name, ino, EXT2_FT_DIR);
        if (pctx.errcode) {
                pctx.str = "ext2fs_link";
                fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
@@ -474,15 +474,17 @@ ino_t get_lost_and_found(e2fsck_t ctx)
 /*
  * This routine will connect a file to lost+found
  */
-int e2fsck_reconnect_file(e2fsck_t ctx, ino_t inode)
+int e2fsck_reconnect_file(e2fsck_t ctx, ino_t ino)
 {
        ext2_filsys fs = ctx->fs;
        errcode_t       retval;
        char            name[80];
        struct problem_context  pctx;
+       struct ext2_inode       inode;
+       int             file_type = 0;
 
        clear_problem_context(&pctx);
-       pctx.ino = inode;
+       pctx.ino = ino;
 
        if (!bad_lost_and_found && !lost_and_found) {
                lost_and_found = get_lost_and_found(ctx);
@@ -494,8 +496,10 @@ int e2fsck_reconnect_file(e2fsck_t ctx, ino_t inode)
                return 1;
        }
        
-       sprintf(name, "#%lu", inode);
-       retval = ext2fs_link(fs, lost_and_found, name, inode, 0);
+       sprintf(name, "#%lu", ino);
+       if (ext2fs_read_inode(fs, ino, &inode) == 0)
+               file_type = ext2_file_type(inode.i_mode);
+       retval = ext2fs_link(fs, lost_and_found, name, ino, file_type);
        if (retval == EXT2_ET_DIR_NO_SPACE) {
                if (!fix_problem(ctx, PR_3_EXPAND_LF_DIR, &pctx))
                        return 1;
@@ -505,14 +509,14 @@ int e2fsck_reconnect_file(e2fsck_t ctx, ino_t inode)
                        fix_problem(ctx, PR_3_CANT_EXPAND_LPF, &pctx);
                        return 1;
                }
-               retval = ext2fs_link(fs, lost_and_found, name, inode, 0);
+               retval = ext2fs_link(fs, lost_and_found, name, ino, file_type);
        }
        if (retval) {
                pctx.errcode = retval;
                fix_problem(ctx, PR_3_CANT_RECONNECT, &pctx);
                return 1;
        }
-       adjust_inode_count(ctx, inode, +1);
+       adjust_inode_count(ctx, ino, +1);
 
        return 0;
 }
index 1e26d60..e265c5b 100644 (file)
@@ -413,6 +413,17 @@ static const struct e2fsck_problem problem_table[] = {
          "@f contains large files, but lacks LARGE_FILE flag in @S.\n",
          PROMPT_FIX, 0 },
          
+       /* Imagic flag set on an inode when filesystem doesn't support it */
+       { PR_1_SET_IMAGIC,
+         "@i %i has imagic flag set.  ",
+         PROMPT_CLEAR, 0 },
+
+       /* Immutable flag set on a device or socket inode */
+       { PR_1_SET_IMMUTABLE,
+         "Special (device/socket/fifo) @i %i has immutable flag set.  ",
+         PROMPT_CLEAR, 0 },
+                 
+
        /* Pass 1b errors */
 
        /* Pass 1B: Rescan for duplicate/bad blocks */
index 5d6b6e7..9aa2cc9 100644 (file)
@@ -236,6 +236,12 @@ struct problem_context {
 /* Filesystem contains large files, but has no such flag in sb */
 #define PR_1_FEATURE_LARGE_FILES       0x01002E
 
+/* Imagic flag set on an inode when filesystem doesn't support it */
+#define PR_1_SET_IMAGIC                        0x01002F
+
+/* Immutable flag set on a device or socket inode */
+#define PR_1_SET_IMMUTABLE             0x010030
+       
 /*
  * Pass 1b errors
  */
index 8c07374..74320b8 100644 (file)
@@ -314,3 +314,31 @@ blk_t get_backup_sb(ext2_filsys fs)
        return fs->super->s_blocks_per_group + 1;
 }
 
+/*
+ * Given a mode, return the ext2 file type
+ */
+int ext2_file_type(unsigned int mode)
+{
+       if (LINUX_S_ISREG(mode))
+               return EXT2_FT_REG_FILE;
+
+       if (LINUX_S_ISDIR(mode))
+               return EXT2_FT_DIR;
+       
+       if (LINUX_S_ISCHR(mode))
+               return EXT2_FT_CHRDEV;
+       
+       if (LINUX_S_ISBLK(mode))
+               return EXT2_FT_BLKDEV;
+       
+       if (LINUX_S_ISLNK(mode))
+               return EXT2_FT_SYMLINK;
+
+       if (LINUX_S_ISFIFO(mode))
+               return EXT2_FT_FIFO;
+       
+       if (LINUX_S_ISSOCK(mode))
+               return EXT2_FT_SOCK;
+       
+       return 0;
+}
index c49b15d..cfe1d60 100644 (file)
@@ -1,3 +1,8 @@
+1999-11-10    <tytso@valinux.com>
+
+       * mke2fs.8.in: Update manual page so that the sparse_option
+               filesystem option is properly named.
+
 1999-11-04    <tytso@valinux.com>
 
        * fsck.c (main): Move setting of the interactive flag to before
index 76ea4ee..1ce7069 100644 (file)
@@ -149,7 +149,7 @@ of desired inodes directly.
 .BI \-O " feature\fR[,...]"
 Create the filesystem with the listed set of features 
 (filesystem options).  The following features are supported: 
-.IR sparse ,
+.IR sparse_super ,
 which cause the filesystem to use sparse superblocks, and
 .IR filetype ,
 which will cause the filesystem to store file type information in