Added dev2name - translate (minor,major) device numbers, or (minor|major<<..)
device number, to /dev/* node name.
This commit is contained in:
parent
b343c18712
commit
da9b8e45f9
@ -66,6 +66,7 @@ ALL = \
|
|||||||
date \
|
date \
|
||||||
dd \
|
dd \
|
||||||
decomp16 \
|
decomp16 \
|
||||||
|
dev2name \
|
||||||
df \
|
df \
|
||||||
dhrystone \
|
dhrystone \
|
||||||
diff \
|
diff \
|
||||||
@ -313,6 +314,10 @@ decomp16: decomp16.c
|
|||||||
$(CCLD) -o $@ $?
|
$(CCLD) -o $@ $?
|
||||||
@install -S 4kw $@
|
@install -S 4kw $@
|
||||||
|
|
||||||
|
dev2name: dev2name.c
|
||||||
|
$(CCLD) -o $@ $?
|
||||||
|
@install -S 4kw $@
|
||||||
|
|
||||||
df: df.c
|
df: df.c
|
||||||
$(CCLD) -I$(SYS) -o $@ $?
|
$(CCLD) -I$(SYS) -o $@ $?
|
||||||
@install -S 4kw $@
|
@install -S 4kw $@
|
||||||
@ -880,6 +885,7 @@ install: \
|
|||||||
/usr/bin/date \
|
/usr/bin/date \
|
||||||
/usr/bin/dd \
|
/usr/bin/dd \
|
||||||
/usr/bin/decomp16 \
|
/usr/bin/decomp16 \
|
||||||
|
/bin/dev2name \
|
||||||
/usr/bin/df \
|
/usr/bin/df \
|
||||||
/usr/bin/dhrystone \
|
/usr/bin/dhrystone \
|
||||||
/usr/bin/diff \
|
/usr/bin/diff \
|
||||||
@ -1139,6 +1145,9 @@ install: \
|
|||||||
/usr/bin/dd: dd
|
/usr/bin/dd: dd
|
||||||
install -cs -o bin $? $@
|
install -cs -o bin $? $@
|
||||||
|
|
||||||
|
/bin/dev2name: dev2name
|
||||||
|
install -cs -o bin $? $@
|
||||||
|
|
||||||
/usr/bin/decomp16: decomp16
|
/usr/bin/decomp16: decomp16
|
||||||
install -cs -o bin $? $@
|
install -cs -o bin $? $@
|
||||||
|
|
||||||
|
54
commands/simple/dev2name.c
Normal file
54
commands/simple/dev2name.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
/* Translate internal FS device number to a /dev/ name. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <minix/config.h>
|
||||||
|
#include <minix/const.h>
|
||||||
|
|
||||||
|
#define PATH_DEV "/dev"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
DIR *dev;
|
||||||
|
struct dirent *e;
|
||||||
|
int dev_n;
|
||||||
|
if(argc <= 1 || argc > 3) {
|
||||||
|
fprintf(stderr, "Usage: \n"
|
||||||
|
"%s <major> <minor>\n"
|
||||||
|
"%s <devicenumber>\n", argv[0], argv[0]);
|
||||||
|
return 1;
|
||||||
|
} else if(argc == 2) dev_n = atoi(argv[1]);
|
||||||
|
else if(argc == 3) dev_n = (atoi(argv[1]) << MAJOR) | atoi(argv[2]);
|
||||||
|
|
||||||
|
if(chdir(PATH_DEV) < 0) {
|
||||||
|
perror(PATH_DEV " chdir");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(dev=opendir("."))) {
|
||||||
|
perror(". in " PATH_DEV);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while((e=readdir(dev))) {
|
||||||
|
struct stat st;
|
||||||
|
if(stat(e->d_name, &st) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if((st.st_mode & (S_IFBLK | S_IFCHR)) && dev_n == st.st_rdev) {
|
||||||
|
printf("%s/%s\n", PATH_DEV, e->d_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user