*BSD News Article 60563


Return to BSD News archive

#! rnews 76628 bsd
Newsgroups: comp.bugs.2bsd
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!inferno.mpx.com.au!news.mel.aone.net.au!imci4!newsfeed.internetmci.com!news.mathworks.com!uunet!in2.uu.net!news.new-york.net!wlbr!sms
From: sms@wlv.iipo.gtegsc.com (Steven M. Schultz)
Subject: mount(8) options, !/etc/mtab, libkern.a, MANY others (#293 part 2 of 8)
Sender: news@wlbr.iipo.gtegsc.com (Steven M. Schultz)
Organization: GTE Government Systems, Thousand Oaks CA USA
Message-ID: <DM4ro7.LyG@wlbr.iipo.gtegsc.com>
X-Nntp-Posting-Host: wlv.iipo.gtegsc.com
Date: Fri, 2 Feb 1996 04:12:07 GMT
Lines: 2666

Subject: mount(8) options, !/etc/mtab, libkern.a, MANY others (#293 part 2 of 8)
Index:	many/many 2.11BSD

Description:
	Mount(8) does not pass options other than 'readonly' thru to the
	kernel even though the kernel understands many more options than
	that.

	/etc/mtab is not needed any longer because applications (mount, umount,
	others) can obtain the list of mounted filesystems via getmntinfo(3),
	or getfsstat(2)

	There are copies of 15 libc routines in the kernel directories.  These
	are invariant but nevertheless are always being recompiled/assembled
	whenever a kernel is built.

Repeat-By:
	It sounds inadequate, but, "observation".

Fix:
	This is #293 (part 2 of 8).

	Please refer to part 1 (#292) for detailed instructions and a
	description of contents.

----------------------------cut here-------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	/usr/src/etc/mount
#	/usr/src/etc/umount
#	/usr/src/lib/libc/stdlib
#	/usr/src/lib/libc/gen/fstab.c
# This archive created: Tue Jan 30 21:07:54 1996
export PATH; PATH=/bin:/usr/bin:$PATH
if test ! -d '/usr/src/etc/mount'
then
	mkdir '/usr/src/etc/mount'
fi
cd '/usr/src/etc/mount'
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X#
X# Public Domain.  1996/1/15 - Steven Schultz
X#
X#	@(#)Makefile	1.0 (2.11BSD GTE) 1996/1/15
X#
XCFLAGS=	 -O
XSEPFLAG= -i
XSRCS=	mount.c getmntopts.c mount_ufs.c
XOBJS=	mount.o getmntopts.o mount_ufs.o
X#
X# We do NOT install the getmntopts.3 man page
X#
XMAN=	mount.0
XMANSRC=	mount.8
X
Xall: mount mount.0
X
Xmount: ${OBJS}
X	${CC} ${CFLAGS} ${SEPFLAG} -o $@ ${OBJS}
X
Xmount.0: ${MANSRC}
X	/usr/man/manroff ${MANSRC} > ${MAN}
X
Xclean:
X	rm -f ${OBJS} ${MAN} mount tags 
X
Xdepend: ${SRCS}
X	mkdep ${CFLAGS} ${SRCS}
X
Xinstall: all
X	install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat8
X	install -s -o root -g bin -m 755 mount ${DESTDIR}/etc/mount
X
Xlint: ${SRCS}
X	lint -hax ${SRCS}
X
Xtags: ${SRCS}
X	ctags ${SRCS}
X# DO NOT DELETE THIS LINE -- mkdep uses it.
X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
SHAR_EOF
chmod 644 'Makefile'
fi
if test -f 'getmntopts.3'
then
	echo shar: "will not over-write existing file 'getmntopts.3'"
else
sed 's/^X//' << \SHAR_EOF > 'getmntopts.3'
X.\" Copyright (c) 1994
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 3. All advertising materials mentioning features or use of this software
X.\"    must display the following acknowledgement:
X.\"	This product includes software developed by the University of
X.\"	California, Berkeley and its contributors.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\"	@(#)getmntopts.3	8.1.1 (2.11BSD) 1996/1/16
X.\"
X.TH GETMNTOPTS 3 "January 16, 1996"
X.UC 7
X.SH NAME
X\fBgetmntopts\fP \- scan mount options
X.SH SYNOPSIS
X.B #include <mntopts.h>
X.sp
X.B void
X.br
X.B getmntopts(options, mopts, flagp)
X.br
X.B char *options;
X.br
X.B struct mntopt *mopts;
X.br
X.B int *flagp
X.SH DESCRIPTION
XThe
X.BR getmntopts ()
Xfunction takes a comma separated option list and a list
Xof valid option names, and computes the bitmask
Xcorresponding to the requested set of options.
X.PP
XThe string
X.I options
Xis broken down into a sequence of comma separated tokens.
XEach token is looked up in the table described by
X.I mopts
Xand the bits in
Xthe word referenced by
X.I flagp
Xare updated.
XThe flag word is not initialized by
X.BR getmntopt .
XThe table,
X.IR mopts ,
Xhas the following format:
X.sp
X.cs R 24
X.nf
Xstruct mntopt {
X	char *m_option;		/* option name */
X	int m_inverse;		/* is this a negative option, eg "dev" */
X	int m_flag;		/* bit to set, eg MNT_RDONLY */
X};
X.br
X.fi
X.cs R
X.PP
XThe members of this structure are:
X.sp
X.TP 10
X\fIm_option\fP
Xthe option name,
Xfor example
X``suid''.
X.TP 10
X\fIm_inverse\fP
Xtells
X.B getmntopts
Xthat the name has the inverse meaning of the
Xbit.
XFor example,
X``suid''
Xis the string, whereas the
Xmount flag is
XMNT_NOSUID.
XIn this case, the sense of the string and the flag
Xare inverted, so the
X.I m_inverse
Xflag should be set.
X.TP 10
X\fIm_flag\fP
Xthe value of the bit to be set or cleared in
Xthe flag word when the option is recognized.
XThe bit is set when the option is discovered,
Xbut cleared if the option name was preceded
Xby the letters
X``no''.
XThe
X.I m_inverse
Xflag causes these two operations to be reversed.
X.PP
XEach of the user visible
X.I MNT_
Xflags has a corresponding
X.I MOPT_
Xmacro which defines an appropriate
X.I "struct mntopt"
Xentry.
XTo simplify the program interface and ensure consistency across all
Xprograms, a general purpose macro,
X.IR MOPT_STDOPTS ,
Xis defined which
Xcontains an entry for all the generic VFS options.
XIn addition, the macros
X.I MOPT_FORCE
Xand
X.I MOPT_UPDATE
Xexist to enable the
X.I MNT_FORCE
Xand
X.I MNT_UPDATE
Xflags to be set.
XFinally, the table must be terminated by an entry with a NULL
Xfirst element.
X.SH EXAMPLES
XMost commands will use the standard option set.
XLocal filesystems which support the
X.I MNT_UPDATE
Xflag, would also have an
X.I MOPT_UPDATE
Xentry.
XThis can be declared and used as follows:
X.sp
X.nf
X.cs R 24
X#include "mntopts.h"
X
Xstruct mntopt mopts[] = {
X	MOPT_STDOPTS,
X	MOPT_UPDATE,
X	{ NULL }
X};
X
X	...
X	mntflags = 0;
X	...
X	getmntopts(options, mopts, &mntflags)
X	...
X.br
X.fi
X.cs R
X.SH DIAGNOSTICS
XThe
X.B getmntopts
Xfunction displays an error message and exits if an
Xunrecognized option is encountered.
X.SH SEE ALSO
Xerr(3),
Xmount(8)
X.SH HISTORY
XThe
X.B getmntopts
Xfunction appeared in 4.4BSD.
SHAR_EOF
chmod 644 'getmntopts.3'
fi
if test -f 'getmntopts.c'
then
	echo shar: "will not over-write existing file 'getmntopts.c'"
else
sed 's/^X//' << \SHAR_EOF > 'getmntopts.c'
X/*-
X * Copyright (c) 1994
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if	!defined(lint) && defined(DOSCCS)
Xstatic char sccsid[] = "@(#)getmntopts.c	8.1.1 (2.11BSD) 1996/1/16";
X#endif /* not lint */
X
X#include <sys/param.h>
X#include <sys/mount.h>
X
X#include <errno.h>
X#include <fstab.h>
X#include <stdlib.h>
X#include <string.h>
X
X#include "mntopts.h"
X
Xvoid
Xgetmntopts(options, m0, flagp)
X	char *options;
X	struct mntopt *m0;
X	int *flagp;
X{
X	register struct mntopt *m;
X	int negative;
X	register char *opt;
X	char *optbuf;
X
X	/* Copy option string, since it is about to be torn asunder... */
X	if ((optbuf = strdup(options)) == NULL)
X		err(1, NULL);
X
X	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
X		/* Check for "no" prefix. */
X		if (opt[0] == 'n' && opt[1] == 'o') {
X			negative = 1;
X			opt += 2;
X		} else
X			negative = 0;
X
X		/* Scan option table. */
X		for (m = m0; m->m_option != NULL; ++m)
X			if (strcasecmp(opt, m->m_option) == 0)
X				break;
X
X		/* Save flag, or fail if option is not recognised. */
X		if (m->m_option) {
X			if (negative == m->m_inverse)
X				*flagp |= m->m_flag;
X			else
X				*flagp &= ~m->m_flag;
X		} else
X			errx(1, "-o %s: option not supported", opt);
X	}
X
X	free(optbuf);
X}
SHAR_EOF
chmod 644 'getmntopts.c'
fi
if test -f 'mntopts.h'
then
	echo shar: "will not over-write existing file 'mntopts.h'"
else
sed 's/^X//' << \SHAR_EOF > 'mntopts.h'
X/*-
X * Copyright (c) 1994
X *      The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *	@(#)mntopts.h	8.3.1 (2.11BSD) 1996/1/16
X */
X
Xstruct mntopt {
X	char *m_option;		/* option name */
X	int m_inverse;		/* if a negative option, eg "dev" */
X	int m_flag;		/* bit to set, eg. MNT_RDONLY */
X};
X
X/* User-visible MNT_ flags. */
X#define MOPT_ASYNC		{ "async",	0, MNT_ASYNC }
X#define MOPT_NODEV		{ "dev",	1, MNT_NODEV }
X#define MOPT_NOEXEC		{ "exec",	1, MNT_NOEXEC }
X#define MOPT_NOSUID		{ "suid",	1, MNT_NOSUID }
X#define MOPT_RDONLY		{ "rdonly",	0, MNT_RDONLY }
X#define MOPT_SYNC		{ "sync",	0, MNT_SYNCHRONOUS }
X
X/* Control flags. */
X#define MOPT_FORCE		{ "force",	1, MNT_FORCE }
X#define MOPT_UPDATE		{ "update",	0, MNT_UPDATE }
X
X/* Support for old-style "ro", "rw" flags. */
X#define MOPT_RO			{ "ro",		0, MNT_RDONLY }
X#define MOPT_RW			{ "rw",		1, MNT_RDONLY }
X#define MOPT_RQ			{ "rq",		1, MNT_RDONLY }
X
X#define MOPT_FSTAB_COMPAT						\
X	MOPT_RO,							\
X	MOPT_RW,							\
X	MOPT_RQ
X
X/* Standard options which all mounts can understand. */
X#define MOPT_STDOPTS							\
X	MOPT_FSTAB_COMPAT,						\
X	MOPT_NODEV,							\
X	MOPT_NOEXEC,							\
X	MOPT_NOSUID,							\
X	MOPT_RDONLY
X
Xvoid getmntopts();
SHAR_EOF
chmod 644 'mntopts.h'
fi
if test -f 'mount.8'
then
	echo shar: "will not over-write existing file 'mount.8'"
else
sed 's/^X//' << \SHAR_EOF > 'mount.8'
X.\" Copyright (c) 1980, 1989, 1991, 1993
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 3. All advertising materials mentioning features or use of this software
X.\"    must display the following acknowledgement:
X.\"	This product includes software developed by the University of
X.\"	California, Berkeley and its contributors.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\"     @(#)mount.8	8.7.1 (2.11BSD) 1996/1/16
X.\"
X.TH MOUNT 8 "January 16, 1996"
X.UC 7
X.SH NAME
X\fBmount\fP \- mount file systems
X.SH SYNOPSIS
X.B mount
X[ \fB\-adfruvw\fP ]
X[ \fB\-t\fP \fIufs\fP | \fIexternal_type\fP ]
X.br
X.B mount
X[ \fB\-dfruvw\fP ]
X\fIspecial\fP | \fInode\fP
X.br
X.B mount
X[ \fB\-dfruvw\fP ]
X[ \fB\-o\fP \fIoptions\fP ]
X[ \fB\-t\fP \fIufs\fP | \fIexternal_type\fP ]
X.I special node
X.SH DESCRIPTION
XThe
X.B mount
Xcommand
Xcalls the
Xmount(2)
Xsystem call to prepare and graft a
X.I "special device"
Xon to the file system tree at the point
X.IR node .
XIf either
X.I special
Xor
X.I node
Xare not provided, the appropriate information is taken from the
Xfstab(5)
Xfile.
X.PP
XThe system maintains a list of currently mounted file systems.
XIf no arguments are given to
X.BR mount ,
Xthis list is printed.
X.PP
XThe options are as follows:
X.sp
X.TP 10
X\fB\-a\fP
XCauses everything to be done except for the actual system call.
XThis option is useful in conjunction with the
X.TP 10
X\fB\-v\fP
Xflag to
Xdetermine what the
X.B mount
Xcommand is trying to do.
X.TP 10
X\fB\-f\fP
XForces the revocation of write access when trying to downgrade
Xa filesystem mount status from read-write to read-only.  For 2.11BSD this
Xflag is currently not implemented.
X.TP 10
X\fB\-o\fP
XOptions are specified with a \fB\-o\fP
Xflag followed by a comma separated string of options.
XThe following options are available:
X.sp
X.RS 1.0i
X.TP 10
Xasync
XAll I/O
Xto the file system should be done asynchronously.
XThis is a
X.B dangerous
Xflag to set,
Xand should not be used unless you are prepared to recreate the file
Xsystem should your system crash.  This option is not currently implemented
Xin 2.11BSD but is planned for the future.
X.TP 10
Xforce
XThe same as
X\fB\-f\fP;
Xforces the revocation of write access when trying to downgrade
Xa filesystem mount status from read-write to read-only.   Currently a NOP
Xin 2.11BSD.
X.TP 10
Xnodev
XDo not interpret character or block special devices on the file system.
XThis option is useful for a server that has file systems containing
Xspecial devices for architectures other than its own.
X.TP 10
Xnoexec
XDo not allow execution of any binaries on the mounted file system.
XThis option is useful for a server that has file systems containing
Xbinaries for architectures other than its own.
X.TP 10
Xnosuid
XDo not allow set-user-identifier or set-group-identifier bits to take effect.
X.TP 10
Xrdonly
XThe same as
X\fB\-r\fP;
Xmount the file system read-only (even the super-user may not write it).
X.TP 10
Xsync
XAll I/O
Xto the file system should be done synchronously.  Not implemented yet in
X2.11BSD but is planned for the future.
X.TP 10
Xupdate
XThe same as
X\fB\-u\fP;
Xindicate that the status of an already mounted file system should be changed.
XNot currently implemented in 2.11BSD.
X.PP
XAny additional options specific to a filesystem type that is not
Xone of the internally known types (see the
X\fB\-t\fP
Xoption) may be passed as a comma separated list; these options are
Xdistinguished by a leading
X\&- (dash).
XOptions that take a value are specified using the syntax -option=value.
XAt present no 2.11BSD mount options use the following form, the example
Xhas been retained for illustrative purposes only.
XFor example, the mount command:
X.sp
Xmount -t mfs -o nosuid,-N,-s=4000 /dev/dk0b /tmp
X.PP
Xcauses
X.B mount
Xto execute the equivalent of:
X.sp
X/sbin/mount_mfs -o nosuid -N -s 4000 /dev/dk0b /tmp
X.br
X.RE 1.0i
X.TP 10
X\fB\-r\fP
XThe file system is to be mounted read-only.
XMount the file system read-only (even the super-user may not write it).
XThe same as the
X``rdonly''
Xargument to the
X\fB\-o\fP
Xoption.
X.TP 10
X\fB\-t\fP "\fIufs\fP | \fIexternal type\fP"
XThe argument following the
X\fB\-t\fP
Xis used to indicate the file system type.
XThe type
X.I ufs
Xis the default.  \fIUfs\fP is also the only value supported by 2.11BSD other 
Xthan \fIswap\fP.  Thus
Xthe \fB\-t\fP will rarely be used.
XThe \fB\-t\fP option can be used
Xto indicate that the actions should only be taken on
Xfilesystems of the specified type.
XMore than one type may be specified in a comma separated list.
XThe list of filesystem types can be prefixed with
X``no''
Xto specify the filesystem types for which action should
X.I not
Xbe taken.
XFor example, the
X.B mount
Xcommand:
X.sp
Xmount -a -t nonfs,mfs
X.sp
Xmounts all filesystems except those of type
XNFS
Xand
XMFS.
X.sp
XIf the type is not one of the internally known types,
Xmount will attempt to execute a program in
X.I /etc/mount_XXX
Xwhere
X.I XXX
Xis replaced by the type name.
XFor example, mfs filesystems are mounted by the program
X.IR /sbin/mount_mfs .
X.TP 10
X\fB\-u\fP
XThe
X\fB\-u\fP
Xflag indicates that the status of an already mounted file
Xsystem should be changed.
XAny of the options discussed above (the
X\fB\-o\fP
Xoption)
Xmay be changed;
Xalso a file system can be changed from read-only to read-write
Xor vice versa.
XAn attempt to change from read-write to read-only will fail if any
Xfiles on the filesystem are currently open for writing unless the
X\fB\-f\fP
Xflag is also specified.
XThis is currently not implemented in 2.11BSD but it is planned that 
Xthe ability to change the flags (nodev, nosuid, etc) will be implemented.
XThe set of options is determined by first extracting the options
Xfor the file system from the
X.I fstab
Xtable,
Xthen applying any options specified by the
X\fB\-o\fP
Xargument,
Xand finally applying the
X\fB\-r\fP
Xor
X\fB\-w\fP
Xoption.
X.TP 10
X\fB\-v\fP
XVerbose mode.
X.TP 10
X\fB\-w\fP
XThe file system object is to be read and write.
X.SH FILES
X.TP 10
X/etc/fstab
Xfile system table
X.SH SEE ALSO
Xmount(2),
Xfstab(5),
Xumount(8)
X.SH BUGS
XIt is possible for a corrupted file system to cause a crash.
X.PP
X.B mount
Xand this manpage were ported from 4.4BSD-Lite to 2.11BSD to gain the
Xability to set the various flags such as \fBnodev\fP, \fBnosuid\fP and
Xso on.   Multiple filesystem types are not supported and several of the
Xoptions and flags are not yet implemented.
X.SH HISTORY
XA
X.B mount
Xcommand appeared in Version 6 AT&T UNIX.
SHAR_EOF
chmod 644 'mount.8'
fi
if test -f 'mount.c'
then
	echo shar: "will not over-write existing file 'mount.c'"
else
sed 's/^X//' << \SHAR_EOF > 'mount.c'
X/*
X * Copyright (c) 1980, 1989, 1993, 1994
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if	!defined(lint) && defined(DOSCCS)
Xstatic char copyright[] =
X"@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
X	The Regents of the University of California.  All rights reserved.\n";
X
Xstatic char sccsid[] = "@(#)mount.c	8.19.1 (2.11BSD) 1996/1/16";
X#endif /* not lint */
X
X#include <sys/param.h>
X#include <sys/mount.h>
X#include <sys/wait.h>
X
X#include <errno.h>
X#include <fstab.h>
X#include <signal.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <unistd.h>
X
X#include "pathnames.h"
X
Xint debug, verbose, skipvfs, mountrw;
X
Xint	badvfsname();
Xint	badvfstype();
Xchar   *catopt();
Xstruct statfs *getmntpt();
Xchar **makevfslist();
Xvoid	mangle();
Xint	mountfs();
Xvoid	prmount();
Xvoid	usage();
X
X/* From mount_ufs.c. */
Xint	mount_ufs();
X
X/* Map from mount otions to printable formats. */
Xstatic struct opt {
X	int o_opt;
X	char *o_name;
X} optnames[] = {
X#ifdef	notnow
X	{ MNT_ASYNC,		"asynchronous" },
X#endif
X	{ MNT_NODEV,		"nodev" },
X	{ MNT_NOEXEC,		"noexec" },
X	{ MNT_NOSUID,		"nosuid" },
X	{ MNT_QUOTA,		"with quotas" },
X	{ MNT_RDONLY,		"read-only" },
X	{ MNT_SYNCHRONOUS,	"synchronous" },
X	{ NULL }
X};
X
Xint
Xmain(argc, argv)
X	int argc;
X	register char *argv[];
X{
X	char *mntonname, **vfslist, *vfstype;
X	register struct fstab *fs;
X	struct statfs *mntbuf;
X	int all, ch, i, init_flags, mntsize, rval;
X	char *options, *na;
X
X	all = init_flags = 0;
X	options = NULL;
X	vfslist = NULL;
X	vfstype = "ufs";
X	while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
X		switch (ch) {
X		case 'a':
X			all = 1;
X			break;
X		case 'd':
X			debug = 1;
X			break;
X		case 'f':
X#ifdef	notnow
X			init_flags |= MNT_FORCE;
X#endif
X			break;
X		case 'o':
X			if (*optarg)
X				options = catopt(options, optarg);
X			break;
X		case 'r':
X			init_flags |= MNT_RDONLY;
X			mountrw = 0;
X			break;
X		case 't':
X			if (vfslist != NULL)
X				errx(1, "only one -t option may be specified.");
X			vfslist = makevfslist(optarg);
X			vfstype = optarg;
X			break;
X		case 'u':
X			init_flags |= MNT_UPDATE;
X			break;
X		case 'v':
X			verbose = 1;
X			break;
X		case 'w':
X			init_flags &= ~MNT_RDONLY;
X			mountrw = 1;
X			break;
X		case '?':
X		default:
X			usage();
X			/* NOTREACHED */
X		}
X	argc -= optind;
X	argv += optind;
X
X#define	BADTYPE(type)							\
X	(strcmp(type, FSTAB_RO) &&					\
X	    strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
X
X	rval = 0;
X	switch (argc) {
X	case 0:
X		if (all)
X			while ((fs = getfsent()) != NULL) {
X				if (BADTYPE(fs->fs_type))
X					continue;
X				/*
X				 * Check to see if "na" is one of the options,
X				 * if so, don't mount it.
X				*/
X				if (fs->fs_mntops &&
X				    (na = strstr(fs->fs_mntops, "na")) &&
X				    ((na = fs->fs_mntops) || na[-1] == ',') &&
X				    (na[2] == ',' || na[2] == '\0')) {
X				    continue;
X				}
X				if (badvfsname(fs->fs_vfstype, vfslist))
X					continue;
X				if (mountfs(fs->fs_vfstype, fs->fs_spec,
X				    fs->fs_file, init_flags, options,
X				    fs->fs_mntops))
X					rval = 1;
X			}
X		else {
X			if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
X				err(1, "getmntinfo");
X			for (i = 0; i < mntsize; i++) {
X				if (badvfstype(mntbuf[i].f_type, vfslist))
X					continue;
X				prmount(mntbuf[i].f_mntfromname,
X				    mntbuf[i].f_mntonname, mntbuf[i].f_flags);
X			}
X		}
X		exit(rval);
X	case 1:
X		if (vfslist != NULL)
X			usage();
X
X		if (init_flags & MNT_UPDATE) {
X			if ((mntbuf = getmntpt(*argv)) == NULL)
X				errx(1,
X				    "unknown special file or file system %s.",
X				    *argv);
X			if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
X				errx(1, "can't find fstab entry for %s.",
X				    *argv);
X			/* If it's an update, ignore the fstab file options. */
X			fs->fs_mntops = NULL;
X			mntonname = mntbuf->f_mntonname;
X		} else {
X			if ((fs = getfsfile(*argv)) == NULL &&
X			    (fs = getfsspec(*argv)) == NULL)
X				errx(1,
X				    "%s: unknown special file or file system.",
X				    *argv);
X			if (BADTYPE(fs->fs_type))
X				errx(1, "%s has unknown file system type.",
X				    *argv);
X			mntonname = fs->fs_file;
X		}
X		rval = mountfs(fs->fs_vfstype, fs->fs_spec,
X		    mntonname, init_flags, options, fs->fs_mntops);
X		break;
X	case 2:
X		/*
X		 * If -t flag has not been specified, and spec contains either
X		 * a ':' or a '@' then assume that an NFS filesystem is being
X		 * specified ala Sun.  Since 2BSD does not support nfs an 
X		 * error is declared here rather than from mountfs().
X		 */
X		if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
X			err(1, "nfs not supported");
X		rval = mountfs(vfstype,
X		    argv[0], argv[1], init_flags, options, NULL);
X		break;
X	default:
X		usage();
X		/* NOTREACHED */
X	}
X
X	exit(rval);
X}
X
Xint
Xmountfs(vfstype, spec, name, flags, options, mntopts)
X	char *vfstype, *spec, *name, *options, *mntopts;
X	int flags;
X{
X	/* List of directories containing mount_xxx subcommands. */
X	static char *edirs[] = {
X		_PATH_ETC,
X		_PATH_BIN,
X		NULL
X	};
X	char *argv[100], **edir;
X	struct statfs sf;
X	pid_t pid;
X	int argc, i;
X	union	wait status;
X	char *optbuf, execname[MAXPATHLEN + 1];
X
X	if (options == NULL) {
X		if (mntopts == NULL || *mntopts == '\0')
X			options = "rw";
X		else
X			options = mntopts;
X		mntopts = "";
X	if (debug)
X		printf("options: %s\n", options);
X	}
X	optbuf = catopt(mntopts ? strdup(mntopts) : 0, options);
X
X	if (strcmp(name, "/") == 0)
X		flags |= MNT_UPDATE;
X#ifdef	notnow
X	if (flags & MNT_FORCE)
X		optbuf = catopt(optbuf, "force");
X#endif
X	if (flags & MNT_RDONLY)
X		optbuf = catopt(optbuf, "ro");
X	if (mountrw)
X		optbuf = catopt(optbuf, "rw");
X	if (flags & MNT_UPDATE)
X		optbuf = catopt(optbuf, "update");
X
X	argc = 0;
X	argv[argc++] = vfstype;
X	mangle(optbuf, &argc, argv);
X	argv[argc++] = spec;
X	argv[argc++] = name;
X	argv[argc] = NULL;
X
X	if (debug) {
X		(void)printf("exec: mount_%s", vfstype);
X		for (i = 1; i < argc; i++)
X			(void)printf(" %s", argv[i]);
X		(void)printf("\n");
X		return (0);
X	}
X
X	switch (pid = vfork()) {
X	case -1:				/* Error. */
X		warn("vfork");
X		free(optbuf);
X		return (1);
X	case 0:					/* Child. */
X		if (strcmp(vfstype, "ufs") == 0)
X			_exit(mount_ufs(argc, (char **) argv));
X
X		/* Go find an executable. */
X		edir = edirs;
X		do {
X			(void)sprintf(execname, "%s/mount_%s", *edir, vfstype);
X			execv(execname, (char **)argv);
X			if (errno != ENOENT)
X				warn("exec %s for %s", execname, name);
X		} while (*++edir != NULL);
X
X		if (errno == ENOENT)
X			warn("exec %s for %s", execname, name);
X		_exit(1);
X		/* NOTREACHED */
X	default:				/* Parent. */
X		free(optbuf);
X
X		if (waitpid(pid, &status, 0) < 0) {
X			warn("waitpid");
X			return (1);
X		}
X
X		if (WIFEXITED(status)) {
X			if (WEXITSTATUS(status) != 0)
X				return (WEXITSTATUS(status));
X		} else if (WIFSIGNALED(status)) {
X			warnx("%s: %s", name, sys_siglist[status.w_termsig]);
X			return (1);
X		}
X
X		if (verbose) {
X			if (statfs(name, &sf) < 0) {
X				warn("%s", name);
X				return (1);
X			}
X			prmount(sf.f_mntfromname, sf.f_mntonname, sf.f_flags);
X		}
X		break;
X	}
X
X	return (0);
X}
X
Xvoid
Xprmount(spec, name, flags)
X	char *spec, *name;
X	int flags;
X{
X	register struct opt *o;
X	register int f;
X
X	(void)printf("%s on %s", spec, name);
X
X	flags &= MNT_VISFLAGMASK;
X	for (f = 0, o = optnames; flags && o->o_opt; o++)
X		if (flags & o->o_opt) {
X			(void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
X			flags &= ~o->o_opt;
X		}
X	(void)printf(f ? ")\n" : "\n");
X}
X
Xstruct statfs *
Xgetmntpt(name)
X	char *name;
X{
X	struct statfs *mntbuf;
X	register int i, mntsize;
X
X	mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
X	for (i = 0; i < mntsize; i++)
X		if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
X		    strcmp(mntbuf[i].f_mntonname, name) == 0)
X			return (&mntbuf[i]);
X	return (NULL);
X}
X
Xint
Xbadvfsname(vfsname, vfslist)
X	char *vfsname;
X	register char **vfslist;
X{
X
X	if (vfslist == NULL)
X		return (0);
X	while (*vfslist != NULL) {
X		if (strcmp(vfsname, *vfslist) == 0)
X			return (skipvfs);
X		++vfslist;
X	}
X	return (!skipvfs);
X}
X
Xint
Xbadvfstype(vfstype, vfslist)
X	int vfstype;
X	register char **vfslist;
X{
Xstatic char *vfsnames[] = INITMOUNTNAMES;
X
X	if ((vfstype < 0) || (vfstype > MOUNT_MAXTYPE))
X		return (0);
X
X	return (badvfsname(vfsnames[vfstype], vfslist));
X}
X
Xchar **
Xmakevfslist(fslist)
X	char *fslist;
X{
X	register char **av;
X	int i;
X	register char *nextcp;
X
X	if (fslist == NULL)
X		return (NULL);
X	if (fslist[0] == 'n' && fslist[1] == 'o') {
X		fslist += 2;
X		skipvfs = 1;
X	}
X	for (i = 0, nextcp = fslist; *nextcp; nextcp++)
X		if (*nextcp == ',')
X			i++;
X	if ((av = (char **)malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
X		warn(NULL);
X		return (NULL);
X	}
X	nextcp = fslist;
X	i = 0;
X	av[i++] = nextcp;
X	while ((nextcp = strchr(nextcp, ',')) != NULL) {
X		*nextcp++ = '\0';
X		av[i++] = nextcp;
X	}
X	av[i++] = NULL;
X	return (av);
X}
X
Xchar *
Xcatopt(s0, s1)
X	char *s0;
X	char *s1;
X{
X	size_t i;
X	char *cp;
X
X	if (s0 && *s0) {
X		i = strlen(s0) + strlen(s1) + 1 + 1;
X		if ((cp = (char *)malloc(i)) == NULL)
X			err(1, NULL);
X		(void)sprintf(cp, "%s,%s", s0, s1);
X	} else
X		cp = strdup(s1);
X
X	if (s0)
X		free(s0);
X	return (cp);
X}
X
Xvoid
Xmangle(options, argcp, argv)
X	char *options;
X	int *argcp;
X	register char **argv;
X{
X	register char *p;
X	char *s;
X	register int argc;
X
X	argc = *argcp;
X	for (s = options; (p = strsep(&s, ",")) != NULL;)
X		if (*p != '\0')
X			if (*p == '-') {
X				argv[argc++] = p;
X				p = strchr(p, '=');
X				if (p) {
X					*p = '\0';
X					argv[argc++] = p+1;
X				}
X			} else {
X				argv[argc++] = "-o";
X				argv[argc++] = p;
X			}
X
X	*argcp = argc;
X}
X
Xvoid
Xusage()
X{
X
X	(void)fprintf(stderr,
X		"usage: mount %s %s\n       mount %s\n       mount %s\n",
X		"[-dfruvw] [-o options] [-t ufs | external_type]",
X			"special node",
X		"[-adfruvw] [-t ufs | external_type]",
X		"[-dfruvw] special | node");
X	exit(1);
X}
SHAR_EOF
chmod 644 'mount.c'
fi
if test -f 'mount_ufs.c'
then
	echo shar: "will not over-write existing file 'mount_ufs.c'"
else
sed 's/^X//' << \SHAR_EOF > 'mount_ufs.c'
X/*-
X * Copyright (c) 1993, 1994
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if	!defined(lint) && defined(DOSCCS)
Xstatic char copyright[] =
X"@(#) Copyright (c) 1993, 1994\n\
X	The Regents of the University of California.  All rights reserved.\n";
X
Xstatic char sccsid[] = "@(#)mount_ufs.c	8.2.1 (2.11BSD) 1996/1/16";
X#endif /* not lint */
X
X#include <sys/param.h>
X#include <sys/mount.h>
X
X#include <errno.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <unistd.h>
X
X#include "mntopts.h"
X
Xvoid	ufs_usage();
X
Xstatic struct mntopt mopts[] = {
X	MOPT_STDOPTS,
X#ifdef	notnow
X	MOPT_ASYNC,
X#endif
X	MOPT_SYNC,
X	MOPT_UPDATE,
X	{ NULL }
X};
X
Xint
Xmount_ufs(argc, argv)
X	int argc;
X	register char *argv[];
X{
X	extern int optreset;
X	int ch, mntflags;
X
X	mntflags = 0;
X	optind = optreset = 1;		/* Reset for parse of new argv. */
X	while ((ch = getopt(argc, argv, "o:")) != EOF)
X		switch (ch) {
X		case 'o':
X			getmntopts(optarg, mopts, &mntflags);
X			break;
X		case '?':
X		default:
X			ufs_usage();
X		}
X	argc -= optind;
X	argv += optind;
X
X	if (argc != 2)
X		ufs_usage();
X
X	if (mount(argv[0], argv[1], mntflags) < 0) {
X		(void)fprintf(stderr, "%s on %s: ", argv[0], argv[1]);
X		switch (errno) {
X		case EMFILE:
X			(void)fprintf(stderr, "mount table full.\n");
X			break;
X		case EINVAL:
X			if (mntflags & MNT_UPDATE)
X				(void)fprintf(stderr,
X		    "Specified device does not match mounted device.\n");
X			else 
X				(void)fprintf(stderr,
X				    "Incorrect super block.\n");
X			break;
X		default:
X			(void)fprintf(stderr, "%s\n", strerror(errno));
X			break;
X		}
X		fflush(stderr);
X		return (1);
X	}
X	return (0);
X}
X
Xvoid
Xufs_usage()
X{
X	(void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n");
X	exit(1);
X}
SHAR_EOF
chmod 644 'mount_ufs.c'
fi
if test -f 'pathnames.h'
then
	echo shar: "will not over-write existing file 'pathnames.h'"
else
sed 's/^X//' << \SHAR_EOF > 'pathnames.h'
X/*
X * Copyright (c) 1989, 1993, 1994
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *	@(#)pathnames.h	8.2.1 (2.11BSD) 1996/1/15
X */
X
X#define _PATH_ETC	"/etc"
X#define _PATH_BIN	"/bin"
SHAR_EOF
chmod 644 'pathnames.h'
fi
chmod 755 .
cd ..
if test ! -d '/usr/src/etc/umount'
then
	mkdir '/usr/src/etc/umount'
fi
cd '/usr/src/etc/umount'
if test -f 'umount.8'
then
	echo shar: "will not over-write existing file 'umount.8'"
else
sed 's/^X//' << \SHAR_EOF > 'umount.8'
X.\" Copyright (c) 1980, 1989, 1991, 1993
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 3. All advertising materials mentioning features or use of this software
X.\"    must display the following acknowledgement:
X.\"	This product includes software developed by the University of
X.\"	California, Berkeley and its contributors.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\"     @(#)umount.8	8.1.1 (2.11BSD) 1996/1/16
X.\"
X.TH UMOUNT 8 "January 16, 1996"
X.UC 7
X.SH NAME
X\fBumount\fP \- unmount file systems
X.SH SYNOPSIS
X.B umount
X[ \fB\-fv\fP ]
X\fIspecial\fP | \fInode\fP
X.br
X.B umount \-a
X[ \fB\-fv\fP ]
X[ \fB\-t\fP \fIufs\fP | \fIexternal_type\fP ]
X.SH DESCRIPTION
XThe
X.B umount
Xcommand
Xcalls the
Xumount(2)
Xsystem call to remove a
X.I "special device"
Xfrom the file system tree at the point
X.IR node .
XIf either
X.I special
Xor
X.I node
Xare not provided, the appropriate information is taken from the
Xfstab(5)
Xfile.
X.PP
XThe options are as follows:
X.sp
X.TP 10
X.B \-a
XAll of the file systems described in
Xfstab(5)
Xare unmounted.
X.TP 10
X.B \-f
XThe file system is forcibly unmounted.
XActive special devices continue to work,
Xbut all other files return errors if further accesses are attempted.
XThe root file system cannot be forcibly unmounted.
XThis is not currently implemented in 2.11BSD.
X.TP 10
X\fB\-t\fP \fIufs\fP | \fIexternal type\fP
XIs used to indicate the actions should only be taken on
Xfilesystems of the specified type.
XMore than one type may be specified in a comma separated list.
XThe list of filesystem types can be prefixed with
X.B no
Xto specify the filesystem types for which action should
X.B not
Xbe taken.
XFor example, the
X.B umount
Xcommand:
X.sp
Xumount -a -t nfs,mfs
X.sp
Xumounts all filesystems of the type
XNFS and MFS.
X.sp
X\fBNOTE\fP: Only UFS is supported by 2.11BSD.  The example is for illustrative
Xpurposes only.
X.TP 10
X.B \-v
XVerbose, additional information is printed out as each file system
Xis unmounted.
X.SH FILES
X.TP 15
X/etc/fstab
Xfile system table
X.SH SEE ALSO
Xumount(2),
Xfstab(5),
Xmount(8)
X.SH HISTORY
XA
X.B umount
Xcommand appeared in
XVersion 6 AT&T UNIX.
SHAR_EOF
chmod 644 'umount.8'
fi
if test -f 'umount.c'
then
	echo shar: "will not over-write existing file 'umount.c'"
else
sed 's/^X//' << \SHAR_EOF > 'umount.c'
X/*-
X * Copyright (c) 1980, 1989, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if	!defined(lint) && defined(DOSCCS)
Xstatic char copyright[] =
X"@(#) Copyright (c) 1980, 1989, 1993\n\
X	The Regents of the University of California.  All rights reserved.\n";
X
Xstatic char sccsid[] = "@(#)umount.c	8.3.1 (2.11BSD) 1996/1/16";
X#endif /* not lint */
X
X#include <sys/param.h>
X#include <sys/stat.h>
X#include <sys/mount.h>
X#include <fstab.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <unistd.h>
X
Xtypedef enum { MNTON, MNTFROM } mntwhat;
X
Xint	fake, fflag, vflag, *typelist;
Xchar	*nfshost;
X
Xint	 fsnametotype();
Xchar	*getmntname();
Xvoid	 maketypelist();
Xint	 selected();
Xint	 namematch();
Xint	 umountall();
Xint	 umountfs();
Xvoid	 usage();
X
Xint
Xmain(argc, argv)
X	int argc;
X	register char *argv[];
X{
X	int all, ch, errs;
X
X	/* Start disks transferring immediately. */
X	sync();
X
X	all = 0;
X	while ((ch = getopt(argc, argv, "aFft:v")) != EOF)
X		switch (ch) {
X		case 'a':
X			all = 1;
X			break;
X		case 'F':
X			fake = 1;
X			break;
X		case 'f':
X#ifdef	notnow
X			fflag = MNT_FORCE;
X#endif
X			break;
X		case 't':
X			maketypelist(optarg);
X			break;
X		case 'v':
X			vflag = 1;
X			break;
X		default:
X			usage();
X			/* NOTREACHED */
X		}
X	argc -= optind;
X	argv += optind;
X
X	if (argc == 0 && !all || argc != 0 && all)
X		usage();
X
X	if (all) {
X		if (setfsent() == 0)
X			err(1, "%s", _PATH_FSTAB);
X		errs = umountall();
X	} else
X		for (errs = 0; *argv != NULL; ++argv)
X			if (umountfs(*argv) == 0)
X				errs = 1;
X	exit(errs);
X}
X
Xint
Xumountall()
X{
X	register struct fstab *fs;
X	int rval, type;
X	register char *cp;
X
X	while ((fs = getfsent()) != NULL) {
X		/* Ignore the root. */
X		if (strcmp(fs->fs_file, "/") == 0)
X			continue;
X		/*
X		 * !!!
X		 * Historic practice: ignore unknown FSTAB_* fields.
X		 */
X		if (strcmp(fs->fs_type, FSTAB_RW) &&
X		    strcmp(fs->fs_type, FSTAB_RO) &&
X		    strcmp(fs->fs_type, FSTAB_RQ))
X			continue;
X		/* If an unknown file system type, complain. */
X		if ((type = fsnametotype(fs->fs_vfstype)) == MOUNT_NONE) {
X			warnx("%s: unknown mount type", fs->fs_vfstype);
X			continue;
X		}
X		if (!selected(type))
X			continue;
X
X		/* 
X		 * We want to unmount the file systems in the reverse order
X		 * that they were mounted.  So, we save off the file name
X		 * in some allocated memory, and then call recursively.
X		 */
X		cp = (char *)malloc((size_t)strlen(fs->fs_file) + 1);
X		if (cp == NULL)
X			err(1, NULL);
X		(void)strcpy(cp, fs->fs_file);
X		rval = umountall();
X		return (umountfs(cp) || rval);
X	}
X	return (0);
X}
X
Xint
Xumountfs(name)
X	char *name;
X{
X	struct stat sb;
X	int type;
X	register char *mntpt;
X
X	if (stat(name, &sb) < 0) {
X		if (((mntpt = getmntname(name, MNTFROM, &type)) == NULL) &&
X		    ((mntpt = getmntname(name, MNTON, &type)) == NULL)) {
X			warnx("%s: not currently mounted", name);
X			return (1);
X		}
X	} else if ((sb.st_mode & S_IFMT) == S_IFBLK) {
X		if ((mntpt = getmntname(name, MNTON, &type)) == NULL) {
X			warnx("%s: not currently mounted", name);
X			return (1);
X		}
X	} else if ((sb.st_mode & S_IFMT) == S_IFDIR) {
X		mntpt = name;
X		if ((name = getmntname(mntpt, MNTFROM, &type)) == NULL) {
X			warnx("%s: not currently mounted", mntpt);
X			return (1);
X		}
X	} else {
X		warnx("%s: not a directory or special device", name);
X		return (1);
X	}
X
X	if (!selected(type))
X		return (0);
X
X	if (vflag)
X		(void)printf("%s: unmount from %s\n", name, mntpt);
X	if (fake)
X		return (0);
X
X	if (umount(name) < 0) {
X		warn("%s on %s", name, mntpt);
X		return (1);
X	}
X
X	return (0);
X}
X
Xchar *
Xgetmntname(name, what, type)
X	char *name;
X	mntwhat what;
X	int *type;
X{
X	struct statfs *mntbuf;
X	register int i, mntsize;
X
X	if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
X		warn("getmntinfo");
X		return (NULL);
X	}
X	for (i = 0; i < mntsize; i++) {
X		if ((what == MNTON) && !strcmp(mntbuf[i].f_mntfromname, name)) {
X			if (type)
X				*type = mntbuf[i].f_type;
X			return (mntbuf[i].f_mntonname);
X		}
X		if ((what == MNTFROM) && !strcmp(mntbuf[i].f_mntonname, name)) {
X			if (type)
X				*type = mntbuf[i].f_type;
X			return (mntbuf[i].f_mntfromname);
X		}
X	}
X	return (NULL);
X}
X
Xstatic enum { IN_LIST, NOT_IN_LIST } which;
X
Xint
Xselected(type)
X	int type;
X{
X	/* If no type specified, it's always selected. */
X	if (typelist == NULL)
X		return (1);
X	for (; *typelist != MOUNT_NONE; ++typelist)
X		if (type == *typelist)
X			return (which == IN_LIST ? 1 : 0);
X	return (which == IN_LIST ? 0 : 1);
X}
X
Xvoid
Xmaketypelist(fslist)
X	register char *fslist;
X{
X	register int *av, i;
X	char *nextcp;
X
X	if ((fslist == NULL) || (fslist[0] == '\0'))
X		errx(1, "empty type list");
X
X	/*
X	 * XXX
X	 * Note: the syntax is "noxxx,yyy" for no xxx's and
X	 * no yyy's, not the more intuitive "noyyy,noyyy".
X	 */
X	if (fslist[0] == 'n' && fslist[1] == 'o') {
X		fslist += 2;
X		which = NOT_IN_LIST;
X	} else
X		which = IN_LIST;
X
X	/* Count the number of types. */
X	for (i = 0, nextcp = fslist; *nextcp != NULL; ++nextcp)
X		if (*nextcp == ',')
X			i++;
X
X	/* Build an array of that many types. */
X	if ((av = typelist = (int *)malloc((i + 2) * sizeof(int))) == NULL)
X		err(1, NULL);
X	for (i = 0; fslist != NULL; fslist = nextcp, ++i) {
X		if ((nextcp = strchr(fslist, ',')) != NULL)
X			*nextcp++ = '\0';
X		av[i] = fsnametotype(fslist);
X		if (av[i] == MOUNT_NONE)
X			errx(1, "%s: unknown mount type", fslist);
X	}
X	/* Terminate the array. */
X	av[i++] = MOUNT_NONE;
X}
X
Xint
Xfsnametotype(name)
X	char *name;
X{
X	static char *namelist[] = INITMOUNTNAMES;
X	register char **cp;
X
X	for (cp = namelist; *cp; ++cp)
X		if (strcmp(name, *cp) == 0)
X			return (cp - namelist);
X	return (MOUNT_NONE);
X}
X
Xvoid
Xusage()
X{
X	(void)fprintf(stderr,
X	    "usage: %s\n       %s\n",
X	    "umount [-fv] [-t fstypelist] special | node",
X	    "umount -a[fv] [-t fstypelist]");
X	exit(1);
X}
SHAR_EOF
chmod 644 'umount.c'
fi
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X#
X# Public Domain.  1996/1/15 - Steven Schultz
X#
X#	@(#)Makefile	1.0 (2.11BSD GTE) 1996/1/15
X#
XCFLAGS=	 -O
XSEPFLAG= -i
XSRCS=	umount.c
XOBJS=	umount.o
XMAN=	umount.0
XMANSRC=	umount.8
X
Xall: umount umount.0
X
Xumount: ${OBJS}
X	${CC} ${CFLAGS} ${SEPFLAG} -o $@ ${OBJS}
X
Xumount.0: ${MANSRC}
X	/usr/man/manroff ${MANSRC} > ${MAN}
X
Xclean:
X	rm -f ${OBJS} ${MAN} umount tags 
X
Xdepend: ${SRCS}
X	mkdep ${CFLAGS} ${SRCS}
X
Xinstall: all
X	install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat8
X	install -s -o root -g bin -m 755 umount ${DESTDIR}/etc/umount
X
Xlint: ${SRCS}
X	lint -hax ${SRCS}
X
Xtags: ${SRCS}
X	ctags ${SRCS}
X# DO NOT DELETE THIS LINE -- mkdep uses it.
X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
SHAR_EOF
chmod 644 'Makefile'
fi
chmod 755 .
cd ..
if test ! -d '/usr/src/lib/libc/stdlib'
then
	mkdir '/usr/src/lib/libc/stdlib'
fi
cd '/usr/src/lib/libc/stdlib'
if test -f 'getopt.c'
then
	echo shar: "will not over-write existing file 'getopt.c'"
else
sed 's/^X//' << \SHAR_EOF > 'getopt.c'
X/*
X * Copyright (c) 1987, 1993, 1994
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if defined(LIBC_SCCS) && !defined(lint)
Xstatic char sccsid[] = "@(#)getopt.c	8.2.1 (2.11BSD) 1996/1/11";
X#endif /* LIBC_SCCS and not lint */
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X
Xint	opterr = 1,		/* if error message should be printed */
X	optind = 1,		/* index into parent argv vector */
X	optopt,			/* character checked for validity */
X	optreset;		/* reset getopt */
Xchar	*optarg;		/* argument associated with option */
X
X#define	BADCH	(int)'?'
X#define	BADARG	(int)':'
X#define	EMSG	""
X
X/*
X * getopt --
X *	Parse argc/argv argument vector.
X */
Xint
Xgetopt(nargc, nargv, ostr)
X	int nargc;
X	char **nargv;
X	char *ostr;
X{
X	extern char *__progname;
X	static char *place = EMSG;		/* option letter processing */
X	char *oli;				/* option letter list index */
X
X	if (optreset || !*place) {		/* update scanning pointer */
X		optreset = 0;
X		if (optind >= nargc || *(place = nargv[optind]) != '-') {
X			place = EMSG;
X			return (EOF);
X		}
X		if (place[1] && *++place == '-') {	/* found "--" */
X			++optind;
X			place = EMSG;
X			return (EOF);
X		}
X	}					/* option letter okay? */
X	if ((optopt = (int)*place++) == (int)':' ||
X	    !(oli = strchr(ostr, optopt))) {
X		/*
X		 * if the user didn't specify '-' as an option,
X		 * assume it means EOF.
X		 */
X		if (optopt == (int)'-')
X			return (EOF);
X		if (!*place)
X			++optind;
X		if (opterr && *ostr != ':')
X			(void)fprintf(stderr,
X			    "%s: illegal option -- %c\n", __progname, optopt);
X		return (BADCH);
X	}
X	if (*++oli != ':') {			/* don't need argument */
X		optarg = NULL;
X		if (!*place)
X			++optind;
X	}
X	else {					/* need an argument */
X		if (*place)			/* no white space */
X			optarg = place;
X		else if (nargc <= ++optind) {	/* no arg */
X			place = EMSG;
X			if (*ostr == ':')
X				return (BADARG);
X			if (opterr)
X				(void)fprintf(stderr,
X				    "%s: option requires an argument -- %c\n",
X				    __progname, optopt);
X			return (BADCH);
X		}
X	 	else				/* white space */
X			optarg = nargv[optind];
X		place = EMSG;
X		++optind;
X	}
X	return (optopt);			/* dump back option letter */
X}
SHAR_EOF
chmod 644 'getopt.c'
fi
if test -f 'getsubopt.c'
then
	echo shar: "will not over-write existing file 'getsubopt.c'"
else
sed 's/^X//' << \SHAR_EOF > 'getsubopt.c'
X/*-
X * Copyright (c) 1990, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if	defined(DOSCCS) && !defined(lint)
Xstatic char sccsid[] = "@(#)getsubopt.c	8.1.1 (2.11BSD) 1996/1/11";
X#endif /* not lint */
X
X#include <stdlib.h>
X
X/*
X * The SVID interface to getsubopt provides no way of figuring out which
X * part of the suboptions list wasn't matched.  This makes error messages
X * tricky...  The extern variable suboptarg is a pointer to the token
X * which didn't match.
X */
Xchar *suboptarg;
X
Xgetsubopt(optionp, tokens, valuep)
X	register char **optionp, **valuep;
X	register char **tokens;
X{
X	register int cnt;
X	register char *p;
X
X	suboptarg = *valuep = NULL;
X
X	if (!optionp || !*optionp)
X		return(-1);
X
X	/* skip leading white-space, commas */
X	for (p = *optionp; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
X
X	if (!*p) {
X		*optionp = p;
X		return(-1);
X	}
X
X	/* save the start of the token, and skip the rest of the token. */
X	for (suboptarg = p;
X	    *++p && *p != ',' && *p != '=' && *p != ' ' && *p != '\t';);
X
X	if (*p) {
X		/*
X		 * If there's an equals sign, set the value pointer, and
X		 * skip over the value part of the token.  Terminate the
X		 * token.
X		 */
X		if (*p == '=') {
X			*p = '\0';
X			for (*valuep = ++p;
X			    *p && *p != ',' && *p != ' ' && *p != '\t'; ++p);
X			if (*p) 
X				*p++ = '\0';
X		} else
X			*p++ = '\0';
X		/* Skip any whitespace or commas after this token. */
X		for (; *p && (*p == ',' || *p == ' ' || *p == '\t'); ++p);
X	}
X
X	/* set optionp for next round. */
X	*optionp = p;
X
X	for (cnt = 0; *tokens; ++tokens, ++cnt)
X		if (!strcmp(suboptarg, *tokens))
X			return(cnt);
X	return(-1);
X}
SHAR_EOF
chmod 644 'getsubopt.c'
fi
if test -f 'strtol.c'
then
	echo shar: "will not over-write existing file 'strtol.c'"
else
sed 's/^X//' << \SHAR_EOF > 'strtol.c'
X/*-
X * Copyright (c) 1990, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if defined(LIBC_SCCS) && !defined(lint)
Xstatic char sccsid[] = "@(#)strtol.c	8.1.1 (2.11BSD) 1996/1/11";
X#endif /* LIBC_SCCS and not lint */
X
X#include <limits.h>
X#include <ctype.h>
X#include <errno.h>
X#include <stdlib.h>
X
X
X/*
X * Convert a string to a long integer.
X *
X * Ignores `locale' stuff.  Assumes that the upper and lower case
X * alphabets and digits are each contiguous.
X */
Xlong
Xstrtol(nptr, endptr, base)
X	char *nptr;
X	char **endptr;
X	register int base;
X{
X	register char *s = nptr;
X	register unsigned long acc;
X	register int c;
X	register unsigned long cutoff;
X	register int neg = 0, any, cutlim;
X
X	/*
X	 * Skip white space and pick up leading +/- sign if any.
X	 * If base is 0, allow 0x for hex and 0 for octal, else
X	 * assume decimal; if base is already 16, allow 0x.
X	 */
X	do {
X		c = *s++;
X	} while (isspace(c));
X	if (c == '-') {
X		neg = 1;
X		c = *s++;
X	} else if (c == '+')
X		c = *s++;
X	if ((base == 0 || base == 16) &&
X	    c == '0' && (*s == 'x' || *s == 'X')) {
X		c = s[1];
X		s += 2;
X		base = 16;
X	}
X	if (base == 0)
X		base = c == '0' ? 8 : 10;
X
X	/*
X	 * Compute the cutoff value between legal numbers and illegal
X	 * numbers.  That is the largest legal value, divided by the
X	 * base.  An input number that is greater than this value, if
X	 * followed by a legal input character, is too big.  One that
X	 * is equal to this value may be valid or not; the limit
X	 * between valid and invalid numbers is then based on the last
X	 * digit.  For instance, if the range for longs is
X	 * [-2147483648..2147483647] and the input base is 10,
X	 * cutoff will be set to 214748364 and cutlim to either
X	 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
X	 * a value > 214748364, or equal but the next digit is > 7 (or 8),
X	 * the number is too big, and we will return a range error.
X	 *
X	 * Set any if any `digits' consumed; make it negative to indicate
X	 * overflow.
X	 */
X	cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
X	cutlim = cutoff % (unsigned long)base;
X	cutoff /= (unsigned long)base;
X	for (acc = 0, any = 0;; c = *s++) {
X		if (isdigit(c))
X			c -= '0';
X		else if (isalpha(c))
X			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
X		else
X			break;
X		if (c >= base)
X			break;
X		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
X			any = -1;
X		else {
X			any = 1;
X			acc *= base;
X			acc += c;
X		}
X	}
X	if (any < 0) {
X		acc = neg ? LONG_MIN : LONG_MAX;
X		errno = ERANGE;
X	} else if (neg)
X		acc = -acc;
X	if (endptr != 0)
X		*endptr = (char *)(any ? s - 1 : nptr);
X	return (acc);
X}
SHAR_EOF
chmod 644 'strtol.c'
fi
if test -f 'strtoul.c'
then
	echo shar: "will not over-write existing file 'strtoul.c'"
else
sed 's/^X//' << \SHAR_EOF > 'strtoul.c'
X/*
X * Copyright (c) 1990, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if defined(LIBC_SCCS) && !defined(lint)
Xstatic char sccsid[] = "@(#)strtoul.c	8.1.1 (2.11BSD) 1996/1/11";
X#endif /* LIBC_SCCS and not lint */
X
X#include <limits.h>
X#include <ctype.h>
X#include <errno.h>
X#include <stdlib.h>
X
X/*
X * Convert a string to an unsigned long integer.
X *
X * Ignores `locale' stuff.  Assumes that the upper and lower case
X * alphabets and digits are each contiguous.
X */
Xunsigned long
Xstrtoul(nptr, endptr, base)
X	char *nptr;
X	char **endptr;
X	register int base;
X{
X	register char *s = nptr;
X	register unsigned long acc;
X	register int c;
X	register unsigned long cutoff;
X	register int neg = 0, any, cutlim;
X
X	/*
X	 * See strtol for comments as to the logic used.
X	 */
X	do {
X		c = *s++;
X	} while (isspace(c));
X	if (c == '-') {
X		neg = 1;
X		c = *s++;
X	} else if (c == '+')
X		c = *s++;
X	if ((base == 0 || base == 16) &&
X	    c == '0' && (*s == 'x' || *s == 'X')) {
X		c = s[1];
X		s += 2;
X		base = 16;
X	}
X	if (base == 0)
X		base = c == '0' ? 8 : 10;
X	cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
X	cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
X	for (acc = 0, any = 0;; c = *s++) {
X		if (isdigit(c))
X			c -= '0';
X		else if (isalpha(c))
X			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
X		else
X			break;
X		if (c >= base)
X			break;
X		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
X			any = -1;
X		else {
X			any = 1;
X			acc *= base;
X			acc += c;
X		}
X	}
X	if (any < 0) {
X		acc = ULONG_MAX;
X		errno = ERANGE;
X	} else if (neg)
X		acc = -acc;
X	if (endptr != 0)
X		*endptr = (char *)(any ? s - 1 : nptr);
X	return (acc);
X}
SHAR_EOF
chmod 644 'strtoul.c'
fi
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^X//' << \SHAR_EOF > 'Makefile'
X#
X#	@(#)Makefile	1.0 (2.11BSD GTE) 1995/1/12
X#
X# This is the Makefile for 'stdlib'.  New routines ported from 4.4BSD's
X# libc/stdlib directory go here but existing libc/gen files are being left
X# where they are.
X#
X
XDEFS=
XCFLAGS=	 -O ${DEFS}
XCC=	cc
X
XSRCS=	getopt.c getsubopt.c strtol.c strtoul.c
XOBJS=	getopt.o getsubopt.o strtol.o strtoul.o
X
X.c.o:
X	${CC} -p ${CFLAGS} -c $*.c
X	ld -X -r $*.o
X	mv a.out profiled/$*.o
X	${CC} ${CFLAGS} -c $*.c
X	ld -X -r $*.o
X	mv a.out $*.o
X
Xall: stdliblib stdliblib_p
X
Xstdliblib stdliblib_p: ${OBJS}
X	@echo "building profiled stdlib"
X	@cd profiled; ar cru ../stdliblib_p ${OBJS}
X	@echo "building normal stdlib"
X	@ar cru stdliblib ${OBJS}
X
Xclean:
X	rm -f ${OBJS} profiled/*.o tags Makefile.bak stdliblib stdliblib_p
X
Xdepend: ${SRCS}
X	mkdep ${CFLAGS} ${SRCS}
X
Xtags:
X	cwd=`pwd`; \
X	for i in ${SRCS}; do \
X		ctags -a -f ${TAGSFILE} $$cwd/$$i; \
X	done
X
X# DO NOT DELETE THIS LINE -- mkdep uses it.
X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
SHAR_EOF
chmod 640 'Makefile'
fi
if test ! -d 'profiled'
then
	mkdir 'profiled'
fi
cd 'profiled'
chmod 755 .
cd ..
chmod 755 .
cd ..
if test -f '/usr/src/lib/libc/gen/fstab.c'
then
	echo shar: "will not over-write existing file '/usr/src/lib/libc/gen/fstab.c'"
else
sed 's/^X//' << \SHAR_EOF > '/usr/src/lib/libc/gen/fstab.c'
X/*
X * Copyright (c) 1980, 1988, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#if defined(LIBC_SCCS) && !defined(lint)
Xstatic char sccsid[] = "@(#)fstab.c	8.1.1 (2.11BSD) 1996/1/15";
X#endif /* LIBC_SCCS and not lint */
X
X#include <errno.h>
X#include <fstab.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <unistd.h>
X#include <sys/uio.h>
X
Xextern	char	*__progname;
Xstatic FILE *_fs_fp;
Xstatic struct fstab _fs_fstab;
X
Xstatic void error();
Xstatic int fstabscan();
X
Xstatic int
Xfstabscan()
X{
X	char *cp;
X	register char *bp;
X#define	MAXLINELENGTH	256
X	static char line[MAXLINELENGTH];
X	char subline[MAXLINELENGTH], *colon = ":";
X	int typexx;
X
X	for (;;) {
X		if (!fgets(line, sizeof(line), _fs_fp))
X			return(0);
X		bp = index(line, '\n');
X		if (!bp)
X			return(0);
X		*bp = '\0';
X		cp = line;
X/* OLD_STYLE_FSTAB */
X		if (!strpbrk(cp, " \t")) {
X			_fs_fstab.fs_spec = strsep(&cp, colon);
X			_fs_fstab.fs_file = strsep(&cp, colon);
X			_fs_fstab.fs_type = strsep(&cp, colon);
X			if (_fs_fstab.fs_type) {
X				if (!strcmp(_fs_fstab.fs_type, FSTAB_XX))
X					continue;
X				_fs_fstab.fs_mntops = _fs_fstab.fs_type;
X				_fs_fstab.fs_vfstype =
X				    strcmp(_fs_fstab.fs_type, FSTAB_SW) ?
X				    "ufs" : "swap";
X				if (bp = strsep(&cp, colon)) {
X					_fs_fstab.fs_freq = atoi(bp);
X					if (bp = strsep(&cp, colon)) {
X						_fs_fstab.fs_passno = atoi(bp);
X						return(1);
X					}
X				}
X			}
X			goto bad;
X		}
X/* OLD_STYLE_FSTAB */
X		_fs_fstab.fs_spec = strtok(cp, " \t");
X		if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
X			continue;
X		_fs_fstab.fs_file = strtok((char *)NULL, " \t");
X		_fs_fstab.fs_vfstype = strtok((char *)NULL, " \t");
X		_fs_fstab.fs_mntops = strtok((char *)NULL, " \t");
X		if (_fs_fstab.fs_mntops == NULL)
X			goto bad;
X		_fs_fstab.fs_freq = 0;
X		_fs_fstab.fs_passno = 0;
X		if ((cp = strtok((char *)NULL, " \t")) != NULL) {
X			_fs_fstab.fs_freq = atoi(cp);
X			if ((cp = strtok((char *)NULL, " \t")) != NULL)
X				_fs_fstab.fs_passno = atoi(cp);
X		}
X		strcpy(subline, _fs_fstab.fs_mntops);
X		for (typexx = 0, cp = strtok(subline, ","); cp;
X		     cp = strtok((char *)NULL, ",")) {
X			if (strlen(cp) != 2)
X				continue;
X			if (!strcmp(cp, FSTAB_RW)) {
X				_fs_fstab.fs_type = FSTAB_RW;
X				break;
X			}
X			if (!strcmp(cp, FSTAB_RQ)) {
X				_fs_fstab.fs_type = FSTAB_RQ;
X				break;
X			}
X			if (!strcmp(cp, FSTAB_RO)) {
X				_fs_fstab.fs_type = FSTAB_RO;
X				break;
X			}
X			if (!strcmp(cp, FSTAB_SW)) {
X				_fs_fstab.fs_type = FSTAB_SW;
X				break;
X			}
X			if (!strcmp(cp, FSTAB_XX)) {
X				_fs_fstab.fs_type = FSTAB_XX;
X				typexx++;
X				break;
X			}
X		}
X		if (typexx)
X			continue;
X		if (cp != NULL)
X			return(1);
X
Xbad:		/* no way to distinguish between EOF and syntax error */
X		error(EFTYPE);
X	}
X	/* NOTREACHED */
X}
X
Xstruct fstab *
Xgetfsent()
X{
X	if (!_fs_fp && !setfsent() || !fstabscan())
X		return((struct fstab *)NULL);
X	return(&_fs_fstab);
X}
X
Xstruct fstab *
Xgetfsspec(name)
X	register char *name;
X{
X	if (setfsent())
X		while (fstabscan())
X			if (!strcmp(_fs_fstab.fs_spec, name))
X				return(&_fs_fstab);
X	return((struct fstab *)NULL);
X}
X
Xstruct fstab *
Xgetfsfile(name)
X	register char *name;
X{
X	if (setfsent())
X		while (fstabscan())
X			if (!strcmp(_fs_fstab.fs_file, name))
X				return(&_fs_fstab);
X	return((struct fstab *)NULL);
X}
X
Xsetfsent()
X{
X	if (_fs_fp) {
X		rewind(_fs_fp);
X		return(1);
X	}
X	if (_fs_fp = fopen(_PATH_FSTAB, "r"))
X		return(1);
X	error(errno);
X	return(0);
X}
X
Xvoid
Xendfsent()
X{
X	if (_fs_fp) {
X		(void)fclose(_fs_fp);
X		_fs_fp = NULL;
X	}
X}
X
Xstatic void
Xerror(err)
X	int err;
X{
X	register int saverrno;
X
X	saverrno = errno;
X	errno = err;
X	warn("%s", _PATH_FSTAB);
X	errno = saverrno;
X}
SHAR_EOF
chmod 444 '/usr/src/lib/libc/gen/fstab.c'
fi
exit 0
#	End of shell archive