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
16 #include <sys/types.h>
19 static const char makedevs_usage[] =
20 "makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]\n"
21 #ifndef BB_FEATURE_TRIVIAL_HELP
22 "\nCreates a range of block or character special files\n\n"
24 "\tb:\tMake a block (buffered) device.\n"
25 "\tc or u:\tMake a character (un-buffered) device.\n"
26 "\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n\n"
27 "FIRST specifies the number appended to NAME to create the first device.\n"
28 "LAST specifies the number of the last item that should be created.\n"
29 "If 's' is the last argument, the base device is created as well.\n\n"
31 "\tmakedevs /dev/ttyS c 4 66 2 63 -> ttyS2-ttyS63\n"
32 "\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8\n"
36 int makedevs_main(int argc, char **argv)
39 const char *basedev = argv[1];
40 const char *type = argv[2];
41 int major = atoi(argv[3]);
42 int Sminor = atoi(argv[4]);
43 int S = atoi(argv[5]);
44 int E = atoi(argv[6]);
45 int sbase = argc == 8 ? 1 : 0;
52 if (argc < 7 || *argv[1]=='-')
53 usage(makedevs_usage);
66 usage(makedevs_usage);
73 dev = (major << 8) | Sminor;
74 strcpy(devname, basedev);
77 sprintf(buf, "%d", S);
83 if (mknod(devname, mode, dev))
84 printf("Failed to create: %s\n", devname);
94 And this is what this program replaces. The shell is too slow!
97 local basedev=$1; local S=$2; local E=$3
98 local major=$4; local Sminor=$5; local type=$6
101 if [ ! "$sbase" = "" ]; then
102 mknod "$basedev" $type $major $Sminor
104 Sminor=`expr $Sminor + 1`
107 while [ $S -le $E ]; do
108 mknod "$basedev$S" $type $major $Sminor
110 Sminor=`expr $Sminor + 1`