1 | /* mknod - build a special file Author: Andy Tanenbaum */
|
---|
2 |
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <unistd.h>
|
---|
6 | #include <minix/minlib.h>
|
---|
7 | #include <errno.h>
|
---|
8 | #include <stdio.h>
|
---|
9 |
|
---|
10 | _PROTOTYPE(int main, (int argc, char *argv []));
|
---|
11 | _PROTOTYPE(void badcomm, (void));
|
---|
12 | _PROTOTYPE(void badfifo, (void));
|
---|
13 | _PROTOTYPE(void badchar, (void));
|
---|
14 | _PROTOTYPE(void badblock, (void));
|
---|
15 |
|
---|
16 | int main(argc, argv)
|
---|
17 | int argc;
|
---|
18 | char *argv[];
|
---|
19 | {
|
---|
20 | /* Mknod name b/c major minor makes a node. */
|
---|
21 |
|
---|
22 | int mode, major, minor, dev;
|
---|
23 |
|
---|
24 | if (argc < 3) badcomm();
|
---|
25 | if (*argv[2] != 'b' && *argv[2] != 'c' && *argv[2] != 'p') badcomm();
|
---|
26 | if (*argv[2] == 'p' && argc != 3) badfifo();
|
---|
27 | if (*argv[2] == 'c' && argc != 5) badchar();
|
---|
28 | if (*argv[2] == 'b' && argc != 5) badblock();
|
---|
29 | if (*argv[2] == 'p') {
|
---|
30 | mode = 010666;
|
---|
31 | dev = 0;
|
---|
32 | } else {
|
---|
33 | mode = (*argv[2] == 'b' ? 060666 : 020666);
|
---|
34 | major = atoi(argv[3]);
|
---|
35 | minor = atoi(argv[4]);
|
---|
36 | if (major - 1 > 0xFE || minor > 0xFF) badcomm();
|
---|
37 | dev = (major << 8) | minor;
|
---|
38 | }
|
---|
39 | if (mknod(argv[1], mode, dev) < 0) {
|
---|
40 | int err = errno;
|
---|
41 | std_err("mknod: ");
|
---|
42 | errno = err;
|
---|
43 | perror(argv[1]);
|
---|
44 | }
|
---|
45 | return(0);
|
---|
46 | }
|
---|
47 |
|
---|
48 | void badcomm()
|
---|
49 | {
|
---|
50 | std_err("Usage: mknod name b/c/p [major minor]\n");
|
---|
51 | exit(1);
|
---|
52 | }
|
---|
53 |
|
---|
54 | void badfifo()
|
---|
55 | {
|
---|
56 | std_err("Usage: mknod name p\n");
|
---|
57 | exit(1);
|
---|
58 | }
|
---|
59 |
|
---|
60 | void badchar()
|
---|
61 | {
|
---|
62 | std_err("Usage: mknod name c major minor\n");
|
---|
63 | exit(1);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void badblock()
|
---|
67 | {
|
---|
68 | std_err("Usage: mknod name b major minor\n");
|
---|
69 | exit(1);
|
---|
70 | }
|
---|