forget difference between big and small commands - obsolete with vm.
[minix.git] / commands / simple / mknod.c
blob223e2c1e68783c86ed28a0cdcd2835ac72b39d1f
1 /* mknod - build a special file Author: Andy Tanenbaum */
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>
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));
16 int main(argc, argv)
17 int argc;
18 char *argv[];
20 /* Mknod name b/c major minor makes a node. */
22 int mode, major, minor, dev;
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;
39 if (mknod(argv[1], mode, dev) < 0) {
40 int err = errno;
41 std_err("mknod: ");
42 errno = err;
43 perror(argv[1]);
45 return(0);
48 void badcomm()
50 std_err("Usage: mknod name b/c/p [major minor]\n");
51 exit(1);
54 void badfifo()
56 std_err("Usage: mknod name p\n");
57 exit(1);
60 void badchar()
62 std_err("Usage: mknod name c major minor\n");
63 exit(1);
66 void badblock()
68 std_err("Usage: mknod name b major minor\n");
69 exit(1);