+2001-07-19 Theodore Tso <tytso@valinux.com>
+
+ * fstype.c (identify_fs): New file which looks at the superblock
+ of the filesystem to determines its type.
+
+ * fsck.c (fsck_device, ignore, interpret_type): Call identify_fs
+ if the type specified in /etc/fstab is "auto".
+
2001-06-23 Theodore Tso <tytso@valinux.com>
* Release of E2fsprogs 1.22
DUMPE2FS_OBJS= dumpe2fs.o
BADBLOCKS_OBJS= badblocks.o
E2IMAGE_OBJS= e2image.o
-FSCK_OBJS= fsck.o get_device_by_label.o base_device.o
+FSCK_OBJS= fsck.o get_device_by_label.o base_device.o fstype.o
SRCS= $(srcdir)/tune2fs.c $(srcdir)/mklost+found.c $(srcdir)/mke2fs.c \
$(srcdir)/chattr.c $(srcdir)/lsattr.c $(srcdir)/dumpe2fs.c \
$(srcdir)/badblocks.c $(srcdir)/fsck.c $(srcdir)/util.c \
- $(srcdir)/uuidgen.c
+ $(srcdir)/uuidgen.c $(srcdir)/fstype.c
LIBS= $(LIBEXT2FS) $(LIBCOM_ERR)
DEPLIBS= $(LIBEXT2FS) $(LIBCOM_ERR)
}
/*
+ * 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)
if ((fsent = lookup(device))) {
device = fsent->device;
+ interpret_type(fsent);
if (!type)
type = fsent->type;
}
if (fs->passno == 0)
return 1;
+ interpret_type(fs);
+
/*
* If a specific fstype is specified, and it doesn't match,
* ignore it.
--- /dev/null
+/*
+ * fstype.c
+ *
+ * Copyright (C) 2001 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <fcntl.h>
+#include <sys/types.h>
+
+struct fs_magic {
+ const char *fs_name;
+ int offset;
+ int len;
+ char *magic;
+};
+
+struct fs_magic type_array[] = {
+ { "ext2", 1024+56, 2, "\123\357" },
+ { "minix", 1040, 2, "\177\023" },
+ { "minix", 1040, 2, "\217\023" },
+ { "minix", 1040, 2, "\150\044" },
+ { "minix", 1040, 2, "\170\044" },
+ { "xfs", 0, 4, "XFSB" },
+ { 0, 0, 0, 0 }
+};
+
+const char *identify_fs(const char *fs_name)
+{
+ char buf[2048];
+ struct fs_magic *p;
+ int fd;
+
+ fd = open(fs_name, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ if (lseek(fd, 0, SEEK_SET) < 0)
+ 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;
+ }
+ return NULL;
+}
+
+#ifdef TEST_PROGRAM
+int main(int argc, char **argv)
+{
+ const char *type;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s device\n", argv[0]);
+ exit(1);
+ }
+ type = identify_fs(argv[1]);
+ printf("%s is a %s filesystem\n", argv[1], type);
+ return (0);
+}
+#endif
+
+
+