blob: 95d7de360d2c521345a2f5014e64d9eb7e7afa87 [file] [log] [blame]
Eric Andersencc8ed391999-10-05 16:24:54 +00001#include "internal.h"
Eric Andersenb0e9a701999-10-18 22:28:26 +00002#include <stdio.h>
Eric Andersencc8ed391999-10-05 16:24:54 +00003#include <errno.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <fcntl.h>
7#include <unistd.h>
8
9const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
10"\tMake special files.\n"
11"\n"
12"\tb:\tMake a block (buffered) device.\n"
13"\tc or u:\tMake a character (un-buffered) device.\n"
14"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
15
16int
Eric Andersenb0e9a701999-10-18 22:28:26 +000017mknod_main(int argc, char** argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000018{
19 mode_t mode = 0;
20 dev_t dev = 0;
21
22 switch(argv[2][0]) {
23 case 'c':
24 case 'u':
25 mode = S_IFCHR;
26 break;
27 case 'b':
28 mode = S_IFBLK;
29 break;
30 case 'p':
31 mode = S_IFIFO;
32 break;
33 default:
Eric Andersenb0e9a701999-10-18 22:28:26 +000034 usage (mknod_usage);
Eric Andersencc8ed391999-10-05 16:24:54 +000035 }
36
37 if ( mode == S_IFCHR || mode == S_IFBLK ) {
38 dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
39 if ( argc != 5 ) {
Eric Andersenb0e9a701999-10-18 22:28:26 +000040 usage (mknod_usage);
Eric Andersencc8ed391999-10-05 16:24:54 +000041 }
42 }
43
44 mode |= 0666;
45
46 if ( mknod(argv[1], mode, dev) != 0 ) {
Eric Andersenb0e9a701999-10-18 22:28:26 +000047 perror(argv[1]);
48 return( FALSE);
Eric Andersencc8ed391999-10-05 16:24:54 +000049 }
Eric Andersenb0e9a701999-10-18 22:28:26 +000050 return( TRUE);
Eric Andersencc8ed391999-10-05 16:24:54 +000051}