blob: f7fbeb2fe848788fdaa84a53d650d299c3fd9473 [file] [log] [blame]
Eric Andersencc8ed391999-10-05 16:24:54 +00001/*
2 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
3 *
4 * makedevs
5 * Make ranges of device files quickly.
6 * known bugs: can't deal with alpha ranges
7 */
8
9#include "internal.h"
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17
Eric Andersene77ae3a1999-10-19 20:03:34 +000018static const char makedevs_usage[] =
Eric Andersencc8ed391999-10-05 16:24:54 +000019"makedevs 0.01 -- Create an entire range of device files\n\n"
20"\tmakedevs /dev/ttyS c 4 64 0 63 (ttyS0-ttyS63)\n"
21"\tmakedevs /dev/hda b 3 0 0 8 s (hda,hda1-hda8)\n";
22
23int
Eric Andersenb0e9a701999-10-18 22:28:26 +000024makedevs_main(int argc, char * * argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000025{
26
27const char *basedev = argv[1];
28const char *type = argv[2];
29int major = atoi(argv[3]);
30int Sminor = atoi(argv[4]);
31int S = atoi(argv[5]);
32int E = atoi(argv[6]);
33int sbase = argc == 8 ? 1 : 0;
34
35mode_t mode = 0;
36dev_t dev = 0;
37char devname[255];
38char buf[255];
39
40 switch (type[0]) {
41 case 'c':
42 mode = S_IFCHR; break;
43 case 'b':
44 mode = S_IFBLK; break;
45 case 'f':
46 mode = S_IFIFO; break;
47 default:
Eric Andersene77ae3a1999-10-19 20:03:34 +000048 usage( makedevs_usage);
Eric Andersencc8ed391999-10-05 16:24:54 +000049 }
50 mode |= 0660;
51
52 while ( S <= E ) {
53
54 if (type[0] != 'f')
55 dev = (major << 8) | Sminor;
56 strcpy(devname, basedev);
57
58 if (sbase == 0) {
59 sprintf(buf, "%d", S);
60 strcat(devname, buf);
61 } else {
62 sbase = 0;
63 }
64
65 if (mknod (devname, mode, dev))
66 printf("Failed to create: %s\n", devname);
67
68 S++; Sminor++;
69 }
70
71return 0;
72}
73
74/*
75And this is what this program replaces. The shell is too slow!
76
77makedev () {
78local basedev=$1; local S=$2; local E=$3
79local major=$4; local Sminor=$5; local type=$6
80local sbase=$7
81
82 if [ ! "$sbase" = "" ]; then
83 mknod "$basedev" $type $major $Sminor
84 S=`expr $S + 1`
85 Sminor=`expr $Sminor + 1`
86 fi
87
88 while [ $S -le $E ]; do
89 mknod "$basedev$S" $type $major $Sminor
90 S=`expr $S + 1`
91 Sminor=`expr $Sminor + 1`
92 done
93}
94*/