aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-06-05 07:58:18 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-06-05 07:58:18 +0000
commit07e1ccdf751c88beb23a20b0c73685b9769701ad (patch)
tree116b7d80d74a05d02a388eeeba72356d5763b98f
parent84b6264670619c8051f0c81a1ed7bb58e161df21 (diff)
downloadbusybox-w32-07e1ccdf751c88beb23a20b0c73685b9769701ad.tar.gz
busybox-w32-07e1ccdf751c88beb23a20b0c73685b9769701ad.tar.bz2
busybox-w32-07e1ccdf751c88beb23a20b0c73685b9769701ad.zip
Woops, the previous commit was an accident, its supplied in the patch,
dont commit yet as we are in feature freeze
-rw-r--r--include/usage.h13
-rw-r--r--miscutils/Config.in30
-rw-r--r--miscutils/makedevs.c192
3 files changed, 32 insertions, 203 deletions
diff --git a/include/usage.h b/include/usage.h
index d41780d27..ce5624752 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1536,7 +1536,6 @@
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
1540#define makedevs_trivial_usage \ 1539#define makedevs_trivial_usage \
1541 "NAME TYPE MAJOR MINOR FIRST LAST [s]" 1540 "NAME TYPE MAJOR MINOR FIRST LAST [s]"
1542#define makedevs_full_usage \ 1541#define makedevs_full_usage \
@@ -1556,18 +1555,6 @@
1556 "[creates ttyS2-ttyS63]\n" \ 1555 "[creates ttyS2-ttyS63]\n" \
1557 "# makedevs /dev/hda b 3 0 0 8 s\n" \ 1556 "# makedevs /dev/hda b 3 0 0 8 s\n" \
1558 "[creates hda,hda1-hda8]\n" 1557 "[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
1571 1558
1572#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK 1559#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
1573#define USAGE_MD5_SHA1_SUM_CHECK(a) a 1560#define USAGE_MD5_SHA1_SUM_CHECK(a) a
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 320f4c2b4..7e18c16a0 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -143,32 +143,10 @@ 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 to create a batch of devices with 146 'makedevs' is a utility used and created by the Linux Router Project.
147 one command. 147 It creates a large number of device special files (/dev devices)
148 . 148 rather quickly, and can be considerably faster then running mknod a
149 There are two choices for command line behaviour, the interface 149 zillion times.
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
161choice
162 prompt "Choose makedevs behaviour"
163 default CONFIG_FEATURE_MAKDEVS_TABLE
164
165config CONFIG_FEATURE_MAKEDEVS_LEAF
166 bool "leaf"
167
168config CONFIG_FEATURE_MAKEDEVS_TABLE
169 bool "table"
170
171endchoice
172 150
173config CONFIG_MT 151config CONFIG_MT
174 bool "mt" 152 bool "mt"
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index 57b2d6c70..45498bb1d 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -1,19 +1,4 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2
3#include <sys/types.h>
4
5#include <fcntl.h>
6#include <getopt.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <time.h>
11#include <unistd.h>
12
13#include "busybox.h"
14
15#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
16
17/* 2/*
18 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com> 3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
19 * 4 *
@@ -21,7 +6,15 @@
21 * Make ranges of device files quickly. 6 * Make ranges of device files quickly.
22 * known bugs: can't deal with alpha ranges 7 * known bugs: can't deal with alpha ranges
23 */ 8 */
24 9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <sys/types.h>
16#include "busybox.h"
17
25int makedevs_main(int argc, char **argv) 18int makedevs_main(int argc, char **argv)
26{ 19{
27 mode_t mode; 20 mode_t mode;
@@ -76,153 +69,24 @@ int makedevs_main(int argc, char **argv)
76 return 0; 69 return 0;
77} 70}
78 71
79#elif defined CONFIG_FEATURE_MAKEDEVS_TABLE
80
81/* 72/*
82 * This program is free software; you can redistribute it and/or modify 73And this is what this program replaces. The shell is too slow!
83 * it under the terms of the GNU General Public License version 2 as 74
84 * published by the Free Software Foundation. 75makedev () {
85 * 76local basedev=$1; local S=$2; local E=$3
86 * This program is distributed in the hope that it will be useful, 77local major=$4; local Sminor=$5; local type=$6
87 * but WITHOUT ANY WARRANTY; without even the implied warranty of 78local sbase=$7
88 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 79
89 * GNU Library General Public License for more details. 80 if [ ! "$sbase" = "" ]; then
90 * 81 mknod "$basedev" $type $major $Sminor
91 * You should have received a copy of the GNU General Public License 82 S=`expr $S + 1`
92 * along with this program; if not, write to the Free Software 83 Sminor=`expr $Sminor + 1`
93 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 84 fi
94 * 85
95 */ 86 while [ $S -le $E ]; do
96 87 mknod "$basedev$S" $type $major $Sminor
97static const struct option makedevs_long_options[] = { 88 S=`expr $S + 1`
98 {"root", 1, NULL, 'r'}, 89 Sminor=`expr $Sminor + 1`
99 {0, 0, 0, 0} 90 done
100};
101
102extern 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 }
218loop:
219 free(line);
220 free(full_name);
221 }
222 fclose(table);
223
224 return 0;
225} 91}
226#else 92*/
227# error makdedevs configuration error, either leaf or table must be selected
228#endif