|
|
1.1 ! root 1: /* ! 2: * mknod -- make a special file or named pipe ! 3: * Usage: /etc/mknod filename type major minor ! 4: * /etc/mknod filename p ! 5: * The 'type' is 'b' for block special or 'c' for character special; ! 6: * 'major' and 'minor' are numbers. ! 7: * The second form creates a pipe with the given filename. ! 8: */ ! 9: ! 10: #include <sys/stat.h> ! 11: ! 12: #define NMAJOR 256 ! 13: #define NMINOR 256 ! 14: ! 15: int force; ! 16: struct stat sb; ! 17: ! 18: main( argc, argv ) ! 19: ! 20: int argc; ! 21: register char **argv; ! 22: ! 23: { ! 24: register unsigned mode; ! 25: unsigned maj, min; ! 26: dev_t dev; ! 27: ! 28: if ( argc >= 2 && strcmp( argv[1], "-f" ) == 0 ) { ! 29: ++force; ! 30: ++argv; ! 31: --argc; ! 32: } ! 33: ! 34: if ( argc < 3 ) ! 35: usage(); ! 36: ! 37: if ( strlen( argv[2] ) != 1 ) ! 38: usage(); ! 39: ! 40: switch ( argc ) { ! 41: ! 42: case 3: ! 43: if ( argv[2][0] != 'p' ) ! 44: usage(); ! 45: ! 46: mode = S_IFPIP; ! 47: dev = 0; ! 48: break; ! 49: ! 50: case 5: ! 51: if ( getuid() != 0 ) ! 52: fatal( "not superuser\n", 0 ); ! 53: ! 54: switch ( argv[2][0] ) { ! 55: ! 56: case 'c': /* mknod name c major minor */ ! 57: mode = S_IFCHR; ! 58: break; ! 59: ! 60: case 'b': /* mknod name b major minor */ ! 61: mode = S_IFBLK; ! 62: break; ! 63: ! 64: default: ! 65: usage(); ! 66: } ! 67: ! 68: if ((maj = atoi(argv[3])) >= NMAJOR) ! 69: usage(); ! 70: ! 71: if ((min = atoi(argv[4])) >= NMINOR) ! 72: usage(); ! 73: ! 74: dev = makedev( maj, min ); ! 75: break; ! 76: ! 77: default: ! 78: usage(); ! 79: } ! 80: ! 81: if ( (stat( argv[1], &sb )) >= 0 ) { ! 82: ! 83: if ((sb.st_mode & S_IFMT) == S_IFDIR) ! 84: usage(); ! 85: ! 86: if (force) ! 87: unlink( argv[1] ); ! 88: } ! 89: ! 90: if ( mknod( argv[1], mode | 0777, dev ) < 0 ) ! 91: fatal( "can't mknod: ", argv[1] ); ! 92: ! 93: exit( 0 ); ! 94: } ! 95: ! 96: usage() ! 97: { ! 98: fatal( "\ ! 99: Usage: mknod [-f] filename b major minor\n\ ! 100: mknod [-f] filename c major minor\n\ ! 101: mknod [-f] filename p", 0 ); ! 102: } ! 103: ! 104: fatal( mesg, file ) ! 105: register char *mesg, *file; ! 106: { ! 107: write( 2, mesg, strlen(mesg) ); ! 108: if (file) ! 109: write( 2, file, strlen(file) ); ! 110: write( 2, "\n", 1 ); ! 111: exit( 1 ); ! 112: } ! 113: ! 114: /* ! 115: * atoi ( s ) ! 116: * ! 117: * Input: s = numeric string to evaluate. ! 118: * ! 119: * Action: Convert numeric string into a positive integer. ! 120: * ! 121: * Return: -1 = invalid character(s) encountered. ! 122: * * = numeric equivalent. ! 123: */ ! 124: ! 125: atoi( s ) ! 126: register char *s; ! 127: { ! 128: register int n = 0; ! 129: ! 130: while ( *s ) { ! 131: ! 132: if ( ('0' <= *s) && (*s <= '9') ) { ! 133: n *= 10; ! 134: n += *s++ - '0'; ! 135: } ! 136: else ! 137: return -1; ! 138: } ! 139: return n; ! 140: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.