source: trunk/minix/commands/simple/dev2name.c@ 15

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

Minix 3.1.2a

File size: 1000 bytes
RevLine 
[9]1
2/* Translate internal FS device number to a /dev/ name. */
3
4#include <stdio.h>
5#include <string.h>
6#include <stdlib.h>
7#include <dirent.h>
8#include <unistd.h>
9
10#include <sys/stat.h>
11#include <sys/types.h>
12#include <minix/config.h>
13#include <minix/const.h>
14
15#define PATH_DEV "/dev"
16
17int
18main(int argc, char *argv[])
19{
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]);
30
31 if(chdir(PATH_DEV) < 0) {
32 perror(PATH_DEV " chdir");
33 return 1;
34 }
35
36 if(!(dev=opendir("."))) {
37 perror(". in " PATH_DEV);
38 return 1;
39 }
40
41 while((e=readdir(dev))) {
42 struct stat st;
43 if(stat(e->d_name, &st) < 0) {
44 continue;
45 }
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;
49 }
50 }
51
52 return 1;
53}
54
Note: See TracBrowser for help on using the repository browser.