aboutsummaryrefslogtreecommitdiff
path: root/miscutils/makedevs.c
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 /miscutils/makedevs.c
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
Diffstat (limited to 'miscutils/makedevs.c')
-rw-r--r--miscutils/makedevs.c192
1 files changed, 28 insertions, 164 deletions
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