diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-06-05 07:54:52 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-06-05 07:54:52 +0000 |
commit | 84b6264670619c8051f0c81a1ed7bb58e161df21 (patch) | |
tree | 80a5447e076ed386b5d7ae7c92540ee87b39f008 | |
parent | 58b118ae33e70bdd37872a2e68f09234c890eeac (diff) | |
download | busybox-w32-84b6264670619c8051f0c81a1ed7bb58e161df21.tar.gz busybox-w32-84b6264670619c8051f0c81a1ed7bb58e161df21.tar.bz2 busybox-w32-84b6264670619c8051f0c81a1ed7bb58e161df21.zip |
Device table support for makedevs, the previous behaviour can been
selected at configure time.
-rw-r--r-- | include/usage.h | 13 | ||||
-rw-r--r-- | miscutils/Config.in | 30 | ||||
-rw-r--r-- | miscutils/makedevs.c | 192 | ||||
-rw-r--r-- | patches/makdevs_table.diff | 294 |
4 files changed, 497 insertions, 32 deletions
diff --git a/include/usage.h b/include/usage.h index ce5624752..d41780d27 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1536,6 +1536,7 @@ | |||
1536 | #define lsmod_full_usage \ | 1536 | #define lsmod_full_usage \ |
1537 | "List the currently loaded kernel modules." | 1537 | "List the currently loaded kernel modules." |
1538 | 1538 | ||
1539 | #ifdef CONFIG_FEATURE_MAKEDEVS_LEAF | ||
1539 | #define makedevs_trivial_usage \ | 1540 | #define makedevs_trivial_usage \ |
1540 | "NAME TYPE MAJOR MINOR FIRST LAST [s]" | 1541 | "NAME TYPE MAJOR MINOR FIRST LAST [s]" |
1541 | #define makedevs_full_usage \ | 1542 | #define makedevs_full_usage \ |
@@ -1555,6 +1556,18 @@ | |||
1555 | "[creates ttyS2-ttyS63]\n" \ | 1556 | "[creates ttyS2-ttyS63]\n" \ |
1556 | "# makedevs /dev/hda b 3 0 0 8 s\n" \ | 1557 | "# makedevs /dev/hda b 3 0 0 8 s\n" \ |
1557 | "[creates hda,hda1-hda8]\n" | 1558 | "[creates hda,hda1-hda8]\n" |
1559 | #endif | ||
1560 | |||
1561 | #ifdef CONFIG_FEATURE_MAKEDEVS_TABLE | ||
1562 | #define makedevs_trivial_usage \ | ||
1563 | "[-r rootdir] [device_table]" | ||
1564 | #define makedevs_full_usage \ | ||
1565 | "Creates a batch of special files as specified in a device table\n" \ | ||
1566 | "The device table has one line per device group, each group is of\n" \ | ||
1567 | "the format\n" \ | ||
1568 | "\ttype mode user group major minor start increment count\n" \ | ||
1569 | "a '-' may be used for blank entries\n" | ||
1570 | #endif | ||
1558 | 1571 | ||
1559 | #ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK | 1572 | #ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK |
1560 | #define USAGE_MD5_SHA1_SUM_CHECK(a) a | 1573 | #define USAGE_MD5_SHA1_SUM_CHECK(a) a |
diff --git a/miscutils/Config.in b/miscutils/Config.in index 7e18c16a0..320f4c2b4 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -143,10 +143,32 @@ config CONFIG_MAKEDEVS | |||
143 | bool "makedevs" | 143 | bool "makedevs" |
144 | default n | 144 | default n |
145 | help | 145 | help |
146 | 'makedevs' is a utility used and created by the Linux Router Project. | 146 | 'makedevs' is a utility used to create a batch of devices with |
147 | It creates a large number of device special files (/dev devices) | 147 | one command. |
148 | rather quickly, and can be considerably faster then running mknod a | 148 | . |
149 | zillion times. | 149 | There are two choices for command line behaviour, the interface |
150 | as used by LEAF/Linux Router Project, or a device table file. | ||
151 | . | ||
152 | 'leaf' is traditionally what busybox follows, it allows multiple | ||
153 | devices of a particluar type to be created per command. | ||
154 | e.g. /dev/hda[0-9] | ||
155 | Device properties are passed as command line arguments. | ||
156 | . | ||
157 | 'table' reads device properties from a file or stdin, allowing | ||
158 | a batch of unrelated devices to be makde with one command. | ||
159 | User/group names are allowed as an alternative to uid/gid. | ||
160 | |||
161 | choice | ||
162 | prompt "Choose makedevs behaviour" | ||
163 | default CONFIG_FEATURE_MAKDEVS_TABLE | ||
164 | |||
165 | config CONFIG_FEATURE_MAKEDEVS_LEAF | ||
166 | bool "leaf" | ||
167 | |||
168 | config CONFIG_FEATURE_MAKEDEVS_TABLE | ||
169 | bool "table" | ||
170 | |||
171 | endchoice | ||
150 | 172 | ||
151 | config CONFIG_MT | 173 | config CONFIG_MT |
152 | bool "mt" | 174 | bool "mt" |
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 45498bb1d..57b2d6c70 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
@@ -1,20 +1,27 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
4 | * | ||
5 | * makedevs | ||
6 | * Make ranges of device files quickly. | ||
7 | * known bugs: can't deal with alpha ranges | ||
8 | */ | ||
9 | 2 | ||
3 | #include <sys/types.h> | ||
4 | |||
5 | #include <fcntl.h> | ||
6 | #include <getopt.h> | ||
10 | #include <stdio.h> | 7 | #include <stdio.h> |
11 | #include <stdlib.h> | 8 | #include <stdlib.h> |
12 | #include <string.h> | 9 | #include <string.h> |
13 | #include <fcntl.h> | 10 | #include <time.h> |
14 | #include <unistd.h> | 11 | #include <unistd.h> |
15 | #include <sys/types.h> | 12 | |
16 | #include "busybox.h" | 13 | #include "busybox.h" |
17 | 14 | ||
15 | #ifdef CONFIG_FEATURE_MAKEDEVS_LEAF | ||
16 | |||
17 | /* | ||
18 | * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
19 | * | ||
20 | * makedevs | ||
21 | * Make ranges of device files quickly. | ||
22 | * known bugs: can't deal with alpha ranges | ||
23 | */ | ||
24 | |||
18 | int makedevs_main(int argc, char **argv) | 25 | int makedevs_main(int argc, char **argv) |
19 | { | 26 | { |
20 | mode_t mode; | 27 | mode_t mode; |
@@ -69,24 +76,153 @@ int makedevs_main(int argc, char **argv) | |||
69 | return 0; | 76 | return 0; |
70 | } | 77 | } |
71 | 78 | ||
79 | #elif defined CONFIG_FEATURE_MAKEDEVS_TABLE | ||
80 | |||
72 | /* | 81 | /* |
73 | And this is what this program replaces. The shell is too slow! | 82 | * This program is free software; you can redistribute it and/or modify |
74 | 83 | * it under the terms of the GNU General Public License version 2 as | |
75 | makedev () { | 84 | * published by the Free Software Foundation. |
76 | local basedev=$1; local S=$2; local E=$3 | 85 | * |
77 | local major=$4; local Sminor=$5; local type=$6 | 86 | * This program is distributed in the hope that it will be useful, |
78 | local sbase=$7 | 87 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
79 | 88 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
80 | if [ ! "$sbase" = "" ]; then | 89 | * GNU Library General Public License for more details. |
81 | mknod "$basedev" $type $major $Sminor | 90 | * |
82 | S=`expr $S + 1` | 91 | * You should have received a copy of the GNU General Public License |
83 | Sminor=`expr $Sminor + 1` | 92 | * along with this program; if not, write to the Free Software |
84 | fi | 93 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
85 | 94 | * | |
86 | while [ $S -le $E ]; do | 95 | */ |
87 | mknod "$basedev$S" $type $major $Sminor | 96 | |
88 | S=`expr $S + 1` | 97 | static const struct option makedevs_long_options[] = { |
89 | Sminor=`expr $Sminor + 1` | 98 | {"root", 1, NULL, 'r'}, |
90 | done | 99 | {0, 0, 0, 0} |
100 | }; | ||
101 | |||
102 | extern int makedevs_main(int argc, char **argv) | ||
103 | { | ||
104 | FILE *table; | ||
105 | int opt; | ||
106 | char *rootdir = "./"; | ||
107 | char *line; | ||
108 | int ret = EXIT_SUCCESS; | ||
109 | |||
110 | bb_opt_complementaly = "d~r"; | ||
111 | bb_applet_long_options = makedevs_long_options; | ||
112 | opt = bb_getopt_ulflags(argc, argv, "d:r:", &rootdir, &rootdir); | ||
113 | |||
114 | if (optind + 1 == argc) { | ||
115 | table = bb_xfopen(argv[optind], "r"); | ||
116 | } else { | ||
117 | table = stdin; | ||
118 | } | ||
119 | |||
120 | if (chdir(rootdir) == -1) { | ||
121 | bb_perror_msg_and_die("Couldnt chdor to %s", rootdir); | ||
122 | } | ||
123 | |||
124 | umask(0); | ||
125 | |||
126 | while ((line = bb_get_chomped_line_from_file(table))) { | ||
127 | char type; | ||
128 | unsigned int mode = 0755; | ||
129 | unsigned int major = 0; | ||
130 | unsigned int minor = 0; | ||
131 | unsigned int count = 0; | ||
132 | unsigned int increment = 0; | ||
133 | unsigned int start = 0; | ||
134 | char name[41]; | ||
135 | char user[41]; | ||
136 | char group[41]; | ||
137 | char *full_name; | ||
138 | uid_t uid; | ||
139 | gid_t gid; | ||
140 | |||
141 | if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, | ||
142 | &type, &mode, user, group, &major, | ||
143 | &minor, &start, &increment, &count)) || | ||
144 | ((major | minor | start | count | increment) > 255)) { | ||
145 | bb_error_msg("Ignoring invalid line\n%s\n", line); | ||
146 | ret = EXIT_FAILURE; | ||
147 | continue; | ||
148 | } | ||
149 | if (name[0] == '#') { | ||
150 | continue; | ||
151 | } | ||
152 | if (group) { | ||
153 | gid = get_ug_id(group, my_getgrnam); | ||
154 | } else { | ||
155 | gid = getgid(); | ||
156 | } | ||
157 | if (user) { | ||
158 | uid = get_ug_id(user, my_getpwnam); | ||
159 | } else { | ||
160 | uid = getuid(); | ||
161 | } | ||
162 | full_name = concat_path_file(rootdir, name); | ||
163 | |||
164 | if (type == 'd') { | ||
165 | bb_make_directory(full_name, mode | S_IFDIR, 0); | ||
166 | if (chown(full_name, uid, gid) == -1) { | ||
167 | bb_perror_msg("chown failed for %s", full_name); | ||
168 | ret = EXIT_FAILURE; | ||
169 | goto loop; | ||
170 | } | ||
171 | } else { | ||
172 | dev_t rdev; | ||
173 | |||
174 | if (type == 'p') { | ||
175 | mode |= S_IFIFO; | ||
176 | } | ||
177 | else if (type == 'c') { | ||
178 | mode |= S_IFCHR; | ||
179 | } | ||
180 | else if (type == 'b') { | ||
181 | mode |= S_IFBLK; | ||
182 | } else { | ||
183 | bb_error_msg("Unsupported file type %c", type); | ||
184 | ret = EXIT_FAILURE; | ||
185 | goto loop; | ||
186 | } | ||
187 | |||
188 | if (count > 0) { | ||
189 | int i; | ||
190 | char *full_name_inc; | ||
191 | |||
192 | full_name_inc = xmalloc(strlen(full_name) + 4); | ||
193 | for (i = start; i < count; i++) { | ||
194 | sprintf(full_name_inc, "%s%d", full_name, i); | ||
195 | rdev = (major << 8) + minor + (i * increment - start); | ||
196 | if (mknod(full_name_inc, mode, rdev) == -1) { | ||
197 | bb_perror_msg("Couldnt create node %s", full_name_inc); | ||
198 | ret = EXIT_FAILURE; | ||
199 | } | ||
200 | else if (chown(full_name_inc, uid, gid) == -1) { | ||
201 | bb_perror_msg("chown failed for %s", full_name_inc); | ||
202 | ret = EXIT_FAILURE; | ||
203 | } | ||
204 | } | ||
205 | free(full_name_inc); | ||
206 | } else { | ||
207 | rdev = (major << 8) + minor; | ||
208 | if (mknod(full_name, mode, rdev) == -1) { | ||
209 | bb_perror_msg("Couldnt create node %s", full_name); | ||
210 | ret = EXIT_FAILURE; | ||
211 | } | ||
212 | else if (chown(full_name, uid, gid) == -1) { | ||
213 | bb_perror_msg("chown failed for %s", full_name); | ||
214 | ret = EXIT_FAILURE; | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | loop: | ||
219 | free(line); | ||
220 | free(full_name); | ||
221 | } | ||
222 | fclose(table); | ||
223 | |||
224 | return 0; | ||
91 | } | 225 | } |
92 | */ | 226 | #else |
227 | # error makdedevs configuration error, either leaf or table must be selected | ||
228 | #endif | ||
diff --git a/patches/makdevs_table.diff b/patches/makdevs_table.diff new file mode 100644 index 000000000..1041608b7 --- /dev/null +++ b/patches/makdevs_table.diff | |||
@@ -0,0 +1,294 @@ | |||
1 | Index: include/usage.h | ||
2 | =================================================================== | ||
3 | RCS file: /var/cvs/busybox/include/usage.h,v | ||
4 | retrieving revision 1.211 | ||
5 | diff -u -r1.211 usage.h | ||
6 | --- a/include/usage.h 26 May 2004 22:09:37 -0000 1.211 | ||
7 | +++ b/include/usage.h 5 Jun 2004 07:51:26 -0000 | ||
8 | @@ -1536,6 +1536,7 @@ | ||
9 | #define lsmod_full_usage \ | ||
10 | "List the currently loaded kernel modules." | ||
11 | |||
12 | +#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF | ||
13 | #define makedevs_trivial_usage \ | ||
14 | "NAME TYPE MAJOR MINOR FIRST LAST [s]" | ||
15 | #define makedevs_full_usage \ | ||
16 | @@ -1555,6 +1556,18 @@ | ||
17 | "[creates ttyS2-ttyS63]\n" \ | ||
18 | "# makedevs /dev/hda b 3 0 0 8 s\n" \ | ||
19 | "[creates hda,hda1-hda8]\n" | ||
20 | +#endif | ||
21 | + | ||
22 | +#ifdef CONFIG_FEATURE_MAKEDEVS_TABLE | ||
23 | +#define makedevs_trivial_usage \ | ||
24 | + "[-r rootdir] [device_table]" | ||
25 | +#define makedevs_full_usage \ | ||
26 | + "Creates a batch of special files as specified in a device table\n" \ | ||
27 | + "The device table has one line per device group, each group is of\n" \ | ||
28 | + "the format\n" \ | ||
29 | + "\ttype mode user group major minor start increment count\n" \ | ||
30 | + "a '-' may be used for blank entries\n" | ||
31 | +#endif | ||
32 | |||
33 | #ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK | ||
34 | #define USAGE_MD5_SHA1_SUM_CHECK(a) a | ||
35 | Index: miscutils/Config.in | ||
36 | =================================================================== | ||
37 | RCS file: /var/cvs/busybox/miscutils/Config.in,v | ||
38 | retrieving revision 1.14 | ||
39 | diff -u -r1.14 Config.in | ||
40 | --- a/miscutils/Config.in 15 Mar 2004 08:28:46 -0000 1.14 | ||
41 | +++ b/miscutils/Config.in 5 Jun 2004 07:51:26 -0000 | ||
42 | @@ -143,10 +143,32 @@ | ||
43 | bool "makedevs" | ||
44 | default n | ||
45 | help | ||
46 | - 'makedevs' is a utility used and created by the Linux Router Project. | ||
47 | - It creates a large number of device special files (/dev devices) | ||
48 | - rather quickly, and can be considerably faster then running mknod a | ||
49 | - zillion times. | ||
50 | + 'makedevs' is a utility used to create a batch of devices with | ||
51 | + one command. | ||
52 | + . | ||
53 | + There are two choices for command line behaviour, the interface | ||
54 | + as used by LEAF/Linux Router Project, or a device table file. | ||
55 | + . | ||
56 | + 'leaf' is traditionally what busybox follows, it allows multiple | ||
57 | + devices of a particluar type to be created per command. | ||
58 | + e.g. /dev/hda[0-9] | ||
59 | + Device properties are passed as command line arguments. | ||
60 | + . | ||
61 | + 'table' reads device properties from a file or stdin, allowing | ||
62 | + a batch of unrelated devices to be makde with one command. | ||
63 | + User/group names are allowed as an alternative to uid/gid. | ||
64 | + | ||
65 | +choice | ||
66 | + prompt "Choose makedevs behaviour" | ||
67 | + default CONFIG_FEATURE_MAKDEVS_TABLE | ||
68 | + | ||
69 | +config CONFIG_FEATURE_MAKEDEVS_LEAF | ||
70 | + bool "leaf" | ||
71 | + | ||
72 | +config CONFIG_FEATURE_MAKEDEVS_TABLE | ||
73 | + bool "table" | ||
74 | + | ||
75 | +endchoice | ||
76 | |||
77 | config CONFIG_MT | ||
78 | bool "mt" | ||
79 | Index: miscutils/makedevs.c | ||
80 | =================================================================== | ||
81 | RCS file: /var/cvs/busybox/miscutils/makedevs.c,v | ||
82 | retrieving revision 1.16 | ||
83 | diff -u -r1.16 makedevs.c | ||
84 | --- a/miscutils/makedevs.c 15 Mar 2004 08:28:46 -0000 1.16 | ||
85 | +++ b/miscutils/makedevs.c 5 Jun 2004 07:51:26 -0000 | ||
86 | @@ -1,20 +1,27 @@ | ||
87 | /* vi: set sw=4 ts=4: */ | ||
88 | -/* | ||
89 | - * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
90 | - * | ||
91 | - * makedevs | ||
92 | - * Make ranges of device files quickly. | ||
93 | - * known bugs: can't deal with alpha ranges | ||
94 | - */ | ||
95 | |||
96 | +#include <sys/types.h> | ||
97 | + | ||
98 | +#include <fcntl.h> | ||
99 | +#include <getopt.h> | ||
100 | #include <stdio.h> | ||
101 | #include <stdlib.h> | ||
102 | #include <string.h> | ||
103 | -#include <fcntl.h> | ||
104 | +#include <time.h> | ||
105 | #include <unistd.h> | ||
106 | -#include <sys/types.h> | ||
107 | + | ||
108 | #include "busybox.h" | ||
109 | |||
110 | +#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF | ||
111 | + | ||
112 | +/* | ||
113 | + * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> | ||
114 | + * | ||
115 | + * makedevs | ||
116 | + * Make ranges of device files quickly. | ||
117 | + * known bugs: can't deal with alpha ranges | ||
118 | + */ | ||
119 | + | ||
120 | int makedevs_main(int argc, char **argv) | ||
121 | { | ||
122 | mode_t mode; | ||
123 | @@ -69,24 +76,153 @@ | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | +#elif defined CONFIG_FEATURE_MAKEDEVS_TABLE | ||
128 | + | ||
129 | /* | ||
130 | -And this is what this program replaces. The shell is too slow! | ||
131 | + * This program is free software; you can redistribute it and/or modify | ||
132 | + * it under the terms of the GNU General Public License version 2 as | ||
133 | + * published by the Free Software Foundation. | ||
134 | + * | ||
135 | + * This program is distributed in the hope that it will be useful, | ||
136 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
137 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
138 | + * GNU Library General Public License for more details. | ||
139 | + * | ||
140 | + * You should have received a copy of the GNU General Public License | ||
141 | + * along with this program; if not, write to the Free Software | ||
142 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
143 | + * | ||
144 | + */ | ||
145 | + | ||
146 | +static const struct option makedevs_long_options[] = { | ||
147 | + {"root", 1, NULL, 'r'}, | ||
148 | + {0, 0, 0, 0} | ||
149 | +}; | ||
150 | |||
151 | -makedev () { | ||
152 | -local basedev=$1; local S=$2; local E=$3 | ||
153 | -local major=$4; local Sminor=$5; local type=$6 | ||
154 | -local sbase=$7 | ||
155 | - | ||
156 | - if [ ! "$sbase" = "" ]; then | ||
157 | - mknod "$basedev" $type $major $Sminor | ||
158 | - S=`expr $S + 1` | ||
159 | - Sminor=`expr $Sminor + 1` | ||
160 | - fi | ||
161 | - | ||
162 | - while [ $S -le $E ]; do | ||
163 | - mknod "$basedev$S" $type $major $Sminor | ||
164 | - S=`expr $S + 1` | ||
165 | - Sminor=`expr $Sminor + 1` | ||
166 | - done | ||
167 | +extern int makedevs_main(int argc, char **argv) | ||
168 | +{ | ||
169 | + FILE *table; | ||
170 | + int opt; | ||
171 | + char *rootdir = "./"; | ||
172 | + char *line; | ||
173 | + int ret = EXIT_SUCCESS; | ||
174 | + | ||
175 | + bb_opt_complementaly = "d~r"; | ||
176 | + bb_applet_long_options = makedevs_long_options; | ||
177 | + opt = bb_getopt_ulflags(argc, argv, "d:r:", &rootdir, &rootdir); | ||
178 | + | ||
179 | + if (optind + 1 == argc) { | ||
180 | + table = bb_xfopen(argv[optind], "r"); | ||
181 | + } else { | ||
182 | + table = stdin; | ||
183 | + } | ||
184 | + | ||
185 | + if (chdir(rootdir) == -1) { | ||
186 | + bb_perror_msg_and_die("Couldnt chdor to %s", rootdir); | ||
187 | + } | ||
188 | + | ||
189 | + umask(0); | ||
190 | + | ||
191 | + while ((line = bb_get_chomped_line_from_file(table))) { | ||
192 | + char type; | ||
193 | + unsigned int mode = 0755; | ||
194 | + unsigned int major = 0; | ||
195 | + unsigned int minor = 0; | ||
196 | + unsigned int count = 0; | ||
197 | + unsigned int increment = 0; | ||
198 | + unsigned int start = 0; | ||
199 | + char name[41]; | ||
200 | + char user[41]; | ||
201 | + char group[41]; | ||
202 | + char *full_name; | ||
203 | + uid_t uid; | ||
204 | + gid_t gid; | ||
205 | + | ||
206 | + if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, | ||
207 | + &type, &mode, user, group, &major, | ||
208 | + &minor, &start, &increment, &count)) || | ||
209 | + ((major | minor | start | count | increment) > 255)) { | ||
210 | + bb_error_msg("Ignoring invalid line\n%s\n", line); | ||
211 | + ret = EXIT_FAILURE; | ||
212 | + continue; | ||
213 | + } | ||
214 | + if (name[0] == '#') { | ||
215 | + continue; | ||
216 | + } | ||
217 | + if (group) { | ||
218 | + gid = get_ug_id(group, my_getgrnam); | ||
219 | + } else { | ||
220 | + gid = getgid(); | ||
221 | + } | ||
222 | + if (user) { | ||
223 | + uid = get_ug_id(user, my_getpwnam); | ||
224 | + } else { | ||
225 | + uid = getuid(); | ||
226 | + } | ||
227 | + full_name = concat_path_file(rootdir, name); | ||
228 | + | ||
229 | + if (type == 'd') { | ||
230 | + bb_make_directory(full_name, mode | S_IFDIR, 0); | ||
231 | + if (chown(full_name, uid, gid) == -1) { | ||
232 | + bb_perror_msg("chown failed for %s", full_name); | ||
233 | + ret = EXIT_FAILURE; | ||
234 | + goto loop; | ||
235 | + } | ||
236 | + } else { | ||
237 | + dev_t rdev; | ||
238 | + | ||
239 | + if (type == 'p') { | ||
240 | + mode |= S_IFIFO; | ||
241 | + } | ||
242 | + else if (type == 'c') { | ||
243 | + mode |= S_IFCHR; | ||
244 | + } | ||
245 | + else if (type == 'b') { | ||
246 | + mode |= S_IFBLK; | ||
247 | + } else { | ||
248 | + bb_error_msg("Unsupported file type %c", type); | ||
249 | + ret = EXIT_FAILURE; | ||
250 | + goto loop; | ||
251 | + } | ||
252 | + | ||
253 | + if (count > 0) { | ||
254 | + int i; | ||
255 | + char *full_name_inc; | ||
256 | + | ||
257 | + full_name_inc = xmalloc(strlen(full_name) + 4); | ||
258 | + for (i = start; i < count; i++) { | ||
259 | + sprintf(full_name_inc, "%s%d", full_name, i); | ||
260 | + rdev = (major << 8) + minor + (i * increment - start); | ||
261 | + if (mknod(full_name_inc, mode, rdev) == -1) { | ||
262 | + bb_perror_msg("Couldnt create node %s", full_name_inc); | ||
263 | + ret = EXIT_FAILURE; | ||
264 | + } | ||
265 | + else if (chown(full_name_inc, uid, gid) == -1) { | ||
266 | + bb_perror_msg("chown failed for %s", full_name_inc); | ||
267 | + ret = EXIT_FAILURE; | ||
268 | + } | ||
269 | + } | ||
270 | + free(full_name_inc); | ||
271 | + } else { | ||
272 | + rdev = (major << 8) + minor; | ||
273 | + if (mknod(full_name, mode, rdev) == -1) { | ||
274 | + bb_perror_msg("Couldnt create node %s", full_name); | ||
275 | + ret = EXIT_FAILURE; | ||
276 | + } | ||
277 | + else if (chown(full_name, uid, gid) == -1) { | ||
278 | + bb_perror_msg("chown failed for %s", full_name); | ||
279 | + ret = EXIT_FAILURE; | ||
280 | + } | ||
281 | + } | ||
282 | + } | ||
283 | +loop: | ||
284 | + free(line); | ||
285 | + free(full_name); | ||
286 | + } | ||
287 | + fclose(table); | ||
288 | + | ||
289 | + return 0; | ||
290 | } | ||
291 | -*/ | ||
292 | +#else | ||
293 | +# error makdedevs configuration error, either leaf or table must be selected | ||
294 | +#endif | ||