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.
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>
20 #include "mfs/const.h"
22 #include "mfs/super.h"
24 static struct super_block super
, *sp
;
26 int fsversion(dev
, prog
)
31 if ((fd
= open(dev
, O_RDONLY
)) < 0) {
33 std_err(" cannot open ");
38 lseek(fd
, (off_t
) SUPER_BLOCK_BYTES
, SEEK_SET
); /* skip boot block */
39 if (read(fd
, (char *) &super
, (unsigned) SUPER_SIZE
) != SUPER_SIZE
) {
41 std_err(" cannot read super block on ");
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);