. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / other / fsversion.c
blob3a0faa59f447611d3308e992e352d015f213d5e9
1 /* This procedure examines a file system and figures out whether it is
2 * version 1 or version 2. It returns the result as an int. If the
3 * file system is neither, it returns -1. A typical call is:
5 * n = fsversion("/dev/hd1", "df");
7 * The first argument is the special file for the file system.
8 * The second is the program name, which is used in error messages.
9 */
11 #include <sys/types.h>
12 #include <minix/config.h>
13 #include <minix/const.h>
14 #include <minix/minlib.h>
15 #include <minix/type.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include <stdio.h>
20 #include "mfs/const.h"
21 #include "mfs/type.h"
22 #include "mfs/super.h"
24 static struct super_block super, *sp;
26 int fsversion(dev, prog)
27 char *dev, *prog;
29 int fd;
31 if ((fd = open(dev, O_RDONLY)) < 0) {
32 std_err(prog);
33 std_err(" cannot open ");
34 perror(dev);
35 return(-1);
38 lseek(fd, (off_t) SUPER_BLOCK_BYTES, SEEK_SET); /* skip boot block */
39 if (read(fd, (char *) &super, (unsigned) SUPER_SIZE) != SUPER_SIZE) {
40 std_err(prog);
41 std_err(" cannot read super block on ");
42 perror(dev);
43 close(fd);
44 return(-1);
46 close(fd);
47 sp = &super;
48 if (sp->s_magic == SUPER_MAGIC) return(1);
49 if (sp->s_magic == SUPER_V2) return(2);
50 if (sp->s_magic == SUPER_V3) return(3);
51 return(-1);