1 /* mknod -- make special files
2 Copyright (C) 1990, 1991 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Usage: mknod [-m mode] [--mode=mode] path {bcu} major minor
19 make a block or character device node
20 mknod [-m mode] [--mode=mode] path p
21 make a FIFO (named pipe)
24 -m, --mode=mode Set the mode of created nodes to MODE, which is
25 symbolic as in chmod and uses the umask as a point of
28 David MacKenzie <djm@ai.mit.edu> */
31 #if defined (CONFIG_BROKETS)
32 /* We use <config.h> instead of "config.h" so that a compilation
33 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
34 (which it would do because it found this file in $srcdir). */
43 #include <sys/types.h>
45 #include "modechange.h"
52 /* The name this program was run with. */
55 /* If non-zero, display usage information and exit. */
58 /* If non-zero, print the version on standard output and exit. */
59 static int show_version
;
61 static struct option
const longopts
[] =
63 {"mode", required_argument
, NULL
, 'm'},
64 {"help", no_argument
, &show_help
, 1},
65 {"version", no_argument
, &show_version
, 1},
74 unsigned short newmode
;
75 struct mode_change
*change
;
79 program_name
= argv
[0];
82 while ((optc
= getopt_long (argc
, argv
, "m:", longopts
, (int *) 0)) != EOF
)
89 symbolic_mode
= optarg
;
98 printf ("%s\n", version_string
);
105 newmode
= 0666 & ~umask (0);
108 change
= mode_compile (symbolic_mode
, 0);
109 if (change
== MODE_INVALID
)
110 error (1, 0, "invalid mode");
111 else if (change
== MODE_MEMORY_EXHAUSTED
)
112 error (1, 0, "virtual memory exhausted");
113 newmode
= mode_adjust (newmode
, change
);
116 if (argc
- optind
!= 2 && argc
- optind
!= 4)
119 /* Only check the first character, to allow mnemonic usage like
120 `mknod /dev/rst0 character 18 0'. */
122 switch (argv
[optind
+ 1][0])
124 case 'b': /* `block' or `buffered' */
126 error (4, 0, "block special files not supported");
128 if (argc
- optind
!= 4)
130 if (mknod (argv
[optind
], newmode
| S_IFBLK
,
131 makedev (atoi (argv
[optind
+ 2]), atoi (argv
[optind
+ 3]))))
132 error (1, errno
, "%s", argv
[optind
]);
136 case 'c': /* `character' */
137 case 'u': /* `unbuffered' */
139 error (4, 0, "character special files not supported");
141 if (argc
- optind
!= 4)
143 if (mknod (argv
[optind
], newmode
| S_IFCHR
,
144 makedev (atoi (argv
[optind
+ 2]), atoi (argv
[optind
+ 3]))))
145 error (1, errno
, "%s", argv
[optind
]);
149 case 'p': /* `pipe' */
151 error (4, 0, "fifo files not supported");
153 if (argc
- optind
!= 2)
155 if (mkfifo (argv
[optind
], newmode
))
156 error (1, errno
, "%s", argv
[optind
]);
171 Usage: %s [options] path {bcu} major minor\n\
172 %s [options] path p\n\
174 [-m mode] [--mode=mode] [--help] [--version]\n",
175 program_name
, program_name
);