mknod: Add support for making FIFOs

This commit is contained in:
Michael Forney 2020-03-01 16:30:56 -08:00
parent ba2f04f391
commit 4542db4e40
2 changed files with 35 additions and 15 deletions

31
mknod.1
View File

@ -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
.Nm
.Op Fl m Ar mode
.Ar name
.Cm p
.Sh DESCRIPTION
.Nm
creates a special device file named
.Ar name
with major number
creates a special file named
.Ar name .
.Pp
The following special file types are supported:
.Bl -tag -width Ds
.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 .
.Ar type
specifies what kind of special file will be created and must be one of:
.Bl -tag -width Ds
.It Ar u | c
A character device.
.It Ar b
A block device.
.El
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl m

19
mknod.c
View File

@ -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]);