1 /* printroot - print root device on stdout Author: Bruce Evans */
3 /* This program figures out what the root device is by doing a stat on it, and
4 * then searching /dev until it finds an entry with the same device number.
5 * A typical use (probably the only use) is in /etc/rc for initializing
6 * /etc/mtab, as follows:
8 * /usr/bin/printroot >/etc/mtab
10 * 9 Dec 1989 - clean up for 1.5 - full prototypes (BDE)
11 * 15 Oct 1989 - avoid ACK cc bugs (BDE):
12 * - sizeof "foo" is 2 (from wrong type char *) instead of 4
13 * - char foo[10] = "bar"; allocates 4 bytes instead of 10
14 * 1 Oct 1989 - Minor changes by Andy Tanenbaum
15 * 5 Oct 1992 - Use readdir (kjb)
16 * 26 Nov 1994 - Flag -r: print just the root device (kjb)
19 #include <sys/types.h>
26 #include <minix/minlib.h>
29 static char DEV_PATH
[] = "/dev/"; /* #define would step on sizeof bug */
30 static char MESSAGE
[] = " / "; /* ditto */
31 #define UNKNOWN_DEV "/dev/unknown"
35 _PROTOTYPE(int main
, (int argc
, char **argv
));
36 _PROTOTYPE(void done
, (char *name
, int status
));
44 struct stat filestat
, rootstat
;
45 static char namebuf
[sizeof DEV_PATH
+ NAME_MAX
];
47 rflag
= (argc
> 1 && strcmp(argv
[1], "-r") == 0);
49 if (stat(ROOT
, &rootstat
) == 0 && (dp
= opendir(DEV_PATH
)) != (DIR *) NULL
) {
50 while ((entry
= readdir(dp
)) != (struct dirent
*) NULL
) {
51 strcpy(namebuf
, DEV_PATH
);
52 strcat(namebuf
, entry
->d_name
);
53 if (stat(namebuf
, &filestat
) != 0) continue;
54 if ((filestat
.st_mode
& S_IFMT
) != S_IFBLK
) continue;
55 if (filestat
.st_rdev
!= rootstat
.st_dev
) continue;
60 return(0); /* not reached */
63 void done(name
, status
)
69 write(1, name
, strlen(name
));
74 write(1, MESSAGE
, sizeof MESSAGE
- 1);
75 v
= fsversion(name
, "printroot"); /* determine file system version */
77 write(1, "1 rw\n", 5);
79 write(1, "2 rw\n", 5);
81 write(1, "3 rw\n", 5);
83 write(1, "0 rw\n", 5);