Mercurial > hg > toybox
annotate toys/pending/makedevs.c @ 1362:b9605ebd3af4 draft
Cleanup pass on makedevs. Need to test it before promoting.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 25 Jun 2014 06:26:17 -0500 |
parents | 41fc44c76ade |
children | d46baa9adb5f |
rev | line source |
---|---|
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
1 /* makedevs.c - Make ranges of device files. |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
2 * |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
3 * Copyright 2014 Bilal Qureshi <bilal.jmi@gmail.com> |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
4 * Copyright 2014 Kyungwan Han <asura321@gmail.com> |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
5 * |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
6 * No Standard |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
7 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
8 USE_MAKEDEVS(NEWTOY(makedevs, "<1>1d:", TOYFLAG_USR|TOYFLAG_BIN)) |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
9 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
10 config MAKEDEVS |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
11 bool "makedevs" |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
12 default n |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
13 help |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
14 usage: makedevs [-d device_table] rootdir |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
15 |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
16 Create a range of special files as specified in a device table. |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
17 |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
18 -d file containing device table (default reads from stdin) |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
19 |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
20 Each line of of the device table has the fields: |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
21 <name> <type> <mode> <uid> <gid> <major> <minor> <start> <increment> <count> |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
22 Where name is the file name, and type is one of the following: |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
23 |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
24 b Block device |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
25 c Character device |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
26 d Directory |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
27 f Regular file |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
28 p Named pipe (fifo) |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
29 |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
30 Other fields specify permissions, user and group id owning the file, |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
31 and additional fields for device special files. Use '-' for blank entries, |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
32 unspecified fields are treated as '-'. |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
33 */ |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
34 |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
35 #define FOR_makedevs |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
36 #include "toys.h" |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
37 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
38 GLOBALS( |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
39 char *fname; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
40 ) |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
41 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
42 void makedevs_main() |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
43 { |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
44 int value, fd = 0, line_no, i; |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
45 char *line = NULL; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
46 |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
47 // Open file and chdir, verbosely |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
48 xprintf("rootdir = %s\n", *toys.optargs); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
49 if (toys.optflags & FLAG_d && strcmp(TT.fname, "-")) { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
50 fd = xopen(TT.fname, O_RDONLY); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
51 xprintf("table = %s\n", TT.fname); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
52 } else xprintf("table = <stdin>"); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
53 xchdir(*toys.optargs); |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
54 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
55 for (line_no = 0; (line = get_line(fd)); free(line)) { |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
56 char type=0, str[64], user[64], group[64], *node = str, *ptr = line; |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
57 unsigned int mode = 0755, major = 0, minor = 0, cnt = 0, incr = 0, |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
58 st_val = 0; |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
59 uid_t uid; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
60 gid_t gid; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
61 struct stat st; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
62 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
63 line_no++; |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
64 while (isspace(*ptr)) ptr++; |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
65 if (!*ptr || *ptr == '#') continue; |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
66 |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
67 while (*ptr && !isspace(*ptr)) ptr++; |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
68 if (*ptr) *ptr++ = 0; |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
69 *user = *group = 0; |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
70 sscanf(ptr, "%c %o %63s %63s %u %u %u %u %u", &type, &mode, |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
71 user, group, &major, &minor, &st_val, &incr, &cnt); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
72 |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
73 // type order here needs to line up with actions[] order. |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
74 i = stridx("pcbdf", type); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
75 if (i == -1) { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
76 error_msg("line %d: bad type %c", line_no, type); |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
77 continue; |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
78 } else mode |= (mode_t[]){S_IFIFO, S_IFCHR, S_IFBLK, 0, 0}[i]; |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
79 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
80 if (*user) { |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
81 struct passwd *usr; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
82 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
83 if (!(usr = getpwnam(user)) && isdigit(*user)) { |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
84 sscanf(user, "%u", &value); |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
85 usr = xgetpwuid(value); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
86 } |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
87 if (!usr) error_exit("bad user '%s'", user); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
88 uid = usr->pw_uid; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
89 } else uid = getuid(); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
90 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
91 if (*group) { |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
92 struct group *grp; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
93 |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
94 if (!(grp = getgrnam(group)) && isdigit(*group)) { |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
95 sscanf (group, "%u", &value); |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
96 grp = getgrgid(value); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
97 } |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
98 if (!grp) error_exit("bad group '%s'", group); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
99 gid = grp->gr_gid; |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
100 } else gid = getgid(); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
101 |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
102 while (*node == '/') node++; // using relative path |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
103 if (type == 'd') { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
104 if (mkpathat(AT_FDCWD, node, mode, 3)) { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
105 perror_msg("can't create directory '%s'", node); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
106 continue; |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
107 } |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
108 } else if (type == 'f') { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
109 if (stat(node, &st) || !S_ISREG(st.st_mode)) { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
110 perror_msg("line %d: regular file '%s' does not exist", line_no, node); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
111 continue; |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
112 } |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
113 } else { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
114 if (cnt) --cnt; |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
115 for (i = 0; i <= cnt; i++) { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
116 sprintf(toybuf, cnt ? "%s%u" : "%s", node, st_val + i); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
117 if (mknod(toybuf, mode, makedev(major, minor + i*incr))) { |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
118 perror_msg("line %d: can't create node '%s'", line_no, toybuf); |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
119 continue; |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
120 } |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
121 } |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
122 } |
1362
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
123 if (chown(toybuf, uid, gid) || chmod(toybuf, mode)) |
b9605ebd3af4
Cleanup pass on makedevs. Need to test it before promoting.
Rob Landley <rob@landley.net>
parents:
1325
diff
changeset
|
124 perror_msg("line %d: can't chown/chmod '%s'", line_no, toybuf); |
1325
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
125 } |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
126 xclose(fd); |
41fc44c76ade
makedevs - making devices/nodes in a range. Supports reading the tabled entry from file.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
127 } |