blob: f979871bd657cdcb10330ffe6f3e0ddbbf5ee437 [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 Andersen3570a342000-09-25 21:45:58 +000010#include "busybox.h"
Eric Andersencc8ed391999-10-05 16:24:54 +000011#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <fcntl.h>
15#include <unistd.h>
16#include <sys/types.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000017
Erik Andersene49d5ec2000-02-08 19:58:47 +000018int makedevs_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000019{
20
Erik Andersene49d5ec2000-02-08 19:58:47 +000021 const char *basedev = argv[1];
22 const char *type = argv[2];
23 int major = atoi(argv[3]);
24 int Sminor = atoi(argv[4]);
25 int S = atoi(argv[5]);
26 int E = atoi(argv[6]);
27 int sbase = argc == 8 ? 1 : 0;
Eric Andersencc8ed391999-10-05 16:24:54 +000028
Erik Andersene49d5ec2000-02-08 19:58:47 +000029 mode_t mode = 0;
30 dev_t dev = 0;
31 char devname[255];
32 char buf[255];
Eric Andersencc8ed391999-10-05 16:24:54 +000033
Erik Andersen5e1189e2000-04-15 16:34:54 +000034 if (argc < 7 || *argv[1]=='-')
35 usage(makedevs_usage);
36
Eric Andersencc8ed391999-10-05 16:24:54 +000037 switch (type[0]) {
Erik Andersene49d5ec2000-02-08 19:58:47 +000038 case 'c':
39 mode = S_IFCHR;
40 break;
41 case 'b':
42 mode = S_IFBLK;
43 break;
44 case 'f':
45 mode = S_IFIFO;
46 break;
47 default:
48 usage(makedevs_usage);
49 }
50 mode |= 0660;
Eric Andersencc8ed391999-10-05 16:24:54 +000051
Erik Andersene49d5ec2000-02-08 19:58:47 +000052 while (S <= E) {
53
Eric Andersencc8ed391999-10-05 16:24:54 +000054 if (type[0] != 'f')
55 dev = (major << 8) | Sminor;
56 strcpy(devname, basedev);
Erik Andersene49d5ec2000-02-08 19:58:47 +000057
Eric Andersencc8ed391999-10-05 16:24:54 +000058 if (sbase == 0) {
Erik Andersene49d5ec2000-02-08 19:58:47 +000059 sprintf(buf, "%d", S);
Eric Andersencc8ed391999-10-05 16:24:54 +000060 strcat(devname, buf);
61 } else {
62 sbase = 0;
63 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000064
65 if (mknod(devname, mode, dev))
66 printf("Failed to create: %s\n", devname);
67
68 S++;
69 Sminor++;
Eric Andersencc8ed391999-10-05 16:24:54 +000070 }
71
Erik Andersene49d5ec2000-02-08 19:58:47 +000072 return 0;
Eric Andersencc8ed391999-10-05 16:24:54 +000073}
74
75/*
76And this is what this program replaces. The shell is too slow!
77
78makedev () {
79local basedev=$1; local S=$2; local E=$3
80local major=$4; local Sminor=$5; local type=$6
81local sbase=$7
82
83 if [ ! "$sbase" = "" ]; then
84 mknod "$basedev" $type $major $Sminor
85 S=`expr $S + 1`
86 Sminor=`expr $Sminor + 1`
87 fi
88
89 while [ $S -le $E ]; do
90 mknod "$basedev$S" $type $major $Sminor
91 S=`expr $S + 1`
92 Sminor=`expr $Sminor + 1`
93 done
94}
95*/