]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsprogs-SLES10--m-support.patch
authorAndreas Dilger <adilger@sun.com>
Sat, 2 Feb 2008 08:30:13 +0000 (01:30 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 11 Feb 2008 02:58:12 +0000 (21:58 -0500)
SLES9 patch to add "fsck -m" option to skip checking mounted filesystems.
This isn't in their upstream e2fsprogs, since SLES uses the fsck in
util-linux, but is needed for compatibility.

misc/fsck.8.in
misc/fsck.c

index aa5fd05fc4b2a1343ceda638f097b006813a6032..068ea26b578105c4d348b8e9e2bf87c9553a922c 100644 (file)
@@ -180,6 +180,10 @@ option,
 will use the specified filesystem type.  If this type is not
 available, then the default file system type (currently ext2) is used. 
 .TP
+.B \-m
+Do not check mounted filesystems and return an exit code of 0
+for mounted filesystems.
+.TP
 .B \-A
 Walk through the
 .I /etc/fstab
index 5cf1a1c854279b8da316fe8b3680832e4f953606..804081daed02fa23a9c46918a39d39ede3ba478d 100644 (file)
@@ -103,6 +103,7 @@ int noexecute = 0;
 int serialize = 0;
 int skip_root = 0;
 int like_mount = 0;
+int ignore_mounted = 0;
 int notitle = 0;
 int parallel_root = 0;
 int progress = 0;
@@ -790,7 +791,7 @@ static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
 #if 0
                printf("Adding %s to list (type %d).\n", s, cmp->type[num]);
 #endif
-               cmp->list[num++] = string_copy(s);
+               cmp->list[num++] = string_copy(s);
                s = strtok(NULL, ",");
        }
        free(list);
@@ -816,7 +817,7 @@ static int opt_in_list(char *opt, char *optlist)
                }
                s = strtok(NULL, ",");
        }
-        free(list);
+       free(list);
        return 0;
 }
 
@@ -852,6 +853,56 @@ static int fs_match(struct fs_info *fs, struct fs_type_compile *cmp)
        return (cmp->negate ? !ret : ret);
 }
 
+/* Check to see whether a filesystem is already mounted */
+static int is_mounted(struct fs_info *fs)
+{
+       struct stat st_buf;
+       dev_t fs_rdev;
+       char *testdir;
+       int retval = 0;
+
+       if (!fs->mountpt) {
+               /*
+                * We have already read /proc/mounts
+                * so any device without a mountpoint
+                * is indeed not mounted.
+                */
+               return 0;
+       }
+
+       if (!strcmp(fs->mountpt,"/")) {
+               /* Root should be always mounted */
+               return 1;
+       }
+
+       if (stat(fs->mountpt, &st_buf) < 0)
+               return 0;
+
+       if (!S_ISDIR(st_buf.st_mode)) {
+               /* This is not a directory, cannot be mounted */
+               return 0;
+       }
+
+       fs_rdev = st_buf.st_dev;
+
+       /* Compare with the upper directory */
+       testdir = malloc(strlen(fs->mountpt) + 4);
+       strcpy(testdir,fs->mountpt);
+       if (fs->mountpt[strlen(fs->mountpt) - 1] == '/')
+               strcat(testdir,"..");
+       else
+               strcat(testdir,"/..");
+
+       if (stat(testdir, &st_buf) == 0) {
+               if (st_buf.st_dev != fs_rdev) {
+                       retval = 1;
+               }
+       }
+       free(testdir);
+
+       return retval;
+}
+
 /* Check if we should ignore this filesystem. */
 static int ignore(struct fs_info *fs)
 {
@@ -1009,6 +1060,15 @@ static int check_all(NOARGS)
                                not_done_yet++;
                                continue;
                        }
+                       if (ignore_mounted) {
+                               /*
+                                * Ignore mounted devices.
+                                */
+                               if (is_mounted(fs)) {
+                                       fs->flags |= FLAG_DONE;
+                                       continue;
+                               }
+                       }
                        /*
                         * If a filesystem on a particular device has
                         * already been spawned, then we need to defer
@@ -1186,6 +1246,9 @@ static void PRS(int argc, char *argv[])
                        case 'P':
                                parallel_root++;
                                break;
+                       case 'm':
+                               ignore_mounted++;
+                               break;
                        case 's':
                                serialize++;
                                break;
@@ -1261,6 +1324,10 @@ int main(int argc, char *argv[])
                fstab = _PATH_MNTTAB;
        load_fs_info(fstab);
 
+       /* Load info from /proc/mounts, too */
+       if (ignore_mounted)
+               load_fs_info("/proc/mounts");
+
        /* Update our search path to include uncommon directories. */
        if (oldpath) {
                fsck_path = malloc (strlen (fsck_prefix_path) + 1 +
@@ -1303,6 +1370,14 @@ int main(int argc, char *argv[])
                        if (!fs)
                                continue;
                }
+               if (ignore_mounted) {
+                       /*
+                        * Ignore mounted devices.
+                        */
+                       if (is_mounted(fs)) {
+                               continue;
+                       }
+               }
                fsck_device(fs, interactive);
                if (serialize ||
                    (max_running && (num_running >= max_running))) {