1 /* vi: set sw=4 ts=4: */
3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
6 * Make ranges of device files quickly.
7 * known bugs: can't deal with alpha ranges
15 #include <sys/types.h>
18 int makedevs_main(int argc, char **argv)
21 char *basedev, *type, *nodname, buf[255];
22 int major, Sminor, S, E;
24 if (argc < 7 || *argv[1]=='-')
29 major = atoi(argv[3]) << 8; /* correcting param to mknod() */
30 Sminor = atoi(argv[4]);
33 nodname = argc == 8 ? basedev : buf;
54 sz = snprintf(buf, sizeof(buf), "%s%d", basedev, S);
55 if(sz<0 || sz>=sizeof(buf)) /* libc different */
56 bb_error_msg_and_die("%s too large", basedev);
58 /* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */
60 if (mknod(nodname, mode, major | Sminor))
61 bb_error_msg("Failed to create: %s", nodname);
63 if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */
73 And this is what this program replaces. The shell is too slow!
76 local basedev=$1; local S=$2; local E=$3
77 local major=$4; local Sminor=$5; local type=$6
80 if [ ! "$sbase" = "" ]; then
81 mknod "$basedev" $type $major $Sminor
83 Sminor=`expr $Sminor + 1`
86 while [ $S -le $E ]; do
87 mknod "$basedev$S" $type $major $Sminor
89 Sminor=`expr $Sminor + 1`