diff --git a/bin/Makefile b/bin/Makefile index cfbbfbb1f..1d2a3c8a2 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,7 +1,7 @@ # $NetBSD: Makefile,v 1.22 2007/12/31 15:31:24 ad Exp $ # @(#)Makefile 8.1 (Berkeley) 5/31/93 -SUBDIR= cat date echo ed expr kill ksh ln ls \ +SUBDIR= cat date df echo ed expr kill ksh ln ls \ mkdir pax pwd rm rmdir sync test .include diff --git a/bin/cat/cat.1 b/bin/cat/cat.1 index c60063330..d2e07539d 100644 --- a/bin/cat/cat.1 +++ b/bin/cat/cat.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: cat.1,v 1.32 2006/09/23 11:24:44 wiz Exp $ +.\" $NetBSD: cat.1,v 1.34 2012/08/09 07:26:28 dholland Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" @(#)cat.1 8.3 (Berkeley) 5/2/95 .\" -.Dd September 23, 2006 +.Dd April 6, 2012 .Dt CAT 1 .Os .Sh NAME @@ -54,6 +54,9 @@ A single dash represents the standard input, and may appear multiple times in the .Ar file list. +If no +.Ar file +operands are given, standard input is read. .Pp The word .Dq concatenate @@ -65,7 +68,7 @@ The options are as follows: .It Fl b Implies the .Fl n -option but doesn't number blank lines. +option, but doesn't number blank lines. .It Fl e Implies the .Fl v @@ -139,7 +142,7 @@ to the file truncating .Ar file3 if it already exists. -See the manual page for your shell (i.e., +See the manual page for your shell (e.g., .Xr sh 1 ) for more information on redirection. .Pp diff --git a/bin/cat/cat.c b/bin/cat/cat.c index 5d955e56a..176aeb986 100644 --- a/bin/cat/cat.c +++ b/bin/cat/cat.c @@ -1,4 +1,4 @@ -/* $NetBSD: cat.c,v 1.47 2008/07/20 00:52:39 lukem Exp $ */ +/* $NetBSD: cat.c,v 1.48 2012/03/17 23:35:28 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -44,7 +44,7 @@ __COPYRIGHT( #if 0 static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: cat.c,v 1.47 2008/07/20 00:52:39 lukem Exp $"); +__RCSID("$NetBSD: cat.c,v 1.48 2012/03/17 23:35:28 christos Exp $"); #endif #endif /* not lint */ @@ -295,8 +295,8 @@ raw_cat(int rfd) if (buf == NULL) { struct stat sbuf; - if (fstat(wfd, &sbuf) == 0 && - sbuf.st_blksize > sizeof(fb_buf)) { + if (fstat(wfd, &sbuf) == 0 && sbuf.st_blksize > 0 && + (size_t)sbuf.st_blksize > sizeof(fb_buf)) { bsize = sbuf.st_blksize; buf = malloc(bsize); } diff --git a/bin/df/Makefile b/bin/df/Makefile new file mode 100644 index 000000000..e3c5edb60 --- /dev/null +++ b/bin/df/Makefile @@ -0,0 +1,11 @@ +# $NetBSD: Makefile,v 1.19 2011/08/28 08:20:58 christos Exp $ +# @(#)Makefile 8.3 (Berkeley) 5/8/95 + +.include + +PROG= df + +LDADD+=-lutil +DPADD+=${LIBUTIL} + +.include diff --git a/bin/df/df.1 b/bin/df/df.1 new file mode 100644 index 000000000..7ab3d0c67 --- /dev/null +++ b/bin/df/df.1 @@ -0,0 +1,206 @@ +.\" $NetBSD: df.1,v 1.44 2010/04/05 21:17:28 joerg Exp $ +.\" +.\" Copyright (c) 1989, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)df.1 8.2 (Berkeley) 1/13/92 +.\" +.Dd March 4, 2008 +.Dt DF 1 +.Os +.Sh NAME +.Nm df +.Nd display free disk space +.Sh SYNOPSIS +.Nm +.Op Fl agklmn +.Op Fl G | Fl i | Fl P +.Op Fl t Ar type +.Op Ar file | Ar file_system ... +.Sh DESCRIPTION +.Nm +displays statistics about the amount of free disk space on the specified +.Ar file_system +or on the file system of which +.Ar file +is a part. +By default, all sizes are reported in 512-byte block counts. +If neither a file or a +.Ar file_system +operand is specified, +statistics for all mounted file systems are displayed +(subject to the +.Fl l +and +.Fl t +options below). +.Pp +Note that the printed count of available blocks takes +.Va minfree +into account, and thus will be negative when the number of free blocks +on the filesystem is less than +.Va minfree . +.Pp +The following options are available: +.Bl -tag -width Ds +.It Fl a +Show all mount points, +including those that were mounted with the +.Dv MNT_IGNORE +flag. +.It Fl G +Display all the fields of the structure(s) returned by +.Xr statvfs 2 . +This option cannot be used with the +.Fl i +or +.Fl P +options, and it is modelled after the Solaris +.Fl g +option. +This option will override the +.Fl g , +.Fl h , +.Fl k , +and +.Fl m +options, as well as any setting of +.Ev BLOCKSIZE . +.It Fl g +The +.Fl g +option causes the numbers to be reported in gigabytes (1024*1024*1024 +bytes). +.It Fl h +"Human-readable" output. +Use unit suffixes: Byte, Kilobyte, Megabyte, +Gigabyte, Terabyte, Petabyte, Exabyte in order to reduce the number of +digits to four or less. +.It Fl i +Include statistics on the number of free inodes. +.It Fl k +By default, all sizes are reported in 512-byte block counts. +The +.Fl k +option causes the numbers to be reported in kilobytes (1024 bytes). +.It Fl l +Display statistics only about mounted file systems with the +.Dv MNT_LOCAL +flag set. +If a non-local file system is given as an argument, a +warning is issued and no information is given on that file system. +.It Fl m +The +.Fl m +option causes the numbers to be reported in megabytes (1024*1024 bytes). +.It Fl n +Print out the previously obtained statistics from the file systems. +This option should be used if it is possible that one or more +file systems are in a state such that they will not be able to provide +statistics without a long delay. +When this option is specified, +.Nm +will not request new statistics from the file systems, but will respond +with the possibly stale statistics that were previously obtained. +.It Fl P +Produce output in the following portable format: +.Pp +If both the +.Fl P +and +.Fl k +option are specified, the output will be preceded by the following header +line, formatted to match the data following it: +.Bd -literal +"Filesystem 1024-blocks Used Available Capacity Mounted on\en" +.Ed +.Pp +If the +.Fl P +option is specified without the +.Fl k +options, the output will be preceded by the following header line, +formatted to match the data following it: +.Bd -literal +"Filesystem \*[Lt]blksize\*[Gt]-blocks Used Available Capacity Mounted on\en" +.Ed +.Pp +The header line is followed by data formatted as follows: +.Bd -literal +"%s %d %d %d %d%% %s\en", \*[Lt]file system name\*[Gt], \*[Lt]total space\*[Gt], + \*[Lt]space used\*[Gt], \*[Lt]space free\*[Gt], \*[Lt]percentage used\*[Gt], + \*[Lt]file system root\*[Gt] +.Ed +.Pp +Note that the +.Fl i +option may not be specified with +.Fl P . +.It Fl t Ar type +Is used to indicate the actions should only be taken on +filesystems of the specified type. +More than one type may be specified in a comma-separated list. +The list of filesystem types can be prefixed with +.Dq no +to specify the filesystem types for which action should +.Em not +be taken. +If a file system is given on the command line that is not of +the specified type, a warning is issued and no information is given on +that file system. +.El +.Sh ENVIRONMENT +.Bl -tag -width BLOCKSIZE +.It Ev BLOCKSIZE +If the environment variable +.Ev BLOCKSIZE +is set, and the +.Fl g , +.Fl h , +.Fl k +and +.Fl m +options are not specified, the block counts will be displayed in units of that +size block. +.El +.Sh SEE ALSO +.Xr quota 1 , +.Xr fstatvfs 2 , +.Xr getvfsstat 2 , +.Xr statvfs 2 , +.Xr getbsize 3 , +.Xr getmntinfo 3 , +.Xr fs 5 , +.Xr fstab 5 , +.Xr mount 8 , +.Xr quot 8 , +.Xr tunefs 8 +.Sh HISTORY +A +.Nm +utility appeared in +.At v6 . diff --git a/bin/df/df.c b/bin/df/df.c new file mode 100644 index 000000000..d36157411 --- /dev/null +++ b/bin/df/df.c @@ -0,0 +1,520 @@ +/* $NetBSD: df.c,v 1.90 2012/01/07 18:45:13 christos Exp $ */ + +/* + * Copyright (c) 1980, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( +"@(#) Copyright (c) 1980, 1990, 1993, 1994\ + The Regents of the University of California. All rights reserved."); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: df.c,v 1.90 2012/01/07 18:45:13 christos Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char *getmntpt(const char *); +static void prtstat(struct statvfs *, int); +static int selected(const char *, size_t); +static void maketypelist(char *); +static size_t regetmntinfo(struct statvfs **, size_t); +__dead static void usage(void); +static void prthumanval(int64_t, const char *); +static void prthuman(struct statvfs *, int64_t, int64_t); + +static int aflag, gflag, hflag, iflag, lflag, nflag, Pflag; +static long usize; +static char **typelist; + +int +main(int argc, char *argv[]) +{ + struct stat stbuf; + struct statvfs *mntbuf; + long mntsize; + int ch, i, maxwidth, width; + char *mntpt; + + setprogname(argv[0]); + (void)setlocale(LC_ALL, ""); + + while ((ch = getopt(argc, argv, "aGghiklmnPt:")) != -1) + switch (ch) { + case 'a': + aflag = 1; + break; + case 'g': + hflag = 0; + usize = 1024 * 1024 * 1024; + break; + case 'G': + gflag = 1; + break; + case 'h': + hflag = 1; + usize = 0; + break; + case 'i': + iflag = 1; + break; + case 'k': + hflag = 0; + usize = 1024; + break; + case 'l': + lflag = 1; + break; + case 'm': + hflag = 0; + usize = 1024 * 1024; + break; + case 'n': + nflag = 1; + break; + case 'P': + Pflag = 1; + break; + case 't': + if (typelist != NULL) + errx(EXIT_FAILURE, + "only one -t option may be specified."); + maketypelist(optarg); + break; + case '?': + default: + usage(); + } + + if (gflag && (Pflag || iflag)) + errx(EXIT_FAILURE, + "only one of -G and -P or -i may be specified"); + if (Pflag && iflag) + errx(EXIT_FAILURE, + "only one of -P and -i may be specified"); +#if 0 + /* + * The block size cannot be checked until after getbsize() is called. + */ + if (Pflag && (hflag || (usize != 1024 && usize != 512))) + errx(EXIT_FAILURE, + "non-standard block size incompatible with -P"); +#endif + argc -= optind; + argv += optind; + + mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); + if (mntsize == 0) + err(EXIT_FAILURE, + "retrieving information on mounted file systems"); + + if (*argv == NULL) { + mntsize = regetmntinfo(&mntbuf, mntsize); + } else { + if ((mntbuf = malloc(argc * sizeof(*mntbuf))) == NULL) + err(EXIT_FAILURE, "can't allocate statvfs array"); + mntsize = 0; + for (/*EMPTY*/; *argv != NULL; argv++) { + if (stat(*argv, &stbuf) < 0) { + if ((mntpt = getmntpt(*argv)) == 0) { + warn("%s", *argv); + continue; + } + } else if (S_ISBLK(stbuf.st_mode)) { + if ((mntpt = getmntpt(*argv)) == 0) + mntpt = *argv; + } else + mntpt = *argv; + /* + * Statfs does not take a `wait' flag, so we cannot + * implement nflag here. + */ + if (!statvfs(mntpt, &mntbuf[mntsize])) + if (lflag && + (mntbuf[mntsize].f_flag & MNT_LOCAL) == 0) + warnx("Warning: %s is not a local %s", + *argv, "file system"); + else if + (!selected(mntbuf[mntsize].f_fstypename, + sizeof(mntbuf[mntsize].f_fstypename))) + warnx("Warning: %s mounted as a %s %s", + *argv, + mntbuf[mntsize].f_fstypename, + "file system"); + else + ++mntsize; + else + warn("%s", *argv); + } + } + + maxwidth = 0; + for (i = 0; i < mntsize; i++) { + width = (int)strlen(mntbuf[i].f_mntfromname); + if (width > maxwidth) + maxwidth = width; + } + for (i = 0; i < mntsize; i++) + prtstat(&mntbuf[i], maxwidth); + return 0; +} + +static char * +getmntpt(const char *name) +{ + size_t mntsize, i; + struct statvfs *mntbuf; + + mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); + if (mntsize == 0) + err(EXIT_FAILURE, "Can't get mount information"); + for (i = 0; i < mntsize; i++) { + if (!strcmp(mntbuf[i].f_mntfromname, name)) + return mntbuf[i].f_mntonname; + } + return 0; +} + +static enum { IN_LIST, NOT_IN_LIST } which; + +static int +selected(const char *type, size_t len) +{ + char **av; + + /* If no type specified, it's always selected. */ + if (typelist == NULL) + return 1; + for (av = typelist; *av != NULL; ++av) + if (!strncmp(type, *av, len)) + return which == IN_LIST ? 1 : 0; + return which == IN_LIST ? 0 : 1; +} + +static void +maketypelist(char *fslist) +{ + size_t i; + char *nextcp, **av; + + if ((fslist == NULL) || (fslist[0] == '\0')) + errx(EXIT_FAILURE, "empty type list"); + + /* + * XXX + * Note: the syntax is "noxxx,yyy" for no xxx's and + * no yyy's, not the more intuitive "noyyy,noyyy". + */ + if (fslist[0] == 'n' && fslist[1] == 'o') { + fslist += 2; + which = NOT_IN_LIST; + } else + which = IN_LIST; + + /* Count the number of types. */ + for (i = 1, nextcp = fslist; + (nextcp = strchr(nextcp, ',')) != NULL; i++) + ++nextcp; + + /* Build an array of that many types. */ + if ((av = typelist = malloc((i + 1) * sizeof(*av))) == NULL) + err(EXIT_FAILURE, "can't allocate type array"); + av[0] = fslist; + for (i = 1, nextcp = fslist; + (nextcp = strchr(nextcp, ',')) != NULL; i++) { + *nextcp = '\0'; + av[i] = ++nextcp; + } + /* Terminate the array. */ + av[i] = NULL; +} + +/* + * Make a pass over the filesystem info in ``mntbuf'' filtering out + * filesystem types not in ``fsmask'' and possibly re-stating to get + * current (not cached) info. Returns the new count of valid statvfs bufs. + */ +static size_t +regetmntinfo(struct statvfs **mntbufp, size_t mntsize) +{ + size_t i, j; + struct statvfs *mntbuf; + + if (!lflag && typelist == NULL && aflag) + return nflag ? mntsize : (size_t)getmntinfo(mntbufp, MNT_WAIT); + + mntbuf = *mntbufp; + j = 0; + for (i = 0; i < mntsize; i++) { + if (!aflag && (mntbuf[i].f_flag & MNT_IGNORE) != 0) + continue; + if (lflag && (mntbuf[i].f_flag & MNT_LOCAL) == 0) + continue; + if (!selected(mntbuf[i].f_fstypename, + sizeof(mntbuf[i].f_fstypename))) + continue; + if (nflag) + mntbuf[j] = mntbuf[i]; + else { + struct statvfs layerbuf = mntbuf[i]; + (void)statvfs(mntbuf[i].f_mntonname, &mntbuf[j]); + /* + * If the FS name changed, then new data is for + * a different layer and we don't want it. + */ + if (memcmp(layerbuf.f_mntfromname, + mntbuf[j].f_mntfromname, MNAMELEN)) + mntbuf[j] = layerbuf; + } + j++; + } + return j; +} + +static void +prthumanval(int64_t bytes, const char *pad) +{ + char buf[6]; + + (void)humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), + bytes, "", HN_AUTOSCALE, + HN_B | HN_NOSPACE | HN_DECIMAL); + + (void)printf("%s %6s", pad, buf); +} + +static void +prthuman(struct statvfs *sfsp, int64_t used, int64_t bavail) +{ + + prthumanval((int64_t)(sfsp->f_blocks * sfsp->f_frsize), " "); + prthumanval((int64_t)(used * sfsp->f_frsize), " "); + prthumanval((int64_t)(bavail * sfsp->f_frsize), " "); +} + +/* + * Convert statvfs returned filesystem size into BLOCKSIZE units. + * Attempts to avoid overflow for large filesystems. + */ +#define fsbtoblk(num, fsbs, bs) \ + (((fsbs) != 0 && (uint64_t)(fsbs) < (uint64_t)(bs)) ? \ + (int64_t)(num) / (int64_t)((bs) / (fsbs)) : \ + (int64_t)(num) * (int64_t)((fsbs) / (bs))) + +/* + * Print out status about a filesystem. + */ +static void +prtstat(struct statvfs *sfsp, int maxwidth) +{ + static long blocksize; + static int headerlen, timesthrough; + static const char *header; + static const char full[] = "100"; + static const char empty[] = " 0"; + int64_t used, availblks, inodes; + int64_t bavail; + char pb[64]; + + if (gflag) { + /* + * From SunOS-5.6: + * + * /var (/dev/dsk/c0t0d0s3 ): 8192 block size 1024 frag size + * 984242 total blocks 860692 free blocks 859708 available 249984 total files + * 248691 free files 8388611 filesys id + * ufs fstype 0x00000004 flag 255 filename length + * + */ + (void)printf("%10s (%-12s): %7ld block size %12ld frag size\n", + sfsp->f_mntonname, sfsp->f_mntfromname, + sfsp->f_iosize, /* On UFS/FFS systems this is + * also called the "optimal + * transfer block size" but it + * is of course the file + * system's block size too. + */ + sfsp->f_bsize); /* not so surprisingly the + * "fundamental file system + * block size" is the frag + * size. + */ + (void)printf("%10" PRId64 " total blocks %10" PRId64 + " free blocks %10" PRId64 " available\n", + (uint64_t)sfsp->f_blocks, (uint64_t)sfsp->f_bfree, + (uint64_t)sfsp->f_bavail); + (void)printf("%10" PRId64 " total files %10" PRId64 + " free files %12lx filesys id\n", + (uint64_t)sfsp->f_ffree, (uint64_t)sfsp->f_files, + sfsp->f_fsid); + (void)printf("%10s fstype %#15lx flag %17ld filename " + "length\n", sfsp->f_fstypename, sfsp->f_flag, + sfsp->f_namemax); + (void)printf("%10lu owner %17" PRId64 " syncwrites %12" PRId64 + " asyncwrites\n\n", (unsigned long)sfsp->f_owner, + sfsp->f_syncwrites, sfsp->f_asyncwrites); + + /* + * a concession by the structured programming police to the + * indentation police.... + */ + return; + } + if (maxwidth < 12) + maxwidth = 12; + if (++timesthrough == 1) { + switch (blocksize = usize) { + case 1024: + header = Pflag ? "1024-blocks" : "1K-blocks"; + headerlen = (int)strlen(header); + break; + case 1024 * 1024: + header = "1M-blocks"; + headerlen = (int)strlen(header); + break; + case 1024 * 1024 * 1024: + header = "1G-blocks"; + headerlen = (int)strlen(header); + break; + default: + if (hflag) { + header = "Size"; + headerlen = (int)strlen(header); + } else + header = getbsize(&headerlen, &blocksize); + break; + } + if (Pflag) { + /* + * either: + * "Filesystem 1024-blocks Used Available Capacity Mounted on\n" + * or: + * "Filesystem 512-blocks Used Available Capacity Mounted on\n" + */ + if (blocksize != 1024 && blocksize != 512) + errx(EXIT_FAILURE, + "non-standard block size incompatible with -P"); + (void)printf("Filesystem %s Used Available Capacity " + "Mounted on\n", header); + } else { + (void)printf("%-*.*s %s Used Avail %%Cap", + maxwidth - (headerlen - 10), + maxwidth - (headerlen - 10), + "Filesystem", header); + if (iflag) + (void)printf(" iUsed iAvail %%iCap"); + (void)printf(" Mounted on\n"); + } + } + used = sfsp->f_blocks - sfsp->f_bfree; + bavail = sfsp->f_bfree - sfsp->f_bresvd; + availblks = bavail + used; + if (Pflag) { + assert(hflag == 0); + assert(blocksize > 0); + /* + * "%s %d %d %d %s %s\n", , , + * , , , + * + */ + (void)printf("%s %" PRId64 " %" PRId64 " %" PRId64 " %s%% %s\n", + sfsp->f_mntfromname, + fsbtoblk(sfsp->f_blocks, sfsp->f_frsize, blocksize), + fsbtoblk(used, sfsp->f_frsize, blocksize), + fsbtoblk(bavail, sfsp->f_frsize, blocksize), + availblks == 0 ? full : strspct(pb, sizeof(pb), used, + availblks, 0), sfsp->f_mntonname); + /* + * another concession by the structured programming police to + * the indentation police.... + * + * Note iflag cannot be set when Pflag is set. + */ + return; + } + + (void)printf("%-*.*s ", maxwidth, maxwidth, sfsp->f_mntfromname); + + if (hflag) + prthuman(sfsp, used, bavail); + else + (void)printf("%10" PRId64 " %10" PRId64 " %10" PRId64, + fsbtoblk(sfsp->f_blocks, sfsp->f_frsize, blocksize), + fsbtoblk(used, sfsp->f_frsize, blocksize), + fsbtoblk(bavail, sfsp->f_frsize, blocksize)); + (void)printf(" %3s%%", + availblks == 0 ? full : + strspct(pb, sizeof(pb), used, availblks, 0)); + if (iflag) { + inodes = sfsp->f_files; + used = inodes - sfsp->f_ffree; + (void)printf(" %8jd %8jd %3s%%", + (intmax_t)used, (intmax_t)sfsp->f_ffree, + inodes == 0 ? (used == 0 ? empty : full) : + strspct(pb, sizeof(pb), used, inodes, 0)); + } + (void)printf(" %s\n", sfsp->f_mntonname); +} + +static void +usage(void) +{ + + (void)fprintf(stderr, + "Usage: %s [-aGgln] [-hkm|-ihkm|-Pk] [-t type] [file | " + "file_system ...]\n", + getprogname()); + exit(1); + /* NOTREACHED */ +} diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c index d3d69a45f..164740a26 100644 --- a/bin/pax/ar_io.c +++ b/bin/pax/ar_io.c @@ -456,13 +456,8 @@ ar_close(void) /* mimic cpio's block count first */ if (frmt && strcmp(NM_CPIO, argv0) == 0) { -#ifdef __minix - (void)fprintf(listf, "%d blocks\n", - (rdcnt ? rdcnt : wrcnt) / 5120); -#else (void)fprintf(listf, OFFT_F " blocks\n", (rdcnt ? rdcnt : wrcnt) / 5120); -#endif } ar_summary(0); diff --git a/commands/DESCRIBE/DESCRIBE.sh b/commands/DESCRIBE/DESCRIBE.sh index 63560ae36..5ad21eb0c 100644 --- a/commands/DESCRIBE/DESCRIBE.sh +++ b/commands/DESCRIBE/DESCRIBE.sh @@ -126,10 +126,6 @@ do ;; 4,125) des="video output" dev=video ;; - 4,126) des="auxiliary input" dev=kbdaux - ;; - 4,127) des="keyboard input" dev=kbd - ;; 4,12[89]|4,1[3-8]?|4,19[01]) p=`expr \\( $minor - 128 \\) / 16 | tr '0123' 'pqrs'` n=`expr $minor % 16` @@ -196,6 +192,40 @@ do 18,0) des="UNIX domain socket" dev=uds ;; + 5[6-9],0|6[0-3],0) + drive=`expr $major - 56` + des="vnode disk $drive" dev=vnd$drive + ;; + 5[6-9],[1-4]|6[0-3],[1-4]) + drive=`expr $major - 56` + par=`expr $minor - 1` + des="vnode disk $drive partition $par" dev=vnd${drive}p${par} + ;; + 5[6-9],12[89]|5[6-9],13[0-9]|5[6-9],14[0-3]|6[0-3],12[89]|5[6-9],13[0-9]|5[6-9],14[0-3]) + drive=`expr $major - 56` + par=`expr \\( \\( $minor - 128 \\) / 4 \\) % 4` + sub=`expr \\( $minor - 128 \\) % 4` + des="vnode disk $drive partition $par slice $sub" + dev=vnd${drive}p${par}s${sub} + ;; + 64,0) + des="keyboard input multiplexer" + dev=kbdmux + ;; + 64,[1-4]) + n=`expr $minor - 1` + des="keyboard input $n" + dev=kbd$n + ;; + 64,64) + des="mouse input multiplexer" + dev=mousemux + ;; + 64,6[5-8]) + n=`expr $minor - 65` + des="mouse input $n" + dev=mouse$n + ;; BAD,BAD) des= dev= ;; diff --git a/commands/MAKEDEV/MAKEDEV.8 b/commands/MAKEDEV/MAKEDEV.8 new file mode 100644 index 000000000..51e0063d8 --- /dev/null +++ b/commands/MAKEDEV/MAKEDEV.8 @@ -0,0 +1,57 @@ +.Dd October 4, 2013 +.Dt MAKEDEV 8 +.Os +.Sh NAME +.Nm MAKEDEV, DESCRIBE +.Nd make/describe device files +.Sh SYNOPSIS +.Nm MAKEDEV +.Op Fl n | Fl m +.Op Fl r | Fl s +.Op key ... +.Nm DESCRIBE +.Op device ... +.Sh DESCRIPTION +.Nm MAKEDEV +may be used to create the device files normally found in the /dev directory. +.Nm MAKEDEV +knows about all supported devices and will create them in the current +directory with the proper owner and mode. For many devices +.Nm MAKEDEV +will not only create the device you want, but also the devices related +to it that you will probably want too. Naming one floppy device will +create all floppy devices for the same drive for instance. +.Pp +The options are as follows: +.Bl -tag -width Xxxexcludexfilexx +.It Fl n +echo the commands it would execute when you call it without that flag. +.It Fl m +echo +.Nm mtree(8) +formatted lines instead of creating the device nodes. +.It Fl r +Restricted set of devices. This set is used when generating the ramdisk. +.It Fl s +Standard set of devices. This set is used when popluating /dev. +.El +.Pp +.Ar key +arguments are simply the names of the devices you want to create. Call +.Nm MAKEDEV +without arguments to see a list of keys that it understands. +.Pp +The command +.Nm DESCRIBE +will give you a one-line description of a given device. By default It +will list all devices in /dev. +.Sh "SEE ALSO" +.Xr dev 4 , +.Xr mknod 8 +.Sh BUGS +The eagerness of +.Nm MAKEDEV +to create devices may cause many "File exists" errors from +.Nm mknod . +.Sh AUTHORS +Written by Kees J. Bot (kjb@cs.vu.nl) and Lionel A. Sambuc (lionel@minix3.org) diff --git a/commands/MAKEDEV/MAKEDEV.sh b/commands/MAKEDEV/MAKEDEV.sh old mode 100644 new mode 100755 index 9a4c1a9cd..30b8ae76a --- a/commands/MAKEDEV/MAKEDEV.sh +++ b/commands/MAKEDEV/MAKEDEV.sh @@ -1,43 +1,115 @@ #!/bin/sh # # MAKEDEV 3.3 - Make special devices. Author: Kees J. Bot +# 3.4 - Rewritten to allow mtree line to be printed, Lionel A. Sambuc +# also use getopt for argument parsing +umask 077 -case $1 in --n) e=echo; shift ;; # Just echo when -n is given. -*) e= -esac +MTREE=false +STD=false +RAMDISK=false +ECHO= +EXIT=0 -case $#:$1 in -1:std) # Standard devices. - set -$- mem fd0 fd1 fd0p0 fd1p0 \ - c0d0 c0d0p0 c0d0p0s0 c0d1 c0d1p0 c0d1p0s0 \ - c0d2 c0d2p0 c0d2p0s0 c0d3 c0d3p0 c0d3p0s0 \ - c0d4 c0d4p0 c0d4p0s0 c0d5 c0d5p0 c0d5p0s0 \ - c0d6 c0d6p0 c0d6p0s0 c0d7 c0d7p0 c0d7p0s0 \ - c1d0 c1d0p0 c1d0p0s0 c1d1 c1d1p0 c1d1p0s0 \ - c1d2 c1d2p0 c1d2p0s0 c1d3 c1d3p0 c1d3p0s0 \ - c1d4 c1d4p0 c1d4p0s0 c1d5 c1d5p0 c1d5p0s0 \ - c1d6 c1d6p0 c1d6p0s0 c1d7 c1d7p0 c1d7p0s0 \ - tty ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03 \ - ttyp0 ttyp1 ttyp2 ttyp3 ttyp4 ttyp5 ttyp6 ttyp7 ttyp8 ttyp9 \ - ttypa ttypb ttypc ttypd ttype ttypf \ - ttyq0 ttyq1 ttyq2 ttyq3 ttyq4 ttyq5 ttyq6 ttyq7 ttyq8 ttyq9 \ - ttyqa ttyqb ttyqc ttyqd ttyqe ttyqf \ - eth klog random uds filter fbd hello fb0 \ - i2c-1 i2c-2 i2c-3 \ - eepromb1s50 eepromb1s51 eepromb1s52 eepromb1s53 \ - eepromb1s54 eepromb1s55 eepromb1s56 eepromb1s57 \ - eepromb2s50 eepromb2s51 eepromb2s52 eepromb2s53 \ - eepromb2s54 eepromb2s55 eepromb2s56 eepromb2s57 \ - eepromb3s50 eepromb3s51 eepromb3s52 eepromb3s53 \ - eepromb3s54 eepromb3s55 eepromb3s56 eepromb3s57 \ - tsl2550b1s39 tsl2550b2s39 tsl2550b3s39 \ - sht21b1s40 sht21b2s40 sht21b3s40 \ +# console => lp tty log +# boot => kmem mem null ram zero +RAMDISK_DEVICES=" + boot + console + input + c0d0 c0d0p0 c0d0p0s0 c0d1 c0d1p0 c0d1p0s0 + c0d2 c0d2p0 c0d2p0s0 c0d3 c0d3p0 c0d3p0s0 + c0d4 c0d4p0 c0d4p0s0 c0d5 c0d5p0 c0d5p0s0 + c0d6 c0d6p0 c0d6p0s0 c0d7 c0d7p0 c0d7p0s0 + c1d0 c1d0p0 c1d0p0s0 c1d1 c1d1p0 c1d1p0s0 + c1d2 c1d2p0 c1d2p0s0 c1d3 c1d3p0 c1d3p0s0 + c1d4 c1d4p0 c1d4p0s0 c1d5 c1d5p0 c1d5p0s0 + c1d6 c1d6p0 c1d6p0s0 c1d7 c1d7p0 c1d7p0s0 + fd0 fd1 fd0p0 fd1p0 + ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03 + ttyp0 ttyp1 ttyp2 ttyp3 ttyp4 ttyp5 ttyp6 ttyp7 ttyp8 ttyp9 + ttypa ttypb ttypc ttypd ttype ttypf + ttyq0 ttyq1 ttyq2 ttyq3 ttyq4 ttyq5 ttyq6 ttyq7 ttyq8 ttyq9 + ttyqa ttyqb ttyqc ttyqd ttyqe ttyqf +" + +#eth => ip tcp udp +STD_DEVICES=" + ${RAMDISK_DEVICES} bmp085b1s77 bmp085b2s77 bmp085b3s77 - ;; -0:|1:-\?) - cat >&2 <&2 <&2 - ex=1 - esac done -exit $ex +if [ ${STD} = "yes" ] +then + DEVICES=${STD_DEVICES} +elif [ ${RAMDISK} = "yes" ] +then + DEVICES=${RAMDISK_DEVICES} +else + while [ $OPTIND -gt 1 ] + do + shift + OPTIND=$((${OPTIND} - 1)) + done + while [ ! -z "$1" ] + do + DEVICES="${DEVICES} $1" + shift + done +fi + +for dev in ${DEVICES} +do + # Reset the defaults + uname=root + gname=operator + permissions=600 + + case ${dev} in + c0*) major=3 ;; + c1*) major=8 ;; + c2*) major=10 ;; + c3*) major=12 ;; + vnd*) # Whole vnode disk devices. + disk=`expr ${dev} : '...\\(.\\)'` + major=`expr ${disk} + 56` + ;; + esac + + # The following is lexicographicaly ordered + case ${dev} in + audio|mixer) + # Audio devices. + makedev audio c 13 0 ${uname} ${gname} 666 + makedev mixer c 13 1 ${uname} ${gname} 666 + ;; + bmp085b[1-3]s77) + # Weather Cape: temperature & pressure sensor + bus=`expr ${dev} : 'bmp085b\\(.*\\)s77'` #bus number + major=`expr ${bus} + 52` + + makedev bmp085b${bus}s77 c ${major} 0 ${uname} ${gname} 444 + ;; + c[0-3]d[0-7]) + # Whole disk devices. + disk=`expr ${dev} : '...\\(.\\)'` + minor=`expr ${disk} '*' 5` + + makedev ${dev} b ${major} ${minor} ${uname} ${gname} ${permissions} + ;; + c[0-3]d[0-7]p[0-3]) + # Disk primary partitions. + prefix=`expr ${dev} : '\\(.*\\).'` + disk=`expr ${dev} : '...\\(.\\)'` + + for p in 0 1 2 3 + do + minor=`expr ${disk} '*' 5 + 1 + ${p}` + makedev ${prefix}${p} b ${major} ${minor} \ + ${uname} ${gname} ${permissions} + done + ;; + c[0-3]d[0-7]p[0-3]s[0-3]) + # Disk subpartition. + prefix=`expr ${dev} : '\\(.*\\)...'` + disk=`expr ${dev} : '...\\(.\\)'` + + for p in 0 1 2 3 + do + for s in 0 1 2 3 + do + minor=`expr 128 + ${disk} '*' 16 + ${p} '*' 4 + ${s}` + makedev ${prefix}${p}s${s} b ${major} ${minor} \ + ${uname} ${gname} ${permissions} + done + done + ;; + c[0-3]t[0-7]|c[0-3]t[0-7]n) + # Tape devices. + prefix=`expr ${dev} : '\\(....\\)'` + tape=`expr ${dev} : '...\\(.\\)'` + minor=`expr 64 + ${tape} '*' 2` + + makedev ${prefix}n c ${major} ${minor} ${uname} ${gname} 660 + makedev ${prefix} c ${major} `expr ${minor} + 1` ${uname} ${gname} 660 + ;; + console|lp|tty|log|video) + # Console, line printer, anonymous tty, diagnostics device, video. + makedev console c 4 0 ${uname} tty ${permissions} + makedev tty c 5 0 ${uname} ${gname} 666 + makedev lp c 6 0 daemon daemon 200 + makedev log c 4 15 ${uname} ${gname} 222 + makedev video c 4 125 ${uname} ${gname} ${permissions} + ;; + eepromb[1-3]s5[0-7]) + # cat24c256 driver + bus=`expr ${dev} : 'eepromb\\(.*\\)s'` + # configurable part of slave addr + slave_low=`expr ${dev} : 'eepromb.s5\\(.*\\)'` + major=`expr ${bus} '*' 8 + ${slave_low} + 17` + + makedev eepromb${bus}s5${slave_low} b ${major} 0 ${uname} ${gname} ${permissions} + ;; + eth|ip|tcp|udp|eth0|ip0|tcp0|udp0) + # TCP/IP devices. + makedev ipstat c 7 0 ${uname} ${gname} 666 + makedev eth0 c 7 1 ${uname} ${gname} ${permissions} + makedev ip0 c 7 2 ${uname} ${gname} ${permissions} + makedev tcp0 c 7 3 ${uname} ${gname} 666 + makedev udp0 c 7 4 ${uname} ${gname} 666 + + # Default interface + makedev eth c 7 1 ${uname} ${gname} ${permissions} + makedev ip c 7 2 ${uname} ${gname} ${permissions} + makedev tcp c 7 3 ${uname} ${gname} 666 + makedev udp c 7 4 ${uname} ${gname} 666 + ;; + fb0) + # Framebuffer driver + makedev ${dev} c 19 0 ${uname} ${gname} 644 + ;; + fbd) + # Faulty block device driver + makedev ${dev} b 14 0 ${uname} ${gname} ${permissions} + ;; + fd[0-3]) + # Floppy disk drive N has minor N. + minor=`expr ${dev} : '..\\(.\\)'` + + makedev ${dev} b 2 ${minor} ${uname} ${gname} 666 + ;; + fd[0-3]p[0-3]) + # Floppy disk partitions. + prefix=`expr ${dev} : '\\(.*\\).'` + drive=`expr ${dev} : '..\\(.\\)'` + + for p in 0 1 2 3 + do + minor=`expr 112 + ${drive} + ${p} '*' 4` + makedev ${prefix}${p} b 2 ${minor} \ + ${uname} ${gname} 666 + done + ;; + filter) + # Filter driver + makedev ${dev} b 11 0 ${uname} ${gname} ${permissions} + ;; + hello) + # Hello driver + makedev ${dev} c 17 0 ${uname} ${gname} 644 + ;; + i2c-[1-3]) + # i2c driver + bus=`expr ${dev} : '....\\(.*\\)'` # bus number + # least significant digit of major + major_low=`expr ${dev} : '....\\(.*\\)'` + major_low=`expr ${major_low} - 1` + + makedev "i2c-${bus}" c 2${major_low} 0 ${uname} ${gname} ${permissions} + ;; + input) + # Input server + makedev kbdmux c 64 0 ${uname} ${gname} ${permissions} + makedev mousemux c 64 64 ${uname} ${gname} ${permissions} + + for n in 0 1 2 3 + do + minor_keyboard=`expr ${n} + 1` + minor_mouse=`expr ${n} + 65` + + makedev kbd${n} c 64 ${minor_keyboard} ${uname} ${gname} ${permissions} + makedev mouse${n} c 64 ${minor_mouse} ${uname} ${gname} ${permissions} + done + ;; + klog) + # Logging device. + makedev ${dev} c 15 0 ${uname} ${gname} ${permissions} + ;; + pc[0-3]|at[0-3]|qd[0-3]|ps[0-3]|pat[0-3]|qh[0-3]|PS[0-3]) + # Obsolete density locked floppy disk drive n. + drive=`expr ${dev} : '.*\\(.\\)'` + minor=${drive} + + for prefix in pc at qd ps pat qh PS + do + makedev ${prefix}${drive} b 2 ${minor} \ + ${uname} ${gname} 666 + minor=`expr ${minor} + 4` + done + ;; + ram|mem|kmem|null|boot|zero|imgrd) + # Memory devices. + makedev ram b 1 0 ${uname} kmem ${permissions} + makedev mem c 1 1 ${uname} kmem 640 + makedev kmem c 1 2 ${uname} kmem 640 + makedev null c 1 3 ${uname} kmem 666 + makedev boot b 1 4 ${uname} kmem ${permissions} + makedev zero c 1 5 ${uname} kmem 644 + makedev imgrd b 1 6 ${uname} kmem ${permissions} + + for n in 0 1 2 3 4 5 + do + minor=`expr ${n} + 7` + + makedev ram${n} b 1 ${minor} ${uname} kmem ${permissions} + done + ;; + random|urandom) + # Random data generator. + makedev random c 16 0 ${uname} ${gname} 644 + makedev urandom c 16 0 ${uname} ${gname} 644 + ;; + sht21b[1-3]s40) + # Weather Cape: relative humidity & temperature sensor + bus=`expr ${dev} : 'sht21b\\(.*\\)s40'` + major=`expr ${bus} + 49` + + makedev sht21b${bus}s40 c ${major} 0 ${uname} ${gname} 444 + ;; + tsl2550b[1-3]s39) + # Weather Cape: ambient light sensor + bus=`expr ${dev} : 'tsl2550b\\(.*\\)s39'` + major=`expr ${bus} + 46` + + makedev tsl2550b${bus}s39 c ${major} 0 ${uname} ${gname} 444 + ;; + tty0[0-3]) + # Serial lines. + line=`expr ${dev} : '.*\\(.\\)'` + minor=`expr ${line} + 16` + + makedev ${dev} c 4 ${minor} ${uname} tty 666 + ;; + tty[p-s][0-9a-f]|pty[p-s][0-9a-f]) + # Pseudo ttys. + dev=`expr ${dev} : '...\\(..\\)'` + group=`expr ${dev} : '\\(.\\)'` + group=`echo ${group} | tr 'pqrs' '0123'` + pty=`expr ${dev} : '.\\(.\\)'` + case ${pty} in + [a-f]) pty=1`/bin/echo ${pty} | tr 'abcdef' '012345'` + esac + minor_tty=`expr ${group} '*' 16 + ${pty} + 128` + minor_pty=`expr ${group} '*' 16 + ${pty} + 192` + + makedev tty${dev} c 4 ${minor_tty} ${uname} tty 666 + makedev pty${dev} c 4 ${minor_pty} ${uname} tty 666 + ;; + ttyc[1-7]) + # Virtual consoles. + minor=`expr ${dev} : '....\\(.*\\)'` + + makedev ${dev} c 4 ${minor} ${uname} tty ${permissions} + ;; + uds) + # Unix domain sockets device + makedev ${dev} c 18 0 ${uname} ${gname} 666 + ;; + vnd[0-7]) + # Whole vnode disk devices. + makedev ${dev} b ${major} 0 ${uname} ${gname} ${permissions} + ;; + vnd[0-7]p[0-3]) + # Vnode disk primary partitions. + prefix=`expr ${dev} : '\\(.*\\).'` + disk=`expr ${dev} : '...\\(.\\)'` + + for p in 0 1 2 3 + do + minor=`expr 1 + ${p}` + + makedev ${prefix}${p} b ${major} ${minor} \ + ${uname} ${gname} ${permissions} + done + ;; + vnd[0-7]p[0-3]s[0-3]) + # Vnode disk subpartition. + prefix=`expr ${dev} : '\\(.*\\)...'` + disk=`expr ${dev} : '...\\(.\\)'` + + for p in 0 1 2 3 + do + for s in 0 1 2 3 + do + minor=`expr 128 + ${p} '*' 4 + ${s}` + + makedev ${prefix}${p}s${s} b ${major} ${minor} \ + ${uname} ${gname} ${permissions} + done + done + ;; + *) + echo "$0: don't know about ${dev}" >&2 + EXIT=1 + esac +done + +exit $EXIT diff --git a/commands/MAKEDEV/Makefile b/commands/MAKEDEV/Makefile index 93040ea76..9a9ac5d1d 100644 --- a/commands/MAKEDEV/Makefile +++ b/commands/MAKEDEV/Makefile @@ -1,4 +1,4 @@ SCRIPTS= MAKEDEV.sh -MAN= +MAN= MAKEDEV.8 .include diff --git a/commands/Makefile b/commands/Makefile index 4754ecbf4..8889be646 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -6,11 +6,11 @@ SUBDIR= add_route arp ash at backup btrace \ cawf cd cdprobe cpp \ chmod chown ci cleantmp cmp co \ compress cp crc cron crontab \ - dd decomp16 DESCRIBE devmand devsize df dhcpd \ - dhrystone diff diskctl dumpcore \ + dd decomp16 DESCRIBE devmand devsize dhcpd \ + dhrystone diff diskctl \ eject factor fbdctl \ find fix format fortune fsck.mfs \ - gcore gcov-pull getty grep host \ + gcov-pull getty grep host \ hostaddr id ifconfig ifdef \ intr ipcrm ipcs irdpd isoread last \ less loadkeys loadramdisk logger look lp \ @@ -27,14 +27,16 @@ SUBDIR= add_route arp ash at backup btrace \ stty svclog svrctl swifi synctree sysenv \ syslogd tail tcpd tcpdp tcpstat telnet \ telnetd term termcap tget time touch \ - truncate udpstat umount uname \ + truncate udpstat umount \ unstack update uud uue version vol \ whereis which writeisofs fetch \ zdump zmodem pkgin_cd pkgin_all \ worldstone updateboot update_bootcfg \ atnormalize dosread fdisk loadfont \ autopart part partition playwave \ - recwave repartition screendump + recwave repartition screendump \ + command echo expr false getopts read test true \ + umask wait .if ${MACHINE_ARCH} == "earm" SUBDIR+= eepromread diff --git a/commands/ash/Makefile b/commands/ash/Makefile index 886f17533..bcf56e683 100644 --- a/commands/ash/Makefile +++ b/commands/ash/Makefile @@ -41,7 +41,7 @@ CPPFLAGS+= -I. -I${.CURDIR} # A. Generate C tools used to build ash .for tool in init nodes signames syntax ${.OBJDIR}/mk${tool}: ${.CURDIR}/mk${tool}.c - ${HOST_CC} ${.ALLSRC} -o ${.TARGET} + ${HOST_CC} ${HOST_CFLAGS} ${HOST_CPPFLAGS} ${.ALLSRC} -o ${.TARGET} CLEANFILES+= ${.OBJDIR}/mk${tool} .endfor diff --git a/commands/cd/Makefile b/commands/cd/Makefile index 35a04b028..34d874c00 100644 --- a/commands/cd/Makefile +++ b/commands/cd/Makefile @@ -2,17 +2,4 @@ SCRIPTS= cd.sh BINDIR= /bin MAN= -LINKS+= ${BINDIR}/cd ${BINDIR}/[ -LINKS+= ${BINDIR}/cd ${BINDIR}/command -LINKS+= ${BINDIR}/cd ${BINDIR}/echo -LINKS+= ${BINDIR}/cd ${BINDIR}/expr -LINKS+= ${BINDIR}/cd ${BINDIR}/false -LINKS+= ${BINDIR}/cd ${BINDIR}/getopts -LINKS+= ${BINDIR}/cd ${BINDIR}/read -LINKS+= ${BINDIR}/cd ${BINDIR}/test -LINKS+= ${BINDIR}/cd ${BINDIR}/true -LINKS+= ${BINDIR}/cd ${BINDIR}/umask -LINKS+= ${BINDIR}/cd ${BINDIR}/wait - - .include diff --git a/commands/cd/cd.sh b/commands/cd/cd.sh deleted file mode 100644 index e1f28e46a..000000000 --- a/commands/cd/cd.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# -# cd 1.3 - equivalents for normally builtin commands. Author: Kees J. Bot - -case $0 in -*/*) command="`expr "$0" : '.*/\(.*\)'`" - ;; -*) command="$0" -esac - -"$command" "$@" diff --git a/commands/cd/cd.sh b/commands/cd/cd.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/cd/cd.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/command/Makefile b/commands/command/Makefile new file mode 100644 index 000000000..4d4f28bde --- /dev/null +++ b/commands/command/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= command.sh +BINDIR= /bin +MAN= + +.include diff --git a/commands/command/command.sh b/commands/command/command.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/command/command.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/df/Makefile b/commands/df/Makefile deleted file mode 100644 index a77a7bffa..000000000 --- a/commands/df/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -PROG= df -MAN= - -.include diff --git a/commands/df/df.c b/commands/df/df.c deleted file mode 100644 index be07620b8..000000000 --- a/commands/df/df.c +++ /dev/null @@ -1,237 +0,0 @@ -/* df - disk free block printout Author: Andy Tanenbaum - * - * 91/04/30 Kees J. Bot (kjb@cs.vu.nl) - * Map filename arguments to the devices they live on. - * Changed output to show percentages. - * - * 92/12/12 Kees J. Bot - * Posixized. (Almost, the normal output is in kilobytes, it should - * be 512-byte units. 'df -P' and 'df -kP' are as it should be.) - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct mtab { /* List of mounted devices from /etc/mtab. */ - struct mtab *next; - dev_t device; - char *devname; - char *mountpoint; -} *mtab= NULL; - -struct mtab *searchtab(char *name); -static void readmtab(const char *type); -int df(const struct mtab *mt); - -int iflag= 0; /* Focus on inodes instead of blocks. */ -int Pflag= 0; /* Posix standard output. */ -int kflag= 0; /* Output in kilobytes instead of 512 byte units for -P. */ -int istty; /* isatty(1) */ - -void usage(void) -{ - fprintf(stderr, "Usage: df [-ikP] [-t type] [device]...\n"); - exit(1); -} - -int unitsize; - -int main(int argc, char *argv[]) -{ - int i; - struct mtab *mt; - char *type= "dev"; - int ex= 0; - - while (argc > 1 && argv[1][0] == '-') { - char *opt= argv[1]+1; - - while (*opt != 0) { - switch (*opt++) { - case 'i': iflag= 1; break; - case 'k': kflag= 1; break; - case 'P': Pflag= 1; break; - case 't': - if (argc < 3) usage(); - type= argv[2]; - argv++; - argc--; - break; - default: - usage(); - } - } - argc--; - argv++; - } - - istty= isatty(1); - - readmtab(type); - - if(!Pflag || (Pflag && kflag)) unitsize = 1024; - else unitsize = 512; - - if (Pflag) { - if (!iflag) - printf("\ -Filesystem %4d-blocks Used Available Capacity Mounted on\n", - unitsize); - else - printf("\ -Filesystem Inodes IUsed IFree %%IUsed Mounted on\n" - ); - } else { - printf("%s\n", !iflag ? "\ -Filesystem Size (kB) Free Used % Files% Mounted on" : "\ -Filesystem Files Free Used % BUsed% Mounted on" - ); - } - - if (argc == 1) { - for (mt= mtab; mt != NULL; mt= mt->next) ex |= df(mt); - } else { - for (i = 1; i < argc; i++) ex |= df(searchtab(argv[i])); - } - exit(ex); -} - -static void readmtab(const char *type) -/* Turn the mounted file table into a list. */ -{ - struct mtab **amt= &mtab, *new; - struct stat st; - char devname[PATH_MAX], mountpoint[PATH_MAX], version[MNTNAMELEN], - rw_flag[MNTFLAGLEN]; - - if (load_mtab("df") < 0) exit(1); - - while (get_mtab_entry(devname, mountpoint, version, rw_flag), - devname[0] != 0) { - if (strcmp(type, "dev") != 0 && strcmp(type, version) != 0) continue; - - /* Make new list cell. */ - if ((new= (struct mtab *) malloc(sizeof(*new))) == NULL - || (new->devname= (char *) malloc(strlen(devname) + 1)) == NULL - || (new->mountpoint= (char *) malloc(strlen(mountpoint) + 1)) == NULL - ) break; - - if (strcmp(devname, "none") != 0 && stat(devname, &st) == 0 && - S_ISBLK(st.st_mode)) { - new->device= st.st_rdev; - } else if (stat(mountpoint, &st) == 0) { - new->device= st.st_dev; - } - strcpy(new->devname, devname); - strcpy(new->mountpoint, mountpoint); - - *amt= new; /* Add the cell to the end. */ - amt= &new->next; - *amt= NULL; - } -} - -struct mtab *searchtab(char *name) -/* See what we can do with a user supplied name, there are three possibilities: - * 1. It's a device and it is in the mtab: Return mtab entry. - * 2. It's a file and lives on a device in the mtab: Return mtab entry. - * 3. It's anything else: Return something df() will choke on. - */ -{ - static struct mtab unknown; - struct mtab *mt; - struct stat st; - - unknown.devname= name; - unknown.mountpoint= ""; - - if (stat(name, &st) < 0) return &unknown; /* Case 3. */ - - unknown.device= S_ISBLK(st.st_mode) ? st.st_rdev : st.st_dev; - - for (mt= mtab; mt != NULL; mt= mt->next) { - if (unknown.device == mt->device) - return mt; /* Case 1 & 2. */ - } - - return &unknown; /* Case 3. */ -} - -/* (num / tot) in percentages rounded up. */ -#define percent(num, tot) \ - ((tot > 0) ? ((int) ((100ULL * (num) + ((tot) - 1)) / (tot))) : 0) - -int df(const struct mtab *mt) -{ - long totblocks, busyblocks, totinodes, busyinodes; - struct statvfs sv; - int n; - - if (statvfs(mt->mountpoint, &sv) < 0) { - fprintf(stderr, "df: %s: %s\n", mt->devname, strerror(errno)); - return(1); - } - - /* Print results. */ - printf("%s", mt->devname); - n= strlen(mt->devname); - if (n > 15 && istty) { putchar('\n'); n= 0; } - while (n < 15) { putchar(' '); n++; } - - totblocks = sv.f_blocks; - busyblocks = sv.f_blocks - sv.f_bfree; - - busyblocks = busyblocks * (sv.f_bsize/512) / (unitsize/512); - totblocks = totblocks * (sv.f_bsize/512) / (unitsize/512); - - totinodes = sv.f_files; - busyinodes = sv.f_files - sv.f_ffree; - - if (!Pflag && !iflag) { - printf(" %9ld %9ld %9ld %3d%% %3d%% %s\n", - totblocks, /* Blocks */ - totblocks - busyblocks, /* free */ - busyblocks, /* used */ - percent(busyblocks, totblocks), /* % */ - percent(busyinodes, totinodes), /* FUsed% */ - mt->mountpoint /* Mounted on */ - ); - } - if (!Pflag && iflag) { - printf(" %9ld %9ld %9ld %3d%% %3d%% %s\n", - totinodes, /* Files */ - totinodes - busyinodes, /* free */ - busyinodes, /* used */ - percent(busyinodes, totinodes), /* % */ - percent(busyblocks, totblocks), /* BUsed% */ - mt->mountpoint /* Mounted on */ - ); - } - if (Pflag && !iflag) { - printf(" %9ld %9ld %9ld %4d%% %s\n", - totblocks, /* Blocks */ - busyblocks, /* Used */ - totblocks - busyblocks, /* Available */ - percent(busyblocks, totblocks), /* Capacity */ - mt->mountpoint /* Mounted on */ - ); - } - if (Pflag && iflag) { - printf(" %9ld %9ld %9ld %4d%% %s\n", - totinodes, /* Inodes */ - busyinodes, /* IUsed */ - totinodes - busyinodes, /* IAvail */ - percent(busyinodes, totinodes), /* Capacity */ - mt->mountpoint /* Mounted on */ - ); - } - return(0); -} diff --git a/commands/dumpcore/Makefile b/commands/dumpcore/Makefile deleted file mode 100644 index 3b469fb13..000000000 --- a/commands/dumpcore/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -PROG= dumpcore -CPPFLAGS+= -I${NETBSDSRCDIR} -MAN= - -.include diff --git a/commands/dumpcore/dumpcore.c b/commands/dumpcore/dumpcore.c deleted file mode 100644 index ca6b70bc6..000000000 --- a/commands/dumpcore/dumpcore.c +++ /dev/null @@ -1,71 +0,0 @@ -/* dumpcore - create core file of running process */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "kernel/proc.h" - -#define CLICK_WORDS (CLICK_SIZE / sizeof(unsigned long)) - -int main(int argc, char *argv[]) -{ - pid_t pid; - int r, status; - - if(argc != 2) { - printf("usage: %s \n", argv[0]); - return 1; - } - - pid = atoi(argv[1]); - - if (ptrace(T_ATTACH, pid, 0, 0) != 0) { - perror("ptrace(T_ATTACH)"); - return 1; - } - - if (waitpid(pid, &status, 0) != pid) { - perror("waitpid"); - return 1; - } - - while (WIFSTOPPED(status) && WSTOPSIG(status) != SIGSTOP) { - /* whatever happens here is fine */ - ptrace(T_RESUME, pid, 0, WSTOPSIG(status)); - - if (waitpid(pid, &status, 0) != pid) { - perror("waitpid"); - return 1; - } - } - - if (!WIFSTOPPED(status)) { - fprintf(stderr, "process died while attaching\n"); - return 1; - } - - if (ptrace(T_DUMPCORE, pid, 0, 0) != 0) { - fprintf(stderr, "warning, dumpcore failed (%s)\n", - strerror(errno)); - } - - if (ptrace(T_DETACH, pid, 0, 0)) { - fprintf(stderr, "warning, detaching failed (%s)\n", - strerror(errno)); - } - - return r; -} diff --git a/commands/echo/Makefile b/commands/echo/Makefile new file mode 100644 index 000000000..a72d62028 --- /dev/null +++ b/commands/echo/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= echo.sh +BINDIR= /bin +MAN= + +.include diff --git a/commands/echo/echo.sh b/commands/echo/echo.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/echo/echo.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/expr/Makefile b/commands/expr/Makefile new file mode 100644 index 000000000..76307486d --- /dev/null +++ b/commands/expr/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= expr.sh +BINDIR= /bin +MAN= + +.include diff --git a/commands/expr/expr.sh b/commands/expr/expr.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/expr/expr.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/false/Makefile b/commands/false/Makefile new file mode 100644 index 000000000..a109e84d3 --- /dev/null +++ b/commands/false/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= false.sh +BINDIR= /bin +MAN= + +.include diff --git a/commands/false/false.sh b/commands/false/false.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/false/false.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/fdisk/fdisk.c b/commands/fdisk/fdisk.c index 4c237f27a..5b41d8308 100644 --- a/commands/fdisk/fdisk.c +++ b/commands/fdisk/fdisk.c @@ -75,7 +75,7 @@ char *secbuf; int badbases; int badsizes; int badorders; -char *devname; +char *dev_name; int nhead; int nsec; int ncyl = 1024; @@ -161,9 +161,9 @@ int main(int argc, char *argv[]) } if (argn == argc) - devname = DEFAULT_DEV; + dev_name = DEFAULT_DEV; else if (argn == argc - 1) - devname = argv[argn]; + dev_name = argv[argn]; else usage(); @@ -232,7 +232,7 @@ void getgeom(void) if (override) return; - if ((fd= open(devname, O_RDONLY)) < 0) return; + if ((fd= open(dev_name, O_RDONLY)) < 0) return; r = ioctl(fd, DIOCGETP, &geom); close(fd); @@ -242,21 +242,21 @@ void getgeom(void) nsec = geom.sectors; ncyl = geom.cylinders; - printf("Geometry of %s: %dx%dx%d\n", devname, ncyl, nhead, nsec); + printf("Geometry of %s: %dx%dx%d\n", dev_name, ncyl, nhead, nsec); } static int devfd; void getboot(char *buffer) { - devfd = open(devname, 2); + devfd = open(dev_name, 2); if (devfd < 0) { - printf("No write permission on %s\n", devname); + printf("No write permission on %s\n", dev_name); readonly = 1; - devfd = open(devname, 0); + devfd = open(dev_name, 0); } if (devfd < 0) { - printf("Cannot open device %s\n", devname); + printf("Cannot open device %s\n", dev_name); exit(1); } if (read(devfd, buffer, SECSIZE) != SECSIZE) { @@ -264,7 +264,7 @@ void getboot(char *buffer) exit(1); } if (* (unsigned short *) &buffer[510] != 0xAA55) { - printf("Invalid boot sector on %s.\n", devname); + printf("Invalid boot sector on %s.\n", dev_name); printf("Partition table reset and boot code installed.\n"); memset(buffer, 0, 512); memcpy(buffer, bootstrap, sizeof(bootstrap)); @@ -514,8 +514,8 @@ int chk_table(void) printf( "Disk appears to have mis-specified number of heads or sectors.\n"); printf("Try fdisk -h%d -s%d %s instead of\n", - maxhead + 1, maxsec, devname); - printf(" fdisk -h%d -s%d %s\n", nhead, nsec, devname); + maxhead + 1, maxsec, dev_name); + printf(" fdisk -h%d -s%d %s\n", nhead, nsec, dev_name); seenpart = 0; } } else { @@ -695,12 +695,12 @@ void getboot(char *buffer) segread(&sregs); /* get ds */ - if (devname[1] != ':') { - printf("Invalid drive %s\n", devname); + if (dev_name[1] != ':') { + printf("Invalid drive %s\n", dev_name); exit(1); } - if (*devname >= 'a') *devname += 'A' - 'a'; - drivenum = (*devname - 'C') & 0xff; + if (*dev_name >= 'a') *dev_name += 'A' - 'a'; + drivenum = (*dev_name - 'C') & 0xff; if (drivenum < 0 || drivenum > 7) { printf("Funny drive number %d\n", drivenum); exit(1); diff --git a/commands/fsck.mfs/fsck.c b/commands/fsck.mfs/fsck.c index b9cdda513..f302b9dea 100644 --- a/commands/fsck.mfs/fsck.c +++ b/commands/fsck.mfs/fsck.c @@ -686,7 +686,7 @@ char **clist; if (input(buf, 80)) ip->i_mode = atoo(buf); printf(" nlinks = %6u", ip->i_nlinks); if (input(buf, 80)) ip->i_nlinks = atol(buf); - printf(" size = %6ld", ip->i_size); + printf(" size = %6d", ip->i_size); if (input(buf, 80)) ip->i_size = atol(buf); if (yes("Write this back")) { devwrite(inoblock(ino), inooff(ino), (char *) ip, @@ -1543,7 +1543,7 @@ char *f, **clist, **ilist, **zlist; rw_super(SUPER_GET); - if(block_size < _MIN_BLOCK_SIZE) + if(block_size < SUPER_BLOCK_BYTES) fatal("funny block size"); if(!(rwbuf = malloc(block_size))) fatal("couldn't allocate fs buf (1)"); @@ -1663,3 +1663,10 @@ char **argv; } return(0); } + +void panic(char *fmt, ...) +{ + fprintf(stderr, "%s\n", fmt); + exit(1); +} + diff --git a/commands/gcore/Makefile b/commands/gcore/Makefile deleted file mode 100644 index 4ad31cc0e..000000000 --- a/commands/gcore/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -PROG= gcore -MAN= - -.include diff --git a/commands/gcore/gcore.c b/commands/gcore/gcore.c deleted file mode 100644 index d07d9c0b2..000000000 --- a/commands/gcore/gcore.c +++ /dev/null @@ -1,58 +0,0 @@ -/* gcore - create core file of running process */ - -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - pid_t pid; - int status; - - if(argc != 2) { - printf("usage: %s \n", argv[0]); - return 1; - } - - pid = atoi(argv[1]); - - if (ptrace(T_ATTACH, pid, 0, 0) != 0) { - perror("ptrace(T_ATTACH)"); - return 1; - } - - if (waitpid(pid, &status, 0) != pid) { - perror("waitpid"); - return 1; - } - - while (WIFSTOPPED(status) && WSTOPSIG(status) != SIGSTOP) { - /* whatever happens here is fine */ - ptrace(T_RESUME, pid, 0, WSTOPSIG(status)); - - if (waitpid(pid, &status, 0) != pid) { - perror("waitpid"); - return 1; - } - } - - if (!WIFSTOPPED(status)) { - fprintf(stderr, "process died while attaching\n"); - return 1; - } - - if (ptrace(T_DUMPCORE, pid, 0, 0)) { - fprintf(stderr, "warning, dumpcore failed (%s)\n", strerror(errno)); - } - - if (ptrace(T_DETACH, pid, 0, 0)) { - fprintf(stderr, "warning, detaching failed (%s)\n", strerror(errno)); - } - - return 0; -} diff --git a/commands/getopts/Makefile b/commands/getopts/Makefile new file mode 100644 index 000000000..1a630c1dd --- /dev/null +++ b/commands/getopts/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= getopts.sh +BINDIR= /bin +MAN= + +.include diff --git a/commands/getopts/getopts.sh b/commands/getopts/getopts.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/getopts/getopts.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/getty/getty.c b/commands/getty/getty.c index 14356c6b3..9e35fb2b6 100644 --- a/commands/getty/getty.c +++ b/commands/getty/getty.c @@ -88,7 +88,7 @@ void do_getty(char *name, size_t len, char **args, const char *ttyname) int ch; struct utsname utsname; char **banner, *t; - static char *def_banner[] = { "%s Release %r Version %v (%t)\n\n%n login: ", 0 }; + static char *def_banner[] = { "%s/%p (%t)\n\n%n login: ", 0 }; /* Clean up tty name. */ if((t = strrchr(ttyname, '/'))) ttyname = t + 1; diff --git a/commands/loadkeys/loadkeys.c b/commands/loadkeys/loadkeys.c index f1f0646b1..38468ba06 100644 --- a/commands/loadkeys/loadkeys.c +++ b/commands/loadkeys/loadkeys.c @@ -6,86 +6,51 @@ #include #include #include +#include #include #include -#if __minix_vmd -#define KBD_DEVICE "/dev/kbd" -#else #define KBD_DEVICE "/dev/console" -#endif - -u16_t keymap[NR_SCAN_CODES * MAP_COLS]; -u8_t comprmap[4 + NR_SCAN_CODES * MAP_COLS * 9/8 * 2 + 1]; - - -void tell(char *s) -{ - write(2, s, strlen(s)); -} - void fatal(char *say) { - int err = errno; - tell("loadkeys: "); - if (say != NULL) { - tell(say); - tell(": "); - } - tell(strerror(err)); - tell("\n"); - exit(1); + fprintf(stderr, "loadkeys: %s: %s\n", say, strerror(errno)); + exit(EXIT_FAILURE); } void usage(void) { - tell("Usage: loadkeys mapfile\n"); - exit(1); + fprintf(stderr, "usage: loadkeys \n"); + exit(EXIT_FAILURE); } int main(int argc, char *argv[]) { - u8_t *cm; - u16_t *km; - int fd, n, fb; + char sig[4]; + keymap_t keymap; + int fd; if (argc != 2) usage(); if ((fd = open(argv[1], O_RDONLY)) < 0) fatal(argv[1]); - if (read(fd, comprmap, sizeof(comprmap)) < 0) fatal(argv[1]); + if (read(fd, sig, sizeof(sig)) < sizeof(sig)) fatal(argv[1]); - if (memcmp(comprmap, KEY_MAGIC, 4) != 0) { - tell("loadkeys: "); - tell(argv[1]); - tell(": not a keymap file\n"); - exit(1); + if (memcmp(sig, KEY_MAGIC, sizeof(sig)) != 0) { + fprintf(stderr, "loadkeys: %s: not a keymap file\n", argv[1]); + return EXIT_FAILURE; } + + if (read(fd, keymap, sizeof(keymap)) < sizeof(keymap)) fatal(argv[1]); + close(fd); - /* Decompress the keymap data. */ - cm = comprmap + 4; - n = 8; - for (km = keymap; km < keymap + NR_SCAN_CODES * MAP_COLS; km++) { - if (n == 8) { - /* Need a new flag byte. */ - fb = *cm++; - n = 0; - } - *km = *cm++; /* Low byte. */ - if (fb & (1 << n)) { - *km |= (*cm++ << 8); /* One of the few special keys. */ - } - n++; - } - if ((fd = open(KBD_DEVICE, O_WRONLY)) < 0) fatal(KBD_DEVICE); if (ioctl(fd, KIOCSMAP, keymap) < 0) fatal(KBD_DEVICE); - return 0; + return EXIT_SUCCESS; } diff --git a/commands/mount/mount.c b/commands/mount/mount.c index f4e463cad..fa34bcccd 100644 --- a/commands/mount/mount.c +++ b/commands/mount/mount.c @@ -24,11 +24,12 @@ int main(argc, argv) int argc; char *argv[]; { - int all = 0, i, v = 0, mountflags; + int all = 0, i, v = 0, mountflags, srvflags; char **ap, *opt, *err, *type, *args, *device; if (argc == 1) list(); /* just list /etc/mtab */ mountflags = 0; + srvflags = 0; type = NULL; args = NULL; ap = argv+1; @@ -36,12 +37,12 @@ char *argv[]; if (argv[i][0] == '-') { opt = argv[i]+1; while (*opt != 0) switch (*opt++) { - case 'r': mountflags |= MS_RDONLY; break; + case 'r': mountflags |= MNT_RDONLY; break; case 't': if (++i == argc) usage(); type = argv[i]; break; - case 'i': mountflags |= MS_REUSE; break; - case 'e': mountflags |= MS_EXISTING; break; + case 'i': srvflags |= MS_REUSE; break; + case 'e': srvflags |= MS_EXISTING; break; case 'n': write_mtab = 0; break; case 'o': if (++i == argc) usage(); args = argv[i]; @@ -75,7 +76,7 @@ char *argv[]; } } - if (mount(device, argv[2], mountflags, type, args) < 0) { + if (mount(device, argv[2], mountflags, srvflags, type, args) < 0) { err = strerror(errno); fprintf(stderr, "mount: Can't mount %s on %s: %s\n", argv[1], argv[2], err); @@ -141,7 +142,7 @@ mount_all() if (has_opt(fs->fs_mntops, "ro")) ro = 1; if (ro) { - mountflags |= MS_RDONLY; + mountflags |= MNT_RDONLY; } device = fs->fs_spec; @@ -152,7 +153,7 @@ mount_all() if (!strcmp(device, "none")) device = NULL; - if (mount(device, mountpoint, mountflags, fs->fs_vfstype, + if (mount(device, mountpoint, mountflags, 0, fs->fs_vfstype, fs->fs_mntops) != 0) { err = strerror(errno); fprintf(stderr, "mount: Can't mount %s on %s: %s\n", diff --git a/commands/playwave/playwave.c b/commands/playwave/playwave.c index 53b92d8dc..28bdbf588 100644 --- a/commands/playwave/playwave.c +++ b/commands/playwave/playwave.c @@ -66,15 +66,36 @@ void usage() exit(-1); } +int open_audio(unsigned int *fragment_size, unsigned int channels, + unsigned int samples_per_sec, unsigned int bits) +{ + unsigned int sign; + int audio; + + /* Open DSP */ + if ((audio = open("/dev/audio", O_RDWR | O_REOPEN)) < 0) + { + printf("Cannot open /dev/audio: %s\n", strerror(errno)); + exit(-1); + } + + ioctl(audio, DSPIOMAX, fragment_size); /* Get maximum fragment size. */ + + /* Set DSP parameters (should check return values..) */ + ioctl(audio, DSPIOSIZE, fragment_size); /* Use max. fragment size. */ + ioctl(audio, DSPIOSTEREO, &channels); + ioctl(audio, DSPIORATE, &samples_per_sec); + ioctl(audio, DSPIOBITS, &bits); + sign = (bits == 16 ? 1 : 0); + ioctl(audio, DSPIOSIGN, &sign); + return audio; +} int main ( int argc, char *argv[] ) { int i, r, audio, file; char *buffer, *file_name = NULL; - unsigned int sign; - unsigned int fragment_size; - unsigned int channels; - unsigned int bits; + unsigned int fragment_size, fragment_size2; long data_pos; int showinfo = 0; @@ -91,22 +112,6 @@ int main ( int argc, char *argv[] ) } else file_name = argv[1]; - /* Open DSP */ - if ((audio = open("/dev/audio", O_RDWR | O_REOPEN)) < 0) - { - printf("Cannot open /dev/audio: %s\n", strerror(errno)); - exit(-1); - } - - /* Get maximum fragment size and try to allocate a buffer */ - ioctl(audio, DSPIOMAX, &fragment_size); - if ((buffer = malloc(fragment_size)) == (char *)0) - { - fprintf(stderr, "Cannot allocate buffer\n"); - exit(-1); - } - ioctl(audio, DSPIOSIZE, &fragment_size); - /* Open wav file */ if((file = open(file_name, O_RDONLY)) < 0) { @@ -141,15 +146,15 @@ int main ( int argc, char *argv[] ) exit(1); } - /* Set DSP parameters */ - channels = c_fields.Channels; - channels--; - bits = s_fields.BitsPerSample; - ioctl(audio, DSPIOSTEREO, &channels); - ioctl(audio, DSPIORATE, &c_fields.SamplesPerSec); - ioctl(audio, DSPIOBITS, &bits); - sign = (bits == 16 ? 1 : 0); - ioctl(audio, DSPIOSIGN, &sign); + /* Open audio device and set DSP parameters */ + audio = open_audio(&fragment_size, c_fields.Channels - 1, + c_fields.SamplesPerSec, s_fields.BitsPerSample); + + if ((buffer = malloc(fragment_size)) == (char *)0) + { + fprintf(stderr, "Cannot allocate buffer\n"); + exit(-1); + } /* Goto data chunk */ lseek(file, data_pos, SEEK_SET); @@ -203,6 +208,20 @@ int main ( int argc, char *argv[] ) { fprintf(stderr, "playwave: write to audio device failed: %s\n", strerror(errno)); + + /* If we get EIO, the driver might have restarted. Reopen the + * audio device. + */ + if (errno == EIO) { + close(audio); + audio = open_audio(&fragment_size2, + c_fields.Channels - 1, c_fields.SamplesPerSec, + s_fields.BitsPerSample); + if (fragment_size2 != fragment_size) { + fprintf(stderr, "Fragment size has changed\n"); + exit(1); + } + } } else { diff --git a/commands/ps/ps.c b/commands/ps/ps.c index c421c7ab9..0b69eb21a 100644 --- a/commands/ps/ps.c +++ b/commands/ps/ps.c @@ -203,7 +203,6 @@ static char *prrecv(struct pstat *ps) case FSTATE_LOCK: blkstr = "flock"; break; case FSTATE_POPEN: blkstr = "popen"; break; case FSTATE_SELECT: blkstr = "select"; break; - case FSTATE_DOPEN: blkstr = "dopen"; break; case FSTATE_TASK: blkstr = taskname(ps->ps_ftask); break; default: blkstr = "??"; break; } diff --git a/commands/read/Makefile b/commands/read/Makefile new file mode 100644 index 000000000..399a45461 --- /dev/null +++ b/commands/read/Makefile @@ -0,0 +1,5 @@ +SCRIPTS= read.sh +BINDIR= /bin +MAN= + +.include diff --git a/commands/read/read.sh b/commands/read/read.sh new file mode 120000 index 000000000..f9350d4b6 --- /dev/null +++ b/commands/read/read.sh @@ -0,0 +1 @@ +../shared/builtin.sh \ No newline at end of file diff --git a/commands/service/parse.c b/commands/service/parse.c index a84db8012..e00911afc 100644 --- a/commands/service/parse.c +++ b/commands/service/parse.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include "kernel/proc.h" #include "config.h" @@ -519,7 +519,7 @@ static void do_io(config_t *cpe, struct rs_start *rs_start) static void do_pci_device(config_t *cpe, struct rs_start *rs_start) { - u16_t vid, did; + u16_t vid, did, sub_vid, sub_did; char *check, *check2; /* Process a list of PCI device IDs */ @@ -536,13 +536,26 @@ static void do_pci_device(config_t *cpe, struct rs_start *rs_start) cpe->file, cpe->line); } vid= strtoul(cpe->word, &check, 0x10); - if (check[0] == '/') - did= strtoul(check+1, &check2, 0x10); - if (check[0] != '/' || check2[0] != '\0') - { + if (check[0] != ':' && /* LEGACY: */ check[0] != '/') { fatal("do_pci_device: bad ID '%s' at %s:%d", cpe->word, cpe->file, cpe->line); } + did= strtoul(check+1, &check, 0x10); + if (check[0] == '/') { + sub_vid= strtoul(check+1, &check, 0x10); + if (check[0] == ':') + sub_did= strtoul(check+1, &check2, 0x10); + if (check[0] != ':' || check2[0] != '\0') { + fatal("do_pci_device: bad ID '%s' at %s:%d", + cpe->word, cpe->file, cpe->line); + } + } else if (check[0] != '\0') { + fatal("do_pci_device: bad ID '%s' at %s:%d", + cpe->word, cpe->file, cpe->line); + } else { + sub_vid = NO_SUB_VID; + sub_did = NO_SUB_DID; + } if (rs_start->rss_nr_pci_id >= RS_NR_PCI_DEVICE) { fatal("do_pci_device: too many device IDs (max %d)", @@ -550,6 +563,8 @@ static void do_pci_device(config_t *cpe, struct rs_start *rs_start) } rs_start->rss_pci_id[rs_start->rss_nr_pci_id].vid= vid; rs_start->rss_pci_id[rs_start->rss_nr_pci_id].did= did; + rs_start->rss_pci_id[rs_start->rss_nr_pci_id].sub_vid= sub_vid; + rs_start->rss_pci_id[rs_start->rss_nr_pci_id].sub_did= sub_did; rs_start->rss_nr_pci_id++; } } @@ -734,6 +749,7 @@ struct { "PROCCTL", VM_PROCCTL }, { "MAPCACHEPAGE", VM_MAPCACHEPAGE }, { "SETCACHEPAGE", VM_SETCACHEPAGE }, + { "CLEARCACHE", VM_CLEARCACHE }, { "VFS_MMAP", VM_VFS_MMAP }, { "VFS_REPLY", VM_VFS_REPLY }, { NULL, 0 }, diff --git a/commands/service/print.c b/commands/service/print.c index 52ea796d5..7f42396ba 100644 --- a/commands/service/print.c +++ b/commands/service/print.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include "config.h" diff --git a/commands/service/service.8 b/commands/service/service.8 index d46d29bbb..711c02248 100644 --- a/commands/service/service.8 +++ b/commands/service/service.8 @@ -5,7 +5,7 @@ service \- Manage an operating system service. .PP \fBservice [-b -c -n -p -r] (up|run|edit|update)\fR \fI\fR [\fB-args\fR \fI\fR] [\fB-dev\fR \fI\fR] -[\fB-devstyle\fR \fI