Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 1 | #include "internal.h" |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 2 | #include <stdio.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 3 | #include <errno.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <fcntl.h> |
| 7 | #include <unistd.h> |
| 8 | |
Eric Andersen | e77ae3a | 1999-10-19 20:03:34 +0000 | [diff] [blame] | 9 | static const char mknod_usage[] = "mknod file b|c|u|p major minor\n" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 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 | |
| 16 | int |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 17 | mknod_main(int argc, char** argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 18 | { |
| 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 Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 34 | usage (mknod_usage); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | if ( mode == S_IFCHR || mode == S_IFBLK ) { |
| 38 | dev = (atoi(argv[3]) << 8) | atoi(argv[4]); |
| 39 | if ( argc != 5 ) { |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 40 | usage (mknod_usage); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | mode |= 0666; |
| 45 | |
| 46 | if ( mknod(argv[1], mode, dev) != 0 ) { |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 47 | perror(argv[1]); |
| 48 | return( FALSE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 49 | } |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 50 | return( TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 51 | } |