blob: b8c6dd1d8331f39a7d97ba49a5504c1305124e10 [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 <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <sys/types.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000016#include "busybox.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]=='-')
Eric Andersen67991cf2001-02-14 21:23:06 +000035 show_usage();
Erik Andersen5e1189e2000-04-15 16:34:54 +000036
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:
Eric Andersen67991cf2001-02-14 21:23:06 +000048 show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +000049 }
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*/