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\n"
21 "Creates a range of block or character special files\n\n"
23 "\tb:\tMake a block (buffered) device.\n"
24 "\tc or u:\tMake a character (un-buffered) device.\n"
25 "\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n\n"
26 "FIRST specifies the number appended to NAME to create the first device.\n"
27 "LAST specifies the number of the last item that should be created.\n"
28 "If 's' is the last argument, the base device is created as well.\n\n"
30 "\tmakedevs /dev/ttyS c 4 66 2 63 -> ttyS2-ttyS63\n"
31 "\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8\n";
33 int makedevs_main(int argc, char **argv)
36 const char *basedev = argv[1];
37 const char *type = argv[2];
38 int major = atoi(argv[3]);
39 int Sminor = atoi(argv[4]);
40 int S = atoi(argv[5]);
41 int E = atoi(argv[6]);
42 int sbase = argc == 8 ? 1 : 0;
49 if (argc < 7 || *argv[1]=='-')
50 usage(makedevs_usage);
63 usage(makedevs_usage);
70 dev = (major << 8) | Sminor;
71 strcpy(devname, basedev);
74 sprintf(buf, "%d", S);
80 if (mknod(devname, mode, dev))
81 printf("Failed to create: %s\n", devname);
91 And this is what this program replaces. The shell is too slow!
94 local basedev=$1; local S=$2; local E=$3
95 local major=$4; local Sminor=$5; local type=$6
98 if [ ! "$sbase" = "" ]; then
99 mknod "$basedev" $type $major $Sminor
101 Sminor=`expr $Sminor + 1`
104 while [ $S -le $E ]; do
105 mknod "$basedev$S" $type $major $Sminor
107 Sminor=`expr $Sminor + 1`