aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2005-07-18 09:28:36 +0000
committerEric Andersen <andersen@codepoet.org>2005-07-18 09:28:36 +0000
commite8614dbcd75915e6bf5badb8669efc04e62453f8 (patch)
treef943b6891fccf9c5c5f0d672dee008c28ff61b8a
parent10427ab5282582f407fab329638c187ae6b0c244 (diff)
downloadbusybox-w32-e8614dbcd75915e6bf5badb8669efc04e62453f8.tar.gz
busybox-w32-e8614dbcd75915e6bf5badb8669efc04e62453f8.tar.bz2
busybox-w32-e8614dbcd75915e6bf5badb8669efc04e62453f8.zip
Fixup device table based makedevs so it actually works
-rw-r--r--include/usage.h36
-rw-r--r--miscutils/makedevs.c69
2 files changed, 71 insertions, 34 deletions
diff --git a/include/usage.h b/include/usage.h
index 017cb9c3e..831a9a74a 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1672,13 +1672,37 @@
1672 1672
1673#ifdef CONFIG_FEATURE_MAKEDEVS_TABLE 1673#ifdef CONFIG_FEATURE_MAKEDEVS_TABLE
1674#define makedevs_trivial_usage \ 1674#define makedevs_trivial_usage \
1675 "[-r rootdir] [device_table]" 1675 "[-d device_table] rootdir"
1676#define makedevs_full_usage \ 1676#define makedevs_full_usage \
1677 "Creates a batch of special files as specified in a device table\n" \ 1677 "Creates a range of special files as specified in a device table.\n" \
1678 "The device table has one line per device group, each group is of\n" \ 1678 "Device table entries take the form of:\n" \
1679 "the format\n" \ 1679 "type mode user group major minor start increment count\n\n" \
1680 "\ttype mode user group major minor start increment count\n" \ 1680 "<type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>\n" \
1681 "a '-' may be used for blank entries\n" 1681 "Where name is the file name, type can be one of:\n" \
1682 " f A regular file\n" \
1683 " d Directory\n" \
1684 " c Character special device file\n" \
1685 " b Block special device file\n" \
1686 " p Fifo (named pipe)\n" \
1687 "uid is the user id for the target file, gid is the group id for the\n" \
1688 "target file. The rest of the entries (major, minor, etc) apply to\n" \
1689 "to device special files. A '-' may be used for blank entries.\n\n" \
1690#define makedevs_example_usage \
1691 "For example:\n" \
1692 "<name> <type> <mode><uid><gid><major><minor><start><inc><count>\n" \
1693 "/dev d 755 0 0 - - - - -\n" \
1694 "/dev/console c 666 0 0 5 1 - - -\n" \
1695 "/dev/null c 666 0 0 1 3 0 0 -\n" \
1696 "/dev/zero c 666 0 0 1 5 0 0 -\n" \
1697 "/dev/hda b 640 0 0 3 0 0 0 -\n" \
1698 "/dev/hda b 640 0 0 3 1 1 1 15\n\n" \
1699 "Will Produce:\n" \
1700 "/dev\n" \
1701 "/dev/console\n" \
1702 "/dev/null\n" \
1703 "/dev/zero\n" \
1704 "/dev/hda\n" \
1705 "/dev/hda[0-15]"
1682#endif 1706#endif
1683 1707
1684#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK 1708#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index 2c9a0a9af..eb3e3680d 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -91,35 +91,42 @@ int makedevs_main(int argc, char **argv)
91 * 91 *
92 */ 92 */
93 93
94static const struct option makedevs_long_options[] = {
95 {"root", 1, NULL, 'r'},
96 {0, 0, 0, 0}
97};
98
99extern int makedevs_main(int argc, char **argv) 94extern int makedevs_main(int argc, char **argv)
100{ 95{
101 FILE *table;
102 int opt; 96 int opt;
103 char *rootdir = "./"; 97 FILE *table = stdin;
104 char *line; 98 char *rootdir = NULL;
99 char *line = NULL;
100 int linenum = 0;
105 int ret = EXIT_SUCCESS; 101 int ret = EXIT_SUCCESS;
106 102
107 bb_opt_complementaly = "d~r"; 103 while ((opt = getopt(argc, argv, "d:")) != -1) {
108 bb_applet_long_options = makedevs_long_options; 104 switch(opt) {
109 opt = bb_getopt_ulflags(argc, argv, "d:r:", &rootdir, &rootdir); 105 case 'd':
106 table = bb_xfopen((line=optarg), "r");
107 break;
108 default:
109 bb_show_usage();
110 }
111 }
110 112
111 if (optind + 1 == argc) { 113 if (optind >= argc || (rootdir=argv[optind])==NULL) {
112 table = bb_xfopen(argv[optind], "r"); 114 bb_error_msg_and_die("root directory not speficied");
113 } else {
114 table = stdin;
115 } 115 }
116 116
117 if (chdir(rootdir) == -1) { 117 if (chdir(rootdir) != 0) {
118 bb_perror_msg_and_die("Couldnt chdor to %s", rootdir); 118 bb_perror_msg_and_die("Couldnt chdir to %s", rootdir);
119 } 119 }
120 120
121 umask(0); 121 umask(0);
122 122
123 printf("rootdir=%s\n", rootdir);
124 if (line) {
125 printf("table='%s'\n", line);
126 } else {
127 printf("table=<stdin>\n");
128 }
129
123 while ((line = bb_get_chomped_line_from_file(table))) { 130 while ((line = bb_get_chomped_line_from_file(table))) {
124 char type; 131 char type;
125 unsigned int mode = 0755; 132 unsigned int mode = 0755;
@@ -135,11 +142,16 @@ extern int makedevs_main(int argc, char **argv)
135 uid_t uid; 142 uid_t uid;
136 gid_t gid; 143 gid_t gid;
137 144
145 linenum++;
146
138 if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, 147 if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name,
139 &type, &mode, user, group, &major, 148 &type, &mode, user, group, &major,
140 &minor, &start, &increment, &count)) || 149 &minor, &start, &increment, &count)) ||
141 ((major | minor | start | count | increment) > 255)) { 150 ((major | minor | start | count | increment) > 255))
142 bb_error_msg("Ignoring invalid line\n%s\n", line); 151 {
152 if (*line=='\0' || *line=='#' || isspace(*line))
153 continue;
154 bb_error_msg("line %d invalid: '%s'\n", linenum, line);
143 ret = EXIT_FAILURE; 155 ret = EXIT_FAILURE;
144 continue; 156 continue;
145 } 157 }
@@ -159,9 +171,9 @@ extern int makedevs_main(int argc, char **argv)
159 full_name = concat_path_file(rootdir, name); 171 full_name = concat_path_file(rootdir, name);
160 172
161 if (type == 'd') { 173 if (type == 'd') {
162 bb_make_directory(full_name, mode | S_IFDIR, 0); 174 bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR);
163 if (chown(full_name, uid, gid) == -1) { 175 if (chown(full_name, uid, gid) == -1) {
164 bb_perror_msg("chown failed for %s", full_name); 176 bb_perror_msg("line %d: chown failed for %s", linenum, full_name);
165 ret = EXIT_FAILURE; 177 ret = EXIT_FAILURE;
166 goto loop; 178 goto loop;
167 } 179 }
@@ -177,7 +189,7 @@ extern int makedevs_main(int argc, char **argv)
177 else if (type == 'b') { 189 else if (type == 'b') {
178 mode |= S_IFBLK; 190 mode |= S_IFBLK;
179 } else { 191 } else {
180 bb_error_msg("Unsupported file type %c", type); 192 bb_error_msg("line %d: Unsupported file type %c", linenum, type);
181 ret = EXIT_FAILURE; 193 ret = EXIT_FAILURE;
182 goto loop; 194 goto loop;
183 } 195 }
@@ -191,11 +203,11 @@ extern int makedevs_main(int argc, char **argv)
191 sprintf(full_name_inc, "%s%d", full_name, i); 203 sprintf(full_name_inc, "%s%d", full_name, i);
192 rdev = (major << 8) + minor + (i * increment - start); 204 rdev = (major << 8) + minor + (i * increment - start);
193 if (mknod(full_name_inc, mode, rdev) == -1) { 205 if (mknod(full_name_inc, mode, rdev) == -1) {
194 bb_perror_msg("Couldnt create node %s", full_name_inc); 206 bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name_inc);
195 ret = EXIT_FAILURE; 207 ret = EXIT_FAILURE;
196 } 208 }
197 else if (chown(full_name_inc, uid, gid) == -1) { 209 else if (chown(full_name_inc, uid, gid) == -1) {
198 bb_perror_msg("chown failed for %s", full_name_inc); 210 bb_perror_msg("line %d: chown failed for %s", linenum, full_name_inc);
199 ret = EXIT_FAILURE; 211 ret = EXIT_FAILURE;
200 } 212 }
201 } 213 }
@@ -203,11 +215,11 @@ extern int makedevs_main(int argc, char **argv)
203 } else { 215 } else {
204 rdev = (major << 8) + minor; 216 rdev = (major << 8) + minor;
205 if (mknod(full_name, mode, rdev) == -1) { 217 if (mknod(full_name, mode, rdev) == -1) {
206 bb_perror_msg("Couldnt create node %s", full_name); 218 bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name);
207 ret = EXIT_FAILURE; 219 ret = EXIT_FAILURE;
208 } 220 }
209 else if (chown(full_name, uid, gid) == -1) { 221 else if (chown(full_name, uid, gid) == -1) {
210 bb_perror_msg("chown failed for %s", full_name); 222 bb_perror_msg("line %d: chown failed for %s", linenum, full_name);
211 ret = EXIT_FAILURE; 223 ret = EXIT_FAILURE;
212 } 224 }
213 } 225 }
@@ -220,6 +232,7 @@ loop:
220 232
221 return 0; 233 return 0;
222} 234}
235
223#else 236#else
224# error makdedevs configuration error, either leaf or table must be selected 237# error makdedevs configuration error, either leaf or table must be selected
225#endif 238#endif