1 /* vi: set sw=4 ts=4: */
15 #ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
18 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
21 * Make ranges of device files quickly.
22 * known bugs: can't deal with alpha ranges
25 int makedevs_main(int argc, char **argv)
28 char *basedev, *type, *nodname, buf[255];
29 int major, Sminor, S, E;
31 if (argc < 7 || *argv[1]=='-')
36 major = atoi(argv[3]) << 8; /* correcting param to mknod() */
37 Sminor = atoi(argv[4]);
40 nodname = argc == 8 ? basedev : buf;
61 sz = snprintf(buf, sizeof(buf), "%s%d", basedev, S);
62 if(sz<0 || sz>=sizeof(buf)) /* libc different */
63 bb_error_msg_and_die("%s too large", basedev);
65 /* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */
67 if (mknod(nodname, mode, major | Sminor))
68 bb_error_msg("Failed to create: %s", nodname);
70 if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */
79 #elif defined CONFIG_FEATURE_MAKEDEVS_TABLE
82 * This program is free software; you can redistribute it and/or modify
83 * it under the terms of the GNU General Public License version 2 as
84 * published by the Free Software Foundation.
86 * This program is distributed in the hope that it will be useful,
87 * but WITHOUT ANY WARRANTY; without even the implied warranty of
88 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 * GNU Library General Public License for more details.
91 * You should have received a copy of the GNU General Public License
92 * along with this program; if not, write to the Free Software
93 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
97 static const struct option makedevs_long_options[] = {
98 {"root", 1, NULL, 'r'},
102 extern int makedevs_main(int argc, char **argv)
106 char *rootdir = "./";
108 int ret = EXIT_SUCCESS;
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);
114 if (optind + 1 == argc) {
115 table = bb_xfopen(argv[optind], "r");
120 if (chdir(rootdir) == -1) {
121 bb_perror_msg_and_die("Couldnt chdor to %s", rootdir);
126 while ((line = bb_get_chomped_line_from_file(table))) {
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;
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);
149 if (name[0] == '#') {
153 gid = get_ug_id(group, my_getgrnam);
158 uid = get_ug_id(user, my_getpwnam);
162 full_name = concat_path_file(rootdir, name);
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);
177 else if (type == 'c') {
180 else if (type == 'b') {
183 bb_error_msg("Unsupported file type %c", type);
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);
200 else if (chown(full_name_inc, uid, gid) == -1) {
201 bb_perror_msg("chown failed for %s", full_name_inc);
207 rdev = (major << 8) + minor;
208 if (mknod(full_name, mode, rdev) == -1) {
209 bb_perror_msg("Couldnt create node %s", full_name);
212 else if (chown(full_name, uid, gid) == -1) {
213 bb_perror_msg("chown failed for %s", full_name);
227 # error makdedevs configuration error, either leaf or table must be selected