xref: /freebsd/sbin/mknod/mknod.c (revision 8fae3551ec46402adf7ab034cf9e02bcbc7ca8ee)
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;
578fae3551SRodney W. Grimes 	char *strerror();
588fae3551SRodney W. Grimes 
598fae3551SRodney W. Grimes 	if (argc != 5) {
608fae3551SRodney W. Grimes 		(void)fprintf(stderr,
618fae3551SRodney W. Grimes 		    "usage: mknod name [b | c] major minor\n");
628fae3551SRodney W. Grimes 		exit(1);
638fae3551SRodney W. Grimes 	}
648fae3551SRodney W. Grimes 
658fae3551SRodney W. Grimes 	mode = 0666;
668fae3551SRodney W. Grimes 	if (argv[2][0] == 'c')
678fae3551SRodney W. Grimes 		mode |= S_IFCHR;
688fae3551SRodney W. Grimes 	else if (argv[2][0] == 'b')
698fae3551SRodney W. Grimes 		mode |= S_IFBLK;
708fae3551SRodney W. Grimes 	else {
718fae3551SRodney W. Grimes 		(void)fprintf(stderr,
728fae3551SRodney W. Grimes 		    "mknod: node must be type 'b' or 'c'.\n");
738fae3551SRodney W. Grimes 		exit(1);
748fae3551SRodney W. Grimes 	}
758fae3551SRodney W. Grimes 
768fae3551SRodney W. Grimes 	if (mknod(argv[1], mode, makedev(atoi(argv[3]), atoi(argv[4]))) < 0) {
778fae3551SRodney W. Grimes 		(void)fprintf(stderr,
788fae3551SRodney W. Grimes 		    "mknod: %s: %s\n", argv[1], strerror(errno));
798fae3551SRodney W. Grimes 		exit(1);
808fae3551SRodney W. Grimes 	}
818fae3551SRodney W. Grimes 	exit(0);
828fae3551SRodney W. Grimes }
83