1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#define FOR_mknod
31#include "toys.h"
32
33GLOBALS(
34 char *Z, *m;
35)
36
37void mknod_main(void)
38{
39 mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
40 int major=0, minor=0, type;
41 int mode = TT.m ? string_to_mode(TT.m, 0777) : 0660;
42
43 type = stridx("pcub", *toys.optargs[1]);
44 if (type == -1) perror_exit("bad type '%c'", *toys.optargs[1]);
45 if (type) {
46 if (toys.optc != 4) perror_exit("need major/minor");
47
48 major = atoi(toys.optargs[2]);
49 minor = atoi(toys.optargs[3]);
50 }
51
52 if (toys.optflags & FLAG_Z)
53 if (-1 == lsm_set_create(TT.Z))
54 perror_exit("-Z '%s' failed", TT.Z);
55 if (mknod(*toys.optargs, mode|modes[type], dev_makedev(major, minor)))
56 perror_exit_raw(*toys.optargs);
57}
58