blob: 99dbc0bd5f4294b74ecc3aafb1db4647dc8f9893 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersencc8ed391999-10-05 16:24:54 +00002/*
3 * public domain -- Dave 'Kill a Cop' Cinege <dcinege@psychosis.com>
4 *
5 * makedevs
6 * Make ranges of device files quickly.
7 * known bugs: can't deal with alpha ranges
8 */
Erik Andersene49d5ec2000-02-08 19:58:47 +00009
Eric Andersencc8ed391999-10-05 16:24:54 +000010#include "internal.h"
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <fcntl.h>
15#include <unistd.h>
16#include <sys/types.h>
17#include <sys/stat.h>
18
Erik Andersene49d5ec2000-02-08 19:58:47 +000019int makedevs_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000020{
21
Erik Andersene49d5ec2000-02-08 19:58:47 +000022 const char *basedev = argv[1];
23 const char *type = argv[2];
24 int major = atoi(argv[3]);
25 int Sminor = atoi(argv[4]);
26 int S = atoi(argv[5]);
27 int E = atoi(argv[6]);
28 int sbase = argc == 8 ? 1 : 0;
Eric Andersencc8ed391999-10-05 16:24:54 +000029
Erik Andersene49d5ec2000-02-08 19:58:47 +000030 mode_t mode = 0;
31 dev_t dev = 0;
32 char devname[255];
33 char buf[255];
Eric Andersencc8ed391999-10-05 16:24:54 +000034
Erik Andersen5e1189e2000-04-15 16:34:54 +000035 if (argc < 7 || *argv[1]=='-')
36 usage(makedevs_usage);
37
Eric Andersencc8ed391999-10-05 16:24:54 +000038 switch (type[0]) {
Erik Andersene49d5ec2000-02-08 19:58:47 +000039 case 'c':
40 mode = S_IFCHR;
41 break;
42 case 'b':
43 mode = S_IFBLK;
44 break;
45 case 'f':
46 mode = S_IFIFO;
47 break;
48 default:
49 usage(makedevs_usage);
50 }
51 mode |= 0660;
Eric Andersencc8ed391999-10-05 16:24:54 +000052
Erik Andersene49d5ec2000-02-08 19:58:47 +000053 while (S <= E) {
54
Eric Andersencc8ed391999-10-05 16:24:54 +000055 if (type[0] != 'f')
56 dev = (major << 8) | Sminor;
57 strcpy(devname, basedev);
Erik Andersene49d5ec2000-02-08 19:58:47 +000058
Eric Andersencc8ed391999-10-05 16:24:54 +000059 if (sbase == 0) {
Erik Andersene49d5ec2000-02-08 19:58:47 +000060 sprintf(buf, "%d", S);
Eric Andersencc8ed391999-10-05 16:24:54 +000061 strcat(devname, buf);
62 } else {
63 sbase = 0;
64 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000065
66 if (mknod(devname, mode, dev))
67 printf("Failed to create: %s\n", devname);
68
69 S++;
70 Sminor++;
Eric Andersencc8ed391999-10-05 16:24:54 +000071 }
72
Erik Andersene49d5ec2000-02-08 19:58:47 +000073 return 0;
Eric Andersencc8ed391999-10-05 16:24:54 +000074}
75
76/*
77And this is what this program replaces. The shell is too slow!
78
79makedev () {
80local basedev=$1; local S=$2; local E=$3
81local major=$4; local Sminor=$5; local type=$6
82local sbase=$7
83
84 if [ ! "$sbase" = "" ]; then
85 mknod "$basedev" $type $major $Sminor
86 S=`expr $S + 1`
87 Sminor=`expr $Sminor + 1`
88 fi
89
90 while [ $S -le $E ]; do
91 mknod "$basedev$S" $type $major $Sminor
92 S=`expr $S + 1`
93 Sminor=`expr $Sminor + 1`
94 done
95}
96*/