source: trunk/minix/lib/other/fsversion.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.2 KB
Line 
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:
4 *
5 * n = fsversion("/dev/hd1", "df");
6 *
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 */
10
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>
19
20#include "fs/const.h"
21#include "fs/type.h"
22#include "fs/super.h"
23
24static struct super_block super, *sp;
25
26int fsversion(dev, prog)
27char *dev, *prog;
28{
29 int fd;
30
31 if ((fd = open(dev, O_RDONLY)) < 0) {
32 std_err(prog);
33 std_err(" cannot open ");
34 perror(dev);
35 return(-1);
36 }
37
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);
45 }
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);
52}
Note: See TracBrowser for help on using the repository browser.