18fae3551SRodney W. Grimes /* 28fae3551SRodney W. Grimes * Copyright (c) 1989, 1993 38fae3551SRodney W. Grimes * The Regents of the University of California. All rights reserved. 48fae3551SRodney W. Grimes * 58fae3551SRodney W. Grimes * This code is derived from software contributed to Berkeley by 68fae3551SRodney W. Grimes * Kevin Fall. 78fae3551SRodney W. Grimes * 88fae3551SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 98fae3551SRodney W. Grimes * modification, are permitted provided that the following conditions 108fae3551SRodney W. Grimes * are met: 118fae3551SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 128fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 138fae3551SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 148fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 158fae3551SRodney W. Grimes * documentation and/or other materials provided with the distribution. 168fae3551SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 178fae3551SRodney W. Grimes * must display the following acknowledgement: 188fae3551SRodney W. Grimes * This product includes software developed by the University of 198fae3551SRodney W. Grimes * California, Berkeley and its contributors. 208fae3551SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 218fae3551SRodney W. Grimes * may be used to endorse or promote products derived from this software 228fae3551SRodney W. Grimes * without specific prior written permission. 238fae3551SRodney W. Grimes * 248fae3551SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 258fae3551SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 268fae3551SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 278fae3551SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 288fae3551SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 298fae3551SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 308fae3551SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 318fae3551SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 328fae3551SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 338fae3551SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 348fae3551SRodney W. Grimes * SUCH DAMAGE. 358fae3551SRodney W. Grimes */ 368fae3551SRodney W. Grimes 378fae3551SRodney W. Grimes #ifndef lint 388fae3551SRodney W. Grimes static char copyright[] = 398fae3551SRodney W. Grimes "@(#) Copyright (c) 1989, 1993\n\ 408fae3551SRodney W. Grimes The Regents of the University of California. All rights reserved.\n"; 418fae3551SRodney W. Grimes #endif /* not lint */ 428fae3551SRodney W. Grimes 438fae3551SRodney W. Grimes #ifndef lint 448fae3551SRodney W. Grimes static char sccsid[] = "@(#)mknod.c 8.1 (Berkeley) 6/5/93"; 458fae3551SRodney W. Grimes #endif /* not lint */ 468fae3551SRodney W. Grimes 478fae3551SRodney W. Grimes #include <sys/types.h> 488fae3551SRodney W. Grimes #include <sys/stat.h> 498fae3551SRodney W. Grimes #include <stdio.h> 508fae3551SRodney W. Grimes 518fae3551SRodney W. Grimes main(argc, argv) 528fae3551SRodney W. Grimes int argc; 538fae3551SRodney W. Grimes char **argv; 548fae3551SRodney W. Grimes { 558fae3551SRodney W. Grimes extern int errno; 568fae3551SRodney W. Grimes u_short mode; 57ce6bb537SJoerg Wunsch u_int32_t major, minor; 58ce6bb537SJoerg Wunsch char *endp; 598fae3551SRodney W. Grimes 608fae3551SRodney W. Grimes if (argc != 5) { 618fae3551SRodney W. Grimes (void)fprintf(stderr, 628fae3551SRodney W. Grimes "usage: mknod name [b | c] major minor\n"); 638fae3551SRodney W. Grimes exit(1); 648fae3551SRodney W. Grimes } 658fae3551SRodney W. Grimes 668fae3551SRodney W. Grimes mode = 0666; 678fae3551SRodney W. Grimes if (argv[2][0] == 'c') 688fae3551SRodney W. Grimes mode |= S_IFCHR; 698fae3551SRodney W. Grimes else if (argv[2][0] == 'b') 708fae3551SRodney W. Grimes mode |= S_IFBLK; 718fae3551SRodney W. Grimes else { 728fae3551SRodney W. Grimes (void)fprintf(stderr, 738fae3551SRodney W. Grimes "mknod: node must be type 'b' or 'c'.\n"); 748fae3551SRodney W. Grimes exit(1); 758fae3551SRodney W. Grimes } 768fae3551SRodney W. Grimes 77ce6bb537SJoerg Wunsch major = strtoul(argv[3], &endp, 0); 78ce6bb537SJoerg Wunsch if (*endp != '\0' || major >= 256) { 79ce6bb537SJoerg Wunsch (void)fprintf(stderr, 80ce6bb537SJoerg Wunsch "mknod: bad major number.\n"); 81ce6bb537SJoerg Wunsch exit(1); 82ce6bb537SJoerg Wunsch } 83ce6bb537SJoerg Wunsch minor = strtoul(argv[4], &endp, 0); 84ce6bb537SJoerg Wunsch if (*endp != '\0') { 85ce6bb537SJoerg Wunsch (void)fprintf(stderr, 86ce6bb537SJoerg Wunsch "mknod: bad minor number.\n"); 87ce6bb537SJoerg Wunsch exit(1); 88ce6bb537SJoerg Wunsch } 89ce6bb537SJoerg Wunsch 90ce6bb537SJoerg Wunsch if (mknod(argv[1], mode, makedev(major, minor)) < 0) { 918fae3551SRodney W. Grimes (void)fprintf(stderr, 928fae3551SRodney W. Grimes "mknod: %s: %s\n", argv[1], strerror(errno)); 938fae3551SRodney W. Grimes exit(1); 948fae3551SRodney W. Grimes } 958fae3551SRodney W. Grimes exit(0); 968fae3551SRodney W. Grimes } 97