mknod.c revision 17302
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1989, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * This code is derived from software contributed to Berkeley by 61558Srgrimes * Kevin Fall. 71558Srgrimes * 81558Srgrimes * Redistribution and use in source and binary forms, with or without 91558Srgrimes * modification, are permitted provided that the following conditions 101558Srgrimes * are met: 111558Srgrimes * 1. Redistributions of source code must retain the above copyright 121558Srgrimes * notice, this list of conditions and the following disclaimer. 131558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141558Srgrimes * notice, this list of conditions and the following disclaimer in the 151558Srgrimes * documentation and/or other materials provided with the distribution. 161558Srgrimes * 3. All advertising materials mentioning features or use of this software 171558Srgrimes * must display the following acknowledgement: 181558Srgrimes * This product includes software developed by the University of 191558Srgrimes * California, Berkeley and its contributors. 201558Srgrimes * 4. Neither the name of the University nor the names of its contributors 211558Srgrimes * may be used to endorse or promote products derived from this software 221558Srgrimes * without specific prior written permission. 231558Srgrimes * 241558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341558Srgrimes * SUCH DAMAGE. 351558Srgrimes */ 361558Srgrimes 371558Srgrimes#ifndef lint 381558Srgrimesstatic char copyright[] = 391558Srgrimes"@(#) Copyright (c) 1989, 1993\n\ 401558Srgrimes The Regents of the University of California. All rights reserved.\n"; 411558Srgrimes#endif /* not lint */ 421558Srgrimes 431558Srgrimes#ifndef lint 441558Srgrimesstatic char sccsid[] = "@(#)mknod.c 8.1 (Berkeley) 6/5/93"; 451558Srgrimes#endif /* not lint */ 461558Srgrimes 471558Srgrimes#include <sys/types.h> 481558Srgrimes#include <sys/stat.h> 491558Srgrimes#include <stdio.h> 501558Srgrimes 511558Srgrimesmain(argc, argv) 521558Srgrimes int argc; 531558Srgrimes char **argv; 541558Srgrimes{ 551558Srgrimes extern int errno; 561558Srgrimes u_short mode; 5717302Sjoerg u_int32_t major, minor; 5817302Sjoerg char *endp; 591558Srgrimes 601558Srgrimes if (argc != 5) { 611558Srgrimes (void)fprintf(stderr, 621558Srgrimes "usage: mknod name [b | c] major minor\n"); 631558Srgrimes exit(1); 641558Srgrimes } 651558Srgrimes 661558Srgrimes mode = 0666; 671558Srgrimes if (argv[2][0] == 'c') 681558Srgrimes mode |= S_IFCHR; 691558Srgrimes else if (argv[2][0] == 'b') 701558Srgrimes mode |= S_IFBLK; 711558Srgrimes else { 721558Srgrimes (void)fprintf(stderr, 731558Srgrimes "mknod: node must be type 'b' or 'c'.\n"); 741558Srgrimes exit(1); 751558Srgrimes } 761558Srgrimes 7717302Sjoerg major = strtoul(argv[3], &endp, 0); 7817302Sjoerg if (*endp != '\0' || major >= 256) { 791558Srgrimes (void)fprintf(stderr, 8017302Sjoerg "mknod: bad major number.\n"); 8117302Sjoerg exit(1); 8217302Sjoerg } 8317302Sjoerg minor = strtoul(argv[4], &endp, 0); 8417302Sjoerg if (*endp != '\0') { 8517302Sjoerg (void)fprintf(stderr, 8617302Sjoerg "mknod: bad minor number.\n"); 8717302Sjoerg exit(1); 8817302Sjoerg } 8917302Sjoerg 9017302Sjoerg if (mknod(argv[1], mode, makedev(major, minor)) < 0) { 9117302Sjoerg (void)fprintf(stderr, 921558Srgrimes "mknod: %s: %s\n", argv[1], strerror(errno)); 931558Srgrimes exit(1); 941558Srgrimes } 951558Srgrimes exit(0); 961558Srgrimes} 97