Added lance entry to drivers.conf.
[minix3-old.git] / commands / simple / dev2name.c
blob0e83357cdb1159fbdd8a4dff6baf00f2f6b87f8c
2 /* Translate internal FS device number to a /dev/ name. */
4 #include <stdio.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <dirent.h>
8 #include <unistd.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <minix/config.h>
13 #include <minix/const.h>
15 #define PATH_DEV "/dev"
17 int
18 main(int argc, char *argv[])
20 DIR *dev;
21 struct dirent *e;
22 int dev_n;
23 if(argc <= 1 || argc > 3) {
24 fprintf(stderr, "Usage: \n"
25 "%s <major> <minor>\n"
26 "%s <devicenumber>\n", argv[0], argv[0]);
27 return 1;
28 } else if(argc == 2) dev_n = atoi(argv[1]);
29 else if(argc == 3) dev_n = (atoi(argv[1]) << MAJOR) | atoi(argv[2]);
31 if(chdir(PATH_DEV) < 0) {
32 perror(PATH_DEV " chdir");
33 return 1;
36 if(!(dev=opendir("."))) {
37 perror(". in " PATH_DEV);
38 return 1;
41 while((e=readdir(dev))) {
42 struct stat st;
43 if(stat(e->d_name, &st) < 0) {
44 continue;
46 if((st.st_mode & (S_IFBLK | S_IFCHR)) && dev_n == st.st_rdev) {
47 printf("%s/%s\n", PATH_DEV, e->d_name);
48 return 0;
52 return 1;