mknod.c revision 17302
139213Sgibbs/*
239213Sgibbs * Copyright (c) 1989, 1993
339213Sgibbs *	The Regents of the University of California.  All rights reserved.
439213Sgibbs *
5139743Simp * This code is derived from software contributed to Berkeley by
639213Sgibbs * Kevin Fall.
739213Sgibbs *
839213Sgibbs * Redistribution and use in source and binary forms, with or without
939213Sgibbs * modification, are permitted provided that the following conditions
1039213Sgibbs * are met:
1139213Sgibbs * 1. Redistributions of source code must retain the above copyright
1239213Sgibbs *    notice, this list of conditions and the following disclaimer.
1339213Sgibbs * 2. Redistributions in binary form must reproduce the above copyright
1439213Sgibbs *    notice, this list of conditions and the following disclaimer in the
1539213Sgibbs *    documentation and/or other materials provided with the distribution.
1639213Sgibbs * 3. All advertising materials mentioning features or use of this software
1739213Sgibbs *    must display the following acknowledgement:
1839213Sgibbs *	This product includes software developed by the University of
1939213Sgibbs *	California, Berkeley and its contributors.
2039213Sgibbs * 4. Neither the name of the University nor the names of its contributors
2139213Sgibbs *    may be used to endorse or promote products derived from this software
2239213Sgibbs *    without specific prior written permission.
2339213Sgibbs *
2439213Sgibbs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2539213Sgibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2639213Sgibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2739213Sgibbs * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2839213Sgibbs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2939213Sgibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3039213Sgibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3139213Sgibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3239213Sgibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33139743Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3439213Sgibbs * SUCH DAMAGE.
3539213Sgibbs */
3639213Sgibbs
3739213Sgibbs#ifndef lint
3839213Sgibbsstatic char copyright[] =
3939213Sgibbs"@(#) Copyright (c) 1989, 1993\n\
4039213Sgibbs	The Regents of the University of California.  All rights reserved.\n";
4139213Sgibbs#endif /* not lint */
4239213Sgibbs
4339213Sgibbs#ifndef lint
4439213Sgibbsstatic char sccsid[] = "@(#)mknod.c	8.1 (Berkeley) 6/5/93";
4539213Sgibbs#endif /* not lint */
4639213Sgibbs
4739213Sgibbs#include <sys/types.h>
4839213Sgibbs#include <sys/stat.h>
4950477Speter#include <stdio.h>
5039213Sgibbs
5139213Sgibbsmain(argc, argv)
5239213Sgibbs	int argc;
5339213Sgibbs	char **argv;
5439213Sgibbs{
5539213Sgibbs	extern int errno;
5639213Sgibbs	u_short mode;
5739213Sgibbs	u_int32_t major, minor;
5839213Sgibbs	char *endp;
5939213Sgibbs
6039213Sgibbs	if (argc != 5) {
6139213Sgibbs		(void)fprintf(stderr,
6239213Sgibbs		    "usage: mknod name [b | c] major minor\n");
6339213Sgibbs		exit(1);
6439213Sgibbs	}
6539213Sgibbs
6660767Sken	mode = 0666;
6760767Sken	if (argv[2][0] == 'c')
6860767Sken		mode |= S_IFCHR;
6960767Sken	else if (argv[2][0] == 'b')
7060767Sken		mode |= S_IFBLK;
7160767Sken	else {
7260767Sken		(void)fprintf(stderr,
7360767Sken		    "mknod: node must be type 'b' or 'c'.\n");
7460767Sken		exit(1);
7560767Sken	}
7660767Sken
7760767Sken	major = strtoul(argv[3], &endp, 0);
7860767Sken	if (*endp != '\0' || major >= 256) {
7960767Sken		(void)fprintf(stderr,
8060767Sken		    "mknod: bad major number.\n");
8160767Sken		exit(1);
8260767Sken	}
8360767Sken	minor = strtoul(argv[4], &endp, 0);
8460767Sken	if (*endp != '\0') {
8539213Sgibbs		(void)fprintf(stderr,
8639213Sgibbs		    "mknod: bad minor number.\n");
8739213Sgibbs		exit(1);
8839213Sgibbs	}
8939213Sgibbs
9039213Sgibbs	if (mknod(argv[1], mode, makedev(major, minor)) < 0) {
9139213Sgibbs		(void)fprintf(stderr,
9239213Sgibbs		    "mknod: %s: %s\n", argv[1], strerror(errno));
9339213Sgibbs		exit(1);
9439213Sgibbs	}
9539213Sgibbs	exit(0);
9639213Sgibbs}
9739213Sgibbs