3.3.0j Squashed for testing purposes
Change-Id: Ic32d886158c29b23f322eb777894be3f9b438caf
This commit is contained in:
parent
d3e3c78051
commit
23f4416bca
|
|
@ -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 \
|
||||
mkdir pax pwd rm rmdir sync test
|
||||
SUBDIR= cat date df echo ed expr kill ksh ln ls \
|
||||
mkdir pax pwd rm rmdir sync test stty
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
11
bin/df/Makefile
Normal file
11
bin/df/Makefile
Normal file
|
|
@ -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 <bsd.own.mk>
|
||||
|
||||
PROG= df
|
||||
|
||||
LDADD+=-lutil
|
||||
DPADD+=${LIBUTIL}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
206
bin/df/df.1
Normal file
206
bin/df/df.1
Normal file
|
|
@ -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 .
|
||||
520
bin/df/df.c
Normal file
520
bin/df/df.c
Normal file
|
|
@ -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 <sys/cdefs.h>
|
||||
#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 <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
#include <util.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
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", <file system name>, <total space>,
|
||||
* <space used>, <space free>, <percentage used>,
|
||||
* <file system root>
|
||||
*/
|
||||
(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 */
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
9
bin/stty/Makefile
Normal file
9
bin/stty/Makefile
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# $NetBSD: Makefile,v 1.11 2012/04/04 10:59:44 joerg Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
|
||||
PROG= stty
|
||||
SRCS= cchar.c gfmt.c key.c modes.c print.c stty.c
|
||||
|
||||
CWARNFLAGS.clang+= -Wno-string-plus-int
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
148
bin/stty/cchar.c
Normal file
148
bin/stty/cchar.c
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
/* $NetBSD: cchar.c,v 1.16 2006/10/16 00:37:55 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cchar.c 8.5 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: cchar.c,v 1.16 2006/10/16 00:37:55 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stty.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* Special control characters.
|
||||
*
|
||||
* Cchars1 are the standard names, cchars2 are the old aliases.
|
||||
* The first are displayed, but both are recognized on the
|
||||
* command line.
|
||||
*/
|
||||
const struct cchar cchars1[] = {
|
||||
{ "discard", VDISCARD, CDISCARD },
|
||||
{ "dsusp", VDSUSP, CDSUSP },
|
||||
{ "eof", VEOF, CEOF },
|
||||
{ "eol", VEOL, CEOL },
|
||||
{ "eol2", VEOL2, CEOL },
|
||||
{ "erase", VERASE, CERASE },
|
||||
{ "intr", VINTR, CINTR },
|
||||
{ "kill", VKILL, CKILL },
|
||||
{ "lnext", VLNEXT, CLNEXT },
|
||||
{ "min", VMIN, CMIN },
|
||||
{ "quit", VQUIT, CQUIT },
|
||||
{ "reprint", VREPRINT, CREPRINT },
|
||||
{ "start", VSTART, CSTART },
|
||||
{ "status", VSTATUS, CSTATUS },
|
||||
{ "stop", VSTOP, CSTOP },
|
||||
{ "susp", VSUSP, CSUSP },
|
||||
{ "time", VTIME, CTIME },
|
||||
{ "werase", VWERASE, CWERASE },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
const struct cchar cchars2[] = {
|
||||
{ "brk", VEOL, CEOL },
|
||||
{ "flush", VDISCARD, CDISCARD },
|
||||
{ "rprnt", VREPRINT, CREPRINT },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
static int c_cchar(const void *, const void *);
|
||||
|
||||
static int
|
||||
c_cchar(const void *a, const void *b)
|
||||
{
|
||||
return (strcmp(((const struct cchar *)a)->name,
|
||||
((const struct cchar *)b)->name));
|
||||
}
|
||||
|
||||
int
|
||||
csearch(char ***argvp, struct info *ip)
|
||||
{
|
||||
struct cchar *cp, tmp;
|
||||
long val;
|
||||
char *arg, *ep, *name;
|
||||
|
||||
name = **argvp;
|
||||
|
||||
tmp.name = name;
|
||||
if (!(cp = (struct cchar *)bsearch(&tmp, cchars1,
|
||||
sizeof(cchars1)/sizeof(cchars1[0]) - 1, sizeof(cchars1[0]),
|
||||
c_cchar)) &&
|
||||
!(cp = (struct cchar *)bsearch(&tmp, cchars2,
|
||||
sizeof(cchars2)/sizeof(cchars2[0]) - 1, sizeof(cchars2[0]),
|
||||
c_cchar)))
|
||||
return (0);
|
||||
|
||||
arg = *++*argvp;
|
||||
if (!arg) {
|
||||
warnx("option requires an argument -- %s", name);
|
||||
usage();
|
||||
}
|
||||
|
||||
#define CHK(s) (*arg == s[0] && !strcmp(arg, s))
|
||||
if (CHK("undef") || CHK("<undef>"))
|
||||
ip->t.c_cc[cp->sub] = _POSIX_VDISABLE;
|
||||
else if (cp->sub == VMIN || cp->sub == VTIME) {
|
||||
val = strtol(arg, &ep, 10);
|
||||
if (val == _POSIX_VDISABLE) {
|
||||
warnx("value of %ld would disable the option -- %s",
|
||||
val, name);
|
||||
usage();
|
||||
}
|
||||
if (val > UCHAR_MAX) {
|
||||
warnx("maximum option value is %d -- %s",
|
||||
UCHAR_MAX, name);
|
||||
usage();
|
||||
}
|
||||
if (*ep != '\0') {
|
||||
warnx("option requires a numeric argument -- %s", name);
|
||||
usage();
|
||||
}
|
||||
ip->t.c_cc[cp->sub] = (cc_t)val;
|
||||
} else if (arg[0] == '^')
|
||||
ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 :
|
||||
(arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037;
|
||||
else
|
||||
ip->t.c_cc[cp->sub] = arg[0];
|
||||
ip->set = 1;
|
||||
return (1);
|
||||
}
|
||||
51
bin/stty/extern.h
Normal file
51
bin/stty/extern.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* $NetBSD: extern.h,v 1.12 2011/08/29 14:51:19 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 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.
|
||||
*
|
||||
* @(#)extern.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#ifndef _EXTERN_H_
|
||||
#define _EXTERN_H_
|
||||
|
||||
int c_cchars(const void *, const void *);
|
||||
int c_modes(const void *, const void *);
|
||||
int csearch(char ***, struct info *);
|
||||
void checkredirect(void);
|
||||
void gprint(struct termios *);
|
||||
void gread(struct termios *, char *);
|
||||
int ksearch(char ***, struct info *);
|
||||
int msearch(char ***, struct info *);
|
||||
void optlist(void);
|
||||
void print(struct termios *, struct winsize *, int, enum FMT);
|
||||
__dead void usage(void);
|
||||
|
||||
extern const struct cchar cchars1[], cchars2[];
|
||||
|
||||
#endif /* !_EXTERN_H_ */
|
||||
132
bin/stty/gfmt.c
Normal file
132
bin/stty/gfmt.c
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/* $NetBSD: gfmt.c,v 1.17 2011/08/29 14:51:19 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)gfmt.c 8.6 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: gfmt.c,v 1.17 2011/08/29 14:51:19 joerg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stty.h"
|
||||
#include "extern.h"
|
||||
|
||||
__dead static void gerr(char *);
|
||||
|
||||
static void
|
||||
gerr(char *s)
|
||||
{
|
||||
if (s)
|
||||
errx(1, "illegal gfmt1 option -- %s", s);
|
||||
else
|
||||
errx(1, "illegal gfmt1 option");
|
||||
}
|
||||
|
||||
void
|
||||
gprint(struct termios *tp)
|
||||
{
|
||||
const struct cchar *cp;
|
||||
|
||||
(void)printf("gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
|
||||
tp->c_cflag, tp->c_iflag, tp->c_lflag, tp->c_oflag);
|
||||
for (cp = cchars1; cp->name; ++cp)
|
||||
(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
|
||||
(void)printf("ispeed=%d:ospeed=%d\n", cfgetispeed(tp), cfgetospeed(tp));
|
||||
}
|
||||
|
||||
void
|
||||
gread(struct termios *tp, char *s)
|
||||
{
|
||||
const struct cchar *cp;
|
||||
char *ep, *p;
|
||||
long tmp;
|
||||
|
||||
if ((s = strchr(s, ':')) == NULL)
|
||||
gerr(NULL);
|
||||
for (++s; s != NULL;) {
|
||||
p = strsep(&s, ":\0");
|
||||
if (!p || !*p)
|
||||
break;
|
||||
if (!(ep = strchr(p, '=')))
|
||||
gerr(p);
|
||||
*ep++ = '\0';
|
||||
(void)sscanf(ep, "%lx", &tmp);
|
||||
|
||||
#define CHK(s) (*p == s[0] && !strcmp(p, s))
|
||||
if (CHK("cflag")) {
|
||||
tp->c_cflag = tmp;
|
||||
continue;
|
||||
}
|
||||
if (CHK("iflag")) {
|
||||
tp->c_iflag = tmp;
|
||||
continue;
|
||||
}
|
||||
#ifdef BSD4_4
|
||||
if (CHK("ispeed")) {
|
||||
(void)sscanf(ep, "%ld", &tmp);
|
||||
tp->c_ispeed = tmp;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (CHK("lflag")) {
|
||||
tp->c_lflag = tmp;
|
||||
continue;
|
||||
}
|
||||
if (CHK("oflag")) {
|
||||
tp->c_oflag = tmp;
|
||||
continue;
|
||||
}
|
||||
#ifdef BSD4_4
|
||||
if (CHK("ospeed")) {
|
||||
(void)sscanf(ep, "%ld", &tmp);
|
||||
tp->c_ospeed = tmp;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
for (cp = cchars1; cp->name != NULL; ++cp)
|
||||
if (CHK(cp->name)) {
|
||||
if (cp->sub == VMIN || cp->sub == VTIME)
|
||||
(void)sscanf(ep, "%ld", &tmp);
|
||||
tp->c_cc[cp->sub] = tmp;
|
||||
break;
|
||||
}
|
||||
if (cp->name == NULL)
|
||||
gerr(p);
|
||||
}
|
||||
}
|
||||
339
bin/stty/key.c
Normal file
339
bin/stty/key.c
Normal file
|
|
@ -0,0 +1,339 @@
|
|||
/* $NetBSD: key.c,v 1.20 2004/04/01 16:10:03 tsarna Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)key.c 8.4 (Berkeley) 2/20/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: key.c,v 1.20 2004/04/01 16:10:03 tsarna Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "stty.h"
|
||||
#include "extern.h"
|
||||
|
||||
__BEGIN_DECLS
|
||||
void f_all(struct info *);
|
||||
void f_cbreak(struct info *);
|
||||
void f_columns(struct info *);
|
||||
void f_dec(struct info *);
|
||||
void f_everything(struct info *);
|
||||
void f_extproc(struct info *);
|
||||
void f_insane(struct info *);
|
||||
void f_ispeed(struct info *);
|
||||
void f_nl(struct info *);
|
||||
void f_ospeed(struct info *);
|
||||
void f_raw(struct info *);
|
||||
void f_rows(struct info *);
|
||||
void f_sane(struct info *);
|
||||
void f_size(struct info *);
|
||||
void f_speed(struct info *);
|
||||
void f_ostart(struct info *);
|
||||
void f_ostop(struct info *);
|
||||
void f_tty(struct info *);
|
||||
__END_DECLS
|
||||
|
||||
static const struct key {
|
||||
const char *name; /* name */
|
||||
void (*f)(struct info *); /* function */
|
||||
#define F_NEEDARG 0x01 /* needs an argument */
|
||||
#define F_OFFOK 0x02 /* can turn off */
|
||||
int flags;
|
||||
} keys[] = {
|
||||
{ "all", f_all, 0 },
|
||||
{ "cbreak", f_cbreak, F_OFFOK },
|
||||
{ "cols", f_columns, F_NEEDARG },
|
||||
{ "columns", f_columns, F_NEEDARG },
|
||||
{ "cooked", f_sane, 0 },
|
||||
{ "dec", f_dec, 0 },
|
||||
{ "everything", f_everything, 0 },
|
||||
{ "extproc", f_extproc, F_OFFOK },
|
||||
{ "insane", f_insane, 0 },
|
||||
{ "ispeed", f_ispeed, F_NEEDARG },
|
||||
{ "new", f_tty, 0 },
|
||||
{ "nl", f_nl, F_OFFOK },
|
||||
{ "old", f_tty, 0 },
|
||||
{ "ospeed", f_ospeed, F_NEEDARG },
|
||||
{ "ostart", f_ostart, 0 },
|
||||
{ "ostop", f_ostop, 0 },
|
||||
{ "raw", f_raw, F_OFFOK },
|
||||
{ "rows", f_rows, F_NEEDARG },
|
||||
{ "sane", f_sane, 0 },
|
||||
{ "size", f_size, 0 },
|
||||
{ "speed", f_speed, 0 },
|
||||
{ "tty", f_tty, 0 },
|
||||
};
|
||||
|
||||
static int c_key(const void *, const void *);
|
||||
|
||||
static int
|
||||
c_key(const void *a, const void *b)
|
||||
{
|
||||
|
||||
return (strcmp(((const struct key *)a)->name,
|
||||
((const struct key *)b)->name));
|
||||
}
|
||||
|
||||
int
|
||||
ksearch(char ***argvp, struct info *ip)
|
||||
{
|
||||
char *name;
|
||||
struct key *kp, tmp;
|
||||
|
||||
name = **argvp;
|
||||
if (*name == '-') {
|
||||
ip->off = 1;
|
||||
++name;
|
||||
} else
|
||||
ip->off = 0;
|
||||
|
||||
tmp.name = name;
|
||||
if (!(kp = (struct key *)bsearch(&tmp, keys,
|
||||
sizeof(keys)/sizeof(struct key), sizeof(struct key), c_key)))
|
||||
return (0);
|
||||
if (!(kp->flags & F_OFFOK) && ip->off) {
|
||||
warnx("illegal option -- %s", name);
|
||||
usage();
|
||||
}
|
||||
if (kp->flags & F_NEEDARG && !(ip->arg = *++*argvp)) {
|
||||
warnx("option requires an argument -- %s", name);
|
||||
usage();
|
||||
}
|
||||
kp->f(ip);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
f_all(struct info *ip)
|
||||
{
|
||||
print(&ip->t, &ip->win, ip->ldisc, STTY_BSD);
|
||||
}
|
||||
|
||||
void
|
||||
f_cbreak(struct info *ip)
|
||||
{
|
||||
if (ip->off)
|
||||
f_sane(ip);
|
||||
else {
|
||||
ip->t.c_iflag |= BRKINT|IXON|IMAXBEL;
|
||||
ip->t.c_oflag |= OPOST;
|
||||
ip->t.c_lflag |= ISIG|IEXTEN;
|
||||
ip->t.c_lflag &= ~ICANON;
|
||||
ip->set = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
f_columns(struct info *ip)
|
||||
{
|
||||
ip->win.ws_col = atoi(ip->arg);
|
||||
ip->wset = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_dec(struct info *ip)
|
||||
{
|
||||
ip->t.c_cc[VERASE] = (u_char)0177;
|
||||
ip->t.c_cc[VKILL] = CTRL('u');
|
||||
ip->t.c_cc[VINTR] = CTRL('c');
|
||||
ip->t.c_lflag &= ~ECHOPRT;
|
||||
ip->t.c_lflag |= ECHOE|ECHOKE|ECHOCTL;
|
||||
ip->t.c_iflag &= ~IXANY;
|
||||
ip->set = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_everything(struct info *ip)
|
||||
{
|
||||
print(&ip->t, &ip->win, ip->ldisc, STTY_BSD);
|
||||
}
|
||||
|
||||
void
|
||||
f_extproc(struct info *ip)
|
||||
{
|
||||
#ifdef TIOCEXT
|
||||
if (ip->off) {
|
||||
int tmp = 0;
|
||||
(void)ioctl(ip->fd, TIOCEXT, &tmp);
|
||||
} else {
|
||||
int tmp = 1;
|
||||
(void)ioctl(ip->fd, TIOCEXT, &tmp);
|
||||
}
|
||||
ip->set = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
f_insane(struct info *ip)
|
||||
{
|
||||
int f, r;
|
||||
|
||||
r = f = open(_PATH_URANDOM, O_RDONLY, 0);
|
||||
if (f >= 0) {
|
||||
r = read(f, &(ip->t), sizeof(struct termios));
|
||||
close(f);
|
||||
}
|
||||
if (r < 0) {
|
||||
/* XXX not cryptographically secure! */
|
||||
|
||||
srandom(time(NULL));
|
||||
ip->t.c_iflag = random();
|
||||
ip->t.c_oflag = random();
|
||||
ip->t.c_cflag = random();
|
||||
ip->t.c_lflag = random();
|
||||
for (f = 0; f < NCCS; f++) {
|
||||
ip->t.c_cc[f] = random() & 0xFF;
|
||||
}
|
||||
ip->t.c_ispeed = random();
|
||||
ip->t.c_ospeed = random();
|
||||
}
|
||||
|
||||
ip->set = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_ispeed(struct info *ip)
|
||||
{
|
||||
cfsetispeed(&ip->t, atoi(ip->arg));
|
||||
ip->set = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_nl(struct info *ip)
|
||||
{
|
||||
if (ip->off) {
|
||||
ip->t.c_iflag |= ICRNL;
|
||||
ip->t.c_oflag |= ONLCR;
|
||||
} else {
|
||||
ip->t.c_iflag &= ~ICRNL;
|
||||
ip->t.c_oflag &= ~ONLCR;
|
||||
}
|
||||
ip->set = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_ospeed(struct info *ip)
|
||||
{
|
||||
cfsetospeed(&ip->t, atoi(ip->arg));
|
||||
ip->set = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_raw(struct info *ip)
|
||||
{
|
||||
if (ip->off)
|
||||
f_sane(ip);
|
||||
else {
|
||||
cfmakeraw(&ip->t);
|
||||
ip->t.c_cflag &= ~(CSIZE|PARENB);
|
||||
ip->t.c_cflag |= CS8;
|
||||
ip->set = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
f_rows(struct info *ip)
|
||||
{
|
||||
ip->win.ws_row = atoi(ip->arg);
|
||||
ip->wset = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_sane(struct info *ip)
|
||||
{
|
||||
ip->t.c_cflag = TTYDEF_CFLAG | (ip->t.c_cflag & (CLOCAL|CRTSCTS|CDTRCTS));
|
||||
ip->t.c_iflag = TTYDEF_IFLAG;
|
||||
ip->t.c_iflag |= ICRNL;
|
||||
/* preserve user-preference flags in lflag */
|
||||
#define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH)
|
||||
ip->t.c_lflag = TTYDEF_LFLAG | (ip->t.c_lflag & LKEEP);
|
||||
ip->t.c_oflag = TTYDEF_OFLAG;
|
||||
ip->set = 1;
|
||||
}
|
||||
|
||||
void
|
||||
f_size(struct info *ip)
|
||||
{
|
||||
(void)printf("%d %d\n", ip->win.ws_row, ip->win.ws_col);
|
||||
}
|
||||
|
||||
void
|
||||
f_speed(struct info *ip)
|
||||
{
|
||||
(void)printf("%d\n", cfgetospeed(&ip->t));
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
f_tty(struct info *ip)
|
||||
{
|
||||
#ifdef TTYDISC
|
||||
int tmp;
|
||||
|
||||
tmp = TTYDISC;
|
||||
if (ioctl(0, TIOCSETD, &tmp) < 0)
|
||||
err(1, "TIOCSETD");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
f_ostart(struct info *ip)
|
||||
{
|
||||
#ifndef __minix
|
||||
if (ioctl (0, TIOCSTART) < 0)
|
||||
#else
|
||||
if (ioctl (0, TIOCSTART, NULL) < 0)
|
||||
#endif
|
||||
err(1, "TIOCSTART");
|
||||
}
|
||||
|
||||
void
|
||||
f_ostop(struct info *ip)
|
||||
{
|
||||
#ifndef __minix
|
||||
if (ioctl (0, TIOCSTOP) < 0)
|
||||
#else
|
||||
if (ioctl (0, TIOCSTOP, NULL) < 0)
|
||||
#endif
|
||||
err(1, "TIOCSTOP");
|
||||
}
|
||||
242
bin/stty/modes.c
Normal file
242
bin/stty/modes.c
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
/* $NetBSD: modes.c,v 1.17 2006/10/16 00:37:55 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: modes.c,v 1.17 2006/10/16 00:37:55 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stty.h"
|
||||
#include "extern.h"
|
||||
|
||||
struct modes {
|
||||
const char *name;
|
||||
tcflag_t set;
|
||||
tcflag_t unset;
|
||||
};
|
||||
|
||||
/*
|
||||
* The code in optlist() depends on minus options following regular
|
||||
* options, i.e. "foo" must immediately precede "-foo".
|
||||
*/
|
||||
const struct modes cmodes[] = {
|
||||
{ "cs5", CS5, CSIZE },
|
||||
{ "cs6", CS6, CSIZE },
|
||||
{ "cs7", CS7, CSIZE },
|
||||
{ "cs8", CS8, CSIZE },
|
||||
{ "cstopb", CSTOPB, 0 },
|
||||
{ "-cstopb", 0, CSTOPB },
|
||||
{ "cread", CREAD, 0 },
|
||||
{ "-cread", 0, CREAD },
|
||||
{ "parenb", PARENB, 0 },
|
||||
{ "-parenb", 0, PARENB },
|
||||
{ "parodd", PARODD, 0 },
|
||||
{ "-parodd", 0, PARODD },
|
||||
{ "parity", PARENB | CS7, PARODD | CSIZE },
|
||||
{ "-parity", CS8, PARODD | PARENB | CSIZE },
|
||||
{ "evenp", PARENB | CS7, PARODD | CSIZE },
|
||||
{ "-evenp", CS8, PARODD | PARENB | CSIZE },
|
||||
{ "oddp", PARENB | CS7 | PARODD, CSIZE },
|
||||
{ "-oddp", CS8, PARODD | PARENB | CSIZE },
|
||||
{ "pass8", CS8, PARODD | PARENB | CSIZE },
|
||||
{ "-pass8", PARENB | CS7, PARODD | CSIZE },
|
||||
{ "hupcl", HUPCL, 0 },
|
||||
{ "-hupcl", 0, HUPCL },
|
||||
{ "hup", HUPCL, 0 },
|
||||
{ "-hup", 0, HUPCL },
|
||||
{ "clocal", CLOCAL, 0 },
|
||||
{ "-clocal", 0, CLOCAL },
|
||||
{ "crtscts", CRTSCTS, 0 },
|
||||
{ "-crtscts", 0, CRTSCTS },
|
||||
{ "mdmbuf", MDMBUF, 0 },
|
||||
{ "-mdmbuf", 0, MDMBUF },
|
||||
{ "cdtrcts", CDTRCTS, 0 },
|
||||
{ "-cdtrcts", 0, CDTRCTS },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
const struct modes imodes[] = {
|
||||
{ "ignbrk", IGNBRK, 0 },
|
||||
{ "-ignbrk", 0, IGNBRK },
|
||||
{ "brkint", BRKINT, 0 },
|
||||
{ "-brkint", 0, BRKINT },
|
||||
{ "ignpar", IGNPAR, 0 },
|
||||
{ "-ignpar", 0, IGNPAR },
|
||||
{ "parmrk", PARMRK, 0 },
|
||||
{ "-parmrk", 0, PARMRK },
|
||||
{ "inpck", INPCK, 0 },
|
||||
{ "-inpck", 0, INPCK },
|
||||
{ "istrip", ISTRIP, 0 },
|
||||
{ "-istrip", 0, ISTRIP },
|
||||
{ "inlcr", INLCR, 0 },
|
||||
{ "-inlcr", 0, INLCR },
|
||||
{ "igncr", IGNCR, 0 },
|
||||
{ "-igncr", 0, IGNCR },
|
||||
{ "icrnl", ICRNL, 0 },
|
||||
{ "-icrnl", 0, ICRNL },
|
||||
{ "ixon", IXON, 0 },
|
||||
{ "-ixon", 0, IXON },
|
||||
{ "flow", IXON, 0 },
|
||||
{ "-flow", 0, IXON },
|
||||
{ "ixoff", IXOFF, 0 },
|
||||
{ "-ixoff", 0, IXOFF },
|
||||
{ "tandem", IXOFF, 0 },
|
||||
{ "-tandem", 0, IXOFF },
|
||||
{ "ixany", IXANY, 0 },
|
||||
{ "-ixany", 0, IXANY },
|
||||
{ "decctlq", 0, IXANY },
|
||||
{ "-decctlq", IXANY, 0 },
|
||||
{ "imaxbel", IMAXBEL, 0 },
|
||||
{ "-imaxbel", 0, IMAXBEL },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
const struct modes lmodes[] = {
|
||||
{ "echo", ECHO, 0 },
|
||||
{ "-echo", 0, ECHO },
|
||||
{ "echoe", ECHOE, 0 },
|
||||
{ "-echoe", 0, ECHOE },
|
||||
{ "crterase", ECHOE, 0 },
|
||||
{ "-crterase", 0, ECHOE },
|
||||
{ "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */
|
||||
{ "-crtbs", 0, ECHOE },
|
||||
{ "echok", ECHOK, 0 },
|
||||
{ "-echok", 0, ECHOK },
|
||||
{ "echoke", ECHOKE, 0 },
|
||||
{ "-echoke", 0, ECHOKE },
|
||||
{ "crtkill", ECHOKE, 0 },
|
||||
{ "-crtkill", 0, ECHOKE },
|
||||
{ "altwerase", ALTWERASE, 0 },
|
||||
{ "-altwerase", 0, ALTWERASE },
|
||||
{ "iexten", IEXTEN, 0 },
|
||||
{ "-iexten", 0, IEXTEN },
|
||||
{ "echonl", ECHONL, 0 },
|
||||
{ "-echonl", 0, ECHONL },
|
||||
{ "echoctl", ECHOCTL, 0 },
|
||||
{ "-echoctl", 0, ECHOCTL },
|
||||
{ "ctlecho", ECHOCTL, 0 },
|
||||
{ "-ctlecho", 0, ECHOCTL },
|
||||
{ "echoprt", ECHOPRT, 0 },
|
||||
{ "-echoprt", 0, ECHOPRT },
|
||||
{ "prterase", ECHOPRT, 0 },
|
||||
{ "-prterase", 0, ECHOPRT },
|
||||
{ "isig", ISIG, 0 },
|
||||
{ "-isig", 0, ISIG },
|
||||
{ "icanon", ICANON, 0 },
|
||||
{ "-icanon", 0, ICANON },
|
||||
{ "noflsh", NOFLSH, 0 },
|
||||
{ "-noflsh", 0, NOFLSH },
|
||||
{ "tostop", TOSTOP, 0 },
|
||||
{ "-tostop", 0, TOSTOP },
|
||||
{ "flusho", FLUSHO, 0 },
|
||||
{ "-flusho", 0, FLUSHO },
|
||||
{ "pendin", PENDIN, 0 },
|
||||
{ "-pendin", 0, PENDIN },
|
||||
{ "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
|
||||
{ "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
|
||||
{ "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT },
|
||||
{ "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL },
|
||||
{ "nokerninfo", NOKERNINFO, 0 },
|
||||
{ "-nokerninfo",0, NOKERNINFO },
|
||||
{ "kerninfo", 0, NOKERNINFO },
|
||||
{ "-kerninfo", NOKERNINFO, 0 },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
const struct modes omodes[] = {
|
||||
{ "opost", OPOST, 0 },
|
||||
{ "-opost", 0, OPOST },
|
||||
{ "litout", 0, OPOST },
|
||||
{ "-litout", OPOST, 0 },
|
||||
{ "onlcr", ONLCR, 0 },
|
||||
{ "-onlcr", 0, ONLCR },
|
||||
{ "ocrnl", OCRNL, 0 },
|
||||
{ "-ocrnl", 0, OCRNL },
|
||||
{ "tabs", 0, OXTABS }, /* "preserve" tabs */
|
||||
{ "-tabs", OXTABS, 0 },
|
||||
{ "oxtabs", OXTABS, 0 },
|
||||
{ "-oxtabs", 0, OXTABS },
|
||||
{ "onocr", ONOCR, 0 },
|
||||
{ "-onocr", 0, ONOCR },
|
||||
{ "onlret", ONLRET, 0 },
|
||||
{ "-onlret", 0, ONLRET },
|
||||
{ .name = NULL },
|
||||
};
|
||||
|
||||
#define CHK(s) (!strcmp(name, s))
|
||||
|
||||
int
|
||||
msearch(char ***argvp, struct info *ip)
|
||||
{
|
||||
const struct modes *mp;
|
||||
char *name;
|
||||
|
||||
name = **argvp;
|
||||
|
||||
for (mp = cmodes; mp->name; ++mp)
|
||||
if (CHK(mp->name)) {
|
||||
ip->t.c_cflag &= ~mp->unset;
|
||||
ip->t.c_cflag |= mp->set;
|
||||
ip->set = 1;
|
||||
return (1);
|
||||
}
|
||||
for (mp = imodes; mp->name; ++mp)
|
||||
if (CHK(mp->name)) {
|
||||
ip->t.c_iflag &= ~mp->unset;
|
||||
ip->t.c_iflag |= mp->set;
|
||||
ip->set = 1;
|
||||
return (1);
|
||||
}
|
||||
for (mp = lmodes; mp->name; ++mp)
|
||||
if (CHK(mp->name)) {
|
||||
ip->t.c_lflag &= ~mp->unset;
|
||||
ip->t.c_lflag |= mp->set;
|
||||
ip->set = 1;
|
||||
return (1);
|
||||
}
|
||||
for (mp = omodes; mp->name; ++mp)
|
||||
if (CHK(mp->name)) {
|
||||
ip->t.c_oflag &= ~mp->unset;
|
||||
ip->t.c_oflag |= mp->set;
|
||||
ip->set = 1;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
273
bin/stty/print.c
Normal file
273
bin/stty/print.c
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
/* $NetBSD: print.c,v 1.22 2005/06/26 19:10:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: print.c,v 1.22 2005/06/26 19:10:49 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stty.h"
|
||||
#include "extern.h"
|
||||
|
||||
static void binit(const char *);
|
||||
static void bput(const char *);
|
||||
static const char *ccval(const struct cchar *, int);
|
||||
|
||||
void
|
||||
print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt)
|
||||
{
|
||||
const struct cchar *p;
|
||||
long tmp;
|
||||
u_char *cc;
|
||||
int cnt, ispeed, ospeed;
|
||||
char buf1[100], buf2[100];
|
||||
|
||||
cnt = 0;
|
||||
|
||||
/* Line discipline. */
|
||||
#ifdef TTYDISC
|
||||
if (ldisc != TTYDISC) {
|
||||
switch(ldisc) {
|
||||
case TABLDISC:
|
||||
cnt += printf("tablet disc; ");
|
||||
break;
|
||||
case SLIPDISC:
|
||||
cnt += printf("slip disc; ");
|
||||
break;
|
||||
case PPPDISC:
|
||||
cnt += printf("ppp disc; ");
|
||||
break;
|
||||
case STRIPDISC:
|
||||
cnt += printf("strip disc; ");
|
||||
break;
|
||||
default:
|
||||
cnt += printf("#%d disc; ", ldisc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Line speed. */
|
||||
ispeed = cfgetispeed(tp);
|
||||
ospeed = cfgetospeed(tp);
|
||||
if (ispeed != ospeed)
|
||||
cnt +=
|
||||
printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed);
|
||||
else
|
||||
cnt += printf("speed %d baud;", ispeed);
|
||||
if (fmt >= STTY_BSD)
|
||||
cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
|
||||
if (cnt)
|
||||
(void)printf("\n");
|
||||
|
||||
#define on(f) ((tmp&f) != 0)
|
||||
#define put(n, f, d) \
|
||||
if (fmt >= STTY_BSD || on(f) != d) \
|
||||
bput(n + on(f));
|
||||
|
||||
/* "local" flags */
|
||||
tmp = tp->c_lflag;
|
||||
binit("lflags");
|
||||
put("-icanon", ICANON, 1);
|
||||
put("-isig", ISIG, 1);
|
||||
put("-iexten", IEXTEN, 1);
|
||||
put("-echo", ECHO, 1);
|
||||
put("-echoe", ECHOE, 0);
|
||||
put("-echok", ECHOK, 0);
|
||||
put("-echoke", ECHOKE, 0);
|
||||
put("-echonl", ECHONL, 0);
|
||||
put("-echoctl", ECHOCTL, 0);
|
||||
put("-echoprt", ECHOPRT, 0);
|
||||
put("-altwerase", ALTWERASE, 0);
|
||||
put("-noflsh", NOFLSH, 0);
|
||||
put("-tostop", TOSTOP, 0);
|
||||
put("-flusho", FLUSHO, 0);
|
||||
put("-pendin", PENDIN, 0);
|
||||
put("-nokerninfo", NOKERNINFO, 0);
|
||||
put("-extproc", EXTPROC, 0);
|
||||
|
||||
/* input flags */
|
||||
tmp = tp->c_iflag;
|
||||
binit("iflags");
|
||||
put("-istrip", ISTRIP, 0);
|
||||
put("-icrnl", ICRNL, 1);
|
||||
put("-inlcr", INLCR, 0);
|
||||
put("-igncr", IGNCR, 0);
|
||||
put("-ixon", IXON, 1);
|
||||
put("-ixoff", IXOFF, 0);
|
||||
put("-ixany", IXANY, 1);
|
||||
put("-imaxbel", IMAXBEL, 1);
|
||||
put("-ignbrk", IGNBRK, 0);
|
||||
put("-brkint", BRKINT, 1);
|
||||
put("-inpck", INPCK, 0);
|
||||
put("-ignpar", IGNPAR, 0);
|
||||
put("-parmrk", PARMRK, 0);
|
||||
|
||||
/* output flags */
|
||||
tmp = tp->c_oflag;
|
||||
binit("oflags");
|
||||
put("-opost", OPOST, 1);
|
||||
put("-onlcr", ONLCR, 1);
|
||||
put("-ocrnl", OCRNL, 0);
|
||||
put("-oxtabs", OXTABS, 1);
|
||||
put("-onocr", OXTABS, 0);
|
||||
put("-onlret", OXTABS, 0);
|
||||
|
||||
/* control flags (hardware state) */
|
||||
tmp = tp->c_cflag;
|
||||
binit("cflags");
|
||||
put("-cread", CREAD, 1);
|
||||
switch(tmp&CSIZE) {
|
||||
case CS5:
|
||||
bput("cs5");
|
||||
break;
|
||||
case CS6:
|
||||
bput("cs6");
|
||||
break;
|
||||
case CS7:
|
||||
bput("cs7");
|
||||
break;
|
||||
case CS8:
|
||||
bput("cs8");
|
||||
break;
|
||||
}
|
||||
bput("-parenb" + on(PARENB));
|
||||
put("-parodd", PARODD, 0);
|
||||
put("-hupcl", HUPCL, 1);
|
||||
put("-clocal", CLOCAL, 0);
|
||||
put("-cstopb", CSTOPB, 0);
|
||||
put("-crtscts", CRTSCTS, 0);
|
||||
put("-mdmbuf", MDMBUF, 0);
|
||||
put("-cdtrcts", CDTRCTS, 0);
|
||||
|
||||
/* special control characters */
|
||||
cc = tp->c_cc;
|
||||
if (fmt == STTY_POSIX) {
|
||||
binit("cchars");
|
||||
for (p = cchars1; p->name; ++p) {
|
||||
(void)snprintf(buf1, sizeof(buf1), "%s = %s;",
|
||||
p->name, ccval(p, cc[p->sub]));
|
||||
bput(buf1);
|
||||
}
|
||||
binit(NULL);
|
||||
} else {
|
||||
binit(NULL);
|
||||
for (p = cchars1, cnt = 0; p->name; ++p) {
|
||||
if (fmt != STTY_BSD && cc[p->sub] == p->def)
|
||||
continue;
|
||||
#define WD "%-8s"
|
||||
(void)snprintf(buf1 + cnt * 8, 9, WD, p->name);
|
||||
(void)snprintf(buf2 + cnt * 8, 9, WD, ccval(p, cc[p->sub]));
|
||||
if (++cnt == LINELENGTH / 8) {
|
||||
cnt = 0;
|
||||
(void)printf("%s\n", buf1);
|
||||
(void)printf("%s\n", buf2);
|
||||
}
|
||||
}
|
||||
if (cnt) {
|
||||
(void)printf("%s\n", buf1);
|
||||
(void)printf("%s\n", buf2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int col;
|
||||
static const char *label;
|
||||
|
||||
static void
|
||||
binit(const char *lb)
|
||||
{
|
||||
|
||||
if (col) {
|
||||
(void)printf("\n");
|
||||
col = 0;
|
||||
}
|
||||
label = lb;
|
||||
}
|
||||
|
||||
static void
|
||||
bput(const char *s)
|
||||
{
|
||||
|
||||
if (col == 0) {
|
||||
col = printf("%s: %s", label, s);
|
||||
return;
|
||||
}
|
||||
if ((col + strlen(s)) > LINELENGTH) {
|
||||
(void)printf("\n\t");
|
||||
col = printf("%s", s) + 8;
|
||||
return;
|
||||
}
|
||||
col += printf(" %s", s);
|
||||
}
|
||||
|
||||
static const char *
|
||||
ccval(const struct cchar *p, int c)
|
||||
{
|
||||
static char buf[5];
|
||||
char *bp;
|
||||
|
||||
if (c == _POSIX_VDISABLE)
|
||||
return ("<undef>");
|
||||
|
||||
if (p->sub == VMIN || p->sub == VTIME) {
|
||||
(void)snprintf(buf, sizeof(buf), "%d", c);
|
||||
return (buf);
|
||||
}
|
||||
bp = buf;
|
||||
if (c & 0200) {
|
||||
*bp++ = 'M';
|
||||
*bp++ = '-';
|
||||
c &= 0177;
|
||||
}
|
||||
if (c == 0177) {
|
||||
*bp++ = '^';
|
||||
*bp++ = '?';
|
||||
}
|
||||
else if (c < 040) {
|
||||
*bp++ = '^';
|
||||
*bp++ = c + '@';
|
||||
}
|
||||
else
|
||||
*bp++ = c;
|
||||
*bp = '\0';
|
||||
return (buf);
|
||||
}
|
||||
635
bin/stty/stty.1
Normal file
635
bin/stty/stty.1
Normal file
|
|
@ -0,0 +1,635 @@
|
|||
.\" $NetBSD: stty.1,v 1.41 2012/06/20 14:19:39 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, 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.
|
||||
.\"
|
||||
.\" @(#)stty.1 8.5 (Berkeley) 6/1/94
|
||||
.\"
|
||||
.Dd June 16, 2012
|
||||
.Dt STTY 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm stty
|
||||
.Nd set options for a terminal device interface
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl a | Fl e | Fl g
|
||||
.Op Fl f Ar file
|
||||
.Op operand ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility sets or reports on terminal
|
||||
characteristics for the device that is its standard input.
|
||||
If no options or operands are specified, it reports the settings of a subset
|
||||
of characteristics as well as additional ones if they differ from their
|
||||
default values.
|
||||
Otherwise it modifies
|
||||
the terminal state according to the specified arguments.
|
||||
Some combinations of arguments are mutually
|
||||
exclusive on some terminal types.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width XfXfileXX
|
||||
.It Fl a
|
||||
Display all the current settings for the terminal to standard output
|
||||
as per
|
||||
.St -p1003.2 .
|
||||
.It Fl e
|
||||
Display all the current settings for the terminal to standard output
|
||||
in the traditional
|
||||
.Bx
|
||||
.Dq all
|
||||
and
|
||||
.Dq everything
|
||||
formats.
|
||||
.It Fl f Ar file
|
||||
Open and use the terminal named by
|
||||
.Ar file
|
||||
rather than using standard input.
|
||||
The file is opened using the
|
||||
.Dv O_NONBLOCK
|
||||
flag of
|
||||
.Fn open ,
|
||||
making it possible to
|
||||
set or display settings on a terminal that might otherwise
|
||||
block on the open.
|
||||
.It Fl g
|
||||
Display all the current settings for the terminal to standard output
|
||||
in a form that may be used as an argument to a subsequent invocation of
|
||||
.Nm
|
||||
to restore the current terminal state as per
|
||||
.St -p1003.2 .
|
||||
.El
|
||||
.Pp
|
||||
The following arguments are available to set the terminal
|
||||
characteristics:
|
||||
.Ss Control Modes
|
||||
Control mode flags affect hardware characteristics associated with the
|
||||
terminal.
|
||||
This corresponds to the
|
||||
.Fa c_cflag
|
||||
of the
|
||||
.Xr termios 4
|
||||
structure.
|
||||
.Bl -tag -width Fl
|
||||
.It Cm parenb Pq Fl parenb
|
||||
Enable (disable) parity generation
|
||||
and detection.
|
||||
.It Cm parodd Pq Fl parodd
|
||||
Select odd (even) parity.
|
||||
.It Cm cs5 cs6 cs7 cs8
|
||||
Select character size, if possible.
|
||||
.It Ar number
|
||||
Set terminal baud rate to
|
||||
.Ar number ,
|
||||
if possible.
|
||||
If the
|
||||
baud rate is set to zero, modem
|
||||
control is no longer
|
||||
asserted.
|
||||
.It Cm ispeed Ar number
|
||||
Set terminal input baud rate to
|
||||
.Ar number ,
|
||||
if possible.
|
||||
If the
|
||||
input baud rate is set to zero, the
|
||||
input baud rate is set to the
|
||||
value of the output baud
|
||||
rate.
|
||||
.It Cm ospeed Ar number
|
||||
Set terminal output baud rate to
|
||||
.Ar number ,
|
||||
if possible.
|
||||
If
|
||||
the output baud rate is set to
|
||||
zero, modem control is
|
||||
no longer asserted.
|
||||
.It Cm speed Ar number
|
||||
This sets both
|
||||
.Cm ispeed
|
||||
and
|
||||
.Cm ospeed
|
||||
to
|
||||
.Ar number .
|
||||
.It Cm hupcl Pq Fl hupcl
|
||||
Stop asserting modem control
|
||||
(do not stop asserting modem control) on last close.
|
||||
.It Cm hup Pq Fl hup
|
||||
Same as hupcl
|
||||
.Pq Fl hupcl .
|
||||
.It Cm cstopb Pq Fl cstopb
|
||||
Use two (one) stop bits per character.
|
||||
.It Cm cread Pq Fl cread
|
||||
Enable (disable) the receiver.
|
||||
.It Cm clocal Pq Fl clocal
|
||||
Assume a line without (with) modem
|
||||
control.
|
||||
.It Cm crtscts Pq Fl crtscts
|
||||
Enable RTS/CTS flow control.
|
||||
.It Cm cdtrcts Pq Fl cdtrcts
|
||||
Enable DTR/CTS flow control (if supported).
|
||||
.El
|
||||
.Ss Input Modes
|
||||
This corresponds to the
|
||||
.Fa c_iflag
|
||||
of the
|
||||
.Xr termios 4
|
||||
structure.
|
||||
.Bl -tag -width Fl
|
||||
.It Cm ignbrk Pq Fl ignbrk
|
||||
Ignore (do not ignore) break on
|
||||
input.
|
||||
.It Cm brkint Pq Fl brkint
|
||||
Signal (do not signal)
|
||||
.Dv INTR
|
||||
on
|
||||
break.
|
||||
.It Cm ignpar Pq Fl ignpar
|
||||
Ignore (do not ignore) parity
|
||||
errors.
|
||||
.It Cm parmrk Pq Fl parmrk
|
||||
Mark (do not mark) parity errors.
|
||||
.It Cm inpck Pq Fl inpck
|
||||
Enable (disable) input parity
|
||||
checking.
|
||||
.It Cm istrip Pq Fl istrip
|
||||
Strip (do not strip) input characters
|
||||
to seven bits.
|
||||
.It Cm inlcr Pq Fl inlcr
|
||||
Map (do not map)
|
||||
.Dv NL
|
||||
to
|
||||
.Dv CR
|
||||
on input.
|
||||
.It Cm igncr Pq Fl igncr
|
||||
Ignore (do not ignore)
|
||||
.Dv CR
|
||||
on input.
|
||||
.It Cm icrnl Pq Fl icrnl
|
||||
Map (do not map)
|
||||
.Dv CR
|
||||
to
|
||||
.Dv NL
|
||||
on input.
|
||||
.It Cm ixon Pq Fl ixon
|
||||
Enable (disable)
|
||||
.Dv START/STOP
|
||||
output
|
||||
control.
|
||||
Output from the system is
|
||||
stopped when the system receives
|
||||
.Dv STOP
|
||||
and started when the system
|
||||
receives
|
||||
.Dv START ,
|
||||
or if
|
||||
.Cm ixany
|
||||
is set, any character restarts output.
|
||||
.It Cm ixoff Pq Fl ixoff
|
||||
Request that the system send (not
|
||||
send)
|
||||
.Dv START/STOP
|
||||
characters when
|
||||
the input queue is nearly
|
||||
empty/full.
|
||||
.It Cm ixany Pq Fl ixany
|
||||
Allow any character (allow only
|
||||
.Dv START )
|
||||
to restart output.
|
||||
.It Cm imaxbel Pq Fl imaxbel
|
||||
The system imposes a limit of
|
||||
.Dv MAX_INPUT
|
||||
(currently 255) characters in the input queue.
|
||||
If
|
||||
.Cm imaxbel
|
||||
is set and the input queue limit has been reached,
|
||||
subsequent input causes the system to send an ASCII BEL
|
||||
character to the output queue (the terminal beeps at you).
|
||||
Otherwise,
|
||||
if
|
||||
.Cm imaxbel
|
||||
is unset and the input queue is full, the next input character causes
|
||||
the entire input and output queues to be discarded.
|
||||
.El
|
||||
.Ss Output Modes
|
||||
This corresponds to the
|
||||
.Fa c_oflag
|
||||
of the
|
||||
.Xr termios 4
|
||||
structure.
|
||||
.Bl -tag -width Fl
|
||||
.It Cm opost Pq Fl opost
|
||||
Post-process output (do not
|
||||
post-process output; ignore all other
|
||||
output modes).
|
||||
.It Cm onlcr Pq Fl onlcr
|
||||
Map (do not map)
|
||||
.Dv NL
|
||||
to
|
||||
.Dv CR-NL
|
||||
on output.
|
||||
.It Cm ocrnl Pq Fl ocrnl
|
||||
Map (do not map)
|
||||
.Dv CR
|
||||
to
|
||||
.Dv NL
|
||||
on output.
|
||||
.It Cm oxtabs Pq Fl oxtabs
|
||||
Expand (do not expand) tabs to spaces on output.
|
||||
.It Cm onocr Pq Fl onocr
|
||||
Do not (do) output CRs at column zero.
|
||||
.It Cm onlret Pq Fl onlret
|
||||
On the terminal NL performs (does not perform) the CR function.
|
||||
.El
|
||||
.Ss Local Modes
|
||||
Local mode flags (lflags) affect various and sundry characteristics of terminal
|
||||
processing.
|
||||
Historically the term "local" pertained to new job control features
|
||||
implemented by Jim Kulp on a
|
||||
.Tn PDP Ns -11/70
|
||||
at
|
||||
.Tn IIASA .
|
||||
Later the driver ran on the first
|
||||
.Tn VAX
|
||||
at Evans Hall, UC Berkeley, where the job control details
|
||||
were greatly modified but the structure definitions and names
|
||||
remained essentially unchanged.
|
||||
The second interpretation of the
|
||||
.Sq l
|
||||
in lflag
|
||||
is
|
||||
.Dq line discipline flag ,
|
||||
which corresponds to the
|
||||
.Fa c_lflag
|
||||
of the
|
||||
.Xr termios 4
|
||||
structure.
|
||||
.Bl -tag -width Fl
|
||||
.It Cm isig Pq Fl isig
|
||||
Enable (disable) the checking of
|
||||
characters against the special control
|
||||
characters
|
||||
.Dv INTR , QUIT ,
|
||||
and
|
||||
.Dv SUSP .
|
||||
.It Cm icanon Pq Fl icanon
|
||||
Enable (disable) canonical input
|
||||
.Dv ( ERASE
|
||||
and
|
||||
.Dv KILL
|
||||
processing).
|
||||
.It Cm iexten Pq Fl iexten
|
||||
Enable (disable) any implementation
|
||||
defined special control characters
|
||||
not currently controlled by icanon,
|
||||
isig, or ixon.
|
||||
.It Cm echo Pq Fl echo
|
||||
Echo back (do not echo back) every
|
||||
character typed.
|
||||
.It Cm echoe Pq Fl echoe
|
||||
The
|
||||
.Dv ERASE
|
||||
character shall (shall
|
||||
not) visually erase the last character
|
||||
in the current line from the
|
||||
display, if possible.
|
||||
.It Cm echok Pq Fl echok
|
||||
Echo (do not echo)
|
||||
.Dv NL
|
||||
after
|
||||
.Dv KILL
|
||||
character.
|
||||
.It Cm echoke Pq Fl echoke
|
||||
The
|
||||
.Dv KILL
|
||||
character shall (shall
|
||||
not) visually erase
|
||||
the current line from the
|
||||
display, if possible.
|
||||
.It Cm echonl Pq Fl echonl
|
||||
Echo (do not echo)
|
||||
.Dv NL ,
|
||||
even if echo
|
||||
is disabled.
|
||||
.It Cm echoctl Pq Fl echoctl
|
||||
If
|
||||
.Cm echoctl
|
||||
is set, echo control characters as ^X.
|
||||
Otherwise control characters echo as themselves.
|
||||
.It Cm echoprt Pq Fl echoprt
|
||||
For printing terminals.
|
||||
If set, echo erased characters backwards within
|
||||
.Dq \e
|
||||
and
|
||||
.Dq / .
|
||||
Otherwise, disable this feature.
|
||||
.It Cm noflsh Pq Fl noflsh
|
||||
Disable (enable) flush after
|
||||
.Dv INTR , QUIT , SUSP .
|
||||
.It Cm tostop Pq Fl tostop
|
||||
Send (do not send)
|
||||
.Dv SIGTTOU
|
||||
for background output.
|
||||
This causes background jobs to stop if they attempt terminal output.
|
||||
.It Cm altwerase Pq Fl altwerase
|
||||
Use (do not use) an alternative word erase algorithm when processing
|
||||
.Dv WERASE
|
||||
characters.
|
||||
This alternative algorithm considers sequences of
|
||||
alphanumeric/underscores as words.
|
||||
It also skips the first preceding character in its classification
|
||||
(as a convenience since the one preceding character could have been
|
||||
erased with simply an
|
||||
.Dv ERASE
|
||||
character).
|
||||
.It Cm mdmbuf Pq Fl mdmbuf
|
||||
If set, flow control output based on condition of Carrier Detect.
|
||||
Otherwise writes return an error if Carrier Detect is low (and Carrier
|
||||
is not being ignored with the
|
||||
.Dv CLOCAL
|
||||
flag).
|
||||
.It Cm flusho Pq Fl flusho
|
||||
Indicates output is (is not) being discarded.
|
||||
.It Cm pendin Pq Fl pendin
|
||||
Indicates input is (is not) pending after a switch from non-canonical
|
||||
to canonical mode and will be re-input when a read becomes pending
|
||||
or more input arrives.
|
||||
.El
|
||||
.Ss Control Characters
|
||||
.Bl -tag -width Fl
|
||||
.It Ar control-character Ar string
|
||||
Set
|
||||
.Ar control-character
|
||||
to string
|
||||
.Ar string .
|
||||
If the string is a single character,
|
||||
then the control character is set to
|
||||
that character.
|
||||
If the string is the
|
||||
two character sequence "^-" or the
|
||||
string "undef", then the control character
|
||||
is disabled (i.e., set to
|
||||
.Bro Dv _POSIX_VDISABLE Brc ) .
|
||||
.Pp
|
||||
Recognized control characters:
|
||||
.Bd -ragged -offset indent
|
||||
.Bl -column character Subscript Description
|
||||
.It control- Ta "" Ta ""
|
||||
.It character Subscript Description
|
||||
.It _________ _________ _______________
|
||||
.It eof Ta Tn VEOF Ta EOF No character
|
||||
.It eol Ta Tn VEOL Ta EOL No character
|
||||
.It eol2 Ta Tn VEOL2 Ta EOL2 No character
|
||||
.It erase Ta Tn VERASE Ta ERASE No character
|
||||
.It werase Ta Tn VWERASE Ta WERASE No character
|
||||
.It kill Ta Tn VKILL Ta KILL No character
|
||||
.It reprint Ta Tn VREPRINT Ta REPRINT No character
|
||||
.It intr Ta Tn VINTR Ta INTR No character
|
||||
.It quit Ta Tn VQUIT Ta QUIT No character
|
||||
.It susp Ta Tn VSUSP Ta SUSP No character
|
||||
.It dsusp Ta Tn VDSUSP Ta DSUSP No character
|
||||
.It start Ta Tn VSTART Ta START No character
|
||||
.It stop Ta Tn VSTOP Ta STOP No character
|
||||
.It lnext Ta Tn VLNEXT Ta LNEXT No character
|
||||
.It status Ta Tn VSTATUS Ta STATUS No character
|
||||
.It discard Ta Tn VDISCARD Ta DISCARD No character
|
||||
.El
|
||||
.Ed
|
||||
.It Cm min Ar number
|
||||
.It Cm time Ar number
|
||||
Set the value of min or time to
|
||||
.Ar number .
|
||||
.Dv MIN
|
||||
and
|
||||
.Dv TIME
|
||||
are used in
|
||||
Non-Canonical mode input processing
|
||||
(-icanon).
|
||||
.El
|
||||
.Ss Combination Modes
|
||||
.Bl -tag -width Fl
|
||||
.It Ar saved settings
|
||||
Set the current terminal characteristics to the saved settings
|
||||
produced by the
|
||||
.Fl g
|
||||
option.
|
||||
.It Cm evenp No or Cm parity
|
||||
Enable parenb and cs7; disable parodd.
|
||||
.It Cm oddp
|
||||
Enable parenb, cs7, and parodd.
|
||||
.It Fl parity , evenp , oddp
|
||||
Disable parenb, and set cs8.
|
||||
.It Cm \&nl Pq Fl \&nl
|
||||
Enable (disable) icrnl.
|
||||
In addition
|
||||
-nl unsets inlcr and igncr.
|
||||
.It Cm ek
|
||||
Reset
|
||||
.Dv ERASE
|
||||
and
|
||||
.Dv KILL
|
||||
characters back to system defaults.
|
||||
.It Cm sane
|
||||
Resets all modes to reasonable values for interactive terminal use.
|
||||
.It Cm insane
|
||||
Sets all modes to random values, which are very likely
|
||||
.Pq but not guaranteed
|
||||
to be unreasonable for interactive terminal use.
|
||||
.It Cm tty
|
||||
Set the line discipline to the standard terminal line discipline
|
||||
.Dv TTYDISC .
|
||||
.It Cm crt Pq Fl crt
|
||||
Set (disable) all modes suitable for a CRT display device.
|
||||
.It Cm kerninfo Pq Fl kerninfo
|
||||
Enable (disable) the system generated status line associated with
|
||||
processing a
|
||||
.Dv STATUS
|
||||
character (usually set to ^T).
|
||||
The status line consists of the
|
||||
system load average, the current command name, its process ID, the
|
||||
event the process is waiting on (or the status of the process), the user
|
||||
and system times, percent CPU, and current memory usage.
|
||||
.It Cm columns Ar number
|
||||
The terminal size is recorded as having
|
||||
.Ar number
|
||||
columns.
|
||||
.It Cm cols Ar number
|
||||
An alias for
|
||||
.Cm columns .
|
||||
.It Cm rows Ar number
|
||||
The terminal size is recorded as having
|
||||
.Ar number
|
||||
rows.
|
||||
.It Cm dec
|
||||
Set modes suitable for users of Digital Equipment Corporation systems
|
||||
.Dv ( ERASE ,
|
||||
.Dv KILL ,
|
||||
and
|
||||
.Dv INTR
|
||||
characters are set to ^?, ^U, and ^C;
|
||||
.Dv ixany
|
||||
is disabled, and
|
||||
.Dv crt
|
||||
is enabled).
|
||||
.It Cm extproc Pq Fl extproc
|
||||
If set, this flag indicates that some amount of terminal processing is being
|
||||
performed by either the terminal hardware or by the remote side connected
|
||||
to a pty.
|
||||
.It Cm raw Pq Fl raw
|
||||
If set, change the modes of the terminal so that no input or output processing
|
||||
is performed.
|
||||
If unset, change the modes of the terminal to some reasonable
|
||||
state that performs input and output processing.
|
||||
Note that since the terminal driver no longer has a single
|
||||
.Dv RAW
|
||||
bit, it is not possible to intuit what flags were set prior to setting
|
||||
.Cm raw .
|
||||
This means that unsetting
|
||||
.Cm raw
|
||||
may not put back all the setting that were previously in effect.
|
||||
To set the terminal into a raw state and then accurately restore it, the following
|
||||
shell code is recommended:
|
||||
.Bd -literal -offset indent
|
||||
save_state=$(stty -g)
|
||||
stty raw
|
||||
\&...
|
||||
stty "$save_state"
|
||||
.Ed
|
||||
.It Cm size
|
||||
The size of the terminal is printed as two numbers on a single line,
|
||||
first rows, then columns.
|
||||
.El
|
||||
.Ss Compatibility Modes
|
||||
These modes remain for compatibility with the previous version of
|
||||
the
|
||||
.Nm
|
||||
utility.
|
||||
.Bl -tag -width Fl
|
||||
.It Cm all
|
||||
Reports all the terminal modes as with
|
||||
.Cm stty Fl a
|
||||
except that the control characters are printed in a columnar format.
|
||||
.It Cm everything
|
||||
Same as
|
||||
.Cm all .
|
||||
.It Cm cooked
|
||||
Same as
|
||||
.Cm sane .
|
||||
.It Cm cbreak
|
||||
If set, enables
|
||||
.Cm brkint , ixon , imaxbel , opost ,
|
||||
.Cm isig , iexten ,
|
||||
and
|
||||
.Fl icanon .
|
||||
If unset, same as
|
||||
.Cm sane .
|
||||
.It Cm new
|
||||
Same as
|
||||
.Cm tty .
|
||||
.It Cm old
|
||||
Same as
|
||||
.Cm tty .
|
||||
.It Cm newcrt Pq Fl newcrt
|
||||
Same as
|
||||
.Cm crt .
|
||||
.It Cm pass8
|
||||
The converse of
|
||||
.Cm parity .
|
||||
.It Cm tandem Pq Fl tandem
|
||||
Same as
|
||||
.Cm ixoff .
|
||||
.It Cm decctlq Pq Fl decctlq
|
||||
The converse of
|
||||
.Cm ixany .
|
||||
.It Cm crterase Pq Fl crterase
|
||||
Same as
|
||||
.Cm echoe .
|
||||
.It Cm crtbs Pq Fl crtbs
|
||||
Same as
|
||||
.Cm echoe .
|
||||
.It Cm crtkill Pq Fl crtkill
|
||||
Same as
|
||||
.Cm echoke .
|
||||
.It Cm ctlecho Pq Fl ctlecho
|
||||
Same as
|
||||
.Cm echoctl .
|
||||
.It Cm prterase Pq Fl prterase
|
||||
Same as
|
||||
.Cm echoprt .
|
||||
.It Cm litout Pq Fl litout
|
||||
The converse of
|
||||
.Cm opost .
|
||||
.It Cm tabs Pq Fl tabs
|
||||
The converse of
|
||||
.Cm oxtabs .
|
||||
.It Cm brk Ar value
|
||||
Same as the control character
|
||||
.Cm eol .
|
||||
.It Cm flush Ar value
|
||||
Same as the control character
|
||||
.Cm discard .
|
||||
.It Cm rprnt Ar value
|
||||
Same as the control character
|
||||
.Cm reprint .
|
||||
.El
|
||||
.Ss Control operations
|
||||
These operations are not modes, but rather commands to be performed by
|
||||
the tty layer.
|
||||
.Bl -tag -width Fl
|
||||
.It Cm ostart
|
||||
Performs a "start output" operation, as normally done by an
|
||||
incoming START character when
|
||||
.Cm ixon
|
||||
is set.
|
||||
.It Cm ostop
|
||||
Performs a "stop output" operation, as normally done by an
|
||||
incoming STOP character when
|
||||
.Cm ixon
|
||||
is set.
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh SEE ALSO
|
||||
.Xr termios 4 ,
|
||||
.Xr tty 4
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compatible.
|
||||
The
|
||||
.Fl e
|
||||
and
|
||||
.Fl f
|
||||
flags are
|
||||
extensions to the standard, as are the operands mentioned in the control
|
||||
operations section.
|
||||
168
bin/stty/stty.c
Normal file
168
bin/stty/stty.c
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
/* $NetBSD: stty.c,v 1.22 2012/06/20 10:09:43 wiz Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1989, 1991, 1993, 1994
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1991, 1993, 1994\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)stty.c 8.3 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: stty.c,v 1.22 2012/06/20 10:09:43 wiz Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "stty.h"
|
||||
#include "extern.h"
|
||||
|
||||
int main(int, char *[]);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct info i;
|
||||
enum FMT fmt;
|
||||
int ch;
|
||||
|
||||
setprogname(argv[0]);
|
||||
(void)setlocale(LC_ALL, "");
|
||||
|
||||
fmt = STTY_NOTSET;
|
||||
i.fd = STDIN_FILENO;
|
||||
|
||||
opterr = 0;
|
||||
while (optind < argc &&
|
||||
strspn(argv[optind], "-aefg") == strlen(argv[optind]) &&
|
||||
(ch = getopt(argc, argv, "aef:g")) != -1)
|
||||
switch(ch) {
|
||||
case 'a': /* undocumented: POSIX compatibility */
|
||||
fmt = STTY_POSIX;
|
||||
break;
|
||||
case 'e':
|
||||
fmt = STTY_BSD;
|
||||
break;
|
||||
case 'f':
|
||||
if ((i.fd = open(optarg, O_RDONLY | O_NONBLOCK)) < 0)
|
||||
err(1, "%s", optarg);
|
||||
break;
|
||||
case 'g':
|
||||
fmt = STTY_GFLAG;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
goto args;
|
||||
}
|
||||
|
||||
args: argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (ioctl(i.fd, TIOCGETD, &i.ldisc) < 0)
|
||||
err(1, "TIOCGETD");
|
||||
if (tcgetattr(i.fd, &i.t) < 0)
|
||||
err(1, "tcgetattr");
|
||||
if (ioctl(i.fd, TIOCGWINSZ, &i.win) < 0)
|
||||
warn("TIOCGWINSZ");
|
||||
|
||||
switch(fmt) {
|
||||
case STTY_NOTSET:
|
||||
if (*argv)
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case STTY_BSD:
|
||||
case STTY_POSIX:
|
||||
print(&i.t, &i.win, i.ldisc, fmt);
|
||||
break;
|
||||
case STTY_GFLAG:
|
||||
gprint(&i.t);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i.set = i.wset = 0; *argv; ++argv) {
|
||||
if (ksearch(&argv, &i))
|
||||
continue;
|
||||
|
||||
if (csearch(&argv, &i))
|
||||
continue;
|
||||
|
||||
if (msearch(&argv, &i))
|
||||
continue;
|
||||
|
||||
if (isdigit((unsigned char)**argv)) {
|
||||
int speed;
|
||||
|
||||
speed = atoi(*argv);
|
||||
cfsetospeed(&i.t, speed);
|
||||
cfsetispeed(&i.t, speed);
|
||||
i.set = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strncmp(*argv, "gfmt1", sizeof("gfmt1") - 1)) {
|
||||
gread(&i.t, *argv + sizeof("gfmt1") - 1);
|
||||
i.set = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
warnx("illegal option -- %s", *argv);
|
||||
usage();
|
||||
}
|
||||
|
||||
if (i.set && tcsetattr(i.fd, 0, &i.t) < 0)
|
||||
err(1, "tcsetattr");
|
||||
if (i.wset && ioctl(i.fd, TIOCSWINSZ, &i.win) < 0)
|
||||
warn("TIOCSWINSZ");
|
||||
exit(0);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: %s [-a|-e|-g] [-f file] [operand ...]\n", getprogname());
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
61
bin/stty/stty.h
Normal file
61
bin/stty/stty.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* $NetBSD: stty.h,v 1.10 2003/08/07 09:05:42 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 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.
|
||||
*
|
||||
* @(#)stty.h 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
#ifndef _STTY_H_
|
||||
#define _STTY_H_
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
|
||||
struct info {
|
||||
int fd; /* file descriptor */
|
||||
int ldisc; /* line discipline */
|
||||
int off; /* turn off */
|
||||
int set; /* need set */
|
||||
int wset; /* need window set */
|
||||
char *arg; /* argument */
|
||||
struct termios t; /* terminal info */
|
||||
struct winsize win; /* window info */
|
||||
};
|
||||
|
||||
struct cchar {
|
||||
const char *name;
|
||||
int sub;
|
||||
u_char def;
|
||||
};
|
||||
|
||||
enum FMT { STTY_NOTSET, STTY_GFLAG, STTY_BSD, STTY_POSIX };
|
||||
|
||||
#define LINELENGTH 72
|
||||
|
||||
#endif /* !_STTY_H_ */
|
||||
|
|
@ -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=
|
||||
;;
|
||||
|
|
|
|||
57
commands/MAKEDEV/MAKEDEV.8
Normal file
57
commands/MAKEDEV/MAKEDEV.8
Normal file
|
|
@ -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)
|
||||
735
commands/MAKEDEV/MAKEDEV.sh
Normal file → Executable file
735
commands/MAKEDEV/MAKEDEV.sh
Normal file → Executable file
|
|
@ -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 <<EOF
|
||||
Usage: $0 [-n] key ...
|
||||
eepromb1s50 eepromb1s51 eepromb1s52 eepromb1s53
|
||||
eepromb1s54 eepromb1s55 eepromb1s56 eepromb1s57
|
||||
eepromb2s50 eepromb2s51 eepromb2s52 eepromb2s53
|
||||
eepromb2s54 eepromb2s55 eepromb2s56 eepromb2s57
|
||||
eepromb3s50 eepromb3s51 eepromb3s52 eepromb3s53
|
||||
eepromb3s54 eepromb3s55 eepromb3s56 eepromb3s57
|
||||
eth fb0 fbd filter hello
|
||||
i2c-1 i2c-2 i2c-3
|
||||
klog random
|
||||
sht21b1s40 sht21b2s40 sht21b3s40
|
||||
tsl2550b1s39 tsl2550b2s39 tsl2550b3s39
|
||||
uds
|
||||
vnd0 vnd0p0 vnd0p0s0 vnd1 vnd1p0 vnd1p0s0
|
||||
vnd2 vnd3 vnd4 vnd5 vnd6 vnd7
|
||||
"
|
||||
|
||||
#makedev ${dev} $type ${major} ${minor} ${uname} ${gname} ${permissions} [link_target]
|
||||
#When called for a link, major and minor are ignored
|
||||
makedev()
|
||||
{
|
||||
# Check that all the arguments are there, we trust the caller to put
|
||||
# values which make sens.
|
||||
[ $# -eq 7 ] || [ $# -eq 8 ] || return 1;
|
||||
|
||||
local _dev=$1
|
||||
local __type=$2
|
||||
local _major=$3
|
||||
local _minor=$4
|
||||
local _uname=$5
|
||||
local _gname=$6
|
||||
local _mode=$7
|
||||
|
||||
case ${__type} in
|
||||
b)_type=block;;
|
||||
c) _type=char;;
|
||||
l) _type=link; _target=$8;;
|
||||
*) return 2;;
|
||||
esac
|
||||
|
||||
if [ ${MTREE} = "yes" ]
|
||||
then
|
||||
if [ ${_type} = "link" ]
|
||||
then
|
||||
echo ./dev/${_dev} type=${_type} \
|
||||
uname=${_uname} gname=${_gname} mode=${_mode} \
|
||||
link=${_target}
|
||||
else
|
||||
echo ./dev/${_dev} type=${_type} \
|
||||
uname=${_uname} gname=${_gname} mode=${_mode} \
|
||||
device=native,${_major},${_minor}
|
||||
fi
|
||||
else
|
||||
if [ ${_type} = "link" ]
|
||||
then
|
||||
${ECHO} ln -f ${_target} ${_dev}
|
||||
else
|
||||
${ECHO} mknod ${_dev} ${__type} ${_major} ${_minor}
|
||||
${ECHO} chmod ${_mode} ${_dev}
|
||||
${ECHO} chown ${_uname}:${_gname} ${_dev}
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# no_return usage()
|
||||
usage()
|
||||
{
|
||||
cat >&2 <<EOF
|
||||
Usage: $0 [-n|-m] [-s|-r] key ...
|
||||
-n: print the commands instead of executing them
|
||||
-m: print mtree(8) line
|
||||
-s: standard set of devices
|
||||
-r: reduced for ramdisk set of devices
|
||||
|
||||
Where key is one of the following:
|
||||
ram mem kmem null boot zero # One of these makes all these memory devices
|
||||
fb0 # Make /dev/fb0
|
||||
|
|
@ -61,280 +133,341 @@ Where key is one of the following:
|
|||
klog # Make /dev/klog
|
||||
random # Make /dev/random, /dev/urandom
|
||||
uds # Make /dev/uds
|
||||
kbd # Make /dev/kbd
|
||||
kbdaux # Make /dev/kbdaux
|
||||
filter # Make /dev/filter
|
||||
fbd # Make /dev/fbd
|
||||
hello # Make /dev/hello
|
||||
video # Make /dev/video
|
||||
std # All standard devices
|
||||
vnd0 vnd0p0 vnd0p0s0 .. # Make vnode disks /dev/vnd[0-7] and (sub)partitions
|
||||
input # Make /dev/kbdmux, /dev/kbd[0-3], idem /dev/mouse~
|
||||
EOF
|
||||
exit 1
|
||||
esac
|
||||
exit 1
|
||||
}
|
||||
|
||||
umask 077
|
||||
ex=0
|
||||
|
||||
for dev
|
||||
# Parse options
|
||||
while getopts "nmrs" arg
|
||||
do
|
||||
case $dev in # One of the controllers? Precompute major device nr.
|
||||
c0*) maj=3 ;;
|
||||
c1*) maj=8 ;;
|
||||
c2*) maj=10 ;;
|
||||
c3*) maj=12 ;;
|
||||
esac
|
||||
|
||||
case $dev in
|
||||
ram|mem|kmem|null|boot|zero|imgrd)
|
||||
# Memory devices.
|
||||
#
|
||||
$e mknod ram b 1 0; $e chmod 600 ram
|
||||
$e mknod mem c 1 1; $e chmod 640 mem
|
||||
$e mknod kmem c 1 2; $e chmod 640 kmem
|
||||
$e mknod null c 1 3; $e chmod 666 null
|
||||
$e mknod boot b 1 4; $e chmod 600 ram
|
||||
$e mknod zero c 1 5; $e chmod 644 zero
|
||||
$e mknod imgrd b 1 6; $e chmod 644 zero
|
||||
for n in 0 1 2 3 4 5
|
||||
do $e mknod ram$n b 1 $((7+$n)); $e chmod 600 ram$n
|
||||
done
|
||||
$e chgrp kmem ram* mem kmem null boot zero imgrd
|
||||
;;
|
||||
fd[0-3])
|
||||
# Floppy disk drive n.
|
||||
#
|
||||
d=`expr $dev : '.*\\(.\\)'` # Drive number.
|
||||
$e mknod $dev b 2 $d
|
||||
$e chmod 666 $dev
|
||||
;;
|
||||
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.
|
||||
#
|
||||
d=`expr $dev : '.*\\(.\\)'` # Drive number.
|
||||
m=$d # Minor device number.
|
||||
|
||||
$e mknod pc$d b 2 $m; m=`expr $m + 4`
|
||||
$e mknod at$d b 2 $m; m=`expr $m + 4`
|
||||
$e mknod qd$d b 2 $m; m=`expr $m + 4`
|
||||
$e mknod ps$d b 2 $m; m=`expr $m + 4`
|
||||
$e mknod pat$d b 2 $m; m=`expr $m + 4`
|
||||
$e mknod qh$d b 2 $m; m=`expr $m + 4`
|
||||
$e mknod PS$d b 2 $m; m=`expr $m + 4`
|
||||
|
||||
$e chmod 666 pc$d at$d qd$d ps$d pat$d qh$d PS$d
|
||||
;;
|
||||
fd[0-3]p[0-3])
|
||||
# Floppy disk partitions.
|
||||
#
|
||||
n=`expr $dev : '\\(.*\\)..'` # Name prefix.
|
||||
d=`expr $dev : '..\\(.\\)'` # Drive number.
|
||||
m=`expr 112 + $d` # Minor of partition 0.
|
||||
alldev=
|
||||
|
||||
for p in 0 1 2 3
|
||||
do
|
||||
m=`expr 112 + $d + $p '*' 4` # Minor of partition $p.
|
||||
$e mknod ${n}p${p} b 2 $m # Make e.g. fd0p0 - fd0p3
|
||||
alldev="$alldev ${n}p${p}"
|
||||
done
|
||||
$e chmod 666 $alldev
|
||||
;;
|
||||
c[0-3]d[0-7])
|
||||
# Whole disk devices.
|
||||
d=`expr $dev : '...\\(.\\)'` # Disk number.
|
||||
m=`expr $d '*' 5` # Minor device number.
|
||||
$e mknod $dev b $maj $m
|
||||
$e chmod 600 $dev
|
||||
;;
|
||||
c[0-3]d[0-7]p[0-3])
|
||||
# Disk primary partitions.
|
||||
n=`expr $dev : '\\(.*\\).'` # Name prefix.
|
||||
d=`expr $dev : '...\\(.\\)'` # Disk number.
|
||||
alldev=
|
||||
|
||||
for p in 0 1 2 3
|
||||
do
|
||||
m=`expr $d '*' 5 + 1 + $p` # Minor device number.
|
||||
$e mknod $n$p b $maj $m
|
||||
alldev="$alldev $n$p"
|
||||
done
|
||||
echo $alldev | xargs $e chmod 600
|
||||
;;
|
||||
c[0-3]d[0-7]p[0-3]s[0-3])
|
||||
# Disk subpartition.
|
||||
n=`expr $dev : '\\(.*\\)...'` # Name prefix.
|
||||
d=`expr $dev : '...\\(.\\)'` # Disk number.
|
||||
alldev=
|
||||
|
||||
for p in 0 1 2 3
|
||||
do
|
||||
for s in 0 1 2 3
|
||||
do
|
||||
m=`expr 128 + $d '*' 16 + $p '*' 4 + $s` # Minor device nr.
|
||||
$e mknod ${n}${p}s${s} b $maj $m
|
||||
alldev="$alldev ${n}${p}s${s}"
|
||||
done
|
||||
done
|
||||
echo $alldev | xargs $e chmod 600
|
||||
;;
|
||||
c[0-3]t[0-7]|c[0-3]t[0-7]n)
|
||||
# Tape devices.
|
||||
n=`expr $dev : '\\(....\\)'` # Name prefix.
|
||||
t=`expr $dev : '...\\(.\\)'` # Tape number.
|
||||
m=`expr 64 + $t '*' 2` # Minor device number.
|
||||
$e mknod ${n}n c $maj $m
|
||||
$e mknod ${n} c $maj `expr $m + 1`
|
||||
$e chmod 660 ${n}n ${n}
|
||||
;;
|
||||
console|lp|tty|log|kbd|kbdaux|video)
|
||||
# Console, line printer, anonymous tty, diagnostics device,
|
||||
# raw keyboard, ps/2 mouse, video.
|
||||
$e mknod console c 4 0
|
||||
$e chmod 600 console
|
||||
$e chgrp tty console
|
||||
$e mknod tty c 5 0
|
||||
$e chmod 666 tty
|
||||
$e mknod lp c 6 0
|
||||
$e chown daemon lp
|
||||
$e chgrp daemon lp
|
||||
$e chmod 200 lp
|
||||
$e mknod log c 4 15
|
||||
$e chmod 222 log
|
||||
$e mknod kbd c 4 127
|
||||
$e mknod kbdaux c 4 126
|
||||
$e chmod 660 kbd kbdaux
|
||||
$e chgrp operator kbd kbdaux
|
||||
$e mknod video c 4 125
|
||||
$e chmod 600 video
|
||||
$e chgrp operator video
|
||||
;;
|
||||
ttyc[1-7])
|
||||
# Virtual consoles.
|
||||
#
|
||||
m=`expr $dev : '....\\(.*\\)'` # Minor device number.
|
||||
$e mknod $dev c 4 $m
|
||||
$e chgrp tty $dev
|
||||
$e chmod 600 $dev
|
||||
;;
|
||||
tty0[0-3])
|
||||
# Serial lines.
|
||||
#
|
||||
n=`expr $dev : '.*\\(.\\)'`
|
||||
$e mknod $dev c 4 `expr $n + 16`
|
||||
$e chmod 666 $dev
|
||||
$e chgrp tty $dev
|
||||
;;
|
||||
tty[p-s][0-9a-f]|pty[p-s][0-9a-f])
|
||||
# Pseudo ttys.
|
||||
#
|
||||
dev=`expr $dev : '...\\(..\\)'`
|
||||
g=`expr $dev : '\\(.\\)'` # Which group.
|
||||
g=`echo $g | tr 'pqrs' '0123'`
|
||||
n=`expr $dev : '.\\(.\\)'` # Which pty in the group.
|
||||
case $n in
|
||||
[a-f]) n=1`/bin/echo $n | tr 'abcdef' '012345'`
|
||||
case "$arg" in
|
||||
n)
|
||||
ECHO=echo
|
||||
;;
|
||||
m)
|
||||
MTREE=yes
|
||||
;;
|
||||
r)
|
||||
RAMDISK=yes
|
||||
;;
|
||||
s)
|
||||
STD=yes
|
||||
;;
|
||||
h|\?)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
$e mknod tty$dev c 4 `expr $g '*' 16 + $n + 128`
|
||||
$e mknod pty$dev c 4 `expr $g '*' 16 + $n + 192`
|
||||
$e chgrp tty tty$dev pty$dev
|
||||
$e chmod 666 tty$dev pty$dev
|
||||
;;
|
||||
eth|ip|tcp|udp|eth0|ip0|tcp0|udp0)
|
||||
# TCP/IP devices.
|
||||
#
|
||||
$e mknod eth0 c 7 0 # Network 0 (Ethernet)
|
||||
$e mknod ip0 c 7 1
|
||||
$e mknod tcp0 c 7 2
|
||||
$e mknod udp0 c 7 3
|
||||
$e chmod 600 eth0 ip0
|
||||
$e chmod 666 tcp0 udp0
|
||||
$e ln -f eth0 eth # Default interface
|
||||
$e ln -f ip0 ip
|
||||
$e ln -f tcp0 tcp
|
||||
$e ln -f udp0 udp
|
||||
;;
|
||||
audio|mixer)
|
||||
# Audio devices.
|
||||
#
|
||||
$e mknod audio c 13 0
|
||||
$e mknod mixer c 13 1
|
||||
$e chmod 666 audio mixer
|
||||
;;
|
||||
random|urandom)
|
||||
# random data generator.
|
||||
$e mknod random c 16 0; $e chmod 644 random
|
||||
$e mknod urandom c 16 0; $e chmod 644 urandom
|
||||
$e chgrp operator random urandom
|
||||
;;
|
||||
uds)
|
||||
# unix domain sockets device
|
||||
$e mknod uds c 18 0;
|
||||
$e chgrp operator uds
|
||||
$e chmod 666 uds
|
||||
;;
|
||||
klog)
|
||||
# logging device.
|
||||
$e mknod klog c 15 0
|
||||
$e chmod 600 klog
|
||||
;;
|
||||
filter)
|
||||
# filter driver
|
||||
$e mknod filter b 11 0
|
||||
$e chmod 600 filter
|
||||
;;
|
||||
fbd)
|
||||
# faulty block device driver
|
||||
$e mknod fbd b 14 0
|
||||
$e chmod 600 fbd
|
||||
;;
|
||||
hello)
|
||||
# hello driver
|
||||
$e mknod hello c 17 0
|
||||
$e chmod 644 hello
|
||||
;;
|
||||
fb0)
|
||||
# framebuffer driver
|
||||
$e mknod fb0 c 19 0
|
||||
$e chmod 644 fb0
|
||||
;;
|
||||
i2c-[1-3])
|
||||
# i2c driver
|
||||
b=`expr $dev : '....\\(.*\\)'` # bus number
|
||||
m=`expr $dev : '....\\(.*\\)' - 1` # least significant digit of major
|
||||
$e mknod i2c-${b} c 2${m} 0
|
||||
$e chmod 600 i2c-${b}
|
||||
;;
|
||||
eepromb[1-3]s5[0-7])
|
||||
# cat24c256 driver
|
||||
b=`expr $dev : 'eepromb\\(.*\\)s'` # bus number
|
||||
s=`expr $dev : 'eepromb.s5\\(.*\\)'` # configurable part of slave addr
|
||||
m=`expr ${b} \* 8 + ${s} + 17`
|
||||
$e mknod eepromb${b}s5${s} b ${m} 0
|
||||
$e chmod 600 eepromb${b}s5${s}
|
||||
;;
|
||||
tsl2550b[1-3]s39)
|
||||
b=`expr $dev : 'tsl2550b\\(.*\\)s39'` #bus number
|
||||
m=`expr ${b} + 46`
|
||||
$e mknod tsl2550b${b}s39 c ${m} 0
|
||||
$e chmod 444 tsl2550b${b}s39
|
||||
;;
|
||||
sht21b[1-3]s40)
|
||||
b=`expr $dev : 'sht21b\\(.*\\)s40'` #bus number
|
||||
m=`expr ${b} + 49`
|
||||
$e mknod sht21b${b}s40 c ${m} 0
|
||||
$e chmod 444 sht21b${b}s40
|
||||
;;
|
||||
bmp085b[1-3]s77)
|
||||
b=`expr $dev : 'bmp085b\\(.*\\)s77'` #bus number
|
||||
m=`expr ${b} + 52`
|
||||
$e mknod bmp085b${b}s77 c ${m} 0
|
||||
$e chmod 444 bmp085b${b}s77
|
||||
;;
|
||||
*)
|
||||
echo "$0: don't know about $dev" >&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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
SCRIPTS= MAKEDEV.sh
|
||||
MAN=
|
||||
MAN= MAKEDEV.8
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
|||
|
|
@ -6,35 +6,37 @@ 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 grep host \
|
||||
hostaddr ifconfig ifdef \
|
||||
intr ipcrm ipcs irdpd isoread last \
|
||||
intr ipcrm ipcs irdpd isoread \
|
||||
less loadkeys loadramdisk logger look lp \
|
||||
lpd lspci mail MAKEDEV \
|
||||
mined \
|
||||
mount mt netconf \
|
||||
nonamed patch \
|
||||
ping postinstall poweroff prep printroot \
|
||||
ping postinstall prep printroot \
|
||||
profile progressbar pr_routes ps pwdauth \
|
||||
ramdisk rarpd rawspeed rcp readclock \
|
||||
reboot remsync rget rlogin \
|
||||
remsync rget rlogin \
|
||||
rotate rsh rshd service setup shar \
|
||||
sleep slip spell sprofalyze sprofdiff srccrc \
|
||||
stty svclog svrctl swifi synctree sysenv \
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <bsd.prog.mk>
|
||||
|
|
|
|||
|
|
@ -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" "$@"
|
||||
1
commands/cd/cd.sh
Symbolic link
1
commands/cd/cd.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
5
commands/command/Makefile
Normal file
5
commands/command/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= command.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/command/command.sh
Symbolic link
1
commands/command/command.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
PROG= df
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
237
commands/df/df.c
237
commands/df/df.c
|
|
@ -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 <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <minix/minlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
PROG= dumpcore
|
||||
CPPFLAGS+= -I${NETBSDSRCDIR}
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/* dumpcore - create core file of running process */
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <minix/config.h>
|
||||
#include <minix/type.h>
|
||||
#include <minix/ipc.h>
|
||||
#include <minix/const.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <timers.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <machine/archtypes.h>
|
||||
#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 <pid>\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;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
PROG= getty
|
||||
SCRIPTS= echo.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
1
commands/echo/echo.sh
Symbolic link
1
commands/echo/echo.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
5
commands/expr/Makefile
Normal file
5
commands/expr/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= expr.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/expr/expr.sh
Symbolic link
1
commands/expr/expr.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
5
commands/false/Makefile
Normal file
5
commands/false/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= false.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/false/false.sh
Symbolic link
1
commands/false/false.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
PROG= gcore
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
/* gcore - create core file of running process */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
pid_t pid;
|
||||
int status;
|
||||
|
||||
if(argc != 2) {
|
||||
printf("usage: %s <pid>\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;
|
||||
}
|
||||
5
commands/getopts/Makefile
Normal file
5
commands/getopts/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= getopts.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/getopts/getopts.sh
Symbolic link
1
commands/getopts/getopts.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
|
|
@ -1,210 +0,0 @@
|
|||
/* getty - get tty speed Author: Fred van Kempen */
|
||||
|
||||
/*
|
||||
* GETTY - Initialize and serve a login-terminal for INIT.
|
||||
* Also, select the correct speed. The STTY() code
|
||||
* was taken from stty(1).c; which was written by
|
||||
* Andrew S. Tanenbaum.
|
||||
*
|
||||
* Usage: getty [speed]
|
||||
*
|
||||
* Version: 3.4 02/17/90
|
||||
*
|
||||
* Author: F. van Kempen, MicroWalt Corporation
|
||||
*
|
||||
* Modifications:
|
||||
* All the good stuff removed to get a minimal getty, because
|
||||
* many modems don't like all that fancy speed detection stuff.
|
||||
* 03/03/91 Kees J. Bot (kjb@cs.vu.nl)
|
||||
*
|
||||
* Uname(), termios. More nonsense removed. (The result has
|
||||
* only 10% of the original functionality, but a 10x chance of
|
||||
* working.)
|
||||
* 12/12/92 Kees J. Bot
|
||||
*
|
||||
* Customizable login banner.
|
||||
* 11/13/95 Kees J. Bot
|
||||
*
|
||||
* Suspend/resume signals removed.
|
||||
* 2001-04-04 Kees J. Bot
|
||||
*
|
||||
* Removed unused custom banner and returned speed option
|
||||
* functionality (by simply calling stty).
|
||||
* 2012-09-24 T. Veerman
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char LOGIN[] = "/usr/bin/login";
|
||||
char SHELL[] = "/bin/sh";
|
||||
|
||||
char *tty_name; /* name of the line */
|
||||
|
||||
/* Crude indication of a tty being physically secure: */
|
||||
#define securetty(dev) ((unsigned) ((dev) - 0x0400) < (unsigned) 8)
|
||||
|
||||
void std_out(const char *s)
|
||||
{
|
||||
write(1, s, strlen(s));
|
||||
}
|
||||
|
||||
/* Read one character from stdin.
|
||||
*/
|
||||
int readch(void)
|
||||
{
|
||||
int st;
|
||||
char ch1;
|
||||
|
||||
/* read character from TTY */
|
||||
st = read(0, &ch1, 1);
|
||||
if (st == 0) {
|
||||
std_out("\n");
|
||||
exit(0);
|
||||
}
|
||||
if (st < 0) {
|
||||
std_out("getty: ");
|
||||
std_out(tty_name);
|
||||
std_out(": read error\n");
|
||||
exit(1);
|
||||
}
|
||||
return(ch1 & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
/* Handle the process of a GETTY.
|
||||
*/
|
||||
void do_getty(char *name, size_t len, char **args, const char *ttyname)
|
||||
{
|
||||
register char *np, *s, *s0;
|
||||
int ch;
|
||||
struct utsname utsname;
|
||||
char **banner, *t;
|
||||
static char *def_banner[] = { "%s Release %r Version %v (%t)\n\n%n login: ", 0 };
|
||||
|
||||
/* Clean up tty name. */
|
||||
if((t = strrchr(ttyname, '/'))) ttyname = t + 1;
|
||||
|
||||
if (args[0] != NULL) {
|
||||
char cmd[5+6+1]; /* "stty " + "115200" + '\0' */
|
||||
int speed;
|
||||
speed = atoi(args[0]);
|
||||
snprintf(cmd, sizeof(cmd), "stty %d\n", speed);
|
||||
system(cmd);
|
||||
}
|
||||
|
||||
/* Display prompt. */
|
||||
ch = ' ';
|
||||
*name = '\0';
|
||||
while (ch != '\n') {
|
||||
/* Get data about this machine. */
|
||||
uname(&utsname);
|
||||
|
||||
/* Print the banner. */
|
||||
for (banner = def_banner; *banner != NULL; banner++) {
|
||||
std_out(banner == args ? "\n" : " ");
|
||||
s0 = *banner;
|
||||
for (s = *banner; *s != 0; s++) {
|
||||
if (*s == '\\') {
|
||||
write(1, s0, s-s0);
|
||||
s0 = s+2;
|
||||
switch (*++s) {
|
||||
case 'n': std_out("\n"); break;
|
||||
case 's': std_out(" "); break;
|
||||
case 't': std_out("\t"); break;
|
||||
case 0: goto leave;
|
||||
default: s0 = s;
|
||||
}
|
||||
} else
|
||||
if (*s == '%') {
|
||||
write(1, s0, s-s0);
|
||||
s0 = s+2;
|
||||
switch (*++s) {
|
||||
case 's': std_out(utsname.sysname); break;
|
||||
case 'n': std_out(utsname.nodename); break;
|
||||
case 'r': std_out(utsname.release); break;
|
||||
case 'v': std_out(utsname.version); break;
|
||||
case 'm': std_out(utsname.machine); break;
|
||||
case 'p': std_out(utsname.arch); break;
|
||||
case 't': std_out(ttyname); break;
|
||||
#if __minix_vmd
|
||||
case 'k': std_out(utsname.kernel); break;
|
||||
case 'h': std_out(utsname.hostname); break;
|
||||
case 'b': std_out(utsname.bus); break;
|
||||
#endif
|
||||
case 0: goto leave;
|
||||
default: s0 = s-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
leave:
|
||||
write(1, s0, s-s0);
|
||||
}
|
||||
|
||||
np = name;
|
||||
while ((ch = readch()) != '\n') {
|
||||
if (np < name + len) *np++ = ch;
|
||||
}
|
||||
*np = '\0';
|
||||
if (*name == '\0') ch = ' '; /* blank line typed! */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Execute the login(1) command with the current
|
||||
* username as its argument. It will reply to the
|
||||
* calling user by typing "Password: "...
|
||||
*/
|
||||
void do_login(char *name)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
execl(LOGIN, LOGIN, name, (char *) NULL);
|
||||
/* Failed to exec login. Impossible, but true. Try a shell, but only if
|
||||
* the terminal is more or less secure, because it will be a root shell.
|
||||
*/
|
||||
std_out("getty: can't exec ");
|
||||
std_out(LOGIN);
|
||||
std_out("\n");
|
||||
if (fstat(0, &st) == 0 && S_ISCHR(st.st_mode) && securetty(st.st_rdev)) {
|
||||
execl(SHELL, SHELL, (char *) NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char name[30];
|
||||
struct sigaction sa;
|
||||
|
||||
/* Don't let QUIT dump core. */
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = exit;
|
||||
sigaction(SIGQUIT, &sa, NULL);
|
||||
|
||||
tty_name = ttyname(0);
|
||||
if (tty_name == NULL) {
|
||||
std_out("getty: tty name unknown\n");
|
||||
pause();
|
||||
return(1);
|
||||
}
|
||||
|
||||
chown(tty_name, 0, 0); /* set owner of TTY to root */
|
||||
chmod(tty_name, 0600); /* mode to max secure */
|
||||
|
||||
do_getty(name, sizeof(name), argv+1, tty_name); /* handle getty() */
|
||||
name[29] = '\0'; /* make sure the name fits! */
|
||||
|
||||
do_login(name); /* and call login(1) if OK */
|
||||
|
||||
return(1); /* never executed */
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
PROG= last
|
||||
MAN=
|
||||
|
||||
LINKS+= ${BINDIR}/last ${BINDIR}/uptime
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,482 +0,0 @@
|
|||
/* last - display login history Author: Terrence W. Holm */
|
||||
|
||||
/* last- Display the user log-in history.
|
||||
* Last(1) searches backwards through the file of log-in
|
||||
* records (/usr/adm/wtmp), displaying the length of
|
||||
* log-in sessions as requested by the options:
|
||||
*
|
||||
* Usage: last [-r] [-count] [-f file] [name] [tty] ...
|
||||
*
|
||||
* -r Search backwards only until the last reboot
|
||||
* record.
|
||||
*
|
||||
* -count Only print out <count> records. Last(1) stops
|
||||
* when either -r or -count is satisfied, or at
|
||||
* the end of the file if neither is given.
|
||||
*
|
||||
* -f file Use "file" instead of "/usr/adm/wtmp".
|
||||
*
|
||||
* name Print records for the user "name".
|
||||
*
|
||||
* tty Print records for the terminal "tty". Actually,
|
||||
* a list of names may be given and all records
|
||||
* that match either the user or tty name are
|
||||
* printed. If no names are given then all records
|
||||
* are displayed.
|
||||
*
|
||||
* A sigquit (^\) causes last(1) to display how far it
|
||||
* has gone back in the log-in record file, it then
|
||||
* continues. This is used to check on the progress of
|
||||
* long running searches. A sigint will stop last(1).
|
||||
*
|
||||
* Author: Terrence W. Holm May 1988
|
||||
*
|
||||
* Revision:
|
||||
* Fred van Kempen, October 1989
|
||||
* -Adapted to MSS.
|
||||
* -Adapted to new utmp database.
|
||||
*
|
||||
* Fred van Kempen, December 1989
|
||||
* -Adapted to POSIX (MINIX 1.5)
|
||||
*
|
||||
* Fred van Kempen, January 1990
|
||||
* -Final edit for 1.5
|
||||
*
|
||||
* Philip Homburg, March 1992
|
||||
* -Include host in output
|
||||
*
|
||||
* Kees J. Bot, July 1997
|
||||
* -Approximate system uptime from last reboot record
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <utmp.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <paths.h>
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#define RLOGIN 1
|
||||
|
||||
#define BUFFER_SIZE 4096 /* Room for wtmp records */
|
||||
#define MAX_WTMP_COUNT ( BUFFER_SIZE / sizeof(struct utmp) )
|
||||
|
||||
#define min( a, b ) ( (a < b) ? a : b )
|
||||
#define max( a, b ) ( (a > b) ? a : b )
|
||||
|
||||
|
||||
typedef struct logout { /* A logout time record */
|
||||
char line[12]; /* The terminal name */
|
||||
long time; /* The logout time */
|
||||
struct logout *next; /* Next in linked list */
|
||||
} logout;
|
||||
|
||||
|
||||
static char *Version = "@(#) LAST 1.7 (10/24/92)";
|
||||
|
||||
|
||||
/* command-line option flags */
|
||||
char boot_limit = FALSE; /* stop on latest reboot */
|
||||
char count_limit = FALSE; /* stop after print_count */
|
||||
char tell_uptime = FALSE; /* tell uptime since last reboot */
|
||||
int print_count;
|
||||
char *prog; /* name of this program */
|
||||
int arg_count; /* used to select specific */
|
||||
char **args; /* users and ttys */
|
||||
|
||||
/* global variables */
|
||||
long boot_time = 0; /* Zero means no reboot yet */
|
||||
char *boot_down; /* "crash" or "down " flag */
|
||||
logout *first_link = NULL; /* List of logout times */
|
||||
int interrupt = FALSE; /* If sigint or sigquit occurs */
|
||||
|
||||
int main(int argc, char **argv);
|
||||
void Sigint(int sig);
|
||||
void Sigquit(int sig);
|
||||
void usage(void);
|
||||
void Process(struct utmp *wtmp);
|
||||
int Print_Record(struct utmp *wtmp);
|
||||
void Print_Duration(long from, long to);
|
||||
void Print_Uptime(void);
|
||||
void Record_Logout_Time(struct utmp *wtmp);
|
||||
|
||||
/* Sigint() and Sigquit() Flag occurrence of an interrupt. */
|
||||
void Sigint(sig)
|
||||
int sig;
|
||||
{
|
||||
interrupt = SIGINT;
|
||||
}
|
||||
|
||||
|
||||
void Sigquit(sig)
|
||||
int sig;
|
||||
{
|
||||
interrupt = SIGQUIT;
|
||||
}
|
||||
|
||||
|
||||
void usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: last [-r] [-u] [-count] [-f file] [name] [tty] ...\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
/* A log-in record format file contains four types of records.
|
||||
*
|
||||
* [1] generated on a system reboot:
|
||||
*
|
||||
* line="~", name="reboot", host="", time=date()
|
||||
*
|
||||
*
|
||||
* [2] generated after a shutdown:
|
||||
*
|
||||
* line="~", name="shutdown", host="", time=date()
|
||||
*
|
||||
*
|
||||
* [3] generated on a successful login(1)
|
||||
*
|
||||
* line=ttyname(), name=cuserid(), host=, time=date()
|
||||
*
|
||||
*
|
||||
* [4] generated by init(8) on a logout
|
||||
*
|
||||
* line=ttyname(), name="", host="", time=date()
|
||||
*
|
||||
*
|
||||
* Note: This version of last(1) does not recognize the '|' and '}' time
|
||||
* change records. Last(1) pairs up line login's and logout's to
|
||||
* generate four types of output lines:
|
||||
*
|
||||
* [1] a system reboot or shutdown
|
||||
*
|
||||
* reboot ~ Mon May 16 14:16
|
||||
* shutdown ~ Mon May 16 14:15
|
||||
*
|
||||
* [2] a login with a matching logout
|
||||
*
|
||||
* edwin tty1 Thu May 26 20:05 - 20:32 (00:27)
|
||||
*
|
||||
* [3] a login followed by a reboot or shutdown
|
||||
*
|
||||
* root tty0 Mon May 16 13:57 - crash (00:19)
|
||||
* root tty1 Mon May 16 13:45 - down (00:30)
|
||||
*
|
||||
* [4] a login not followed by a logout or reboot
|
||||
*
|
||||
* terry tty0 Thu May 26 21:19 still logged in
|
||||
*/
|
||||
void Process(wtmp)
|
||||
struct utmp *wtmp;
|
||||
{
|
||||
logout *link;
|
||||
logout *next_link;
|
||||
char is_reboot;
|
||||
|
||||
/* suppress the job number on an "ftp" line */
|
||||
if (!strncmp(wtmp->ut_line, "ftp", (size_t)3)) strncpy(wtmp->ut_line, "ftp", (size_t)8);
|
||||
|
||||
if (!strcmp(wtmp->ut_line, "~")) {
|
||||
/* A reboot or shutdown record */
|
||||
if (boot_limit) exit(0);
|
||||
|
||||
if (Print_Record(wtmp)) putchar('\n');
|
||||
boot_time = wtmp->ut_time;
|
||||
|
||||
is_reboot = !strcmp(wtmp->ut_name, "reboot");
|
||||
if (is_reboot)
|
||||
boot_down = "crash";
|
||||
else
|
||||
boot_down = "down ";
|
||||
|
||||
if (tell_uptime) {
|
||||
if (!is_reboot) {
|
||||
fprintf(stderr,
|
||||
"%s: no reboot record added to wtmp file on system boot!\n",
|
||||
prog);
|
||||
exit(1);
|
||||
}
|
||||
Print_Uptime();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* remove any logout records */
|
||||
for (link = first_link; link != NULL; link = next_link) {
|
||||
next_link = link->next;
|
||||
free(link);
|
||||
}
|
||||
first_link = NULL;
|
||||
} else if (wtmp->ut_name[0] == '\0') {
|
||||
/* A logout record */
|
||||
Record_Logout_Time(wtmp);
|
||||
} else {
|
||||
/* A login record */
|
||||
for (link = first_link; link != NULL; link = link->next)
|
||||
if (!strncmp(link->line, wtmp->ut_line, (size_t)8)) {
|
||||
/* found corresponding logout record */
|
||||
if (Print_Record(wtmp)) {
|
||||
printf("- %.5s ", ctime(&link->time) + 11);
|
||||
Print_Duration(wtmp->ut_time, link->time);
|
||||
}
|
||||
/* record login time */
|
||||
link->time = wtmp->ut_time;
|
||||
return;
|
||||
}
|
||||
/* could not find a logout record for this login tty */
|
||||
if (Print_Record(wtmp))
|
||||
if (boot_time == 0) /* still on */
|
||||
printf(" still logged in\n");
|
||||
else { /* system crashed while on */
|
||||
printf("- %s ", boot_down);
|
||||
Print_Duration(wtmp->ut_time, boot_time);
|
||||
}
|
||||
Record_Logout_Time(wtmp); /* Needed in case of 2
|
||||
* consecutive logins */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Print_Record(wtmp) If the record was requested, then print out
|
||||
* the user name, terminal, host and time.
|
||||
*/
|
||||
int Print_Record(wtmp)
|
||||
struct utmp *wtmp;
|
||||
{
|
||||
int i;
|
||||
char print_flag = FALSE;
|
||||
|
||||
/* just interested in the uptime? */
|
||||
if (tell_uptime) return(FALSE);
|
||||
|
||||
/* check if we have already printed the requested number of records */
|
||||
if (count_limit && print_count == 0) exit(0);
|
||||
|
||||
for (i = 0; i < arg_count; ++i)
|
||||
if (!strncmp(args[i], wtmp->ut_name, sizeof(wtmp->ut_name)) ||
|
||||
!strncmp(args[i], wtmp->ut_line, sizeof(wtmp->ut_line)))
|
||||
print_flag = TRUE;
|
||||
|
||||
if (arg_count == 0 || print_flag) {
|
||||
#ifdef RLOGIN
|
||||
printf("%-8.8s %-8.8s %-16.16s %.16s ",
|
||||
wtmp->ut_name, wtmp->ut_line, wtmp->ut_host,
|
||||
ctime(&wtmp->ut_time));
|
||||
#else
|
||||
printf("%-8.8s %-8.8s %.16s ",
|
||||
wtmp->ut_name, wtmp->ut_line, ctime(&wtmp->ut_time));
|
||||
#endif
|
||||
--print_count;
|
||||
return(TRUE);
|
||||
}
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/* Print_Duration(from, to) Calculate and print the days and hh:mm between
|
||||
* the log-in and the log-out.
|
||||
*/
|
||||
void Print_Duration(from, to)
|
||||
long from;
|
||||
long to;
|
||||
{
|
||||
long delta, days, hours, minutes;
|
||||
|
||||
delta = max(to - from, 0);
|
||||
days = delta / (24L * 60L * 60L);
|
||||
delta = delta % (24L * 60L * 60L);
|
||||
hours = delta / (60L * 60L);
|
||||
delta = delta % (60L * 60L);
|
||||
minutes = delta / 60L;
|
||||
|
||||
if (days > 0)
|
||||
printf("(%ld+", days);
|
||||
else
|
||||
printf(" (");
|
||||
|
||||
printf("%02ld:%02ld)\n", hours, minutes);
|
||||
}
|
||||
|
||||
|
||||
/* Print_Uptime() Calculate and print the "uptime" between the last recorded
|
||||
* boot and the current time.
|
||||
*/
|
||||
void Print_Uptime()
|
||||
{
|
||||
#define NLOADS 3
|
||||
int nloads;
|
||||
double loads[NLOADS];
|
||||
char *utmp_file = _PATH_UTMP;
|
||||
unsigned nusers;
|
||||
struct utmp ut;
|
||||
FILE *uf;
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
unsigned long up;
|
||||
|
||||
/* Count the number of active users in the utmp file. */
|
||||
if ((uf = fopen(utmp_file, "r")) == NULL) {
|
||||
fprintf(stderr, "%s: %s: %s\n", prog, utmp_file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
nusers = 0;
|
||||
while (fread(&ut, sizeof(ut), 1, uf) == 1) {
|
||||
#ifdef USER_PROCESS
|
||||
if (ut.ut_type == USER_PROCESS) nusers++;
|
||||
#else
|
||||
if (ut.ut_name[0] != 0 && ut.ut_line[0] != 0) nusers++;
|
||||
#endif
|
||||
}
|
||||
fclose(uf);
|
||||
|
||||
/* Current time. */
|
||||
now = time((time_t *) NULL);
|
||||
tm = localtime(&now);
|
||||
|
||||
/* Uptime. */
|
||||
up = now - boot_time;
|
||||
|
||||
printf(" %d:%02d up", tm->tm_hour, tm->tm_min);
|
||||
if (up >= 24 * 3600L) {
|
||||
unsigned long days = up / (24 * 3600L);
|
||||
printf(" %lu day%s,", days, days == 1 ? "" : "s");
|
||||
}
|
||||
printf(" %lu:%02lu,", (up % (24 * 3600L)) / 3600, (up % 3600) / 60);
|
||||
printf(" %u user%s", nusers, nusers == 1 ? "" : "s");
|
||||
if((nloads = getloadavg(loads, NLOADS)) > 0) {
|
||||
int i;
|
||||
printf(", load averages:");
|
||||
for(i = 0; i < nloads; i++)
|
||||
printf("%s %.2f", (i > 0) ? "," : "", loads[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/* Record_Logout_Time(wtmp) A linked list of "last logout time" is kept.
|
||||
* Each element of the list is for one terminal.
|
||||
*/
|
||||
void Record_Logout_Time(wtmp)
|
||||
struct utmp *wtmp;
|
||||
{
|
||||
logout *link;
|
||||
|
||||
/* see if the terminal is already in the list */
|
||||
for (link = first_link; link != NULL; link = link->next)
|
||||
if (!strncmp(link->line, wtmp->ut_line, (size_t)8)) {
|
||||
link->time = wtmp->ut_time;
|
||||
return;
|
||||
}
|
||||
/* allocate a new logout record, for a tty not previously encountered */
|
||||
link = (logout *) malloc(sizeof(logout));
|
||||
if (link == NULL) {
|
||||
fprintf(stderr, "%s: malloc failure\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
strncpy(link->line, wtmp->ut_line, (size_t)8);
|
||||
link->time = wtmp->ut_time;
|
||||
link->next = first_link;
|
||||
|
||||
first_link = link;
|
||||
}
|
||||
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *wtmp_file = _PATH_WTMP;
|
||||
FILE *f;
|
||||
long size; /* Number of wtmp records in the file */
|
||||
int wtmp_count; /* How many to read into wtmp_buffer */
|
||||
struct utmp wtmp_buffer[MAX_WTMP_COUNT];
|
||||
|
||||
if ((prog = strrchr(argv[0], '/')) == NULL) prog = argv[0]; else prog++;
|
||||
|
||||
--argc;
|
||||
++argv;
|
||||
|
||||
while (argc > 0 && *argv[0] == '-') {
|
||||
if (!strcmp(argv[0], "-r"))
|
||||
boot_limit = TRUE;
|
||||
else
|
||||
if (!strcmp(argv[0], "-u"))
|
||||
tell_uptime = TRUE;
|
||||
else if (argc > 1 && !strcmp(argv[0], "-f")) {
|
||||
wtmp_file = argv[1];
|
||||
--argc;
|
||||
++argv;
|
||||
} else if ((print_count = atoi(argv[0] + 1)) > 0)
|
||||
count_limit = TRUE;
|
||||
else
|
||||
usage();
|
||||
|
||||
--argc;
|
||||
++argv;
|
||||
}
|
||||
|
||||
arg_count = argc;
|
||||
args = argv;
|
||||
|
||||
if (!strcmp(prog, "uptime")) tell_uptime = TRUE;
|
||||
|
||||
if ((f = fopen(wtmp_file, "r")) == NULL) {
|
||||
perror(wtmp_file);
|
||||
exit(1);
|
||||
}
|
||||
if (fseek(f, 0L, 2) != 0 || (size = ftell(f)) % sizeof(struct utmp) != 0) {
|
||||
fprintf(stderr, "%s: invalid wtmp file\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
|
||||
signal(SIGINT, Sigint);
|
||||
signal(SIGQUIT, Sigquit);
|
||||
}
|
||||
size /= sizeof(struct utmp); /* Number of records in wtmp */
|
||||
|
||||
if (size == 0) wtmp_buffer[0].ut_time = time((time_t *)0);
|
||||
|
||||
while (size > 0) {
|
||||
wtmp_count = (int) min(size, MAX_WTMP_COUNT);
|
||||
size -= (long) wtmp_count;
|
||||
|
||||
fseek(f, size * sizeof(struct utmp), 0);
|
||||
|
||||
|
||||
if (fread(&wtmp_buffer[0], sizeof(struct utmp), (size_t)wtmp_count, f)
|
||||
!= wtmp_count) {
|
||||
fprintf(stderr, "%s: read error on wtmp file\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
while (--wtmp_count >= 0) {
|
||||
Process(&wtmp_buffer[wtmp_count]);
|
||||
if (interrupt) {
|
||||
printf("\ninterrupted %.16s \n",
|
||||
ctime(&wtmp_buffer[wtmp_count].ut_time));
|
||||
|
||||
if (interrupt == SIGINT) exit(2);
|
||||
|
||||
interrupt = FALSE;
|
||||
signal(SIGQUIT, Sigquit);
|
||||
}
|
||||
}
|
||||
|
||||
} /* end while(size > 0) */
|
||||
|
||||
if (tell_uptime) {
|
||||
fprintf(stderr,
|
||||
"%s: no reboot record in wtmp file to compute uptime from\n",
|
||||
prog);
|
||||
return(1);
|
||||
}
|
||||
|
||||
printf("\nwtmp begins %.16s \n", ctime(&wtmp_buffer[0].ut_time));
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
|
@ -6,86 +6,51 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#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 <mapfile>\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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
SCRIPTS= poweroff.sh
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# poweroff 1.0 - power off the system Author: David van Moolenbroek
|
||||
# 12 Jun 2009
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "usage: poweroff" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PATH=/usr/bin:$PATH
|
||||
|
||||
exec shutdown -p
|
||||
|
|
@ -193,7 +193,6 @@ static char *prrecv(struct pstat *ps)
|
|||
blkstr = "?";
|
||||
if (ps->ps_recv == PM_PROC_NR) {
|
||||
switch (ps->ps_pstate) {
|
||||
case PSTATE_PAUSED: blkstr = "pause"; break;
|
||||
case PSTATE_WAITING: blkstr = "wait"; break;
|
||||
case PSTATE_SIGSUSP: blkstr = "sigsusp"; break;
|
||||
}
|
||||
|
|
@ -203,7 +202,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;
|
||||
}
|
||||
|
|
|
|||
5
commands/read/Makefile
Normal file
5
commands/read/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= read.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/read/read.sh
Symbolic link
1
commands/read/read.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include <lib.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
|
@ -146,6 +147,7 @@ readclock(int type, struct tm *t, int flags)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
memset(&m, 0, sizeof(m));
|
||||
m.RTCDEV_TM = (char *) t;
|
||||
m.RTCDEV_FLAGS = flags;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
# Makefile for shutdown / halt / reboot.
|
||||
|
||||
PROGS= shutdown halt
|
||||
SRCS.shutdown= shutdown.c sh_wall.c log.c
|
||||
SRCS.halt= halt.c log.c
|
||||
BINDIR=/bin
|
||||
BINMODE= 4754
|
||||
SYMLINKS+= ${BINDIR}/halt ${BINDIR}/reboot
|
||||
SYMLINKS+= ${BINDIR}/halt /usr/bin/halt
|
||||
SYMLINKS+= ${BINDIR}/shutdown /usr/bin/shutdown
|
||||
SYMLINKS+= ${BINDIR}/reboot /usr/bin/reboot
|
||||
MAN.shutdown=
|
||||
MAN.halt=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
This a new implementation of a shutdown procedure. It allows
|
||||
the system to go down graciously with informing the
|
||||
users. This package contains 3 programs:
|
||||
|
||||
- halt = Immediately stop the system, no info to users
|
||||
- shutdown = Inform users, close down the system properly
|
||||
- wall = Vincent Archer's implementation of wall (Write all)
|
||||
|
||||
Installing
|
||||
|
||||
Shutdown and halt use a new systemcall, which I've added to
|
||||
MM. Therefor there are several diff's which should be applied:
|
||||
|
||||
callnr.hd - New callnr for reboot(2)
|
||||
Diff against /usr/include/minix/callnr.h.
|
||||
Those of you using a symlink package should
|
||||
change the number and mm/table.c into a free
|
||||
number. I used 54, LSTAT.
|
||||
param.hd - Defines reboot_flag as a part of the messages
|
||||
proto.hd - Add's prototype for do_reboot()
|
||||
table.cd - Interpretation of the systemcall to MM
|
||||
mm.cd - I have added the do_reboot code to mm/getset.c but
|
||||
I couldn't find a getset.c to create a useable diff :-(
|
||||
So you can add where you want it. It is pure code, no diff.
|
||||
|
||||
Now edit log.c and search for ``host''. Change this into your
|
||||
systemname or make it empty.
|
||||
|
||||
Shutdown and halt log their actions in /usr/adm/log, edit the
|
||||
makefile and undefine -DLOG if you don't want this (this at the end of
|
||||
the makefile). You can change SHUT_LOG in shutdown.c and log.c if you
|
||||
want it in another file.
|
||||
|
||||
Then type a `make'. This will take a minute or so (13 sec. with bcc :-).
|
||||
Remember to build a new image and update the ps_database.
|
||||
|
||||
Type `make install' to place the program's where I've got them.
|
||||
Use them, try them and let me now if you've got problems running
|
||||
something.
|
||||
|
||||
I have tested to sources both on 16-bits and 32-bits MINIX. I have compiled
|
||||
it with gcc, bcc and ACK, so that shouldn't really give a problem. Maybe
|
||||
the standard MINIX-make chokes on the makefile, atleast mine did.
|
||||
|
||||
NOTE:
|
||||
Make install does not place the man-pages somewhere. You should
|
||||
do this yourself.
|
||||
|
||||
--
|
||||
Edvard Tuinder ed@pulstar.NL.mugnet.org v892231@si.hhs.NL
|
||||
Student Computer Science
|
||||
Haagse Hogeschool, The Hague, The Netherlands
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
/* halt / reboot - halt or reboot system (depends on name)
|
||||
|
||||
halt - calling reboot() with RBT_HALT
|
||||
reboot - calling reboot() with RBT_REBOOT
|
||||
|
||||
author: Edvard Tuinder v892231@si.hhs.NL
|
||||
|
||||
This program calls the library function reboot(2) which performs
|
||||
the system-call do_reboot.
|
||||
|
||||
*/
|
||||
|
||||
#define _POSIX_SOURCE 1
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <minix/reboot.h>
|
||||
|
||||
#include "wtmp.h"
|
||||
|
||||
void write_log( char *fn );
|
||||
void usage( void );
|
||||
int main( int argc, char *argv[] );
|
||||
|
||||
char *prog;
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-hrRfpd]\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(argc,argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int flag = -1; /* default action unknown */
|
||||
int fast = 0; /* fast halt/reboot, don't bother being nice. */
|
||||
int i;
|
||||
struct stat dummy;
|
||||
pid_t pid;
|
||||
|
||||
if ((prog = strrchr(argv[0],'/')) == NULL) prog = argv[0]; else prog++;
|
||||
|
||||
if (strcmp(prog, "halt") == 0) flag = RBT_HALT;
|
||||
if (strcmp(prog, "reboot") == 0) flag = RBT_REBOOT;
|
||||
|
||||
i = 1;
|
||||
while (i < argc && argv[i][0] == '-') {
|
||||
char *opt = argv[i++] + 1;
|
||||
|
||||
if (*opt == '-' && opt[1] == 0) break; /* -- */
|
||||
|
||||
while (*opt != 0) switch (*opt++) {
|
||||
case 'h': flag = RBT_HALT; break;
|
||||
case 'r': flag = RBT_REBOOT; break;
|
||||
case 'R': flag = RBT_RESET; break;
|
||||
case 'd': flag = RBT_DEFAULT; break;
|
||||
case 'p': flag = RBT_POWEROFF; break;
|
||||
case 'f': fast = 1; break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (i != argc) usage();
|
||||
|
||||
if (flag == -1) {
|
||||
fprintf(stderr, "Don't know what to do when named '%s'\n", prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (stat("/usr/bin", &dummy) < 0) {
|
||||
/* It seems that /usr isn't present, let's assume "-f." */
|
||||
fast = 1;
|
||||
}
|
||||
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
|
||||
/* Skip this part for fast shut down. */
|
||||
if (! fast) {
|
||||
/* Run the shutdown scripts. */
|
||||
switch ((pid = fork())) {
|
||||
case -1:
|
||||
fprintf(stderr, "%s: can't fork(): %s\n", prog, strerror(errno));
|
||||
exit(1);
|
||||
case 0:
|
||||
execl("/bin/sh", "sh", "/etc/rc", "down", (char *) NULL);
|
||||
fprintf(stderr, "%s: can't execute: /bin/sh: %s\n",
|
||||
prog, strerror(errno));
|
||||
exit(1);
|
||||
default:
|
||||
while (waitpid(pid, NULL, 0) != pid) {}
|
||||
}
|
||||
}
|
||||
|
||||
/* Tell init to stop spawning getty's. */
|
||||
kill(1, SIGTERM);
|
||||
|
||||
/* Extra sync for the case where SIGTERM causes deadlock */
|
||||
sync();
|
||||
|
||||
/* Give everybody a chance to die peacefully. */
|
||||
printf("Sending SIGTERM to all processes ...\n");
|
||||
kill(-1, SIGTERM);
|
||||
sleep(1);
|
||||
|
||||
write_log(STR_WTMP);
|
||||
write_log(STR_ROOT_WTMP);
|
||||
|
||||
sync();
|
||||
|
||||
reboot(flag);
|
||||
fprintf(stderr, "%s: reboot(): %s\n", prog, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
log - log the shutdown's and the halt's
|
||||
|
||||
Author: Edvard Tuinder <v892231@si.hhs.NL>
|
||||
|
||||
shutdown is logged in /usr/adm/wtmp and in /usr/adm/log (if desired)
|
||||
halt is logged only in /usr/adm/wtmp as `halt' to prevent last from
|
||||
reporting halt's as crashes.
|
||||
|
||||
*/
|
||||
|
||||
#define _POSIX_SOURCE 1
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <utmp.h>
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
static char SHUT_LOG[] = "/usr/adm/log";
|
||||
|
||||
char who[8];
|
||||
extern char *prog;
|
||||
static char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
void write_log(char *wtmpfile)
|
||||
{
|
||||
int fd;
|
||||
static struct utmp wtmp;
|
||||
static struct passwd *pwd;
|
||||
char mes[90];
|
||||
struct tm *tm;
|
||||
time_t now;
|
||||
struct utsname utsname;
|
||||
char *host = "localhost";
|
||||
|
||||
time(&now);
|
||||
tm = localtime(&now);
|
||||
|
||||
if (uname(&utsname) >= 0) host = utsname.nodename;
|
||||
|
||||
pwd = getpwuid(getuid());
|
||||
if (pwd == (struct passwd *)0)
|
||||
strcpy (who,"root");
|
||||
else
|
||||
strcpy (who,pwd->pw_name);
|
||||
fd = open(wtmpfile,O_APPEND|O_WRONLY|O_CREAT,1);
|
||||
if (fd) {
|
||||
if (strcmp(prog,"reboot"))
|
||||
strcpy (wtmp.ut_name, prog);
|
||||
else
|
||||
strcpy (wtmp.ut_name, "shutdown"); /* last ... */
|
||||
strcpy (wtmp.ut_id, "~~");
|
||||
strcpy (wtmp.ut_line, "~");
|
||||
wtmp.ut_pid = 0;
|
||||
wtmp.ut_type = BOOT_TIME;
|
||||
wtmp.ut_time = now;
|
||||
wtmp.ut_host[0]= '\0';
|
||||
write (fd, (char *) &wtmp,sizeof(struct utmp));
|
||||
close(fd);
|
||||
}
|
||||
fd = open(SHUT_LOG,O_APPEND|O_WRONLY,1);
|
||||
if (!fd)
|
||||
perror ("open");
|
||||
else {
|
||||
sprintf (mes,"%s %02d %02d:%02d:%02d %s: system %s by %s@%s\n",
|
||||
month[tm->tm_mon],tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,
|
||||
prog,prog,who,host);
|
||||
write (fd,mes,strlen(mes));
|
||||
close(fd);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
/* wall - write to all logged in users Author: V. Archer */
|
||||
/*
|
||||
Edvard Tuinder v892231@si.hhs.NL
|
||||
Modified some things to include this with my shutdown/halt
|
||||
package
|
||||
*/
|
||||
|
||||
#define _POSIX_SOURCE 1
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utmp.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/stat.h>
|
||||
#undef UTMP
|
||||
|
||||
static char UTMP[] = "/etc/utmp"; /* Currently logged in users. */
|
||||
|
||||
void wall( char *when, char *extra );
|
||||
void crnlcat( char *message, char *more );
|
||||
|
||||
void
|
||||
wall(when, extra)
|
||||
char *when; /* When is shutdown */
|
||||
char *extra; /* If non-nil, why is the shutdown */
|
||||
{
|
||||
struct utmp utmp;
|
||||
char utmptty[5 + sizeof(utmp.ut_line) + 2];
|
||||
char message[1024];
|
||||
struct passwd *pw;
|
||||
int utmpfd, ttyfd;
|
||||
char *ourtty, *ourname;
|
||||
time_t now;
|
||||
struct utsname utsname;
|
||||
struct stat con_st, tty_st;
|
||||
|
||||
if ((ourtty = ttyname(1))) {
|
||||
if ((ourname = strrchr(ourtty, '/'))) ourtty = ourname+1;
|
||||
} else ourtty = "system task";
|
||||
if ((pw = getpwuid(getuid()))) ourname = pw->pw_name;
|
||||
else ourname = "unknown";
|
||||
|
||||
time(&now);
|
||||
if (uname(&utsname) != 0) strcpy(utsname.nodename, "?");
|
||||
sprintf(message, "\r\nBroadcast message from %s@%s (%s)\r\n%.24s...\r\n",
|
||||
ourname, utsname.nodename, ourtty, ctime(&now));
|
||||
|
||||
crnlcat(message, when);
|
||||
crnlcat(message, extra);
|
||||
|
||||
/* Search the UTMP database for all logged-in users. */
|
||||
|
||||
if ((utmpfd = open(UTMP, O_RDONLY)) < 0) {
|
||||
fprintf(stderr, "Cannot open utmp file\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* first the console */
|
||||
strcpy(utmptty, "/dev/console");
|
||||
if ((ttyfd = open(utmptty, O_WRONLY | O_NONBLOCK)) < 0) {
|
||||
perror(utmptty);
|
||||
} else {
|
||||
fstat(ttyfd, &con_st);
|
||||
write(ttyfd, message, strlen(message));
|
||||
close(ttyfd);
|
||||
}
|
||||
|
||||
while (read(utmpfd, (char *) &utmp, sizeof(utmp)) == sizeof(utmp)) {
|
||||
/* is this the user we are looking for? */
|
||||
if (utmp.ut_type != USER_PROCESS) continue;
|
||||
|
||||
strncpy(utmptty+5, utmp.ut_line, sizeof(utmp.ut_line));
|
||||
utmptty[5 + sizeof(utmp.ut_line) + 1] = 0;
|
||||
if ((ttyfd = open(utmptty, O_WRONLY | O_NONBLOCK)) < 0) {
|
||||
perror(utmptty);
|
||||
continue;
|
||||
}
|
||||
fstat(ttyfd, &tty_st);
|
||||
if (tty_st.st_rdev != con_st.st_rdev)
|
||||
write(ttyfd, message, strlen(message));
|
||||
close(ttyfd);
|
||||
}
|
||||
close(utmpfd);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
crnlcat(message, more)
|
||||
char *message, *more;
|
||||
{
|
||||
char *p = message;
|
||||
char *m = more;
|
||||
char *end = message + 1024 - 1;
|
||||
|
||||
while (p < end && *p != 0) p++;
|
||||
|
||||
while (p < end && *m != 0) {
|
||||
if (*m == '\n' && (p == message || p[-1] != '\n')) {
|
||||
*p++ = '\r';
|
||||
if (p == end) p--;
|
||||
}
|
||||
*p++ = *m++;
|
||||
}
|
||||
*p = 0;
|
||||
}
|
||||
|
|
@ -1,393 +0,0 @@
|
|||
/*
|
||||
shutdown - close down the system graciously
|
||||
|
||||
Author: Edvard Tuinder <v892231@si.hhs.NL>
|
||||
|
||||
This program informs the users that the system is going
|
||||
down, when and why. After that a shutdown notice is written in
|
||||
both /usr/adm/wtmp and by syslog(3). Then reboot(2) is called
|
||||
to really close the system.
|
||||
|
||||
This actually is a ``nice'' halt(8).
|
||||
|
||||
Options are supposed to be as with BSD
|
||||
-h: shutdown and halt the system
|
||||
-r: shutdown and reboot
|
||||
-k: stop an already running shutdown
|
||||
-o: obsolete: not implemented
|
||||
|
||||
New Minix options:
|
||||
-C: crash check, i.e. is the last wtmp entry a shutdown entry?
|
||||
-R: reset the system
|
||||
-d: default CTRL-ALT-DEL shutdown for current bootloader
|
||||
*/
|
||||
|
||||
#define _POSIX_SOURCE 1
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
#include <errno.h>
|
||||
#include <minix/reboot.h>
|
||||
|
||||
#include "wtmp.h"
|
||||
|
||||
static char SHUT_PID[] = "/usr/run/shutdown.pid";
|
||||
static char NOLOGIN[] = "/etc/nologin";
|
||||
|
||||
#ifndef __STDC__
|
||||
#define inform_user_time inf_time
|
||||
#define inform_user inf_user
|
||||
#endif
|
||||
|
||||
void usage( void );
|
||||
void write_pid( void );
|
||||
int inform_user_time( void );
|
||||
void inform_user( void );
|
||||
void terminate( void );
|
||||
void wall( char *when, char *extra );
|
||||
int crash_check( void );
|
||||
void parse_time( char *arg );
|
||||
void get_message( void );
|
||||
int main( int argc, char *argv[] );
|
||||
char *itoa( int n );
|
||||
|
||||
long wait_time=0L;
|
||||
char message[1024];
|
||||
char info[80];
|
||||
int reboot_flag='h'; /* default is halt */
|
||||
int info_min, info_hour;
|
||||
char *prog;
|
||||
|
||||
void parse_time (arg)
|
||||
char *arg;
|
||||
{
|
||||
char *p = arg;
|
||||
int hours, minutes;
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
int delta = 0;
|
||||
int bad = 0;
|
||||
|
||||
if (p[0] == '+') { delta = 1; p++; }
|
||||
|
||||
hours = strtoul(p, &p, 10);
|
||||
if (*p == 0 && delta) {
|
||||
minutes = hours;
|
||||
hours = 0;
|
||||
} else {
|
||||
if (*p != ':' && *p != '.')
|
||||
bad = 1;
|
||||
else
|
||||
p++;
|
||||
minutes = strtoul(p, &p, 10);
|
||||
if (*p != 0) bad = 1;
|
||||
}
|
||||
if (bad) {
|
||||
fprintf(stderr,"Invalid time specification `%s'\n",arg);
|
||||
usage();
|
||||
}
|
||||
|
||||
time(&now);
|
||||
tm = localtime(&now);
|
||||
|
||||
if (!delta) {
|
||||
hours -= tm->tm_hour;
|
||||
minutes -= tm->tm_min;
|
||||
}
|
||||
|
||||
if (minutes < 0) {
|
||||
minutes += 60;
|
||||
hours--;
|
||||
}
|
||||
if (hours < 0) hours += 24; /* Time after midnight. */
|
||||
|
||||
tm->tm_hour += hours;
|
||||
tm->tm_min += minutes;
|
||||
(void) mktime(tm);
|
||||
info_hour = tm->tm_hour;
|
||||
info_min = tm->tm_min;
|
||||
|
||||
sprintf(info,
|
||||
"The system will shutdown in %d hour%s and %d minute%s at %02d:%02d\n\n",
|
||||
hours,hours==1?"":"s",minutes,minutes==1?"":"s",info_hour,info_min);
|
||||
|
||||
wait_time += hours * 3600 + minutes * 60;
|
||||
return;
|
||||
}
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, now = 0, nologin = 0, want_terminate = 0, want_message = 0, check = 0;
|
||||
char *opt;
|
||||
int tty;
|
||||
static char HALT1[] = "-?";
|
||||
static char *HALT[] = { "shutdown", HALT1, NULL };
|
||||
|
||||
/* Parse options. */
|
||||
for (i = 1; i < argc && argv[i][0] == '-'; i++) {
|
||||
if (argv[i][1] == '-' && argv[i][2] == 0) {
|
||||
/* -- */
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
for (opt = argv[i] + 1; *opt != 0; opt++) {
|
||||
switch (*opt) {
|
||||
case 'k':
|
||||
want_terminate = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case 'r':
|
||||
case 'p':
|
||||
case 'd':
|
||||
case 'R':
|
||||
reboot_flag = *opt;
|
||||
break;
|
||||
case 'm':
|
||||
want_message = 1;
|
||||
break;
|
||||
case 'C':
|
||||
check = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr,"shutdown: invalid option '-%c'\n",*opt);
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((argc - i) > 2) usage();
|
||||
|
||||
if (check) exit(crash_check() ? 0 : 2);
|
||||
|
||||
if (i == argc) {
|
||||
/* No timespec, assume "now". */
|
||||
now = 1;
|
||||
} else {
|
||||
if (!strcmp(argv[i], "now"))
|
||||
now++;
|
||||
else
|
||||
parse_time(argv[i]);
|
||||
}
|
||||
|
||||
if ((argc - i) == 2) {
|
||||
/* One line message */
|
||||
strcat(message, argv[i+1]);
|
||||
strcat(message, "\n");
|
||||
}
|
||||
|
||||
if (want_terminate) terminate();
|
||||
if (want_message) get_message();
|
||||
|
||||
puts(info);
|
||||
|
||||
prog = strrchr(*argv,'/');
|
||||
if (prog == (char *)0)
|
||||
prog = *argv;
|
||||
else
|
||||
prog++;
|
||||
|
||||
if (!now) {
|
||||
/* Daemonize. */
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
break;
|
||||
case -1:
|
||||
fprintf(stderr, "%s: can't fork\n", prog);
|
||||
exit(1);
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
/* Detach from the terminal (if any). */
|
||||
if ((tty = open("/dev/tty", O_RDONLY)) != -1) {
|
||||
close(tty);
|
||||
setsid();
|
||||
}
|
||||
write_pid();
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (wait_time <= 5 * 60 && !nologin && !now) {
|
||||
close(creat(NOLOGIN,00644));
|
||||
nologin = 1;
|
||||
}
|
||||
if (wait_time <= 60) break;
|
||||
if(inform_user_time())
|
||||
inform_user();
|
||||
sleep (60);
|
||||
wait_time -= 60;
|
||||
}
|
||||
|
||||
if (!now) {
|
||||
inform_user();
|
||||
sleep (30); /* Last minute before shutdown */
|
||||
wait_time -= 30;
|
||||
inform_user();
|
||||
sleep (30); /* Last 30 seconds before shutdown */
|
||||
}
|
||||
wait_time = 0;
|
||||
inform_user();
|
||||
|
||||
unlink(SHUT_PID); /* No way of stopping anymore */
|
||||
unlink(NOLOGIN);
|
||||
|
||||
HALT[1][1] = reboot_flag;
|
||||
#if __minix_vmd
|
||||
execv("/usr/sbin/halt", HALT);
|
||||
#else
|
||||
execv("/usr/bin/halt", HALT);
|
||||
#endif
|
||||
if (errno != ENOENT)
|
||||
fprintf(stderr, "Can't execute 'halt': %s\n", strerror(errno));
|
||||
|
||||
sleep(2);
|
||||
reboot(RBT_HALT);
|
||||
fprintf(stderr, "Reboot call failed: %s\n", strerror(errno));
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
void usage()
|
||||
{
|
||||
fputs("Usage: shutdown [-hrRpmkd] [time [message]]\n", stderr);
|
||||
fputs(" -h -> halt system after shutdown\n", stderr);
|
||||
fputs(" -r -> reboot system after shutdown\n", stderr);
|
||||
fputs(" -R -> reset system after shutdown\n", stderr);
|
||||
fputs(" -p -> power system off after shutdown\n", stderr);
|
||||
fputs(" -d -> default CTRL-ALT-DEL shutdown for current bootloader\n", stderr);
|
||||
fputs(" -m -> read a shutdown message from standard input\n", stderr);
|
||||
fputs(" -k -> stop an already running shutdown\n", stderr);
|
||||
fputs(" time -> keyword ``now'', minutes before shutdown ``+5'',\n", stderr);
|
||||
fputs(" or absolute time specification ``11:20''\n", stderr);
|
||||
fputs(" message -> short shutdown message\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void terminate()
|
||||
{
|
||||
FILE *in;
|
||||
pid_t pid;
|
||||
char c_pid[5];
|
||||
|
||||
in = fopen(SHUT_PID,"r");
|
||||
if (in == (FILE *)0) {
|
||||
fputs ("Can't get pid of shutdown process, probably not running shutdown\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
fgets(c_pid,5,in);
|
||||
fclose(in);
|
||||
pid = atoi(c_pid);
|
||||
if (kill(pid,9) == -1)
|
||||
fputs("Can't kill the shutdown process, probably not running anymore\n",stderr);
|
||||
else
|
||||
puts("Shutdown process terminated");
|
||||
unlink(SHUT_PID);
|
||||
unlink(NOLOGIN);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void get_message()
|
||||
{
|
||||
char line[80];
|
||||
|
||||
puts ("Type your message. End with ^D at an empty line");
|
||||
fputs ("shutdown> ",stdout);fflush(stdout);
|
||||
while (fgets(line,80,stdin) != (char *)0) {
|
||||
strcat (message,line);
|
||||
bzero(line,strlen(line));
|
||||
fputs ("shutdown> ",stdout);fflush(stdout);
|
||||
}
|
||||
putc('\n',stdout);fflush(stdout);
|
||||
}
|
||||
|
||||
int inform_user_time()
|
||||
{
|
||||
int min;
|
||||
|
||||
min = wait_time /60;
|
||||
|
||||
if (min == 60 || min == 30 || min == 15 || min == 10 || min <= 5)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void inform_user()
|
||||
{
|
||||
int hour, minute;
|
||||
char mes[80];
|
||||
|
||||
hour = 0;
|
||||
minute = wait_time / 60;
|
||||
while (minute >= 60) {
|
||||
minute -= 60;
|
||||
hour++;
|
||||
}
|
||||
|
||||
if (hour)
|
||||
sprintf(mes,
|
||||
"\nThe system will shutdown in %d hour%s and %d minute%s at %.02d:%.02d\n\n",
|
||||
hour,hour==1?"":"s",minute,minute==1?"":"s",info_hour,info_min);
|
||||
else
|
||||
if (minute > 1)
|
||||
sprintf(mes,
|
||||
"\nThe system will shutdown in %d minutes at %.02d:%.02d\n\n",
|
||||
minute,info_hour,info_min);
|
||||
else
|
||||
if (wait_time > 1)
|
||||
sprintf(mes,
|
||||
"\nThe system will shutdown in %ld seconds\n\n",
|
||||
wait_time);
|
||||
else
|
||||
sprintf(mes,
|
||||
"\nThe system will shutdown NOW\n\n");
|
||||
|
||||
wall(mes,message);
|
||||
}
|
||||
|
||||
void write_pid()
|
||||
{
|
||||
char pid[5];
|
||||
int fd;
|
||||
|
||||
fd = creat(SHUT_PID,00600);
|
||||
if (!fd)
|
||||
return;
|
||||
strncpy (pid,itoa(getpid()), sizeof(pid));
|
||||
write (fd,pid,sizeof(pid));
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
int crash_check()
|
||||
{
|
||||
struct utmp last;
|
||||
int fd = -1, crashed;
|
||||
struct stat st;
|
||||
|
||||
if (stat(STR_ROOT_WTMP, &st) < 0 || st.st_size == 0) {
|
||||
if (stat(STR_WTMP, &st) < 0 || st.st_size == 0) {
|
||||
return 0;
|
||||
}
|
||||
if ((fd = open(STR_WTMP, O_RDONLY)) < 0) return 0;
|
||||
} else if ((fd = open(STR_ROOT_WTMP, O_RDONLY)) < 0) return 0;
|
||||
|
||||
crashed = (lseek(fd, - (off_t) sizeof(last), SEEK_END) == -1
|
||||
|| read(fd, (void *) &last, sizeof(last)) != sizeof(last)
|
||||
|| last.ut_line[0] != '~'
|
||||
|| (strncmp(last.ut_name, "shutdown", sizeof(last.ut_name))
|
||||
&& strncmp(last.ut_name, "halt", sizeof(last.ut_name)))
|
||||
);
|
||||
close(fd);
|
||||
return crashed;
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
static char STR_WTMP[] = "/usr/adm/wtmp";
|
||||
static char STR_ROOT_WTMP[] = "/etc/wtmp";
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
#include <configfile.h>
|
||||
|
||||
#include <machine/archtypes.h>
|
||||
#include <timers.h>
|
||||
#include <minix/timers.h>
|
||||
#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++;
|
||||
}
|
||||
}
|
||||
|
|
@ -712,7 +727,6 @@ struct
|
|||
{
|
||||
{ "EXIT", VM_EXIT },
|
||||
{ "FORK", VM_FORK },
|
||||
{ "BRK", VM_BRK },
|
||||
{ "EXEC_NEWMEM", VM_EXEC_NEWMEM },
|
||||
{ "PUSH_SIG", 0 },
|
||||
{ "WILLEXIT", VM_WILLEXIT },
|
||||
|
|
@ -734,6 +748,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 },
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <configfile.h>
|
||||
|
||||
#include <machine/archtypes.h>
|
||||
#include <timers.h>
|
||||
#include <minix/timers.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "config.h"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ service \- Manage an operating system service.
|
|||
.PP
|
||||
\fBservice [-b -c -n -p -r] (up|run|edit|update)\fR \fI<binary|self>\fR
|
||||
[\fB-args\fR \fI<args>\fR] [\fB-dev\fR \fI<special>\fR]
|
||||
[\fB-devstyle\fR \fI<style>\fR] [\fB-period\fR \fI<ticks>\fR]
|
||||
[\fB-period\fR \fI<ticks>\fR]
|
||||
[\fB-script\fR \fI<path>\fR] [\fB-label\fR \fI<name>\fR]
|
||||
[\fB-config\fR \fI<path>\fR] [\fB-state\fR \fI<state>\fR]
|
||||
[\fB-maxtime\fR \fI<time>\fR]
|
||||
|
|
@ -103,12 +103,6 @@ given by \fI<binary>\fR. The default is to use no arguments.
|
|||
specifies the device file to associate to the system service (used only for
|
||||
device drivers). The default is to associate no device file to the service.
|
||||
.TP
|
||||
.BI \-devstyle " <style>"
|
||||
specifies the device style to associate to the system service (used only for
|
||||
device drivers). The list of supported device styles is available in
|
||||
the header file \fB<minix/dmap.h>\fR.
|
||||
The default is to associate no device style (\fBSTYLE_NDEV\fR) to the service.
|
||||
.TP
|
||||
.BI \-period " <ticks>"
|
||||
specifies the period to use for the system service.
|
||||
When a period is specified, \fBRS\fR sends a ping request to
|
||||
|
|
@ -160,7 +154,7 @@ label \fI<name>\fR. This action can be used to dynamically update the
|
|||
properties of any system service, including those contained in the
|
||||
boot image (e.g. \fBVM\fR). There are a few exceptions to the properties
|
||||
that can be actually overridden dynamically. For example, the device file
|
||||
and the device style associated to the service will no be updated. This
|
||||
associated to the service will no be updated. This
|
||||
action takes the same options supported by the \fBup\fR action.
|
||||
.PP
|
||||
.SS
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#include <configfile.h>
|
||||
|
||||
#include <machine/archtypes.h>
|
||||
#include <timers.h>
|
||||
#include <minix/timers.h>
|
||||
#include <err.h>
|
||||
#include "kernel/proc.h"
|
||||
|
||||
|
|
@ -86,7 +86,6 @@ static char *known_requests[] = {
|
|||
#define ARG_ARGS "-args" /* list of arguments to be passed */
|
||||
#define ARG_DEV "-dev" /* major device number for drivers */
|
||||
#define ARG_MAJOR "-major" /* major number */
|
||||
#define ARG_DEVSTYLE "-devstyle" /* device style */
|
||||
#define ARG_PERIOD "-period" /* heartbeat period in ticks */
|
||||
#define ARG_SCRIPT "-script" /* name of the script to restart a
|
||||
* system service
|
||||
|
|
@ -113,7 +112,6 @@ static char *req_path_self = SELF_REQ_PATH;
|
|||
static char *req_args = "";
|
||||
static int req_major = 0;
|
||||
static int devman_id = 0;
|
||||
static int req_dev_style = STYLE_NDEV;
|
||||
static long req_period = 0;
|
||||
static char *req_script = NULL;
|
||||
static char *req_config = PATH_CONFIG;
|
||||
|
|
@ -131,9 +129,9 @@ static void print_usage(char *app_name, char *problem)
|
|||
fprintf(stderr, "Warning, %s\n", problem);
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr,
|
||||
" %s [%s %s %s %s] (up|run|edit|update) <binary|%s> [%s <args>] [%s <special>] [%s <style>] [%s <major_nr>] [%s <dev_id>] [%s <ticks>] [%s <path>] [%s <name>] [%s <path>] [%s <state>] [%s <time>]\n",
|
||||
" %s [%s %s %s %s] (up|run|edit|update) <binary|%s> [%s <args>] [%s <special>] [%s <major_nr>] [%s <dev_id>] [%s <ticks>] [%s <path>] [%s <name>] [%s <path>] [%s <state>] [%s <time>]\n",
|
||||
app_name, OPT_COPY, OPT_REUSE, OPT_NOBLOCK, OPT_REPLICA, SELF_BINARY,
|
||||
ARG_ARGS, ARG_DEV, ARG_DEVSTYLE, ARG_MAJOR, ARG_DEVMANID, ARG_PERIOD, ARG_SCRIPT,
|
||||
ARG_ARGS, ARG_DEV, ARG_MAJOR, ARG_DEVMANID, ARG_PERIOD, ARG_SCRIPT,
|
||||
ARG_LABELNAME, ARG_CONFIG, ARG_LU_STATE, ARG_LU_MAXTIME);
|
||||
fprintf(stderr, " %s down <label>\n", app_name);
|
||||
fprintf(stderr, " %s refresh <label>\n", app_name);
|
||||
|
|
@ -315,9 +313,6 @@ static int parse_arguments(int argc, char **argv, u32_t *rss_flags)
|
|||
exit(EINVAL);
|
||||
}
|
||||
req_major = major(stat_buf.st_rdev);
|
||||
if(req_dev_style == STYLE_NDEV) {
|
||||
req_dev_style = STYLE_DEV;
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], ARG_MAJOR)==0) {
|
||||
if (req_major != 0) {
|
||||
|
|
@ -329,26 +324,7 @@ static int parse_arguments(int argc, char **argv, u32_t *rss_flags)
|
|||
} else {
|
||||
exit(EINVAL);
|
||||
}
|
||||
if(req_dev_style == STYLE_NDEV) {
|
||||
req_dev_style = STYLE_DEV;
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], ARG_DEVSTYLE)==0) {
|
||||
char* dev_style_keys[] = { "STYLE_DEV", "STYLE_DEVA", "STYLE_TTY",
|
||||
"STYLE_CTTY", "STYLE_CLONE", "STYLE_CLONE_A", NULL };
|
||||
int dev_style_values[] = { STYLE_DEV, STYLE_DEVA, STYLE_TTY,
|
||||
STYLE_CTTY, STYLE_CLONE, STYLE_CLONE_A };
|
||||
for(j=0;dev_style_keys[j]!=NULL;j++) {
|
||||
if(!strcmp(dev_style_keys[j], argv[i+1])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(dev_style_keys[j] == NULL) {
|
||||
print_usage(argv[ARG_NAME], "bad device style");
|
||||
exit(EINVAL);
|
||||
}
|
||||
req_dev_style = dev_style_values[j];
|
||||
}
|
||||
else if (strcmp(argv[i], ARG_SCRIPT)==0) {
|
||||
req_script = argv[i+1];
|
||||
}
|
||||
|
|
@ -440,6 +416,7 @@ int main(int argc, char **argv)
|
|||
* should end up here. The default is used for not yet supported requests.
|
||||
*/
|
||||
result = OK;
|
||||
memset(&m, 0, sizeof(m));
|
||||
switch(request) {
|
||||
case RS_UPDATE:
|
||||
m.RS_LU_STATE = req_lu_state;
|
||||
|
|
@ -466,7 +443,6 @@ int main(int argc, char **argv)
|
|||
config.rs_start.rss_cmd= command;
|
||||
config.rs_start.rss_cmdlen= strlen(command);
|
||||
config.rs_start.rss_major= req_major;
|
||||
config.rs_start.rss_dev_style= req_dev_style;
|
||||
config.rs_start.rss_period= req_period;
|
||||
config.rs_start.rss_script= req_script;
|
||||
config.rs_start.devman_id= devman_id;
|
||||
|
|
|
|||
|
|
@ -412,9 +412,9 @@ then
|
|||
|
||||
# Get sizes and space availability while the file systems are still
|
||||
# mounted. Otherwise we have to mount them again just for this.
|
||||
required_root_space=`df -k /dev/$root | awk '{print $4}' | tail -n 1`
|
||||
free_root_space=`df -k /dev/$root | awk '{print $3}' | tail -n 1`
|
||||
free_usr_space=`df -k /dev/$usr | awk '{print $3}' | tail -n 1`
|
||||
required_root_space=`df -kP /dev/$root | awk '{print $3}' | tail -n 1`
|
||||
free_root_space=`df -kP /dev/$root | awk '{print $4}' | tail -n 1`
|
||||
free_usr_space=`df -kP /dev/$usr | awk '{print $4}' | tail -n 1`
|
||||
|
||||
umount /mnt/usr && umount /mnt || exit
|
||||
|
||||
|
|
|
|||
22
commands/shared/README
Normal file
22
commands/shared/README
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
builtin.sh is installed as a set of tools to stand in for specific
|
||||
filesystem call to builtin commands.
|
||||
|
||||
for example if /bin/test is used, then builtin.sh will be loaded
|
||||
and simply call the builtin function of the same name.
|
||||
|
||||
At this moment it is installed as the following commands:
|
||||
/bin/[
|
||||
/bin/command
|
||||
/bin/echo
|
||||
/bin/expr
|
||||
/bin/false
|
||||
/bin/getopts
|
||||
/bin/read
|
||||
/bin/test
|
||||
/bin/true
|
||||
/bin/umask
|
||||
/bin/wait
|
||||
|
||||
If one of the following is replaced by the NetBSD equivalent, please
|
||||
update the list, and remove this completly when it is not anymore
|
||||
required.
|
||||
11
commands/shared/builtin.sh
Normal file
11
commands/shared/builtin.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# cd 1.3 - equivalents for normally builtin commands. Author: Kees J. Bot
|
||||
|
||||
case $0 in
|
||||
*/*) command="`expr "$0" : '.*/\(.*\)'`"
|
||||
;;
|
||||
*) command="$0"
|
||||
esac
|
||||
|
||||
"$command" "$@"
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
PROG= stty
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1270
commands/stty/stty.c
1270
commands/stty/stty.c
File diff suppressed because it is too large
Load Diff
|
|
@ -18,10 +18,9 @@ static char *bin_name;
|
|||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int r, param;
|
||||
int param;
|
||||
endpoint_t proc_e = NONE;
|
||||
struct sysgetenv sysgetenv;
|
||||
message m;
|
||||
char *to_whom, *operation, *what, *value;
|
||||
unsigned i;
|
||||
|
||||
|
|
@ -60,10 +59,7 @@ int main (int argc, char *argv[])
|
|||
else
|
||||
usage();
|
||||
|
||||
m.m2_i1 = param;
|
||||
m.m2_p1 = (char *) &sysgetenv;
|
||||
r = _syscall(proc_e, SVRCTL, &m);
|
||||
if (r != 0) {
|
||||
if (svrctl(param, &sysgetenv) != 0) {
|
||||
if (errno == ESRCH)
|
||||
fprintf(stderr, "invalid parameter: %s\n", what);
|
||||
else if (errno == EINVAL)
|
||||
|
|
@ -87,10 +83,7 @@ int main (int argc, char *argv[])
|
|||
else
|
||||
usage();
|
||||
|
||||
m.m2_i1 = param;
|
||||
m.m2_p1 = (char *) &sysgetenv;
|
||||
r = _syscall(proc_e, SVRCTL, &m);
|
||||
if (r != 0) {
|
||||
if (svrctl(param, &sysgetenv) != 0) {
|
||||
if (errno == ESRCH)
|
||||
fprintf(stderr, "invalid parameter: %s\n", what);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
|
||||
PROG= in.telnetd
|
||||
SRCS= main.c telnet.c term.c pty.c wtmp.c
|
||||
SRCS= main.c telnet.c term.c pty.c
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ int opt_d = 0; /* debugging output flag */
|
|||
|
||||
void usage(void);
|
||||
int main(int argc, char *argv[]);
|
||||
void wtmp(int type, int linenr, char *line, pid_t pid, char *host);
|
||||
|
||||
void usage()
|
||||
{
|
||||
|
|
@ -144,14 +143,10 @@ char *hostname;
|
|||
return(-1);
|
||||
}
|
||||
|
||||
wtmp(LOGIN_PROCESS, lineno, tty_name+5, pid, hostname);
|
||||
|
||||
term_inout(pty_fd);
|
||||
|
||||
(void) close(pty_fd);
|
||||
|
||||
wtmp(DEAD_PROCESS, lineno, tty_name+5, pid, hostname);
|
||||
|
||||
chown(tty_name, 0, 0);
|
||||
chmod(tty_name, 0666);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* TNET A server program for MINIX which implements the TCP/IP
|
||||
* suite of networking protocols. It is based on the
|
||||
* TCP/IP code written by Phil Karn et al, as found in
|
||||
* his NET package for Packet Radio communications.
|
||||
*
|
||||
* This file contains an implementation of the "server"
|
||||
* for the TELNET protocol. This protocol can be used to
|
||||
* remote-login on other systems, just like a normal TTY
|
||||
* session.
|
||||
*
|
||||
* Usage: telnetd [-dv]
|
||||
*
|
||||
* Version: @(#)telnetd.c 1.00 07/26/92
|
||||
*
|
||||
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
|
||||
* Michael Temari, <temari@temari.ae.ge.com>
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <utmp.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include "telnetd.h"
|
||||
|
||||
static char PATH_UTMP[] = "/etc/utmp";
|
||||
static char PATH_WTMP[] = "/usr/adm/wtmp";
|
||||
|
||||
void wtmp(int type, int linenr, char *line, pid_t pid, char *host);
|
||||
void report(char *label);
|
||||
|
||||
void wtmp(type, linenr, line, pid, host)
|
||||
int type; /* type of entry */
|
||||
int linenr; /* line number in ttytab */
|
||||
char *line; /* tty name (only good on login) */
|
||||
pid_t pid; /* pid of process */
|
||||
char *host; /* name of the remote host */
|
||||
{
|
||||
/* Log an event into the UTMP and WTMP files. */
|
||||
|
||||
struct utmp utmp; /* UTMP/WTMP User Accounting */
|
||||
int fd;
|
||||
|
||||
/* Clear the utmp record. */
|
||||
memset((void *) &utmp, 0, sizeof(utmp));
|
||||
|
||||
/* Fill in utmp. */
|
||||
switch (type) {
|
||||
case LOGIN_PROCESS:
|
||||
/* A new login, fill in line and host name. */
|
||||
strncpy(utmp.ut_line, line, sizeof(utmp.ut_line));
|
||||
strncpy(utmp.ut_host, host, sizeof(utmp.ut_host));
|
||||
break;
|
||||
|
||||
case DEAD_PROCESS:
|
||||
/* A logout. Use the current utmp entry, but make sure it is a
|
||||
* user process exiting, and not getty or login giving up.
|
||||
*/
|
||||
if ((fd = open(PATH_UTMP, O_RDONLY)) < 0) {
|
||||
if (errno != ENOENT) report(PATH_UTMP);
|
||||
return;
|
||||
}
|
||||
if (lseek(fd, (off_t) (linenr+1) * sizeof(utmp), SEEK_SET) == -1
|
||||
|| read(fd, &utmp, sizeof(utmp)) == -1
|
||||
) {
|
||||
report(PATH_UTMP);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
if (utmp.ut_type != USER_PROCESS) return;
|
||||
strncpy(utmp.ut_name, "", sizeof(utmp.ut_name));
|
||||
break;
|
||||
}
|
||||
|
||||
/* Finish new utmp entry. */
|
||||
utmp.ut_pid = pid;
|
||||
utmp.ut_type = type;
|
||||
utmp.ut_time = time((time_t *) 0);
|
||||
|
||||
/* Write new entry to utmp. */
|
||||
if ((fd = open(PATH_UTMP, O_WRONLY)) < 0
|
||||
|| lseek(fd, (off_t) (linenr+1) * sizeof(utmp), SEEK_SET) == -1
|
||||
|| write(fd, &utmp, sizeof(utmp)) == -1
|
||||
) {
|
||||
if (errno != ENOENT) report(PATH_UTMP);
|
||||
}
|
||||
if (fd != -1) close(fd);
|
||||
|
||||
if (type == DEAD_PROCESS) {
|
||||
/* Add new wtmp entry. */
|
||||
if ((fd = open(PATH_WTMP, O_WRONLY | O_APPEND)) < 0
|
||||
|| write(fd, &utmp, sizeof(utmp)) == -1
|
||||
) {
|
||||
if (errno != ENOENT) report(PATH_WTMP);
|
||||
}
|
||||
if (fd != -1) close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void report(label)
|
||||
char *label;
|
||||
{
|
||||
char message[128];
|
||||
|
||||
sprintf(message, "telnetd: %i: %s\r\n", errno, strerror(errno));
|
||||
(void) write(1, message, strlen(message));
|
||||
}
|
||||
5
commands/test/Makefile
Normal file
5
commands/test/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= test.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/test/test.sh
Symbolic link
1
commands/test/test.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
5
commands/true/Makefile
Normal file
5
commands/true/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= true.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/true/true.sh
Symbolic link
1
commands/true/true.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
5
commands/umask/Makefile
Normal file
5
commands/umask/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= umask.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/umask/umask.sh
Symbolic link
1
commands/umask/umask.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
|
|
@ -47,7 +47,7 @@ char *argv[];
|
|||
|
||||
found = find_mtab_entry(name);
|
||||
|
||||
if (umount2(name, umount_flags) < 0) {
|
||||
if (umount(name, umount_flags) < 0) {
|
||||
if (errno == EINVAL)
|
||||
std_err("umount: Device not mounted\n");
|
||||
else if (errno == ENOTBLK)
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
PROG= uname
|
||||
MAN=
|
||||
|
||||
LINKS+= ${BINDIR}/uname ${BINDIR}/arch
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/* uname - print system name Author: Earl Chew */
|
||||
|
||||
/* Print the following system information as returned by the uname()
|
||||
* function:
|
||||
*
|
||||
* system name Minix
|
||||
* node name waddles
|
||||
* release name 1.5
|
||||
* version 10
|
||||
* machine name i86
|
||||
* arch i86 (Minix specific)
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Define the uname components. */
|
||||
#define ALL ((unsigned) 0x1F)
|
||||
#define SYSNAME ((unsigned) 0x01)
|
||||
#define NODENAME ((unsigned) 0x02)
|
||||
#define RELEASE ((unsigned) 0x04)
|
||||
#define U_MACHINE ((unsigned) 0x10)
|
||||
#define ARCH ((unsigned) 0x20)
|
||||
|
||||
int main(int argc, char **argv );
|
||||
void print(int fd, ... );
|
||||
void usage(void );
|
||||
|
||||
#ifdef __STDC__
|
||||
void print(int fd, ...)
|
||||
#else
|
||||
void print(fd)
|
||||
int fd;
|
||||
#endif
|
||||
{
|
||||
/* Print a sequence of strings onto the named channel. */
|
||||
va_list argp;
|
||||
char *p;
|
||||
|
||||
va_start(argp, fd);
|
||||
while (1) {
|
||||
p = va_arg(argp, char *);
|
||||
if (p == (char *) NULL) break;
|
||||
write(fd, p, strlen(p));
|
||||
}
|
||||
va_end(argp);
|
||||
}
|
||||
|
||||
char *name;
|
||||
|
||||
void usage()
|
||||
{
|
||||
print(STDERR_FILENO, "Usage: ", name, " -snrvmpa\n", (char *) NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int info;
|
||||
char *p;
|
||||
struct utsname un;
|
||||
|
||||
name = strrchr(argv[0], '/');
|
||||
if (name == NULL) name = argv[0]; else name++;
|
||||
|
||||
for (info = 0; argc > 1; argc--, argv++) {
|
||||
if (argv[1][0] == '-') {
|
||||
for (p = &argv[1][1]; *p; p++) {
|
||||
switch (*p) {
|
||||
case 'a': info |= ALL; break;
|
||||
case 'm': info |= U_MACHINE; break;
|
||||
case 'n': info |= NODENAME; break;
|
||||
case 'r': info |= RELEASE; break;
|
||||
case 's': info |= SYSNAME; break;
|
||||
case 'v': info |= RELEASE; break;
|
||||
case 'p': info |= ARCH; break;
|
||||
default: usage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (info == 0) info = strcmp(name, "arch") == 0 ? ARCH : SYSNAME;
|
||||
|
||||
if (uname(&un) != 0) {
|
||||
print(STDERR_FILENO, "unable to determine uname values\n", (char *) NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((info & SYSNAME) != 0)
|
||||
print(STDOUT_FILENO, un.sysname, (char *) NULL);
|
||||
if ((info & NODENAME) != 0) {
|
||||
if ((info & (SYSNAME)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.nodename, (char *) NULL);
|
||||
}
|
||||
if ((info & RELEASE) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.release, (char *) NULL);
|
||||
print(STDOUT_FILENO, ".", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.version, (char *) NULL);
|
||||
}
|
||||
if ((info & U_MACHINE) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME|RELEASE)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.machine, (char *) NULL);
|
||||
}
|
||||
if ((info & ARCH) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME|RELEASE|U_MACHINE)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.arch, (char *) NULL);
|
||||
}
|
||||
print(STDOUT_FILENO, "\n", (char *) NULL);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
5
commands/wait/Makefile
Normal file
5
commands/wait/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
SCRIPTS= wait.sh
|
||||
BINDIR= /bin
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
1
commands/wait/wait.sh
Symbolic link
1
commands/wait/wait.sh
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../shared/builtin.sh
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
./boot/minix/.temp/mod07_log minix-sys
|
||||
./boot/minix/.temp/mod08_tty minix-sys
|
||||
./boot/minix/.temp/mod09_mfs minix-sys
|
||||
./boot/minix/.temp/mod10_vm minix-sys
|
||||
./boot/minix/.temp/mod11_pfs minix-sys
|
||||
./boot/minix/.temp/mod12_init minix-sys
|
||||
./boot/minix/.temp/mod07_tty minix-sys
|
||||
./boot/minix/.temp/mod08_mfs minix-sys
|
||||
./boot/minix/.temp/mod09_vm minix-sys
|
||||
./boot/minix/.temp/mod10_pfs minix-sys
|
||||
./boot/minix/.temp/mod11_init minix-sys
|
||||
./etc/rc.capes minix-sys
|
||||
./etc/rc.capes/BB-BONE-WTHR-01 minix-sys
|
||||
./etc/system.conf.d/lan8710a minix-sys
|
||||
./multiboot/mod07_log minix-sys
|
||||
./multiboot/mod08_tty minix-sys
|
||||
./multiboot/mod09_mfs minix-sys
|
||||
./multiboot/mod10_vm minix-sys
|
||||
./multiboot/mod11_pfs minix-sys
|
||||
./multiboot/mod12_init minix-sys
|
||||
./multiboot/mod07_tty minix-sys
|
||||
./multiboot/mod08_mfs minix-sys
|
||||
./multiboot/mod09_vm minix-sys
|
||||
./multiboot/mod10_pfs minix-sys
|
||||
./multiboot/mod11_init minix-sys
|
||||
./sbin/gpio minix-sys
|
||||
./usr/bin/eepromread minix-sys
|
||||
./usr/include/arm minix-sys
|
||||
|
|
@ -47,6 +45,7 @@
|
|||
./usr/include/arm/mcontext.h minix-sys
|
||||
./usr/include/arm/mutex.h minix-sys
|
||||
./usr/include/arm/param.h minix-sys
|
||||
./usr/include/arm/proc.h minix-sys
|
||||
./usr/include/arm/profile.h minix-sys
|
||||
./usr/include/arm/rwlock.h minix-sys
|
||||
./usr/include/arm/setjmp.h minix-sys
|
||||
|
|
@ -87,6 +86,7 @@
|
|||
./usr/include/evbarm/mutex.h minix-sys
|
||||
./usr/include/evbarm/param.h minix-sys
|
||||
./usr/include/evbarm/partition.h minix-sys
|
||||
./usr/include/evbarm/proc.h minix-sys
|
||||
./usr/include/evbarm/profile.h minix-sys
|
||||
./usr/include/evbarm/rwlock.h minix-sys
|
||||
./usr/include/evbarm/setjmp.h minix-sys
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
|
||||
./boot/minix/.temp/mod07_log minix-sys
|
||||
./boot/minix/.temp/mod08_tty minix-sys
|
||||
./boot/minix/.temp/mod09_mfs minix-sys
|
||||
./boot/minix/.temp/mod10_vm minix-sys
|
||||
./boot/minix/.temp/mod11_pfs minix-sys
|
||||
./boot/minix/.temp/mod12_init minix-sys
|
||||
./boot/minix/.temp/mod07_tty minix-sys
|
||||
./boot/minix/.temp/mod08_mfs minix-sys
|
||||
./boot/minix/.temp/mod09_vm minix-sys
|
||||
./boot/minix/.temp/mod10_pfs minix-sys
|
||||
./boot/minix/.temp/mod11_init minix-sys
|
||||
./etc/system.conf.d/atl2 minix-sys
|
||||
./etc/system.conf.d/dec21140A minix-sys
|
||||
./etc/system.conf.d/e1000 minix-sys
|
||||
|
|
@ -13,16 +12,16 @@
|
|||
./etc/system.conf.d/rtl8139 minix-sys
|
||||
./etc/system.conf.d/rtl8169 minix-sys
|
||||
./etc/system.conf.d/virtio_net minix-sys
|
||||
./multiboot/mod07_log minix-sys
|
||||
./multiboot/mod08_tty minix-sys
|
||||
./multiboot/mod09_mfs minix-sys
|
||||
./multiboot/mod10_vm minix-sys
|
||||
./multiboot/mod11_pfs minix-sys
|
||||
./multiboot/mod12_init minix-sys
|
||||
./multiboot/mod07_tty minix-sys
|
||||
./multiboot/mod08_mfs minix-sys
|
||||
./multiboot/mod09_vm minix-sys
|
||||
./multiboot/mod10_pfs minix-sys
|
||||
./multiboot/mod11_init minix-sys
|
||||
./sbin/ahci minix-sys
|
||||
./sbin/at_wini minix-sys
|
||||
./sbin/floppy minix-sys
|
||||
./sbin/hgfs minix-sys
|
||||
./sbin/pckbd minix-sys
|
||||
./sbin/vbfs minix-sys
|
||||
./sbin/virtio_blk minix-sys
|
||||
./usr/include/gcc-4.5/abmintrin.h minix-sys gcccmds
|
||||
|
|
@ -69,6 +68,7 @@
|
|||
./usr/include/i386/fenv.h minix-sys
|
||||
./usr/include/i386/float.h minix-sys
|
||||
./usr/include/i386/fpu.h minix-sys
|
||||
./usr/include/i386/frame.h minix-sys
|
||||
./usr/include/i386/ieeefp.h minix-sys
|
||||
./usr/include/i386/ieee.h minix-sys
|
||||
./usr/include/i386/int86.h minix-sys
|
||||
|
|
@ -80,6 +80,7 @@
|
|||
./usr/include/i386/int_types.h minix-sys
|
||||
./usr/include/i386/ipcconst.h minix-sys
|
||||
./usr/include/i386/limits.h minix-sys
|
||||
./usr/include/i386/lock.h minix-sys
|
||||
./usr/include/i386/math.h minix-sys
|
||||
./usr/include/i386/mcontext.h minix-sys
|
||||
./usr/include/i386/memory.h minix-sys
|
||||
|
|
@ -88,6 +89,7 @@
|
|||
./usr/include/i386/npx.h minix-sys
|
||||
./usr/include/i386/param.h minix-sys
|
||||
./usr/include/i386/partition.h minix-sys
|
||||
./usr/include/i386/pcb.h minix-sys
|
||||
./usr/include/i386/pci_amd.h minix-sys
|
||||
./usr/include/i386/pci.h minix-sys
|
||||
./usr/include/i386/pci_intel.h minix-sys
|
||||
|
|
@ -95,11 +97,15 @@
|
|||
./usr/include/i386/pci_via.h minix-sys
|
||||
./usr/include/i386/pio.h minix-sys
|
||||
./usr/include/i386/ports.h minix-sys
|
||||
./usr/include/i386/proc.h minix-sys
|
||||
./usr/include/i386/profile.h minix-sys
|
||||
./usr/include/i386/rwlock.h minix-sys
|
||||
./usr/include/i386/segments.h minix-sys
|
||||
./usr/include/i386/setjmp.h minix-sys
|
||||
./usr/include/i386/signal.h minix-sys
|
||||
./usr/include/i386/stackframe.h minix-sys
|
||||
./usr/include/i386/sysarch.h minix-sys
|
||||
./usr/include/i386/tss.h minix-sys
|
||||
./usr/include/i386/types.h minix-sys
|
||||
./usr/include/i386/vm.h minix-sys
|
||||
./usr/include/i386/vmparam.h minix-sys
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -6,25 +6,25 @@
|
|||
.if ${MKIMAGEONLY} == "yes"
|
||||
|
||||
.if ${MACHINE_ARCH} == "i386"
|
||||
SUBDIR= at_wini floppy log tty pci
|
||||
SUBDIR= at_wini floppy tty pci pckbd
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_ARCH} == "earm"
|
||||
SUBDIR= log tty
|
||||
SUBDIR= tty
|
||||
.endif
|
||||
|
||||
.else # ${MKIMAGEONLY} != "yes"
|
||||
|
||||
.if ${MACHINE_ARCH} == "i386"
|
||||
SUBDIR= ahci amddev atl2 at_wini audio dec21140A dp8390 dpeth \
|
||||
e1000 fbd filter floppy fxp hello lance log mmc orinoco pci printer \
|
||||
random readclock rtl8139 rtl8169 ti1225 tty vbox acpi \
|
||||
virtio_blk virtio_net
|
||||
e1000 fbd filter floppy fxp hello lance log mmc orinoco pci pckbd \
|
||||
printer random readclock rtl8139 rtl8169 ti1225 tty uds vbox acpi \
|
||||
virtio_blk virtio_net vnd
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_ARCH} == "earm"
|
||||
SUBDIR= bmp085 cat24c256 fb gpio i2c mmc lan8710a log readclock \
|
||||
sht21 tda19988 tps65217 tps65950 tsl2550 tty random
|
||||
sht21 tda19988 tps65217 tps65950 tsl2550 tty random uds vnd
|
||||
.endif
|
||||
|
||||
.endif # ${MKIMAGEONLY} != "yes"
|
||||
|
|
|
|||
|
|
@ -149,9 +149,9 @@ int main(void)
|
|||
((struct acpi_request_hdr *)&m)->m_source);
|
||||
}
|
||||
|
||||
err = send(m.m_source, &m);
|
||||
err = ipc_send(m.m_source, &m);
|
||||
if (err != OK) {
|
||||
printf("ACPI: send failed: %d\n", err);
|
||||
printf("ACPI: ipc_send failed: %d\n", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ static struct port_state {
|
|||
struct device part[DEV_PER_DRIVE]; /* partition bases and sizes */
|
||||
struct device subpart[SUB_PER_DRIVE]; /* same for subpartitions */
|
||||
|
||||
timer_t timer; /* port-specific timeout timer */
|
||||
minix_timer_t timer; /* port-specific timeout timer */
|
||||
int left; /* number of tries left before giving up */
|
||||
/* (only used for signature probing) */
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ static struct port_state {
|
|||
u32_t pend_mask; /* commands not yet complete */
|
||||
struct {
|
||||
thread_id_t tid;/* ID of the worker thread */
|
||||
timer_t timer; /* timer associated with each request */
|
||||
minix_timer_t timer; /* timer associated with each request */
|
||||
int result; /* success/failure result of the commands */
|
||||
} cmd_info[NR_CMDS];
|
||||
} port_state[NR_PORTS];
|
||||
|
|
@ -232,36 +232,33 @@ static void port_set_cmd(struct port_state *ps, int cmd, cmd_fis_t *fis,
|
|||
u8_t packet[ATAPI_PACKET_SIZE], prd_t *prdt, int nr_prds, int write);
|
||||
static void port_issue(struct port_state *ps, int cmd, clock_t timeout);
|
||||
static int port_exec(struct port_state *ps, int cmd, clock_t timeout);
|
||||
static void port_timeout(struct timer *tp);
|
||||
static void port_timeout(minix_timer_t *tp);
|
||||
static void port_disconnect(struct port_state *ps);
|
||||
|
||||
static char *ahci_portname(struct port_state *ps);
|
||||
static int ahci_open(dev_t minor, int access);
|
||||
static int ahci_close(dev_t minor);
|
||||
static ssize_t ahci_transfer(dev_t minor, int do_write, u64_t position,
|
||||
static int ahci_open(devminor_t minor, int access);
|
||||
static int ahci_close(devminor_t minor);
|
||||
static ssize_t ahci_transfer(devminor_t minor, int do_write, u64_t position,
|
||||
endpoint_t endpt, iovec_t *iovec, unsigned int count, int flags);
|
||||
static struct device *ahci_part(dev_t minor);
|
||||
static struct device *ahci_part(devminor_t minor);
|
||||
static void ahci_alarm(clock_t stamp);
|
||||
static int ahci_ioctl(dev_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant);
|
||||
static int ahci_ioctl(devminor_t minor, unsigned long request,
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t user_endpt);
|
||||
static void ahci_intr(unsigned int mask);
|
||||
static int ahci_device(dev_t minor, device_id_t *id);
|
||||
static struct port_state *ahci_get_port(dev_t minor);
|
||||
static int ahci_device(devminor_t minor, device_id_t *id);
|
||||
static struct port_state *ahci_get_port(devminor_t minor);
|
||||
|
||||
/* AHCI driver table. */
|
||||
static struct blockdriver ahci_dtab = {
|
||||
BLOCKDRIVER_TYPE_DISK,
|
||||
ahci_open,
|
||||
ahci_close,
|
||||
ahci_transfer,
|
||||
ahci_ioctl,
|
||||
NULL, /* bdr_cleanup */
|
||||
ahci_part,
|
||||
NULL, /* bdr_geometry */
|
||||
ahci_intr,
|
||||
ahci_alarm,
|
||||
NULL, /* bdr_other */
|
||||
ahci_device
|
||||
.bdr_type = BLOCKDRIVER_TYPE_DISK,
|
||||
.bdr_open = ahci_open,
|
||||
.bdr_close = ahci_close,
|
||||
.bdr_transfer = ahci_transfer,
|
||||
.bdr_ioctl = ahci_ioctl,
|
||||
.bdr_part = ahci_part,
|
||||
.bdr_intr = ahci_intr,
|
||||
.bdr_alarm = ahci_alarm,
|
||||
.bdr_device = ahci_device
|
||||
};
|
||||
|
||||
/*===========================================================================*
|
||||
|
|
@ -1715,7 +1712,7 @@ static void port_intr(struct port_state *ps)
|
|||
/*===========================================================================*
|
||||
* port_timeout *
|
||||
*===========================================================================*/
|
||||
static void port_timeout(struct timer *tp)
|
||||
static void port_timeout(minix_timer_t *tp)
|
||||
{
|
||||
/* A timeout has occurred on this port. Figure out what the timeout is
|
||||
* for, and take appropriate action.
|
||||
|
|
@ -2422,7 +2419,7 @@ static char *ahci_portname(struct port_state *ps)
|
|||
/*===========================================================================*
|
||||
* ahci_map_minor *
|
||||
*===========================================================================*/
|
||||
static struct port_state *ahci_map_minor(dev_t minor, struct device **dvp)
|
||||
static struct port_state *ahci_map_minor(devminor_t minor, struct device **dvp)
|
||||
{
|
||||
/* Map a minor device number to a port and a pointer to the partition's
|
||||
* device structure. Return NULL if this minor device number does not
|
||||
|
|
@ -2433,7 +2430,7 @@ static struct port_state *ahci_map_minor(dev_t minor, struct device **dvp)
|
|||
|
||||
ps = NULL;
|
||||
|
||||
if (minor < NR_MINORS) {
|
||||
if (minor >= 0 && minor < NR_MINORS) {
|
||||
port = ahci_map[minor / DEV_PER_DRIVE];
|
||||
|
||||
if (port == NO_PORT)
|
||||
|
|
@ -2458,7 +2455,7 @@ static struct port_state *ahci_map_minor(dev_t minor, struct device **dvp)
|
|||
/*===========================================================================*
|
||||
* ahci_part *
|
||||
*===========================================================================*/
|
||||
static struct device *ahci_part(dev_t minor)
|
||||
static struct device *ahci_part(devminor_t minor)
|
||||
{
|
||||
/* Return a pointer to the partition information structure of the given
|
||||
* minor device.
|
||||
|
|
@ -2474,7 +2471,7 @@ static struct device *ahci_part(dev_t minor)
|
|||
/*===========================================================================*
|
||||
* ahci_open *
|
||||
*===========================================================================*/
|
||||
static int ahci_open(dev_t minor, int access)
|
||||
static int ahci_open(devminor_t minor, int access)
|
||||
{
|
||||
/* Open a device.
|
||||
*/
|
||||
|
|
@ -2500,7 +2497,7 @@ static int ahci_open(dev_t minor, int access)
|
|||
return ENXIO;
|
||||
|
||||
/* Some devices may only be opened in read-only mode. */
|
||||
if ((ps->flags & FLAG_READONLY) && (access & W_BIT))
|
||||
if ((ps->flags & FLAG_READONLY) && (access & BDEV_W_BIT))
|
||||
return EACCES;
|
||||
|
||||
if (ps->open_count == 0) {
|
||||
|
|
@ -2543,7 +2540,7 @@ static int ahci_open(dev_t minor, int access)
|
|||
/*===========================================================================*
|
||||
* ahci_close *
|
||||
*===========================================================================*/
|
||||
static int ahci_close(dev_t minor)
|
||||
static int ahci_close(devminor_t minor)
|
||||
{
|
||||
/* Close a device.
|
||||
*/
|
||||
|
|
@ -2599,7 +2596,7 @@ static int ahci_close(dev_t minor)
|
|||
/*===========================================================================*
|
||||
* ahci_transfer *
|
||||
*===========================================================================*/
|
||||
static ssize_t ahci_transfer(dev_t minor, int do_write, u64_t position,
|
||||
static ssize_t ahci_transfer(devminor_t minor, int do_write, u64_t position,
|
||||
endpoint_t endpt, iovec_t *iovec, unsigned int count, int flags)
|
||||
{
|
||||
/* Perform data transfer on the selected device.
|
||||
|
|
@ -2634,8 +2631,8 @@ static ssize_t ahci_transfer(dev_t minor, int do_write, u64_t position,
|
|||
/*===========================================================================*
|
||||
* ahci_ioctl *
|
||||
*===========================================================================*/
|
||||
static int ahci_ioctl(dev_t minor, unsigned int request, endpoint_t endpt,
|
||||
cp_grant_id_t grant)
|
||||
static int ahci_ioctl(devminor_t minor, unsigned long request,
|
||||
endpoint_t endpt, cp_grant_id_t grant, endpoint_t UNUSED(user_endpt))
|
||||
{
|
||||
/* Process I/O control requests.
|
||||
*/
|
||||
|
|
@ -2685,13 +2682,13 @@ static int ahci_ioctl(dev_t minor, unsigned int request, endpoint_t endpt,
|
|||
sizeof(val));
|
||||
}
|
||||
|
||||
return EINVAL;
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* ahci_device *
|
||||
*===========================================================================*/
|
||||
static int ahci_device(dev_t minor, device_id_t *id)
|
||||
static int ahci_device(devminor_t minor, device_id_t *id)
|
||||
{
|
||||
/* Map a minor device number to a device ID.
|
||||
*/
|
||||
|
|
@ -2709,7 +2706,7 @@ static int ahci_device(dev_t minor, device_id_t *id)
|
|||
/*===========================================================================*
|
||||
* ahci_get_port *
|
||||
*===========================================================================*/
|
||||
static struct port_state *ahci_get_port(dev_t minor)
|
||||
static struct port_state *ahci_get_port(devminor_t minor)
|
||||
{
|
||||
/* Get the port structure associated with the given minor device.
|
||||
* Called only from worker threads, so the minor device is already
|
||||
|
|
|
|||
|
|
@ -264,7 +264,6 @@ typedef struct vumap_phys prd_t;
|
|||
*/
|
||||
#define MAX_DRIVES 8
|
||||
#define NR_MINORS (MAX_DRIVES * DEV_PER_DRIVE)
|
||||
#define SUB_PER_DRIVE (NR_PARTITIONS * NR_PARTITIONS)
|
||||
#define NR_SUBDEVS (MAX_DRIVES * SUB_PER_DRIVE)
|
||||
|
||||
/* Port states. */
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ int main(void)
|
|||
if (m.m_type == IOMMU_MAP) {
|
||||
r= do_add4pci(&m);
|
||||
m.m_type= r;
|
||||
send(m.m_source, &m);
|
||||
ipc_send(m.m_source, &m);
|
||||
continue;
|
||||
}
|
||||
printf("amddev: got message from %d\n", m.m_source);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#define VERBOSE 0 /* display identify messages during boot */
|
||||
#define VERBOSE_DMA 0 /* display DMA debugging information */
|
||||
#define ENABLE_ATAPI 1 /* add ATAPI cd-rom support to driver */
|
||||
|
||||
#define ATAPI_DEBUG 0 /* To debug ATAPI code. */
|
||||
|
||||
|
|
@ -129,7 +128,6 @@
|
|||
* regular LBA.
|
||||
*/
|
||||
|
||||
#if ENABLE_ATAPI
|
||||
#define ERROR_SENSE 0xF0 /* sense key mask */
|
||||
#define SENSE_NONE 0x00 /* no sense key */
|
||||
#define SENSE_RECERR 0x10 /* recovered error */
|
||||
|
|
@ -156,7 +154,6 @@
|
|||
#define REG_CNT_LO 4 /* low byte of cylinder number */
|
||||
#define REG_CNT_HI 5 /* high byte of cylinder number */
|
||||
#define REG_DRIVE 6 /* drive select */
|
||||
#endif
|
||||
|
||||
#define REG_STATUS 7 /* status */
|
||||
#define STATUS_BSY 0x80 /* controller busy */
|
||||
|
|
@ -167,15 +164,10 @@
|
|||
#define STATUS_CORR 0x04 /* correctable error occurred */
|
||||
#define STATUS_CHECK 0x01 /* check error */
|
||||
|
||||
#if ENABLE_ATAPI
|
||||
#define ATAPI_PACKETCMD 0xA0 /* packet command */
|
||||
#define ATAPI_IDENTIFY 0xA1 /* identify drive */
|
||||
#define SCSI_READ10 0x28 /* read from disk */
|
||||
#define SCSI_SENSE 0x03 /* sense request */
|
||||
#endif /* ATAPI */
|
||||
|
||||
/* Interrupt request lines. */
|
||||
#define NO_IRQ 0 /* no IRQ set yet */
|
||||
|
||||
#define ATAPI_PACKETSIZE 12
|
||||
#define SENSE_PACKETSIZE 18
|
||||
|
|
@ -185,17 +177,16 @@
|
|||
#define ERR_BAD_SECTOR (-2) /* block marked bad detected */
|
||||
|
||||
/* Some controllers don't interrupt, the clock will wake us up. */
|
||||
#define WAKEUP_SECS 32 /* drive may be out for 31 seconds max */
|
||||
#define WAKEUP_SECS 32 /* drive may be out for 31 seconds max */
|
||||
#define WAKEUP_TICKS (WAKEUP_SECS*system_hz)
|
||||
|
||||
/* Miscellaneous. */
|
||||
#define MAX_DRIVES 8
|
||||
#define COMPAT_DRIVES 4
|
||||
#define MAX_DRIVES 4 /* max number of actual drives per instance */
|
||||
#define MAX_DRIVENODES 8 /* number of drive nodes, for node numbering */
|
||||
#define MAX_SECS 256 /* controller can transfer this many sectors */
|
||||
#define MAX_ERRORS 4 /* how often to try rd/wt before quitting */
|
||||
#define NR_MINORS (MAX_DRIVES * DEV_PER_DRIVE)
|
||||
#define SUB_PER_DRIVE (NR_PARTITIONS * NR_PARTITIONS)
|
||||
#define NR_SUBDEVS (MAX_DRIVES * SUB_PER_DRIVE)
|
||||
#define NR_MINORS (MAX_DRIVENODES * DEV_PER_DRIVE)
|
||||
#define NR_SUBDEVS (MAX_DRIVENODES * SUB_PER_DRIVE)
|
||||
#define DELAY_USECS 1000 /* controller timeout in microseconds */
|
||||
#define DELAY_TICKS 1 /* controller timeout in ticks */
|
||||
#define DEF_TIMEOUT_USECS 5000000L /* controller timeout in microseconds */
|
||||
|
|
@ -204,18 +195,15 @@
|
|||
#define INITIALIZED 0x01 /* drive is initialized */
|
||||
#define DEAF 0x02 /* controller must be reset */
|
||||
#define SMART 0x04 /* drive supports ATA commands */
|
||||
#if ENABLE_ATAPI
|
||||
#define ATAPI 0x08 /* it is an ATAPI device */
|
||||
#else
|
||||
#define ATAPI 0 /* don't bother with ATAPI; optimise out */
|
||||
#endif
|
||||
#define IDENTIFIED 0x10 /* w_identify done successfully */
|
||||
#define IGNORING 0x20 /* w_identify failed once */
|
||||
|
||||
#define NO_DMA_VAR "ata_no_dma"
|
||||
|
||||
/* BIOS parameter table layout. */
|
||||
#define bp_cylinders(t) (t[0] | (t[1] << 8))
|
||||
#define bp_heads(t) (t[2])
|
||||
#define bp_precomp(t) (t[5] | (t[6] << 8))
|
||||
#define bp_sectors(t) (t[14])
|
||||
#define ATA_IF_NATIVE0 (1L << 0) /* first channel is in native mode */
|
||||
#define ATA_IF_NATIVE1 (1L << 2) /* second channel is in native mode */
|
||||
|
||||
extern int sef_cb_lu_prepare(int state);
|
||||
extern int sef_cb_lu_state_isvalid(int state);
|
||||
extern void sef_cb_lu_state_dump(int state);
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ static void atl2_reply(void)
|
|||
ATL2_DEBUG(("ATL2: sending reply, flags %x count %d\n", flags,
|
||||
m.DL_COUNT));
|
||||
|
||||
if ((r = send(state.task_endpt, &m)) != OK)
|
||||
if ((r = ipc_send(state.task_endpt, &m)) != OK)
|
||||
panic("unable to reply: %d", r);
|
||||
|
||||
state.flags &= ~(ATL2_FLAG_PACK_SENT | ATL2_FLAG_PACK_RCVD);
|
||||
|
|
@ -1042,7 +1042,7 @@ static void atl2_conf(message *m)
|
|||
m->m_type = DL_CONF_REPLY;
|
||||
m->DL_STAT = OK;
|
||||
|
||||
if ((r = send(m->m_source, m)) != OK)
|
||||
if ((r = ipc_send(m->m_source, m)) != OK)
|
||||
printf("ATL2: unable to send reply (%d)\n", r);
|
||||
}
|
||||
|
||||
|
|
@ -1060,7 +1060,7 @@ static void atl2_getstat(message *m)
|
|||
|
||||
m->m_type = DL_STAT_REPLY;
|
||||
|
||||
if ((r = send(m->m_source, m)) != OK)
|
||||
if ((r = ipc_send(m->m_source, m)) != OK)
|
||||
printf("ATL2: unable to send reply (%d)\n", r);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ service atl2
|
|||
UMAP # 14
|
||||
IRQCTL # 19
|
||||
;
|
||||
pci device 1969/2048;
|
||||
pci device 1969:2048;
|
||||
ipc
|
||||
SYSTEM pm rs tty ds vm
|
||||
pci inet lwip
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ int drv_stop(int sub_dev)
|
|||
|
||||
|
||||
/* all IO-ctl's sent to the upper driver are passed to this function */
|
||||
int drv_io_ctl(int request, void * val, int * len, int sub_dev) {
|
||||
int drv_io_ctl(unsigned long request, void * val, int * len, int sub_dev) {
|
||||
|
||||
int status;
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user