commit 4542db4e40f68bafaa4586d89fce4567c2d2b71e
parent ba2f04f391ebc91a1b40f20dd32392afd6d8ac60
Author: Michael Forney <mforney@mforney.org>
Date: Sun, 1 Mar 2020 16:30:56 -0800
mknod: Add support for making FIFOs
Diffstat:
M | mknod.1 | | | 31 | +++++++++++++++++++------------ |
M | mknod.c | | | 19 | ++++++++++++++++--- |
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/mknod.1 b/mknod.1
@@ -8,25 +8,32 @@
.Nm
.Op Fl m Ar mode
.Ar name
-.Ar type
+.Cm b Ns | Ns Cm c Ns | Ns Cm u
.Ar major
.Ar minor
-.Sh DESCRIPTION
.Nm
-creates a special device file named
+.Op Fl m Ar mode
.Ar name
-with major number
-.Ar major ,
-and minor number
-.Ar minor .
-.Ar type
-specifies what kind of special file will be created and must be one of:
+.Cm p
+.Sh DESCRIPTION
+.Nm
+creates a special file named
+.Ar name .
+.Pp
+The following special file types are supported:
.Bl -tag -width Ds
-.It Ar u | c
-A character device.
-.It Ar b
+.It Cm b
A block device.
+.It Cm c | u
+A character device.
+.It Cm p
+A named pipe.
.El
+.Pp
+Block and character devices are created with major number
+.Ar major ,
+and minor number
+.Ar minor .
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl m
diff --git a/mknod.c b/mknod.c
@@ -16,7 +16,9 @@
static void
usage(void)
{
- eprintf("usage: %s [-m mode] name type major minor\n", argv0);
+ eprintf("usage: %s [-m mode] name b|c|u major minor\n"
+ " %s [-m mode] name p\n",
+ argv0, argv0);
}
int
@@ -33,7 +35,7 @@ main(int argc, char *argv[])
usage();
} ARGEND;
- if (argc != 4)
+ if (argc < 2)
usage();
if (strlen(argv[1]) != 1)
@@ -46,12 +48,23 @@ main(int argc, char *argv[])
case 'c':
mode |= S_IFCHR;
break;
+ case 'p':
+ mode |= S_IFIFO;
+ break;
default:
invalid:
eprintf("invalid type '%s'\n", argv[1]);
}
- dev = makedev(estrtonum(argv[2], 0, LLONG_MAX), estrtonum(argv[3], 0, LLONG_MAX));
+ if (S_ISFIFO(mode)) {
+ if (argc != 2)
+ usage();
+ dev = 0;
+ } else {
+ if (argc != 4)
+ usage();
+ dev = makedev(estrtonum(argv[2], 0, LLONG_MAX), estrtonum(argv[3], 0, LLONG_MAX));
+ }
if (mknod(argv[0], mode, dev) == -1)
eprintf("mknod %s:", argv[0]);