From 5599c2fa871d455464d92336d40b80ea1c8560f5 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 3 Feb 2002 00:08:52 -0500 Subject: [PATCH] Changed fsck to support filesystems types in /etc/fstab of the form "ext3,ext2", etc. Added support for only searching for a specified list of filesystems. Also add support for identifying reiserfs filesystems. --- misc/ChangeLog | 9 +++++++++ misc/Makefile.in | 4 ++++ misc/fsck.c | 5 +++-- misc/fsck.h | 2 +- misc/fstype.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------------ 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index 77de737..ae10356 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,12 @@ +2002-02-03 Theodore Tso + + * 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 * fsck.c: Allow the number of outstanding processes fs-specific diff --git a/misc/Makefile.in b/misc/Makefile.in index d9c9ad0..e922ffa 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -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 diff --git a/misc/fsck.c b/misc/fsck.c index 743200b..d4c1d66 100644 --- a/misc/fsck.c +++ b/misc/fsck.c @@ -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); diff --git a/misc/fsck.h b/misc/fsck.h index 71eb011..a4baaae 100644 --- a/misc/fsck.h +++ b/misc/fsck.h @@ -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); diff --git a/misc/fstype.c b/misc/fstype.c index 8f12738..783ef65 100644 --- a/misc/fstype.c +++ b/misc/fstype.c @@ -10,6 +10,7 @@ */ #include +#include #if HAVE_UNISTD_H #include #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 - - - -- 1.8.3.1