source: trunk/minix/commands/simple/mknod.c@ 11

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

Minix 3.1.2a

File size: 1.4 KB
Line 
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
16int main(argc, argv)
17int argc;
18char *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
48void badcomm()
49{
50 std_err("Usage: mknod name b/c/p [major minor]\n");
51 exit(1);
52}
53
54void badfifo()
55{
56 std_err("Usage: mknod name p\n");
57 exit(1);
58}
59
60void badchar()
61{
62 std_err("Usage: mknod name c major minor\n");
63 exit(1);
64}
65
66void badblock()
67{
68 std_err("Usage: mknod name b major minor\n");
69 exit(1);
70}
Note: See TracBrowser for help on using the repository browser.