aboutsummaryrefslogtreecommitdiff
path: root/miscutils/makedevs.c
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils/makedevs.c')
-rw-r--r--miscutils/makedevs.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index c945a1352..9e7ca340f 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -6,6 +6,41 @@
6 * Make ranges of device files quickly. 6 * Make ranges of device files quickly.
7 * known bugs: can't deal with alpha ranges 7 * known bugs: can't deal with alpha ranges
8 */ 8 */
9//config:config MAKEDEVS
10//config: bool "makedevs"
11//config: default y
12//config: help
13//config: 'makedevs' is a utility used to create a batch of devices with
14//config: one command.
15//config:
16//config: There are two choices for command line behaviour, the interface
17//config: as used by LEAF/Linux Router Project, or a device table file.
18//config:
19//config: 'leaf' is traditionally what busybox follows, it allows multiple
20//config: devices of a particluar type to be created per command.
21//config: e.g. /dev/hda[0-9]
22//config: Device properties are passed as command line arguments.
23//config:
24//config: 'table' reads device properties from a file or stdin, allowing
25//config: a batch of unrelated devices to be made with one command.
26//config: User/group names are allowed as an alternative to uid/gid.
27//config:
28//config:choice
29//config: prompt "Choose makedevs behaviour"
30//config: depends on MAKEDEVS
31//config: default FEATURE_MAKEDEVS_TABLE
32//config:
33//config:config FEATURE_MAKEDEVS_LEAF
34//config: bool "leaf"
35//config:
36//config:config FEATURE_MAKEDEVS_TABLE
37//config: bool "table"
38//config:
39//config:endchoice
40
41//applet:IF_MAKEDEVS(APPLET(makedevs, BB_DIR_SBIN, BB_SUID_DROP))
42
43//kbuild:lib-$(CONFIG_MAKEDEVS) += makedevs.o
9 44
10//usage:#if ENABLE_FEATURE_MAKEDEVS_LEAF 45//usage:#if ENABLE_FEATURE_MAKEDEVS_LEAF
11//usage:#define makedevs_trivial_usage 46//usage:#define makedevs_trivial_usage
@@ -122,8 +157,11 @@ int makedevs_main(int argc, char **argv)
122 157
123 /* if mode != S_IFCHR and != S_IFBLK, 158 /* if mode != S_IFCHR and != S_IFBLK,
124 * third param in mknod() ignored */ 159 * third param in mknod() ignored */
125 if (mknod(nodname, mode, makedev(Smajor, Sminor))) 160 if (mknod(nodname, mode, makedev(Smajor, Sminor)) != 0
161 && errno != EEXIST
162 ) {
126 bb_perror_msg("can't create '%s'", nodname); 163 bb_perror_msg("can't create '%s'", nodname);
164 }
127 165
128 /*if (nodname == basedev)*/ /* ex. /dev/hda - to /dev/hda1 ... */ 166 /*if (nodname == basedev)*/ /* ex. /dev/hda - to /dev/hda1 ... */
129 nodname = buf; 167 nodname = buf;
@@ -244,7 +282,9 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
244 for (i = start; i <= start + count; i++) { 282 for (i = start; i <= start + count; i++) {
245 sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); 283 sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i);
246 rdev = makedev(major, minor + (i - start) * increment); 284 rdev = makedev(major, minor + (i - start) * increment);
247 if (mknod(full_name_inc, mode, rdev) < 0) { 285 if (mknod(full_name_inc, mode, rdev) != 0
286 && errno != EEXIST
287 ) {
248 bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc); 288 bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc);
249 ret = EXIT_FAILURE; 289 ret = EXIT_FAILURE;
250 } else if (chown(full_name_inc, uid, gid) < 0) { 290 } else if (chown(full_name_inc, uid, gid) < 0) {