Whamcloud - gitweb
mke2fs.c (zap_sector): Now takes a third argument, which is how
[tools/e2fsprogs.git] / misc / fsck.c
index 0f233e1..10cf39f 100644 (file)
@@ -106,16 +106,6 @@ const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
 char *fsck_path = 0;
 static int ignore(struct fs_info *);
 
-char *string_copy(const char *s)
-{
-       char    *ret;
-
-       ret = malloc(strlen(s)+1);
-       if (ret)
-               strcpy(ret, s);
-       return ret;
-}
-
 static char *skip_over_blank(char *cp)
 {
        while (*cp && isspace(*cp))
@@ -217,18 +207,11 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
  */
 static char *interpret_device(char *spec)
 {
-       char *dev = NULL;
-       
-       if (!strncmp(spec, "UUID=", 5))
-               dev = get_spec_by_uuid(spec+5);
-       else if (!strncmp(spec, "LABEL=", 6))
-               dev = get_spec_by_volume_label(spec+6);
-       else
-               return spec;
-       if (dev) {
-               free(spec);
-               return (dev);
-       }
+       char *dev = interpret_spec(spec);
+
+       if (dev)
+               return dev;
+
        /*
         * Check to see if this was because /proc/partitions isn't
         * found.
@@ -243,15 +226,36 @@ static char *interpret_device(char *spec)
         * Check to see if this is because we're not running as root
         */
        if (geteuid())
-               fprintf(stderr, "Must be root to scan for matching "
-                       "filesystems: %s\n", spec);
+               fprintf(stderr,
+                       "Must be root to scan for matching filesystems: %s\n",
+                       spec);
        else
-               fprintf(stderr, "Couldn't find matching filesystem: %s\n", 
+               fprintf(stderr, "Couldn't find matching filesystem: %s\n",
                        spec);
        exit(EXIT_ERROR);
 }
 
 /*
+ * Interpret filesystem auto type if necessary
+ */
+static void interpret_type(struct fs_info *fs)
+{
+       const char      *type;
+       
+       if (strcmp(fs->type, "auto") == 0) {
+               type = identify_fs(fs->device);
+               if (type) {
+                       free(fs->type);
+                       fs->type = string_copy(type);
+               } else
+                       fprintf(stderr, _("Could not determine "
+                                         "filesystem type for %s\n"),
+                               fs->device);
+       }
+}
+
+
+/*
  * Load the filesystem database from /etc/fstab
  */
 static void load_fs_info(const char *filename)
@@ -598,6 +602,7 @@ static void fsck_device(char *device, int interactive)
 
        if ((fsent = lookup(device))) {
                device = fsent->device;
+               interpret_type(fsent);
                if (!type)
                        type = fsent->type;
        }
@@ -627,8 +632,8 @@ struct fs_type_compile {
 #define FS_TYPE_NEGOPT 2
 
 static const char *fs_type_syntax_error =
-_("Either all or none of the filesystem types passed to -t must be prefixed\n"
-  "with 'no' or '!'.\n");
+N_("Either all or none of the filesystem types passed to -t must be prefixed\n"
+   "with 'no' or '!'.\n");
 
 static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
 {
@@ -683,7 +688,7 @@ static void compile_fs_type(char *fs_type, struct fs_type_compile *cmp)
                        }
                        if ((negate && !cmp->negate) ||
                            (!negate && cmp->negate)) {
-                               fprintf(stderr, fs_type_syntax_error);
+                               fprintf(stderr, _(fs_type_syntax_error));
                                exit(EXIT_USAGE);
                        }
                }
@@ -764,6 +769,8 @@ static int ignore(struct fs_info *fs)
        if (fs->passno == 0)
                return 1;
 
+       interpret_type(fs);
+
        /*
         * If a specific fstype is specified, and it doesn't match,
         * ignore it.
@@ -821,7 +828,7 @@ static int device_already_active(char *device)
        if (!base) 
                return (instance_list != 0);
        for (inst = instance_list; inst; inst = inst->next) {
-               if (!strcmp(base, inst->base_device)) {
+               if (!inst->base_device || !strcmp(base, inst->base_device)) {
                        free(base);
                        return 1;
                }
@@ -851,7 +858,8 @@ static int check_all(NOARGS)
        for (fs = filesys_info; fs; fs = fs->next) {
                if (ignore(fs))
                        fs->flags |= FLAG_DONE;
-               fs->device = interpret_device(fs->device);
+               else
+                       fs->device = interpret_device(fs->device);
        }
                
        /*
@@ -1066,8 +1074,7 @@ int main(int argc, char *argv[])
        PRS(argc, argv);
 
        if (!notitle)
-               printf(_("Parallelizing fsck version %s (%s)\n"),
-                       E2FSPROGS_VERSION, E2FSPROGS_DATE);
+               printf("fsck %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
 
        fstab = getenv("FSTAB_FILE");
        if (!fstab)
@@ -1092,6 +1099,10 @@ int main(int argc, char *argv[])
        if (doall)
                return check_all();
 
+       if (num_devices == 0) {
+               fprintf(stderr, _("\nNo devices specified to be checked!\n"));
+               exit(EXIT_ERROR);
+       }
        for (i = 0 ; i < num_devices; i++) {
                fsck_device(devices[i], interactive);
                if (serialize) {