Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/mknod.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1004 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1004 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <sys/stat.h> |
4 | |
5 | char *progname; |
6 | |
7 | static __noreturn usage(void) |
8 | { |
9 | fprintf(stderr, "Usage: %s name {b|c|p} major minor\n", progname); |
10 | exit(1); |
11 | } |
12 | |
13 | int main(int argc, char *argv[]) |
14 | { |
15 | char *name, *type, typec, *endp; |
16 | unsigned int major, minor; |
17 | mode_t mode; |
18 | dev_t dev; |
19 | |
20 | progname = *argv++; |
21 | |
22 | name = *argv++; |
23 | if (!name) |
24 | usage(); |
25 | |
26 | type = *argv++; |
27 | if (!type || !type[0] || type[1]) |
28 | usage(); |
29 | typec = type[0]; |
30 | |
31 | mode = 0; |
32 | switch (type[0]) { |
33 | case 'c': |
34 | mode = S_IFCHR; |
35 | break; |
36 | case 'b': |
37 | mode = S_IFBLK; |
38 | break; |
39 | case 'p': |
40 | mode = S_IFIFO; |
41 | break; |
42 | default: |
43 | usage(); |
44 | } |
45 | |
46 | if (mode == S_IFIFO) { |
47 | dev = 0; |
48 | } else { |
49 | if (!argv[0] || !argv[1]) |
50 | usage(); |
51 | |
52 | major = strtol(*argv++, &endp, 0); |
53 | if (*endp != '\0') |
54 | usage(); |
55 | minor = strtol(*argv++, &endp, 0); |
56 | if (*endp != '\0') |
57 | usage(); |
58 | dev = makedev(major, minor); |
59 | } |
60 | |
61 | if (*argv) |
62 | usage(); |
63 | |
64 | if (mknod(name, mode|0666, dev) == -1) { |
65 | perror("mknod"); |
66 | exit(1); |
67 | } |
68 | |
69 | exit(0); |
70 | } |