Whamcloud - gitweb
Changed fsck to support filesystems types in /etc/fstab of the form
authorTheodore Ts'o <tytso@mit.edu>
Sun, 3 Feb 2002 05:08:52 +0000 (00:08 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 3 Feb 2002 05:08:52 +0000 (00:08 -0500)
"ext3,ext2", etc.

Added support for only searching for a specified list of filesystems.
Also add support for identifying reiserfs filesystems.

misc/ChangeLog
misc/Makefile.in
misc/fsck.c
misc/fsck.h
misc/fstype.c

index 77de737..ae10356 100644 (file)
@@ -1,3 +1,12 @@
+2002-02-03  Theodore Tso  <tytso@valinux.com>
+
+       * fsck.c (interpret_type): Allow filesystems types of the form
+               "ext3,ext2", etc.
+
+       * fstype.c (identify_fs): Add support for only searching for a
+               specified list of filesystems.  Also add support for
+               identifying reiserfs filesystems.
+
 2002-01-29  Theodore Tso  <tytso@valinux.com>
 
        * fsck.c: Allow the number of outstanding processes fs-specific
index d9c9ad0..e922ffa 100644 (file)
@@ -64,6 +64,10 @@ e2image: $(E2IMAGE_OBJS) $(DEPLIBS)
 base_device: base_device.c
        $(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $< -DDEBUG -o $@
 
+fstype: fstype.c
+       $(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -DTEST_PROGRAM $(srcdir)/fstype.c \
+               get_device_by_label.o $(LIBUUID) $(LIBS) -o fstype
+
 check:: base_device
        ./base_device < $(srcdir)/base_device.tst > base_device.out
        cmp $(srcdir)/base_device.tst base_device.out
index 743200b..d4c1d66 100644 (file)
@@ -244,10 +244,11 @@ static void interpret_type(struct fs_info *fs)
 {
        const char      *type;
        
-       if (strcmp(fs->type, "auto") == 0) {
+       if (strcmp(fs->type, "auto") == 0 ||
+           (strchr(fs->type, ',') != 0)) {
                if (fs && strchr(fs->device, '='))
                        fs->device = interpret_device(fs->device);
-               type = identify_fs(fs->device);
+               type = identify_fs(fs->device, fs->type);
                if (type) {
                        free(fs->type);
                        fs->type = string_copy(type);
index 71eb011..a4baaae 100644 (file)
@@ -61,4 +61,4 @@ struct fsck_instance {
 
 extern char *base_device(char *device);
 extern char *string_copy(const char *s);
-extern const char *identify_fs(const char *fs_name);
+extern const char *identify_fs(const char *fs_name, const char *fs_types);
index 8f12738..783ef65 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -25,8 +26,23 @@ struct fs_magic {
        const char      *magic;
 };
 
+#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs"
+#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
+#define REISERFS_DISK_OFFSET_IN_BYTES ((64 * 1024) + 52)
+/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */
+#define REISERFS_OLD_DISK_OFFSET_IN_BYTES ((8 * 1024) + 52)
+
 struct fs_magic type_array[] = {
        { "ext2", 1024+56, 2, "\123\357" },
+       { "ext3", 1024+56, 2, "\123\357" },
+       { "reiserfs", REISERFS_DISK_OFFSET_IN_BYTES, 9,
+                 REISER2FS_SUPER_MAGIC_STRING },
+       { "reiserfs", REISERFS_DISK_OFFSET_IN_BYTES, 8,
+                 REISERFS_SUPER_MAGIC_STRING },
+       { "reiserfs", REISERFS_OLD_DISK_OFFSET_IN_BYTES, 9,
+                 REISER2FS_SUPER_MAGIC_STRING },
+       { "reiserfs", REISERFS_OLD_DISK_OFFSET_IN_BYTES, 8,
+                 REISERFS_SUPER_MAGIC_STRING },
        { "minix", 1040, 2, "\177\023" },
        { "minix", 1040, 2, "\217\023" },
        { "minix", 1040, 2, "\150\044" },
@@ -35,9 +51,10 @@ struct fs_magic type_array[] = {
        { 0, 0, 0, 0 }
 };
 
-const char *identify_fs(const char *fs_name)
+const char *identify_fs(const char *fs_name, const char *fs_types)
 {
-       char    buf[2048];
+       char    buf[73728], *s;
+       const char *t;
        struct fs_magic *p;
        int     fd;
 
@@ -48,9 +65,26 @@ const char *identify_fs(const char *fs_name)
                return NULL;
        if (read(fd, buf, sizeof(buf)) != sizeof(buf))
                return NULL;
-       for (p = type_array; p->fs_name; p++) {
-               if (memcmp(p->magic, buf+p->offset, p->len) == 0)
-                       return p->fs_name;
+       close(fd);
+       if (!fs_types || !strcmp(fs_types, "auto")) {
+               for (p = type_array; p->fs_name; p++) {
+                       if (memcmp(p->magic, buf+p->offset, p->len) == 0)
+                               return p->fs_name;
+               }
+       } else {
+               s = string_copy(fs_types);
+               for (t = strtok(s, ","); t; t = strtok(NULL, ",")) {
+                       for (p = type_array; p->fs_name; p++) {
+                               if (strcmp(p->fs_name, t))
+                                       continue;
+                               if (memcmp(p->magic, buf+p->offset,
+                                          p->len) == 0) {
+                                       free(s);
+                                       return p->fs_name;
+                               }
+                       }
+               }
+               free(s);
        }
        return NULL;
 }
@@ -60,15 +94,17 @@ int main(int argc, char **argv)
 {
        const char      *type;
        
-       if (argc != 2) {
-               fprintf(stderr, "Usage: %s device\n", argv[0]);
+       if (argc < 2 || argc > 3) {
+               fprintf(stderr, "Usage: %s [type list] device\n", argv[0]);
                exit(1);
        }
-       type = identify_fs(argv[1]);
-       printf("%s is a %s filesystem\n", argv[1], type);
+       if (argc == 2) {
+               type = identify_fs(argv[1], NULL);
+               printf("%s is a %s filesystem\n", argv[1], type);
+       } else {
+               type = identify_fs(argv[2],argv[1]);
+               printf("%s is a %s filesystem\n", argv[2], type);
+       }
        return (0);
 }
 #endif
-
-       
-