1 /* This package consists of 4 routines for handling the /etc/mtab file.
2 * The /etc/mtab file contains information about the root and mounted file
3 * systems as a series of lines, each one with exactly four fields separated
4 * by one space as follows:
6 * special mounted_on version rw_flag
9 * special is the name of the block special file
10 * mounted_on is the directory on which it is mounted
11 * version is either 1 or 2 for MINIX V1 and V2 file systems
12 * rw_flag is rw or ro for read/write or read only
14 * An example /etc/mtab:
21 * The four routines for handling /etc/mtab are as follows. They use two
22 * (hidden) internal buffers, mtab_in for input and mtab_out for output.
24 * load_mtab(&prog_name) - read /etc/mtab into mtab_in
25 * get_mtab_entry(&s1, &s2, &s3, &s4) - arrays that are filled in
27 * If load_mtab works, it returns 0. If it fails, it prints its own error
28 * message on stderr and returns -1. When get_mtab_entry
29 * runs out of entries to return, it sets the first pointer to NULL and returns
33 #include <sys/types.h>
35 #include <minix/minlib.h>
43 #define BUF_SIZE 512 /* size of the /etc/mtab buffer */
45 char *etc_mtab
= "/etc/mtab"; /* name of the /etc/mtab file */
46 static char mtab_in
[BUF_SIZE
+1]; /* holds /etc/mtab when it is read in */
47 static char *iptr
= mtab_in
; /* pointer to next line to feed out. */
49 int load_mtab(char *prog_name
);
50 int get_mtab_entry(char dev
[PATH_MAX
], char mount_point
[PATH_MAX
],
51 char type
[MNTNAMELEN
], char flags
[MNTFLAGLEN
]);
52 static void err(char *prog_name
, char *str
);
55 int load_mtab(prog_name
)
58 /* Read in /etc/mtab and store it in /etc/mtab. */
64 fd
= open(etc_mtab
, O_RDONLY
);
66 err(prog_name
, ": cannot open ");
70 /* File opened. Read it in. */
71 n
= read(fd
, mtab_in
, BUF_SIZE
);
74 err(prog_name
, ": cannot read ");
78 /* Some nut has mounted 50 file systems or something like that. */
80 std_err(": file too large: ");
92 int get_mtab_entry(char dev
[PATH_MAX
], char mount_point
[PATH_MAX
],
93 char type
[MNTNAMELEN
], char flags
[MNTFLAGLEN
])
95 /* Return the next entry from mtab_in. */
99 if (iptr
>= &mtab_in
[BUF_SIZE
]) {
104 r
= sscanf(iptr
, "%s on %s type %s (%[^)]s\n",
105 dev
, mount_point
, type
, flags
);
111 iptr
= strchr(iptr
, '\n'); /* Find end of line */
112 if (iptr
!= NULL
) iptr
++; /* Move to next line */
119 char *prog_name
, *str
;