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.
6 * 9 Dec 1989 - clean up for 1.5 - full prototypes (BDE)
7 * 15 Oct 1989 - avoid ACK cc bugs (BDE):
8 * - sizeof "foo" is 2 (from wrong type char *) instead of 4
9 * - char foo[10] = "bar"; allocates 4 bytes instead of 10
10 * 1 Oct 1989 - Minor changes by Andy Tanenbaum
11 * 5 Oct 1992 - Use readdir (kjb)
12 * 26 Nov 1994 - Flag -r: print just the root device (kjb)
15 #include <sys/types.h>
22 #include <minix/minlib.h>
25 static char DEV_PATH
[] = "/dev/"; /* #define would step on sizeof bug */
26 static char MESSAGE
[] = " / "; /* ditto */
27 #define UNKNOWN_DEV "/dev/unknown"
31 int main(int argc
, char **argv
);
32 void done(char *name
, int status
);
40 struct stat filestat
, rootstat
;
41 static char namebuf
[sizeof DEV_PATH
+ NAME_MAX
];
43 rflag
= (argc
> 1 && strcmp(argv
[1], "-r") == 0);
45 if (stat(ROOT
, &rootstat
) == 0 && (dp
= opendir(DEV_PATH
)) != (DIR *) NULL
) {
46 while ((entry
= readdir(dp
)) != (struct dirent
*) NULL
) {
47 strcpy(namebuf
, DEV_PATH
);
48 strcat(namebuf
, entry
->d_name
);
49 if (stat(namebuf
, &filestat
) != 0) continue;
50 if ((filestat
.st_mode
& S_IFMT
) != S_IFBLK
) continue;
51 if (filestat
.st_rdev
!= rootstat
.st_dev
) continue;
56 return(0); /* not reached */
59 void done(name
, status
)
65 write(1, name
, strlen(name
));
70 write(1, MESSAGE
, sizeof MESSAGE
- 1);
71 v
= fsversion(name
, "printroot"); /* determine file system version */
73 case FSVERSION_MFS1
: write(1, "1 rw\n", 5); break;
74 case FSVERSION_MFS2
: write(1, "2 rw\n", 5); break;
75 case FSVERSION_MFS3
: write(1, "3 rw\n", 5); break;
76 case FSVERSION_EXT2
: write(1, "ext2 rw\n", 8); break;
77 default: write(1, "0 rw\n", 5); break;