4 * Copyright (C) 2001 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
17 #include <sys/types.h>
28 struct fs_magic type_array[] = {
29 { "ext2", 1024+56, 2, "\123\357" },
30 { "minix", 1040, 2, "\177\023" },
31 { "minix", 1040, 2, "\217\023" },
32 { "minix", 1040, 2, "\150\044" },
33 { "minix", 1040, 2, "\170\044" },
34 { "xfs", 0, 4, "XFSB" },
38 const char *identify_fs(const char *fs_name)
44 fd = open(fs_name, O_RDONLY);
47 if (lseek(fd, 0, SEEK_SET) < 0)
49 if (read(fd, buf, sizeof(buf)) != sizeof(buf))
51 for (p = type_array; p->fs_name; p++) {
52 if (memcmp(p->magic, buf+p->offset, p->len) == 0)
59 int main(int argc, char **argv)
64 fprintf(stderr, "Usage: %s device\n", argv[0]);
67 type = identify_fs(argv[1]);
68 printf("%s is a %s filesystem\n", argv[1], type);