Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 1 | #include "internal.h" |
| 2 | #include <errno.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | const char mknod_usage[] = "mknod file b|c|u|p major minor\n" |
| 9 | "\tMake special files.\n" |
| 10 | "\n" |
| 11 | "\tb:\tMake a block (buffered) device.\n" |
| 12 | "\tc or u:\tMake a character (un-buffered) device.\n" |
| 13 | "\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n"; |
| 14 | |
| 15 | int |
| 16 | mknod_main(struct FileInfo * i, int argc, char * * argv) |
| 17 | { |
| 18 | mode_t mode = 0; |
| 19 | dev_t dev = 0; |
| 20 | |
| 21 | switch(argv[2][0]) { |
| 22 | case 'c': |
| 23 | case 'u': |
| 24 | mode = S_IFCHR; |
| 25 | break; |
| 26 | case 'b': |
| 27 | mode = S_IFBLK; |
| 28 | break; |
| 29 | case 'p': |
| 30 | mode = S_IFIFO; |
| 31 | break; |
| 32 | default: |
| 33 | usage(mknod_usage); |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | if ( mode == S_IFCHR || mode == S_IFBLK ) { |
| 38 | dev = (atoi(argv[3]) << 8) | atoi(argv[4]); |
| 39 | if ( argc != 5 ) { |
| 40 | usage(mknod_usage); |
| 41 | return 1; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | mode |= 0666; |
| 46 | |
| 47 | if ( mknod(argv[1], mode, dev) != 0 ) { |
| 48 | name_and_error(argv[1]); |
| 49 | return 1; |
| 50 | } |
| 51 | return 0; |
| 52 | } |