From: deraadt Date: Sun, 21 Apr 1996 23:38:17 +0000 (+0000) Subject: sync to netbsd 960418 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f3bae140e877f130f33051ddb228cb34a056c92b;p=openbsd sync to netbsd 960418 --- diff --git a/include/protocols/timed.h b/include/protocols/timed.h index 427adffe4cf..a8930f5343b 100644 --- a/include/protocols/timed.h +++ b/include/protocols/timed.h @@ -1,4 +1,5 @@ -/* $NetBSD: timed.h,v 1.3 1994/10/26 00:56:53 cgd Exp $ */ +/* $OpenBSD: timed.h,v 1.2 1996/04/21 23:38:17 deraadt Exp $ */ +/* $NetBSD: timed.h,v 1.5 1996/04/09 20:40:32 cgd Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -46,11 +47,14 @@ #define ANYADDR NULL struct tsp { - u_char tsp_type; - u_char tsp_vers; - u_short tsp_seq; + u_int8_t tsp_type; + u_int8_t tsp_vers; + u_int16_t tsp_seq; union { - struct timeval tspu_time; + struct { + int32_t tv_sec; + int32_t tv_usec; + } tspu_time; char tspu_hopcnt; } tsp_u; char tsp_name[MAXHOSTNAMELEN]; diff --git a/lib/libarch/alpha/Makefile b/lib/libarch/alpha/Makefile deleted file mode 100644 index d2822fd6bfd..00000000000 --- a/lib/libarch/alpha/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile,v 1.1 1996/03/19 23:14:54 niklas Exp $ -# $NetBSD: Makefile,v 1.1 1996/02/21 02:45:40 jtk Exp $ - -#.PATH: ${LIBC}/i386 - -SRCS+= alpha_mmclock_gettime.c alpha_mmclock_init.c gettimeofday.c - -.include diff --git a/lib/libarch/alpha/alpha_mmclock_gettime.c b/lib/libarch/alpha/alpha_mmclock_gettime.c deleted file mode 100644 index ca56c77bfcf..00000000000 --- a/lib/libarch/alpha/alpha_mmclock_gettime.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $NetBSD: alpha_mmclock_gettime.c,v 1.1 1995/12/20 12:54:24 cgd Exp $ */ - -/* - * Copyright (c) 1995 Carnegie-Mellon University. - * All rights reserved. - * - * Author: Chris G. Demetriou - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -#include -#include -#include -#include -#include - -#include "libalpha.h" - -void -alpha_mmclock_gettime(tdp) - struct alpha_timedata *tdp; -{ - u_long npcc, pccdiff; - - do { - tdp->td_tv.tv_usec = alpha_mmclockdata->td_tv.tv_usec; - tdp->td_tv.tv_sec = alpha_mmclockdata->td_tv.tv_sec; - tdp->td_cc = alpha_mmclockdata->td_cc; - } while (tdp->td_tv.tv_usec != alpha_mmclockdata->td_tv.tv_usec || - tdp->td_tv.tv_sec != alpha_mmclockdata->td_tv.tv_sec); - - npcc = rpcc() & 0x00000000ffffffffUL; - if (npcc < tdp->td_cc) - npcc += 0x0000000100000000UL; - tdp->td_cc = npcc - tdp->td_cc; -} diff --git a/lib/libarch/alpha/alpha_mmclock_init.c b/lib/libarch/alpha/alpha_mmclock_init.c deleted file mode 100644 index 5a83f2750ce..00000000000 --- a/lib/libarch/alpha/alpha_mmclock_init.c +++ /dev/null @@ -1,68 +0,0 @@ -/* $NetBSD: alpha_mmclock_init.c,v 1.1 1995/12/20 12:55:21 cgd Exp $ */ - -/* - * Copyright (c) 1995 Carnegie-Mellon University. - * All rights reserved. - * - * Author: Chris G. Demetriou - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -#include -#include -#include -#include - -#include "libalpha.h" - -volatile struct alpha_timedata *alpha_mmclockdata; -u_long alpha_cycles_per_second; - -int __alpha_mmclock_init_failed; - -volatile struct alpha_timedata * -alpha_mmclock_init() -{ - int fd; - - if (alpha_mmclockdata != NULL) - return (alpha_mmclockdata); - - fd = open("/dev/mmclock", O_RDONLY, 0); - if (fd == -1) - goto fail; - - alpha_mmclockdata = (struct alpha_timedata *) - mmap(NULL, getpagesize(), PROT_READ, MAP_FILE, fd, 0); - close(fd); - if (alpha_mmclockdata == NULL) - goto fail; - - alpha_cycles_per_second = alpha_mmclockdata->td_cpc; - - __alpha_mmclock_init_failed = 0; - return (alpha_mmclockdata); - -fail: - __alpha_mmclock_init_failed = 1; - return (NULL); -} diff --git a/lib/libarch/alpha/gettimeofday.c b/lib/libarch/alpha/gettimeofday.c deleted file mode 100644 index 6ef009b37b4..00000000000 --- a/lib/libarch/alpha/gettimeofday.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $NetBSD: gettimeofday.c,v 1.1 1995/12/20 12:56:06 cgd Exp $ */ - -/* - * Copyright (c) 1995 Carnegie-Mellon University. - * All rights reserved. - * - * Author: Chris G. Demetriou - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -#include -#include -#include -#include -#include - -#include "libalpha.h" - -int -gettimeofday(tvp, tzp) - struct timeval *tvp; - struct timezone *tzp; -{ - u_long opcc, npcc, pccdiff; - static struct timeval lasttime; - - if (tzp == NULL && alpha_mmclockdata == NULL && - !__alpha_mmclock_init_failed) - alpha_mmclockdata = alpha_mmclock_init(); - if (tzp != NULL || alpha_mmclockdata == NULL) - return (syscall(SYS_gettimeofday, tvp, tzp)); - - if (tvp == NULL) - return 0; - - do { - tvp->tv_usec = alpha_mmclockdata->td_tv.tv_usec; - tvp->tv_sec = alpha_mmclockdata->td_tv.tv_sec; - opcc = alpha_mmclockdata->td_cc; - } while (tvp->tv_usec != alpha_mmclockdata->td_tv.tv_usec || - tvp->tv_sec != alpha_mmclockdata->td_tv.tv_sec); - - npcc = rpcc() & 0x00000000ffffffffUL; - if (npcc < opcc) - npcc += 0x0000000100000000UL; - pccdiff = npcc - opcc; - - tvp->tv_usec += (pccdiff * 1000000) / alpha_cycles_per_second; - if (tvp->tv_usec > 1000000) { - tvp->tv_sec++; - tvp->tv_usec -= 1000000; - } - - if ((tvp->tv_sec == lasttime.tv_sec && - tvp->tv_usec <= lasttime.tv_usec) && - (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) { - tvp->tv_sec++; - tvp->tv_usec -= 1000000; - } - - lasttime = *tvp; - return 0; -} diff --git a/lib/libarch/alpha/libalpha.h b/lib/libarch/alpha/libalpha.h deleted file mode 100644 index 358f2ec3cbe..00000000000 --- a/lib/libarch/alpha/libalpha.h +++ /dev/null @@ -1,30 +0,0 @@ -/* $NetBSD: libalpha.h,v 1.1 1995/12/20 12:56:44 cgd Exp $ */ - -/* - * Copyright (c) 1995 Carnegie-Mellon University. - * All rights reserved. - * - * Author: Chris G. Demetriou - * - * Permission to use, copy, modify and distribute this software and - * its documentation is hereby granted, provided that both the copyright - * notice and this permission notice appear in all copies of the - * software, derivative works or modified versions, and any portions - * thereof, and that both notices appear in supporting documentation. - * - * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" - * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND - * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * - * Carnegie Mellon requests users of this software to return to - * - * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU - * School of Computer Science - * Carnegie Mellon University - * Pittsburgh PA 15213-3890 - * - * any improvements or extensions that they make and grant Carnegie the - * rights to redistribute these changes. - */ - -extern int __alpha_mmclock_init_failed; diff --git a/lib/libc/arch/ns32k/gen/Makefile.inc b/lib/libc/arch/ns32k/gen/Makefile.inc index ed6ccce6f18..01633096cf5 100644 --- a/lib/libc/arch/ns32k/gen/Makefile.inc +++ b/lib/libc/arch/ns32k/gen/Makefile.inc @@ -1,5 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.4 1995/05/03 03:25:11 phil Exp $ +# $OpenBSD: Makefile.inc,v 1.2 1996/04/21 23:38:37 deraadt Exp $ +# $NetBSD: Makefile.inc,v 1.5 1996/04/05 00:23:05 phil Exp $ SRCS+= __main.c _setjmp.S alloca.S fabs.S frexp.S infinity.c isinf.c SRCS+= ldexp.S modf.S setjmp.S sigsetjmp.S -SRCS+= flt_rounds.c fpgetround.c fpsetround.c +SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \ + fpsetround.c fpsetsticky.c diff --git a/lib/libc/arch/ns32k/gen/fpgetmask.c b/lib/libc/arch/ns32k/gen/fpgetmask.c new file mode 100644 index 00000000000..64b26fe3977 --- /dev/null +++ b/lib/libc/arch/ns32k/gen/fpgetmask.c @@ -0,0 +1,21 @@ +/* $OpenBSD: fpgetmask.c,v 1.1 1996/04/21 23:38:40 deraadt Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include +#include +#include + +fp_except +fpgetmask() +{ + fp_except x; + fp_except ebits = FPC_IEN | FPC_OVE | FPC_IVE | FPC_DZE | FPC_UNDE; + + sfsr(x); + + return x & ebits; +} diff --git a/lib/libc/arch/ns32k/gen/fpgetsticky.c b/lib/libc/arch/ns32k/gen/fpgetsticky.c new file mode 100644 index 00000000000..86771541ab6 --- /dev/null +++ b/lib/libc/arch/ns32k/gen/fpgetsticky.c @@ -0,0 +1,27 @@ +/* $OpenBSD: fpgetsticky.c,v 1.1 1996/04/21 23:38:41 deraadt Exp $ */ + +/* + * Written by J.T. Conklin, Apr 11, 1995 + * Public domain. + */ + +#include +#include +#include + +fp_except +fpgetsticky() +{ + fp_except x; + fp_except ebits = FPC_IEN | FPC_OVE | FPC_IVE | FPC_DZE | FPC_UNDE; + + sfsr(x); + /* Map FPC_UF to soft underflow enable */ + if (x & FPC_UF) + x |= FPC_UNDE << 1; + else + x &= ~(FPC_UNDE << 1); + x >>= 1; + + return x & ebits; +} diff --git a/lib/libc/arch/ns32k/gen/fpsetmask.c b/lib/libc/arch/ns32k/gen/fpsetmask.c new file mode 100644 index 00000000000..34c4034c10d --- /dev/null +++ b/lib/libc/arch/ns32k/gen/fpsetmask.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpsetmask.c,v 1.1 1996/04/21 23:38:44 deraadt Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include +#include +#include + +fp_except +fpsetmask(mask) + fp_except mask; +{ + fp_except old; + fp_except new; + fp_except ebits = FPC_IEN | FPC_OVE | FPC_IVE | FPC_DZE | FPC_UNDE; + + sfsr(old); + + new = old; + new &= ~ebits; + new |= mask & ebits; + + lfsr(new); + + return old & ebits; +} diff --git a/lib/libc/arch/ns32k/gen/fpsetsticky.c b/lib/libc/arch/ns32k/gen/fpsetsticky.c new file mode 100644 index 00000000000..1bfc6ff763b --- /dev/null +++ b/lib/libc/arch/ns32k/gen/fpsetsticky.c @@ -0,0 +1,42 @@ +/* $OpenBSD: fpsetsticky.c,v 1.1 1996/04/21 23:38:47 deraadt Exp $ */ + +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include +#include +#include + +fp_except +fpsetsticky(sticky) + fp_except sticky; +{ + fp_except old; + fp_except new; + fp_except ebits = FPC_IEN | FPC_OVE | FPC_IVE | FPC_DZE | FPC_UEN | FPC_UNDE; + + if (sticky & FPC_UNDE) { + sticky |= FPC_UEN; + sticky &= ~FPC_UNDE; + } + + sfsr(old); + + new = old; + new &= ebits; + new |= (sticky & ebits) << 1; + + lfsr(new); + + /* Map FPC_UF to soft underflow enable */ + if (old & FPC_UF) { + old |= FPC_UNDE << 1; + old &= FPC_UF; + } else + old &= ~(FPC_UNDE << 1); + old >>= 1; + + return old & ebits; +} diff --git a/lib/libc/arch/ns32k/gen/infinity.c b/lib/libc/arch/ns32k/gen/infinity.c index 69308d69077..7033c6485f8 100644 --- a/lib/libc/arch/ns32k/gen/infinity.c +++ b/lib/libc/arch/ns32k/gen/infinity.c @@ -1,5 +1,7 @@ +/* $OpenBSD: infinity.c,v 1.2 1996/04/21 23:38:49 deraadt Exp $ */ + #ifndef lint -static char rcsid[] = "$Id: infinity.c,v 1.1.1.1 1995/10/18 08:41:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: infinity.c,v 1.2 1996/04/21 23:38:49 deraadt Exp $"; #endif /* not lint */ /* infinity.c */ @@ -7,4 +9,4 @@ static char rcsid[] = "$Id: infinity.c,v 1.1.1.1 1995/10/18 08:41:37 deraadt Exp #include /* bytes for +Infinity on a ns32k */ -char __infinity[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0x7f }; +char __infinity[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }; diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index d980d3e0746..bdbc4b2fb1d 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,11 +1,12 @@ -# $NetBSD: Makefile.inc,v 1.70 1995/04/25 00:06:17 jtc Exp $ +# $OpenBSD: Makefile.inc,v 1.2 1996/04/21 23:39:01 deraadt Exp $ +# $NetBSD: Makefile.inc,v 1.71 1996/04/15 23:44:53 jtc Exp $ # @(#)Makefile.inc 8.3 (Berkeley) 4/16/94 # gen sources .PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/gen ${.CURDIR}/gen SRCS+= alarm.c assert.c clock.c closedir.c confstr.c ctermid.c \ - ctype_.c daemon.c devname.c disklabel.c err.c errlist.c \ + ctype_.c daemon.c devname.c disklabel.c err.c errx.c errlist.c \ errno.c exec.c fnmatch.c fstab.c ftok.c fts.c getbsize.c getcap.c \ getcwd.c getdomainname.c getgrent.c getgrouplist.c gethostname.c \ getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \ @@ -17,7 +18,7 @@ SRCS+= alarm.c assert.c clock.c closedir.c confstr.c ctermid.c \ sigsetops.c sleep.c sysconf.c sysctl.c syslog.c telldir.c \ time.c times.c timezone.c tolower_.c ttyname.c ttyslot.c toupper_.c \ ualarm.c uname.c unvis.c usleep.c utime.c valloc.c vis.c wait.c \ - wait3.c waitpid.c + wait3.c waitpid.c warn.c warnx.c vwarn.c vwarnx.c verr.c verrx.c # indirect reference stubs, to be removed soon. SRCS+= _err.c _errx.c _sys_errlist.c _sys_nerr.c _sys_siglist.c \ diff --git a/lib/libc/gen/_err.c b/lib/libc/gen/_err.c index 60f679dfa71..032ee4b1bfd 100644 --- a/lib/libc/gen/_err.c +++ b/lib/libc/gen/_err.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _err.c,v 1.2 1996/04/21 23:39:04 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -10,13 +12,6 @@ __indr_reference(_err, err); #else #define _err err -#define _errx errx -#define _warn warn -#define _warnx warnx -#define _verr verr -#define _verrx verrx -#define _vwarn vwarn -#define _vwarnx vwarnx #define rcsid _rcsid #include "err.c" diff --git a/lib/libc/gen/_errx.c b/lib/libc/gen/_errx.c index 6b03fbaa60a..739ed17ec60 100644 --- a/lib/libc/gen/_errx.c +++ b/lib/libc/gen/_errx.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _errx.c,v 1.2 1996/04/21 23:39:05 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_errx, errx); +#else + +#define _errx errx +#define rcsid _rcsid +#include "errx.c" + #endif diff --git a/lib/libc/gen/_verr.c b/lib/libc/gen/_verr.c index b747c98c41c..3ff3d8a5fdc 100644 --- a/lib/libc/gen/_verr.c +++ b/lib/libc/gen/_verr.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _verr.c,v 1.2 1996/04/21 23:39:07 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_verr, verr); +#else + +#define _verr verr +#define rcsid _rcsid +#include "verr.c" + #endif diff --git a/lib/libc/gen/_verrx.c b/lib/libc/gen/_verrx.c index ff8342d512f..5d2acd4bdfc 100644 --- a/lib/libc/gen/_verrx.c +++ b/lib/libc/gen/_verrx.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _verrx.c,v 1.2 1996/04/21 23:39:08 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_verrx, verrx); +#else + +#define _verrx verrx +#define rcsid _rcsid +#include "verrx.c" + #endif diff --git a/lib/libc/gen/_vwarn.c b/lib/libc/gen/_vwarn.c index 11d4ff6a5fe..b8fcf397622 100644 --- a/lib/libc/gen/_vwarn.c +++ b/lib/libc/gen/_vwarn.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _vwarn.c,v 1.2 1996/04/21 23:39:10 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_vwarn, vwarn); +#else + +#define _vwarn vwarn +#define rcsid _rcsid +#include "vwarn.c" + #endif diff --git a/lib/libc/gen/_vwarnx.c b/lib/libc/gen/_vwarnx.c index 463ce58ce80..532a93b57c6 100644 --- a/lib/libc/gen/_vwarnx.c +++ b/lib/libc/gen/_vwarnx.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _vwarnx.c,v 1.2 1996/04/21 23:39:12 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_vwarnx, vwarnx); +#else + +#define _vwarnx vwarnx +#define rcsid _rcsid +#include "vwarnx.c" + #endif diff --git a/lib/libc/gen/_warn.c b/lib/libc/gen/_warn.c index 4e42eaf31bb..9776e82379d 100644 --- a/lib/libc/gen/_warn.c +++ b/lib/libc/gen/_warn.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _warn.c,v 1.2 1996/04/21 23:39:14 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_warn, warn); +#else + +#define _warn warn +#define rcsid _rcsid +#include "warn.c" + #endif diff --git a/lib/libc/gen/_warnx.c b/lib/libc/gen/_warnx.c index 74b9715dcba..007e41d573a 100644 --- a/lib/libc/gen/_warnx.c +++ b/lib/libc/gen/_warnx.c @@ -1,3 +1,5 @@ +/* $OpenBSD: _warnx.c,v 1.2 1996/04/21 23:39:15 deraadt Exp $ */ + /* * J.T. Conklin, December 12, 1994 * Public Domain @@ -7,4 +9,10 @@ #ifdef __indr_reference __indr_reference(_warnx, warnx); +#else + +#define _warnx warnx +#define rcsid _rcsid +#include "warnx.c" + #endif diff --git a/lib/libc/gen/err.c b/lib/libc/gen/err.c index bc825899183..094ea952a98 100644 --- a/lib/libc/gen/err.c +++ b/lib/libc/gen/err.c @@ -1,4 +1,5 @@ -/* $NetBSD: err.c,v 1.12 1995/02/25 17:19:26 cgd Exp $ */ +/* $OpenBSD: err.c,v 1.2 1996/04/21 23:39:17 deraadt Exp $ */ +/* $NetBSD: err.c,v 1.13 1996/04/15 23:45:29 jtc Exp $ */ /*- * Copyright (c) 1993 @@ -37,15 +38,11 @@ #if 0 static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$NetBSD: err.c,v 1.12 1995/02/25 17:19:26 cgd Exp $"; +static char rcsid[] = "$NetBSD: err.c,v 1.13 1996/04/15 23:45:29 jtc Exp $"; #endif #endif /* LIBC_SCCS and not lint */ #include -#include -#include -#include -#include #ifdef __STDC__ #include @@ -53,26 +50,6 @@ static char rcsid[] = "$NetBSD: err.c,v 1.12 1995/02/25 17:19:26 cgd Exp $"; #include #endif -extern char *__progname; /* Program name, from crt0. */ - -__dead void -_verr(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; -{ - int sverrno; - - sverrno = errno; - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, ": "); - } - (void)fprintf(stderr, "%s\n", strerror(sverrno)); - exit(eval); -} - __dead void #ifdef __STDC__ _err(int eval, const char *fmt, ...) @@ -95,109 +72,3 @@ _err(va_alist) _verr(eval, fmt, ap); va_end(ap); } - -__dead void -_verrx(eval, fmt, ap) - int eval; - const char *fmt; - va_list ap; -{ - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, "\n"); - exit(eval); -} - -__dead void -#if __STDC__ -_errx(int eval, const char *fmt, ...) -#else -_errx(va_alist) - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - int eval; - const char *fmt; - - va_start(ap); - eval = va_arg(ap, int); - fmt = va_arg(ap, const char *); -#endif - _verrx(eval, fmt, ap); - va_end(ap); -} - - -void -_vwarn(fmt, ap) - const char *fmt; - va_list ap; -{ - int sverrno; - - sverrno = errno; - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) { - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, ": "); - } - (void)fprintf(stderr, "%s\n", strerror(sverrno)); -} - -void -#if __STDC__ -_warn(const char *fmt, ...) -#else -_warn(va_alist) - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - const char *fmt; - - va_start(ap); - fmt = va_arg(ap, const char *); -#endif - _vwarn(fmt, ap); - va_end(ap); -} - -void -_vwarnx(fmt, ap) - const char *fmt; - va_list ap; -{ - (void)fprintf(stderr, "%s: ", __progname); - if (fmt != NULL) - (void)vfprintf(stderr, fmt, ap); - (void)fprintf(stderr, "\n"); -} - -void -#ifdef __STDC__ -_warnx(const char *fmt, ...) -#else -_warnx(va_alist) - va_dcl -#endif -{ - va_list ap; -#ifdef __STDC__ - va_start(ap, fmt); -#else - const char *fmt; - - va_start(ap); - fmt = va_arg(ap, const char *); -#endif - _vwarnx(fmt, ap); - va_end(ap); -} diff --git a/lib/libc/gen/errx.c b/lib/libc/gen/errx.c new file mode 100644 index 00000000000..7f9dd6a38c3 --- /dev/null +++ b/lib/libc/gen/errx.c @@ -0,0 +1,74 @@ +/* $OpenBSD: errx.c,v 1.1 1996/04/21 23:39:18 deraadt Exp $ */ +/* $NetBSD: errx.c,v 1.1 1996/04/15 23:45:32 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: errx.c,v 1.1 1996/04/15 23:45:32 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +__dead void +#if __STDC__ +_errx(int eval, const char *fmt, ...) +#else +_errx(va_alist) + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + int eval; + const char *fmt; + + va_start(ap); + eval = va_arg(ap, int); + fmt = va_arg(ap, const char *); +#endif + _verrx(eval, fmt, ap); + va_end(ap); +} diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index cc131dd54d7..bc1e3646d0f 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -1,4 +1,5 @@ -/* $NetBSD: fstab.c,v 1.7 1995/02/27 04:34:44 cgd Exp $ */ +/* $OpenBSD: fstab.c,v 1.2 1996/04/21 23:39:19 deraadt Exp $ */ +/* $NetBSD: fstab.c,v 1.8 1996/04/03 19:48:56 jtc Exp $ */ /* * Copyright (c) 1980, 1988, 1993 @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)fstab.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$NetBSD: fstab.c,v 1.7 1995/02/27 04:34:44 cgd Exp $"; +static char rcsid[] = "$NetBSD: fstab.c,v 1.8 1996/04/03 19:48:56 jtc Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -53,10 +54,10 @@ static char rcsid[] = "$NetBSD: fstab.c,v 1.7 1995/02/27 04:34:44 cgd Exp $"; static FILE *_fs_fp; static struct fstab _fs_fstab; -static error __P((int)); -static fstabscan __P((void)); +static void error __P((int)); +static int fstabscan __P((void)); -static +static int fstabscan() { register char *cp; @@ -176,6 +177,7 @@ getfsfile(name) return((struct fstab *)NULL); } +int setfsent() { if (_fs_fp) { @@ -197,7 +199,7 @@ endfsent() } } -static +static void error(err) int err; { diff --git a/lib/libc/gen/gethostname.3 b/lib/libc/gen/gethostname.3 index ff8717eb84a..63f4dd0e443 100644 --- a/lib/libc/gen/gethostname.3 +++ b/lib/libc/gen/gethostname.3 @@ -1,4 +1,5 @@ -.\" $NetBSD: gethostname.3,v 1.3 1996/02/11 16:15:40 neil Exp $ +.\" $OpenBSD: gethostname.3,v 1.3 1996/04/21 23:39:21 deraadt Exp $ +.\" $NetBSD: gethostname.3,v 1.4 1996/04/08 20:56:38 jtc Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -84,8 +85,8 @@ invalid address. The caller tried to set the hostname and was not the super-user. .El .Sh SEE ALSO -.Xr sysctl 3 -.Xr gethostid 3 +.Xr sysctl 3 , +.Xr gethostid 3 , .Xr sysctl 8 .Sh BUGS Host names are limited to diff --git a/lib/libc/gen/getttyent.3 b/lib/libc/gen/getttyent.3 index 94adb769aff..39c2e04f6e4 100644 --- a/lib/libc/gen/getttyent.3 +++ b/lib/libc/gen/getttyent.3 @@ -1,4 +1,5 @@ -.\" $NetBSD: getttyent.3,v 1.6 1995/02/27 04:13:16 cgd Exp $ +.\" $OpenBSD: getttyent.3,v 1.2 1996/04/21 23:39:22 deraadt Exp $ +.\" $NetBSD: getttyent.3,v 1.7 1996/03/17 19:36:53 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -104,6 +105,9 @@ Allow users with a uid of 0 to login on this terminal. .It Dv TTY_LOCAL If the terminal port's driver supports it, cause the line to be treated as ``local.'' +.It Dv TTY_MDMBUF +If the terminal port's driver supports it, use +DTR/DCD hardware flow control on the line by default. .It Dv TTY_RTSCTS If the terminal port's driver supports it, use full-duplex RTS/CTS hardware flow control on the line diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 0d6eb4eeb4d..37c111a21c9 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -1,4 +1,5 @@ -/* $NetBSD: setmode.c,v 1.12 1995/03/23 19:51:13 jtc Exp $ */ +/* $OpenBSD: setmode.c,v 1.3 1996/04/21 23:39:25 deraadt Exp $ */ +/* $NetBSD: setmode.c,v 1.13 1996/04/03 19:49:01 jtc Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -40,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$NetBSD: setmode.c,v 1.12 1995/03/23 19:51:13 jtc Exp $"; +static char rcsid[] = "$NetBSD: setmode.c,v 1.13 1996/04/03 19:49:01 jtc Exp $"; #endif #endif /* LIBC_SCCS and not lint */ diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c index a8b0c25e730..cc075f49859 100644 --- a/lib/libc/gen/siginterrupt.c +++ b/lib/libc/gen/siginterrupt.c @@ -1,4 +1,5 @@ -/* $NetBSD: siginterrupt.c,v 1.6 1995/03/04 01:56:00 cgd Exp $ */ +/* $OpenBSD: siginterrupt.c,v 1.2 1996/04/21 23:39:27 deraadt Exp $ */ +/* $NetBSD: siginterrupt.c,v 1.7 1996/04/03 19:49:03 jtc Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93"; #else -static char rcsid[] = "$NetBSD: siginterrupt.c,v 1.6 1995/03/04 01:56:00 cgd Exp $"; +static char rcsid[] = "$NetBSD: siginterrupt.c,v 1.7 1996/04/03 19:49:03 jtc Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -47,6 +48,7 @@ static char rcsid[] = "$NetBSD: siginterrupt.c,v 1.6 1995/03/04 01:56:00 cgd Exp * Set signal state to prevent restart of system calls * after an instance of the indicated signal. */ +int siginterrupt(sig, flag) int sig, flag; { diff --git a/lib/libc/gen/signal.3 b/lib/libc/gen/signal.3 index dd9c82b255b..260d4945760 100644 --- a/lib/libc/gen/signal.3 +++ b/lib/libc/gen/signal.3 @@ -1,4 +1,5 @@ -.\" $NetBSD: signal.3,v 1.5 1995/02/27 05:51:12 cgd Exp $ +.\" $OpenBSD: signal.3,v 1.2 1996/04/21 23:39:28 deraadt Exp $ +.\" $NetBSD: signal.3,v 1.6 1996/03/26 02:05:55 jtc Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -42,11 +43,11 @@ .Sh SYNOPSIS .Fd #include .Ft void -.Fn *signal sig func\*(lp\*(rp -.Ft void -.\" can not do this with .Fn yet +.\" can not do this with just .Fn yet .br -\*(lp\|\*(fN*func\*(rp\*(lp\|\*(rp\fR +.Po +.Fn *signal "int sig" "void (*func)()" +.Pc Ns \*(lp\*(rp .Sh DESCRIPTION This .Fn signal diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3 index 1c28f23dbe1..07973bc965f 100644 --- a/lib/libc/gen/sysctl.3 +++ b/lib/libc/gen/sysctl.3 @@ -1,3 +1,4 @@ +.\" $OpenBSD: sysctl.3,v 1.2 1996/04/21 23:39:30 deraadt Exp $ .\" $NetBSD: sysctl.3,v 1.7 1995/09/30 07:03:54 thorpej Exp $ .\" .\" Copyright (c) 1993 @@ -40,6 +41,7 @@ .Nm sysctl .Nd get or set system information .Sh SYNOPSIS +.Fd #include .Fd #include .Ft int .Fn sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp" "size_t newlen" diff --git a/lib/libc/gen/verr.c b/lib/libc/gen/verr.c new file mode 100644 index 00000000000..fba24377e51 --- /dev/null +++ b/lib/libc/gen/verr.c @@ -0,0 +1,75 @@ +/* $OpenBSD: verr.c,v 1.1 1996/04/21 23:39:32 deraadt Exp $ */ +/* $NetBSD: verr.c,v 1.1 1996/04/15 23:45:35 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: verr.c,v 1.1 1996/04/15 23:45:35 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +extern char *__progname; /* Program name, from crt0. */ + +__dead void +_verr(eval, fmt, ap) + int eval; + const char *fmt; + va_list ap; +{ + int sverrno; + + sverrno = errno; + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + (void)fprintf(stderr, "%s\n", strerror(sverrno)); + exit(eval); +} diff --git a/lib/libc/gen/verrx.c b/lib/libc/gen/verrx.c new file mode 100644 index 00000000000..23a4e4e417a --- /dev/null +++ b/lib/libc/gen/verrx.c @@ -0,0 +1,68 @@ +/* $OpenBSD: verrx.c,v 1.1 1996/04/21 23:39:33 deraadt Exp $ */ +/* $NetBSD: verrx.c,v 1.1 1996/04/15 23:45:36 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: verrx.c,v 1.1 1996/04/15 23:45:36 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +extern char *__progname; /* Program name, from crt0. */ + +__dead void +_verrx(eval, fmt, ap) + int eval; + const char *fmt; + va_list ap; +{ + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, "\n"); + exit(eval); +} diff --git a/lib/libc/gen/vwarn.c b/lib/libc/gen/vwarn.c new file mode 100644 index 00000000000..7c4c8a2a78d --- /dev/null +++ b/lib/libc/gen/vwarn.c @@ -0,0 +1,72 @@ +/* $OpenBSD: vwarn.c,v 1.1 1996/04/21 23:39:34 deraadt Exp $ */ +/* $NetBSD: vwarn.c,v 1.1 1996/04/15 23:45:38 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: vwarn.c,v 1.1 1996/04/15 23:45:38 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +extern char *__progname; /* Program name, from crt0. */ + +void +_vwarn(fmt, ap) + const char *fmt; + va_list ap; +{ + int sverrno; + + sverrno = errno; + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) { + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, ": "); + } + (void)fprintf(stderr, "%s\n", strerror(sverrno)); +} diff --git a/lib/libc/gen/vwarnx.c b/lib/libc/gen/vwarnx.c new file mode 100644 index 00000000000..b1d16a688d8 --- /dev/null +++ b/lib/libc/gen/vwarnx.c @@ -0,0 +1,65 @@ +/* $OpenBSD: vwarnx.c,v 1.1 1996/04/21 23:39:35 deraadt Exp $ */ +/* $NetBSD: vwarnx.c,v 1.1 1996/04/15 23:45:40 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: vwarnx.c,v 1.1 1996/04/15 23:45:40 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +extern char *__progname; /* Program name, from crt0. */ + +void +_vwarnx(fmt, ap) + const char *fmt; + va_list ap; +{ + (void)fprintf(stderr, "%s: ", __progname); + if (fmt != NULL) + (void)vfprintf(stderr, fmt, ap); + (void)fprintf(stderr, "\n"); +} diff --git a/lib/libc/gen/warn.c b/lib/libc/gen/warn.c new file mode 100644 index 00000000000..4f0fa6f693e --- /dev/null +++ b/lib/libc/gen/warn.c @@ -0,0 +1,72 @@ +/* $OpenBSD: warn.c,v 1.1 1996/04/21 23:39:37 deraadt Exp $ */ +/* $NetBSD: warn.c,v 1.1 1996/04/15 23:45:42 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: warn.c,v 1.1 1996/04/15 23:45:42 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +void +#ifdef __STDC__ +_warn(const char *fmt, ...) +#else +_warn(va_alist) + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + const char *fmt; + + va_start(ap); + fmt = va_arg(ap, const char *); +#endif + _vwarn(fmt, ap); + va_end(ap); +} diff --git a/lib/libc/gen/warnx.c b/lib/libc/gen/warnx.c new file mode 100644 index 00000000000..9b1e8d5a940 --- /dev/null +++ b/lib/libc/gen/warnx.c @@ -0,0 +1,72 @@ +/* $OpenBSD: warnx.c,v 1.1 1996/04/21 23:39:38 deraadt Exp $ */ +/* $NetBSD: warnx.c,v 1.1 1996/04/15 23:45:44 jtc Exp $ */ + +/*- + * Copyright (c) 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char sccsid[] = "@(#)err.c 8.1 (Berkeley) 6/4/93"; +#else +static char rcsid[] = "$NetBSD: warnx.c,v 1.1 1996/04/15 23:45:44 jtc Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ + +#include + +#ifdef __STDC__ +#include +#else +#include +#endif + +void +#ifdef __STDC__ +_warnx(const char *fmt, ...) +#else +_warnx(va_alist) + va_dcl +#endif +{ + va_list ap; +#ifdef __STDC__ + va_start(ap, fmt); +#else + const char *fmt; + + va_start(ap); + fmt = va_arg(ap, const char *); +#endif + _vwarnx(fmt, ap); + va_end(ap); +} diff --git a/sbin/Makefile b/sbin/Makefile index c99bfdc7ab4..88fe9b4efaa 100644 --- a/sbin/Makefile +++ b/sbin/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.3 1996/03/21 00:15:18 niklas Exp $ -# $NetBSD: Makefile,v 1.26 1996/03/16 10:29:36 leo Exp $ +# $OpenBSD: Makefile,v 1.4 1996/04/21 23:45:41 deraadt Exp $ +# $NetBSD: Makefile,v 1.28 1996/04/05 01:44:24 cgd Exp $ # @(#)Makefile 8.5 (Berkeley) 3/31/94 # Not ported: XNSrouted enpload scsiformat startslip @@ -7,21 +7,14 @@ SUBDIR= badsect disklabel ccdconfig dmesg fastboot ifconfig init ipf \ ipfstat mknod modload modunload mount mountd nfsd nfsiod nologin \ - ping quotacheck reboot route routed shutdown slattach swapon \ - ttyflags umount - -# XXX Temporarely until all ports are able to use savecore (leo) -.if (${MACHINE} == "atari") -SUBDIR+= savecore -.else -SUBDIR+= savecore.old -.endif + ping quotacheck reboot route routed savecore shutdown slattach \ + swapon ttyflags umount # support for various file systems SUBDIR+= mount_ados SUBDIR+= mount_cd9660 SUBDIR+= mount_fdesc -SUBDIR+= mount_ffs newfs fsck fsdb dumpfs dump restore clri tunefs +SUBDIR+= mount_ffs newfs fsck_ffs fsdb dumpfs dump restore clri tunefs SUBDIR+= mount_kernfs SUBDIR+= mount_lfs newlfs dumplfs # mount_mfs -> newfs diff --git a/sbin/fsck/Makefile b/sbin/fsck/Makefile deleted file mode 100644 index 6b9a9d086fb..00000000000 --- a/sbin/fsck/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $NetBSD: Makefile,v 1.10 1995/03/18 14:55:39 cgd Exp $ -# @(#)Makefile 8.1 (Berkeley) 6/5/93 - -PROG= fsck -MAN= fsck.8 -SRCS= dir.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \ - pass5.c preen.c setup.c utilities.c ffs_subr.c ffs_tables.c -.PATH: ${.CURDIR}/../../sys/ufs/ffs - -.if make(install) -SUBDIR+= SMM.doc -.endif - -.include diff --git a/sbin/fsck/SMM.doc/0.t b/sbin/fsck/SMM.doc/0.t deleted file mode 100644 index b6598c0f817..00000000000 --- a/sbin/fsck/SMM.doc/0.t +++ /dev/null @@ -1,152 +0,0 @@ -.\" $NetBSD: 0.t,v 1.2 1995/03/18 14:56:05 cgd Exp $ -.\" -.\" Copyright (c) 1986, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)0.t 8.1 (Berkeley) 6/8/93 -.\" -.if n .ND -.TL -Fsck \- The UNIX\(dg File System Check Program -.EH 'SMM:3-%''The \s-2UNIX\s+2 File System Check Program' -.OH 'The \s-2UNIX\s+2 File System Check Program''SMM:3-%' -.AU -Marshall Kirk McKusick -.AI -Computer Systems Research Group -Computer Science Division -Department of Electrical Engineering and Computer Science -University of California, Berkeley -Berkeley, CA 94720 -.AU -T. J. Kowalski -.AI -Bell Laboratories -Murray Hill, New Jersey 07974 -.AB -.FS -\(dgUNIX is a trademark of Bell Laboratories. -.FE -.FS -This work was done under grants from -the National Science Foundation under grant MCS80-05144, -and the Defense Advance Research Projects Agency (DoD) under -Arpa Order No. 4031 monitored by Naval Electronic System Command under -Contract No. N00039-82-C-0235. -.FE -This document reflects the use of -.I fsck -with the 4.2BSD and 4.3BSD file system organization. This -is a revision of the -original paper written by -T. J. Kowalski. -.PP -File System Check Program (\fIfsck\fR) -is an interactive file system check and repair program. -.I Fsck -uses the redundant structural information in the -UNIX file system to perform several consistency checks. -If an inconsistency is detected, it is reported -to the operator, who may elect to fix or ignore -each inconsistency. -These inconsistencies result from the permanent interruption -of the file system updates, which are performed every -time a file is modified. -Unless there has been a hardware failure, -.I fsck -is able to repair corrupted file systems -using procedures based upon the order in which UNIX honors -these file system update requests. -.PP -The purpose of this document is to describe the normal updating -of the file system, -to discuss the possible causes of file system corruption, -and to present the corrective actions implemented -by -.I fsck. -Both the program and the interaction between the -program and the operator are described. -.sp 2 -.LP -Revised July 16, 1985 -.AE -.LP -.bp -.ce -.B "TABLE OF CONTENTS" -.LP -.sp 1 -.nf -.B "1. Introduction" -.LP -.sp .5v -.nf -.B "2. Overview of the file system -2.1. Superblock -2.2. Summary Information -2.3. Cylinder groups -2.4. Fragments -2.5. Updates to the file system -.LP -.sp .5v -.nf -.B "3. Fixing corrupted file systems -3.1. Detecting and correcting corruption -3.2. Super block checking -3.3. Free block checking -3.4. Checking the inode state -3.5. Inode links -3.6. Inode data size -3.7. Checking the data associated with an inode -3.8. File system connectivity -.LP -.sp .5v -.nf -.B Acknowledgements -.LP -.sp .5v -.nf -.B References -.LP -.sp .5v -.nf -.B "4. Appendix A -4.1. Conventions -4.2. Initialization -4.3. Phase 1 - Check Blocks and Sizes -4.4. Phase 1b - Rescan for more Dups -4.5. Phase 2 - Check Pathnames -4.6. Phase 3 - Check Connectivity -4.7. Phase 4 - Check Reference Counts -4.8. Phase 5 - Check Cyl groups -4.9. Cleanup -.ds RH Introduction -.bp diff --git a/sbin/fsck/SMM.doc/1.t b/sbin/fsck/SMM.doc/1.t deleted file mode 100644 index 91622cbe3e3..00000000000 --- a/sbin/fsck/SMM.doc/1.t +++ /dev/null @@ -1,85 +0,0 @@ -.\" $NetBSD: 1.t,v 1.2 1995/03/18 14:56:06 cgd Exp $ -.\" -.\" Copyright (c) 1982, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)1.t 8.1 (Berkeley) 6/5/93 -.\" -.ds RH Introduction -.NH -Introduction -.PP -This document reflects the use of -.I fsck -with the 4.2BSD and 4.3BSD file system organization. This -is a revision of the -original paper written by -T. J. Kowalski. -.PP -When a UNIX -operating system is brought up, a consistency -check of the file systems should always be performed. -This precautionary measure helps to insure -a reliable environment for file storage on disk. -If an inconsistency is discovered, -corrective action must be taken. -.I Fsck -runs in two modes. -Normally it is run non-interactively by the system after -a normal boot. -When running in this mode, -it will only make changes to the file system that are known -to always be correct. -If an unexpected inconsistency is found -.I fsck -will exit with a non-zero exit status, -leaving the system running single-user. -Typically the operator then runs -.I fsck -interactively. -When running in this mode, -each problem is listed followed by a suggested corrective action. -The operator must decide whether or not the suggested correction -should be made. -.PP -The purpose of this memo is to dispel the -mystique surrounding -file system inconsistencies. -It first describes the updating of the file system -(the calm before the storm) and -then describes file system corruption (the storm). -Finally, -the set of deterministic corrective actions -used by -.I fsck -(the Coast Guard -to the rescue) is presented. -.ds RH Overview of the File System diff --git a/sbin/fsck/SMM.doc/2.t b/sbin/fsck/SMM.doc/2.t deleted file mode 100644 index a4abd91fe4a..00000000000 --- a/sbin/fsck/SMM.doc/2.t +++ /dev/null @@ -1,267 +0,0 @@ -.\" $NetBSD: 2.t,v 1.2 1995/03/18 14:56:08 cgd Exp $ -.\" -.\" Copyright (c) 1982, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)2.t 8.1 (Berkeley) 6/5/93 -.\" -.ds RH Overview of the file system -.NH -Overview of the file system -.PP -The file system is discussed in detail in [Mckusick84]; -this section gives a brief overview. -.NH 2 -Superblock -.PP -A file system is described by its -.I "super-block" . -The super-block is built when the file system is created (\c -.I newfs (8)) -and never changes. -The super-block -contains the basic parameters of the file system, -such as the number of data blocks it contains -and a count of the maximum number of files. -Because the super-block contains critical data, -.I newfs -replicates it to protect against catastrophic loss. -The -.I "default super block" -always resides at a fixed offset from the beginning -of the file system's disk partition. -The -.I "redundant super blocks" -are not referenced unless a head crash -or other hard disk error causes the default super-block -to be unusable. -The redundant blocks are sprinkled throughout the disk partition. -.PP -Within the file system are files. -Certain files are distinguished as directories and contain collections -of pointers to files that may themselves be directories. -Every file has a descriptor associated with it called an -.I "inode". -The inode contains information describing ownership of the file, -time stamps indicating modification and access times for the file, -and an array of indices pointing to the data blocks for the file. -In this section, -we assume that the first 12 blocks -of the file are directly referenced by values stored -in the inode structure itself\(dg. -.FS -\(dgThe actual number may vary from system to system, but is usually in -the range 5-13. -.FE -The inode structure may also contain references to indirect blocks -containing further data block indices. -In a file system with a 4096 byte block size, a singly indirect -block contains 1024 further block addresses, -a doubly indirect block contains 1024 addresses of further single indirect -blocks, -and a triply indirect block contains 1024 addresses of further doubly indirect -blocks (the triple indirect block is never needed in practice). -.PP -In order to create files with up to -2\(ua32 bytes, -using only two levels of indirection, -the minimum size of a file system block is 4096 bytes. -The size of file system blocks can be any power of two -greater than or equal to 4096. -The block size of the file system is maintained in the super-block, -so it is possible for file systems of different block sizes -to be accessible simultaneously on the same system. -The block size must be decided when -.I newfs -creates the file system; -the block size cannot be subsequently -changed without rebuilding the file system. -.NH 2 -Summary information -.PP -Associated with the super block is non replicated -.I "summary information" . -The summary information changes -as the file system is modified. -The summary information contains -the number of blocks, fragments, inodes and directories in the file system. -.NH 2 -Cylinder groups -.PP -The file system partitions the disk into one or more areas called -.I "cylinder groups". -A cylinder group is comprised of one or more consecutive -cylinders on a disk. -Each cylinder group includes inode slots for files, a -.I "block map" -describing available blocks in the cylinder group, -and summary information describing the usage of data blocks -within the cylinder group. -A fixed number of inodes is allocated for each cylinder group -when the file system is created. -The current policy is to allocate one inode for each 2048 -bytes of disk space; -this is expected to be far more inodes than will ever be needed. -.PP -All the cylinder group bookkeeping information could be -placed at the beginning of each cylinder group. -However if this approach were used, -all the redundant information would be on the top platter. -A single hardware failure that destroyed the top platter -could cause the loss of all copies of the redundant super-blocks. -Thus the cylinder group bookkeeping information -begins at a floating offset from the beginning of the cylinder group. -The offset for -the -.I "i+1" st -cylinder group is about one track further -from the beginning of the cylinder group -than it was for the -.I "i" th -cylinder group. -In this way, -the redundant -information spirals down into the pack; -any single track, cylinder, -or platter can be lost without losing all copies of the super-blocks. -Except for the first cylinder group, -the space between the beginning of the cylinder group -and the beginning of the cylinder group information stores data. -.NH 2 -Fragments -.PP -To avoid waste in storing small files, -the file system space allocator divides a single -file system block into one or more -.I "fragments". -The fragmentation of the file system is specified -when the file system is created; -each file system block can be optionally broken into -2, 4, or 8 addressable fragments. -The lower bound on the size of these fragments is constrained -by the disk sector size; -typically 512 bytes is the lower bound on fragment size. -The block map associated with each cylinder group -records the space availability at the fragment level. -Aligned fragments are examined -to determine block availability. -.PP -On a file system with a block size of 4096 bytes -and a fragment size of 1024 bytes, -a file is represented by zero or more 4096 byte blocks of data, -and possibly a single fragmented block. -If a file system block must be fragmented to obtain -space for a small amount of data, -the remainder of the block is made available for allocation -to other files. -For example, -consider an 11000 byte file stored on -a 4096/1024 byte file system. -This file uses two full size blocks and a 3072 byte fragment. -If no fragments with at least 3072 bytes -are available when the file is created, -a full size block is split yielding the necessary 3072 byte -fragment and an unused 1024 byte fragment. -This remaining fragment can be allocated to another file, as needed. -.NH 2 -Updates to the file system -.PP -Every working day hundreds of files -are created, modified, and removed. -Every time a file is modified, -the operating system performs a -series of file system updates. -These updates, when written on disk, yield a consistent file system. -The file system stages -all modifications of critical information; -modification can -either be completed or cleanly backed out after a crash. -Knowing the information that is first written to the file system, -deterministic procedures can be developed to -repair a corrupted file system. -To understand this process, -the order that the update -requests were being honored must first be understood. -.PP -When a user program does an operation to change the file system, -such as a -.I write , -the data to be written is copied into an internal -.I "in-core" -buffer in the kernel. -Normally, the disk update is handled asynchronously; -the user process is allowed to proceed even though -the data has not yet been written to the disk. -The data, -along with the inode information reflecting the change, -is eventually written out to disk. -The real disk write may not happen until long after the -.I write -system call has returned. -Thus at any given time, the file system, -as it resides on the disk, -lags the state of the file system represented by the in-core information. -.PP -The disk information is updated to reflect the in-core information -when the buffer is required for another use, -when a -.I sync (2) -is done (at 30 second intervals) by -.I "/etc/update" "(8)," -or by manual operator intervention with the -.I sync (8) -command. -If the system is halted without writing out the in-core information, -the file system on the disk will be in an inconsistent state. -.PP -If all updates are done asynchronously, several serious -inconsistencies can arise. -One inconsistency is that a block may be claimed by two inodes. -Such an inconsistency can occur when the system is halted before -the pointer to the block in the old inode has been cleared -in the copy of the old inode on the disk, -and after the pointer to the block in the new inode has been written out -to the copy of the new inode on the disk. -Here, -there is no deterministic method for deciding -which inode should really claim the block. -A similar problem can arise with a multiply claimed inode. -.PP -The problem with asynchronous inode updates -can be avoided by doing all inode deallocations synchronously. -Consequently, -inodes and indirect blocks are written to the disk synchronously -(\fIi.e.\fP the process blocks until the information is -really written to disk) -when they are being deallocated. -Similarly inodes are kept consistent by synchronously -deleting, adding, or changing directory entries. -.ds RH Fixing corrupted file systems diff --git a/sbin/fsck/SMM.doc/3.t b/sbin/fsck/SMM.doc/3.t deleted file mode 100644 index a1db17b2d7c..00000000000 --- a/sbin/fsck/SMM.doc/3.t +++ /dev/null @@ -1,441 +0,0 @@ -.\" $NetBSD: 3.t,v 1.2 1995/03/18 14:56:10 cgd Exp $ -.\" -.\" Copyright (c) 1982, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)3.t 8.1 (Berkeley) 6/5/93 -.\" -.ds RH Fixing corrupted file systems -.NH -Fixing corrupted file systems -.PP -A file system -can become corrupted in several ways. -The most common of these ways are -improper shutdown procedures -and hardware failures. -.PP -File systems may become corrupted during an -.I "unclean halt" . -This happens when proper shutdown -procedures are not observed, -physically write-protecting a mounted file system, -or a mounted file system is taken off-line. -The most common operator procedural failure is forgetting to -.I sync -the system before halting the CPU. -.PP -File systems may become further corrupted if proper startup -procedures are not observed, e.g., -not checking a file system for inconsistencies, -and not repairing inconsistencies. -Allowing a corrupted file system to be used (and, thus, to be modified -further) can be disastrous. -.PP -Any piece of hardware can fail at any time. -Failures -can be as subtle as a bad block -on a disk pack, or as blatant as a non-functional disk-controller. -.NH 2 -Detecting and correcting corruption -.PP -Normally -.I fsck -is run non-interactively. -In this mode it will only fix -corruptions that are expected to occur from an unclean halt. -These actions are a proper subset of the actions that -.I fsck -will take when it is running interactively. -Throughout this paper we assume that -.I fsck -is being run interactively, -and all possible errors can be encountered. -When an inconsistency is discovered in this mode, -.I fsck -reports the inconsistency for the operator to -chose a corrective action. -.PP -A quiescent\(dd -.FS -\(dd I.e., unmounted and not being written on. -.FE -file system may be checked for structural integrity -by performing consistency checks on the -redundant data intrinsic to a file system. -The redundant data is either read from -the file system, -or computed from other known values. -The file system -.B must -be in a quiescent state when -.I fsck -is run, -since -.I fsck -is a multi-pass program. -.PP -In the following sections, -we discuss methods to discover inconsistencies -and possible corrective actions -for the cylinder group blocks, the inodes, the indirect blocks, and -the data blocks containing directory entries. -.NH 2 -Super-block checking -.PP -The most commonly corrupted item in a file system -is the summary information -associated with the super-block. -The summary information is prone to corruption -because it is modified with every change to the file -system's blocks or inodes, -and is usually corrupted -after an unclean halt. -.PP -The super-block is checked for inconsistencies -involving file-system size, number of inodes, -free-block count, and the free-inode count. -The file-system size must be larger than the -number of blocks used by the super-block -and the number of blocks used by the list of inodes. -The file-system size and layout information -are the most critical pieces of information for -.I fsck . -While there is no way to actually check these sizes, -since they are statically determined by -.I newfs , -.I fsck -can check that these sizes are within reasonable bounds. -All other file system checks require that these sizes be correct. -If -.I fsck -detects corruption in the static parameters of the default super-block, -.I fsck -requests the operator to specify the location of an alternate super-block. -.NH 2 -Free block checking -.PP -.I Fsck -checks that all the blocks -marked as free in the cylinder group block maps -are not claimed by any files. -When all the blocks have been initially accounted for, -.I fsck -checks that -the number of free blocks -plus the number of blocks claimed by the inodes -equals the total number of blocks in the file system. -.PP -If anything is wrong with the block allocation maps, -.I fsck -will rebuild them, -based on the list it has computed of allocated blocks. -.PP -The summary information associated with the super-block -counts the total number of free blocks within the file system. -.I Fsck -compares this count to the -number of free blocks it found within the file system. -If the two counts do not agree, then -.I fsck -replaces the incorrect count in the summary information -by the actual free-block count. -.PP -The summary information -counts the total number of free inodes within the file system. -.I Fsck -compares this count to the number -of free inodes it found within the file system. -If the two counts do not agree, then -.I fsck -replaces the incorrect count in the -summary information by the actual free-inode count. -.NH 2 -Checking the inode state -.PP -An individual inode is not as likely to be corrupted as -the allocation information. -However, because of the great number of active inodes, -a few of the inodes are usually corrupted. -.PP -The list of inodes in the file system -is checked sequentially starting with inode 2 -(inode 0 marks unused inodes; -inode 1 is saved for future generations) -and progressing through the last inode in the file system. -The state of each inode is checked for -inconsistencies involving format and type, -link count, -duplicate blocks, -bad blocks, -and inode size. -.PP -Each inode contains a mode word. -This mode word describes the type and state of the inode. -Inodes must be one of six types: -regular inode, directory inode, symbolic link inode, -special block inode, special character inode, or socket inode. -Inodes may be found in one of three allocation states: -unallocated, allocated, and neither unallocated nor allocated. -This last state suggests an incorrectly formated inode. -An inode can get in this state if -bad data is written into the inode list. -The only possible corrective action is for -.I fsck -is to clear the inode. -.NH 2 -Inode links -.PP -Each inode counts the -total number of directory entries -linked to the inode. -.I Fsck -verifies the link count of each inode -by starting at the root of the file system, -and descending through the directory structure. -The actual link count for each inode -is calculated during the descent. -.PP -If the stored link count is non-zero and the actual -link count is zero, -then no directory entry appears for the inode. -If this happens, -.I fsck -will place the disconnected file in the -.I lost+found -directory. -If the stored and actual link counts are non-zero and unequal, -a directory entry may have been added or removed without the inode being -updated. -If this happens, -.I fsck -replaces the incorrect stored link count by the actual link count. -.PP -Each inode contains a list, -or pointers to -lists (indirect blocks), -of all the blocks claimed by the inode. -Since indirect blocks are owned by an inode, -inconsistencies in indirect blocks directly -affect the inode that owns it. -.PP -.I Fsck -compares each block number claimed by an inode -against a list of already allocated blocks. -If another inode already claims a block number, -then the block number is added to a list of -.I "duplicate blocks" . -Otherwise, the list of allocated blocks -is updated to include the block number. -.PP -If there are any duplicate blocks, -.I fsck -will perform a partial second -pass over the inode list -to find the inode of the duplicated block. -The second pass is needed, -since without examining the files associated with -these inodes for correct content, -not enough information is available -to determine which inode is corrupted and should be cleared. -If this condition does arise -(only hardware failure will cause it), -then the inode with the earliest -modify time is usually incorrect, -and should be cleared. -If this happens, -.I fsck -prompts the operator to clear both inodes. -The operator must decide which one should be kept -and which one should be cleared. -.PP -.I Fsck -checks the range of each block number claimed by an inode. -If the block number is -lower than the first data block in the file system, -or greater than the last data block, -then the block number is a -.I "bad block number" . -Many bad blocks in an inode are usually caused by -an indirect block that was not written to the file system, -a condition which can only occur if there has been a hardware failure. -If an inode contains bad block numbers, -.I fsck -prompts the operator to clear it. -.NH 2 -Inode data size -.PP -Each inode contains a count of the number of data blocks -that it contains. -The number of actual data blocks -is the sum of the allocated data blocks -and the indirect blocks. -.I Fsck -computes the actual number of data blocks -and compares that block count against -the actual number of blocks the inode claims. -If an inode contains an incorrect count -.I fsck -prompts the operator to fix it. -.PP -Each inode contains a thirty-two bit size field. -The size is the number of data bytes -in the file associated with the inode. -The consistency of the byte size field is roughly checked -by computing from the size field the maximum number of blocks -that should be associated with the inode, -and comparing that expected block count against -the actual number of blocks the inode claims. -.NH 2 -Checking the data associated with an inode -.PP -An inode can directly or indirectly -reference three kinds of data blocks. -All referenced blocks must be the same kind. -The three types of data blocks are: -plain data blocks, symbolic link data blocks, and directory data blocks. -Plain data blocks -contain the information stored in a file; -symbolic link data blocks -contain the path name stored in a link. -Directory data blocks contain directory entries. -.I Fsck -can only check the validity of directory data blocks. -.PP -Each directory data block is checked for -several types of inconsistencies. -These inconsistencies include -directory inode numbers pointing to unallocated inodes, -directory inode numbers that are greater than -the number of inodes in the file system, -incorrect directory inode numbers for ``\fB.\fP'' and ``\fB..\fP'', -and directories that are not attached to the file system. -If the inode number in a directory data block -references an unallocated inode, -then -.I fsck -will remove that directory entry. -Again, -this condition can only arise when there has been a hardware failure. -.PP -If a directory entry inode number references -outside the inode list, then -.I fsck -will remove that directory entry. -This condition occurs if bad data is written into a directory data block. -.PP -The directory inode number entry for ``\fB.\fP'' -must be the first entry in the directory data block. -The inode number for ``\fB.\fP'' -must reference itself; -e.g., it must equal the inode number -for the directory data block. -The directory inode number entry -for ``\fB..\fP'' must be -the second entry in the directory data block. -Its value must equal the inode number for the -parent of the directory entry -(or the inode number of the directory -data block if the directory is the -root directory). -If the directory inode numbers are -incorrect, -.I fsck -will replace them with the correct values. -If there are multiple hard links to a directory, -the first one encountered is considered the real parent -to which ``\fB..\fP'' should point; -\fIfsck\fP recommends deletion for the subsequently discovered names. -.NH 2 -File system connectivity -.PP -.I Fsck -checks the general connectivity of the file system. -If directories are not linked into the file system, then -.I fsck -links the directory back into the file system in the -.I lost+found -directory. -This condition only occurs when there has been a hardware failure. -.ds RH "References" -.SH -\s+2Acknowledgements\s0 -.PP -I thank Bill Joy, Sam Leffler, Robert Elz and Dennis Ritchie -for their suggestions and help in implementing the new file system. -Thanks also to Robert Henry for his editorial input to -get this document together. -Finally we thank our sponsors, -the National Science Foundation under grant MCS80-05144, -and the Defense Advance Research Projects Agency (DoD) under -Arpa Order No. 4031 monitored by Naval Electronic System Command under -Contract No. N00039-82-C-0235. (Kirk McKusick, July 1983) -.PP -I would like to thank Larry A. Wehr for advice that lead -to the first version of -.I fsck -and Rick B. Brandt for adapting -.I fsck -to -UNIX/TS. (T. Kowalski, July 1979) -.sp 2 -.SH -\s+2References\s0 -.LP -.IP [Dolotta78] 20 -Dolotta, T. A., and Olsson, S. B. eds., -.I "UNIX User's Manual, Edition 1.1\^" , -January 1978. -.IP [Joy83] 20 -Joy, W., Cooper, E., Fabry, R., Leffler, S., McKusick, M., and Mosher, D. -4.2BSD System Manual, -.I "University of California at Berkeley" , -.I "Computer Systems Research Group Technical Report" -#4, 1982. -.IP [McKusick84] 20 -McKusick, M., Joy, W., Leffler, S., and Fabry, R. -A Fast File System for UNIX, -\fIACM Transactions on Computer Systems 2\fP, 3. -pp. 181-197, August 1984. -.IP [Ritchie78] 20 -Ritchie, D. M., and Thompson, K., -The UNIX Time-Sharing System, -.I "The Bell System Technical Journal" -.B 57 , -6 (July-August 1978, Part 2), pp. 1905-29. -.IP [Thompson78] 20 -Thompson, K., -UNIX Implementation, -.I "The Bell System Technical Journal\^" -.B 57 , -6 (July-August 1978, Part 2), pp. 1931-46. -.ds RH Appendix A \- Fsck Error Conditions -.bp diff --git a/sbin/fsck/SMM.doc/4.t b/sbin/fsck/SMM.doc/4.t deleted file mode 100644 index 3045b3abb55..00000000000 --- a/sbin/fsck/SMM.doc/4.t +++ /dev/null @@ -1,1426 +0,0 @@ -.\" $NetBSD: 4.t,v 1.2 1995/03/18 14:56:12 cgd Exp $ -.\" -.\" Copyright (c) 1982, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)4.t 8.1 (Berkeley) 6/5/93 -.\" -.ds RH Appendix A \- Fsck Error Conditions -.NH -Appendix A \- Fsck Error Conditions -.NH 2 -Conventions -.PP -.I Fsck -is -a multi-pass file system check program. -Each file system pass invokes a different Phase of the -.I fsck -program. -After the initial setup, -.I fsck -performs successive Phases over each file system, -checking blocks and sizes, -path-names, -connectivity, -reference counts, -and the map of free blocks, -(possibly rebuilding it), -and performs some cleanup. -.LP -Normally -.I fsck -is run non-interactively to -.I preen -the file systems after an unclean halt. -While preen'ing a file system, -it will only fix corruptions that are expected -to occur from an unclean halt. -These actions are a proper subset of the actions that -.I fsck -will take when it is running interactively. -Throughout this appendix many errors have several options -that the operator can take. -When an inconsistency is detected, -.I fsck -reports the error condition to the operator. -If a response is required, -.I fsck -prints a prompt message and -waits for a response. -When preen'ing most errors are fatal. -For those that are expected, -the response taken is noted. -This appendix explains the meaning of each error condition, -the possible responses, and the related error conditions. -.LP -The error conditions are organized by the -.I Phase -of the -.I fsck -program in which they can occur. -The error conditions that may occur -in more than one Phase -will be discussed in initialization. -.NH 2 -Initialization -.PP -Before a file system check can be performed, certain -tables have to be set up and certain files opened. -This section concerns itself with the opening of files and -the initialization of tables. -This section lists error conditions resulting from -command line options, -memory requests, -opening of files, -status of files, -file system size checks, -and creation of the scratch file. -All the initialization errors are fatal -when the file system is being preen'ed. -.sp -.LP -.B "\fIC\fP option?" -.br -\fIC\fP is not a legal option to -.I fsck ; -legal options are \-b, \-c, \-y, \-n, and \-p. -.I Fsck -terminates on this error condition. -See the -.I fsck (8) -manual entry for further detail. -.sp -.LP -.B "cannot alloc NNN bytes for blockmap" -.br -.B "cannot alloc NNN bytes for freemap" -.br -.B "cannot alloc NNN bytes for statemap" -.br -.B "cannot alloc NNN bytes for lncntp" -.br -.I Fsck 's -request for memory for its virtual -memory tables failed. -This should never happen. -.I Fsck -terminates on this error condition. -See a guru. -.sp -.LP -.B "Can't open checklist file: \fIF\fP" -.br -The file system checklist file -\fIF\fP (usually -.I /etc/fstab ) -can not be opened for reading. -.I Fsck -terminates on this error condition. -Check access modes of \fIF\fP. -.sp -.LP -.B "Can't stat root" -.br -.I Fsck 's -request for statistics about the root directory ``/'' failed. -This should never happen. -.I Fsck -terminates on this error condition. -See a guru. -.sp -.LP -.B "Can't stat \fIF\fP" -.br -.B "Can't make sense out of name \fIF\fP" -.br -.I Fsck 's -request for statistics about the file system \fIF\fP failed. -When running manually, -it ignores this file system -and continues checking the next file system given. -Check access modes of \fIF\fP. -.sp -.LP -.B "Can't open \fIF\fP" -.br -.I Fsck 's -request attempt to open the file system \fIF\fP failed. -When running manually, it ignores this file system -and continues checking the next file system given. -Check access modes of \fIF\fP. -.sp -.LP -.B "\fIF\fP: (NO WRITE)" -.br -Either the \-n flag was specified or -.I fsck 's -attempt to open the file system \fIF\fP for writing failed. -When running manually, -all the diagnostics are printed out, -but no modifications are attempted to fix them. -.sp -.LP -.B "file is not a block or character device; OK" -.br -You have given -.I fsck -a regular file name by mistake. -Check the type of the file specified. -.LP -Possible responses to the OK prompt are: -.IP YES -ignore this error condition. -.IP NO -ignore this file system and continues checking -the next file system given. -.sp -.LP -.B "UNDEFINED OPTIMIZATION IN SUPERBLOCK (SET TO DEFAULT)" -.br -The superblock optimization parameter is neither OPT_TIME -nor OPT_SPACE. -.LP -Possible responses to the SET TO DEFAULT prompt are: -.IP YES -The superblock is set to request optimization to minimize -running time of the system. -(If optimization to minimize disk space utilization is -desired, it can be set using \fItunefs\fP(8).) -.IP NO -ignore this error condition. -.sp -.LP -.B "IMPOSSIBLE MINFREE=\fID\fP IN SUPERBLOCK (SET TO DEFAULT)" -.br -The superblock minimum space percentage is greater than 99% -or less then 0%. -.LP -Possible responses to the SET TO DEFAULT prompt are: -.IP YES -The minfree parameter is set to 10%. -(If some other percentage is desired, -it can be set using \fItunefs\fP(8).) -.IP NO -ignore this error condition. -.sp -.LP -.B "IMPOSSIBLE INTERLEAVE=\fID\fP IN SUPERBLOCK (SET TO DEFAULT)" -.br -The file system interleave is less than or equal to zero. -.LP -Possible responses to the SET TO DEFAULT prompt are: -.IP YES -The interleave parameter is set to 1. -.IP NO -ignore this error condition. -.sp -.LP -.B "IMPOSSIBLE NPSECT=\fID\fP IN SUPERBLOCK (SET TO DEFAULT)" -.br -The number of physical sectors per track is less than the number -of usable sectors per track. -.LP -Possible responses to the SET TO DEFAULT prompt are: -.IP YES -The npsect parameter is set to the number of usable sectors per track. -.IP NO -ignore this error condition. -.sp -.LP -One of the following messages will appear: -.br -.B "MAGIC NUMBER WRONG" -.br -.B "NCG OUT OF RANGE" -.br -.B "CPG OUT OF RANGE" -.br -.B "NCYL DOES NOT JIVE WITH NCG*CPG" -.br -.B "SIZE PREPOSTEROUSLY LARGE" -.br -.B "TRASHED VALUES IN SUPER BLOCK" -.br -and will be followed by the message: -.br -.B "\fIF\fP: BAD SUPER BLOCK: \fIB\fP" -.br -.B "USE -b OPTION TO FSCK TO SPECIFY LOCATION OF AN ALTERNATE" -.br -.B "SUPER-BLOCK TO SUPPLY NEEDED INFORMATION; SEE fsck(8)." -.br -The super block has been corrupted. -An alternative super block must be selected from among those -listed by -.I newfs -(8) when the file system was created. -For file systems with a blocksize less than 32K, -specifying \-b 32 is a good first choice. -.sp -.LP -.B "INTERNAL INCONSISTENCY: \fIM\fP" -.br -.I Fsck 's -has had an internal panic, whose message is specified as \fIM\fP. -This should never happen. -See a guru. -.sp -.LP -.B "CAN NOT SEEK: BLK \fIB\fP (CONTINUE)" -.br -.I Fsck 's -request for moving to a specified block number \fIB\fP in -the file system failed. -This should never happen. -See a guru. -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -attempt to continue to run the file system check. -Often, -however the problem will persist. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -If the block was part of the virtual memory buffer -cache, -.I fsck -will terminate with the message ``Fatal I/O error''. -.IP NO -terminate the program. -.sp -.LP -.B "CAN NOT READ: BLK \fIB\fP (CONTINUE)" -.br -.I Fsck 's -request for reading a specified block number \fIB\fP in -the file system failed. -This should never happen. -See a guru. -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -attempt to continue to run the file system check. -It will retry the read and print out the message: -.br -.B "THE FOLLOWING SECTORS COULD NOT BE READ: \fIN\fP" -.br -where \fIN\fP indicates the sectors that could not be read. -If -.I fsck -ever tries to write back one of the blocks on which the read failed -it will print the message: -.br -.B "WRITING ZERO'ED BLOCK \fIN\fP TO DISK" -.br -where \fIN\fP indicates the sector that was written with zero's. -If the disk is experiencing hardware problems, the problem will persist. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -If the block was part of the virtual memory buffer -cache, -.I fsck -will terminate with the message ``Fatal I/O error''. -.IP NO -terminate the program. -.sp -.LP -.B "CAN NOT WRITE: BLK \fIB\fP (CONTINUE)" -.br -.I Fsck 's -request for writing a specified block number \fIB\fP -in the file system failed. -The disk is write-protected; -check the write protect lock on the drive. -If that is not the problem, see a guru. -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -attempt to continue to run the file system check. -The write operation will be retried with the failed blocks -indicated by the message: -.br -.B "THE FOLLOWING SECTORS COULD NOT BE WRITTEN: \fIN\fP" -.br -where \fIN\fP indicates the sectors that could not be written. -If the disk is experiencing hardware problems, the problem will persist. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -If the block was part of the virtual memory buffer -cache, -.I fsck -will terminate with the message ``Fatal I/O error''. -.IP NO -terminate the program. -.sp -.LP -.B "bad inode number DDD to ginode" -.br -An internal error has attempted to read non-existent inode \fIDDD\fP. -This error causes -.I fsck -to exit. -See a guru. -.NH 2 -Phase 1 \- Check Blocks and Sizes -.PP -This phase concerns itself with -the inode list. -This section lists error conditions resulting from -checking inode types, -setting up the zero-link-count table, -examining inode block numbers for bad or duplicate blocks, -checking inode size, -and checking inode format. -All errors in this phase except -.B "INCORRECT BLOCK COUNT" -and -.B "PARTIALLY TRUNCATED INODE" -are fatal if the file system is being preen'ed. -.sp -.LP -.B "UNKNOWN FILE TYPE I=\fII\fP (CLEAR)" -.br -The mode word of the inode \fII\fP indicates that the inode is not a -special block inode, special character inode, socket inode, regular inode, -symbolic link, or directory inode. -.LP -Possible responses to the CLEAR prompt are: -.IP YES -de-allocate inode \fII\fP by zeroing its contents. -This will always invoke the UNALLOCATED error condition in Phase 2 -for each directory entry pointing to this inode. -.IP NO -ignore this error condition. -.sp -.LP -.B "PARTIALLY TRUNCATED INODE I=\fII\fP (SALVAGE)" -.br -.I Fsck -has found inode \fII\fP whose size is shorter than the number of -blocks allocated to it. -This condition should only occur if the system crashes while in the -midst of truncating a file. -When preen'ing the file system, -.I fsck -completes the truncation to the specified size. -.LP -Possible responses to SALVAGE are: -.IP YES -complete the truncation to the size specified in the inode. -.IP NO -ignore this error condition. -.sp -.LP -.B "LINK COUNT TABLE OVERFLOW (CONTINUE)" -.br -An internal table for -.I fsck -containing allocated inodes with a link count of -zero cannot allocate more memory. -Increase the virtual memory for -.I fsck . -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -continue with the program. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -If another allocated inode with a zero link count is found, -this error condition is repeated. -.IP NO -terminate the program. -.sp -.LP -.B "\fIB\fP BAD I=\fII\fP" -.br -Inode \fII\fP contains block number \fIB\fP with a number -lower than the number of the first data block in the file system or -greater than the number of the last block -in the file system. -This error condition may invoke the -.B "EXCESSIVE BAD BLKS" -error condition in Phase 1 (see next paragraph) if -inode \fII\fP has too many block numbers outside the file system range. -This error condition will always invoke the -.B "BAD/DUP" -error condition in Phase 2 and Phase 4. -.sp -.LP -.B "EXCESSIVE BAD BLKS I=\fII\fP (CONTINUE)" -.br -There is more than a tolerable number (usually 10) of blocks with a number -lower than the number of the first data block in the file system or greater than -the number of last block in the file system associated with inode \fII\fP. -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -ignore the rest of the blocks in this inode -and continue checking with the next inode in the file system. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -.IP NO -terminate the program. -.sp -.LP -.B "BAD STATE DDD TO BLKERR" -.br -An internal error has scrambled -.I fsck 's -state map to have the impossible value \fIDDD\fP. -.I Fsck -exits immediately. -See a guru. -.sp -.LP -.B "\fIB\fP DUP I=\fII\fP" -.br -Inode \fII\fP contains block number \fIB\fP that is already claimed by -another inode. -This error condition may invoke the -.B "EXCESSIVE DUP BLKS" -error condition in Phase 1 if -inode \fII\fP has too many block numbers claimed by other inodes. -This error condition will always invoke Phase 1b and the -.B "BAD/DUP" -error condition in Phase 2 and Phase 4. -.sp -.LP -.B "EXCESSIVE DUP BLKS I=\fII\fP (CONTINUE)" -.br -There is more than a tolerable number (usually 10) of blocks claimed by other -inodes. -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -ignore the rest of the blocks in this inode -and continue checking with the next inode in the file system. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -.IP NO -terminate the program. -.sp -.LP -.B "DUP TABLE OVERFLOW (CONTINUE)" -.br -An internal table in -.I fsck -containing duplicate block numbers cannot allocate any more space. -Increase the amount of virtual memory available to -.I fsck . -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -continue with the program. -This error condition will not allow a complete check of the file system. -A second run of -.I fsck -should be made to re-check this file system. -If another duplicate block is found, this error condition will repeat. -.IP NO -terminate the program. -.sp -.LP -.B "PARTIALLY ALLOCATED INODE I=\fII\fP (CLEAR)" -.br -Inode \fII\fP is neither allocated nor unallocated. -.LP -Possible responses to the CLEAR prompt are: -.IP YES -de-allocate inode \fII\fP by zeroing its contents. -.IP NO -ignore this error condition. -.sp -.LP -.B "INCORRECT BLOCK COUNT I=\fII\fP (\fIX\fP should be \fIY\fP) (CORRECT)" -.br -The block count for inode \fII\fP is \fIX\fP blocks, -but should be \fIY\fP blocks. -When preen'ing the count is corrected. -.LP -Possible responses to the CORRECT prompt are: -.IP YES -replace the block count of inode \fII\fP with \fIY\fP. -.IP NO -ignore this error condition. -.NH 2 -Phase 1B: Rescan for More Dups -.PP -When a duplicate block is found in the file system, the file system is -rescanned to find the inode that previously claimed that block. -This section lists the error condition when the duplicate block is found. -.sp -.LP -.B "\fIB\fP DUP I=\fII\fP" -.br -Inode \fII\fP contains block number \fIB\fP that -is already claimed by another inode. -This error condition will always invoke the -.B "BAD/DUP" -error condition in Phase 2. -You can determine which inodes have overlapping blocks by examining -this error condition and the DUP error condition in Phase 1. -.NH 2 -Phase 2 \- Check Pathnames -.PP -This phase concerns itself with removing directory entries -pointing to -error conditioned inodes -from Phase 1 and Phase 1b. -This section lists error conditions resulting from -root inode mode and status, -directory inode pointers in range, -and directory entries pointing to bad inodes, -and directory integrity checks. -All errors in this phase are fatal if the file system is being preen'ed, -except for directories not being a multiple of the blocks size -and extraneous hard links. -.sp -.LP -.B "ROOT INODE UNALLOCATED (ALLOCATE)" -.br -The root inode (usually inode number 2) has no allocate mode bits. -This should never happen. -.LP -Possible responses to the ALLOCATE prompt are: -.IP YES -allocate inode 2 as the root inode. -The files and directories usually found in the root will be recovered -in Phase 3 and put into -.I lost+found . -If the attempt to allocate the root fails, -.I fsck -will exit with the message: -.br -.B "CANNOT ALLOCATE ROOT INODE" . -.IP NO -.I fsck -will exit. -.sp -.LP -.B "ROOT INODE NOT DIRECTORY (REALLOCATE)" -.br -The root inode (usually inode number 2) -is not directory inode type. -.LP -Possible responses to the REALLOCATE prompt are: -.IP YES -clear the existing contents of the root inode -and reallocate it. -The files and directories usually found in the root will be recovered -in Phase 3 and put into -.I lost+found . -If the attempt to allocate the root fails, -.I fsck -will exit with the message: -.br -.B "CANNOT ALLOCATE ROOT INODE" . -.IP NO -.I fsck -will then prompt with -.B "FIX" -.LP -Possible responses to the FIX prompt are: -.IP YES -replace the root inode's type to be a directory. -If the root inode's data blocks are not directory blocks, -many error conditions will be produced. -.IP NO -terminate the program. -.sp -.LP -.B "DUPS/BAD IN ROOT INODE (REALLOCATE)" -.br -Phase 1 or Phase 1b have found duplicate blocks -or bad blocks in the root inode (usually inode number 2) for the file system. -.LP -Possible responses to the REALLOCATE prompt are: -.IP YES -clear the existing contents of the root inode -and reallocate it. -The files and directories usually found in the root will be recovered -in Phase 3 and put into -.I lost+found . -If the attempt to allocate the root fails, -.I fsck -will exit with the message: -.br -.B "CANNOT ALLOCATE ROOT INODE" . -.IP NO -.I fsck -will then prompt with -.B "CONTINUE" . -.LP -Possible responses to the CONTINUE prompt are: -.IP YES -ignore the -.B "DUPS/BAD" -error condition in the root inode and -attempt to continue to run the file system check. -If the root inode is not correct, -then this may result in many other error conditions. -.IP NO -terminate the program. -.sp -.LP -.B "NAME TOO LONG \fIF\fP" -.br -An excessively long path name has been found. -This usually indicates loops in the file system name space. -This can occur if the super user has made circular links to directories. -The offending links must be removed (by a guru). -.sp -.LP -.B "I OUT OF RANGE I=\fII\fP NAME=\fIF\fP (REMOVE)" -.br -A directory entry \fIF\fP has an inode number \fII\fP that is greater than -the end of the inode list. -.LP -Possible responses to the REMOVE prompt are: -.IP YES -the directory entry \fIF\fP is removed. -.IP NO -ignore this error condition. -.sp -.LP -.B "UNALLOCATED I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP \fItype\fP=\fIF\fP (REMOVE)" -.br -A directory or file entry \fIF\fP points to an unallocated inode \fII\fP. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, modify time \fIT\fP, -and name \fIF\fP are printed. -.LP -Possible responses to the REMOVE prompt are: -.IP YES -the directory entry \fIF\fP is removed. -.IP NO -ignore this error condition. -.sp -.LP -.B "DUP/BAD I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP \fItype\fP=\fIF\fP (REMOVE)" -.br -Phase 1 or Phase 1b have found duplicate blocks or bad blocks -associated with directory or file entry \fIF\fP, inode \fII\fP. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, modify time \fIT\fP, -and directory name \fIF\fP are printed. -.LP -Possible responses to the REMOVE prompt are: -.IP YES -the directory entry \fIF\fP is removed. -.IP NO -ignore this error condition. -.sp -.LP -.B "ZERO LENGTH DIRECTORY I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (REMOVE)" -.br -A directory entry \fIF\fP has a size \fIS\fP that is zero. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, modify time \fIT\fP, -and directory name \fIF\fP are printed. -.LP -Possible responses to the REMOVE prompt are: -.IP YES -the directory entry \fIF\fP is removed; -this will always invoke the BAD/DUP error condition in Phase 4. -.IP NO -ignore this error condition. -.sp -.LP -.B "DIRECTORY TOO SHORT I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fIF\fP has been found whose size \fIS\fP -is less than the minimum size directory. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, modify time \fIT\fP, -and directory name \fIF\fP are printed. -.LP -Possible responses to the FIX prompt are: -.IP YES -increase the size of the directory to the minimum directory size. -.IP NO -ignore this directory. -.sp -.LP -.B "DIRECTORY \fIF\fP LENGTH \fIS\fP NOT MULTIPLE OF \fIB\fP (ADJUST) -.br -A directory \fIF\fP has been found with size \fIS\fP that is not -a multiple of the directory blocksize \fIB\fP. -.LP -Possible responses to the ADJUST prompt are: -.IP YES -the length is rounded up to the appropriate block size. -This error can occur on 4.2BSD file systems. -Thus when preen'ing the file system only a warning is printed -and the directory is adjusted. -.IP NO -ignore the error condition. -.sp -.LP -.B "DIRECTORY CORRUPTED I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (SALVAGE)" -.br -A directory with an inconsistent internal state has been found. -.LP -Possible responses to the FIX prompt are: -.IP YES -throw away all entries up to the next directory boundary (usually 512-byte) -boundary. -This drastic action can throw away up to 42 entries, -and should be taken only after other recovery efforts have failed. -.IP NO -skip up to the next directory boundary and resume reading, -but do not modify the directory. -.sp -.LP -.B "BAD INODE NUMBER FOR `.' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fII\fP has been found whose inode number for `.' does -does not equal \fII\fP. -.LP -Possible responses to the FIX prompt are: -.IP YES -change the inode number for `.' to be equal to \fII\fP. -.IP NO -leave the inode number for `.' unchanged. -.sp -.LP -.B "MISSING `.' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fII\fP has been found whose first entry is unallocated. -.LP -Possible responses to the FIX prompt are: -.IP YES -build an entry for `.' with inode number equal to \fII\fP. -.IP NO -leave the directory unchanged. -.sp -.LP -.B "MISSING `.' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP" -.br -.B "CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS \fIF\fP" -.br -A directory \fII\fP has been found whose first entry is \fIF\fP. -.I Fsck -cannot resolve this problem. -The file system should be mounted and the offending entry \fIF\fP -moved elsewhere. -The file system should then be unmounted and -.I fsck -should be run again. -.sp -.LP -.B "MISSING `.' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP" -.br -.B "CANNOT FIX, INSUFFICIENT SPACE TO ADD `.'" -.br -A directory \fII\fP has been found whose first entry is not `.'. -.I Fsck -cannot resolve this problem as it should never happen. -See a guru. -.sp -.LP -.B "EXTRA `.' ENTRY I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fII\fP has been found that has more than one entry for `.'. -.LP -Possible responses to the FIX prompt are: -.IP YES -remove the extra entry for `.'. -.IP NO -leave the directory unchanged. -.sp -.LP -.B "BAD INODE NUMBER FOR `..' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fII\fP has been found whose inode number for `..' does -does not equal the parent of \fII\fP. -.LP -Possible responses to the FIX prompt are: -.IP YES -change the inode number for `..' to be equal to the parent of \fII\fP -(``\fB..\fP'' in the root inode points to itself). -.IP NO -leave the inode number for `..' unchanged. -.sp -.LP -.B "MISSING `..' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fII\fP has been found whose second entry is unallocated. -.LP -Possible responses to the FIX prompt are: -.IP YES -build an entry for `..' with inode number equal to the parent of \fII\fP -(``\fB..\fP'' in the root inode points to itself). -.IP NO -leave the directory unchanged. -.sp -.LP -.B "MISSING `..' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP" -.br -.B "CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS \fIF\fP" -.br -A directory \fII\fP has been found whose second entry is \fIF\fP. -.I Fsck -cannot resolve this problem. -The file system should be mounted and the offending entry \fIF\fP -moved elsewhere. -The file system should then be unmounted and -.I fsck -should be run again. -.sp -.LP -.B "MISSING `..' I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP" -.br -.B "CANNOT FIX, INSUFFICIENT SPACE TO ADD `..'" -.br -A directory \fII\fP has been found whose second entry is not `..'. -.I Fsck -cannot resolve this problem. -The file system should be mounted and the second entry in the directory -moved elsewhere. -The file system should then be unmounted and -.I fsck -should be run again. -.sp -.LP -.B "EXTRA `..' ENTRY I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP DIR=\fIF\fP (FIX)" -.br -A directory \fII\fP has been found that has more than one entry for `..'. -.LP -Possible responses to the FIX prompt are: -.IP YES -remove the extra entry for `..'. -.IP NO -leave the directory unchanged. -.sp -.LP -.B "\fIN\fP IS AN EXTRANEOUS HARD LINK TO A DIRECTORY \fID\fP (REMOVE) -.br -.I Fsck -has found a hard link, \fIN\fP, to a directory, \fID\fP. -When preen'ing the extraneous links are ignored. -.LP -Possible responses to the REMOVE prompt are: -.IP YES -delete the extraneous entry, \fIN\fP. -.IP NO -ignore the error condition. -.sp -.LP -.B "BAD INODE \fIS\fP TO DESCEND" -.br -An internal error has caused an impossible state \fIS\fP to be passed to the -routine that descends the file system directory structure. -.I Fsck -exits. -See a guru. -.sp -.LP -.B "BAD RETURN STATE \fIS\fP FROM DESCEND" -.br -An internal error has caused an impossible state \fIS\fP to be returned -from the routine that descends the file system directory structure. -.I Fsck -exits. -See a guru. -.sp -.LP -.B "BAD STATE \fIS\fP FOR ROOT INODE" -.br -An internal error has caused an impossible state \fIS\fP to be assigned -to the root inode. -.I Fsck -exits. -See a guru. -.NH 2 -Phase 3 \- Check Connectivity -.PP -This phase concerns itself with the directory connectivity seen in -Phase 2. -This section lists error conditions resulting from -unreferenced directories, -and missing or full -.I lost+found -directories. -.sp -.LP -.B "UNREF DIR I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP (RECONNECT)" -.br -The directory inode \fII\fP was not connected to a directory entry -when the file system was traversed. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, and -modify time \fIT\fP of directory inode \fII\fP are printed. -When preen'ing, the directory is reconnected if its size is non-zero, -otherwise it is cleared. -.LP -Possible responses to the RECONNECT prompt are: -.IP YES -reconnect directory inode \fII\fP to the file system in the -directory for lost files (usually \fIlost+found\fP). -This may invoke the -.I lost+found -error condition in Phase 3 -if there are problems connecting directory inode \fII\fP to \fIlost+found\fP. -This may also invoke the CONNECTED error condition in Phase 3 if the link -was successful. -.IP NO -ignore this error condition. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "NO lost+found DIRECTORY (CREATE)" -.br -There is no -.I lost+found -directory in the root directory of the file system; -When preen'ing -.I fsck -tries to create a \fIlost+found\fP directory. -.LP -Possible responses to the CREATE prompt are: -.IP YES -create a \fIlost+found\fP directory in the root of the file system. -This may raise the message: -.br -.B "NO SPACE LEFT IN / (EXPAND)" -.br -See below for the possible responses. -Inability to create a \fIlost+found\fP directory generates the message: -.br -.B "SORRY. CANNOT CREATE lost+found DIRECTORY" -.br -and aborts the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.IP NO -abort the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "lost+found IS NOT A DIRECTORY (REALLOCATE)" -.br -The entry for -.I lost+found -is not a directory. -.LP -Possible responses to the REALLOCATE prompt are: -.IP YES -allocate a directory inode, and change \fIlost+found\fP to reference it. -The previous inode reference by the \fIlost+found\fP name is not cleared. -Thus it will either be reclaimed as an UNREF'ed inode or have its -link count ADJUST'ed later in this Phase. -Inability to create a \fIlost+found\fP directory generates the message: -.br -.B "SORRY. CANNOT CREATE lost+found DIRECTORY" -.br -and aborts the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.IP NO -abort the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "NO SPACE LEFT IN /lost+found (EXPAND)" -.br -There is no space to add another entry to the -.I lost+found -directory in the root directory -of the file system. -When preen'ing the -.I lost+found -directory is expanded. -.LP -Possible responses to the EXPAND prompt are: -.IP YES -the -.I lost+found -directory is expanded to make room for the new entry. -If the attempted expansion fails -.I fsck -prints the message: -.br -.B "SORRY. NO SPACE IN lost+found DIRECTORY" -.br -and aborts the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -Clean out unnecessary entries in -.I lost+found . -This error is fatal if the file system is being preen'ed. -.IP NO -abort the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "DIR I=\fII1\fP CONNECTED. PARENT WAS I=\fII2\fP" -.br -This is an advisory message indicating a directory inode \fII1\fP was -successfully connected to the -.I lost+found -directory. -The parent inode \fII2\fP of the directory inode \fII1\fP is -replaced by the inode number of the -.I lost+found -directory. -.sp -.LP -.B "DIRECTORY \fIF\fP LENGTH \fIS\fP NOT MULTIPLE OF \fIB\fP (ADJUST) -.br -A directory \fIF\fP has been found with size \fIS\fP that is not -a multiple of the directory blocksize \fIB\fP -(this can reoccur in Phase 3 if it is not adjusted in Phase 2). -.LP -Possible responses to the ADJUST prompt are: -.IP YES -the length is rounded up to the appropriate block size. -This error can occur on 4.2BSD file systems. -Thus when preen'ing the file system only a warning is printed -and the directory is adjusted. -.IP NO -ignore the error condition. -.sp -.LP -.B "BAD INODE \fIS\fP TO DESCEND" -.br -An internal error has caused an impossible state \fIS\fP to be passed to the -routine that descends the file system directory structure. -.I Fsck -exits. -See a guru. -.NH 2 -Phase 4 \- Check Reference Counts -.PP -This phase concerns itself with the link count information -seen in Phase 2 and Phase 3. -This section lists error conditions resulting from -unreferenced files, -missing or full -.I lost+found -directory, -incorrect link counts for files, directories, symbolic links, or special files, -unreferenced files, symbolic links, and directories, -and bad or duplicate blocks in files, symbolic links, and directories. -All errors in this phase are correctable if the file system is being preen'ed -except running out of space in the \fIlost+found\fP directory. -.sp -.LP -.B "UNREF FILE I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP (RECONNECT)" -.br -Inode \fII\fP was not connected to a directory entry -when the file system was traversed. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, and -modify time \fIT\fP of inode \fII\fP are printed. -When preen'ing the file is cleared if either its size or its -link count is zero, -otherwise it is reconnected. -.LP -Possible responses to the RECONNECT prompt are: -.IP YES -reconnect inode \fII\fP to the file system in the directory for -lost files (usually \fIlost+found\fP). -This may invoke the -.I lost+found -error condition in Phase 4 -if there are problems connecting inode \fII\fP to -.I lost+found . -.IP NO -ignore this error condition. -This will always invoke the CLEAR error condition in Phase 4. -.sp -.LP -.B "(CLEAR)" -.br -The inode mentioned in the immediately previous error condition can not be -reconnected. -This cannot occur if the file system is being preen'ed, -since lack of space to reconnect files is a fatal error. -.LP -Possible responses to the CLEAR prompt are: -.IP YES -de-allocate the inode mentioned in the immediately previous error condition by zeroing its contents. -.IP NO -ignore this error condition. -.sp -.LP -.B "NO lost+found DIRECTORY (CREATE)" -.br -There is no -.I lost+found -directory in the root directory of the file system; -When preen'ing -.I fsck -tries to create a \fIlost+found\fP directory. -.LP -Possible responses to the CREATE prompt are: -.IP YES -create a \fIlost+found\fP directory in the root of the file system. -This may raise the message: -.br -.B "NO SPACE LEFT IN / (EXPAND)" -.br -See below for the possible responses. -Inability to create a \fIlost+found\fP directory generates the message: -.br -.B "SORRY. CANNOT CREATE lost+found DIRECTORY" -.br -and aborts the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.IP NO -abort the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "lost+found IS NOT A DIRECTORY (REALLOCATE)" -.br -The entry for -.I lost+found -is not a directory. -.LP -Possible responses to the REALLOCATE prompt are: -.IP YES -allocate a directory inode, and change \fIlost+found\fP to reference it. -The previous inode reference by the \fIlost+found\fP name is not cleared. -Thus it will either be reclaimed as an UNREF'ed inode or have its -link count ADJUST'ed later in this Phase. -Inability to create a \fIlost+found\fP directory generates the message: -.br -.B "SORRY. CANNOT CREATE lost+found DIRECTORY" -.br -and aborts the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.IP NO -abort the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "NO SPACE LEFT IN /lost+found (EXPAND)" -.br -There is no space to add another entry to the -.I lost+found -directory in the root directory -of the file system. -When preen'ing the -.I lost+found -directory is expanded. -.LP -Possible responses to the EXPAND prompt are: -.IP YES -the -.I lost+found -directory is expanded to make room for the new entry. -If the attempted expansion fails -.I fsck -prints the message: -.br -.B "SORRY. NO SPACE IN lost+found DIRECTORY" -.br -and aborts the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -Clean out unnecessary entries in -.I lost+found . -This error is fatal if the file system is being preen'ed. -.IP NO -abort the attempt to linkup the lost inode. -This will always invoke the UNREF error condition in Phase 4. -.sp -.LP -.B "LINK COUNT \fItype\fP I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP COUNT=\fIX\fP SHOULD BE \fIY\fP (ADJUST)" -.br -The link count for inode \fII\fP, -is \fIX\fP but should be \fIY\fP. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, and modify time \fIT\fP -are printed. -When preen'ing the link count is adjusted unless the number of references -is increasing, a condition that should never occur unless precipitated -by a hardware failure. -When the number of references is increasing under preen mode, -.I fsck -exits with the message: -.br -.B "LINK COUNT INCREASING" -.LP -Possible responses to the ADJUST prompt are: -.IP YES -replace the link count of file inode \fII\fP with \fIY\fP. -.IP NO -ignore this error condition. -.sp -.LP -.B "UNREF \fItype\fP I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP (CLEAR)" -.br -Inode \fII\fP, was not connected to a directory entry when the -file system was traversed. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, -and modify time \fIT\fP of inode \fII\fP -are printed. -When preen'ing, -this is a file that was not connected because its size or link count was zero, -hence it is cleared. -.LP -Possible responses to the CLEAR prompt are: -.IP YES -de-allocate inode \fII\fP by zeroing its contents. -.IP NO -ignore this error condition. -.sp -.LP -.B "BAD/DUP \fItype\fP I=\fII\fP OWNER=\fIO\fP MODE=\fIM\fP SIZE=\fIS\fP MTIME=\fIT\fP (CLEAR)" -.br -Phase 1 or Phase 1b have found duplicate blocks -or bad blocks associated with -inode \fII\fP. -The owner \fIO\fP, mode \fIM\fP, size \fIS\fP, -and modify time \fIT\fP of inode \fII\fP -are printed. -This error cannot arise when the file system is being preen'ed, -as it would have caused a fatal error earlier. -.LP -Possible responses to the CLEAR prompt are: -.IP YES -de-allocate inode \fII\fP by zeroing its contents. -.IP NO -ignore this error condition. -.NH 2 -Phase 5 - Check Cyl groups -.PP -This phase concerns itself with the free-block and used-inode maps. -This section lists error conditions resulting from -allocated blocks in the free-block maps, -free blocks missing from free-block maps, -and the total free-block count incorrect. -It also lists error conditions resulting from -free inodes in the used-inode maps, -allocated inodes missing from used-inode maps, -and the total used-inode count incorrect. -.sp -.LP -.B "CG \fIC\fP: BAD MAGIC NUMBER" -.br -The magic number of cylinder group \fIC\fP is wrong. -This usually indicates that the cylinder group maps have been destroyed. -When running manually the cylinder group is marked as needing -to be reconstructed. -This error is fatal if the file system is being preen'ed. -.sp -.LP -.B "BLK(S) MISSING IN BIT MAPS (SALVAGE)" -.br -A cylinder group block map is missing some free blocks. -During preen'ing the maps are reconstructed. -.LP -Possible responses to the SALVAGE prompt are: -.IP YES -reconstruct the free block map. -.IP NO -ignore this error condition. -.sp -.LP -.B "SUMMARY INFORMATION BAD (SALVAGE)" -.br -The summary information was found to be incorrect. -When preen'ing, -the summary information is recomputed. -.LP -Possible responses to the SALVAGE prompt are: -.IP YES -reconstruct the summary information. -.IP NO -ignore this error condition. -.sp -.LP -.B "FREE BLK COUNT(S) WRONG IN SUPERBLOCK (SALVAGE)" -.br -The superblock free block information was found to be incorrect. -When preen'ing, -the superblock free block information is recomputed. -.LP -Possible responses to the SALVAGE prompt are: -.IP YES -reconstruct the superblock free block information. -.IP NO -ignore this error condition. -.NH 2 -Cleanup -.PP -Once a file system has been checked, a few cleanup functions are performed. -This section lists advisory messages about -the file system -and modify status of the file system. -.sp -.LP -.B "\fIV\fP files, \fIW\fP used, \fIX\fP free (\fIY\fP frags, \fIZ\fP blocks)" -.br -This is an advisory message indicating that -the file system checked contained -\fIV\fP files using -\fIW\fP fragment sized blocks leaving -\fIX\fP fragment sized blocks free in the file system. -The numbers in parenthesis breaks the free count down into -\fIY\fP free fragments and -\fIZ\fP free full sized blocks. -.sp -.LP -.B "***** REBOOT UNIX *****" -.br -This is an advisory message indicating that -the root file system has been modified by -.I fsck. -If UNIX is not rebooted immediately, -the work done by -.I fsck -may be undone by the in-core copies of tables -UNIX keeps. -When preen'ing, -.I fsck -will exit with a code of 4. -The standard auto-reboot script distributed with 4.3BSD -interprets an exit code of 4 by issuing a reboot system call. -.sp -.LP -.B "***** FILE SYSTEM WAS MODIFIED *****" -.br -This is an advisory message indicating that -the current file system was modified by -.I fsck. -If this file system is mounted or is the current root file system, -.I fsck -should be halted and UNIX rebooted. -If UNIX is not rebooted immediately, -the work done by -.I fsck -may be undone by the in-core copies of tables -UNIX keeps. diff --git a/sbin/fsck/SMM.doc/Makefile b/sbin/fsck/SMM.doc/Makefile deleted file mode 100644 index f6c1f7ce621..00000000000 --- a/sbin/fsck/SMM.doc/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $NetBSD: Makefile,v 1.2 1995/03/18 14:56:15 cgd Exp $ -# @(#)Makefile 8.1 (Berkeley) 6/8/93 - -DIR= smm/03.fsck -SRCS= 0.t 1.t 2.t 3.t 4.t -MACROS= -ms - -.include diff --git a/sbin/fsck/dir.c b/sbin/fsck/dir.c deleted file mode 100644 index 37a1fc3c904..00000000000 --- a/sbin/fsck/dir.c +++ /dev/null @@ -1,728 +0,0 @@ -/* $NetBSD: dir.c,v 1.17 1995/03/18 14:55:40 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)dir.c 8.5 (Berkeley) 12/8/94"; -#else -static char rcsid[] = "$NetBSD: dir.c,v 1.17 1995/03/18 14:55:40 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "fsck.h" -#include "extern.h" - -char *lfname = "lost+found"; -int lfmode = 01777; -struct dirtemplate emptydir = { 0, DIRBLKSIZ }; -struct dirtemplate dirhead = { - 0, 12, DT_DIR, 1, ".", - 0, DIRBLKSIZ - 12, DT_DIR, 2, ".." -}; -struct odirtemplate odirhead = { - 0, 12, 1, ".", - 0, DIRBLKSIZ - 12, 2, ".." -}; - -int expanddir __P((struct dinode *, char *)); -void freedir __P((ino_t, ino_t)); -struct direct *fsck_readdir(); -struct bufarea *getdirblk(); -int lftempname __P((char *, ino_t)); - -/* - * Propagate connected state through the tree. - */ -void -propagate() -{ - register struct inoinfo **inpp, *inp; - struct inoinfo **inpend; - long change; - - inpend = &inpsort[inplast]; - do { - change = 0; - for (inpp = inpsort; inpp < inpend; inpp++) { - inp = *inpp; - if (inp->i_parent == 0) - continue; - if (statemap[inp->i_parent] == DFOUND && - statemap[inp->i_number] == DSTATE) { - statemap[inp->i_number] = DFOUND; - change++; - } - } - } while (change > 0); -} - -/* - * Scan each entry in a directory block. - */ -int -dirscan(idesc) - register struct inodesc *idesc; -{ - register struct direct *dp; - register struct bufarea *bp; - int dsize, n; - long blksiz; - char dbuf[DIRBLKSIZ]; - - if (idesc->id_type != DATA) - errexit("wrong type to dirscan %d\n", idesc->id_type); - if (idesc->id_entryno == 0 && - (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0) - idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ); - blksiz = idesc->id_numfrags * sblock.fs_fsize; - if (chkrange(idesc->id_blkno, idesc->id_numfrags)) { - idesc->id_filesize -= blksiz; - return (SKIP); - } - idesc->id_loc = 0; - for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) { - dsize = dp->d_reclen; - memcpy(dbuf, dp, (size_t)dsize); -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (!newinofmt) { - struct direct *tdp = (struct direct *)dbuf; - u_char tmp; - - tmp = tdp->d_namlen; - tdp->d_namlen = tdp->d_type; - tdp->d_type = tmp; - } -# endif - idesc->id_dirp = (struct direct *)dbuf; - if ((n = (*idesc->id_func)(idesc)) & ALTERED) { -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (!newinofmt && !doinglevel2) { - struct direct *tdp; - u_char tmp; - - tdp = (struct direct *)dbuf; - tmp = tdp->d_namlen; - tdp->d_namlen = tdp->d_type; - tdp->d_type = tmp; - } -# endif - bp = getdirblk(idesc->id_blkno, blksiz); - memcpy(bp->b_un.b_buf + idesc->id_loc - dsize, dbuf, - (size_t)dsize); - dirty(bp); - sbdirty(); - } - if (n & STOP) - return (n); - } - return (idesc->id_filesize > 0 ? KEEPON : STOP); -} - -/* - * get next entry in a directory. - */ -struct direct * -fsck_readdir(idesc) - register struct inodesc *idesc; -{ - register struct direct *dp, *ndp; - register struct bufarea *bp; - long size, blksiz, fix, dploc; - - blksiz = idesc->id_numfrags * sblock.fs_fsize; - bp = getdirblk(idesc->id_blkno, blksiz); - if (idesc->id_loc % DIRBLKSIZ == 0 && idesc->id_filesize > 0 && - idesc->id_loc < blksiz) { - dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc); - if (dircheck(idesc, dp)) - goto dpok; - if (idesc->id_fix == IGNORE) - return (0); - fix = dofix(idesc, "DIRECTORY CORRUPTED"); - bp = getdirblk(idesc->id_blkno, blksiz); - dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc); - dp->d_reclen = DIRBLKSIZ; - dp->d_ino = 0; - dp->d_type = 0; - dp->d_namlen = 0; - dp->d_name[0] = '\0'; - if (fix) - dirty(bp); - idesc->id_loc += DIRBLKSIZ; - idesc->id_filesize -= DIRBLKSIZ; - return (dp); - } -dpok: - if (idesc->id_filesize <= 0 || idesc->id_loc >= blksiz) - return NULL; - dploc = idesc->id_loc; - dp = (struct direct *)(bp->b_un.b_buf + dploc); - idesc->id_loc += dp->d_reclen; - idesc->id_filesize -= dp->d_reclen; - if ((idesc->id_loc % DIRBLKSIZ) == 0) - return (dp); - ndp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc); - if (idesc->id_loc < blksiz && idesc->id_filesize > 0 && - dircheck(idesc, ndp) == 0) { - size = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ); - idesc->id_loc += size; - idesc->id_filesize -= size; - if (idesc->id_fix == IGNORE) - return (0); - fix = dofix(idesc, "DIRECTORY CORRUPTED"); - bp = getdirblk(idesc->id_blkno, blksiz); - dp = (struct direct *)(bp->b_un.b_buf + dploc); - dp->d_reclen += size; - if (fix) - dirty(bp); - } - return (dp); -} - -/* - * Verify that a directory entry is valid. - * This is a superset of the checks made in the kernel. - */ -int -dircheck(idesc, dp) - struct inodesc *idesc; - register struct direct *dp; -{ - register int size; - register char *cp; - u_char namlen, type; - int spaceleft; - - spaceleft = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ); - if (dp->d_ino >= maxino || - dp->d_reclen == 0 || - dp->d_reclen > spaceleft || - (dp->d_reclen & 0x3) != 0) - return (0); - if (dp->d_ino == 0) - return (1); - size = DIRSIZ(!newinofmt, dp); -# if (BYTE_ORDER == LITTLE_ENDIAN) - if (!newinofmt) { - type = dp->d_namlen; - namlen = dp->d_type; - } else { - namlen = dp->d_namlen; - type = dp->d_type; - } -# else - namlen = dp->d_namlen; - type = dp->d_type; -# endif - if (dp->d_reclen < size || - idesc->id_filesize < size || - namlen > MAXNAMLEN || - type > 15) - return (0); - for (cp = dp->d_name, size = 0; size < namlen; size++) - if (*cp == '\0' || (*cp++ == '/')) - return (0); - if (*cp != '\0') - return (0); - return (1); -} - -void -direrror(ino, errmesg) - ino_t ino; - char *errmesg; -{ - - fileerror(ino, ino, errmesg); -} - -void -fileerror(cwd, ino, errmesg) - ino_t cwd, ino; - char *errmesg; -{ - register struct dinode *dp; - char pathbuf[MAXPATHLEN + 1]; - - pwarn("%s ", errmesg); - pinode(ino); - printf("\n"); - getpathname(pathbuf, cwd, ino); - if (ino < ROOTINO || ino > maxino) { - pfatal("NAME=%s\n", pathbuf); - return; - } - dp = ginode(ino); - if (ftypeok(dp)) - pfatal("%s=%s\n", - (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE", pathbuf); - else - pfatal("NAME=%s\n", pathbuf); -} - -void -adjust(idesc, lcnt) - register struct inodesc *idesc; - short lcnt; -{ - register struct dinode *dp; - - dp = ginode(idesc->id_number); - if (dp->di_nlink == lcnt) { - if (linkup(idesc->id_number, (ino_t)0) == 0) - clri(idesc, "UNREF", 0); - } else { - pwarn("LINK COUNT %s", (lfdir == idesc->id_number) ? lfname : - ((dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE")); - pinode(idesc->id_number); - printf(" COUNT %d SHOULD BE %d", - dp->di_nlink, dp->di_nlink - lcnt); - if (preen) { - if (lcnt < 0) { - printf("\n"); - pfatal("LINK COUNT INCREASING"); - } - printf(" (ADJUSTED)\n"); - } - if (preen || reply("ADJUST") == 1) { - dp->di_nlink -= lcnt; - inodirty(); - } - } -} - -int -mkentry(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - struct direct newent; - int newlen, oldlen; - - newent.d_namlen = strlen(idesc->id_name); - newlen = DIRSIZ(0, &newent); - if (dirp->d_ino != 0) - oldlen = DIRSIZ(0, dirp); - else - oldlen = 0; - if (dirp->d_reclen - oldlen < newlen) - return (KEEPON); - newent.d_reclen = dirp->d_reclen - oldlen; - dirp->d_reclen = oldlen; - dirp = (struct direct *)(((char *)dirp) + oldlen); - dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */ - dirp->d_reclen = newent.d_reclen; - if (newinofmt) - dirp->d_type = typemap[idesc->id_parent]; - else - dirp->d_type = 0; - dirp->d_namlen = newent.d_namlen; - memcpy(dirp->d_name, idesc->id_name, (size_t)dirp->d_namlen + 1); -# if (BYTE_ORDER == LITTLE_ENDIAN) - /* - * If the entry was split, dirscan() will only reverse the byte - * order of the original entry, and not the new one, before - * writing it back out. So, we reverse the byte order here if - * necessary. - */ - if (oldlen != 0 && !newinofmt && !doinglevel2) { - u_char tmp; - - tmp = dirp->d_namlen; - dirp->d_namlen = dirp->d_type; - dirp->d_type = tmp; - } -# endif - return (ALTERED|STOP); -} - -int -chgino(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - - if (memcmp(dirp->d_name, idesc->id_name, (int)dirp->d_namlen + 1)) - return (KEEPON); - dirp->d_ino = idesc->id_parent; - if (newinofmt) - dirp->d_type = typemap[idesc->id_parent]; - else - dirp->d_type = 0; - return (ALTERED|STOP); -} - -int -linkup(orphan, parentdir) - ino_t orphan; - ino_t parentdir; -{ - register struct dinode *dp; - int lostdir; - ino_t oldlfdir; - struct inodesc idesc; - char tempname[BUFSIZ]; - - memset(&idesc, 0, sizeof(struct inodesc)); - dp = ginode(orphan); - lostdir = (dp->di_mode & IFMT) == IFDIR; - pwarn("UNREF %s ", lostdir ? "DIR" : "FILE"); - pinode(orphan); - if (preen && dp->di_size == 0) - return (0); - if (preen) - printf(" (RECONNECTED)\n"); - else - if (reply("RECONNECT") == 0) - return (0); - if (lfdir == 0) { - dp = ginode(ROOTINO); - idesc.id_name = lfname; - idesc.id_type = DATA; - idesc.id_func = findino; - idesc.id_number = ROOTINO; - if ((ckinode(dp, &idesc) & FOUND) != 0) { - lfdir = idesc.id_parent; - } else { - pwarn("NO lost+found DIRECTORY"); - if (preen || reply("CREATE")) { - lfdir = allocdir(ROOTINO, (ino_t)0, lfmode); - if (lfdir != 0) { - if (makeentry(ROOTINO, lfdir, lfname) != 0) { - if (preen) - printf(" (CREATED)\n"); - } else { - freedir(lfdir, ROOTINO); - lfdir = 0; - if (preen) - printf("\n"); - } - } - } - } - if (lfdir == 0) { - pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY"); - printf("\n\n"); - return (0); - } - } - dp = ginode(lfdir); - if ((dp->di_mode & IFMT) != IFDIR) { - pfatal("lost+found IS NOT A DIRECTORY"); - if (reply("REALLOCATE") == 0) - return (0); - oldlfdir = lfdir; - if ((lfdir = allocdir(ROOTINO, (ino_t)0, lfmode)) == 0) { - pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); - return (0); - } - if ((changeino(ROOTINO, lfname, lfdir) & ALTERED) == 0) { - pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); - return (0); - } - inodirty(); - idesc.id_type = ADDR; - idesc.id_func = pass4check; - idesc.id_number = oldlfdir; - adjust(&idesc, lncntp[oldlfdir] + 1); - lncntp[oldlfdir] = 0; - dp = ginode(lfdir); - } - if (statemap[lfdir] != DFOUND) { - pfatal("SORRY. NO lost+found DIRECTORY\n\n"); - return (0); - } - (void)lftempname(tempname, orphan); - if (makeentry(lfdir, orphan, tempname) == 0) { - pfatal("SORRY. NO SPACE IN lost+found DIRECTORY"); - printf("\n\n"); - return (0); - } - lncntp[orphan]--; - if (lostdir) { - if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 && - parentdir != (ino_t)-1) - (void)makeentry(orphan, lfdir, ".."); - dp = ginode(lfdir); - dp->di_nlink++; - inodirty(); - lncntp[lfdir]++; - pwarn("DIR I=%lu CONNECTED. ", orphan); - if (parentdir != (ino_t)-1) - printf("PARENT WAS I=%lu\n", parentdir); - if (preen == 0) - printf("\n"); - } - return (1); -} - -/* - * fix an entry in a directory. - */ -int -changeino(dir, name, newnum) - ino_t dir; - char *name; - ino_t newnum; -{ - struct inodesc idesc; - - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = DATA; - idesc.id_func = chgino; - idesc.id_number = dir; - idesc.id_fix = DONTKNOW; - idesc.id_name = name; - idesc.id_parent = newnum; /* new value for name */ - return (ckinode(ginode(dir), &idesc)); -} - -/* - * make an entry in a directory - */ -int -makeentry(parent, ino, name) - ino_t parent, ino; - char *name; -{ - struct dinode *dp; - struct inodesc idesc; - char pathbuf[MAXPATHLEN + 1]; - - if (parent < ROOTINO || parent >= maxino || - ino < ROOTINO || ino >= maxino) - return (0); - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = DATA; - idesc.id_func = mkentry; - idesc.id_number = parent; - idesc.id_parent = ino; /* this is the inode to enter */ - idesc.id_fix = DONTKNOW; - idesc.id_name = name; - dp = ginode(parent); - if (dp->di_size % DIRBLKSIZ) { - dp->di_size = roundup(dp->di_size, DIRBLKSIZ); - inodirty(); - } - if ((ckinode(dp, &idesc) & ALTERED) != 0) - return (1); - getpathname(pathbuf, parent, parent); - dp = ginode(parent); - if (expanddir(dp, pathbuf) == 0) - return (0); - return (ckinode(dp, &idesc) & ALTERED); -} - -/* - * Attempt to expand the size of a directory - */ -int -expanddir(dp, name) - register struct dinode *dp; - char *name; -{ - daddr_t lastbn, newblk; - register struct bufarea *bp; - char *cp, firstblk[DIRBLKSIZ]; - - lastbn = lblkno(&sblock, dp->di_size); - if (lastbn >= NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0) - return (0); - if ((newblk = allocblk(sblock.fs_frag)) == 0) - return (0); - dp->di_db[lastbn + 1] = dp->di_db[lastbn]; - dp->di_db[lastbn] = newblk; - dp->di_size += sblock.fs_bsize; - dp->di_blocks += btodb(sblock.fs_bsize); - bp = getdirblk(dp->di_db[lastbn + 1], - (long)dblksize(&sblock, dp, lastbn + 1)); - if (bp->b_errs) - goto bad; - memcpy(firstblk, bp->b_un.b_buf, DIRBLKSIZ); - bp = getdirblk(newblk, sblock.fs_bsize); - if (bp->b_errs) - goto bad; - memcpy(bp->b_un.b_buf, firstblk, DIRBLKSIZ); - for (cp = &bp->b_un.b_buf[DIRBLKSIZ]; - cp < &bp->b_un.b_buf[sblock.fs_bsize]; - cp += DIRBLKSIZ) - memcpy(cp, &emptydir, sizeof emptydir); - dirty(bp); - bp = getdirblk(dp->di_db[lastbn + 1], - (long)dblksize(&sblock, dp, lastbn + 1)); - if (bp->b_errs) - goto bad; - memcpy(bp->b_un.b_buf, &emptydir, sizeof emptydir); - pwarn("NO SPACE LEFT IN %s", name); - if (preen) - printf(" (EXPANDED)\n"); - else if (reply("EXPAND") == 0) - goto bad; - dirty(bp); - inodirty(); - return (1); -bad: - dp->di_db[lastbn] = dp->di_db[lastbn + 1]; - dp->di_db[lastbn + 1] = 0; - dp->di_size -= sblock.fs_bsize; - dp->di_blocks -= btodb(sblock.fs_bsize); - freeblk(newblk, sblock.fs_frag); - return (0); -} - -/* - * allocate a new directory - */ -int -allocdir(parent, request, mode) - ino_t parent, request; - int mode; -{ - ino_t ino; - char *cp; - struct dinode *dp; - register struct bufarea *bp; - struct dirtemplate *dirp; - - ino = allocino(request, IFDIR|mode); - if (newinofmt) - dirp = &dirhead; - else - dirp = (struct dirtemplate *)&odirhead; - dirp->dot_ino = ino; - dirp->dotdot_ino = parent; - dp = ginode(ino); - bp = getdirblk(dp->di_db[0], sblock.fs_fsize); - if (bp->b_errs) { - freeino(ino); - return (0); - } - memcpy(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate)); - for (cp = &bp->b_un.b_buf[DIRBLKSIZ]; - cp < &bp->b_un.b_buf[sblock.fs_fsize]; - cp += DIRBLKSIZ) - memcpy(cp, &emptydir, sizeof emptydir); - dirty(bp); - dp->di_nlink = 2; - inodirty(); - if (ino == ROOTINO) { - lncntp[ino] = dp->di_nlink; - cacheino(dp, ino); - return(ino); - } - if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) { - freeino(ino); - return (0); - } - cacheino(dp, ino); - statemap[ino] = statemap[parent]; - if (statemap[ino] == DSTATE) { - lncntp[ino] = dp->di_nlink; - lncntp[parent]++; - } - dp = ginode(parent); - dp->di_nlink++; - inodirty(); - return (ino); -} - -/* - * free a directory inode - */ -void -freedir(ino, parent) - ino_t ino, parent; -{ - struct dinode *dp; - - if (ino != parent) { - dp = ginode(parent); - dp->di_nlink--; - inodirty(); - } - freeino(ino); -} - -/* - * generate a temporary name for the lost+found directory. - */ -int -lftempname(bufp, ino) - char *bufp; - ino_t ino; -{ - register ino_t in; - register char *cp; - int namlen; - - cp = bufp + 2; - for (in = maxino; in > 0; in /= 10) - cp++; - *--cp = 0; - namlen = cp - bufp; - in = ino; - while (cp > bufp) { - *--cp = (in % 10) + '0'; - in /= 10; - } - *cp = '#'; - return (namlen); -} - -/* - * Get a directory block. - * Insure that it is held until another is requested. - */ -struct bufarea * -getdirblk(blkno, size) - daddr_t blkno; - long size; -{ - - if (pdirbp != 0) - pdirbp->b_flags &= ~B_INUSE; - pdirbp = getdatablk(blkno, size); - return (pdirbp); -} diff --git a/sbin/fsck/extern.h b/sbin/fsck/extern.h deleted file mode 100644 index dbc23a0eb16..00000000000 --- a/sbin/fsck/extern.h +++ /dev/null @@ -1,70 +0,0 @@ -/* $NetBSD: extern.h,v 1.4 1995/04/12 21:24:07 mycroft Exp $ */ - -/* - * Copyright (c) 1994 James A. Jegers - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ - -void adjust __P((struct inodesc *, short)); -int allocblk __P((long)); -int allocdir __P((ino_t, ino_t, int)); -void blkerror __P((ino_t, char *, daddr_t)); -int bread __P((int, char *, daddr_t, long)); -void bufinit(); -void bwrite __P((int, char *, daddr_t, long)); -void cacheino __P((struct dinode *, ino_t)); -int changeino __P((ino_t, char *, ino_t)); -int checkfstab __P((int, int, int (*)(), int (*)() )); -int chkrange __P((daddr_t, int)); -void ckfini __P((int)); -int ckinode __P((struct dinode *, struct inodesc *)); -void clri __P((struct inodesc *, char *, int)); -int dircheck __P((struct inodesc *, struct direct *)); -void direrror __P((ino_t, char *)); -int dirscan __P((struct inodesc *)); -int dofix __P((struct inodesc *, char *)); -void fileerror __P((ino_t, ino_t, char *)); -int findino __P((struct inodesc *)); -int findname __P((struct inodesc *)); -void flush __P((int, struct bufarea *)); -void freeblk __P((daddr_t, long)); -void freeino __P((ino_t)); -void freeinodebuf(); -int ftypeok __P((struct dinode *)); -void getpathname __P((char *, ino_t, ino_t)); -void inocleanup(); -void inodirty(); -int linkup __P((ino_t, ino_t)); -int makeentry __P((ino_t, ino_t, char *)); -void pass1(); -void pass1b(); -void pass2(); -void pass3(); -void pass4(); -int pass4check(); -void pass5(); -void pinode __P((ino_t)); -void propagate(); -int reply __P((char *)); -void resetinodebuf(); -int setup __P((char *)); - diff --git a/sbin/fsck/fsck.8 b/sbin/fsck/fsck.8 deleted file mode 100644 index 727f2767679..00000000000 --- a/sbin/fsck/fsck.8 +++ /dev/null @@ -1,308 +0,0 @@ -.\" $NetBSD: fsck.8,v 1.10 1995/07/12 01:49:16 cgd Exp $ -.\" -.\" Copyright (c) 1980, 1989, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)fsck.8 8.3 (Berkeley) 11/29/94 -.\" -.Dd November 29, 1994 -.Dt FSCK 8 -.Os BSD 4 -.Sh NAME -.Nm fsck -.Nd filesystem consistency check and interactive repair -.Sh SYNOPSIS -.Nm fsck -.Fl p -.Op Fl f -.Op Fl m Ar mode -.Nm fsck -.Op Fl f -.Op Fl b Ar block# -.Op Fl c Ar level -.Op Fl l Ar maxparallel -.Op Fl y -.Op Fl n -.Op Fl m Ar mode -.Op Ar filesystem -.Ar ... -.Sh DESCRIPTION -The first form of -.Nm fsck -preens a standard set of filesystems or the specified filesystems. -It is normally used in the script -.Pa /etc/rc -during automatic reboot. -Here -.Nm fsck -reads the table -.Pa /etc/fstab -to determine which filesystems to check. -Only partitions in fstab that are mounted ``rw,'' ``rq'' or ``ro'' -and that have non-zero pass number are checked. -Filesystems with pass number 1 (normally just the root filesystem) -are checked one at a time. -When pass 1 completes, all remaining filesystems are checked, -running one process per disk drive. -The disk drive containing each filesystem is inferred from the longest prefix -of the device name that ends in a digit; the remaining characters are assumed -to be the partition designator. -.Pp -The kernel takes care that only a restricted class of innocuous filesystem -inconsistencies can happen unless hardware or software failures intervene. -These are limited to the following: -.Bl -item -compact -.It -Unreferenced inodes -.It -Link counts in inodes too large -.It -Missing blocks in the free map -.It -Blocks in the free map also in files -.It -Counts in the super-block wrong -.El -.Pp -These are the only inconsistencies that -.Nm fsck -with the -.Fl p -option will correct; if it encounters other inconsistencies, it exits -with an abnormal return status and an automatic reboot will then fail. -For each corrected inconsistency one or more lines will be printed -identifying the filesystem on which the correction will take place, -and the nature of the correction. After successfully correcting a filesystem, -.Nm fsck -will print the number of files on that filesystem, -the number of used and free blocks, -and the percentage of fragmentation. -.Pp -If sent a -.Dv QUIT -signal, -.Nm fsck -will finish the filesystem checks, then exit with an abnormal -return status that causes an automatic reboot to fail. -This is useful when you want to finish the filesystem checks during an -automatic reboot, -but do not want the machine to come up multiuser after the checks complete. -.Pp -Without the -.Fl p -option, -.Nm fsck -audits and interactively repairs inconsistent conditions for filesystems. -If the filesystem is inconsistent the operator is prompted for concurrence -before each correction is attempted. -It should be noted that some of the corrective actions which are not -correctable under the -.Fl p -option will result in some loss of data. -The amount and severity of data lost may be determined from the diagnostic -output. -The default action for each consistency correction -is to wait for the operator to respond -.Li yes -or -.Li no . -If the operator does not have write permission on the filesystem -.Nm fsck -will default to a -.Fl n -action. -.Pp -.Nm Fsck -has more consistency checks than -its predecessors -.Em check , dcheck , fcheck , -and -.Em icheck -combined. -.Pp -The following flags are interpreted by -.Nm fsck . -.Bl -tag -width indent -.It Fl f -Force checking of file systems. Normally, if a file system is cleanly -unmounted, the kernel will set a -.Dq clean flag -in the file system superblock, and -.Nm -will not check the file system. This option forces -.Nm -to check the file system, regardless of the state of the clean flag. -.It Fl b -Use the block specified immediately after the flag as -the super block for the filesystem. Block 32 is usually -an alternate super block. -.It Fl l -Limit the number of parallel checks to the number specified in the following -argument. -By default, the limit is the number of disks, running one process per disk. -If a smaller limit is given, the disks are checked round-robin, one filesystem -at a time. -.It Fl m -Use the mode specified in octal immediately after the flag as the -permission bits to use when creating the -.Pa lost+found -directory rather than the default 1777. -In particular, systems that do not wish to have lost files accessible -by all users on the system should use a more restrictive -set of permissions such as 700. -.It Fl y -Assume a yes response to all questions asked by -.Nm fsck ; -this should be used with great caution as this is a free license -to continue after essentially unlimited trouble has been encountered. -.It Fl n -Assume a no response to all questions asked by -.Nm fsck -except for -.Ql CONTINUE? , -which is assumed to be affirmative; -do not open the filesystem for writing. -.It Fl c -Convert the filesystem to the specified level. -Note that the level of a filesystem can only be raised. -.Bl -tag -width indent -There are currently four levels defined: -.It 0 -The filesystem is in the old (static table) format. -.It 1 -The filesystem is in the new (dynamic table) format. -.It 2 -The filesystem supports 32-bit uid's and gid's, -short symbolic links are stored in the inode, -and directories have an added field showing the file type. -.It 3 -If maxcontig is greater than one, -build the free segment maps to aid in finding contiguous sets of blocks. -If maxcontig is equal to one, delete any existing segment maps. -.El -.Pp -In interactive mode, -.Nm fsck -will list the conversion to be made -and ask whether the conversion should be done. -If a negative answer is given, -no further operations are done on the filesystem. -In preen mode, -the conversion is listed and done if -possible without user interaction. -Conversion in preen mode is best used when all the filesystems -are being converted at once. -The format of a filesystem can be determined from the -first line of output from -.Xr dumpfs 8 . -.El -.Pp -If no filesystems are given to -.Nm fsck -then a default list of filesystems is read from -the file -.Pa /etc/fstab . -.Pp -.Bl -enum -indent indent -compact -Inconsistencies checked are as follows: -.It -Blocks claimed by more than one inode or the free map. -.It -Blocks claimed by an inode outside the range of the filesystem. -.It -Incorrect link counts. -.It -Size checks: -.Bl -item -indent indent -compact -.It -Directory size not a multiple of DIRBLKSIZ. -.It -Partially truncated file. -.El -.It -Bad inode format. -.It -Blocks not accounted for anywhere. -.It -Directory checks: -.Bl -item -indent indent -compact -.It -File pointing to unallocated inode. -.It -Inode number out of range. -.It -Dot or dot-dot not the first two entries of a directory -or having the wrong inode number. -.El -.It -Super Block checks: -.Bl -item -indent indent -compact -.It -More blocks for inodes than there are in the filesystem. -.It -Bad free block map format. -.It -Total free block and/or free inode count incorrect. -.El -.El -.Pp -Orphaned files and directories (allocated but unreferenced) are, -with the operator's concurrence, reconnected by -placing them in the -.Pa lost+found -directory. -The name assigned is the inode number. -If the -.Pa lost+found -directory does not exist, it is created. -If there is insufficient space its size is increased. -.Pp -Because of inconsistencies between the block device and the buffer cache, -the raw device should always be used. -.Sh FILES -.Bl -tag -width /etc/fstab -compact -.It Pa /etc/fstab -contains default list of filesystems to check. -.El -.Sh DIAGNOSTICS -The diagnostics produced by -.Nm fsck -are fully enumerated and explained in Appendix A of -.Rs -.%T "Fsck \- The UNIX File System Check Program" -.Re -.Sh SEE ALSO -.Xr fstab 5 , -.Xr fs 5 , -.Xr fsdb 8 , -.Xr newfs 8 , -.Xr mkfs 8 , -.Xr reboot 8 diff --git a/sbin/fsck/fsck.h b/sbin/fsck/fsck.h deleted file mode 100644 index b112a6b1f49..00000000000 --- a/sbin/fsck/fsck.h +++ /dev/null @@ -1,217 +0,0 @@ -/* $NetBSD: fsck.h,v 1.10 1995/04/12 21:24:09 mycroft Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - * - * @(#)fsck.h 8.1 (Berkeley) 6/5/93 - */ - -#define MAXDUP 10 /* limit on dup blks (per inode) */ -#define MAXBAD 10 /* limit on bad blks (per inode) */ -#define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ -#define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ - -#ifndef BUFSIZ -#define BUFSIZ 1024 -#endif - -#define USTATE 01 /* inode not allocated */ -#define FSTATE 02 /* inode is file */ -#define DSTATE 03 /* inode is directory */ -#define DFOUND 04 /* directory found during descent */ -#define DCLEAR 05 /* directory is to be cleared */ -#define FCLEAR 06 /* file is to be cleared */ - -/* - * buffer cache structure. - */ -struct bufarea { - struct bufarea *b_next; /* free list queue */ - struct bufarea *b_prev; /* free list queue */ - daddr_t b_bno; - int b_size; - int b_errs; - int b_flags; - union { - char *b_buf; /* buffer space */ - daddr_t *b_indir; /* indirect block */ - struct fs *b_fs; /* super block */ - struct cg *b_cg; /* cylinder group */ - struct dinode *b_dinode; /* inode block */ - } b_un; - char b_dirty; -}; - -#define B_INUSE 1 - -#define MINBUFS 5 /* minimum number of buffers required */ -struct bufarea bufhead; /* head of list of other blks in filesys */ -struct bufarea sblk; /* file system superblock */ -struct bufarea cgblk; /* cylinder group blocks */ -struct bufarea *pdirbp; /* current directory contents */ -struct bufarea *pbp; /* current inode block */ -struct bufarea *getdatablk(); - -#define dirty(bp) (bp)->b_dirty = 1 -#define initbarea(bp) \ - (bp)->b_dirty = 0; \ - (bp)->b_bno = (daddr_t)-1; \ - (bp)->b_flags = 0; - -#define sbdirty() sblk.b_dirty = 1 -#define cgdirty() cgblk.b_dirty = 1 -#define sblock (*sblk.b_un.b_fs) -#define cgrp (*cgblk.b_un.b_cg) - -enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; - -struct inodesc { - enum fixstate id_fix; /* policy on fixing errors */ - int (*id_func)(); /* function to be applied to blocks of inode */ - ino_t id_number; /* inode number described */ - ino_t id_parent; /* for DATA nodes, their parent */ - daddr_t id_blkno; /* current block number being examined */ - int id_numfrags; /* number of frags contained in block */ - quad_t id_filesize; /* for DATA nodes, the size of the directory */ - int id_loc; /* for DATA nodes, current location in dir */ - int id_entryno; /* for DATA nodes, current entry number */ - struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ - char *id_name; /* for DATA nodes, name to find or enter */ - char id_type; /* type of descriptor, DATA or ADDR */ -}; -/* file types */ -#define DATA 1 -#define ADDR 2 - -/* - * Linked list of duplicate blocks. - * - * The list is composed of two parts. The first part of the - * list (from duplist through the node pointed to by muldup) - * contains a single copy of each duplicate block that has been - * found. The second part of the list (from muldup to the end) - * contains duplicate blocks that have been found more than once. - * To check if a block has been found as a duplicate it is only - * necessary to search from duplist through muldup. To find the - * total number of times that a block has been found as a duplicate - * the entire list must be searched for occurences of the block - * in question. The following diagram shows a sample list where - * w (found twice), x (found once), y (found three times), and z - * (found once) are duplicate block numbers: - * - * w -> y -> x -> z -> y -> w -> y - * ^ ^ - * | | - * duplist muldup - */ -struct dups { - struct dups *next; - daddr_t dup; -}; -struct dups *duplist; /* head of dup list */ -struct dups *muldup; /* end of unique duplicate dup block numbers */ - -/* - * Linked list of inodes with zero link counts. - */ -struct zlncnt { - struct zlncnt *next; - ino_t zlncnt; -}; -struct zlncnt *zlnhead; /* head of zero link count list */ - -/* - * Inode cache data structures. - */ -struct inoinfo { - struct inoinfo *i_nexthash; /* next entry in hash chain */ - ino_t i_number; /* inode number of this entry */ - ino_t i_parent; /* inode number of parent */ - ino_t i_dotdot; /* inode number of `..' */ - size_t i_isize; /* size of inode */ - u_int i_numblks; /* size of block array in bytes */ - daddr_t i_blks[1]; /* actually longer */ -} **inphead, **inpsort; -long numdirs, listmax, inplast; - -char *cdevname; /* name of device being checked */ -long dev_bsize; /* computed value of DEV_BSIZE */ -long secsize; /* actual disk sector size */ -char nflag; /* assume a no response */ -char yflag; /* assume a yes response */ -int bflag; /* location of alternate super block */ -int debug; /* output debugging info */ -int cvtlevel; /* convert to newer file system format */ -int doinglevel1; /* converting to new cylinder group format */ -int doinglevel2; /* converting to new inode format */ -int newinofmt; /* filesystem has new inode format */ -char preen; /* just fix normal inconsistencies */ -char hotroot; /* checking root device */ -char havesb; /* superblock has been read */ -char skipclean; /* skip clean file systems if preening */ -int fsmodified; /* 1 => write done to file system */ -int fsreadfd; /* file descriptor for reading file system */ -int fswritefd; /* file descriptor for writing file system */ - -daddr_t maxfsblock; /* number of blocks in the file system */ -char *blockmap; /* ptr to primary blk allocation map */ -ino_t maxino; /* number of inodes in file system */ -ino_t lastino; /* last inode in use */ -char *statemap; /* ptr to inode state table */ -char *typemap; /* ptr to inode type table */ -int16_t *lncntp; /* ptr to link count table */ - -ino_t lfdir; /* lost & found directory inode number */ -char *lfname; /* lost & found directory name */ -int lfmode; /* lost & found directory creation mode */ - -daddr_t n_blks; /* number of blocks in use */ -daddr_t n_files; /* number of files in use */ - -#define clearinode(dp) (*(dp) = zino) -struct dinode zino; - -#define setbmap(blkno) setbit(blockmap, blkno) -#define testbmap(blkno) isset(blockmap, blkno) -#define clrbmap(blkno) clrbit(blockmap, blkno) - -#define STOP 0x01 -#define SKIP 0x02 -#define KEEPON 0x04 -#define ALTERED 0x08 -#define FOUND 0x10 - -time_t time(); -struct dinode *ginode(); -struct inoinfo *getinoinfo(); -void getblk(); -ino_t allocino(); diff --git a/sbin/fsck/inode.c b/sbin/fsck/inode.c deleted file mode 100644 index d7c71139228..00000000000 --- a/sbin/fsck/inode.c +++ /dev/null @@ -1,577 +0,0 @@ -/* $NetBSD: inode.c,v 1.17 1995/12/17 06:03:36 thorpej Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95"; -#else -static char rcsid[] = "$NetBSD: inode.c,v 1.17 1995/12/17 06:03:36 thorpej Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include -#ifndef SMALL -#include -#endif -#include -#include -#include - -#include "fsck.h" -#include "extern.h" - -static ino_t startinum; - -int iblock __P((struct inodesc *, long, quad_t)); - -int -ckinode(dp, idesc) - struct dinode *dp; - register struct inodesc *idesc; -{ - register ufs_daddr_t *ap; - long ret, n, ndb, offset; - struct dinode dino; - quad_t remsize, sizepb; - mode_t mode; - - if (idesc->id_fix != IGNORE) - idesc->id_fix = DONTKNOW; - idesc->id_entryno = 0; - idesc->id_filesize = dp->di_size; - mode = dp->di_mode & IFMT; - if (mode == IFBLK || mode == IFCHR || (mode == IFLNK && - (dp->di_size < sblock.fs_maxsymlinklen || - (sblock.fs_maxsymlinklen == 0 && dp->di_blocks == 0)))) - return (KEEPON); - dino = *dp; - ndb = howmany(dino.di_size, sblock.fs_bsize); - for (ap = &dino.di_db[0]; ap < &dino.di_db[NDADDR]; ap++) { - if (--ndb == 0 && (offset = blkoff(&sblock, dino.di_size)) != 0) - idesc->id_numfrags = - numfrags(&sblock, fragroundup(&sblock, offset)); - else - idesc->id_numfrags = sblock.fs_frag; - if (*ap == 0) - continue; - idesc->id_blkno = *ap; - if (idesc->id_type == ADDR) - ret = (*idesc->id_func)(idesc); - else - ret = dirscan(idesc); - if (ret & STOP) - return (ret); - } - idesc->id_numfrags = sblock.fs_frag; - remsize = dino.di_size - sblock.fs_bsize * NDADDR; - sizepb = sblock.fs_bsize; - for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) { - if (*ap) { - idesc->id_blkno = *ap; - ret = iblock(idesc, n, remsize); - if (ret & STOP) - return (ret); - } - sizepb *= NINDIR(&sblock); - remsize -= sizepb; - } - return (KEEPON); -} - -int -iblock(idesc, ilevel, isize) - struct inodesc *idesc; - long ilevel; - quad_t isize; -{ - register daddr_t *ap; - register daddr_t *aplim; - register struct bufarea *bp; - int i, n, (*func)(), nif; - quad_t sizepb; - char buf[BUFSIZ]; - extern int pass1check(); - - if (idesc->id_type == ADDR) { - func = idesc->id_func; - if (((n = (*func)(idesc)) & KEEPON) == 0) - return (n); - } else - func = dirscan; - if (chkrange(idesc->id_blkno, idesc->id_numfrags)) - return (SKIP); - bp = getdatablk(idesc->id_blkno, sblock.fs_bsize); - ilevel--; - for (sizepb = sblock.fs_bsize, i = 0; i < ilevel; i++) - sizepb *= NINDIR(&sblock); - nif = howmany(isize , sizepb); - if (nif > NINDIR(&sblock)) - nif = NINDIR(&sblock); - if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) { - aplim = &bp->b_un.b_indir[NINDIR(&sblock)]; - for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) { - if (*ap == 0) - continue; - (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%lu", - idesc->id_number); - if (dofix(idesc, buf)) { - *ap = 0; - dirty(bp); - } - } - flush(fswritefd, bp); - } - aplim = &bp->b_un.b_indir[nif]; - for (ap = bp->b_un.b_indir; ap < aplim; ap++) { - if (*ap) { - idesc->id_blkno = *ap; - if (ilevel == 0) - n = (*func)(idesc); - else - n = iblock(idesc, ilevel, isize); - if (n & STOP) { - bp->b_flags &= ~B_INUSE; - return (n); - } - } - isize -= sizepb; - } - bp->b_flags &= ~B_INUSE; - return (KEEPON); -} - -/* - * Check that a block in a legal block number. - * Return 0 if in range, 1 if out of range. - */ -int -chkrange(blk, cnt) - daddr_t blk; - int cnt; -{ - register int c; - - if ((unsigned)(blk + cnt) > maxfsblock) - return (1); - c = dtog(&sblock, blk); - if (blk < cgdmin(&sblock, c)) { - if ((blk + cnt) > cgsblock(&sblock, c)) { - if (debug) { - printf("blk %ld < cgdmin %ld;", - blk, cgdmin(&sblock, c)); - printf(" blk + cnt %ld > cgsbase %ld\n", - blk + cnt, cgsblock(&sblock, c)); - } - return (1); - } - } else { - if ((blk + cnt) > cgbase(&sblock, c+1)) { - if (debug) { - printf("blk %ld >= cgdmin %ld;", - blk, cgdmin(&sblock, c)); - printf(" blk + cnt %ld > sblock.fs_fpg %ld\n", - blk+cnt, sblock.fs_fpg); - } - return (1); - } - } - return (0); -} - -/* - * General purpose interface for reading inodes. - */ -struct dinode * -ginode(inumber) - ino_t inumber; -{ - daddr_t iblk; - - if (inumber < ROOTINO || inumber > maxino) - errexit("bad inode number %d to ginode\n", inumber); - if (startinum == 0 || - inumber < startinum || inumber >= startinum + INOPB(&sblock)) { - iblk = ino_to_fsba(&sblock, inumber); - if (pbp != 0) - pbp->b_flags &= ~B_INUSE; - pbp = getdatablk(iblk, sblock.fs_bsize); - startinum = (inumber / INOPB(&sblock)) * INOPB(&sblock); - } - return (&pbp->b_un.b_dinode[inumber % INOPB(&sblock)]); -} - -/* - * Special purpose version of ginode used to optimize first pass - * over all the inodes in numerical order. - */ -ino_t nextino, lastinum; -long readcnt, readpercg, fullcnt, inobufsize, partialcnt, partialsize; -struct dinode *inodebuf; - -struct dinode * -getnextinode(inumber) - ino_t inumber; -{ - long size; - daddr_t dblk; - static struct dinode *dp; - - if (inumber != nextino++ || inumber > maxino) - errexit("bad inode number %d to nextinode\n", inumber); - if (inumber >= lastinum) { - readcnt++; - dblk = fsbtodb(&sblock, ino_to_fsba(&sblock, lastinum)); - if (readcnt % readpercg == 0) { - size = partialsize; - lastinum += partialcnt; - } else { - size = inobufsize; - lastinum += fullcnt; - } - (void)bread(fsreadfd, (char *)inodebuf, dblk, size); /* ??? */ - dp = inodebuf; - } - return (dp++); -} - -void -resetinodebuf() -{ - - startinum = 0; - nextino = 0; - lastinum = 0; - readcnt = 0; - inobufsize = blkroundup(&sblock, INOBUFSIZE); - fullcnt = inobufsize / sizeof(struct dinode); - readpercg = sblock.fs_ipg / fullcnt; - partialcnt = sblock.fs_ipg % fullcnt; - partialsize = partialcnt * sizeof(struct dinode); - if (partialcnt != 0) { - readpercg++; - } else { - partialcnt = fullcnt; - partialsize = inobufsize; - } - if (inodebuf == NULL && - (inodebuf = (struct dinode *)malloc((unsigned)inobufsize)) == NULL) - errexit("Cannot allocate space for inode buffer\n"); - while (nextino < ROOTINO) - (void)getnextinode(nextino); -} - -void -freeinodebuf() -{ - - if (inodebuf != NULL) - free((char *)inodebuf); - inodebuf = NULL; -} - -/* - * Routines to maintain information about directory inodes. - * This is built during the first pass and used during the - * second and third passes. - * - * Enter inodes into the cache. - */ -void -cacheino(dp, inumber) - register struct dinode *dp; - ino_t inumber; -{ - register struct inoinfo *inp; - struct inoinfo **inpp; - unsigned int blks; - - blks = howmany(dp->di_size, sblock.fs_bsize); - if (blks > NDADDR) - blks = NDADDR + NIADDR; - inp = (struct inoinfo *) - malloc(sizeof(*inp) + (blks - 1) * sizeof(daddr_t)); - if (inp == NULL) - return; - inpp = &inphead[inumber % numdirs]; - inp->i_nexthash = *inpp; - *inpp = inp; - if (inumber == ROOTINO) - inp->i_parent = ROOTINO; - else - inp->i_parent = (ino_t)0; - inp->i_dotdot = (ino_t)0; - inp->i_number = inumber; - inp->i_isize = dp->di_size; - inp->i_numblks = blks * sizeof(daddr_t); - memcpy(&inp->i_blks[0], &dp->di_db[0], (size_t)inp->i_numblks); - if (inplast == listmax) { - listmax += 100; - inpsort = (struct inoinfo **)realloc((char *)inpsort, - (unsigned)listmax * sizeof(struct inoinfo *)); - if (inpsort == NULL) - errexit("cannot increase directory list"); - } - inpsort[inplast++] = inp; -} - -/* - * Look up an inode cache structure. - */ -struct inoinfo * -getinoinfo(inumber) - ino_t inumber; -{ - register struct inoinfo *inp; - - for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) { - if (inp->i_number != inumber) - continue; - return (inp); - } - errexit("cannot find inode %d\n", inumber); - return ((struct inoinfo *)0); -} - -/* - * Clean up all the inode cache structure. - */ -void -inocleanup() -{ - register struct inoinfo **inpp; - - if (inphead == NULL) - return; - for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) - free((char *)(*inpp)); - free((char *)inphead); - free((char *)inpsort); - inphead = inpsort = NULL; -} - -void -inodirty() -{ - - dirty(pbp); -} - -void -clri(idesc, type, flag) - register struct inodesc *idesc; - char *type; - int flag; -{ - register struct dinode *dp; - - dp = ginode(idesc->id_number); - if (flag == 1) { - pwarn("%s %s", type, - (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE"); - pinode(idesc->id_number); - } - if (preen || reply("CLEAR") == 1) { - if (preen) - printf(" (CLEARED)\n"); - n_files--; - (void)ckinode(dp, idesc); - clearinode(dp); - statemap[idesc->id_number] = USTATE; - inodirty(); - } -} - -int -findname(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - - if (dirp->d_ino != idesc->id_parent) - return (KEEPON); - memcpy(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1); - return (STOP|FOUND); -} - -int -findino(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - - if (dirp->d_ino == 0) - return (KEEPON); - if (strcmp(dirp->d_name, idesc->id_name) == 0 && - dirp->d_ino >= ROOTINO && dirp->d_ino <= maxino) { - idesc->id_parent = dirp->d_ino; - return (STOP|FOUND); - } - return (KEEPON); -} - -void -pinode(ino) - ino_t ino; -{ - register struct dinode *dp; - register char *p; - struct passwd *pw; - time_t t; - - printf(" I=%lu ", ino); - if (ino < ROOTINO || ino > maxino) - return; - dp = ginode(ino); - printf(" OWNER="); -#ifndef SMALL - if ((pw = getpwuid((int)dp->di_uid)) != 0) - printf("%s ", pw->pw_name); - else -#endif - printf("%u ", (unsigned)dp->di_uid); - printf("MODE=%o\n", dp->di_mode); - if (preen) - printf("%s: ", cdevname); - printf("SIZE=%qu ", dp->di_size); - t = dp->di_mtime; - p = ctime(&t); - printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]); -} - -void -blkerror(ino, type, blk) - ino_t ino; - char *type; - daddr_t blk; -{ - - pfatal("%ld %s I=%lu", blk, type, ino); - printf("\n"); - switch (statemap[ino]) { - - case FSTATE: - statemap[ino] = FCLEAR; - return; - - case DSTATE: - statemap[ino] = DCLEAR; - return; - - case FCLEAR: - case DCLEAR: - return; - - default: - errexit("BAD STATE %d TO BLKERR", statemap[ino]); - /* NOTREACHED */ - } -} - -/* - * allocate an unused inode - */ -ino_t -allocino(request, type) - ino_t request; - int type; -{ - register ino_t ino; - register struct dinode *dp; - time_t t; - - if (request == 0) - request = ROOTINO; - else if (statemap[request] != USTATE) - return (0); - for (ino = request; ino < maxino; ino++) - if (statemap[ino] == USTATE) - break; - if (ino == maxino) - return (0); - switch (type & IFMT) { - case IFDIR: - statemap[ino] = DSTATE; - break; - case IFREG: - case IFLNK: - statemap[ino] = FSTATE; - break; - default: - return (0); - } - dp = ginode(ino); - dp->di_db[0] = allocblk((long)1); - if (dp->di_db[0] == 0) { - statemap[ino] = USTATE; - return (0); - } - dp->di_mode = type; - (void)time(&t); - dp->di_atime = t; - dp->di_mtime = dp->di_ctime = dp->di_atime; - dp->di_size = sblock.fs_fsize; - dp->di_blocks = btodb(sblock.fs_fsize); - n_files++; - inodirty(); - if (newinofmt) - typemap[ino] = IFTODT(type); - return (ino); -} - -/* - * deallocate an inode - */ -void -freeino(ino) - ino_t ino; -{ - struct inodesc idesc; - struct dinode *dp; - - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = ADDR; - idesc.id_func = pass4check; - idesc.id_number = ino; - dp = ginode(ino); - (void)ckinode(dp, &idesc); - clearinode(dp); - inodirty(); - statemap[ino] = USTATE; - n_files--; -} diff --git a/sbin/fsck/main.c b/sbin/fsck/main.c deleted file mode 100644 index d5cd4107794..00000000000 --- a/sbin/fsck/main.c +++ /dev/null @@ -1,344 +0,0 @@ -/* $NetBSD: main.c,v 1.18.2.1 1995/11/01 00:06:18 jtc Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1980, 1986, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94"; -#else -static char rcsid[] = "$NetBSD: main.c,v 1.18.2.1 1995/11/01 00:06:18 jtc Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fsck.h" -#include "extern.h" - -void catch(), catchquit(), voidquit(); -int returntosingle; -int argtoi __P((int, char *, char *, int)); -int checkfilesys __P((char *, char *, long, int)); -int docheck __P((struct fstab *)); - -int -main(argc, argv) - int argc; - char *argv[]; -{ - int ch; - int ret, maxrun = 0; - extern char *optarg, *blockcheck(); - extern int optind; - - sync(); - skipclean = 1; - while ((ch = getopt(argc, argv, "dfpnNyYb:c:l:m:")) != EOF) { - switch (ch) { - case 'p': - preen++; - break; - - case 'b': - skipclean = 0; - bflag = argtoi('b', "number", optarg, 10); - printf("Alternate super block location: %d\n", bflag); - break; - - case 'c': - skipclean = 0; - cvtlevel = argtoi('c', "conversion level", optarg, 10); - break; - - case 'd': - debug++; - break; - - case 'f': - skipclean = 0; - break; - - case 'l': - maxrun = argtoi('l', "number", optarg, 10); - break; - - case 'm': - lfmode = argtoi('m', "mode", optarg, 8); - if (lfmode &~ 07777) - errexit("bad mode to -m: %o\n", lfmode); - printf("** lost+found creation mode %o\n", lfmode); - break; - - case 'n': - case 'N': - nflag++; - yflag = 0; - break; - - case 'y': - case 'Y': - yflag++; - nflag = 0; - break; - - default: - errexit("%c option?\n", ch); - } - } - argc -= optind; - argv += optind; - if (signal(SIGINT, SIG_IGN) != SIG_IGN) - (void)signal(SIGINT, catch); - if (preen) - (void)signal(SIGQUIT, catchquit); - if (argc) { - while (argc-- > 0) - (void)checkfilesys(blockcheck(*argv++), 0, 0L, 0); - exit(0); - } - ret = checkfstab(preen, maxrun, docheck, checkfilesys); - if (returntosingle) - exit(2); - exit(ret); -} - -int -argtoi(flag, req, str, base) - int flag; - char *req, *str; - int base; -{ - char *cp; - int ret; - - ret = (int)strtol(str, &cp, base); - if (cp == str || *cp) - errexit("-%c flag requires a %s\n", flag, req); - return (ret); -} - -/* - * Determine whether a filesystem should be checked. - */ -int -docheck(fsp) - register struct fstab *fsp; -{ - - if ((strcmp(fsp->fs_vfstype, "ufs") && - strcmp(fsp->fs_vfstype, "ffs")) || - (strcmp(fsp->fs_type, FSTAB_RW) && - strcmp(fsp->fs_type, FSTAB_RO)) || - fsp->fs_passno == 0) - return (0); - return (1); -} - -/* - * Check the specified filesystem. - */ -/* ARGSUSED */ -int -checkfilesys(filesys, mntpt, auxdata, child) - char *filesys, *mntpt; - long auxdata; - int child; -{ - daddr_t n_ffree, n_bfree; - struct dups *dp; - struct zlncnt *zlnp; - int cylno; - - if (preen && child) - (void)signal(SIGQUIT, voidquit); - cdevname = filesys; - if (debug && preen) - pwarn("starting\n"); - switch (setup(filesys)) { - case 0: - if (preen) - pfatal("CAN'T CHECK FILE SYSTEM."); - case -1: - return (0); - } - /* - * 1: scan inodes tallying blocks used - */ - if (preen == 0) { - printf("** Last Mounted on %s\n", sblock.fs_fsmnt); - if (hotroot) - printf("** Root file system\n"); - printf("** Phase 1 - Check Blocks and Sizes\n"); - } - pass1(); - - /* - * 1b: locate first references to duplicates, if any - */ - if (duplist) { - if (preen) - pfatal("INTERNAL ERROR: dups with -p"); - printf("** Phase 1b - Rescan For More DUPS\n"); - pass1b(); - } - - /* - * 2: traverse directories from root to mark all connected directories - */ - if (preen == 0) - printf("** Phase 2 - Check Pathnames\n"); - pass2(); - - /* - * 3: scan inodes looking for disconnected directories - */ - if (preen == 0) - printf("** Phase 3 - Check Connectivity\n"); - pass3(); - - /* - * 4: scan inodes looking for disconnected files; check reference counts - */ - if (preen == 0) - printf("** Phase 4 - Check Reference Counts\n"); - pass4(); - - /* - * 5: check and repair resource counts in cylinder groups - */ - if (preen == 0) - printf("** Phase 5 - Check Cyl groups\n"); - pass5(); - - /* - * print out summary statistics - */ - n_ffree = sblock.fs_cstotal.cs_nffree; - n_bfree = sblock.fs_cstotal.cs_nbfree; - pwarn("%ld files, %ld used, %ld free ", - n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree); - printf("(%ld frags, %ld blocks, %d.%d%% fragmentation)\n", - n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize, - ((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10); - if (debug && - (n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree)) - printf("%ld files missing\n", n_files); - if (debug) { - n_blks += sblock.fs_ncg * - (cgdmin(&sblock, 0) - cgsblock(&sblock, 0)); - n_blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0); - n_blks += howmany(sblock.fs_cssize, sblock.fs_fsize); - if (n_blks -= maxfsblock - (n_ffree + sblock.fs_frag * n_bfree)) - printf("%ld blocks missing\n", n_blks); - if (duplist != NULL) { - printf("The following duplicate blocks remain:"); - for (dp = duplist; dp; dp = dp->next) - printf(" %ld,", dp->dup); - printf("\n"); - } - if (zlnhead != NULL) { - printf("The following zero link count inodes remain:"); - for (zlnp = zlnhead; zlnp; zlnp = zlnp->next) - printf(" %lu,", zlnp->zlncnt); - printf("\n"); - } - } - zlnhead = (struct zlncnt *)0; - duplist = (struct dups *)0; - muldup = (struct dups *)0; - inocleanup(); - if (fsmodified) { - (void)time(&sblock.fs_time); - sbdirty(); - } - if (cvtlevel && sblk.b_dirty) { - /* - * Write out the duplicate super blocks - */ - for (cylno = 0; cylno < sblock.fs_ncg; cylno++) - bwrite(fswritefd, (char *)&sblock, - fsbtodb(&sblock, cgsblock(&sblock, cylno)), SBSIZE); - } - ckfini(1); - free(blockmap); - free(statemap); - free((char *)lncntp); - if (!fsmodified) - return (0); - if (!preen) - printf("\n***** FILE SYSTEM WAS MODIFIED *****\n"); - if (hotroot) { - struct statfs stfs_buf; - /* - * We modified the root. Do a mount update on - * it, unless it is read-write, so we can continue. - */ - if (statfs("/", &stfs_buf) == 0) { - long flags = stfs_buf.f_flags; - struct ufs_args args; - int ret; - - if (flags & MNT_RDONLY) { - args.fspec = 0; - args.export.ex_flags = 0; - args.export.ex_root = 0; - flags |= MNT_UPDATE | MNT_RELOAD; - ret = mount(MOUNT_FFS, "/", flags, &args); - if (ret == 0) - return(0); - } - } - if (!preen) - printf("\n***** REBOOT NOW *****\n"); - sync(); - return (4); - } - return (0); -} diff --git a/sbin/fsck/pass1.c b/sbin/fsck/pass1.c deleted file mode 100644 index fc1b664856e..00000000000 --- a/sbin/fsck/pass1.c +++ /dev/null @@ -1,337 +0,0 @@ -/* $NetBSD: pass1.c,v 1.14 1996/01/18 21:55:27 mycroft Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93"; -#else -static char rcsid[] = "$NetBSD: pass1.c,v 1.14 1996/01/18 21:55:27 mycroft Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "fsck.h" -#include "extern.h" - -static daddr_t badblk; -static daddr_t dupblk; -int pass1check(); -struct dinode *getnextinode(); -void checkinode __P((ino_t, struct inodesc *)); - -void -pass1() -{ - ino_t inumber; - int c, i, cgd; - struct inodesc idesc; - - /* - * Set file system reserved blocks in used block map. - */ - for (c = 0; c < sblock.fs_ncg; c++) { - cgd = cgdmin(&sblock, c); - if (c == 0) - i = cgbase(&sblock, c); - else - i = cgsblock(&sblock, c); - for (; i < cgd; i++) - setbmap(i); - } - i = sblock.fs_csaddr; - cgd = i + howmany(sblock.fs_cssize, sblock.fs_fsize); - for (; i < cgd; i++) - setbmap(i); - /* - * Find all allocated blocks. - */ - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = ADDR; - idesc.id_func = pass1check; - inumber = 0; - n_files = n_blks = 0; - resetinodebuf(); - for (c = 0; c < sblock.fs_ncg; c++) { - for (i = 0; i < sblock.fs_ipg; i++, inumber++) { - if (inumber < ROOTINO) - continue; - checkinode(inumber, &idesc); - } - } - freeinodebuf(); -} - -void -checkinode(inumber, idesc) - ino_t inumber; - register struct inodesc *idesc; -{ - register struct dinode *dp; - struct zlncnt *zlnp; - int ndb, j; - mode_t mode; - char *symbuf; - - dp = getnextinode(inumber); - mode = dp->di_mode & IFMT; - if (mode == 0) { - if (memcmp(dp->di_db, zino.di_db, NDADDR * sizeof(daddr_t)) || - memcmp(dp->di_ib, zino.di_ib, NIADDR * sizeof(daddr_t)) || - dp->di_mode || dp->di_size) { - pfatal("PARTIALLY ALLOCATED INODE I=%lu", inumber); - if (reply("CLEAR") == 1) { - dp = ginode(inumber); - clearinode(dp); - inodirty(); - } - } - statemap[inumber] = USTATE; - return; - } - lastino = inumber; - if (/* dp->di_size < 0 || */ - dp->di_size + sblock.fs_bsize - 1 < dp->di_size) { - if (debug) - printf("bad size %qu:", dp->di_size); - goto unknown; - } - if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) { - dp = ginode(inumber); - dp->di_size = sblock.fs_fsize; - dp->di_mode = IFREG|0600; - inodirty(); - } - ndb = howmany(dp->di_size, sblock.fs_bsize); - if (ndb < 0) { - if (debug) - printf("bad size %qu ndb %d:", - dp->di_size, ndb); - goto unknown; - } - if (mode == IFBLK || mode == IFCHR) - ndb++; - if (mode == IFLNK) { - /* - * Note that the old fastlink format always had di_blocks set - * to 0. Other than that we no longer use the `spare' field - * (which is now the extended uid) for sanity checking, the - * new format is the same as the old. We simply ignore the - * conversion altogether. - mycroft, 19MAY1994 - */ - if (doinglevel2 && - dp->di_size > 0 && dp->di_size < MAXSYMLINKLEN && - dp->di_blocks != 0) { - symbuf = alloca(secsize); - if (bread(fsreadfd, symbuf, - fsbtodb(&sblock, dp->di_db[0]), - (long)secsize) != 0) - errexit("cannot read symlink"); - if (debug) { - symbuf[dp->di_size] = 0; - printf("convert symlink %d(%s) of size %d\n", - inumber, symbuf, (long)dp->di_size); - } - dp = ginode(inumber); - memcpy(dp->di_shortlink, symbuf, (long)dp->di_size); - dp->di_blocks = 0; - inodirty(); - } - /* - * Fake ndb value so direct/indirect block checks below - * will detect any garbage after symlink string. - */ - if (dp->di_size < sblock.fs_maxsymlinklen || - (sblock.fs_maxsymlinklen == 0 && dp->di_blocks == 0)) { - ndb = howmany(dp->di_size, sizeof(daddr_t)); - if (ndb > NDADDR) { - j = ndb - NDADDR; - for (ndb = 1; j > 1; j--) - ndb *= NINDIR(&sblock); - ndb += NDADDR; - } - } - } - for (j = ndb; j < NDADDR; j++) - if (dp->di_db[j] != 0) { - if (debug) - printf("bad direct addr: %ld\n", dp->di_db[j]); - goto unknown; - } - for (j = 0, ndb -= NDADDR; ndb > 0; j++) - ndb /= NINDIR(&sblock); - for (; j < NIADDR; j++) - if (dp->di_ib[j] != 0) { - if (debug) - printf("bad indirect addr: %ld\n", - dp->di_ib[j]); - goto unknown; - } - if (ftypeok(dp) == 0) - goto unknown; - n_files++; - lncntp[inumber] = dp->di_nlink; - if (dp->di_nlink <= 0) { - zlnp = (struct zlncnt *)malloc(sizeof *zlnp); - if (zlnp == NULL) { - pfatal("LINK COUNT TABLE OVERFLOW"); - if (reply("CONTINUE") == 0) - errexit(""); - } else { - zlnp->zlncnt = inumber; - zlnp->next = zlnhead; - zlnhead = zlnp; - } - } - if (mode == IFDIR) { - if (dp->di_size == 0) - statemap[inumber] = DCLEAR; - else - statemap[inumber] = DSTATE; - cacheino(dp, inumber); - } else - statemap[inumber] = FSTATE; - typemap[inumber] = IFTODT(mode); - if (doinglevel2 && - (dp->di_ouid != (u_short)-1 || dp->di_ogid != (u_short)-1)) { - dp = ginode(inumber); - dp->di_uid = dp->di_ouid; - dp->di_ouid = -1; - dp->di_gid = dp->di_ogid; - dp->di_ogid = -1; - inodirty(); - } - badblk = dupblk = 0; - idesc->id_number = inumber; - (void)ckinode(dp, idesc); - idesc->id_entryno *= btodb(sblock.fs_fsize); - if (dp->di_blocks != idesc->id_entryno) { - pwarn("INCORRECT BLOCK COUNT I=%lu (%ld should be %ld)", - inumber, dp->di_blocks, idesc->id_entryno); - if (preen) - printf(" (CORRECTED)\n"); - else if (reply("CORRECT") == 0) - return; - dp = ginode(inumber); - dp->di_blocks = idesc->id_entryno; - inodirty(); - } - return; -unknown: - pfatal("UNKNOWN FILE TYPE I=%lu", inumber); - statemap[inumber] = FCLEAR; - if (reply("CLEAR") == 1) { - statemap[inumber] = USTATE; - dp = ginode(inumber); - clearinode(dp); - inodirty(); - } -} - -int -pass1check(idesc) - register struct inodesc *idesc; -{ - int res = KEEPON; - int anyout, nfrags; - daddr_t blkno = idesc->id_blkno; - register struct dups *dlp; - struct dups *new; - - if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) { - blkerror(idesc->id_number, "BAD", blkno); - if (badblk++ >= MAXBAD) { - pwarn("EXCESSIVE BAD BLKS I=%lu", - idesc->id_number); - if (preen) - printf(" (SKIPPING)\n"); - else if (reply("CONTINUE") == 0) - errexit(""); - return (STOP); - } - } - for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { - if (anyout && chkrange(blkno, 1)) { - res = SKIP; - } else if (!testbmap(blkno)) { - n_blks++; - setbmap(blkno); - } else { - blkerror(idesc->id_number, "DUP", blkno); - if (dupblk++ >= MAXDUP) { - pwarn("EXCESSIVE DUP BLKS I=%lu", - idesc->id_number); - if (preen) - printf(" (SKIPPING)\n"); - else if (reply("CONTINUE") == 0) - errexit(""); - return (STOP); - } - new = (struct dups *)malloc(sizeof(struct dups)); - if (new == NULL) { - pfatal("DUP TABLE OVERFLOW."); - if (reply("CONTINUE") == 0) - errexit(""); - return (STOP); - } - new->dup = blkno; - if (muldup == 0) { - duplist = muldup = new; - new->next = 0; - } else { - new->next = muldup->next; - muldup->next = new; - } - for (dlp = duplist; dlp != muldup; dlp = dlp->next) - if (dlp->dup == blkno) - break; - if (dlp == muldup && dlp->dup != blkno) - muldup = new; - } - /* - * count the number of blocks found in id_entryno - */ - idesc->id_entryno++; - } - return (res); -} diff --git a/sbin/fsck/pass1b.c b/sbin/fsck/pass1b.c deleted file mode 100644 index de541f25329..00000000000 --- a/sbin/fsck/pass1b.c +++ /dev/null @@ -1,109 +0,0 @@ -/* $NetBSD: pass1b.c,v 1.9 1995/03/18 14:55:51 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93"; -#else -static char rcsid[] = "$NetBSD: pass1b.c,v 1.9 1995/03/18 14:55:51 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include - -#include -#include "fsck.h" -#include "extern.h" - -int pass1bcheck(); -static struct dups *duphead; - -void -pass1b() -{ - register int c, i; - register struct dinode *dp; - struct inodesc idesc; - ino_t inumber; - - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = ADDR; - idesc.id_func = pass1bcheck; - duphead = duplist; - inumber = 0; - for (c = 0; c < sblock.fs_ncg; c++) { - for (i = 0; i < sblock.fs_ipg; i++, inumber++) { - if (inumber < ROOTINO) - continue; - dp = ginode(inumber); - if (dp == NULL) - continue; - idesc.id_number = inumber; - if (statemap[inumber] != USTATE && - (ckinode(dp, &idesc) & STOP)) - return; - } - } -} - -int -pass1bcheck(idesc) - register struct inodesc *idesc; -{ - register struct dups *dlp; - int nfrags, res = KEEPON; - daddr_t blkno = idesc->id_blkno; - - for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { - if (chkrange(blkno, 1)) - res = SKIP; - for (dlp = duphead; dlp; dlp = dlp->next) { - if (dlp->dup == blkno) { - blkerror(idesc->id_number, "DUP", blkno); - dlp->dup = duphead->dup; - duphead->dup = blkno; - duphead = duphead->next; - } - if (dlp == muldup) - break; - } - if (muldup == 0 || duphead == muldup->next) - return (STOP); - } - return (res); -} diff --git a/sbin/fsck/pass2.c b/sbin/fsck/pass2.c deleted file mode 100644 index 4c17f67db1f..00000000000 --- a/sbin/fsck/pass2.c +++ /dev/null @@ -1,471 +0,0 @@ -/* $NetBSD: pass2.c,v 1.12 1995/03/18 14:55:52 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)pass2.c 8.6 (Berkeley) 10/27/94"; -#else -static char rcsid[] = "$NetBSD: pass2.c,v 1.12 1995/03/18 14:55:52 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include "fsck.h" -#include "extern.h" - -#define MINDIRSIZE (sizeof (struct dirtemplate)) - -int pass2check(), blksort(); - -void -pass2() -{ - register struct dinode *dp; - register struct inoinfo **inpp, *inp; - struct inoinfo **inpend; - struct inodesc curino; - struct dinode dino; - char pathbuf[MAXPATHLEN + 1]; - - switch (statemap[ROOTINO]) { - - case USTATE: - pfatal("ROOT INODE UNALLOCATED"); - if (reply("ALLOCATE") == 0) - errexit(""); - if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) - errexit("CANNOT ALLOCATE ROOT INODE\n"); - break; - - case DCLEAR: - pfatal("DUPS/BAD IN ROOT INODE"); - if (reply("REALLOCATE")) { - freeino(ROOTINO); - if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) - errexit("CANNOT ALLOCATE ROOT INODE\n"); - break; - } - if (reply("CONTINUE") == 0) - errexit(""); - break; - - case FSTATE: - case FCLEAR: - pfatal("ROOT INODE NOT DIRECTORY"); - if (reply("REALLOCATE")) { - freeino(ROOTINO); - if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO) - errexit("CANNOT ALLOCATE ROOT INODE\n"); - break; - } - if (reply("FIX") == 0) - errexit(""); - dp = ginode(ROOTINO); - dp->di_mode &= ~IFMT; - dp->di_mode |= IFDIR; - inodirty(); - break; - - case DSTATE: - break; - - default: - errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]); - } - statemap[ROOTINO] = DFOUND; - if (newinofmt) { - statemap[WINO] = FSTATE; - typemap[WINO] = DT_WHT; - } - /* - * Sort the directory list into disk block order. - */ - qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort); - /* - * Check the integrity of each directory. - */ - memset(&curino, 0, sizeof(struct inodesc)); - curino.id_type = DATA; - curino.id_func = pass2check; - dp = &dino; - inpend = &inpsort[inplast]; - for (inpp = inpsort; inpp < inpend; inpp++) { - inp = *inpp; - if (inp->i_isize == 0) - continue; - if (inp->i_isize < MINDIRSIZE) { - direrror(inp->i_number, "DIRECTORY TOO SHORT"); - inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ); - if (reply("FIX") == 1) { - dp = ginode(inp->i_number); - dp->di_size = inp->i_isize; - inodirty(); - dp = &dino; - } - } else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) { - getpathname(pathbuf, inp->i_number, inp->i_number); - pwarn("DIRECTORY %s: LENGTH %d NOT MULTIPLE OF %d", - pathbuf, inp->i_isize, DIRBLKSIZ); - if (preen) - printf(" (ADJUSTED)\n"); - inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ); - if (preen || reply("ADJUST") == 1) { - dp = ginode(inp->i_number); - dp->di_size = roundup(inp->i_isize, DIRBLKSIZ); - inodirty(); - dp = &dino; - } - } - memset(&dino, 0, sizeof(struct dinode)); - dino.di_mode = IFDIR; - dp->di_size = inp->i_isize; - memcpy(&dp->di_db[0], &inp->i_blks[0], (size_t)inp->i_numblks); - curino.id_number = inp->i_number; - curino.id_parent = inp->i_parent; - (void)ckinode(dp, &curino); - } - /* - * Now that the parents of all directories have been found, - * make another pass to verify the value of `..' - */ - for (inpp = inpsort; inpp < inpend; inpp++) { - inp = *inpp; - if (inp->i_parent == 0 || inp->i_isize == 0) - continue; - if (statemap[inp->i_parent] == DFOUND && - statemap[inp->i_number] == DSTATE) - statemap[inp->i_number] = DFOUND; - if (inp->i_dotdot == inp->i_parent || - inp->i_dotdot == (ino_t)-1) - continue; - if (inp->i_dotdot == 0) { - inp->i_dotdot = inp->i_parent; - fileerror(inp->i_parent, inp->i_number, "MISSING '..'"); - if (reply("FIX") == 0) - continue; - (void)makeentry(inp->i_number, inp->i_parent, ".."); - lncntp[inp->i_parent]--; - continue; - } - fileerror(inp->i_parent, inp->i_number, - "BAD INODE NUMBER FOR '..'"); - if (reply("FIX") == 0) - continue; - lncntp[inp->i_dotdot]++; - lncntp[inp->i_parent]--; - inp->i_dotdot = inp->i_parent; - (void)changeino(inp->i_number, "..", inp->i_parent); - } - /* - * Mark all the directories that can be found from the root. - */ - propagate(); -} - -int -pass2check(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - register struct inoinfo *inp; - int n, entrysize, ret = 0; - struct dinode *dp; - char *errmsg; - struct direct proto; - char namebuf[MAXPATHLEN + 1]; - char pathbuf[MAXPATHLEN + 1]; - - /* - * If converting, set directory entry type. - */ - if (doinglevel2 && dirp->d_ino > 0 && dirp->d_ino < maxino) { - dirp->d_type = typemap[dirp->d_ino]; - ret |= ALTERED; - } - /* - * check for "." - */ - if (idesc->id_entryno != 0) - goto chk1; - if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) { - if (dirp->d_ino != idesc->id_number) { - direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'"); - dirp->d_ino = idesc->id_number; - if (reply("FIX") == 1) - ret |= ALTERED; - } - if (newinofmt && dirp->d_type != DT_DIR) { - direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'"); - dirp->d_type = DT_DIR; - if (reply("FIX") == 1) - ret |= ALTERED; - } - goto chk1; - } - direrror(idesc->id_number, "MISSING '.'"); - proto.d_ino = idesc->id_number; - if (newinofmt) - proto.d_type = DT_DIR; - else - proto.d_type = 0; - proto.d_namlen = 1; - (void)strcpy(proto.d_name, "."); -# if BYTE_ORDER == LITTLE_ENDIAN - if (!newinofmt) { - u_char tmp; - - tmp = proto.d_type; - proto.d_type = proto.d_namlen; - proto.d_namlen = tmp; - } -# endif - entrysize = DIRSIZ(0, &proto); - if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) { - pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n", - dirp->d_name); - } else if (dirp->d_reclen < entrysize) { - pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n"); - } else if (dirp->d_reclen < 2 * entrysize) { - proto.d_reclen = dirp->d_reclen; - memcpy(dirp, &proto, (size_t)entrysize); - if (reply("FIX") == 1) - ret |= ALTERED; - } else { - n = dirp->d_reclen - entrysize; - proto.d_reclen = entrysize; - memcpy(dirp, &proto, (size_t)entrysize); - idesc->id_entryno++; - lncntp[dirp->d_ino]--; - dirp = (struct direct *)((char *)(dirp) + entrysize); - memset(dirp, 0, (size_t)n); - dirp->d_reclen = n; - if (reply("FIX") == 1) - ret |= ALTERED; - } -chk1: - if (idesc->id_entryno > 1) - goto chk2; - inp = getinoinfo(idesc->id_number); - proto.d_ino = inp->i_parent; - if (newinofmt) - proto.d_type = DT_DIR; - else - proto.d_type = 0; - proto.d_namlen = 2; - (void)strcpy(proto.d_name, ".."); -# if BYTE_ORDER == LITTLE_ENDIAN - if (!newinofmt) { - u_char tmp; - - tmp = proto.d_type; - proto.d_type = proto.d_namlen; - proto.d_namlen = tmp; - } -# endif - entrysize = DIRSIZ(0, &proto); - if (idesc->id_entryno == 0) { - n = DIRSIZ(0, dirp); - if (dirp->d_reclen < n + entrysize) - goto chk2; - proto.d_reclen = dirp->d_reclen - n; - dirp->d_reclen = n; - idesc->id_entryno++; - lncntp[dirp->d_ino]--; - dirp = (struct direct *)((char *)(dirp) + n); - memset(dirp, 0, (size_t)proto.d_reclen); - dirp->d_reclen = proto.d_reclen; - } - if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) { - inp->i_dotdot = dirp->d_ino; - if (newinofmt && dirp->d_type != DT_DIR) { - direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'"); - dirp->d_type = DT_DIR; - if (reply("FIX") == 1) - ret |= ALTERED; - } - goto chk2; - } - if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) { - fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); - pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n", - dirp->d_name); - inp->i_dotdot = (ino_t)-1; - } else if (dirp->d_reclen < entrysize) { - fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); - pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n"); - inp->i_dotdot = (ino_t)-1; - } else if (inp->i_parent != 0) { - /* - * We know the parent, so fix now. - */ - inp->i_dotdot = inp->i_parent; - fileerror(inp->i_parent, idesc->id_number, "MISSING '..'"); - proto.d_reclen = dirp->d_reclen; - memcpy(dirp, &proto, (size_t)entrysize); - if (reply("FIX") == 1) - ret |= ALTERED; - } - idesc->id_entryno++; - if (dirp->d_ino != 0) - lncntp[dirp->d_ino]--; - return (ret|KEEPON); -chk2: - if (dirp->d_ino == 0) - return (ret|KEEPON); - if (dirp->d_namlen <= 2 && - dirp->d_name[0] == '.' && - idesc->id_entryno >= 2) { - if (dirp->d_namlen == 1) { - direrror(idesc->id_number, "EXTRA '.' ENTRY"); - dirp->d_ino = 0; - if (reply("FIX") == 1) - ret |= ALTERED; - return (KEEPON | ret); - } - if (dirp->d_name[1] == '.') { - direrror(idesc->id_number, "EXTRA '..' ENTRY"); - dirp->d_ino = 0; - if (reply("FIX") == 1) - ret |= ALTERED; - return (KEEPON | ret); - } - } - idesc->id_entryno++; - n = 0; - if (dirp->d_ino > maxino) { - fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE"); - n = reply("REMOVE"); - } else if (newinofmt && - ((dirp->d_ino == WINO && dirp->d_type != DT_WHT) || - (dirp->d_ino != WINO && dirp->d_type == DT_WHT))) { - fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY"); - dirp->d_ino = WINO; - dirp->d_type = DT_WHT; - if (reply("FIX") == 1) - ret |= ALTERED; - } else { -again: - switch (statemap[dirp->d_ino]) { - case USTATE: - if (idesc->id_entryno <= 2) - break; - fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED"); - n = reply("REMOVE"); - break; - - case DCLEAR: - case FCLEAR: - if (idesc->id_entryno <= 2) - break; - if (statemap[dirp->d_ino] == FCLEAR) - errmsg = "DUP/BAD"; - else if (!preen) - errmsg = "ZERO LENGTH DIRECTORY"; - else { - n = 1; - break; - } - fileerror(idesc->id_number, dirp->d_ino, errmsg); - if ((n = reply("REMOVE")) == 1) - break; - dp = ginode(dirp->d_ino); - statemap[dirp->d_ino] = - (dp->di_mode & IFMT) == IFDIR ? DSTATE : FSTATE; - lncntp[dirp->d_ino] = dp->di_nlink; - goto again; - - case DSTATE: - if (statemap[idesc->id_number] == DFOUND) - statemap[dirp->d_ino] = DFOUND; - /* fall through */ - - case DFOUND: - inp = getinoinfo(dirp->d_ino); - if (inp->i_parent != 0 && idesc->id_entryno > 2) { - getpathname(pathbuf, idesc->id_number, - idesc->id_number); - getpathname(namebuf, dirp->d_ino, dirp->d_ino); - pwarn("%s %s %s\n", pathbuf, - "IS AN EXTRANEOUS HARD LINK TO DIRECTORY", - namebuf); - if (preen) - printf(" (IGNORED)\n"); - else if ((n = reply("REMOVE")) == 1) - break; - } - if (idesc->id_entryno > 2) - inp->i_parent = idesc->id_number; - /* fall through */ - - case FSTATE: - if (newinofmt && dirp->d_type != typemap[dirp->d_ino]) { - fileerror(idesc->id_number, dirp->d_ino, - "BAD TYPE VALUE"); - dirp->d_type = typemap[dirp->d_ino]; - if (reply("FIX") == 1) - ret |= ALTERED; - } - lncntp[dirp->d_ino]--; - break; - - default: - errexit("BAD STATE %d FOR INODE I=%d", - statemap[dirp->d_ino], dirp->d_ino); - } - } - if (n == 0) - return (ret|KEEPON); - dirp->d_ino = 0; - return (ret|KEEPON|ALTERED); -} - -/* - * Routine to sort disk blocks. - */ -int -blksort(inpp1, inpp2) - struct inoinfo **inpp1, **inpp2; -{ - - return ((*inpp1)->i_blks[0] - (*inpp2)->i_blks[0]); -} diff --git a/sbin/fsck/pass3.c b/sbin/fsck/pass3.c deleted file mode 100644 index a30c99210d4..00000000000 --- a/sbin/fsck/pass3.c +++ /dev/null @@ -1,79 +0,0 @@ -/* $NetBSD: pass3.c,v 1.8 1995/03/18 14:55:54 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)pass3.c 8.1 (Berkeley) 6/5/93"; -#else -static char rcsid[] = "$NetBSD: pass3.c,v 1.8 1995/03/18 14:55:54 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include "fsck.h" -#include "extern.h" - -void -pass3() -{ - register struct inoinfo **inpp, *inp; - ino_t orphan; - int loopcnt; - - for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) { - inp = *inpp; - if (inp->i_number == ROOTINO || - !(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE)) - continue; - if (statemap[inp->i_number] == DCLEAR) - continue; - for (loopcnt = 0; ; loopcnt++) { - orphan = inp->i_number; - if (inp->i_parent == 0 || - statemap[inp->i_parent] != DSTATE || - loopcnt > numdirs) - break; - inp = getinoinfo(inp->i_parent); - } - (void)linkup(orphan, inp->i_dotdot); - inp->i_parent = inp->i_dotdot = lfdir; - lncntp[lfdir]--; - statemap[orphan] = DFOUND; - propagate(); - } -} diff --git a/sbin/fsck/pass4.c b/sbin/fsck/pass4.c deleted file mode 100644 index 0c3e9651ef9..00000000000 --- a/sbin/fsck/pass4.c +++ /dev/null @@ -1,140 +0,0 @@ -/* $NetBSD: pass4.c,v 1.9 1995/03/18 14:55:56 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93"; -#else -static char rcsid[] = "$NetBSD: pass4.c,v 1.9 1995/03/18 14:55:56 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include "fsck.h" -#include "extern.h" - -void -pass4() -{ - register ino_t inumber; - register struct zlncnt *zlnp; - struct dinode *dp; - struct inodesc idesc; - int n; - - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = ADDR; - idesc.id_func = pass4check; - for (inumber = ROOTINO; inumber <= lastino; inumber++) { - idesc.id_number = inumber; - switch (statemap[inumber]) { - - case FSTATE: - case DFOUND: - n = lncntp[inumber]; - if (n) - adjust(&idesc, (short)n); - else { - for (zlnp = zlnhead; zlnp; zlnp = zlnp->next) - if (zlnp->zlncnt == inumber) { - zlnp->zlncnt = zlnhead->zlncnt; - zlnp = zlnhead; - zlnhead = zlnhead->next; - free((char *)zlnp); - clri(&idesc, "UNREF", 1); - break; - } - } - break; - - case DSTATE: - clri(&idesc, "UNREF", 1); - break; - - case DCLEAR: - dp = ginode(inumber); - if (dp->di_size == 0) { - clri(&idesc, "ZERO LENGTH", 1); - break; - } - /* fall through */ - case FCLEAR: - clri(&idesc, "BAD/DUP", 1); - break; - - case USTATE: - break; - - default: - errexit("BAD STATE %d FOR INODE I=%d", - statemap[inumber], inumber); - } - } -} - -int -pass4check(idesc) - register struct inodesc *idesc; -{ - register struct dups *dlp; - int nfrags, res = KEEPON; - daddr_t blkno = idesc->id_blkno; - - for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { - if (chkrange(blkno, 1)) { - res = SKIP; - } else if (testbmap(blkno)) { - for (dlp = duplist; dlp; dlp = dlp->next) { - if (dlp->dup != blkno) - continue; - dlp->dup = duplist->dup; - dlp = duplist; - duplist = duplist->next; - free((char *)dlp); - break; - } - if (dlp == 0) { - clrbmap(blkno); - n_blks--; - } - } - } - return (res); -} diff --git a/sbin/fsck/pass5.c b/sbin/fsck/pass5.c deleted file mode 100644 index f26d679c45e..00000000000 --- a/sbin/fsck/pass5.c +++ /dev/null @@ -1,330 +0,0 @@ -/* $NetBSD: pass5.c,v 1.14 1995/03/21 01:30:16 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)pass5.c 8.6 (Berkeley) 11/30/94"; -#else -static char rcsid[] = "$NetBSD: pass5.c,v 1.14 1995/03/21 01:30:16 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include "fsck.h" -#include "extern.h" - -void -pass5() -{ - int c, blk, frags, basesize, sumsize, mapsize, savednrpos; - register struct fs *fs = &sblock; - register struct cg *cg = &cgrp; - daddr_t dbase, dmax; - register daddr_t d; - register long i, j; - struct csum *cs; - struct csum cstotal; - struct inodesc idesc[3]; - char buf[MAXBSIZE]; - register struct cg *newcg = (struct cg *)buf; - struct ocg *ocg = (struct ocg *)buf; - - statemap[WINO] = USTATE; - memset(newcg, 0, (size_t)fs->fs_cgsize); - newcg->cg_niblk = fs->fs_ipg; - if (cvtlevel >= 3) { - if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) { - if (preen) - pwarn("DELETING CLUSTERING MAPS\n"); - if (preen || reply("DELETE CLUSTERING MAPS")) { - fs->fs_contigsumsize = 0; - doinglevel1 = 1; - sbdirty(); - } - } - if (fs->fs_maxcontig > 1) { - char *doit = 0; - - if (fs->fs_contigsumsize < 1) { - doit = "CREAT"; - } else if (fs->fs_contigsumsize < fs->fs_maxcontig && - fs->fs_contigsumsize < FS_MAXCONTIG) { - doit = "EXPAND"; - } - if (doit) { - i = fs->fs_contigsumsize; - fs->fs_contigsumsize = - MIN(fs->fs_maxcontig, FS_MAXCONTIG); - if (CGSIZE(fs) > fs->fs_bsize) { - pwarn("CANNOT %s CLUSTER MAPS\n", doit); - fs->fs_contigsumsize = i; - } else if (preen || - reply("CREATE CLUSTER MAPS")) { - if (preen) - pwarn("%sING CLUSTER MAPS\n", - doit); - fs->fs_cgsize = - fragroundup(fs, CGSIZE(fs)); - doinglevel1 = 1; - sbdirty(); - } - } - } - } - switch ((int)fs->fs_postblformat) { - - case FS_42POSTBLFMT: - basesize = (char *)(&ocg->cg_btot[0]) - - (char *)(&ocg->cg_firstfield); - sumsize = &ocg->cg_iused[0] - (u_int8_t *)(&ocg->cg_btot[0]); - mapsize = &ocg->cg_free[howmany(fs->fs_fpg, NBBY)] - - (u_char *)&ocg->cg_iused[0]; - ocg->cg_magic = CG_MAGIC; - savednrpos = fs->fs_nrpos; - fs->fs_nrpos = 8; - break; - - case FS_DYNAMICPOSTBLFMT: - newcg->cg_btotoff = - &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield); - newcg->cg_boff = - newcg->cg_btotoff + fs->fs_cpg * sizeof(int32_t); - newcg->cg_iusedoff = newcg->cg_boff + - fs->fs_cpg * fs->fs_nrpos * sizeof(int16_t); - newcg->cg_freeoff = - newcg->cg_iusedoff + howmany(fs->fs_ipg, NBBY); - if (fs->fs_contigsumsize <= 0) { - newcg->cg_nextfreeoff = newcg->cg_freeoff + - howmany(fs->fs_cpg * fs->fs_spc / NSPF(fs), NBBY); - } else { - newcg->cg_clustersumoff = newcg->cg_freeoff + - howmany(fs->fs_cpg * fs->fs_spc / NSPF(fs), NBBY) - - sizeof(int32_t); - newcg->cg_clustersumoff = - roundup(newcg->cg_clustersumoff, sizeof(int32_t)); - newcg->cg_clusteroff = newcg->cg_clustersumoff + - (fs->fs_contigsumsize + 1) * sizeof(int32_t); - newcg->cg_nextfreeoff = newcg->cg_clusteroff + - howmany(fs->fs_cpg * fs->fs_spc / NSPB(fs), NBBY); - } - newcg->cg_magic = CG_MAGIC; - basesize = &newcg->cg_space[0] - - (u_char *)(&newcg->cg_firstfield); - sumsize = newcg->cg_iusedoff - newcg->cg_btotoff; - mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff; - break; - - default: - errexit("UNKNOWN ROTATIONAL TABLE FORMAT %d\n", - fs->fs_postblformat); - } - memset(&idesc[0], 0, sizeof idesc); - for (i = 0; i < 3; i++) { - idesc[i].id_type = ADDR; - if (doinglevel2) - idesc[i].id_fix = FIX; - } - memset(&cstotal, 0, sizeof(struct csum)); - j = blknum(fs, fs->fs_size + fs->fs_frag - 1); - for (i = fs->fs_size; i < j; i++) - setbmap(i); - for (c = 0; c < fs->fs_ncg; c++) { - getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize); - if (!cg_chkmagic(cg)) - pfatal("CG %d: BAD MAGIC NUMBER\n", c); - dbase = cgbase(fs, c); - dmax = dbase + fs->fs_fpg; - if (dmax > fs->fs_size) - dmax = fs->fs_size; - newcg->cg_time = cg->cg_time; - newcg->cg_cgx = c; - if (c == fs->fs_ncg - 1) - newcg->cg_ncyl = fs->fs_ncyl % fs->fs_cpg; - else - newcg->cg_ncyl = fs->fs_cpg; - newcg->cg_ndblk = dmax - dbase; - if (fs->fs_contigsumsize > 0) - newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag; - newcg->cg_cs.cs_ndir = 0; - newcg->cg_cs.cs_nffree = 0; - newcg->cg_cs.cs_nbfree = 0; - newcg->cg_cs.cs_nifree = fs->fs_ipg; - if (cg->cg_rotor < newcg->cg_ndblk) - newcg->cg_rotor = cg->cg_rotor; - else - newcg->cg_rotor = 0; - if (cg->cg_frotor < newcg->cg_ndblk) - newcg->cg_frotor = cg->cg_frotor; - else - newcg->cg_frotor = 0; - if (cg->cg_irotor < newcg->cg_niblk) - newcg->cg_irotor = cg->cg_irotor; - else - newcg->cg_irotor = 0; - memset(&newcg->cg_frsum[0], 0, sizeof newcg->cg_frsum); - memset(&cg_blktot(newcg)[0], 0, - (size_t)(sumsize + mapsize)); - if (fs->fs_postblformat == FS_42POSTBLFMT) - ocg->cg_magic = CG_MAGIC; - j = fs->fs_ipg * c; - for (i = 0; i < fs->fs_ipg; j++, i++) { - switch (statemap[j]) { - - case USTATE: - break; - - case DSTATE: - case DCLEAR: - case DFOUND: - newcg->cg_cs.cs_ndir++; - /* fall through */ - - case FSTATE: - case FCLEAR: - newcg->cg_cs.cs_nifree--; - setbit(cg_inosused(newcg), i); - break; - - default: - if (j < ROOTINO) - break; - errexit("BAD STATE %d FOR INODE I=%d", - statemap[j], j); - } - } - if (c == 0) - for (i = 0; i < ROOTINO; i++) { - setbit(cg_inosused(newcg), i); - newcg->cg_cs.cs_nifree--; - } - for (i = 0, d = dbase; - d < dmax; - d += fs->fs_frag, i += fs->fs_frag) { - frags = 0; - for (j = 0; j < fs->fs_frag; j++) { - if (testbmap(d + j)) - continue; - setbit(cg_blksfree(newcg), i + j); - frags++; - } - if (frags == fs->fs_frag) { - newcg->cg_cs.cs_nbfree++; - j = cbtocylno(fs, i); - cg_blktot(newcg)[j]++; - cg_blks(fs, newcg, j)[cbtorpos(fs, i)]++; - if (fs->fs_contigsumsize > 0) - setbit(cg_clustersfree(newcg), - i / fs->fs_frag); - } else if (frags > 0) { - newcg->cg_cs.cs_nffree += frags; - blk = blkmap(fs, cg_blksfree(newcg), i); - ffs_fragacct(fs, blk, newcg->cg_frsum, 1); - } - } - if (fs->fs_contigsumsize > 0) { - int32_t *sump = cg_clustersum(newcg); - u_char *mapp = cg_clustersfree(newcg); - int map = *mapp++; - int bit = 1; - int run = 0; - - for (i = 0; i < newcg->cg_nclusterblks; i++) { - if ((map & bit) != 0) { - run++; - } else if (run != 0) { - if (run > fs->fs_contigsumsize) - run = fs->fs_contigsumsize; - sump[run]++; - run = 0; - } - if ((i & (NBBY - 1)) != (NBBY - 1)) { - bit <<= 1; - } else { - map = *mapp++; - bit = 1; - } - } - if (run != 0) { - if (run > fs->fs_contigsumsize) - run = fs->fs_contigsumsize; - sump[run]++; - } - } - cstotal.cs_nffree += newcg->cg_cs.cs_nffree; - cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree; - cstotal.cs_nifree += newcg->cg_cs.cs_nifree; - cstotal.cs_ndir += newcg->cg_cs.cs_ndir; - cs = &fs->fs_cs(fs, c); - if (memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0 && - dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) { - memcpy(cs, &newcg->cg_cs, sizeof *cs); - sbdirty(); - } - if (doinglevel1) { - memcpy(cg, newcg, (size_t)fs->fs_cgsize); - cgdirty(); - continue; - } - if (memcmp(cg_inosused(newcg), - cg_inosused(cg), mapsize) != 0 && - dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) { - memcpy(cg_inosused(cg), cg_inosused(newcg), - (size_t)mapsize); - cgdirty(); - } - if ((memcmp(newcg, cg, basesize) != 0 || - memcmp(&cg_blktot(newcg)[0], - &cg_blktot(cg)[0], sumsize) != 0) && - dofix(&idesc[2], "SUMMARY INFORMATION BAD")) { - memcpy(cg, newcg, (size_t)basesize); - memcpy(&cg_blktot(cg)[0], - &cg_blktot(newcg)[0], (size_t)sumsize); - cgdirty(); - } - } - if (fs->fs_postblformat == FS_42POSTBLFMT) - fs->fs_nrpos = savednrpos; - if (memcmp(&cstotal, &fs->fs_cstotal, sizeof *cs) != 0 - && dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) { - memcpy(&fs->fs_cstotal, &cstotal, sizeof *cs); - fs->fs_ronly = 0; - fs->fs_fmod = 0; - sbdirty(); - } -} diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c deleted file mode 100644 index d347cd3f1de..00000000000 --- a/sbin/fsck/preen.c +++ /dev/null @@ -1,370 +0,0 @@ -/* $NetBSD: preen.c,v 1.11 1995/03/18 14:55:59 cgd Exp $ */ - -/* - * Copyright (c) 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)preen.c 8.3 (Berkeley) 12/6/94"; -#else -static char rcsid[] = "$NetBSD: preen.c,v 1.11 1995/03/18 14:55:59 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct part { - struct part *next; /* forward link of partitions on disk */ - char *name; /* device name */ - char *fsname; /* mounted filesystem name */ - long auxdata; /* auxillary data for application */ -} *badlist, **badnext = &badlist; - -struct disk { - char *name; /* disk base name */ - struct disk *next; /* forward link for list of disks */ - struct part *part; /* head of list of partitions on disk */ - int pid; /* If != 0, pid of proc working on */ -} *disks; - -int nrun, ndisks; -char hotroot; - -char *rawname(), *unrawname(), *blockcheck(); -void addpart __P((char *, char *, long)); -int startdisk __P((struct disk *, int (*)() )); - -int -checkfstab(preen, maxrun, docheck, chkit) - int preen, maxrun; - int (*docheck)(), (*chkit)(); -{ - register struct fstab *fsp; - register struct disk *dk, *nextdisk; - register struct part *pt; - int ret, pid, retcode, passno, sumstatus, status; - long auxdata; - char *name; - - sumstatus = 0; - for (passno = 1; passno <= 2; passno++) { - if (setfsent() == 0) { - fprintf(stderr, "Can't open checklist file: %s\n", - _PATH_FSTAB); - return (8); - } - while ((fsp = getfsent()) != 0) { - if ((auxdata = (*docheck)(fsp)) == 0) - continue; - if (preen == 0 || passno == 1 && fsp->fs_passno == 1) { - if (name = blockcheck(fsp->fs_spec)) { - if (sumstatus = (*chkit)(name, - fsp->fs_file, auxdata, 0)) - return (sumstatus); - } else if (preen) - return (8); - } else if (passno == 2 && fsp->fs_passno > 1) { - if ((name = blockcheck(fsp->fs_spec)) == NULL) { - fprintf(stderr, "BAD DISK NAME %s\n", - fsp->fs_spec); - sumstatus |= 8; - continue; - } - addpart(name, fsp->fs_file, auxdata); - } - } - if (preen == 0) - return (0); - } - if (preen) { - if (maxrun == 0) - maxrun = ndisks; - if (maxrun > ndisks) - maxrun = ndisks; - nextdisk = disks; - for (passno = 0; passno < maxrun; ++passno) { - while (ret = startdisk(nextdisk, chkit) && nrun > 0) - sleep(10); - if (ret) - return (ret); - nextdisk = nextdisk->next; - } - while ((pid = wait(&status)) != -1) { - for (dk = disks; dk; dk = dk->next) - if (dk->pid == pid) - break; - if (dk == 0) { - printf("Unknown pid %d\n", pid); - continue; - } - if (WIFEXITED(status)) - retcode = WEXITSTATUS(status); - else - retcode = 0; - if (WIFSIGNALED(status)) { - printf("%s (%s): EXITED WITH SIGNAL %d\n", - dk->part->name, dk->part->fsname, - WTERMSIG(status)); - retcode = 8; - } - if (retcode != 0) { - sumstatus |= retcode; - *badnext = dk->part; - badnext = &dk->part->next; - dk->part = dk->part->next; - *badnext = NULL; - } else - dk->part = dk->part->next; - dk->pid = 0; - nrun--; - if (dk->part == NULL) - ndisks--; - - if (nextdisk == NULL) { - if (dk->part) { - while (ret = startdisk(dk, chkit) && - nrun > 0) - sleep(10); - if (ret) - return (ret); - } - } else if (nrun < maxrun && nrun < ndisks) { - for ( ;; ) { - if ((nextdisk = nextdisk->next) == NULL) - nextdisk = disks; - if (nextdisk->part != NULL && - nextdisk->pid == 0) - break; - } - while (ret = startdisk(nextdisk, chkit) && - nrun > 0) - sleep(10); - if (ret) - return (ret); - } - } - } - if (sumstatus) { - if (badlist == 0) - return (sumstatus); - fprintf(stderr, "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t", - badlist->next ? "S" : "", "UNEXPECTED INCONSISTENCY:"); - for (pt = badlist; pt; pt = pt->next) - fprintf(stderr, "%s (%s)%s", pt->name, pt->fsname, - pt->next ? ", " : "\n"); - return (sumstatus); - } - (void)endfsent(); - return (0); -} - -struct disk * -finddisk(name) - char *name; -{ - register struct disk *dk, **dkp; - register char *p; - size_t len; - - for (p = name + strlen(name) - 1; p >= name; --p) - if (isdigit(*p)) { - len = p - name + 1; - break; - } - if (p < name) - len = strlen(name); - - for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) { - if (strncmp(dk->name, name, len) == 0 && - dk->name[len] == 0) - return (dk); - } - if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) { - fprintf(stderr, "out of memory"); - exit (8); - } - dk = *dkp; - if ((dk->name = malloc(len + 1)) == NULL) { - fprintf(stderr, "out of memory"); - exit (8); - } - (void)strncpy(dk->name, name, len); - dk->name[len] = '\0'; - dk->part = NULL; - dk->next = NULL; - dk->pid = 0; - ndisks++; - return (dk); -} - -void -addpart(name, fsname, auxdata) - char *name, *fsname; - long auxdata; -{ - struct disk *dk = finddisk(name); - register struct part *pt, **ppt = &dk->part; - - for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next) - if (strcmp(pt->name, name) == 0) { - printf("%s in fstab more than once!\n", name); - return; - } - if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) { - fprintf(stderr, "out of memory"); - exit (8); - } - pt = *ppt; - if ((pt->name = malloc(strlen(name) + 1)) == NULL) { - fprintf(stderr, "out of memory"); - exit (8); - } - (void)strcpy(pt->name, name); - if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) { - fprintf(stderr, "out of memory"); - exit (8); - } - (void)strcpy(pt->fsname, fsname); - pt->next = NULL; - pt->auxdata = auxdata; -} - -int -startdisk(dk, checkit) - register struct disk *dk; - int (*checkit)(); -{ - register struct part *pt = dk->part; - - dk->pid = fork(); - if (dk->pid < 0) { - perror("fork"); - return (8); - } - if (dk->pid == 0) - exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1)); - nrun++; - return (0); -} - -char * -blockcheck(origname) - char *origname; -{ - struct stat stslash, stblock, stchar; - char *newname, *raw; - int retried = 0; - - hotroot = 0; - if (stat("/", &stslash) < 0) { - perror("/"); - printf("Can't stat root\n"); - return (origname); - } - newname = origname; -retry: - if (stat(newname, &stblock) < 0) { - perror(newname); - printf("Can't stat %s\n", newname); - return (origname); - } - if (S_ISBLK(stblock.st_mode)) { - if (stslash.st_dev == stblock.st_rdev) - hotroot++; - raw = rawname(newname); - if (stat(raw, &stchar) < 0) { - perror(raw); - printf("Can't stat %s\n", raw); - return (origname); - } - if (S_ISCHR(stchar.st_mode)) { - return (raw); - } else { - printf("%s is not a character device\n", raw); - return (origname); - } - } else if (S_ISCHR(stblock.st_mode) && !retried) { - newname = unrawname(newname); - retried++; - goto retry; - } - /* - * Not a block or character device, just return name and - * let the user decide whether to use it. - */ - return (origname); -} - -char * -unrawname(name) - char *name; -{ - char *dp; - struct stat stb; - - if ((dp = strrchr(name, '/')) == 0) - return (name); - if (stat(name, &stb) < 0) - return (name); - if (!S_ISCHR(stb.st_mode)) - return (name); - if (dp[1] != 'r') - return (name); - (void)strcpy(&dp[1], &dp[2]); - return (name); -} - -char * -rawname(name) - char *name; -{ - static char rawbuf[32]; - char *dp; - - if ((dp = strrchr(name, '/')) == 0) - return (0); - *dp = 0; - (void)strcpy(rawbuf, name); - *dp = '/'; - (void)strcat(rawbuf, "/r"); - (void)strcat(rawbuf, &dp[1]); - return (rawbuf); -} diff --git a/sbin/fsck/setup.c b/sbin/fsck/setup.c deleted file mode 100644 index 64bc542b990..00000000000 --- a/sbin/fsck/setup.c +++ /dev/null @@ -1,511 +0,0 @@ -/* $NetBSD: setup.c,v 1.22 1995/07/12 01:49:23 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)setup.c 8.5 (Berkeley) 11/23/94"; -#else -static char rcsid[] = "$NetBSD: setup.c,v 1.22 1995/07/12 01:49:23 cgd Exp $"; -#endif -#endif /* not lint */ - -#define DKTYPENAMES -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include "fsck.h" -#include "extern.h" - -struct bufarea asblk; -#define altsblock (*asblk.b_un.b_fs) -#define POWEROF2(num) (((num) & ((num) - 1)) == 0) - -void badsb __P((int, char *)); -int calcsb __P((char *, int, struct fs *)); -struct disklabel *getdisklabel(); -int readsb __P((int)); - -int -setup(dev) - char *dev; -{ - long cg, size, asked, i, j; - long bmapsize; - struct disklabel *lp; - off_t sizepb; - struct stat statb; - struct fs proto; - int doskipclean; - - havesb = 0; - fswritefd = -1; - doskipclean = skipclean; - if (stat(dev, &statb) < 0) { - printf("Can't stat %s: %s\n", dev, strerror(errno)); - return (0); - } - if (!S_ISCHR(statb.st_mode)) { - pfatal("%s is not a character device", dev); - if (reply("CONTINUE") == 0) - return (0); - } - if ((fsreadfd = open(dev, O_RDONLY)) < 0) { - printf("Can't open %s: %s\n", dev, strerror(errno)); - return (0); - } - if (preen == 0) - printf("** %s", dev); - if (nflag || (fswritefd = open(dev, O_WRONLY)) < 0) { - fswritefd = -1; - if (preen) - pfatal("NO WRITE ACCESS"); - printf(" (NO WRITE)"); - } - if (preen == 0) - printf("\n"); - fsmodified = 0; - lfdir = 0; - initbarea(&sblk); - initbarea(&asblk); - sblk.b_un.b_buf = malloc(SBSIZE); - asblk.b_un.b_buf = malloc(SBSIZE); - if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL) - errexit("cannot allocate space for superblock\n"); - if (lp = getdisklabel((char *)NULL, fsreadfd)) - dev_bsize = secsize = lp->d_secsize; - else - dev_bsize = secsize = DEV_BSIZE; - /* - * Read in the superblock, looking for alternates if necessary - */ - if (readsb(1) == 0) { - if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0) - return(0); - if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0) - return (0); - for (cg = 0; cg < proto.fs_ncg; cg++) { - bflag = fsbtodb(&proto, cgsblock(&proto, cg)); - if (readsb(0) != 0) - break; - } - if (cg >= proto.fs_ncg) { - printf("%s %s\n%s %s\n%s %s\n", - "SEARCH FOR ALTERNATE SUPER-BLOCK", - "FAILED. YOU MUST USE THE", - "-b OPTION TO FSCK TO SPECIFY THE", - "LOCATION OF AN ALTERNATE", - "SUPER-BLOCK TO SUPPLY NEEDED", - "INFORMATION; SEE fsck(8)."); - return(0); - } - doskipclean = 0; - pwarn("USING ALTERNATE SUPERBLOCK AT %d\n", bflag); - } - if (debug) - printf("clean = %d\n", sblock.fs_clean); - if (sblock.fs_clean & FS_ISCLEAN) { - if (doskipclean) { - pwarn("%sile system is clean; not checking\n", - preen ? "f" : "** F"); - return (-1); - } - if (!preen) - pwarn("** File system is already clean\n"); - } - maxfsblock = sblock.fs_size; - maxino = sblock.fs_ncg * sblock.fs_ipg; - /* - * Check and potentially fix certain fields in the super block. - */ - if (sblock.fs_optim != FS_OPTTIME && sblock.fs_optim != FS_OPTSPACE) { - pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK"); - if (reply("SET TO DEFAULT") == 1) { - sblock.fs_optim = FS_OPTTIME; - sbdirty(); - } - } - if ((sblock.fs_minfree < 0 || sblock.fs_minfree > 99)) { - pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", - sblock.fs_minfree); - if (reply("SET TO DEFAULT") == 1) { - sblock.fs_minfree = 10; - sbdirty(); - } - } - if (sblock.fs_interleave < 1 || - sblock.fs_interleave > sblock.fs_nsect) { - pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", - sblock.fs_interleave); - sblock.fs_interleave = 1; - if (preen) - printf(" (FIXED)\n"); - if (preen || reply("SET TO DEFAULT") == 1) { - sbdirty(); - dirty(&asblk); - } - } - if (sblock.fs_npsect < sblock.fs_nsect || - sblock.fs_npsect > sblock.fs_nsect*2) { - pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", - sblock.fs_npsect); - sblock.fs_npsect = sblock.fs_nsect; - if (preen) - printf(" (FIXED)\n"); - if (preen || reply("SET TO DEFAULT") == 1) { - sbdirty(); - dirty(&asblk); - } - } - if (sblock.fs_inodefmt >= FS_44INODEFMT) { - newinofmt = 1; - } else { - sblock.fs_qbmask = ~sblock.fs_bmask; - sblock.fs_qfmask = ~sblock.fs_fmask; - newinofmt = 0; - } - /* - * Convert to new inode format. - */ - if (cvtlevel >= 2 && sblock.fs_inodefmt < FS_44INODEFMT) { - if (preen) - pwarn("CONVERTING TO NEW INODE FORMAT\n"); - else if (!reply("CONVERT TO NEW INODE FORMAT")) - return(0); - doinglevel2++; - sblock.fs_inodefmt = FS_44INODEFMT; - sizepb = sblock.fs_bsize; - sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1; - for (i = 0; i < NIADDR; i++) { - sizepb *= NINDIR(&sblock); - sblock.fs_maxfilesize += sizepb; - } - sblock.fs_maxsymlinklen = MAXSYMLINKLEN; - sblock.fs_qbmask = ~sblock.fs_bmask; - sblock.fs_qfmask = ~sblock.fs_fmask; - sbdirty(); - dirty(&asblk); - } - /* - * Convert to new cylinder group format. - */ - if (cvtlevel >= 1 && sblock.fs_postblformat == FS_42POSTBLFMT) { - if (preen) - pwarn("CONVERTING TO NEW CYLINDER GROUP FORMAT\n"); - else if (!reply("CONVERT TO NEW CYLINDER GROUP FORMAT")) - return(0); - doinglevel1++; - sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT; - sblock.fs_nrpos = 8; - sblock.fs_postbloff = - (char *)(&sblock.fs_opostbl[0][0]) - - (char *)(&sblock.fs_firstfield); - sblock.fs_rotbloff = &sblock.fs_space[0] - - (u_char *)(&sblock.fs_firstfield); - sblock.fs_cgsize = - fragroundup(&sblock, CGSIZE(&sblock)); - sbdirty(); - dirty(&asblk); - } - if (asblk.b_dirty && !bflag) { - memcpy(&altsblock, &sblock, (size_t)sblock.fs_sbsize); - flush(fswritefd, &asblk); - } - /* - * read in the summary info. - */ - asked = 0; - for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) { - size = sblock.fs_cssize - i < sblock.fs_bsize ? - sblock.fs_cssize - i : sblock.fs_bsize; - sblock.fs_csp[j] = (struct csum *)calloc(1, (unsigned)size); - if (bread(fsreadfd, (char *)sblock.fs_csp[j], - fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag), - size) != 0 && !asked) { - pfatal("BAD SUMMARY INFORMATION"); - if (reply("CONTINUE") == 0) - errexit(""); - asked++; - } - } - /* - * allocate and initialize the necessary maps - */ - bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t)); - blockmap = calloc((unsigned)bmapsize, sizeof (char)); - if (blockmap == NULL) { - printf("cannot alloc %u bytes for blockmap\n", - (unsigned)bmapsize); - goto badsblabel; - } - statemap = calloc((unsigned)(maxino + 1), sizeof(char)); - if (statemap == NULL) { - printf("cannot alloc %u bytes for statemap\n", - (unsigned)(maxino + 1)); - goto badsblabel; - } - typemap = calloc((unsigned)(maxino + 1), sizeof(char)); - if (typemap == NULL) { - printf("cannot alloc %u bytes for typemap\n", - (unsigned)(maxino + 1)); - goto badsblabel; - } - lncntp = (int16_t *)calloc((unsigned)(maxino + 1), sizeof(int16_t)); - if (lncntp == NULL) { - printf("cannot alloc %u bytes for lncntp\n", - (unsigned)(maxino + 1) * sizeof(int16_t)); - goto badsblabel; - } - numdirs = sblock.fs_cstotal.cs_ndir; - inplast = 0; - listmax = numdirs + 10; - inpsort = (struct inoinfo **)calloc((unsigned)listmax, - sizeof(struct inoinfo *)); - inphead = (struct inoinfo **)calloc((unsigned)numdirs, - sizeof(struct inoinfo *)); - if (inpsort == NULL || inphead == NULL) { - printf("cannot alloc %u bytes for inphead\n", - (unsigned)numdirs * sizeof(struct inoinfo *)); - goto badsblabel; - } - bufinit(); - return (1); - -badsblabel: - ckfini(0); - return (0); -} - -/* - * Read in the super block and its summary info. - */ -int -readsb(listerr) - int listerr; -{ - daddr_t super = bflag ? bflag : SBOFF / dev_bsize; - - if (bread(fsreadfd, (char *)&sblock, super, (long)SBSIZE) != 0) - return (0); - sblk.b_bno = super; - sblk.b_size = SBSIZE; - /* - * run a few consistency checks of the super block - */ - if (sblock.fs_magic != FS_MAGIC) - { badsb(listerr, "MAGIC NUMBER WRONG"); return (0); } - if (sblock.fs_ncg < 1) - { badsb(listerr, "NCG OUT OF RANGE"); return (0); } - if (sblock.fs_cpg < 1) - { badsb(listerr, "CPG OUT OF RANGE"); return (0); } - if (sblock.fs_ncg * sblock.fs_cpg < sblock.fs_ncyl || - (sblock.fs_ncg - 1) * sblock.fs_cpg >= sblock.fs_ncyl) - { badsb(listerr, "NCYL LESS THAN NCG*CPG"); return (0); } - if (sblock.fs_sbsize > SBSIZE) - { badsb(listerr, "SIZE PREPOSTEROUSLY LARGE"); return (0); } - /* - * Compute block size that the filesystem is based on, - * according to fsbtodb, and adjust superblock block number - * so we can tell if this is an alternate later. - */ - super *= dev_bsize; - dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1); - sblk.b_bno = super / dev_bsize; - if (bflag) { - havesb = 1; - return (1); - } - /* - * Set all possible fields that could differ, then do check - * of whole super block against an alternate super block. - * When an alternate super-block is specified this check is skipped. - */ - getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize); - if (asblk.b_errs) - return (0); - altsblock.fs_firstfield = sblock.fs_firstfield; - altsblock.fs_fscktime = sblock.fs_fscktime; - altsblock.fs_time = sblock.fs_time; - altsblock.fs_cstotal = sblock.fs_cstotal; - altsblock.fs_cgrotor = sblock.fs_cgrotor; - altsblock.fs_fmod = sblock.fs_fmod; - altsblock.fs_clean = sblock.fs_clean; - altsblock.fs_ronly = sblock.fs_ronly; - altsblock.fs_flags = sblock.fs_flags; - altsblock.fs_maxcontig = sblock.fs_maxcontig; - altsblock.fs_minfree = sblock.fs_minfree; - altsblock.fs_optim = sblock.fs_optim; - altsblock.fs_rotdelay = sblock.fs_rotdelay; - altsblock.fs_maxbpg = sblock.fs_maxbpg; - memcpy(altsblock.fs_csp, sblock.fs_csp, - sizeof sblock.fs_csp); - altsblock.fs_maxcluster = sblock.fs_maxcluster; - memcpy(altsblock.fs_fsmnt, sblock.fs_fsmnt, - sizeof sblock.fs_fsmnt); - memcpy(altsblock.fs_sparecon, sblock.fs_sparecon, - sizeof sblock.fs_sparecon); - /* - * The following should not have to be copied. - */ - altsblock.fs_fsbtodb = sblock.fs_fsbtodb; - altsblock.fs_interleave = sblock.fs_interleave; - altsblock.fs_npsect = sblock.fs_npsect; - altsblock.fs_nrpos = sblock.fs_nrpos; - altsblock.fs_state = sblock.fs_state; - altsblock.fs_qbmask = sblock.fs_qbmask; - altsblock.fs_qfmask = sblock.fs_qfmask; - altsblock.fs_state = sblock.fs_state; - altsblock.fs_maxfilesize = sblock.fs_maxfilesize; - if (memcmp(&sblock, &altsblock, (int)sblock.fs_sbsize)) { - if (debug) { - long *nlp, *olp, *endlp; - - printf("superblock mismatches\n"); - nlp = (long *)&altsblock; - olp = (long *)&sblock; - endlp = olp + (sblock.fs_sbsize / sizeof *olp); - for ( ; olp < endlp; olp++, nlp++) { - if (*olp == *nlp) - continue; - printf("offset %d, original %d, alternate %d\n", - olp - (long *)&sblock, *olp, *nlp); - } - } - badsb(listerr, - "VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE"); - return (0); - } - havesb = 1; - return (1); -} - -void -badsb(listerr, s) - int listerr; - char *s; -{ - - if (!listerr) - return; - if (preen) - printf("%s: ", cdevname); - pfatal("BAD SUPER BLOCK: %s\n", s); -} - -/* - * Calculate a prototype superblock based on information in the disk label. - * When done the cgsblock macro can be calculated and the fs_ncg field - * can be used. Do NOT attempt to use other macros without verifying that - * their needed information is available! - */ -int -calcsb(dev, devfd, fs) - char *dev; - int devfd; - register struct fs *fs; -{ - register struct disklabel *lp; - register struct partition *pp; - register char *cp; - int i; - - cp = strchr(dev, '\0') - 1; - if (cp == (char *)-1 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)) { - pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev); - return (0); - } - lp = getdisklabel(dev, devfd); - if (isdigit(*cp)) - pp = &lp->d_partitions[0]; - else - pp = &lp->d_partitions[*cp - 'a']; - if (pp->p_fstype != FS_BSDFFS) { - pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n", - dev, pp->p_fstype < FSMAXTYPES ? - fstypenames[pp->p_fstype] : "unknown"); - return (0); - } - memset(fs, 0, sizeof(struct fs)); - fs->fs_fsize = pp->p_fsize; - fs->fs_frag = pp->p_frag; - fs->fs_cpg = pp->p_cpg; - fs->fs_size = pp->p_size; - fs->fs_ntrak = lp->d_ntracks; - fs->fs_nsect = lp->d_nsectors; - fs->fs_spc = lp->d_secpercyl; - fs->fs_nspf = fs->fs_fsize / lp->d_secsize; - fs->fs_sblkno = roundup( - howmany(lp->d_bbsize + lp->d_sbsize, fs->fs_fsize), - fs->fs_frag); - fs->fs_cgmask = 0xffffffff; - for (i = fs->fs_ntrak; i > 1; i >>= 1) - fs->fs_cgmask <<= 1; - if (!POWEROF2(fs->fs_ntrak)) - fs->fs_cgmask <<= 1; - fs->fs_cgoffset = roundup( - howmany(fs->fs_nsect, NSPF(fs)), fs->fs_frag); - fs->fs_fpg = (fs->fs_cpg * fs->fs_spc) / NSPF(fs); - fs->fs_ncg = howmany(fs->fs_size / fs->fs_spc, fs->fs_cpg); - for (fs->fs_fsbtodb = 0, i = NSPF(fs); i > 1; i >>= 1) - fs->fs_fsbtodb++; - dev_bsize = lp->d_secsize; - return (1); -} - -struct disklabel * -getdisklabel(s, fd) - char *s; - int fd; -{ - static struct disklabel lab; - - if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { - if (s == NULL) - return ((struct disklabel *)NULL); - pwarn("ioctl (GCINFO): %s\n", strerror(errno)); - errexit("%s: can't read disk label\n", s); - } - return (&lab); -} diff --git a/sbin/fsck/utilities.c b/sbin/fsck/utilities.c deleted file mode 100644 index 74d2db5be1d..00000000000 --- a/sbin/fsck/utilities.c +++ /dev/null @@ -1,604 +0,0 @@ -/* $NetBSD: utilities.c,v 1.15 1995/04/23 10:33:09 cgd Exp $ */ - -/* - * Copyright (c) 1980, 1986, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93"; -#else -static char rcsid[] = "$NetBSD: utilities.c,v 1.15 1995/04/23 10:33:09 cgd Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fsck.h" -#include "extern.h" - -long diskreads, totalreads; /* Disk cache statistics */ - -int -ftypeok(dp) - struct dinode *dp; -{ - switch (dp->di_mode & IFMT) { - - case IFDIR: - case IFREG: - case IFBLK: - case IFCHR: - case IFLNK: - case IFSOCK: - case IFIFO: - return (1); - - default: - if (debug) - printf("bad file type 0%o\n", dp->di_mode); - return (0); - } -} - -int -reply(question) - char *question; -{ - int persevere; - char c; - - if (preen) - pfatal("INTERNAL ERROR: GOT TO reply()"); - persevere = !strcmp(question, "CONTINUE"); - printf("\n"); - if (!persevere && (nflag || fswritefd < 0)) { - printf("%s? no\n\n", question); - return (0); - } - if (yflag || (persevere && nflag)) { - printf("%s? yes\n\n", question); - return (1); - } - do { - printf("%s? [yn] ", question); - (void) fflush(stdout); - c = getc(stdin); - while (c != '\n' && getc(stdin) != '\n') - if (feof(stdin)) - return (0); - } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N'); - printf("\n"); - if (c == 'y' || c == 'Y') - return (1); - return (0); -} - -/* - * Malloc buffers and set up cache. - */ -void -bufinit() -{ - register struct bufarea *bp; - long bufcnt, i; - char *bufp; - - pbp = pdirbp = (struct bufarea *)0; - bufp = malloc((unsigned int)sblock.fs_bsize); - if (bufp == 0) - errexit("cannot allocate buffer pool\n"); - cgblk.b_un.b_buf = bufp; - initbarea(&cgblk); - bufhead.b_next = bufhead.b_prev = &bufhead; - bufcnt = MAXBUFSPACE / sblock.fs_bsize; - if (bufcnt < MINBUFS) - bufcnt = MINBUFS; - for (i = 0; i < bufcnt; i++) { - bp = (struct bufarea *)malloc(sizeof(struct bufarea)); - bufp = malloc((unsigned int)sblock.fs_bsize); - if (bp == NULL || bufp == NULL) { - if (i >= MINBUFS) - break; - errexit("cannot allocate buffer pool\n"); - } - bp->b_un.b_buf = bufp; - bp->b_prev = &bufhead; - bp->b_next = bufhead.b_next; - bufhead.b_next->b_prev = bp; - bufhead.b_next = bp; - initbarea(bp); - } - bufhead.b_size = i; /* save number of buffers */ -} - -/* - * Manage a cache of directory blocks. - */ -struct bufarea * -getdatablk(blkno, size) - daddr_t blkno; - long size; -{ - register struct bufarea *bp; - - for (bp = bufhead.b_next; bp != &bufhead; bp = bp->b_next) - if (bp->b_bno == fsbtodb(&sblock, blkno)) - goto foundit; - for (bp = bufhead.b_prev; bp != &bufhead; bp = bp->b_prev) - if ((bp->b_flags & B_INUSE) == 0) - break; - if (bp == &bufhead) - errexit("deadlocked buffer pool\n"); - getblk(bp, blkno, size); - /* fall through */ -foundit: - totalreads++; - bp->b_prev->b_next = bp->b_next; - bp->b_next->b_prev = bp->b_prev; - bp->b_prev = &bufhead; - bp->b_next = bufhead.b_next; - bufhead.b_next->b_prev = bp; - bufhead.b_next = bp; - bp->b_flags |= B_INUSE; - return (bp); -} - -void -getblk(bp, blk, size) - register struct bufarea *bp; - daddr_t blk; - long size; -{ - daddr_t dblk; - - dblk = fsbtodb(&sblock, blk); - if (bp->b_bno != dblk) { - flush(fswritefd, bp); - diskreads++; - bp->b_errs = bread(fsreadfd, bp->b_un.b_buf, dblk, size); - bp->b_bno = dblk; - bp->b_size = size; - } -} - -void -flush(fd, bp) - int fd; - register struct bufarea *bp; -{ - register int i, j; - - if (!bp->b_dirty) - return; - if (bp->b_errs != 0) - pfatal("WRITING %sZERO'ED BLOCK %d TO DISK\n", - (bp->b_errs == bp->b_size / dev_bsize) ? "" : "PARTIALLY ", - bp->b_bno); - bp->b_dirty = 0; - bp->b_errs = 0; - bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size); - if (bp != &sblk) - return; - for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) { - bwrite(fswritefd, (char *)sblock.fs_csp[j], - fsbtodb(&sblock, sblock.fs_csaddr + j * sblock.fs_frag), - sblock.fs_cssize - i < sblock.fs_bsize ? - sblock.fs_cssize - i : sblock.fs_bsize); - } -} - -void -rwerror(mesg, blk) - char *mesg; - daddr_t blk; -{ - - if (preen == 0) - printf("\n"); - pfatal("CANNOT %s: BLK %ld", mesg, blk); - if (reply("CONTINUE") == 0) - errexit("Program terminated\n"); -} - -void -ckfini(markclean) - int markclean; -{ - register struct bufarea *bp, *nbp; - int cnt = 0; - - if (fswritefd < 0) { - (void)close(fsreadfd); - return; - } - flush(fswritefd, &sblk); - if (havesb && sblk.b_bno != SBOFF / dev_bsize && - !preen && reply("UPDATE STANDARD SUPERBLOCK")) { - sblk.b_bno = SBOFF / dev_bsize; - sbdirty(); - flush(fswritefd, &sblk); - } - flush(fswritefd, &cgblk); - free(cgblk.b_un.b_buf); - for (bp = bufhead.b_prev; bp && bp != &bufhead; bp = nbp) { - cnt++; - flush(fswritefd, bp); - nbp = bp->b_prev; - free(bp->b_un.b_buf); - free((char *)bp); - } - if (bufhead.b_size != cnt) - errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt); - pbp = pdirbp = (struct bufarea *)0; - if (markclean && (sblock.fs_clean & FS_ISCLEAN) == 0) { - /* - * Mark the file system as clean, and sync the superblock. - */ - if (preen) - pwarn("MARKING FILE SYSTEM CLEAN\n"); - else if (!reply("MARK FILE SYSTEM CLEAN")) - markclean = 0; - if (markclean) { - sblock.fs_clean = FS_ISCLEAN; - sbdirty(); - flush(fswritefd, &sblk); - } - } - if (debug) - printf("cache missed %ld of %ld (%d%%)\n", diskreads, - totalreads, (int)(diskreads * 100 / totalreads)); - (void)close(fsreadfd); - (void)close(fswritefd); -} - -int -bread(fd, buf, blk, size) - int fd; - char *buf; - daddr_t blk; - long size; -{ - char *cp; - int i, errs; - off_t offset; - - offset = blk; - offset *= dev_bsize; - if (lseek(fd, offset, 0) < 0) - rwerror("SEEK", blk); - else if (read(fd, buf, (int)size) == size) - return (0); - rwerror("READ", blk); - if (lseek(fd, offset, 0) < 0) - rwerror("SEEK", blk); - errs = 0; - memset(buf, 0, (size_t)size); - printf("THE FOLLOWING DISK SECTORS COULD NOT BE READ:"); - for (cp = buf, i = 0; i < size; i += secsize, cp += secsize) { - if (read(fd, cp, (int)secsize) != secsize) { - (void)lseek(fd, offset + i + secsize, 0); - if (secsize != dev_bsize && dev_bsize != 1) - printf(" %ld (%ld),", - (blk * dev_bsize + i) / secsize, - blk + i / dev_bsize); - else - printf(" %ld,", blk + i / dev_bsize); - errs++; - } - } - printf("\n"); - return (errs); -} - -void -bwrite(fd, buf, blk, size) - int fd; - char *buf; - daddr_t blk; - long size; -{ - int i; - char *cp; - off_t offset; - - if (fd < 0) - return; - offset = blk; - offset *= dev_bsize; - if (lseek(fd, offset, 0) < 0) - rwerror("SEEK", blk); - else if (write(fd, buf, (int)size) == size) { - fsmodified = 1; - return; - } - rwerror("WRITE", blk); - if (lseek(fd, offset, 0) < 0) - rwerror("SEEK", blk); - printf("THE FOLLOWING SECTORS COULD NOT BE WRITTEN:"); - for (cp = buf, i = 0; i < size; i += dev_bsize, cp += dev_bsize) - if (write(fd, cp, (int)dev_bsize) != dev_bsize) { - (void)lseek(fd, offset + i + dev_bsize, 0); - printf(" %ld,", blk + i / dev_bsize); - } - printf("\n"); - return; -} - -/* - * allocate a data block with the specified number of fragments - */ -int -allocblk(frags) - long frags; -{ - register int i, j, k; - - if (frags <= 0 || frags > sblock.fs_frag) - return (0); - for (i = 0; i < maxfsblock - sblock.fs_frag; i += sblock.fs_frag) { - for (j = 0; j <= sblock.fs_frag - frags; j++) { - if (testbmap(i + j)) - continue; - for (k = 1; k < frags; k++) - if (testbmap(i + j + k)) - break; - if (k < frags) { - j += k; - continue; - } - for (k = 0; k < frags; k++) - setbmap(i + j + k); - n_blks += frags; - return (i + j); - } - } - return (0); -} - -/* - * Free a previously allocated block - */ -void -freeblk(blkno, frags) - daddr_t blkno; - long frags; -{ - struct inodesc idesc; - - idesc.id_blkno = blkno; - idesc.id_numfrags = frags; - (void)pass4check(&idesc); -} - -/* - * Find a pathname - */ -void -getpathname(namebuf, curdir, ino) - char *namebuf; - ino_t curdir, ino; -{ - int len; - register char *cp; - struct inodesc idesc; - static int busy = 0; - - if (curdir == ino && ino == ROOTINO) { - (void)strcpy(namebuf, "/"); - return; - } - if (busy || - (statemap[curdir] != DSTATE && statemap[curdir] != DFOUND)) { - (void)strcpy(namebuf, "?"); - return; - } - busy = 1; - memset(&idesc, 0, sizeof(struct inodesc)); - idesc.id_type = DATA; - idesc.id_fix = IGNORE; - cp = &namebuf[MAXPATHLEN - 1]; - *cp = '\0'; - if (curdir != ino) { - idesc.id_parent = curdir; - goto namelookup; - } - while (ino != ROOTINO) { - idesc.id_number = ino; - idesc.id_func = findino; - idesc.id_name = ".."; - if ((ckinode(ginode(ino), &idesc) & FOUND) == 0) - break; - namelookup: - idesc.id_number = idesc.id_parent; - idesc.id_parent = ino; - idesc.id_func = findname; - idesc.id_name = namebuf; - if ((ckinode(ginode(idesc.id_number), &idesc)&FOUND) == 0) - break; - len = strlen(namebuf); - cp -= len; - memcpy(cp, namebuf, (size_t)len); - *--cp = '/'; - if (cp < &namebuf[MAXNAMLEN]) - break; - ino = idesc.id_number; - } - busy = 0; - if (ino != ROOTINO) - *--cp = '?'; - memcpy(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp)); -} - -void -catch() -{ - if (!doinglevel2) - ckfini(0); - exit(12); -} - -/* - * When preening, allow a single quit to signal - * a special exit after filesystem checks complete - * so that reboot sequence may be interrupted. - */ -void -catchquit() -{ - extern returntosingle; - - printf("returning to single-user after filesystem check\n"); - returntosingle = 1; - (void)signal(SIGQUIT, SIG_DFL); -} - -/* - * Ignore a single quit signal; wait and flush just in case. - * Used by child processes in preen. - */ -void -voidquit() -{ - - sleep(1); - (void)signal(SIGQUIT, SIG_IGN); - (void)signal(SIGQUIT, SIG_DFL); -} - -/* - * determine whether an inode should be fixed. - */ -int -dofix(idesc, msg) - register struct inodesc *idesc; - char *msg; -{ - - switch (idesc->id_fix) { - - case DONTKNOW: - if (idesc->id_type == DATA) - direrror(idesc->id_number, msg); - else - pwarn(msg); - if (preen) { - printf(" (SALVAGED)\n"); - idesc->id_fix = FIX; - return (ALTERED); - } - if (reply("SALVAGE") == 0) { - idesc->id_fix = NOFIX; - return (0); - } - idesc->id_fix = FIX; - return (ALTERED); - - case FIX: - return (ALTERED); - - case NOFIX: - case IGNORE: - return (0); - - default: - errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix); - } - /* NOTREACHED */ -} - -/* VARARGS1 */ -errexit(s1, s2, s3, s4) - char *s1; - long s2, s3, s4; -{ - printf(s1, s2, s3, s4); - exit(8); -} - -/* - * An unexpected inconsistency occured. - * Die if preening, otherwise just print message and continue. - */ -/* VARARGS1 */ -pfatal(s, a1, a2, a3) - char *s; - long a1, a2, a3; -{ - - if (preen) { - printf("%s: ", cdevname); - printf(s, a1, a2, a3); - printf("\n"); - printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n", - cdevname); - exit(8); - } - printf(s, a1, a2, a3); -} - -/* - * Pwarn just prints a message when not preening, - * or a warning (preceded by filename) when preening. - */ -/* VARARGS1 */ -pwarn(s, a1, a2, a3, a4, a5, a6) - char *s; - long a1, a2, a3, a4, a5, a6; -{ - - if (preen) - printf("%s: ", cdevname); - printf(s, a1, a2, a3, a4, a5, a6); -} - -#ifndef lint -/* - * Stub for routines from kernel. - */ -panic(s) - char *s; -{ - - pfatal("INTERNAL INCONSISTENCY:"); - errexit(s); -} -#endif diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile index 381b81783ad..37fc709bf89 100644 --- a/sbin/fsdb/Makefile +++ b/sbin/fsdb/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:36 thorpej Exp $ +# $NetBSD: Makefile,v 1.3 1996/04/08 21:03:06 jtc Exp $ # @(#)Makefile 8.1 (Berkeley) 6/5/93 PROG= fsdb @@ -6,8 +6,9 @@ MAN= fsdb.8 SRCS= fsdb.c fsdbutil.c \ dir.c inode.c pass1.c pass1b.c pass2.c pass3.c pass4.c \ pass5.c preen.c setup.c utilities.c ffs_subr.c ffs_tables.c -CFLAGS+= -I${.CURDIR}/../../sbin/fsck +CFLAGS+= -I${.CURDIR}/../../sbin/fsck_ffs LDADD+= -ledit -ltermcap -.PATH: ${.CURDIR}/../../sbin/fsck ${.CURDIR}/../../sys/ufs/ffs +DPADD+= ${LIBEDIT} ${LIBTERMCAP} +.PATH: ${.CURDIR}/../../sbin/fsck_ffs ${.CURDIR}/../../sys/ufs/ffs .include diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index 9c10c8ccfb3..cf7f0b6dc9e 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -1,5 +1,5 @@ -/* $OpenBSD: fsdb.c,v 1.2 1996/03/21 00:15:46 niklas Exp $ */ -/* $NetBSD: fsdb.c,v 1.3 1996/02/27 22:28:12 jtc Exp $ */ +/* $OpenBSD: fsdb.c,v 1.3 1996/04/21 23:46:22 deraadt Exp $ */ +/* $NetBSD: fsdb.c,v 1.4 1996/03/21 17:56:15 jtc Exp $ */ /*- * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: fsdb.c,v 1.3 1996/02/27 22:28:12 jtc Exp $"; +static char rcsid[] = "$NetBSD: fsdb.c,v 1.4 1996/03/21 17:56:15 jtc Exp $"; #endif /* not lint */ #include @@ -83,7 +83,7 @@ int returntosingle = 0; * fsreadfd is set up to read from the file system, fswritefd to write to * the file system. */ -void +int main(argc, argv) int argc; char *argv[]; diff --git a/sbin/mount_ados/mount_ados.c b/sbin/mount_ados/mount_ados.c index 430e515a098..06aa281a3e3 100644 --- a/sbin/mount_ados/mount_ados.c +++ b/sbin/mount_ados/mount_ados.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_ados.c,v 1.4 1995/03/18 14:57:10 cgd Exp $ */ +/* $NetBSD: mount_ados.c,v 1.5 1996/04/13 01:30:59 jtc Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: mount_ados.c,v 1.4 1995/03/18 14:57:10 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_ados.c,v 1.5 1996/04/13 01:30:59 jtc Exp $"; #endif /* not lint */ #include @@ -49,7 +49,7 @@ static char rcsid[] = "$NetBSD: mount_ados.c,v 1.4 1995/03/18 14:57:10 cgd Exp $ #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_cd9660/mount_cd9660.c b/sbin/mount_cd9660/mount_cd9660.c index 442a5f23319..0a7043faafd 100644 --- a/sbin/mount_cd9660/mount_cd9660.c +++ b/sbin/mount_cd9660/mount_cd9660.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_cd9660.c,v 1.2 1995/03/18 14:57:15 cgd Exp $ */ +/* $NetBSD: mount_cd9660.c,v 1.3 1996/04/13 01:31:08 jtc Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -48,7 +48,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mount_cd9660.c 8.4 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_cd9660.c,v 1.2 1995/03/18 14:57:15 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_cd9660.c,v 1.3 1996/04/13 01:31:08 jtc Exp $"; #endif #endif /* not lint */ @@ -64,7 +64,7 @@ static char rcsid[] = "$NetBSD: mount_cd9660.c,v 1.2 1995/03/18 14:57:15 cgd Exp #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_UPDATE, { NULL } diff --git a/sbin/mount_fdesc/mount_fdesc.c b/sbin/mount_fdesc/mount_fdesc.c index 20575122557..6179013a071 100644 --- a/sbin/mount_fdesc/mount_fdesc.c +++ b/sbin/mount_fdesc/mount_fdesc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_fdesc.c,v 1.6 1995/03/18 14:57:20 cgd Exp $ */ +/* $NetBSD: mount_fdesc.c,v 1.7 1996/04/13 01:31:15 jtc Exp $ */ /* * Copyright (c) 1990, 1992 Jan-Simon Pendry @@ -47,7 +47,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_fdesc.c 8.2 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_fdesc.c,v 1.6 1995/03/18 14:57:20 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_fdesc.c,v 1.7 1996/04/13 01:31:15 jtc Exp $"; #endif #endif /* not lint */ @@ -62,7 +62,7 @@ static char rcsid[] = "$NetBSD: mount_fdesc.c,v 1.6 1995/03/18 14:57:20 cgd Exp #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_ffs/mount_ffs.c b/sbin/mount_ffs/mount_ffs.c index 1ba1743f34f..1c9fcb98476 100644 --- a/sbin/mount_ffs/mount_ffs.c +++ b/sbin/mount_ffs/mount_ffs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_ffs.c,v 1.1.2.1 1995/11/01 00:06:20 jtc Exp $ */ +/* $NetBSD: mount_ffs.c,v 1.3 1996/04/13 01:31:19 jtc Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mount_ufs.c 8.2 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_ffs.c,v 1.1.2.1 1995/11/01 00:06:20 jtc Exp $"; +static char rcsid[] = "$NetBSD: mount_ffs.c,v 1.3 1996/04/13 01:31:19 jtc Exp $"; #endif #endif /* not lint */ @@ -61,7 +61,7 @@ static char rcsid[] = "$NetBSD: mount_ffs.c,v 1.1.2.1 1995/11/01 00:06:20 jtc Ex void ffs_usage __P((void)); -static struct mntopt mopts[] = { +static const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_ASYNC, MOPT_SYNC, diff --git a/sbin/mount_kernfs/mount_kernfs.c b/sbin/mount_kernfs/mount_kernfs.c index 84f141b9d17..283c77c1d23 100644 --- a/sbin/mount_kernfs/mount_kernfs.c +++ b/sbin/mount_kernfs/mount_kernfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_kernfs.c,v 1.6 1995/03/18 14:57:27 cgd Exp $ */ +/* $NetBSD: mount_kernfs.c,v 1.8 1996/04/13 05:35:39 cgd Exp $ */ /* * Copyright (c) 1990, 1992 Jan-Simon Pendry @@ -47,7 +47,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_kernfs.c 8.2 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_kernfs.c,v 1.6 1995/03/18 14:57:27 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_kernfs.c,v 1.8 1996/04/13 05:35:39 cgd Exp $"; #endif #endif /* not lint */ @@ -62,7 +62,7 @@ static char rcsid[] = "$NetBSD: mount_kernfs.c,v 1.6 1995/03/18 14:57:27 cgd Exp #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_lfs/mount_lfs.c b/sbin/mount_lfs/mount_lfs.c index 28d1f7fa0ce..b46ce67444f 100644 --- a/sbin/mount_lfs/mount_lfs.c +++ b/sbin/mount_lfs/mount_lfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_lfs.c,v 1.2 1995/03/18 14:57:32 cgd Exp $ */ +/* $NetBSD: mount_lfs.c,v 1.4 1996/04/13 05:35:44 cgd Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mount_lfs.c 8.3 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_lfs.c,v 1.2 1995/03/18 14:57:32 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_lfs.c,v 1.4 1996/04/13 05:35:44 cgd Exp $"; #endif #endif /* not lint */ @@ -59,7 +59,7 @@ static char rcsid[] = "$NetBSD: mount_lfs.c,v 1.2 1995/03/18 14:57:32 cgd Exp $" #include "mntopts.h" #include "pathnames.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_UPDATE, { NULL } diff --git a/sbin/mount_msdos/mount_msdos.c b/sbin/mount_msdos/mount_msdos.c index 8aa66639056..fbd03990a9f 100644 --- a/sbin/mount_msdos/mount_msdos.c +++ b/sbin/mount_msdos/mount_msdos.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_msdos.c,v 1.12 1996/01/19 21:14:46 leo Exp $ */ +/* $NetBSD: mount_msdos.c,v 1.14 1996/04/13 05:35:47 cgd Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -31,7 +31,7 @@ */ #ifndef lint -static char rcsid[] = "$NetBSD: mount_msdos.c,v 1.12 1996/01/19 21:14:46 leo Exp $"; +static char rcsid[] = "$NetBSD: mount_msdos.c,v 1.14 1996/04/13 05:35:47 cgd Exp $"; #endif /* not lint */ #include @@ -49,7 +49,7 @@ static char rcsid[] = "$NetBSD: mount_msdos.c,v 1.12 1996/01/19 21:14:46 leo Exp #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_nfs/Makefile b/sbin/mount_nfs/Makefile index ba0017f8e65..6c49ac859de 100644 --- a/sbin/mount_nfs/Makefile +++ b/sbin/mount_nfs/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.3 1996/03/21 00:15:56 niklas Exp $ +# $OpenBSD: Makefile,v 1.4 1996/04/21 23:46:48 deraadt Exp $ # $NetBSD: Makefile,v 1.5 1996/02/18 11:59:09 fvdl Exp $ # @(#)Makefile 8.2 (Berkeley) 3/27/94 @@ -13,7 +13,7 @@ MAN= mount_nfs.8 #.PATH: ${MOUNT} CFLAGS+=-DNFS -.include # For KERBEROS +#.include # For KERBEROS .if defined(KERBEROS) CFLAGS+=-DNFSKERB diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index 34fb23cb7b3..60694b9f81d 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mount_nfs.c,v 1.3 1996/03/21 00:16:03 niklas Exp $ */ -/* $NetBSD: mount_nfs.c,v 1.11 1996/02/18 11:59:11 fvdl Exp $ */ +/* $OpenBSD: mount_nfs.c,v 1.4 1996/04/21 23:46:50 deraadt Exp $ */ +/* $NetBSD: mount_nfs.c,v 1.12 1996/04/13 01:31:43 jtc Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.11 1996/02/18 11:59:11 fvdl Exp $"; +static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.12 1996/04/13 01:31:43 jtc Exp $"; #endif #endif /* not lint */ @@ -107,7 +107,7 @@ static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.11 1996/02/18 11:59:11 fvdl Exp #define ALTF_SOFT 0x800 #define ALTF_TCP 0x1000 -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_FORCE, MOPT_UPDATE, diff --git a/sbin/mount_null/mount_null.8 b/sbin/mount_null/mount_null.8 index 7c403407378..6490b1d1d0d 100644 --- a/sbin/mount_null/mount_null.8 +++ b/sbin/mount_null/mount_null.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: mount_null.8,v 1.3 1995/07/12 07:08:27 cgd Exp $ +.\" $NetBSD: mount_null.8,v 1.4 1996/04/10 20:57:19 thorpej Exp $ .\" .\" Copyright (c) 1992, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -187,7 +187,7 @@ by mapping an vnode arguments to the lower layer. The first approach is to call the aliasing layer's bypass routine. This method is most suitable when you wish to invoke the operation currently being handled on the lower layer. It has the advantage -the the bypass routine already must do argument mapping. +the bypass routine already must do argument mapping. An example of this is .Em null_getattrs in the null layer. diff --git a/sbin/mount_null/mount_null.c b/sbin/mount_null/mount_null.c index 12f4ed8706d..76f77190e9c 100644 --- a/sbin/mount_null/mount_null.c +++ b/sbin/mount_null/mount_null.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_null.c,v 1.2 1995/03/18 14:57:48 cgd Exp $ */ +/* $NetBSD: mount_null.c,v 1.3 1996/04/13 01:31:49 jtc Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -46,7 +46,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_null.c 8.5 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_null.c,v 1.2 1995/03/18 14:57:48 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_null.c,v 1.3 1996/04/13 01:31:49 jtc Exp $"; #endif #endif /* not lint */ @@ -62,7 +62,7 @@ static char rcsid[] = "$NetBSD: mount_null.c,v 1.2 1995/03/18 14:57:48 cgd Exp $ #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_portal/mount_portal.c b/sbin/mount_portal/mount_portal.c index 390f70d00b7..4e2cc744ba9 100644 --- a/sbin/mount_portal/mount_portal.c +++ b/sbin/mount_portal/mount_portal.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_portal.c,v 1.6 1995/06/08 12:38:07 cgd Exp $ */ +/* $NetBSD: mount_portal.c,v 1.8 1996/04/13 01:31:54 jtc Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -46,7 +46,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_portal.c 8.4 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_portal.c,v 1.6 1995/06/08 12:38:07 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_portal.c,v 1.8 1996/04/13 01:31:54 jtc Exp $"; #endif #endif /* not lint */ @@ -69,11 +69,13 @@ static char rcsid[] = "$NetBSD: mount_portal.c,v 1.6 1995/06/08 12:38:07 cgd Exp #include "pathnames.h" #include "portald.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; +static char *mountpt; /* made available to signal handler */ + static void usage __P((void)); static sig_atomic_t readcf; /* Set when SIGHUP received */ @@ -98,6 +100,15 @@ sighup(sig) readcf = 1; } +static void +sigterm(sig) + int sig; +{ + if (unmount(mountpt, MNT_FORCE) < 0) + syslog(LOG_WARNING, "sigterm: unmounting %s failed: %s", + mountpt, strerror(errno)); +} + int main(argc, argv) int argc; @@ -106,7 +117,6 @@ main(argc, argv) struct portal_args args; struct sockaddr_un un; char *conf; - char *mountpt; int mntflags = 0; char tag[32]; @@ -168,7 +178,7 @@ main(argc, argv) (void) listen(so, 5); args.pa_socket = so; - sprintf(tag, "portal:%d", getpid()); + sprintf(tag, "portal:%d", getpid() + 1); args.pa_config = tag; rc = mount(MOUNT_PORTAL, mountpt, mntflags, &args); @@ -190,6 +200,7 @@ main(argc, argv) signal(SIGCHLD, sigchld); signal(SIGHUP, sighup); + signal(SIGTERM, sigterm); /* * Just loop waiting for new connections and activating them diff --git a/sbin/mount_procfs/mount_procfs.c b/sbin/mount_procfs/mount_procfs.c index 2e75b8fbb81..777e93f57c5 100644 --- a/sbin/mount_procfs/mount_procfs.c +++ b/sbin/mount_procfs/mount_procfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_procfs.c,v 1.6 1995/03/18 14:58:11 cgd Exp $ */ +/* $NetBSD: mount_procfs.c,v 1.7 1996/04/13 01:31:59 jtc Exp $ */ /* * Copyright (c) 1990, 1992, 1993 Jan-Simon Pendry @@ -47,7 +47,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_procfs.c 8.3 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_procfs.c,v 1.6 1995/03/18 14:58:11 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_procfs.c,v 1.7 1996/04/13 01:31:59 jtc Exp $"; #endif #endif /* not lint */ @@ -62,7 +62,7 @@ static char rcsid[] = "$NetBSD: mount_procfs.c,v 1.6 1995/03/18 14:58:11 cgd Exp #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_umap/mount_umap.c b/sbin/mount_umap/mount_umap.c index 616fa17addf..2fa2a6ade80 100644 --- a/sbin/mount_umap/mount_umap.c +++ b/sbin/mount_umap/mount_umap.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_umap.c,v 1.4 1995/04/24 13:23:11 cgd Exp $ */ +/* $NetBSD: mount_umap.c,v 1.5 1996/04/13 01:32:05 jtc Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -46,7 +46,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_umap.c 8.3 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_umap.c,v 1.4 1995/04/24 13:23:11 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_umap.c,v 1.5 1996/04/13 01:32:05 jtc Exp $"; #endif #endif /* not lint */ @@ -82,7 +82,7 @@ static char rcsid[] = "$NetBSD: mount_umap.c,v 1.4 1995/04/24 13:23:11 cgd Exp $ * will, in turn, call the umap version of mount. */ -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/mount_union/mount_union.c b/sbin/mount_union/mount_union.c index ce9edce3ba1..1c639b3b756 100644 --- a/sbin/mount_union/mount_union.c +++ b/sbin/mount_union/mount_union.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_union.c,v 1.2 1995/03/18 14:58:24 cgd Exp $ */ +/* $NetBSD: mount_union.c,v 1.3 1996/04/13 01:32:11 jtc Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -46,7 +46,7 @@ char copyright[] = #if 0 static char sccsid[] = "@(#)mount_union.c 8.5 (Berkeley) 3/27/94"; #else -static char rcsid[] = "$NetBSD: mount_union.c,v 1.2 1995/03/18 14:58:24 cgd Exp $"; +static char rcsid[] = "$NetBSD: mount_union.c,v 1.3 1996/04/13 01:32:11 jtc Exp $"; #endif #endif /* not lint */ @@ -63,7 +63,7 @@ static char rcsid[] = "$NetBSD: mount_union.c,v 1.2 1995/03/18 14:58:24 cgd Exp #include "mntopts.h" -struct mntopt mopts[] = { +const struct mntopt mopts[] = { MOPT_STDOPTS, { NULL } }; diff --git a/sbin/quotacheck/Makefile b/sbin/quotacheck/Makefile index 6a11131b2bd..dc2b361ca6f 100644 --- a/sbin/quotacheck/Makefile +++ b/sbin/quotacheck/Makefile @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.5 1995/03/18 14:59:19 cgd Exp $ +# $NetBSD: Makefile,v 1.6 1996/04/05 04:17:57 cgd Exp $ # @(#)Makefile 8.1 (Berkeley) 6/5/93 PROG= quotacheck SRCS= quotacheck.c preen.c MAN= quotacheck.8 -.PATH: ${.CURDIR}/../fsck +.PATH: ${.CURDIR}/../fsck_ffs .include diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c index 69cf395dfe8..3c1e3fca961 100644 --- a/sbin/quotacheck/quotacheck.c +++ b/sbin/quotacheck/quotacheck.c @@ -1,4 +1,4 @@ -/* $NetBSD: quotacheck.c,v 1.10.2.1 1995/11/01 00:32:51 jtc Exp $ */ +/* $NetBSD: quotacheck.c,v 1.12 1996/03/30 22:34:25 mark Exp $ */ /* * Copyright (c) 1980, 1990, 1993 @@ -46,7 +46,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)quotacheck.c 8.3 (Berkeley) 1/29/94"; #else -static char rcsid[] = "$NetBSD: quotacheck.c,v 1.10.2.1 1995/11/01 00:32:51 jtc Exp $"; +static char rcsid[] = "$NetBSD: quotacheck.c,v 1.12 1996/03/30 22:34:25 mark Exp $"; #endif #endif /* not lint */ @@ -138,10 +138,11 @@ main(argc, argv) struct quotaname *auxdata; int i, argnum, maxrun, errs; long done = 0; - char ch, *name; + char *name; + int ch; errs = maxrun = 0; - while ((ch = getopt(argc, argv, "aguvl:")) != EOF) { + while ((ch = getopt(argc, argv, "aguvl:")) != -1) { switch(ch) { case 'a': aflag++; diff --git a/sbin/route/route.c b/sbin/route/route.c index 8c2e31a2d05..79211fe4483 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.15 1996/01/07 00:07:23 pk Exp $ */ +/* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */ /* * Copyright (c) 1983, 1989, 1991, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/19/94"; #else -static char rcsid[] = "$NetBSD: route.c,v 1.15 1996/01/07 00:07:23 pk Exp $"; +static char rcsid[] = "$NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $"; #endif #endif /* not lint */ @@ -861,7 +861,7 @@ getaddr(which, s, hpp) if (hpp == NULL) hpp = &hp; *hpp = NULL; - if (((val = inet_addr(s)) != -1) && + if (((val = inet_addr(s)) != INADDR_NONE) && (which != RTA_DST || forcenet == 0)) { su->sin.sin_addr.s_addr = val; if (inet_lnaof(su->sin.sin_addr) != INADDR_ANY) @@ -871,7 +871,7 @@ getaddr(which, s, hpp) goto netdone; } } - if ((val = inet_network(s)) != -1 || + if ((val = inet_network(s)) != INADDR_NONE || ((np = getnetbyname(s)) != NULL && (val = np->n_net) != 0)) { netdone: if (which == RTA_DST) diff --git a/sbin/savecore.old/Makefile b/sbin/savecore.old/Makefile deleted file mode 100644 index 71b014cb6cd..00000000000 --- a/sbin/savecore.old/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $OpenBSD: Makefile,v 1.1 1996/03/21 00:16:39 niklas Exp $ -# $NetBSD: Makefile,v 1.1.1.1 1996/03/16 10:25:12 leo Exp $ -# @(#)Makefile 8.2 (Berkeley) 4/17/94 - -PROG= savecore -SRCS= savecore.c zopen.c -MAN= savecore.8 -.PATH: ${.CURDIR}/../../usr.bin/compress - -.include diff --git a/sbin/savecore.old/savecore.8 b/sbin/savecore.old/savecore.8 deleted file mode 100644 index 5cf34d9e296..00000000000 --- a/sbin/savecore.old/savecore.8 +++ /dev/null @@ -1,133 +0,0 @@ -.\" $OpenBSD: savecore.8,v 1.1 1996/03/21 00:16:41 niklas Exp $ -.\" $NetBSD: savecore.8,v 1.1.1.1 1996/03/16 10:25:12 leo Exp $ -.\" -.\" Copyright (c) 1980, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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. -.\" -.\" @(#)savecore.8 8.1 (Berkeley) 6/5/93 -.\" -.Dd June 5, 1993 -.Dt SAVECORE 8 -.Os BSD 4 -.Sh NAME -.Nm savecore -.Nd "save a core dump of the operating system" -.Sh SYNOPSIS -.Nm savecore -.Fl c -.Nm savecore -.Op Fl fvz -.Op Fl N Ar system -.Ar directory -.Sh DESCRIPTION -.Nm Savecore -copies the currently running kernel and its associated core dump into -.Fa directory , -and enters a reboot message and information about the core dump into -the system log. -.Pp -The options are as follows: -.Bl -tag -width directory -.It Fl c -Clears the dump, so that future invocations of -.Nm savecore -will ignore it. -.It Fl f -Forces a dump to be taken even if the dump doesn't appear correct or there -is insufficient disk space. -.It Fl N -Use -.Ar system -as the kernel instead of the default ``/netbsd''. -.It Fl v -Prints out some additional debugging information. -.It Fl z -Compresses the core dump and kernel (see -.Xr compress 1 ). -.El -.Pp -.Nm Savecore -checks the core dump in various ways to make sure that it is current and -that it corresponds to the currently running system. -If it passes these checks, it saves the core image in -.Ar directory Ns Pa /netbsd.#.core -and the system in -.Ar directory Ns Pa /netbsd.# -(or in -.Ar directory Ns Pa /netbsd.#.Z.core -and -.Ar directory Ns Pa /netbsd.#.Z , -respectively, if the -.Fl z -option is used). -The ``#'' is the number from the first line of the file -.Ar directory Ns Pa /bounds , -and it is incremented and stored back into the file each time -.Nm savecore -successfully runs. -.Pp -.Nm Savecore -also checks the available disk space before attempting to make the copies. -If there is insufficient disk space in the filesystem containing -.Ar directory , -or if the file -.Ar directory Ns Pa /minfree -exists and the number of free kilobytes (for non-superusers) in the -filesystem after the copies were made would be less than the number -in the first line of this file, the copies are not attempted. -.Pp -If -.Nm savecore -successfully copies the kernel and the core dump, the core dump is cleared -so that future invocations of -.Nm savecore -will ignore it. -.Pp -.Nm Savecore -is meant to be called near the end of the initialization file -.Pa /etc/rc -(see -.Xr rc 8 ) . -.Sh FILES -.Bl -tag -width /netbsdxx -compact -.It Pa /netbsd -current kernel -.El -.Sh BUGS -The minfree code does not consider the effect of compression. -.Sh SEE ALSO -.Xr compress 1 , -.Xr syslogd 8 -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.1 . diff --git a/sbin/savecore.old/savecore.c b/sbin/savecore.old/savecore.c deleted file mode 100644 index b7824f51bd2..00000000000 --- a/sbin/savecore.old/savecore.c +++ /dev/null @@ -1,663 +0,0 @@ -/* $OpenBSD: savecore.c,v 1.2 1996/04/17 22:02:23 dm Exp $ */ -/* $NetBSD: savecore.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $ */ - -/*- - * Copyright (c) 1986, 1992, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1986, 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; -#else -static char rcsid[] = "$NetBSD: savecore.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $"; -#endif -#endif /* not lint */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern FILE *zopen __P((const char *fname, const char *mode, int bits)); - -#define ok(number) ((number) - KERNBASE) - -struct nlist current_nl[] = { /* Namelist for currently running system. */ -#define X_DUMPDEV 0 - { "_dumpdev" }, -#define X_DUMPLO 1 - { "_dumplo" }, -#define X_TIME 2 - { "_time" }, -#define X_DUMPSIZE 3 - { "_dumpsize" }, -#define X_VERSION 4 - { "_version" }, -#define X_PANICSTR 5 - { "_panicstr" }, -#define X_DUMPMAG 6 - { "_dumpmag" }, - { "" }, -}; -int cursyms[] = { X_DUMPDEV, X_DUMPLO, X_VERSION, X_DUMPMAG, -1 }; -int dumpsyms[] = { X_TIME, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG, -1 }; - -struct nlist dump_nl[] = { /* Name list for dumped system. */ - { "_dumpdev" }, /* Entries MUST be the same as */ - { "_dumplo" }, /* those in current_nl[]. */ - { "_time" }, - { "_dumpsize" }, - { "_version" }, - { "_panicstr" }, - { "_dumpmag" }, - { "" }, -}; - -/* Types match kernel declarations. */ -long dumplo; /* where dump starts on dumpdev */ -int dumpmag; /* magic number in dump */ -int dumpsize; /* amount of memory dumped */ - -char *kernel; -char *dirname; /* directory to save dumps in */ -char *ddname; /* name of dump device */ -dev_t dumpdev; /* dump device */ -int dumpfd; /* read/write descriptor on block dev */ -time_t now; /* current date */ -char panic_mesg[1024]; -int panicstr; -char vers[1024]; - -int clear, compress, force, verbose; /* flags */ - -void check_kmem __P((void)); -int check_space __P((void)); -void clear_dump __P((void)); -int Create __P((char *, int)); -int dump_exists __P((void)); -char *find_dev __P((dev_t, int)); -int get_crashtime __P((void)); -void kmem_setup __P((void)); -void log __P((int, char *, ...)); -void Lseek __P((int, off_t, int)); -int Open __P((char *, int rw)); -int Read __P((int, void *, int)); -char *rawname __P((char *s)); -void save_core __P((void)); -void usage __P((void)); -void Write __P((int, void *, int)); - -int -main(argc, argv) - int argc; - char *argv[]; -{ - int ch; - - openlog("savecore", LOG_PERROR, LOG_DAEMON); - - while ((ch = getopt(argc, argv, "cdfN:vz")) != -1) - switch(ch) { - case 'c': - clear = 1; - break; - case 'd': /* Not documented. */ - case 'v': - verbose = 1; - break; - case 'f': - force = 1; - break; - case 'N': - kernel = optarg; - break; - case 'z': - compress = 1; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (!clear) { - if (argc != 1 && argc != 2) - usage(); - dirname = argv[0]; - } - if (argc == 2) - kernel = argv[1]; - - (void)time(&now); - kmem_setup(); - - if (clear) { - clear_dump(); - exit(0); - } - - if (!dump_exists() && !force) - exit(1); - - check_kmem(); - - if (panicstr) - syslog(LOG_ALERT, "reboot after panic: %s", panic_mesg); - else - syslog(LOG_ALERT, "reboot"); - - if ((!get_crashtime() || !check_space()) && !force) - exit(1); - - save_core(); - - clear_dump(); - exit(0); -} - -void -kmem_setup() -{ - FILE *fp; - int kmem, i; - char *dump_sys; - - /* - * Some names we need for the currently running system, others for - * the system that was running when the dump was made. The values - * obtained from the current system are used to look for things in - * /dev/kmem that cannot be found in the dump_sys namelist, but are - * presumed to be the same (since the disk partitions are probably - * the same!) - */ - if ((nlist(_PATH_UNIX, current_nl)) == -1) - syslog(LOG_ERR, "%s: nlist: %s", _PATH_UNIX, strerror(errno)); - for (i = 0; cursyms[i] != -1; i++) - if (current_nl[cursyms[i]].n_value == 0) { - syslog(LOG_ERR, "%s: %s not in namelist", - _PATH_UNIX, current_nl[cursyms[i]].n_name); - exit(1); - } - - dump_sys = kernel ? kernel : _PATH_UNIX; - if ((nlist(dump_sys, dump_nl)) == -1) - syslog(LOG_ERR, "%s: nlist: %s", dump_sys, strerror(errno)); - for (i = 0; dumpsyms[i] != -1; i++) - if (dump_nl[dumpsyms[i]].n_value == 0) { - syslog(LOG_ERR, "%s: %s not in namelist", - dump_sys, dump_nl[dumpsyms[i]].n_name); - exit(1); - } - - kmem = Open(_PATH_KMEM, O_RDONLY); - Lseek(kmem, (off_t)current_nl[X_DUMPDEV].n_value, L_SET); - (void)Read(kmem, &dumpdev, sizeof(dumpdev)); - if (dumpdev == NODEV) { - syslog(LOG_WARNING, "no core dump (no dumpdev)"); - exit(1); - } - Lseek(kmem, (off_t)current_nl[X_DUMPLO].n_value, L_SET); - (void)Read(kmem, &dumplo, sizeof(dumplo)); - dumplo *= DEV_BSIZE; - if (verbose) - (void)printf("dumplo = %d (%d * %d)\n", - dumplo, dumplo / DEV_BSIZE, DEV_BSIZE); - Lseek(kmem, (off_t)current_nl[X_DUMPMAG].n_value, L_SET); - (void)Read(kmem, &dumpmag, sizeof(dumpmag)); - ddname = find_dev(dumpdev, S_IFBLK); - dumpfd = Open(ddname, O_RDWR); - fp = fdopen(kmem, "r"); - if (fp == NULL) { - syslog(LOG_ERR, "%s: fdopen: %m", _PATH_KMEM); - exit(1); - } - if (kernel) - return; - (void)fseek(fp, (off_t)current_nl[X_VERSION].n_value, L_SET); - (void)fgets(vers, sizeof(vers), fp); - - /* Don't fclose(fp), we use dumpfd later. */ -} - -void -check_kmem() -{ - register char *cp; - FILE *fp; - char core_vers[1024]; - - fp = fdopen(dumpfd, "r"); - if (fp == NULL) { - syslog(LOG_ERR, "%s: fdopen: %m", ddname); - exit(1); - } - fseek(fp, (off_t)(dumplo + ok(dump_nl[X_VERSION].n_value)), L_SET); - fgets(core_vers, sizeof(core_vers), fp); - if (strcmp(vers, core_vers) && kernel == 0) - syslog(LOG_WARNING, - "warning: %s version mismatch:\n\t%s\nand\t%s\n", - _PATH_UNIX, vers, core_vers); - (void)fseek(fp, - (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET); - (void)fread(&panicstr, sizeof(panicstr), 1, fp); - if (panicstr) { - (void)fseek(fp, dumplo + ok(panicstr), L_SET); - cp = panic_mesg; - do - *cp = getc(fp); - while (*cp++ && cp < &panic_mesg[sizeof(panic_mesg)]); - } - /* Don't fclose(fp), we use dumpfd later. */ -} - -void -clear_dump() -{ - long newdumplo; - - newdumplo = 0; - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); - Write(dumpfd, &newdumplo, sizeof(newdumplo)); -} - -int -dump_exists() -{ - int newdumpmag; - - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); - (void)Read(dumpfd, &newdumpmag, sizeof(newdumpmag)); - - /* Read the dump size. */ - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET); - (void)Read(dumpfd, &dumpsize, sizeof(dumpsize)); - dumpsize *= getpagesize(); - - /* - * Return zero if core dump doesn't seem to be there, and note - * it for syslog. This check and return happens after the dump size - * is read, so dumpsize is whether or not the core is valid (for -f). - */ - if (newdumpmag != dumpmag) { - if (verbose) - syslog(LOG_WARNING, "magic number mismatch (%x != %x)", - newdumpmag, dumpmag); - syslog(LOG_WARNING, "no core dump"); - return (0); - } - return (1); -} - -char buf[1024 * 1024]; - -void -save_core() -{ - register FILE *fp; - register int bounds, ifd, nr, nw, ofd; - char *rawp, path[MAXPATHLEN]; - - /* - * Get the current number and update the bounds file. Do the update - * now, because may fail later and don't want to overwrite anything. - */ - (void)snprintf(path, sizeof(path), "%s/bounds", dirname); - if ((fp = fopen(path, "r")) == NULL) - goto err1; - if (fgets(buf, sizeof(buf), fp) == NULL) { - if (ferror(fp)) -err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); - bounds = 0; - } else - bounds = atoi(buf); - if (fp != NULL) - (void)fclose(fp); - if ((fp = fopen(path, "w")) == NULL) - syslog(LOG_ERR, "%s: %m", path); - else { - (void)fprintf(fp, "%d\n", bounds + 1); - (void)fclose(fp); - } - (void)fclose(fp); - - /* Create the core file. */ - (void)snprintf(path, sizeof(path), "%s/bsd.%d.core%s", - dirname, bounds, compress ? ".Z" : ""); - if (compress) { - if ((fp = zopen(path, "w", 0)) == NULL) { - syslog(LOG_ERR, "%s: %s", path, strerror(errno)); - exit(1); - } - } else - ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - - /* Open the raw device. */ - rawp = rawname(ddname); - if ((ifd = open(rawp, O_RDONLY)) == -1) { - syslog(LOG_WARNING, "%s: %m; using block device", rawp); - ifd = dumpfd; - } - - /* Seek to the start of the core. */ - Lseek(ifd, (off_t)dumplo, L_SET); - - /* Copy the core file. */ - syslog(LOG_NOTICE, "writing %score to %s", - compress ? "compressed " : "", path); - for (; dumpsize > 0; dumpsize -= nr) { - (void)printf("%6dK\r", dumpsize / 1024); - (void)fflush(stdout); - nr = read(ifd, buf, MIN(dumpsize, sizeof(buf))); - if (nr <= 0) { - if (nr == 0) - syslog(LOG_WARNING, - "WARNING: EOF on dump device"); - else - syslog(LOG_ERR, "%s: %m", rawp); - goto err2; - } - if (compress) - nw = fwrite(buf, 1, nr, fp); - else - nw = write(ofd, buf, nr); - if (nw != nr) { - syslog(LOG_ERR, "%s: %s", - path, strerror(nw == 0 ? EIO : errno)); -err2: syslog(LOG_WARNING, - "WARNING: core may be incomplete"); - (void)printf("\n"); - exit(1); - } - } - (void)close(ifd); - if (compress) - (void)fclose(fp); - else - (void)close(ofd); - - /* Copy the kernel. */ - ifd = Open(kernel ? kernel : _PATH_UNIX, O_RDONLY); - (void)snprintf(path, sizeof(path), "%s/bsd.%d%s", - dirname, bounds, compress ? ".Z" : ""); - if (compress) { - if ((fp = zopen(path, "w", 0)) == NULL) { - syslog(LOG_ERR, "%s: %s", path, strerror(errno)); - exit(1); - } - } else - ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - syslog(LOG_NOTICE, "writing %skernel to %s", - compress ? "compressed " : "", path); - while ((nr = read(ifd, buf, sizeof(buf))) > 0) { - if (compress) - nw = fwrite(buf, 1, nr, fp); - else - nw = write(ofd, buf, nr); - if (nw != nr) { - syslog(LOG_ERR, "%s: %s", - path, strerror(nw == 0 ? EIO : errno)); - syslog(LOG_WARNING, - "WARNING: kernel may be incomplete"); - exit(1); - } - } - if (nr < 0) { - syslog(LOG_ERR, "%s: %s", - kernel ? kernel : _PATH_UNIX, strerror(errno)); - syslog(LOG_WARNING, - "WARNING: kernel may be incomplete"); - exit(1); - } - if (compress) - (void)fclose(fp); - else - (void)close(ofd); -} - -char * -find_dev(dev, type) - register dev_t dev; - register int type; -{ - register DIR *dfd; - struct dirent *dir; - struct stat sb; - char *dp, devname[MAXPATHLEN + 1]; - - if ((dfd = opendir(_PATH_DEV)) == NULL) { - syslog(LOG_ERR, "%s: %s", _PATH_DEV, strerror(errno)); - exit(1); - } - (void)strcpy(devname, _PATH_DEV); - while ((dir = readdir(dfd))) { - (void)strcpy(devname + sizeof(_PATH_DEV) - 1, dir->d_name); - if (lstat(devname, &sb)) { - syslog(LOG_ERR, "%s: %s", devname, strerror(errno)); - continue; - } - if ((sb.st_mode & S_IFMT) != type) - continue; - if (dev == sb.st_rdev) { - closedir(dfd); - if ((dp = strdup(devname)) == NULL) { - syslog(LOG_ERR, "%s", strerror(errno)); - exit(1); - } - return (dp); - } - } - closedir(dfd); - syslog(LOG_ERR, "can't find device %d/%d", major(dev), minor(dev)); - exit(1); -} - -char * -rawname(s) - char *s; -{ - char *sl, name[MAXPATHLEN]; - - if ((sl = strrchr(s, '/')) == NULL || sl[1] == '0') { - syslog(LOG_ERR, - "can't make raw dump device name from %s", s); - return (s); - } - (void)snprintf(name, sizeof(name), "%.*s/r%s", sl - s, s, sl + 1); - if ((sl = strdup(name)) == NULL) { - syslog(LOG_ERR, "%s", strerror(errno)); - exit(1); - } - return (sl); -} - -int -get_crashtime() -{ - time_t dumptime; /* Time the dump was taken. */ - - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_TIME].n_value)), L_SET); - (void)Read(dumpfd, &dumptime, sizeof(dumptime)); - if (dumptime == 0) { - if (verbose) - syslog(LOG_ERR, "dump time is zero"); - return (0); - } - (void)printf("savecore: system went down at %s", ctime(&dumptime)); -#define LEEWAY (7 * SECSPERDAY) - if (dumptime < now - LEEWAY || dumptime > now + LEEWAY) { - (void)printf("dump time is unreasonable\n"); - return (0); - } - return (1); -} - -int -check_space() -{ - register FILE *fp; - char *tkernel; - off_t minfree, spacefree, kernelsize, needed; - struct stat st; - struct statfs fsbuf; - char buf[100], path[MAXPATHLEN]; - - tkernel = kernel ? kernel : _PATH_UNIX; - if (stat(tkernel, &st) < 0) { - syslog(LOG_ERR, "%s: %m", tkernel); - exit(1); - } - kernelsize = st.st_blocks * S_BLKSIZE; - if (statfs(dirname, &fsbuf) < 0) { - syslog(LOG_ERR, "%s: %m", dirname); - exit(1); - } - spacefree = (fsbuf.f_bavail * fsbuf.f_bsize) / 1024; - - (void)snprintf(path, sizeof(path), "%s/minfree", dirname); - if ((fp = fopen(path, "r")) == NULL) - minfree = 0; - else { - if (fgets(buf, sizeof(buf), fp) == NULL) - minfree = 0; - else - minfree = atoi(buf); - (void)fclose(fp); - } - - needed = (dumpsize + kernelsize) / 1024; - if (minfree > 0 && spacefree - needed < minfree) { - syslog(LOG_WARNING, - "no dump, not enough free space on device"); - return (0); - } - if (spacefree - needed < minfree) - syslog(LOG_WARNING, - "dump performed, but free space threshold crossed"); - return (1); -} - -int -Open(name, rw) - char *name; - int rw; -{ - int fd; - - if ((fd = open(name, rw, 0)) < 0) { - syslog(LOG_ERR, "%s: %m", name); - exit(1); - } - return (fd); -} - -int -Read(fd, bp, size) - int fd, size; - void *bp; -{ - int nr; - - nr = read(fd, bp, size); - if (nr != size) { - syslog(LOG_ERR, "read: %m"); - exit(1); - } - return (nr); -} - -void -Lseek(fd, off, flag) - int fd, flag; - off_t off; -{ - off_t ret; - - ret = lseek(fd, off, flag); - if (ret == -1) { - syslog(LOG_ERR, "lseek: %m"); - exit(1); - } -} - -int -Create(file, mode) - char *file; - int mode; -{ - register int fd; - - fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, mode); - if (fd < 0) { - syslog(LOG_ERR, "%s: %m", file); - exit(1); - } - return (fd); -} - -void -Write(fd, bp, size) - int fd, size; - void *bp; -{ - int n; - - if ((n = write(fd, bp, size)) < size) { - syslog(LOG_ERR, "write: %s", strerror(n == -1 ? errno : EIO)); - exit(1); - } -} - -void -usage() -{ - (void)syslog(LOG_ERR, "usage: savecore [-cfvz] [-N system] directory"); - exit(1); -} diff --git a/sbin/savecore/Makefile b/sbin/savecore/Makefile index 31fd8b57608..6a5af9c16ce 100644 --- a/sbin/savecore/Makefile +++ b/sbin/savecore/Makefile @@ -1,8 +1,13 @@ -# $NetBSD: Makefile,v 1.8 1995/03/18 15:00:59 cgd Exp $ +# $NetBSD: Makefile,v 1.9 1996/03/30 06:49:21 cgd Exp $ # @(#)Makefile 8.2 (Berkeley) 4/17/94 PROG= savecore -SRCS= savecore.c zopen.c +.if (${MACHINE} == "atari") # XXX until other ports use new libkvm +SRCS= savecore.c +.else +SRCS= savecore_old.c +.endif +SRCS+= zopen.c MAN= savecore.8 .PATH: ${.CURDIR}/../../usr.bin/compress diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index fe65684c0e5..2ce1f72db9c 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -1,5 +1,5 @@ -/* $OpenBSD: savecore.c,v 1.3 1996/03/21 00:16:36 niklas Exp $ */ -/* $NetBSD: savecore.c,v 1.25 1996/03/16 10:29:46 leo Exp $ */ +/* $OpenBSD: savecore.c,v 1.4 1996/04/21 23:47:27 deraadt Exp $ */ +/* $NetBSD: savecore.c,v 1.26 1996/03/18 21:16:05 leo Exp $ */ /*- * Copyright (c) 1986, 1992, 1993 @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$NetBSD: savecore.c,v 1.25 1996/03/16 10:29:46 leo Exp $"; +static char rcsid[] = "$NetBSD: savecore.c,v 1.26 1996/03/18 21:16:05 leo Exp $"; #endif #endif /* not lint */ @@ -277,10 +277,10 @@ kmem_setup() dump_sys, dump_nl[dumpsyms[i]].n_name); exit(1); } - hdrsz = kvm_dump_mkheader(kd_kern, kd_dump, (off_t)dumplo); + hdrsz = kvm_dump_mkheader(kd_dump, (off_t)dumplo); if (hdrsz == -1) { syslog(LOG_ERR, "%s: kvm_dump_mkheader: %s", dump_sys, - kvm_geterr(kd_kern)); + kvm_geterr(kd_dump)); exit(1); } dumplo += hdrsz; @@ -414,6 +414,12 @@ err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); exit(1); } + if (kvm_dump_wrtheader(kd_dump, fp, dumpsize) == -1) { + syslog(LOG_ERR, "kvm_dump_wrtheader: %s : %s", path, + kvm_geterr(kd_dump)); + exit(1); + } + /* Copy the core file. */ syslog(LOG_NOTICE, "writing %score to %s", compress ? "compressed " : "", path); diff --git a/sbin/savecore/savecore_old.c b/sbin/savecore/savecore_old.c new file mode 100644 index 00000000000..9de2a14ad52 --- /dev/null +++ b/sbin/savecore/savecore_old.c @@ -0,0 +1,662 @@ +/* $NetBSD: savecore_old.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $ */ + +/*- + * Copyright (c) 1986, 1992, 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1986, 1992, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; +#else +static char rcsid[] = "$NetBSD: savecore_old.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $"; +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern FILE *zopen __P((const char *fname, const char *mode, int bits)); + +#define ok(number) ((number) - KERNBASE) + +struct nlist current_nl[] = { /* Namelist for currently running system. */ +#define X_DUMPDEV 0 + { "_dumpdev" }, +#define X_DUMPLO 1 + { "_dumplo" }, +#define X_TIME 2 + { "_time" }, +#define X_DUMPSIZE 3 + { "_dumpsize" }, +#define X_VERSION 4 + { "_version" }, +#define X_PANICSTR 5 + { "_panicstr" }, +#define X_DUMPMAG 6 + { "_dumpmag" }, + { "" }, +}; +int cursyms[] = { X_DUMPDEV, X_DUMPLO, X_VERSION, X_DUMPMAG, -1 }; +int dumpsyms[] = { X_TIME, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG, -1 }; + +struct nlist dump_nl[] = { /* Name list for dumped system. */ + { "_dumpdev" }, /* Entries MUST be the same as */ + { "_dumplo" }, /* those in current_nl[]. */ + { "_time" }, + { "_dumpsize" }, + { "_version" }, + { "_panicstr" }, + { "_dumpmag" }, + { "" }, +}; + +/* Types match kernel declarations. */ +long dumplo; /* where dump starts on dumpdev */ +int dumpmag; /* magic number in dump */ +int dumpsize; /* amount of memory dumped */ + +char *kernel; +char *dirname; /* directory to save dumps in */ +char *ddname; /* name of dump device */ +dev_t dumpdev; /* dump device */ +int dumpfd; /* read/write descriptor on block dev */ +time_t now; /* current date */ +char panic_mesg[1024]; +int panicstr; +char vers[1024]; + +int clear, compress, force, verbose; /* flags */ + +void check_kmem __P((void)); +int check_space __P((void)); +void clear_dump __P((void)); +int Create __P((char *, int)); +int dump_exists __P((void)); +char *find_dev __P((dev_t, int)); +int get_crashtime __P((void)); +void kmem_setup __P((void)); +void log __P((int, char *, ...)); +void Lseek __P((int, off_t, int)); +int Open __P((char *, int rw)); +int Read __P((int, void *, int)); +char *rawname __P((char *s)); +void save_core __P((void)); +void usage __P((void)); +void Write __P((int, void *, int)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ch; + + openlog("savecore", LOG_PERROR, LOG_DAEMON); + + while ((ch = getopt(argc, argv, "cdfN:vz")) != -1) + switch(ch) { + case 'c': + clear = 1; + break; + case 'd': /* Not documented. */ + case 'v': + verbose = 1; + break; + case 'f': + force = 1; + break; + case 'N': + kernel = optarg; + break; + case 'z': + compress = 1; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (!clear) { + if (argc != 1 && argc != 2) + usage(); + dirname = argv[0]; + } + if (argc == 2) + kernel = argv[1]; + + (void)time(&now); + kmem_setup(); + + if (clear) { + clear_dump(); + exit(0); + } + + if (!dump_exists() && !force) + exit(1); + + check_kmem(); + + if (panicstr) + syslog(LOG_ALERT, "reboot after panic: %s", panic_mesg); + else + syslog(LOG_ALERT, "reboot"); + + if ((!get_crashtime() || !check_space()) && !force) + exit(1); + + save_core(); + + clear_dump(); + exit(0); +} + +void +kmem_setup() +{ + FILE *fp; + int kmem, i; + char *dump_sys; + + /* + * Some names we need for the currently running system, others for + * the system that was running when the dump was made. The values + * obtained from the current system are used to look for things in + * /dev/kmem that cannot be found in the dump_sys namelist, but are + * presumed to be the same (since the disk partitions are probably + * the same!) + */ + if ((nlist(_PATH_UNIX, current_nl)) == -1) + syslog(LOG_ERR, "%s: nlist: %s", _PATH_UNIX, strerror(errno)); + for (i = 0; cursyms[i] != -1; i++) + if (current_nl[cursyms[i]].n_value == 0) { + syslog(LOG_ERR, "%s: %s not in namelist", + _PATH_UNIX, current_nl[cursyms[i]].n_name); + exit(1); + } + + dump_sys = kernel ? kernel : _PATH_UNIX; + if ((nlist(dump_sys, dump_nl)) == -1) + syslog(LOG_ERR, "%s: nlist: %s", dump_sys, strerror(errno)); + for (i = 0; dumpsyms[i] != -1; i++) + if (dump_nl[dumpsyms[i]].n_value == 0) { + syslog(LOG_ERR, "%s: %s not in namelist", + dump_sys, dump_nl[dumpsyms[i]].n_name); + exit(1); + } + + kmem = Open(_PATH_KMEM, O_RDONLY); + Lseek(kmem, (off_t)current_nl[X_DUMPDEV].n_value, L_SET); + (void)Read(kmem, &dumpdev, sizeof(dumpdev)); + if (dumpdev == NODEV) { + syslog(LOG_WARNING, "no core dump (no dumpdev)"); + exit(1); + } + Lseek(kmem, (off_t)current_nl[X_DUMPLO].n_value, L_SET); + (void)Read(kmem, &dumplo, sizeof(dumplo)); + dumplo *= DEV_BSIZE; + if (verbose) + (void)printf("dumplo = %d (%d * %d)\n", + dumplo, dumplo / DEV_BSIZE, DEV_BSIZE); + Lseek(kmem, (off_t)current_nl[X_DUMPMAG].n_value, L_SET); + (void)Read(kmem, &dumpmag, sizeof(dumpmag)); + ddname = find_dev(dumpdev, S_IFBLK); + dumpfd = Open(ddname, O_RDWR); + fp = fdopen(kmem, "r"); + if (fp == NULL) { + syslog(LOG_ERR, "%s: fdopen: %m", _PATH_KMEM); + exit(1); + } + if (kernel) + return; + (void)fseek(fp, (off_t)current_nl[X_VERSION].n_value, L_SET); + (void)fgets(vers, sizeof(vers), fp); + + /* Don't fclose(fp), we use dumpfd later. */ +} + +void +check_kmem() +{ + register char *cp; + FILE *fp; + char core_vers[1024]; + + fp = fdopen(dumpfd, "r"); + if (fp == NULL) { + syslog(LOG_ERR, "%s: fdopen: %m", ddname); + exit(1); + } + fseek(fp, (off_t)(dumplo + ok(dump_nl[X_VERSION].n_value)), L_SET); + fgets(core_vers, sizeof(core_vers), fp); + if (strcmp(vers, core_vers) && kernel == 0) + syslog(LOG_WARNING, + "warning: %s version mismatch:\n\t%s\nand\t%s\n", + _PATH_UNIX, vers, core_vers); + (void)fseek(fp, + (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET); + (void)fread(&panicstr, sizeof(panicstr), 1, fp); + if (panicstr) { + (void)fseek(fp, dumplo + ok(panicstr), L_SET); + cp = panic_mesg; + do + *cp = getc(fp); + while (*cp++ && cp < &panic_mesg[sizeof(panic_mesg)]); + } + /* Don't fclose(fp), we use dumpfd later. */ +} + +void +clear_dump() +{ + long newdumplo; + + newdumplo = 0; + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); + Write(dumpfd, &newdumplo, sizeof(newdumplo)); +} + +int +dump_exists() +{ + int newdumpmag; + + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); + (void)Read(dumpfd, &newdumpmag, sizeof(newdumpmag)); + + /* Read the dump size. */ + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET); + (void)Read(dumpfd, &dumpsize, sizeof(dumpsize)); + dumpsize *= getpagesize(); + + /* + * Return zero if core dump doesn't seem to be there, and note + * it for syslog. This check and return happens after the dump size + * is read, so dumpsize is whether or not the core is valid (for -f). + */ + if (newdumpmag != dumpmag) { + if (verbose) + syslog(LOG_WARNING, "magic number mismatch (%x != %x)", + newdumpmag, dumpmag); + syslog(LOG_WARNING, "no core dump"); + return (0); + } + return (1); +} + +char buf[1024 * 1024]; + +void +save_core() +{ + register FILE *fp; + register int bounds, ifd, nr, nw, ofd; + char *rawp, path[MAXPATHLEN]; + + /* + * Get the current number and update the bounds file. Do the update + * now, because may fail later and don't want to overwrite anything. + */ + (void)snprintf(path, sizeof(path), "%s/bounds", dirname); + if ((fp = fopen(path, "r")) == NULL) + goto err1; + if (fgets(buf, sizeof(buf), fp) == NULL) { + if (ferror(fp)) +err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); + bounds = 0; + } else + bounds = atoi(buf); + if (fp != NULL) + (void)fclose(fp); + if ((fp = fopen(path, "w")) == NULL) + syslog(LOG_ERR, "%s: %m", path); + else { + (void)fprintf(fp, "%d\n", bounds + 1); + (void)fclose(fp); + } + (void)fclose(fp); + + /* Create the core file. */ + (void)snprintf(path, sizeof(path), "%s/netbsd.%d.core%s", + dirname, bounds, compress ? ".Z" : ""); + if (compress) { + if ((fp = zopen(path, "w", 0)) == NULL) { + syslog(LOG_ERR, "%s: %s", path, strerror(errno)); + exit(1); + } + } else + ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + /* Open the raw device. */ + rawp = rawname(ddname); + if ((ifd = open(rawp, O_RDONLY)) == -1) { + syslog(LOG_WARNING, "%s: %m; using block device", rawp); + ifd = dumpfd; + } + + /* Seek to the start of the core. */ + Lseek(ifd, (off_t)dumplo, L_SET); + + /* Copy the core file. */ + syslog(LOG_NOTICE, "writing %score to %s", + compress ? "compressed " : "", path); + for (; dumpsize > 0; dumpsize -= nr) { + (void)printf("%6dK\r", dumpsize / 1024); + (void)fflush(stdout); + nr = read(ifd, buf, MIN(dumpsize, sizeof(buf))); + if (nr <= 0) { + if (nr == 0) + syslog(LOG_WARNING, + "WARNING: EOF on dump device"); + else + syslog(LOG_ERR, "%s: %m", rawp); + goto err2; + } + if (compress) + nw = fwrite(buf, 1, nr, fp); + else + nw = write(ofd, buf, nr); + if (nw != nr) { + syslog(LOG_ERR, "%s: %s", + path, strerror(nw == 0 ? EIO : errno)); +err2: syslog(LOG_WARNING, + "WARNING: core may be incomplete"); + (void)printf("\n"); + exit(1); + } + } + (void)close(ifd); + if (compress) + (void)fclose(fp); + else + (void)close(ofd); + + /* Copy the kernel. */ + ifd = Open(kernel ? kernel : _PATH_UNIX, O_RDONLY); + (void)snprintf(path, sizeof(path), "%s/netbsd.%d%s", + dirname, bounds, compress ? ".Z" : ""); + if (compress) { + if ((fp = zopen(path, "w", 0)) == NULL) { + syslog(LOG_ERR, "%s: %s", path, strerror(errno)); + exit(1); + } + } else + ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + syslog(LOG_NOTICE, "writing %skernel to %s", + compress ? "compressed " : "", path); + while ((nr = read(ifd, buf, sizeof(buf))) > 0) { + if (compress) + nw = fwrite(buf, 1, nr, fp); + else + nw = write(ofd, buf, nr); + if (nw != nr) { + syslog(LOG_ERR, "%s: %s", + path, strerror(nw == 0 ? EIO : errno)); + syslog(LOG_WARNING, + "WARNING: kernel may be incomplete"); + exit(1); + } + } + if (nr < 0) { + syslog(LOG_ERR, "%s: %s", + kernel ? kernel : _PATH_UNIX, strerror(errno)); + syslog(LOG_WARNING, + "WARNING: kernel may be incomplete"); + exit(1); + } + if (compress) + (void)fclose(fp); + else + (void)close(ofd); +} + +char * +find_dev(dev, type) + register dev_t dev; + register int type; +{ + register DIR *dfd; + struct dirent *dir; + struct stat sb; + char *dp, devname[MAXPATHLEN + 1]; + + if ((dfd = opendir(_PATH_DEV)) == NULL) { + syslog(LOG_ERR, "%s: %s", _PATH_DEV, strerror(errno)); + exit(1); + } + (void)strcpy(devname, _PATH_DEV); + while ((dir = readdir(dfd))) { + (void)strcpy(devname + sizeof(_PATH_DEV) - 1, dir->d_name); + if (lstat(devname, &sb)) { + syslog(LOG_ERR, "%s: %s", devname, strerror(errno)); + continue; + } + if ((sb.st_mode & S_IFMT) != type) + continue; + if (dev == sb.st_rdev) { + closedir(dfd); + if ((dp = strdup(devname)) == NULL) { + syslog(LOG_ERR, "%s", strerror(errno)); + exit(1); + } + return (dp); + } + } + closedir(dfd); + syslog(LOG_ERR, "can't find device %d/%d", major(dev), minor(dev)); + exit(1); +} + +char * +rawname(s) + char *s; +{ + char *sl, name[MAXPATHLEN]; + + if ((sl = strrchr(s, '/')) == NULL || sl[1] == '0') { + syslog(LOG_ERR, + "can't make raw dump device name from %s", s); + return (s); + } + (void)snprintf(name, sizeof(name), "%.*s/r%s", sl - s, s, sl + 1); + if ((sl = strdup(name)) == NULL) { + syslog(LOG_ERR, "%s", strerror(errno)); + exit(1); + } + return (sl); +} + +int +get_crashtime() +{ + time_t dumptime; /* Time the dump was taken. */ + + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_TIME].n_value)), L_SET); + (void)Read(dumpfd, &dumptime, sizeof(dumptime)); + if (dumptime == 0) { + if (verbose) + syslog(LOG_ERR, "dump time is zero"); + return (0); + } + (void)printf("savecore: system went down at %s", ctime(&dumptime)); +#define LEEWAY (7 * SECSPERDAY) + if (dumptime < now - LEEWAY || dumptime > now + LEEWAY) { + (void)printf("dump time is unreasonable\n"); + return (0); + } + return (1); +} + +int +check_space() +{ + register FILE *fp; + char *tkernel; + off_t minfree, spacefree, kernelsize, needed; + struct stat st; + struct statfs fsbuf; + char buf[100], path[MAXPATHLEN]; + + tkernel = kernel ? kernel : _PATH_UNIX; + if (stat(tkernel, &st) < 0) { + syslog(LOG_ERR, "%s: %m", tkernel); + exit(1); + } + kernelsize = st.st_blocks * S_BLKSIZE; + if (statfs(dirname, &fsbuf) < 0) { + syslog(LOG_ERR, "%s: %m", dirname); + exit(1); + } + spacefree = (fsbuf.f_bavail * fsbuf.f_bsize) / 1024; + + (void)snprintf(path, sizeof(path), "%s/minfree", dirname); + if ((fp = fopen(path, "r")) == NULL) + minfree = 0; + else { + if (fgets(buf, sizeof(buf), fp) == NULL) + minfree = 0; + else + minfree = atoi(buf); + (void)fclose(fp); + } + + needed = (dumpsize + kernelsize) / 1024; + if (minfree > 0 && spacefree - needed < minfree) { + syslog(LOG_WARNING, + "no dump, not enough free space on device"); + return (0); + } + if (spacefree - needed < minfree) + syslog(LOG_WARNING, + "dump performed, but free space threshold crossed"); + return (1); +} + +int +Open(name, rw) + char *name; + int rw; +{ + int fd; + + if ((fd = open(name, rw, 0)) < 0) { + syslog(LOG_ERR, "%s: %m", name); + exit(1); + } + return (fd); +} + +int +Read(fd, bp, size) + int fd, size; + void *bp; +{ + int nr; + + nr = read(fd, bp, size); + if (nr != size) { + syslog(LOG_ERR, "read: %m"); + exit(1); + } + return (nr); +} + +void +Lseek(fd, off, flag) + int fd, flag; + off_t off; +{ + off_t ret; + + ret = lseek(fd, off, flag); + if (ret == -1) { + syslog(LOG_ERR, "lseek: %m"); + exit(1); + } +} + +int +Create(file, mode) + char *file; + int mode; +{ + register int fd; + + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, mode); + if (fd < 0) { + syslog(LOG_ERR, "%s: %m", file); + exit(1); + } + return (fd); +} + +void +Write(fd, bp, size) + int fd, size; + void *bp; +{ + int n; + + if ((n = write(fd, bp, size)) < size) { + syslog(LOG_ERR, "write: %s", strerror(n == -1 ? errno : EIO)); + exit(1); + } +} + +void +usage() +{ + (void)syslog(LOG_ERR, "usage: savecore [-cfvz] [-N system] directory"); + exit(1); +} diff --git a/sbin/ttyflags/ttyflags.c b/sbin/ttyflags/ttyflags.c index 2d38d891b76..a35fc99f2e5 100644 --- a/sbin/ttyflags/ttyflags.c +++ b/sbin/ttyflags/ttyflags.c @@ -1,4 +1,4 @@ -/* $NetBSD: ttyflags.c,v 1.6 1995/08/13 05:24:03 cgd Exp $ */ +/* $NetBSD: ttyflags.c,v 1.8 1996/04/09 05:20:30 cgd Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -37,7 +37,7 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char rcsid[] = "$NetBSD: ttyflags.c,v 1.6 1995/08/13 05:24:03 cgd Exp $"; +static char rcsid[] = "$NetBSD: ttyflags.c,v 1.8 1996/04/09 05:20:30 cgd Exp $"; #endif /* not lint */ #include @@ -51,6 +51,7 @@ static char rcsid[] = "$NetBSD: ttyflags.c,v 1.6 1995/08/13 05:24:03 cgd Exp $"; #include #include #include +#include #include #include @@ -153,35 +154,57 @@ change_ttys(ttylist) return (rval); } + /* - * Acutually do the work; find out what the new flags value should be, + * Actually do the work; find out what the new flags value should be, * open the device, and change the flags. */ int change_ttyflags(tep) struct ttyent *tep; { - int fd, flags, rval, st; + int fd, flags, rval, st, sep; char path[PATH_MAX]; + char strflags[256]; st = tep->ty_status; - flags = rval = 0; + sep = flags = rval = 0; + strflags[0] = '\0'; + /* Convert ttyent.h flags into ioctl flags. */ - if (st & TTY_LOCAL) + if (st & TTY_LOCAL) { flags |= TIOCFLAG_CLOCAL; - if (st & TTY_RTSCTS) + (void)strcat(strflags, "local"); + sep++; + } + if (st & TTY_RTSCTS) { flags |= TIOCFLAG_CRTSCTS; - if (st & TTY_SOFTCAR) + if (sep++) + (void)strcat(strflags, "|"); + (void)strcat(strflags, "rtscts"); + } + if (st & TTY_SOFTCAR) { flags |= TIOCFLAG_SOFTCAR; - if (st & TTY_MDMBUF) + if (sep++) + (void)strcat(strflags, "|"); + (void)strcat(strflags, "softcar"); + } + if (st & TTY_MDMBUF) { flags |= TIOCFLAG_MDMBUF; + if (sep++) + (void)strcat(strflags, "|"); + (void)strcat(strflags, "mdmbuf"); + } + + if (strflags[0] == '\0') + (void)strcpy(strflags, "none"); /* Find the full device path name. */ (void)snprintf(path, sizeof path, "%s%s", _PATH_DEV, tep->ty_name); if (vflag) - warnx("setting flags on %s to %0x", path, flags); + warnx("setting flags on %s to %s", path, strflags); if (nflag) return (0); diff --git a/usr.bin/apply/apply.1 b/usr.bin/apply/apply.1 index 6b6b3e5ad27..3fdaa99a77d 100644 --- a/usr.bin/apply/apply.1 +++ b/usr.bin/apply/apply.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: apply.1,v 1.3 1995/03/25 03:38:21 glass Exp $ +.\" $NetBSD: apply.1,v 1.4 1996/03/18 23:16:57 jtc Exp $ .\" .\" Copyright (c) 1983, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -82,7 +82,7 @@ is run, without arguments, once for each If any sequences of .Dq Li \&%d occur in command, the -.Fl n +.Fl # option is ignored. .It Fl a Ns Ar c The use of the character diff --git a/usr.bin/file/magdir/OpenBSD b/usr.bin/file/magdir/OpenBSD index 242aec64993..e7949cff490 100644 --- a/usr.bin/file/magdir/OpenBSD +++ b/usr.bin/file/magdir/OpenBSD @@ -10,6 +10,13 @@ >16 lelong >0 not stripped >32 byte 0x6a (uses shared libs) +0 lelong&077777777 041400314 FreeBSD/i386 demand paged +>3 byte &0x80 +>>20 lelong <4096 shared library +>>20 lelong =4096 dynamically linked executable +>>20 lelong >4096 dynamically linked executable +>3 byte ^0x80 executable +>16 lelong >0 not stripped 0 lelong 000000407 OpenBSD little-endian object file >16 lelong >0 not stripped @@ -183,3 +190,24 @@ >16 belong >0 not stripped 0 belong&0377777777 043400507 OpenBSD/mips core >12 string >\0 from '%s' + +0 belong&0377777777 043600413 NetBSD/arm32 demand paged +>0 byte &0x80 +>>20 lelong <8192 shared library +>>20 lelong =8192 dynamically linked executable +>>20 lelong >8192 dynamically linked executable +>0 byte ^0x80 executable +>16 lelong >0 not stripped +0 belong&0377777777 043600410 NetBSD/arm32 pure +>0 byte &0x80 dynamically linked executable +>0 byte ^0x80 executable +>16 lelong >0 not stripped +0 belong&0377777777 043600407 NetBSD/arm32 +>0 byte &0x80 dynamically linked executable +>0 byte ^0x80 +>>0 byte &0x40 position independent +>>20 lelong !0 executable +>>20 lelong =0 object file +>16 lelong >0 not stripped +0 belong&0377777777 043600507 NetBSD/arm32 core +>12 string >\0 from '%s' diff --git a/usr.bin/gencat/gencat.c b/usr.bin/gencat/gencat.c index 40f3104da48..b6b6b2afe0d 100644 --- a/usr.bin/gencat/gencat.c +++ b/usr.bin/gencat/gencat.c @@ -80,7 +80,7 @@ void usage() { fprintf(stderr, " catfile msgfile [-h ]...\n"); } -void main( +int main( #if ANSI_C || defined(__cplusplus) int argc, char *argv[]) #else diff --git a/usr.bin/gprof/arm32.c b/usr.bin/gprof/arm32.c new file mode 100644 index 00000000000..2b0bfdfa19c --- /dev/null +++ b/usr.bin/gprof/arm32.c @@ -0,0 +1,17 @@ +/* $NetBSD: arm32.c,v 1.1 1996/04/01 21:51:22 mark Exp $ */ + +#ifndef lint +static char rcsid[] = "$NetBSD: arm32.c,v 1.1 1996/04/01 21:51:22 mark Exp $"; +#endif /* not lint */ + +#include "gprof.h" + +/* + * gprof -c isn't currently supported... + */ +findcall( parentp , p_lowpc , p_highpc ) + nltype *parentp; + unsigned long p_lowpc; + unsigned long p_highpc; +{ +} diff --git a/usr.bin/gprof/arm32.h b/usr.bin/gprof/arm32.h new file mode 100644 index 00000000000..fd4c0f4e4ef --- /dev/null +++ b/usr.bin/gprof/arm32.h @@ -0,0 +1,45 @@ +/* $NetBSD: arm32.h,v 1.1 1996/04/01 21:51:26 mark 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +/* + * offset (in bytes) of the code from the entry address of a routine. + * (see asgnsamples for use and explanation.) + */ + +#define OFFSET_OF_CODE 0 +#define UNITS_TO_CODE (OFFSET_OF_CODE / sizeof(UNIT)) + +enum opermodes { dummy }; +typedef enum opermodes operandenum; diff --git a/usr.bin/gprof/gprof.h b/usr.bin/gprof/gprof.h index d0ba72299df..681d9e92477 100644 --- a/usr.bin/gprof/gprof.h +++ b/usr.bin/gprof/gprof.h @@ -1,4 +1,4 @@ -/* $NetBSD: gprof.h,v 1.12 1995/04/19 07:22:59 cgd Exp $ */ +/* $NetBSD: gprof.h,v 1.13 1996/04/01 21:54:06 mark Exp $ */ /* * Copyright (c) 1983, 1993 @@ -46,6 +46,9 @@ #if alpha # include "alpha.h" #endif +#if arm32 +# include "arm32.h" +#endif #if i386 # include "i386.h" #endif diff --git a/usr.bin/make/buf.c b/usr.bin/make/buf.c index 22d3a0e855d..52179007773 100644 --- a/usr.bin/make/buf.c +++ b/usr.bin/make/buf.c @@ -1,4 +1,4 @@ -/* $NetBSD: buf.c,v 1.6 1995/06/14 15:18:51 christos Exp $ */ +/* $NetBSD: buf.c,v 1.7 1996/03/29 02:17:13 jtc Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)buf.c 5.5 (Berkeley) 12/28/90"; #else -static char rcsid[] = "$NetBSD: buf.c,v 1.6 1995/06/14 15:18:51 christos Exp $"; +static char rcsid[] = "$NetBSD: buf.c,v 1.7 1996/03/29 02:17:13 jtc Exp $"; #endif #endif /* not lint */ @@ -69,7 +69,7 @@ static char rcsid[] = "$NetBSD: buf.c,v 1.6 1995/06/14 15:18:51 christos Exp $"; #define BufExpand(bp,nb) \ if (bp->left < (nb)+1) {\ int newSize = (bp)->size + max((nb)+1,BUF_ADD_INC); \ - Byte *newBuf = (Byte *) realloc((bp)->buffer, newSize); \ + Byte *newBuf = (Byte *) erealloc((bp)->buffer, newSize); \ \ (bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \ (bp)->outPtr = newBuf + ((bp)->outPtr - (bp)->buffer);\ diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h index c719a2ca197..d1b948ecf54 100644 --- a/usr.bin/make/extern.h +++ b/usr.bin/make/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.7 1995/11/02 23:55:00 christos Exp $ */ +/* $NetBSD: nonints.h,v 1.9 1996/03/31 21:30:07 christos Exp $ */ /*- * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -71,7 +71,8 @@ void Punt __P((char *, ...)); void DieHorribly __P((void)); int PrintAddr __P((ClientData, ClientData)); void Finish __P((int)); -char *emalloc __P((size_t)); +void *emalloc __P((size_t)); +void *erealloc __P((void *, size_t)); void enomem __P((void)); int eunlink __P((const char *)); diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 0bf0ab56f1d..5ffcbcfb3a5 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.6 1996/03/27 19:32:36 niklas Exp $ */ -/* $NetBSD: main.c,v 1.26 1996/03/11 13:45:33 christos Exp $ */ +/* $OpenBSD: main.c,v 1.7 1996/04/21 23:43:21 deraadt Exp $ */ +/* $NetBSD: main.c,v 1.28 1996/03/31 21:30:05 christos Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -50,7 +50,7 @@ char copyright[] = static char sccsid[] = "@(#)main.c 5.25 (Berkeley) 4/1/91"; static char rcsid[] = "$NetBSD: main.c,v 1.26 1996/03/11 13:45:33 christos Exp $"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.6 1996/03/27 19:32:36 niklas Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.7 1996/04/21 23:43:21 deraadt Exp $"; #endif #endif /* not lint */ @@ -981,17 +981,31 @@ Finish(errors) * emalloc -- * malloc, but die on error. */ -char * +void * emalloc(len) size_t len; { - char *p; + void *p; - if ((p = (char *) malloc(len)) == NULL) + if ((p = malloc(len)) == NULL) enomem(); return(p); } +/* + * erealloc -- + * realloc, but die on error. + */ +void * +erealloc(ptr, size) + void *ptr; + size_t size; +{ + if ((ptr = realloc(ptr, size)) == NULL) + enomem(); + return(ptr); +} + /* * enomem -- * die when out of memory. diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h index c719a2ca197..d1b948ecf54 100644 --- a/usr.bin/make/nonints.h +++ b/usr.bin/make/nonints.h @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.7 1995/11/02 23:55:00 christos Exp $ */ +/* $NetBSD: nonints.h,v 1.9 1996/03/31 21:30:07 christos Exp $ */ /*- * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -71,7 +71,8 @@ void Punt __P((char *, ...)); void DieHorribly __P((void)); int PrintAddr __P((ClientData, ClientData)); void Finish __P((int)); -char *emalloc __P((size_t)); +void *emalloc __P((size_t)); +void *erealloc __P((void *, size_t)); void enomem __P((void)); int eunlink __P((const char *)); diff --git a/usr.bin/make/str.c b/usr.bin/make/str.c index 77f773483be..94dacf99a89 100644 --- a/usr.bin/make/str.c +++ b/usr.bin/make/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.10.2.1 1995/10/30 22:55:14 jtc Exp $ */ +/* $NetBSD: str.c,v 1.12 1996/03/29 02:17:34 jtc Exp $ */ /*- * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90"; #else -static char rcsid[] = "$NetBSD: str.c,v 1.10.2.1 1995/10/30 22:55:14 jtc Exp $"; +static char rcsid[] = "$NetBSD: str.c,v 1.12 1996/03/29 02:17:34 jtc Exp $"; #endif #endif /* not lint */ @@ -206,9 +206,8 @@ brk_string(str, store_argc, expand) *t++ = '\0'; if (argc == argmax) { argmax *= 2; /* ramp up fast */ - if (!(argv = (char **)realloc(argv, - (argmax + 1) * sizeof(char *)))) - enomem(); + argv = (char **)erealloc(argv, + (argmax + 1) * sizeof(char *)); } argv[argc++] = start; start = (char *)NULL; diff --git a/usr.bin/make/targ.c b/usr.bin/make/targ.c index 143cbd329b2..6d047701616 100644 --- a/usr.bin/make/targ.c +++ b/usr.bin/make/targ.c @@ -1,4 +1,5 @@ -/* $NetBSD: targ.c,v 1.6 1995/12/16 05:03:15 christos Exp $ */ +/* $OpenBSD: targ.c,v 1.3 1996/04/21 23:43:28 deraadt Exp $ */ +/* $NetBSD: targ.c,v 1.7 1996/04/08 18:57:49 jtc Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -40,7 +41,7 @@ #ifndef lint /* from: static char sccsid[] = "@(#)targ.c 5.9 (Berkeley) 3/1/91"; */ -static char *rcsid = "$Id: targ.c,v 1.2 1995/12/17 13:42:03 deraadt Exp $"; +static char *rcsid = "$Id: targ.c,v 1.3 1996/04/21 23:43:28 deraadt Exp $"; #endif /* not lint */ /*- @@ -471,9 +472,9 @@ Targ_FmtTime (time) parts = localtime(&time); - sprintf (buf, "%d:%02d:%02d %s %d, 19%d", + sprintf (buf, "%d:%02d:%02d %s %d, %d", parts->tm_hour, parts->tm_min, parts->tm_sec, - months[parts->tm_mon], parts->tm_mday, parts->tm_year); + months[parts->tm_mon], parts->tm_mday, 1900 + parts->tm_year); return(buf); } diff --git a/usr.bin/quota/quota.c b/usr.bin/quota/quota.c index dc0b07f2d11..6ec5d5f9b5a 100644 --- a/usr.bin/quota/quota.c +++ b/usr.bin/quota/quota.c @@ -42,7 +42,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)quota.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$Id: quota.c,v 1.2 1995/11/25 16:46:24 deraadt Exp $"; +static char rcsid[] = "$Id: quota.c,v 1.3 1996/04/21 23:43:38 deraadt Exp $"; #endif /* not lint */ /* @@ -92,11 +92,11 @@ main(argc, argv) int ngroups; gid_t mygid, gidset[NGROUPS]; int i, gflag = 0, uflag = 0; - char ch; + int ch; extern char *optarg; extern int optind, errno; - while ((ch = getopt(argc, argv, "ugvq")) != EOF) { + while ((ch = getopt(argc, argv, "ugvq")) != -1) { switch(ch) { case 'g': gflag++; diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c index 9ee0e8da946..4fb7222e740 100644 --- a/usr.bin/rusers/rusers.c +++ b/usr.bin/rusers/rusers.c @@ -27,7 +27,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: rusers.c,v 1.1.1.1 1995/10/18 08:46:04 deraadt Exp $"; +static char rcsid[] = "$Id: rusers.c,v 1.2 1996/04/21 23:43:46 deraadt Exp $"; #endif /* not lint */ #include @@ -224,13 +224,15 @@ allhosts(void) } } -void usage(void) +void +usage(void) { fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0); exit(1); } -void main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { int ch; extern int optind; diff --git a/usr.bin/showmount/showmount.c b/usr.bin/showmount/showmount.c index 77440130481..953036b0af8 100644 --- a/usr.bin/showmount/showmount.c +++ b/usr.bin/showmount/showmount.c @@ -1,4 +1,4 @@ -/* $NetBSD: showmount.c,v 1.5 1995/08/31 22:26:08 jtc Exp $ */ +/* $NetBSD: showmount.c,v 1.6 1996/04/01 21:32:19 mark Exp $ */ /* * Copyright (c) 1989, 1993, 1995 @@ -46,7 +46,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)showmount.c 8.3 (Berkeley) 3/29/95"; #endif -static char rcsid[] = "$NetBSD: showmount.c,v 1.5 1995/08/31 22:26:08 jtc Exp $"; +static char rcsid[] = "$NetBSD: showmount.c,v 1.6 1996/04/01 21:32:19 mark Exp $"; #endif not lint #include @@ -114,9 +114,10 @@ main(argc, argv) struct exportslist *exp; struct grouplist *grp; int estat, rpcs = 0, mntvers = 1; - char ch, *host; + char *host; + int ch; - while ((ch = getopt(argc, argv, "ade3")) != EOF) + while ((ch = getopt(argc, argv, "ade3")) != -1) switch((char)ch) { case 'a': if (type == 0) { diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c index 49929243a37..6d1e8ee9a0c 100644 --- a/usr.bin/systat/main.c +++ b/usr.bin/systat/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.6 1995/05/06 06:25:07 jtc Exp $ */ +/* $NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $ */ /*- * Copyright (c) 1980, 1992, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$NetBSD: main.c,v 1.6 1995/05/06 06:25:07 jtc Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $"; #endif /* not lint */ #include @@ -82,7 +82,7 @@ int CMDLINE; static WINDOW *wload; /* one line window for load average */ -void +int main(argc, argv) int argc; char **argv; diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 85e8b9daeab..769e2ee4070 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -1,5 +1,5 @@ -/* $OpenBSD: commands.c,v 1.3 1996/03/27 19:32:58 niklas Exp $ */ -/* $NetBSD: commands.c,v 1.13 1996/02/28 21:03:53 thorpej Exp $ */ +/* $OpenBSD: commands.c,v 1.4 1996/04/21 23:44:11 deraadt Exp $ */ +/* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* * Copyright (c) 1988, 1990, 1993 @@ -37,9 +37,9 @@ #ifndef lint #if 0 static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; -static char rcsid[] = "$NetBSD: commands.c,v 1.13 1996/02/28 21:03:53 thorpej Exp $"; +static char rcsid[] = "$NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $"; #else -static char rcsid[] = "$OpenBSD: commands.c,v 1.3 1996/03/27 19:32:58 niklas Exp $"; +static char rcsid[] = "$OpenBSD: commands.c,v 1.4 1996/04/21 23:44:11 deraadt Exp $"; #endif #endif /* not lint */ @@ -2172,7 +2172,11 @@ tn(argc, argv) if (temp != INADDR_NONE) { sin.sin_addr.s_addr = temp; sin.sin_family = AF_INET; - (void) strcpy(_hostname, hostp); + host = gethostbyaddr((char *)&temp, sizeof(temp), AF_INET); + if (host) + (void) strcpy(_hostname, host->h_name); + else + (void) strcpy(_hostname, hostp); hostname = _hostname; } else { host = gethostbyname(hostp); diff --git a/usr.bin/units/Makefile b/usr.bin/units/Makefile index ead83fe2ab0..4b6b5307b0e 100644 --- a/usr.bin/units/Makefile +++ b/usr.bin/units/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1.1.1 1995/10/18 08:46:30 deraadt Exp $ +# $OpenBSD: Makefile,v 1.2 1996/04/21 23:44:23 deraadt Exp $ PROG= units diff --git a/usr.bin/units/README b/usr.bin/units/README index a0c9906a1b7..ce335343db6 100644 --- a/usr.bin/units/README +++ b/usr.bin/units/README @@ -1,4 +1,4 @@ -# NetBSD $Id: README,v 1.1.1.1 1995/10/18 08:46:30 deraadt Exp $ +# $NetBSD: README,v 1.2 1996/04/06 06:00:59 thorpej Exp $ This is a program which I wrote as a clone of the UNIX 'units' command. I threw it together in a couple days, but it seems to work, diff --git a/usr.bin/units/pathnames.h b/usr.bin/units/pathnames.h index 781f8028bea..94253eaf253 100644 --- a/usr.bin/units/pathnames.h +++ b/usr.bin/units/pathnames.h @@ -1,3 +1,5 @@ +/* $NetBSD: pathnames.h,v 1.3 1996/04/06 06:01:00 thorpej Exp $ */ + /* * Copyright (c) 1993 Christopher G. Demetriou * All rights reserved. @@ -26,8 +28,6 @@ * 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. - * - * $Id: pathnames.h,v 1.1.1.1 1995/10/18 08:46:30 deraadt Exp $ */ #define _PATH_UNITSLIB "/usr/share/misc/units.lib" diff --git a/usr.bin/units/units.1 b/usr.bin/units/units.1 index 24259ff111a..d5e0f6cdd80 100644 --- a/usr.bin/units/units.1 +++ b/usr.bin/units/units.1 @@ -1,4 +1,4 @@ -.\" $Id: units.1,v 1.1.1.1 1995/10/18 08:46:30 deraadt Exp $ +.\" $NetBSD: units.1,v 1.6 1996/04/06 06:01:02 thorpej Exp $ .TH UNITS 1 "14 July 1993" .SH NAME units - conversion program diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c index af23eefd8c7..13aaf1a2d06 100644 --- a/usr.bin/units/units.c +++ b/usr.bin/units/units.c @@ -1,3 +1,5 @@ +/* $NetBSD: units.c,v 1.6 1996/04/06 06:01:03 thorpej Exp $ */ + /* * units.c Copyright (c) 1993 by Adrian Mariano (adrian@cam.cornell.edu) * @@ -13,8 +15,6 @@ * * I would appreciate (though I do not require) receiving a copy of any * improvements you might make to this program. - * - * $Id: units.c,v 1.1.1.1 1995/10/18 08:46:30 deraadt Exp $ */ #include @@ -625,20 +625,20 @@ usage() } -void +int main(int argc, char **argv) { struct unittype have, want; char havestr[81], wantstr[81]; - char optchar; + int optchar; char *userfile = 0; int quiet = 0; extern char *optarg; extern int optind; - while (EOF != (optchar = getopt(argc, argv, "vqf:"))) { + while ((optchar = getopt(argc, argv, "vqf:")) != -1) { switch (optchar) { case 'f': userfile = optarg; diff --git a/usr.bin/units/units.lib b/usr.bin/units/units.lib index b2c5a3bab53..060e3ed3d82 100644 --- a/usr.bin/units/units.lib +++ b/usr.bin/units/units.lib @@ -1,4 +1,4 @@ -/ $Id: units.lib,v 1.1.1.1 1995/10/18 08:46:30 deraadt Exp $ +/ $NetBSD: units.lib,v 1.3 1996/04/06 06:01:04 thorpej Exp $ / primitive units diff --git a/usr.bin/vgrind/vfontedpr.c b/usr.bin/vgrind/vfontedpr.c index 1bcf6f83ffc..2b67f566a3f 100644 --- a/usr.bin/vgrind/vfontedpr.c +++ b/usr.bin/vgrind/vfontedpr.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfontedpr.c,v 1.3 1994/11/17 08:28:03 jtc Exp $ */ +/* $NetBSD: vfontedpr.c,v 1.4 1996/03/21 18:08:30 jtc Exp $ */ /* * Copyright (c) 1980, 1993 @@ -43,7 +43,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)vfontedpr.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$NetBSD: vfontedpr.c,v 1.3 1994/11/17 08:28:03 jtc Exp $"; +static char rcsid[] = "$NetBSD: vfontedpr.c,v 1.4 1996/03/21 18:08:30 jtc Exp $"; #endif /* not lint */ #include @@ -130,7 +130,7 @@ char *language = "c"; /* the language indicator */ #define ps(x) printf("%s", x) -void +int main(argc, argv) int argc; char *argv[]; diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 11d06254ec3..9d388064806 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -1,5 +1,5 @@ -/* $NetBSD: vmstat.c,v 1.27 1995/10/10 01:17:35 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.8 1996/04/18 12:00:05 mickey Exp $ */ +/* $OpenBSD: vmstat.c,v 1.9 1996/04/21 23:44:44 deraadt Exp $ */ +/* $NetBSD: vmstat.c,v 1.28 1996/04/04 00:27:50 cgd Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$NetBSD: vmstat.c,v 1.27 1995/10/10 01:17:35 cgd Exp $"; +static char rcsid[] = "$NetBSD: vmstat.c,v 1.28 1996/04/04 00:27:50 cgd Exp $"; #endif #endif /* not lint */ @@ -770,7 +770,8 @@ dointr() register long *intrcnt, inttotal, uptime; register int nintr, inamlen; register char *intrname; - struct evcnt evcnt, *allevents; + struct evcntlist allevents; + struct evcnt evcnt, *evptr; struct device dev; uptime = getuptime(); @@ -796,8 +797,9 @@ dointr() inttotal += *intrcnt++; } kread(X_ALLEVENTS, &allevents, sizeof allevents); - while (allevents) { - if (kvm_read(kd, (long)allevents, (void *)&evcnt, + evptr = allevents.tqh_first; + while (evptr) { + if (kvm_read(kd, (long)evptr, (void *)&evcnt, sizeof evcnt) != sizeof evcnt) { (void)fprintf(stderr, "vmstat: event chain trashed\n", kvm_geterr(kd)); @@ -815,7 +817,7 @@ dointr() evcnt.ev_count, evcnt.ev_count / uptime); inttotal += evcnt.ev_count++; } - allevents = evcnt.ev_next; + evptr = evcnt.ev_list.tqe_next; } (void)printf("Total %8ld %8ld\n", inttotal, inttotal / uptime); } diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index 25d3cdbcb30..1eee27dde0b 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -222,7 +222,7 @@ main(argc, argv) (void)printf(HEADER); if ((kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nentries)) == NULL) - err(1, "%s", kvm_geterr(kd)); + errx(1, "%s", kvm_geterr(kd)); for (i = 0; i < nentries; i++, kp++) { struct proc *p = &kp->kp_proc; struct eproc *e; diff --git a/usr.bin/xlint/lint1/param.h b/usr.bin/xlint/lint1/param.h index 3ff1c1e1539..46ae4b74322 100644 --- a/usr.bin/xlint/lint1/param.h +++ b/usr.bin/xlint/lint1/param.h @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.5 1995/12/17 02:53:11 jonathan Exp $ */ +/* $NetBSD: param.h,v 1.6 1996/04/01 21:47:57 mark Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -81,6 +81,9 @@ #elif __vax__ #define PTRDIFF_IS_LONG 0 #define SIZEOF_IS_ULONG 0 +#elif __arm32__ +#define PTRDIFF_IS_LONG 0 +#define SIZEOF_IS_ULONG 0 #else #error unknown machine type #endif diff --git a/usr.bin/yacc/Makefile b/usr.bin/yacc/Makefile index e87e84ce30f..07e3da18cd5 100644 --- a/usr.bin/yacc/Makefile +++ b/usr.bin/yacc/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $ +# $OpenBSD: Makefile,v 1.2 1996/04/21 23:45:02 deraadt Exp $ PROG= yacc SRCS= closure.c error.c lalr.c lr0.c main.c mkpar.c output.c reader.c \ diff --git a/usr.bin/yacc/closure.c b/usr.bin/yacc/closure.c index 6b39eeda07e..303bfbaf0c4 100644 --- a/usr.bin/yacc/closure.c +++ b/usr.bin/yacc/closure.c @@ -1,5 +1,47 @@ +/* $NetBSD: closure.c,v 1.4 1996/03/19 03:21:29 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: closure.c,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)closure.c 5.3 (Berkeley) 5/24/93"; +#else +static char rcsid[] = "$NetBSD: closure.c,v 1.4 1996/03/19 03:21:29 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h index 57e2e28151c..00116e1ea42 100644 --- a/usr.bin/yacc/defs.h +++ b/usr.bin/yacc/defs.h @@ -1,4 +1,43 @@ -/* $OpenBSD: defs.h,v 1.4 1996/03/31 04:56:00 etheisen Exp $ */ +/* $OpenBSD: defs.h,v 1.5 1996/04/21 23:45:06 deraadt Exp $ */ +/* $NetBSD: defs.h,v 1.6 1996/03/19 03:21:30 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + * + * @(#)defs.h 5.6 (Berkeley) 5/24/93 + */ #include #include diff --git a/usr.bin/yacc/error.c b/usr.bin/yacc/error.c index 2858605052b..9b33f451c72 100644 --- a/usr.bin/yacc/error.c +++ b/usr.bin/yacc/error.c @@ -1,9 +1,51 @@ -/* routines for printing error messages */ +/* $NetBSD: error.c,v 1.4 1996/03/19 03:21:32 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ #ifndef lint -static char rcsid[] = "$Id: error.c,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 6/1/90"; +#else +static char rcsid[] = "$NetBSD: error.c,v 1.4 1996/03/19 03:21:32 jtc Exp $"; +#endif #endif /* not lint */ +/* routines for printing error messages */ + #include "defs.h" diff --git a/usr.bin/yacc/lalr.c b/usr.bin/yacc/lalr.c index 3391cba59ab..bf28f5510ab 100644 --- a/usr.bin/yacc/lalr.c +++ b/usr.bin/yacc/lalr.c @@ -1,5 +1,47 @@ +/* $NetBSD: lalr.c,v 1.4 1996/03/19 03:21:33 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: lalr.c,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)lalr.c 5.3 (Berkeley) 6/1/90"; +#else +static char rcsid[] = "$NetBSD: lalr.c,v 1.4 1996/03/19 03:21:33 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.bin/yacc/lr0.c b/usr.bin/yacc/lr0.c index ac3c745fb36..678f3579b36 100644 --- a/usr.bin/yacc/lr0.c +++ b/usr.bin/yacc/lr0.c @@ -1,5 +1,47 @@ +/* $NetBSD: lr0.c,v 1.4 1996/03/19 03:21:35 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: lr0.c,v 1.1.1.1 1995/10/18 08:47:05 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)lr0.c 5.3 (Berkeley) 1/20/91"; +#else +static char rcsid[] = "$NetBSD: lr0.c,v 1.4 1996/03/19 03:21:35 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.bin/yacc/main.c b/usr.bin/yacc/main.c index 82b6d409c80..e225915c2a8 100644 --- a/usr.bin/yacc/main.c +++ b/usr.bin/yacc/main.c @@ -1,5 +1,53 @@ +/* $NetBSD: main.c,v 1.5 1996/03/19 03:21:38 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: main.c,v 1.2 1995/12/22 00:57:08 niklas Exp $"; +char copyright[] = +"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ + All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93"; +#else +static char rcsid[] = "$NetBSD: main.c,v 1.5 1996/03/19 03:21:38 jtc Exp $"; +#endif #endif /* not lint */ #include @@ -78,7 +126,8 @@ int k; void -onintr() +onintr(signo) + int signo; { done(1); } diff --git a/usr.bin/yacc/mkpar.c b/usr.bin/yacc/mkpar.c index 34df17afc77..d044a0adb80 100644 --- a/usr.bin/yacc/mkpar.c +++ b/usr.bin/yacc/mkpar.c @@ -1,7 +1,49 @@ -/* $OpenBSD: mkpar.c,v 1.3 1996/03/31 04:56:02 etheisen Exp $ */ +/* $OpenBSD: mkpar.c,v 1.4 1996/04/21 23:45:15 deraadt Exp $ */ + +/* $NetBSD: mkpar.c,v 1.4 1996/03/19 03:21:39 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ #ifndef lint -static char rcsid[] = "$Id: mkpar.c,v 1.3 1996/03/31 04:56:02 etheisen Exp $"; +#if 0 +static char sccsid[] = "@(#)mkpar.c 5.3 (Berkeley) 1/20/91"; +#else +static char rcsid[] = "$NetBSD: mkpar.c,v 1.4 1996/03/19 03:21:39 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" @@ -360,4 +402,3 @@ free_parser() FREE(parser); } - diff --git a/usr.bin/yacc/output.c b/usr.bin/yacc/output.c index 9996fd75867..63844fcfdbd 100644 --- a/usr.bin/yacc/output.c +++ b/usr.bin/yacc/output.c @@ -1,5 +1,47 @@ +/* $NetBSD: output.c,v 1.4 1996/03/19 03:21:41 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: output.c,v 1.1.1.1 1995/10/18 08:47:06 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)output.c 5.7 (Berkeley) 5/24/93"; +#else +static char rcsid[] = "$NetBSD: output.c,v 1.4 1996/03/19 03:21:41 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.bin/yacc/reader.c b/usr.bin/yacc/reader.c index f0504e32239..84e8fe6fce1 100644 --- a/usr.bin/yacc/reader.c +++ b/usr.bin/yacc/reader.c @@ -1,7 +1,49 @@ -/* $OpenBSD: reader.c,v 1.4 1996/03/31 04:56:01 etheisen Exp $ */ +/* $OpenBSD: reader.c,v 1.5 1996/04/21 23:45:19 deraadt Exp $ */ + +/* $NetBSD: reader.c,v 1.5 1996/03/19 03:21:43 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ #ifndef lint -static char rcsid[] = "$Id: reader.c,v 1.4 1996/03/31 04:56:01 etheisen Exp $"; +#if 0 +static char sccsid[] = "@(#)reader.c 5.7 (Berkeley) 1/20/91"; +#else +static char rcsid[] = "$NetBSD: reader.c,v 1.5 1996/03/19 03:21:43 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.bin/yacc/skeleton.c b/usr.bin/yacc/skeleton.c index 7fa773f16a1..de78f96b6c5 100644 --- a/usr.bin/yacc/skeleton.c +++ b/usr.bin/yacc/skeleton.c @@ -1,4 +1,49 @@ -/* $OpenBSD: skeleton.c,v 1.3 1996/03/27 19:33:21 niklas Exp $ */ +/* $OpenBSD: skeleton.c,v 1.4 1996/04/21 23:45:21 deraadt Exp $ */ +/* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95"; +#else +static char rcsid[] = "$NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $"; +#endif +#endif /* not lint */ #include "defs.h" @@ -18,8 +63,9 @@ char *banner[] = { "#ifndef lint", "/*static char yysccsid[] = \"from: @(#)yaccpar 1.9 (Berkeley) 02/21/93\";*/", - "static char yyrcsid[] = \"$OpenBSD: skeleton.c,v 1.3 1996/03/27 19:33:21 niklas Exp $\";", + "static char yyrcsid[] = \"$OpenBSD: skeleton.c,v 1.4 1996/04/21 23:45:21 deraadt Exp $\";", "#endif", + "#include ", "#define YYBYACC 1", "#define YYMAJOR 1", "#define YYMINOR 9", @@ -60,10 +106,11 @@ char *header[] = "#ifdef YYMAXDEPTH", "#define YYSTACKSIZE YYMAXDEPTH", "#else", - "#define YYSTACKSIZE 500", - "#define YYMAXDEPTH 500", + "#define YYSTACKSIZE 10000", + "#define YYMAXDEPTH 10000", "#endif", "#endif", + "#define YYINITSTACKSIZE 200", "int yydebug;", "int yynerrs;", "int yyerrflag;", @@ -72,30 +119,53 @@ char *header[] = "YYSTYPE *yyvsp;", "YYSTYPE yyval;", "YYSTYPE yylval;", - "short yyss[YYSTACKSIZE];", - "YYSTYPE yyvs[YYSTACKSIZE];", - "#define yystacksize YYSTACKSIZE", + "short *yyss;", + "short *yysslim;", + "YYSTYPE *yyvs;", + "int yystacksize;", 0 }; char *body[] = { + "/* allocate initial stack or double stack size, up to YYMAXDEPTH */", + "static int yygrowstack()", + "{", + " int newsize, i;", + " short *newss;", + " YYSTYPE *newvs;", + "", + " if ((newsize = yystacksize) == 0)", + " newsize = YYINITSTACKSIZE;", + " else if (newsize >= YYMAXDEPTH)", + " return -1;", + " else if ((newsize *= 2) > YYMAXDEPTH)", + " newsize = YYMAXDEPTH;", + " i = yyssp - yyss;", + " if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)", + " return -1;", + " yyss = newss;", + " yyssp = newss + i;", + " if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)", + " return -1;", + " yyvs = newvs;", + " yyvsp = newvs + i;", + " yystacksize = newsize;", + " yysslim = yyss + newsize - 1;", + " return 0;", + "}", + "", "#define YYABORT goto yyabort", "#define YYREJECT goto yyabort", "#define YYACCEPT goto yyaccept", "#define YYERROR goto yyerrlab", "int", - "#if defined(__STDC__)", - "yyparse(void)", - "#else", "yyparse()", - "#endif", "{", " register int yym, yyn, yystate;", "#if YYDEBUG", " register char *yys;", - " extern char *getenv();", "", " if (yys = getenv(\"YYDEBUG\"))", " {", @@ -109,6 +179,7 @@ char *body[] = " yyerrflag = 0;", " yychar = (-1);", "", + " if (yyss == NULL && yygrowstack()) goto yyoverflow;", " yyssp = yyss;", " yyvsp = yyvs;", " *yyssp = yystate = 0;", @@ -137,7 +208,7 @@ char *body[] = " printf(\"%sdebug: state %d, shifting to state %d\\n\",", " YYPREFIX, yystate, yytable[yyn]);", "#endif", - " if (yyssp >= yyss + yystacksize - 1)", + " if (yyssp >= yysslim && yygrowstack())", " {", " goto yyoverflow;", " }", @@ -154,6 +225,10 @@ char *body[] = " goto yyreduce;", " }", " if (yyerrflag) goto yyinrecovery;", + "#ifdef lint", + " goto yynewerror;", + "#endif", + "yynewerror:", " yyerror(\"syntax error\");", "#ifdef lint", " goto yyerrlab;", @@ -174,7 +249,7 @@ char *body[] = " printf(\"%sdebug: state %d, error recovery shifting\\", " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);", "#endif", - " if (yyssp >= yyss + yystacksize - 1)", + " if (yyssp >= yysslim && yygrowstack())", " {", " goto yyoverflow;", " }", @@ -271,7 +346,7 @@ char *trailer[] = " printf(\"%sdebug: after reduction, shifting from state %d \\", "to state %d\\n\", YYPREFIX, *yyssp, yystate);", "#endif", - " if (yyssp >= yyss + yystacksize - 1)", + " if (yyssp >= yysslim && yygrowstack())", " {", " goto yyoverflow;", " }", diff --git a/usr.bin/yacc/symtab.c b/usr.bin/yacc/symtab.c index abf71249695..64677bd7651 100644 --- a/usr.bin/yacc/symtab.c +++ b/usr.bin/yacc/symtab.c @@ -1,5 +1,47 @@ +/* $NetBSD: symtab.c,v 1.4 1996/03/19 03:21:48 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: symtab.c,v 1.1.1.1 1995/10/18 08:47:06 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)symtab.c 5.3 (Berkeley) 6/1/90"; +#else +static char rcsid[] = "$NetBSD: symtab.c,v 1.4 1996/03/19 03:21:48 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.bin/yacc/test/error.tab.c b/usr.bin/yacc/test/error.tab.c index bced9f28a36..b16d6ddc8d8 100644 --- a/usr.bin/yacc/test/error.tab.c +++ b/usr.bin/yacc/test/error.tab.c @@ -1,11 +1,14 @@ #ifndef lint /*static char yysccsid[] = "from: @(#)yaccpar 1.9 (Berkeley) 02/21/93";*/ -static char rcsid[] = "$Id: error.tab.c,v 1.1.1.1 1995/10/18 08:47:06 deraadt Exp $"; +static char yyrcsid[] = "$OpenBSD: error.tab.c,v 1.2 1996/04/21 23:45:31 deraadt Exp $"; #endif +#include #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 -#define yyclearin (yychar=(-1)) +#define YYLEX yylex() +#define YYEMPTY -1 +#define yyclearin (yychar=(YYEMPTY)) #define yyerrok (yyerrflag=0) #define YYRECOVERING (yyerrflag!=0) #define YYPREFIX "yy" @@ -58,10 +61,11 @@ typedef int YYSTYPE; #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else -#define YYSTACKSIZE 500 -#define YYMAXDEPTH 500 +#define YYSTACKSIZE 10000 +#define YYMAXDEPTH 10000 #endif #endif +#define YYINITSTACKSIZE 200 int yydebug; int yynerrs; int yyerrflag; @@ -70,14 +74,42 @@ short *yyssp; YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; -short yyss[YYSTACKSIZE]; -YYSTYPE yyvs[YYSTACKSIZE]; -#define yystacksize YYSTACKSIZE +short *yyss; +short *yysslim; +YYSTYPE *yyvs; +int yystacksize; #line 4 "error.y" main(){printf("yyparse() = %d\n",yyparse());} yylex(){return-1;} yyerror(s)char*s;{printf("%s\n",s);} -#line 80 "error.tab.c" +#line 86 "error.tab.c" +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack() +{ + int newsize, i; + short *newss; + YYSTYPE *newvs; + + if ((newsize = yystacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + i = yyssp - yyss; + if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL) + return -1; + yyss = newss; + yyssp = newss + i; + if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL) + return -1; + yyvs = newvs; + yyvsp = newvs + i; + yystacksize = newsize; + yysslim = yyss + newsize - 1; + return 0; +} + #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept @@ -88,7 +120,6 @@ yyparse() register int yym, yyn, yystate; #if YYDEBUG register char *yys; - extern char *getenv(); if (yys = getenv("YYDEBUG")) { @@ -102,12 +133,13 @@ yyparse() yyerrflag = 0; yychar = (-1); + if (yyss == NULL && yygrowstack()) goto yyoverflow; yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0; yyloop: - if (yyn = yydefred[yystate]) goto yyreduce; + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; @@ -130,7 +162,7 @@ yyloop: printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]); #endif - if (yyssp >= yyss + yystacksize - 1) + if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } @@ -171,7 +203,7 @@ yyinrecovery: printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); #endif - if (yyssp >= yyss + yystacksize - 1) + if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } @@ -260,7 +292,7 @@ yyreduce: printf("%sdebug: after reduction, shifting from state %d \ to state %d\n", YYPREFIX, *yyssp, yystate); #endif - if (yyssp >= yyss + yystacksize - 1) + if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } diff --git a/usr.bin/yacc/test/ftp.tab.c b/usr.bin/yacc/test/ftp.tab.c index 307dfd4b086..177b1f9ea5b 100644 --- a/usr.bin/yacc/test/ftp.tab.c +++ b/usr.bin/yacc/test/ftp.tab.c @@ -1,18 +1,22 @@ #ifndef lint /*static char yysccsid[] = "from: @(#)yaccpar 1.9 (Berkeley) 02/21/93";*/ -static char rcsid[] = "$Id: ftp.tab.c,v 1.1.1.1 1995/10/18 08:47:07 deraadt Exp $"; +static char yyrcsid[] = "$OpenBSD: ftp.tab.c,v 1.2 1996/04/21 23:45:32 deraadt Exp $"; #endif +#include #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 -#define yyclearin (yychar=(-1)) +#define YYLEX yylex() +#define YYEMPTY -1 +#define yyclearin (yychar=(YYEMPTY)) #define yyerrok (yyerrflag=0) #define YYRECOVERING (yyerrflag!=0) #define YYPREFIX "yy" -#line 26 "ftp.y" +#line 28 "ftp.y" #ifndef lint -static char sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; +/*static char sccsid[] = "from: @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89";*/ +static char rcsid[] = "$Id: ftp.tab.c,v 1.2 1996/04/21 23:45:32 deraadt Exp $"; #endif /* not lint */ #include @@ -57,7 +61,7 @@ char cbuf[512]; char *fromname; char *index(); -#line 60 "ftp.tab.c" +#line 65 "ftp.tab.c" #define A 257 #define B 258 #define C 259 @@ -366,10 +370,11 @@ typedef int YYSTYPE; #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else -#define YYSTACKSIZE 500 -#define YYMAXDEPTH 500 +#define YYSTACKSIZE 10000 +#define YYMAXDEPTH 10000 #endif #endif +#define YYINITSTACKSIZE 200 int yydebug; int yynerrs; int yyerrflag; @@ -378,10 +383,11 @@ short *yyssp; YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; -short yyss[YYSTACKSIZE]; -YYSTYPE yyvs[YYSTACKSIZE]; -#define yystacksize YYSTACKSIZE -#line 658 "ftp.y" +short *yyss; +short *yysslim; +YYSTYPE *yyvs; +int yystacksize; +#line 662 "ftp.y" extern jmp_buf errcatch; @@ -905,7 +911,34 @@ char *filename; reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); } } -#line 908 "ftp.tab.c" +#line 915 "ftp.tab.c" +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack() +{ + int newsize, i; + short *newss; + YYSTYPE *newvs; + + if ((newsize = yystacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; + i = yyssp - yyss; + if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL) + return -1; + yyss = newss; + yyssp = newss + i; + if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL) + return -1; + yyvs = newvs; + yyvsp = newvs + i; + yystacksize = newsize; + yysslim = yyss + newsize - 1; + return 0; +} + #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept @@ -916,7 +949,6 @@ yyparse() register int yym, yyn, yystate; #if YYDEBUG register char *yys; - extern char *getenv(); if (yys = getenv("YYDEBUG")) { @@ -930,12 +962,13 @@ yyparse() yyerrflag = 0; yychar = (-1); + if (yyss == NULL && yygrowstack()) goto yyoverflow; yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0; yyloop: - if (yyn = yydefred[yystate]) goto yyreduce; + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; @@ -958,7 +991,7 @@ yyloop: printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]); #endif - if (yyssp >= yyss + yystacksize - 1) + if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } @@ -999,7 +1032,7 @@ yyinrecovery: printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); #endif - if (yyssp >= yyss + yystacksize - 1) + if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } @@ -1047,27 +1080,27 @@ yyreduce: switch (yyn) { case 2: -#line 99 "ftp.y" +#line 102 "ftp.y" { fromname = (char *) 0; } break; case 4: -#line 106 "ftp.y" +#line 109 "ftp.y" { user((char *) yyvsp[-1]); free((char *) yyvsp[-1]); } break; case 5: -#line 111 "ftp.y" +#line 114 "ftp.y" { pass((char *) yyvsp[-1]); free((char *) yyvsp[-1]); } break; case 6: -#line 116 "ftp.y" +#line 119 "ftp.y" { usedefault = 0; if (pdata >= 0) { @@ -1078,13 +1111,13 @@ case 6: } break; case 7: -#line 125 "ftp.y" +#line 128 "ftp.y" { passive(); } break; case 8: -#line 129 "ftp.y" +#line 132 "ftp.y" { switch (cmd_type) { @@ -1121,7 +1154,7 @@ case 8: } break; case 9: -#line 164 "ftp.y" +#line 167 "ftp.y" { switch (yyvsp[-1]) { @@ -1135,7 +1168,7 @@ case 9: } break; case 10: -#line 176 "ftp.y" +#line 179 "ftp.y" { switch (yyvsp[-1]) { @@ -1149,19 +1182,19 @@ case 10: } break; case 11: -#line 188 "ftp.y" +#line 191 "ftp.y" { reply(202, "ALLO command ignored."); } break; case 12: -#line 192 "ftp.y" +#line 195 "ftp.y" { reply(202, "ALLO command ignored."); } break; case 13: -#line 196 "ftp.y" +#line 199 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) retrieve((char *) 0, (char *) yyvsp[-1]); @@ -1170,7 +1203,7 @@ case 13: } break; case 14: -#line 203 "ftp.y" +#line 206 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) store((char *) yyvsp[-1], "w", 0); @@ -1179,7 +1212,7 @@ case 14: } break; case 15: -#line 210 "ftp.y" +#line 213 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) store((char *) yyvsp[-1], "a", 0); @@ -1188,14 +1221,14 @@ case 15: } break; case 16: -#line 217 "ftp.y" +#line 220 "ftp.y" { if (yyvsp[-1]) send_file_list("."); } break; case 17: -#line 222 "ftp.y" +#line 225 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) send_file_list((char *) yyvsp[-1]); @@ -1204,14 +1237,14 @@ case 17: } break; case 18: -#line 229 "ftp.y" +#line 232 "ftp.y" { if (yyvsp[-1]) retrieve("/bin/ls -lgA", ""); } break; case 19: -#line 234 "ftp.y" +#line 237 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) retrieve("/bin/ls -lgA %s", (char *) yyvsp[-1]); @@ -1220,7 +1253,7 @@ case 19: } break; case 20: -#line 241 "ftp.y" +#line 244 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) statfilecmd((char *) yyvsp[-1]); @@ -1229,13 +1262,13 @@ case 20: } break; case 21: -#line 248 "ftp.y" +#line 251 "ftp.y" { statcmd(); } break; case 22: -#line 252 "ftp.y" +#line 255 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) delete((char *) yyvsp[-1]); @@ -1244,7 +1277,7 @@ case 22: } break; case 23: -#line 259 "ftp.y" +#line 262 "ftp.y" { if (fromname) { renamecmd(fromname, (char *) yyvsp[-1]); @@ -1257,20 +1290,20 @@ case 23: } break; case 24: -#line 270 "ftp.y" +#line 273 "ftp.y" { reply(225, "ABOR command successful."); } break; case 25: -#line 274 "ftp.y" +#line 277 "ftp.y" { if (yyvsp[-1]) cwd(pw->pw_dir); } break; case 26: -#line 279 "ftp.y" +#line 282 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) cwd((char *) yyvsp[-1]); @@ -1279,13 +1312,13 @@ case 26: } break; case 27: -#line 286 "ftp.y" +#line 289 "ftp.y" { help(cmdtab, (char *) 0); } break; case 28: -#line 290 "ftp.y" +#line 293 "ftp.y" { register char *cp = (char *)yyvsp[-1]; @@ -1302,13 +1335,13 @@ case 28: } break; case 29: -#line 305 "ftp.y" +#line 308 "ftp.y" { reply(200, "NOOP command successful."); } break; case 30: -#line 309 "ftp.y" +#line 312 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) makedir((char *) yyvsp[-1]); @@ -1317,7 +1350,7 @@ case 30: } break; case 31: -#line 316 "ftp.y" +#line 319 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) removedir((char *) yyvsp[-1]); @@ -1326,33 +1359,33 @@ case 31: } break; case 32: -#line 323 "ftp.y" +#line 326 "ftp.y" { if (yyvsp[-1]) pwd(); } break; case 33: -#line 328 "ftp.y" +#line 331 "ftp.y" { if (yyvsp[-1]) cwd(".."); } break; case 34: -#line 333 "ftp.y" +#line 336 "ftp.y" { help(sitetab, (char *) 0); } break; case 35: -#line 337 "ftp.y" +#line 340 "ftp.y" { help(sitetab, (char *) yyvsp[-1]); } break; case 36: -#line 341 "ftp.y" +#line 344 "ftp.y" { int oldmask; @@ -1364,7 +1397,7 @@ case 36: } break; case 37: -#line 351 "ftp.y" +#line 354 "ftp.y" { int oldmask; @@ -1381,7 +1414,7 @@ case 37: } break; case 38: -#line 366 "ftp.y" +#line 369 "ftp.y" { if (yyvsp[-5] && (yyvsp[-1] != NULL)) { if (yyvsp[-3] > 0777) @@ -1397,7 +1430,7 @@ case 38: } break; case 39: -#line 380 "ftp.y" +#line 383 "ftp.y" { reply(200, "Current IDLE time limit is %d seconds; max %d", @@ -1405,7 +1438,7 @@ case 39: } break; case 40: -#line 386 "ftp.y" +#line 389 "ftp.y" { if (yyvsp[-1] < 30 || yyvsp[-1] > maxtimeout) { reply(501, @@ -1421,7 +1454,7 @@ case 40: } break; case 41: -#line 400 "ftp.y" +#line 403 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) store((char *) yyvsp[-1], "w", 1); @@ -1430,7 +1463,7 @@ case 41: } break; case 42: -#line 407 "ftp.y" +#line 410 "ftp.y" { #ifdef unix #ifdef BSD @@ -1445,7 +1478,7 @@ case 42: } break; case 43: -#line 428 "ftp.y" +#line 431 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) sizecmd((char *) yyvsp[-1]); @@ -1454,7 +1487,7 @@ case 43: } break; case 44: -#line 445 "ftp.y" +#line 448 "ftp.y" { if (yyvsp[-3] && yyvsp[-1] != NULL) { struct stat stbuf; @@ -1468,8 +1501,9 @@ case 44: struct tm *gmtime(); t = gmtime(&stbuf.st_mtime); reply(213, - "19%02d%02d%02d%02d%02d%02d", - t->tm_year, t->tm_mon+1, t->tm_mday, + "%04d%02d%02d%02d%02d%02d", + 1900 + t->tm_year, + t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } } @@ -1478,20 +1512,20 @@ case 44: } break; case 45: -#line 467 "ftp.y" +#line 471 "ftp.y" { reply(221, "Goodbye."); dologout(0); } break; case 46: -#line 472 "ftp.y" +#line 476 "ftp.y" { yyerrok; } break; case 47: -#line 477 "ftp.y" +#line 481 "ftp.y" { char *renamefrom(); @@ -1504,13 +1538,13 @@ case 47: } break; case 49: -#line 493 "ftp.y" +#line 497 "ftp.y" { *(char **)&(yyval) = ""; } break; case 52: -#line 504 "ftp.y" +#line 508 "ftp.y" { register char *a, *p; @@ -1522,116 +1556,116 @@ case 52: } break; case 53: -#line 516 "ftp.y" +#line 520 "ftp.y" { yyval = FORM_N; } break; case 54: -#line 520 "ftp.y" +#line 524 "ftp.y" { yyval = FORM_T; } break; case 55: -#line 524 "ftp.y" +#line 528 "ftp.y" { yyval = FORM_C; } break; case 56: -#line 530 "ftp.y" +#line 534 "ftp.y" { cmd_type = TYPE_A; cmd_form = FORM_N; } break; case 57: -#line 535 "ftp.y" +#line 539 "ftp.y" { cmd_type = TYPE_A; cmd_form = yyvsp[0]; } break; case 58: -#line 540 "ftp.y" +#line 544 "ftp.y" { cmd_type = TYPE_E; cmd_form = FORM_N; } break; case 59: -#line 545 "ftp.y" +#line 549 "ftp.y" { cmd_type = TYPE_E; cmd_form = yyvsp[0]; } break; case 60: -#line 550 "ftp.y" +#line 554 "ftp.y" { cmd_type = TYPE_I; } break; case 61: -#line 554 "ftp.y" +#line 558 "ftp.y" { cmd_type = TYPE_L; cmd_bytesz = NBBY; } break; case 62: -#line 559 "ftp.y" +#line 563 "ftp.y" { cmd_type = TYPE_L; cmd_bytesz = yyvsp[0]; } break; case 63: -#line 565 "ftp.y" +#line 569 "ftp.y" { cmd_type = TYPE_L; cmd_bytesz = yyvsp[0]; } break; case 64: -#line 572 "ftp.y" +#line 576 "ftp.y" { yyval = STRU_F; } break; case 65: -#line 576 "ftp.y" +#line 580 "ftp.y" { yyval = STRU_R; } break; case 66: -#line 580 "ftp.y" +#line 584 "ftp.y" { yyval = STRU_P; } break; case 67: -#line 586 "ftp.y" +#line 590 "ftp.y" { yyval = MODE_S; } break; case 68: -#line 590 "ftp.y" +#line 594 "ftp.y" { yyval = MODE_B; } break; case 69: -#line 594 "ftp.y" +#line 598 "ftp.y" { yyval = MODE_C; } break; case 70: -#line 600 "ftp.y" +#line 604 "ftp.y" { /* * Problem: this production is used for all pathname @@ -1650,7 +1684,7 @@ case 70: } break; case 72: -#line 622 "ftp.y" +#line 626 "ftp.y" { register int ret, dec, multby, digit; @@ -1675,7 +1709,7 @@ case 72: } break; case 73: -#line 647 "ftp.y" +#line 651 "ftp.y" { if (logged_in) yyval = 1; @@ -1685,7 +1719,7 @@ case 73: } } break; -#line 1688 "ftp.tab.c" +#line 1723 "ftp.tab.c" } yyssp -= yym; yystate = *yyssp; @@ -1728,7 +1762,7 @@ break; printf("%sdebug: after reduction, shifting from state %d \ to state %d\n", YYPREFIX, *yyssp, yystate); #endif - if (yyssp >= yyss + yystacksize - 1) + if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } diff --git a/usr.bin/yacc/test/ftp.y b/usr.bin/yacc/test/ftp.y index ad27211635b..0067c4bc86a 100644 --- a/usr.bin/yacc/test/ftp.y +++ b/usr.bin/yacc/test/ftp.y @@ -1,3 +1,5 @@ +/* $OpenBSD: ftp.y,v 1.2 1996/04/21 23:45:35 deraadt Exp $ */ + /* * Copyright (c) 1985, 1988 Regents of the University of California. * All rights reserved. @@ -15,7 +17,6 @@ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * from: @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89 - * $Id: ftp.y,v 1.1.1.1 1995/10/18 08:47:07 deraadt Exp $ */ /* @@ -27,7 +28,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89";*/ -static char rcsid[] = "$Id: ftp.y,v 1.1.1.1 1995/10/18 08:47:07 deraadt Exp $"; +static char rcsid[] = "$Id: ftp.y,v 1.2 1996/04/21 23:45:35 deraadt Exp $"; #endif /* not lint */ #include @@ -457,8 +458,9 @@ cmd: USER SP username CRLF struct tm *gmtime(); t = gmtime(&stbuf.st_mtime); reply(213, - "19%02d%02d%02d%02d%02d%02d", - t->tm_year, t->tm_mon+1, t->tm_mday, + "%04d%02d%02d%02d%02d%02d", + 1900 + t->tm_year, + t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } } diff --git a/usr.bin/yacc/verbose.c b/usr.bin/yacc/verbose.c index d3c7f500ec5..41481d8959f 100644 --- a/usr.bin/yacc/verbose.c +++ b/usr.bin/yacc/verbose.c @@ -1,10 +1,51 @@ +/* $NetBSD: verbose.c,v 1.4 1996/03/19 03:21:50 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: verbose.c,v 1.1.1.1 1995/10/18 08:47:06 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)verbose.c 5.3 (Berkeley) 1/20/91"; +#else +static char rcsid[] = "$NetBSD: verbose.c,v 1.4 1996/03/19 03:21:50 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" - static short *null_rules; verbose() @@ -329,4 +370,3 @@ int stateno; fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k); } } - diff --git a/usr.bin/yacc/warshall.c b/usr.bin/yacc/warshall.c index b7ede40e8fd..03567fa88e0 100644 --- a/usr.bin/yacc/warshall.c +++ b/usr.bin/yacc/warshall.c @@ -1,5 +1,47 @@ +/* $NetBSD: warshall.c,v 1.4 1996/03/19 03:21:51 jtc Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Paul Corbett. + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. 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. + */ + #ifndef lint -static char rcsid[] = "$Id: warshall.c,v 1.1.1.1 1995/10/18 08:47:06 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)warshall.c 5.4 (Berkeley) 5/24/93"; +#else +static char rcsid[] = "$NetBSD: warshall.c,v 1.4 1996/03/19 03:21:51 jtc Exp $"; +#endif #endif /* not lint */ #include "defs.h" diff --git a/usr.sbin/bootpd/bootpd.c b/usr.sbin/bootpd/bootpd.c index 483a6a1b067..f31d26874db 100644 --- a/usr.sbin/bootpd/bootpd.c +++ b/usr.sbin/bootpd/bootpd.c @@ -21,7 +21,7 @@ SOFTWARE. ************************************************************************/ #ifndef lint -static char rcsid[] = "$Id: bootpd.c,v 1.1.1.1 1995/10/18 08:47:25 deraadt Exp $"; +static char rcsid[] = "$Id: bootpd.c,v 1.2 1996/04/21 23:39:59 deraadt Exp $"; #endif /* @@ -185,7 +185,7 @@ char *bootpd_dump = DUMPTAB_FILE; * main server loop is started. */ -void +int main(argc, argv) int argc; char **argv; diff --git a/usr.sbin/config/config.8 b/usr.sbin/config/config.8 index b93276db33d..e8c8bac7e0b 100644 --- a/usr.sbin/config/config.8 +++ b/usr.sbin/config/config.8 @@ -1,5 +1,5 @@ -.\" $OpenBSD: config.8,v 1.2 1996/03/25 15:55:01 niklas Exp $ -.\" $NetBSD: config.8,v 1.8 1996/03/03 17:28:05 thorpej Exp $ +.\" $OpenBSD: config.8,v 1.3 1996/04/21 23:40:05 deraadt Exp $ +.\" $NetBSD: config.8,v 1.9 1996/03/17 06:29:19 cgd Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -53,7 +53,7 @@ program. .\"used on the SPARC and i386 platforms. .\"The old version of config is still used with the .\"HP300, DECstation, and derivative platforms. -.\"Only the version of +.\"Only the version of .\".Nm config .\"applicable to the architecture that you are running .\"will be installed on your machine. diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 116503b51a8..178c6923741 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -1,5 +1,5 @@ -/* $OpenBSD: config.h,v 1.2 1996/03/25 15:55:02 niklas Exp $ */ -/* $NetBSD: config.h,v 1.19 1996/03/03 17:28:08 thorpej Exp $ */ +/* $OpenBSD: config.h,v 1.3 1996/04/21 23:40:07 deraadt Exp $ */ +/* $NetBSD: config.h,v 1.23 1996/03/17 13:18:15 cgd Exp $ */ /* * Copyright (c) 1992, 1993 @@ -94,19 +94,27 @@ struct attr { }; /* - * The "base" part of a device ("uba", "sd"; but not "uba2" or - * "sd0"). It may be found "at" one or more attributes, including - * "at root" (this is represented by a NULL attribute). + * The "base" part (struct devbase) of a device ("uba", "sd"; but not + * "uba2" or "sd0"). It may be found "at" one or more attributes, + * including "at root" (this is represented by a NULL attribute), as + * specified by the device attachments (struct deva). * * Each device may also export attributes. If any provide an output * interface (e.g., "esp" provides "scsi"), other devices (e.g., * "tg"s) can be found at instances of this one (e.g., "esp"s). * Such a connection must provide locators as specified by that - * interface attribute (e.g., "target"). + * interface attribute (e.g., "target"). The base device can + * export both output (aka `interface') attributes, as well as + * import input (`plain') attributes. Device attachments may + * only import input attributes; it makes no sense to have a + * specific attachment export a new interface to other devices. * * Each base carries a list of instances (via d_ihead). Note that this * list "skips over" aliases; those must be found through the instances - * themselves. + * themselves. Each base also carries a list of possible attachments, + * each of which specify a set of devices that the device can attach + * to, as well as the device instances that are actually using that + * attachment. */ struct devbase { const char *d_name; /* e.g., "sd" */ @@ -114,12 +122,25 @@ struct devbase { int d_isdef; /* set once properly defined */ int d_ispseudo; /* is a pseudo-device */ int d_major; /* used for "root on sd0", e.g. */ + struct nvlist *d_attrs; /* attributes, if any */ + int d_umax; /* highest unit number + 1 */ + struct devi *d_ihead; /* first instance, if any */ + struct devi **d_ipp; /* used for tacking on more instances */ + struct deva *d_ahead; /* first attachment, if any */ + struct deva **d_app; /* used for tacking on attachments */ +}; + +struct deva { + const char *d_name; /* name of attachment, e.g. "com_isa" */ + struct deva *d_next; /* linked list */ + struct deva *d_bsame; /* list on same base */ + int d_isdef; /* set once properly defined */ + struct devbase *d_devbase; /* the base device */ struct nvlist *d_atlist; /* e.g., "at tg" (attr list) */ struct nvlist *d_vectors; /* interrupt vectors, if any */ struct nvlist *d_attrs; /* attributes, if any */ struct devi *d_ihead; /* first instance, if any */ struct devi **d_ipp; /* used for tacking on more instances */ - int d_umax; /* highest unit number + 1 */ }; /* @@ -139,10 +160,12 @@ struct devi { struct devbase *i_base;/* e.g., pointer to "sd" base */ struct devi *i_next; /* list of all instances */ struct devi *i_bsame; /* list on same base */ + struct devi *i_asame; /* list on same base attachment */ struct devi *i_alias; /* other aliases of this instance */ const char *i_at; /* where this is "at" (NULL if at root) */ struct attr *i_atattr; /* attr that allowed attach */ - struct devbase *i_atdev;/* dev if "at ", else NULL */ + struct devbase *i_atdev;/* if "at ", else NULL */ + struct deva *i_atdeva; const char **i_locs; /* locators (as given by i_atattr) */ int i_atunit; /* unit from "at" */ int i_cfflags; /* flags from config line */ @@ -165,7 +188,16 @@ struct devi { /* * Files. Each file is either standard (always included) or optional, - * depending on whether it has names on which to *be* optional. + * depending on whether it has names on which to *be* optional. The + * options field (fi_optx) is actually an expression tree, with nodes + * for OR, AND, and NOT, as well as atoms (words) representing some + * particular option. The node type is stored in the nv_int field. + * Subexpressions appear in the `next' field; for the binary operators + * AND and OR, the left subexpression is first stored in the nv_ptr field. + * + * For any file marked as needs-count or needs-flag, fixfiles() will + * build fi_optf, a `flat list' of the options with nv_int fields that + * contain counts or `need' flags; this is used in mkheaders(). */ struct files { struct files *fi_next; /* linked list */ @@ -176,9 +208,14 @@ struct files { const char *fi_path; /* full file path */ const char *fi_tail; /* name, i.e., rindex(fi_path, '/') + 1 */ const char *fi_base; /* tail minus ".c" (or whatever) */ - struct nvlist *fi_opt; /* optional on ... */ + struct nvlist *fi_optx;/* options expression */ + struct nvlist *fi_optf;/* flattened version of above, if needed */ const char *fi_mkrule; /* special make rule, if any */ }; +#define FX_ATOM 0 /* atom (in nv_name) */ +#define FX_NOT 1 /* NOT expr (subexpression in nv_next) */ +#define FX_AND 2 /* AND expr (lhs in nv_ptr, rhs in nv_next) */ +#define FX_OR 3 /* OR expr (lhs in nv_ptr, rhs in nv_next) */ /* flags */ #define FI_SEL 0x01 /* selected */ @@ -210,10 +247,12 @@ int maxpartitions; /* configuration's "maxpartitions" parameter */ struct nvlist *options; /* options */ struct nvlist *mkoptions; /* makeoptions */ struct hashtab *devbasetab; /* devbase lookup */ +struct hashtab *devatab; /* devbase attachment lookup */ struct hashtab *selecttab; /* selects things that are "optional foo" */ struct hashtab *needcnttab; /* retains names marked "needs-count" */ struct devbase *allbases; /* list of all devbase structures */ +struct deva *alldevas; /* list of all devbase attachment structures */ struct config *allcf; /* list of configured kernels */ struct devi *alldevi; /* list of all instances */ struct devi *allpseudo; /* list of all pseudo-devices */ @@ -252,6 +291,8 @@ const char *intern __P((const char *)); /* main.c */ void addoption __P((const char *name, const char *value)); void addmkoption __P((const char *name, const char *value)); +int devbase_has_instances __P((struct devbase *, int)); +int deva_has_instances __P((struct deva *, int)); /* mkheaders.c */ int mkheaders __P((void)); @@ -281,6 +322,7 @@ char *path __P((const char *)); void error __P((const char *, ...)); /* immediate errs */ void xerror __P((const char *, int, const char *, ...)); /* delayed errs */ __dead void panic __P((const char *, ...)); -struct nvlist *newnv __P((const char *, const char *, void *, int)); +struct nvlist *newnv __P((const char *, const char *, void *, int, + struct nvlist *)); void nvfree __P((struct nvlist *)); void nvfreel __P((struct nvlist *)); diff --git a/usr.sbin/config/files.c b/usr.sbin/config/files.c index 61574f5b004..ac2f302cf51 100644 --- a/usr.sbin/config/files.c +++ b/usr.sbin/config/files.c @@ -1,7 +1,7 @@ -/* $OpenBSD: files.c,v 1.3 1996/03/25 15:55:03 niklas Exp $ */ -/* $NetBSD: files.c,v 1.3 1996/03/03 17:28:10 thorpej Exp $ */ +/* $OpenBSD: files.c,v 1.4 1996/04/21 23:40:09 deraadt Exp $ */ +/* $NetBSD: files.c,v 1.6 1996/03/17 13:18:17 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -66,6 +66,14 @@ static struct hashtab *pathtab; /* full path names */ static struct files **nextfile; static struct files **unchecked; +static int checkaux __P((const char *, void *)); +static int fixcount __P((const char *, void *)); +static int fixfsel __P((const char *, void *)); +static int fixsel __P((const char *, void *)); +static int expr_eval __P((struct nvlist *, + int (*)(const char *, void *), void *)); +static void expr_free __P((struct nvlist *)); + void initfiles() { @@ -88,17 +96,17 @@ showprev(pref, fi) } void -addfile(path, opts, flags, rule) +addfile(path, optx, flags, rule) const char *path; - struct nvlist *opts; + struct nvlist *optx; int flags; const char *rule; { struct files *fi; - const char *base, *dotp, *tail; + const char *dotp, *tail; size_t baselen; int needc, needf; - char buf[200]; + char base[200]; /* check various errors */ needc = flags & FI_NEEDSCOUNT; @@ -107,15 +115,10 @@ addfile(path, opts, flags, rule) error("cannot mix needs-count and needs-flag"); goto bad; } - if (opts == NULL && (needc || needf)) { + if (optx == NULL && (needc || needf)) { error("nothing to %s for %s", needc ? "count" : "flag", path); goto bad; } - if ((fi = ht_lookup(pathtab, path)) != NULL) { - showprev("", fi); - error("file %s listed again", path); - goto bad; - } /* find last part of pathname, and same without trailing suffix */ tail = rindex(path, '/'); @@ -125,57 +128,41 @@ addfile(path, opts, flags, rule) tail++; dotp = rindex(tail, '.'); if (dotp == NULL || dotp[1] == 0 || - (baselen = dotp - tail) >= sizeof(buf)) { + (baselen = dotp - tail) >= sizeof(base)) { error("invalid pathname `%s'", path); goto bad; } /* - * Make a copy of the path without the .c/.s/whatever suffix. - * This must be unique per "files" file (e.g., a specific - * file can override a standard file, but no standard file - * can override another standard file). This is not perfect - * but should catch any major errors. - */ - bcopy(tail, buf, baselen); - buf[baselen] = 0; - base = intern(buf); - if ((fi = ht_lookup(basetab, base)) != NULL) { - if (fi->fi_srcfile != yyfile) { - showprev("note: ", fi); - error("is overridden by %s", path); - errors--; /* take it away */ - fi->fi_flags |= FI_HIDDEN; - } else { - showprev("", fi); - error("collides with %s (both make %s.o)", - path, base); - goto bad; - } - } - - /* - * Commit this file to memory. + * Commit this file to memory. We will decide later whether it + * will be used after all. */ fi = emalloc(sizeof *fi); + if (ht_insert(pathtab, path, fi)) { + free(fi); + if ((fi = ht_lookup(pathtab, path)) == NULL) + panic("addfile: ht_lookup(%s)", path); + error("duplicate file %s", path); + xerror(fi->fi_srcfile, fi->fi_srcline, + "here is the original definition"); + } + memcpy(base, tail, baselen); + base[baselen] = 0; fi->fi_next = NULL; fi->fi_srcfile = yyfile; fi->fi_srcline = currentline(); fi->fi_flags = flags; - fi->fi_lastc = dotp[strlen(dotp) - 1]; fi->fi_path = path; fi->fi_tail = tail; - fi->fi_base = base; - fi->fi_opt = opts; + fi->fi_base = intern(base); + fi->fi_optx = optx; + fi->fi_optf = NULL; fi->fi_mkrule = rule; - if (ht_insert(pathtab, path, fi)) - panic("addfile: ht_insert(%s)", path); - (void)ht_replace(basetab, base, fi); *nextfile = fi; nextfile = &fi->fi_next; return; bad: - nvfreel(opts); + expr_free(optx); } /* @@ -191,75 +178,265 @@ checkfiles() register struct nvlist *nv; last = NULL; - for (fi = *unchecked; fi != NULL; last = fi, fi = fi->fi_next) { - if ((fi->fi_flags & FI_NEEDSCOUNT) == 0) - continue; - for (nv = fi->fi_opt; nv != NULL; nv = nv->nv_next) - if (ht_lookup(devbasetab, nv->nv_name) == NULL) { - xerror(fi->fi_srcfile, fi->fi_srcline, - "`%s' is not a countable device", - nv->nv_name); - /* keep fixfiles() from complaining again */ - fi->fi_flags |= FI_HIDDEN; - } - } + for (fi = *unchecked; fi != NULL; last = fi, fi = fi->fi_next) + if ((fi->fi_flags & FI_NEEDSCOUNT) != 0) + (void)expr_eval(fi->fi_optx, checkaux, fi); if (last != NULL) unchecked = &last->fi_next; } +/* + * Auxiliary function for checkfiles, called from expr_eval. + * We are not actually interested in the expression's value. + */ +static int +checkaux(name, context) + const char *name; + void *context; +{ + register struct files *fi = context; + + if (ht_lookup(devbasetab, name) == NULL) { + xerror(fi->fi_srcfile, fi->fi_srcline, + "`%s' is not a countable device", + name); + /* keep fixfiles() from complaining again */ + fi->fi_flags |= FI_HIDDEN; + } + return (0); +} + /* * We have finished reading everything. Tack the files down: calculate - * selection and counts as needed. + * selection and counts as needed. Check that the object files built + * from the selected sources do not collide. */ int fixfiles() { - register struct files *fi; - register struct nvlist *nv; - register struct devbase *dev; - int sel, err; + register struct files *fi, *ofi; + struct nvlist *flathead, **flatp; + int err, sel; err = 0; for (fi = allfiles; fi != NULL; fi = fi->fi_next) { + /* Skip files that generated counted-device complaints. */ if (fi->fi_flags & FI_HIDDEN) continue; - if ((nv = fi->fi_opt) == NULL) { /* standard */ - fi->fi_flags |= FI_SEL; - continue; + if (fi->fi_optx != NULL) { + /* Optional: see if it is to be included. */ + flathead = NULL; + flatp = &flathead; + sel = expr_eval(fi->fi_optx, + fi->fi_flags & FI_NEEDSCOUNT ? fixcount : + fi->fi_flags & FI_NEEDSFLAG ? fixfsel : + fixsel, + &flatp); + fi->fi_optf = flathead; + if (!sel) + continue; } - /* figure out whether it is selected */ - sel = 0; - if (fi->fi_flags & FI_NEEDSCOUNT) { - /* ... and compute counts too */ - do { - dev = ht_lookup(devbasetab, nv->nv_name); - if (dev == NULL) { - xerror(fi->fi_srcfile, fi->fi_srcline, - "`%s' is not a countable device", - nv->nv_name); - err = 1; - } else { - if (dev->d_umax) - sel = 1; - nv->nv_int = dev->d_umax; - (void)ht_insert(needcnttab, - nv->nv_name, nv); - } - } while ((nv = nv->nv_next) != NULL); - } else { - do { - if (ht_lookup(selecttab, nv->nv_name)) { - sel = 1; - break; - } - } while ((nv = nv->nv_next) != NULL); - if (fi->fi_flags & FI_NEEDSFLAG) - for (nv = fi->fi_opt; nv; nv = nv->nv_next) - nv->nv_int = sel; + + /* We like this file. Make sure it generates a unique .o. */ + if (ht_insert(basetab, fi->fi_base, fi)) { + if ((ofi = ht_lookup(basetab, fi->fi_base)) == NULL) + panic("fixfiles ht_lookup(%s)", fi->fi_base); + /* + * If the new file comes from a different source, + * allow the new one to override the old one. + */ + if (fi->fi_path != ofi->fi_path) { + if (ht_replace(basetab, fi->fi_base, fi) != 1) + panic("fixfiles ht_replace(%s)", + fi->fi_base); + ofi->fi_flags &= ~FI_SEL; + ofi->fi_flags |= FI_HIDDEN; + } else { + xerror(fi->fi_srcfile, fi->fi_srcline, + "object file collision on %s.o, from %s", + fi->fi_base, fi->fi_path); + xerror(ofi->fi_srcfile, ofi->fi_srcline, + "here is the previous file: %s", + ofi->fi_path); + err = 1; + } } - /* if selected, we are go */ - if (sel) - fi->fi_flags |= FI_SEL; + fi->fi_flags |= FI_SEL; } return (err); } + +/* + * Called when evaluating a needs-count expression. Make sure the + * atom is a countable device. The expression succeeds iff there + * is at least one of them (note that while `xx*' will not always + * set xx's d_umax > 0, you cannot mix '*' and needs-count). The + * mkheaders() routine wants a flattened, in-order list of the + * atoms for `#define name value' lines, so we build that as we + * are called to eval each atom. + */ +static int +fixcount(name, context) + register const char *name; + void *context; +{ + register struct nvlist ***p = context; + register struct devbase *dev; + register struct nvlist *nv; + + dev = ht_lookup(devbasetab, name); + if (dev == NULL) /* cannot occur here; we checked earlier */ + panic("fixcount(%s)", name); + nv = newnv(name, NULL, NULL, dev->d_umax, NULL); + **p = nv; + *p = &nv->nv_next; + (void)ht_insert(needcnttab, name, nv); + return (dev->d_umax != 0); +} + +/* + * Called from fixfiles when eval'ing a selection expression for a + * file that will generate a .h with flags. We will need the flat list. + */ +static int +fixfsel(name, context) + const char *name; + void *context; +{ + register struct nvlist ***p = context; + register struct nvlist *nv; + register int sel; + + sel = ht_lookup(selecttab, name) != NULL; + nv = newnv(name, NULL, NULL, sel, NULL); + **p = nv; + *p = &nv->nv_next; + return (sel); +} + +/* + * As for fixfsel above, but we do not need the flat list. + */ +static int +fixsel(name, context) + const char *name; + void *context; +{ + + return (ht_lookup(selecttab, name) != NULL); +} + +/* + * Eval an expression tree. Calls the given function on each node, + * passing it the given context & the name; return value is &/|/! of + * results of evaluating atoms. + * + * No short circuiting ever occurs. fn must return 0 or 1 (otherwise + * our mixing of C's bitwise & boolean here may give surprises). + */ +static int +expr_eval(expr, fn, context) + register struct nvlist *expr; + register int (*fn) __P((const char *, void *)); + register void *context; +{ + int lhs, rhs; + + switch (expr->nv_int) { + + case FX_ATOM: + return ((*fn)(expr->nv_name, context)); + + case FX_NOT: + return (!expr_eval(expr->nv_next, fn, context)); + + case FX_AND: + lhs = expr_eval(expr->nv_ptr, fn, context); + rhs = expr_eval(expr->nv_next, fn, context); + return (lhs & rhs); + + case FX_OR: + lhs = expr_eval(expr->nv_ptr, fn, context); + rhs = expr_eval(expr->nv_next, fn, context); + return (lhs | rhs); + } + panic("expr_eval %d", expr->nv_int); + /* NOTREACHED */ +} + +/* + * Free an expression tree. + */ +static void +expr_free(expr) + register struct nvlist *expr; +{ + register struct nvlist *rhs; + + /* This loop traverses down the RHS of each subexpression. */ + for (; expr != NULL; expr = rhs) { + switch (expr->nv_int) { + + /* Atoms and !-exprs have no left hand side. */ + case FX_ATOM: + case FX_NOT: + break; + + /* For AND and OR nodes, free the LHS. */ + case FX_AND: + case FX_OR: + expr_free(expr->nv_ptr); + break; + + default: + panic("expr_free %d", expr->nv_int); + } + rhs = expr->nv_next; + nvfree(expr); + } +} + +#ifdef DEBUG +/* + * Print expression tree. + */ +void +prexpr(expr) + struct nvlist *expr; +{ + static void pr0(); + + printf("expr ="); + pr0(expr); + printf("\n"); + (void)fflush(stdout); +} + +static void +pr0(e) + register struct nvlist *e; +{ + + switch (e->nv_int) { + case FX_ATOM: + printf(" %s", e->nv_name); + return; + case FX_NOT: + printf(" (!"); + break; + case FX_AND: + printf(" (&"); + break; + case FX_OR: + printf(" (|"); + break; + default: + printf(" (?%d?", e->nv_int); + break; + } + if (e->nv_ptr) + pr0(e->nv_ptr); + pr0(e->nv_next); + printf(")"); +} +#endif diff --git a/usr.sbin/config/gram.y b/usr.sbin/config/gram.y index 3b197a85745..8d50756b2e3 100644 --- a/usr.sbin/config/gram.y +++ b/usr.sbin/config/gram.y @@ -1,6 +1,6 @@ %{ -/* $OpenBSD: gram.y,v 1.2 1996/03/25 15:55:04 niklas Exp $ */ -/* $NetBSD: gram.y,v 1.3 1996/03/03 17:28:13 thorpej Exp $ */ +/* $OpenBSD: gram.y,v 1.3 1996/04/21 23:40:11 deraadt Exp $ */ +/* $NetBSD: gram.y,v 1.7 1996/03/17 13:18:18 cgd Exp $ */ /* * Copyright (c) 1992, 1993 @@ -69,14 +69,21 @@ static struct config conf; /* at most one active at a time */ /* the following is used to recover nvlist space after errors */ static struct nvlist *alloc[1000]; static int adepth; -#define new0(n,s,p,i) (alloc[adepth++] = newnv(n, s, p, i)) -#define new_n(n) new0(n, NULL, NULL, 0) -#define new_ns(n, s) new0(n, s, NULL, 0) -#define new_si(s, i) new0(NULL, s, NULL, i) -#define new_nsi(n,s,i) new0(n, s, NULL, i) -#define new_np(n, p) new0(n, NULL, p, 0) -#define new_s(s) new0(NULL, s, NULL, 0) -#define new_p(p) new0(NULL, NULL, p, 0) +#define new0(n,s,p,i,x) (alloc[adepth++] = newnv(n, s, p, i, x)) +#define new_n(n) new0(n, NULL, NULL, 0, NULL) +#define new_nx(n, x) new0(n, NULL, NULL, 0, x) +#define new_ns(n, s) new0(n, s, NULL, 0, NULL) +#define new_si(s, i) new0(NULL, s, NULL, i, NULL) +#define new_nsi(n,s,i) new0(n, s, NULL, i, NULL) +#define new_np(n, p) new0(n, NULL, p, 0, NULL) +#define new_s(s) new0(NULL, s, NULL, 0, NULL) +#define new_p(p) new0(NULL, NULL, p, 0, NULL) +#define new_px(p, x) new0(NULL, NULL, p, 0, x) + +#define fx_atom(s) new0(s, NULL, NULL, FX_ATOM, NULL) +#define fx_not(e) new0(NULL, NULL, NULL, FX_NOT, e) +#define fx_and(e1, e2) new0(NULL, NULL, e1, FX_AND, e2) +#define fx_or(e1, e2) new0(NULL, NULL, e1, FX_OR, e2) static void cleanup __P((void)); static void setmachine __P((const char *, const char *)); @@ -87,22 +94,24 @@ static void setmaxpartitions __P((int)); %union { struct attr *attr; struct devbase *devb; + struct deva *deva; struct nvlist *list; const char *str; int val; } -%token AND AT COMPILE_WITH CONFIG DEFINE DEVICE DUMPS ENDFILE +%token AND AT ATTACH COMPILE_WITH CONFIG DEFINE DEVICE DUMPS ENDFILE %token XFILE FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS -%token MINOR ON OPTIONS PSEUDO_DEVICE ROOT SWAP VECTOR +%token MINOR ON OPTIONS PSEUDO_DEVICE ROOT SWAP VECTOR WITH %token FFLAG NUMBER %token PATHNAME WORD -%type fopts +%type fopts fexpr fatom %type fflgs %type rule %type attr %type devbase +%type devattach_opt %type atlist interface_opt %type atname %type loclist_opt loclist locdef @@ -164,9 +173,19 @@ file: /* order of options is important, must use right recursion */ fopts: - WORD fopts = { ($$ = new_n($1))->nv_next = $2; } | + fexpr = { $$ = $1; } | /* empty */ = { $$ = NULL; }; +fexpr: + fatom = { $$ = $1; } | + '!' fatom = { $$ = fx_not($2); } | + fexpr '&' fexpr = { $$ = fx_and($1, $3); } | + fexpr '|' fexpr = { $$ = fx_or($1, $3); } | + '(' fexpr ')' = { $$ = $2; }; + +fatom: + WORD = { $$ = fx_atom($1); }; + fflgs: fflgs FFLAG = { $$ = $1 | $2; } | /* empty */ = { $$ = 0; }; @@ -194,14 +213,17 @@ one_def: file | include | DEFINE WORD interface_opt = { (void)defattr($2, $3); } | - DEVICE devbase AT atlist veclist_opt interface_opt attrs_opt - = { defdev($2, 0, $4, $5, $6, $7); } | + DEVICE devbase interface_opt attrs_opt + = { defdev($2, 0, $3, $4); } | + ATTACH devbase AT atlist veclist_opt devattach_opt attrs_opt + = { defdevattach($6, $2, $4, $5, + $7); } | MAXUSERS NUMBER NUMBER NUMBER = { setdefmaxusers($2, $3, $4); } | - PSEUDO_DEVICE devbase attrs_opt = { defdev($2,1,NULL,NULL,NULL,$3); } | + PSEUDO_DEVICE devbase attrs_opt = { defdev($2,1,NULL,$3); } | MAJOR '{' majorlist '}'; atlist: - atlist ',' atname = { ($$ = new_n($3))->nv_next = $1; } | + atlist ',' atname = { $$ = new_nx($3, $1); } | atname = { $$ = new_n($1); }; atname: @@ -214,14 +236,18 @@ veclist_opt: /* veclist order matters, must use right recursion */ veclist: - WORD veclist = { ($$ = new_n($1))->nv_next = $2; } | + WORD veclist = { $$ = new_nx($1, $2); } | WORD = { $$ = new_n($1); }; devbase: WORD = { $$ = getdevbase($1); }; +devattach_opt: + WITH WORD = { $$ = getdevattach($2); } | + /* empty */ = { $$ = NULL; }; + interface_opt: - '{' loclist_opt '}' = { ($$ = new_n(""))->nv_next = $2; } | + '{' loclist_opt '}' = { $$ = new_nx("", $2); } | /* empty */ = { $$ = NULL; }; loclist_opt: @@ -257,7 +283,7 @@ attrs_opt: /* empty */ = { $$ = NULL; }; attrs: - attrs ',' attr = { ($$ = new_p($3))->nv_next = $1; } | + attrs ',' attr = { $$ = new_px($3, $1); } | attr = { $$ = new_p($1); }; attr: @@ -351,7 +377,6 @@ device_instance: attachment: ROOT = { $$ = NULL; } | WORD '?' = { $$ = wildref($1); } | - WORD '*' = { $$ = starref($1); } | WORD = { $$ = $1; }; locators: diff --git a/usr.sbin/config/hash.c b/usr.sbin/config/hash.c index e1290fd9456..538b7a703ff 100644 --- a/usr.sbin/config/hash.c +++ b/usr.sbin/config/hash.c @@ -1,5 +1,5 @@ -/* $OpenBSD: hash.c,v 1.2 1996/03/25 15:55:05 niklas Exp $ */ -/* $NetBSD: hash.c,v 1.2 1996/03/03 17:28:15 thorpej Exp $ */ +/* $OpenBSD: hash.c,v 1.3 1996/04/21 23:40:12 deraadt Exp $ */ +/* $NetBSD: hash.c,v 1.3 1996/03/17 13:18:20 cgd Exp $ */ /* * Copyright (c) 1992, 1993 @@ -262,6 +262,8 @@ ht_insrep(ht, nam, val, replace) } *hpp = hp = newhashent(nam, h); hp->h_value = val; + if (++ht->ht_used > ht->ht_lim) + ht_expand(ht); return (0); } diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 5a2539a6e5b..c0e4482d74a 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -1,7 +1,7 @@ -/* $OpenBSD: main.c,v 1.3 1996/03/25 15:55:06 niklas Exp $ */ -/* $NetBSD: main.c,v 1.13 1996/03/03 17:28:17 thorpej Exp $ */ +/* $OpenBSD: main.c,v 1.4 1996/04/21 23:40:14 deraadt Exp $ */ +/* $NetBSD: main.c,v 1.17 1996/03/17 11:50:13 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -78,7 +78,6 @@ static int do_option __P((struct hashtab *, struct nvlist ***, static int crosscheck __P((void)); static int badstar __P((void)); static int mksymlinks __P((void)); -static int has_instances __P((struct devbase *, int)); static int hasparent __P((struct devi *)); static int cfcrosscheck __P((struct config *, const char *, struct nvlist *)); @@ -150,6 +149,7 @@ usage: initfiles(); initsem(); devbasetab = ht_new(); + devatab = ht_new(); selecttab = ht_new(); needcnttab = ht_new(); opttab = ht_new(); @@ -323,7 +323,7 @@ do_option(ht, nppp, name, value, type) register struct nvlist *nv; /* assume it will work */ - nv = newnv(name, value, NULL, 0); + nv = newnv(name, value, NULL, 0, NULL); if (ht_insert(ht, name, nv) == 0) { **nppp = nv; *nppp = &nv->nv_next; @@ -343,23 +343,40 @@ do_option(ht, nppp, name, value, type) /* * Return true if there is at least one instance of the given unit - * on the given base (or any units, if unit == WILD). + * on the given device attachment (or any units, if unit == WILD). */ -static int -has_instances(dev, unit) - register struct devbase *dev; +int +deva_has_instances(deva, unit) + register struct deva *deva; int unit; { register struct devi *i; if (unit == WILD) - return (dev->d_ihead != NULL); - for (i = dev->d_ihead; i != NULL; i = i->i_bsame) + return (deva->d_ihead != NULL); + for (i = deva->d_ihead; i != NULL; i = i->i_asame) if (unit == i->i_unit) return (1); return (0); } +/* + * Return true if there is at least one instance of the given unit + * on the given base (or any units, if unit == WILD). + */ +int +devbase_has_instances(dev, unit) + register struct devbase *dev; + int unit; +{ + register struct deva *da; + + for (da = dev->d_ahead; da != NULL; da = da->d_bsame) + if (deva_has_instances(da, unit)) + return (1); + return (0); +} + static int hasparent(i) register struct devi *i; @@ -367,11 +384,30 @@ hasparent(i) register struct nvlist *nv; int atunit = i->i_atunit; - if (i->i_atdev != NULL && has_instances(i->i_atdev, atunit)) - return (1); + /* + * We determine whether or not a device has a parent in in one + * of two ways: + * (1) If a parent device was named in the config file, + * i.e. cases (2) and (3) in sem.c:adddev(), then + * we search its devbase for a matching unit number. + * (2) If the device was attach to an attribute, then we + * search all attributes the device can be attached to + * for parents (with appropriate unit numebrs) that + * may be able to attach the device. + */ + + /* + * Case (1): A parent was named. Either it's configured, or not. + */ + if (i->i_atdev != NULL) + return (devbase_has_instances(i->i_atdev, atunit)); + + /* + * Case (2): No parent was named. Look for devs that provide the attr. + */ if (i->i_atattr != NULL) for (nv = i->i_atattr->a_refs; nv != NULL; nv = nv->nv_next) - if (has_instances(nv->nv_ptr, atunit)) + if (devbase_has_instances(nv->nv_ptr, atunit)) return (1); return (0); } @@ -384,7 +420,7 @@ cfcrosscheck(cf, what, nv) { register struct devbase *dev; register struct devi *pd; - int errs; + int errs, devminor; for (errs = 0; nv != NULL; nv = nv->nv_next) { if (nv->nv_name == NULL) @@ -392,13 +428,15 @@ cfcrosscheck(cf, what, nv) dev = ht_lookup(devbasetab, nv->nv_name); if (dev == NULL) panic("cfcrosscheck(%s)", nv->nv_name); - if (has_instances(dev, STAR) || - has_instances(dev, minor(nv->nv_int) / maxpartitions)) + devminor = minor(nv->nv_int) / maxpartitions; + if (devbase_has_instances(dev, devminor)) + continue; + if (devbase_has_instances(dev, STAR) && + devminor >= dev->d_umax) continue; for (pd = allpseudo; pd != NULL; pd = pd->i_next) - if (pd->i_base == dev && - (minor(nv->nv_int) / maxpartitions) < dev->d_umax && - (minor(nv->nv_int) / maxpartitions) >= 0) + if (pd->i_base == dev && devminor < dev->d_umax && + devminor >= 0) goto loop; (void)fprintf(stderr, "%s%d: %s says %s on %s, but there's no %s\n", @@ -429,11 +467,9 @@ crosscheck() continue; xerror(conffile, i->i_lineno, "%s at %s is orphaned", i->i_name, i->i_at); - if (i->i_atunit == WILD) - (void)fprintf(stderr, " (no %s declared)\n", - i->i_at); - else - (void)fprintf(stderr, " (no %s declared)\n", i->i_at); + (void)fprintf(stderr, " (%s %s declared)\n", + i->i_atunit == WILD ? "nothing matching" : "no", + i->i_at); errs++; } if (allcf == NULL) { @@ -452,21 +488,23 @@ crosscheck() } /* - * Check to see if there is more than one *'d unit for any device, - * or a *'d unit with a needs-count file. + * Check to see if there is a *'d unit with a needs-count file. */ int badstar() { register struct devbase *d; + register struct deva *da; register struct devi *i; register int errs, n; errs = 0; for (d = allbases; d != NULL; d = d->d_next) { - for (i = d->d_ihead; i != NULL; i = i->i_bsame) - if (i->i_unit == STAR) - goto foundstar; + for (da = d->d_ahead; da != NULL; da = da->d_bsame) + for (i = da->d_ihead; i != NULL; i = i->i_asame) { + if (i->i_unit == STAR) + goto foundstar; + } continue; foundstar: if (ht_lookup(needcnttab, d->d_name)) { @@ -481,12 +519,6 @@ badstar() n++; if (n < 1) panic("badstar() n<1"); - if (n == 1) - continue; - (void)fprintf(stderr, - "config: %d %s*'s in configuration; can only have 1\n", - n, d->d_name); - errs++; } return (errs); } diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c index 91ddb8c28ac..d158c209a22 100644 --- a/usr.sbin/config/mkheaders.c +++ b/usr.sbin/config/mkheaders.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mkheaders.c,v 1.2 1996/03/25 15:55:07 niklas Exp $ */ -/* $NetBSD: mkheaders.c,v 1.8 1996/03/03 17:28:20 thorpej Exp $ */ +/* $OpenBSD: mkheaders.c,v 1.3 1996/04/21 23:40:15 deraadt Exp $ */ +/* $NetBSD: mkheaders.c,v 1.10 1996/03/17 13:18:21 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -69,7 +69,7 @@ mkheaders() if (fi->fi_flags & FI_HIDDEN) continue; if (fi->fi_flags & (FI_NEEDSCOUNT | FI_NEEDSFLAG) && - emitcnt(fi->fi_opt)) + emitcnt(fi->fi_optf)) return (1); } return (0); diff --git a/usr.sbin/config/mkioconf.c b/usr.sbin/config/mkioconf.c index 56c40015a2e..c9b418d6831 100644 --- a/usr.sbin/config/mkioconf.c +++ b/usr.sbin/config/mkioconf.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mkioconf.c,v 1.2 1996/03/25 15:55:08 niklas Exp $ */ -/* $NetBSD: mkioconf.c,v 1.36 1996/03/03 17:28:23 thorpej Exp $ */ +/* $OpenBSD: mkioconf.c,v 1.3 1996/04/21 23:40:17 deraadt Exp $ */ +/* $NetBSD: mkioconf.c,v 1.38 1996/03/17 06:29:27 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -161,16 +161,25 @@ emitexterns(fp) register FILE *fp; { register struct devbase *d; + register struct deva *da; NEWLINE; for (d = allbases; d != NULL; d = d->d_next) { - if (d->d_ihead == NULL) + if (!devbase_has_instances(d, WILD)) continue; - if (fprintf(fp, "extern struct cfdriver %scd;\n", + if (fprintf(fp, "extern struct cfdriver %s_cd;\n", d->d_name) < 0) return (1); } NEWLINE; + for (da = alldevas; da != NULL; da = da->d_next) { + if (!deva_has_instances(da, WILD)) + continue; + if (fprintf(fp, "extern struct cfattach %s_ca;\n", + da->d_name) < 0) + return (1); + } + NEWLINE; return (0); } @@ -216,7 +225,7 @@ emitcfdata(fp) { register struct devi **p, *i, **par; register int unit, v; - register const char *vs, *state, *basename; + register const char *vs, *state, *basename, *attachment; register struct nvlist *nv; register struct attr *a; char *loc; @@ -227,7 +236,7 @@ emitcfdata(fp) #define STAR FSTATE_STAR\n\ \n\ struct cfdata cfdata[] = {\n\ -\t/* driver unit state loc flags parents ivstubs */\n") < 0) + /* attachment driver unit state loc flags parents ivstubs */\n") < 0) return (1); for (p = packed; (i = *p) != NULL; p++) { /* the description */ @@ -251,6 +260,7 @@ struct cfdata cfdata[] = {\n\ /* then the actual defining line */ basename = i->i_base->d_name; + attachment = i->i_atdeva->d_name; if (i->i_unit == STAR) { unit = i->i_base->d_umax; state = "STAR"; @@ -271,12 +281,13 @@ struct cfdata cfdata[] = {\n\ } else loc = "loc"; if (fprintf(fp, "\ -\t{&%scd,%s%2d, %s, %7s, %#6x, pv+%2d, %s%d},\n", + {&%s_ca,%s&%s_cd,%s%2d, %s, %7s, %#6x, pv+%2d, %s%d},\n", + attachment, strlen(attachment) < 6 ? "\t\t" : "\t", basename, strlen(basename) < 3 ? "\t\t" : "\t", unit, state, loc, i->i_cfflags, i->i_pvoff, vs, v) < 0) return (1); } - return (fputs("\t{0}\n};\n", fp) < 0); + return (fputs(" {0}\n};\n", fp) < 0); } /* @@ -346,7 +357,7 @@ emitvec(fp) nvec = 0; for (p = packed; (i = *p) != NULL; p++) { - if ((head = i->i_base->d_vectors) == NULL) + if ((head = i->i_atdeva->d_vectors) == NULL) continue; if ((unit = i->i_unit) == STAR) panic("emitvec unit==STAR"); @@ -366,7 +377,7 @@ emitvec(fp) return (1); nvec = 0; for (p = packed; (i = *p) != NULL; p++) { - if ((head = i->i_base->d_vectors) == NULL) + if ((head = i->i_atdeva->d_vectors) == NULL) continue; i->i_ivoff = nvec; unit = i->i_unit; diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index 237ea6c1a17..33a31571ace 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mkmakefile.c,v 1.2 1996/03/25 15:55:09 niklas Exp $ */ -/* $NetBSD: mkmakefile.c,v 1.27 1996/03/03 17:28:26 thorpej Exp $ */ +/* $OpenBSD: mkmakefile.c,v 1.3 1996/04/21 23:40:18 deraadt Exp $ */ +/* $NetBSD: mkmakefile.c,v 1.29 1996/03/17 13:18:23 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -53,15 +53,19 @@ #include #include "config.h" #include "sem.h" + /* * Make the Makefile. */ +static const char *srcpath __P((struct files *)); + static int emitdefs __P((FILE *)); +static int emitfiles __P((FILE *, int)); + static int emitobjs __P((FILE *)); static int emitcfiles __P((FILE *)); static int emitsfiles __P((FILE *)); -static int emitfiles __P((FILE *, int)); static int emitrules __P((FILE *)); static int emitload __P((FILE *)); @@ -142,6 +146,33 @@ bad: return (1); } +/* + * Return (possibly in a static buffer) the name of the `source' for a + * file. If we have `options source', or if the file is marked `always + * source', this is always the path from the `file' line; otherwise we + * get the .o from the obj-directory. + */ +static const char * +srcpath(fi) + register struct files *fi; +{ +#if 1 + /* Always have source, don't support object dirs for kernel builds. */ + return (fi->fi_path); +#else + static char buf[MAXPATHLEN]; + + if (have_source || (fi->fi_flags & FI_ALWAYSSRC) != 0) + return (fi->fi_path); + if (objpath == NULL) { + error("obj-directory not set"); + return (NULL); + } + (void)snprintf(buf, sizeof buf, "%s/%s.o", objpath, fi->fi_base); + return (buf); +#endif +} + static int emitdefs(fp) register FILE *fp; @@ -225,6 +256,7 @@ emitfiles(fp, suffix) register struct files *fi; register struct config *cf; register int lpos, len, sp; + register const char *fpath; char swapname[100]; if (fprintf(fp, "%cFILES=", toupper(suffix)) < 0) @@ -234,10 +266,12 @@ emitfiles(fp, suffix) for (fi = allfiles; fi != NULL; fi = fi->fi_next) { if ((fi->fi_flags & FI_SEL) == 0) continue; - len = strlen(fi->fi_path); - if (fi->fi_path[len - 1] != suffix) + if ((fpath = srcpath(fi)) == NULL) + return (1); + len = strlen(fpath); + if (fpath[len - 1] != suffix) continue; - if (*fi->fi_path != '/') + if (*fpath != '/') len += 3; /* "$S/" */ if (lpos + len > 72) { if (fputs(" \\\n", fp) < 0) @@ -245,8 +279,8 @@ emitfiles(fp, suffix) sp = '\t'; lpos = 7; } - if (fprintf(fp, "%c%s%s", sp, *fi->fi_path != '/' ? "$S/" : "", - fi->fi_path) < 0) + if (fprintf(fp, "%c%s%s", sp, *fpath != '/' ? "$S/" : "", + fpath) < 0) return (1); lpos += len + 1; sp = ' '; @@ -291,19 +325,21 @@ emitrules(fp) register FILE *fp; { register struct files *fi; - register const char *cp; + register const char *cp, *fpath; int ch; char buf[200]; for (fi = allfiles; fi != NULL; fi = fi->fi_next) { if ((fi->fi_flags & FI_SEL) == 0) continue; + if ((fpath = srcpath(fi)) == NULL) + return (1); if (fprintf(fp, "%s.o: %s%s\n", fi->fi_base, - *fi->fi_path != '/' ? "$S/" : "", fi->fi_path) < 0) + *fpath != '/' ? "$S/" : "", fpath) < 0) return (1); if ((cp = fi->fi_mkrule) == NULL) { cp = fi->fi_flags & FI_DRIVER ? "DRIVER" : "NORMAL"; - ch = fi->fi_lastc; + ch = fpath[strlen(fpath) - 1]; if (islower(ch)) ch = toupper(ch); (void)sprintf(buf, "${%s_%c%s}", cp, ch, diff --git a/usr.sbin/config/mkswap.c b/usr.sbin/config/mkswap.c index 83e86bb106c..53171687799 100644 --- a/usr.sbin/config/mkswap.c +++ b/usr.sbin/config/mkswap.c @@ -1,7 +1,7 @@ -/* $OpenBSD: mkswap.c,v 1.2 1996/03/25 15:55:10 niklas Exp $ */ -/* $NetBSD: mkswap.c,v 1.2 1996/03/03 17:28:29 thorpej Exp $ */ +/* $OpenBSD: mkswap.c,v 1.3 1996/04/21 23:40:20 deraadt Exp $ */ +/* $NetBSD: mkswap.c,v 1.4 1996/03/17 20:36:25 christos Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -121,9 +121,9 @@ mkoneswap(cf) goto wrerror; mountroot = cf->cf_root->nv_str == s_nfs ? "nfs_mountroot" : "ffs_mountroot"; - if (fprintf(fp, "extern int %s();\n", mountroot) < 0) + if (fprintf(fp, "extern int %s __P((void *));\n", mountroot) < 0) goto wrerror; - if (fprintf(fp, "int (*mountroot)() = %s;\n", mountroot) < 0) + if (fprintf(fp, "int (*mountroot) __P((void *)) = %s;\n", mountroot) < 0) goto wrerror; if (fclose(fp)) { diff --git a/usr.sbin/config/pack.c b/usr.sbin/config/pack.c index 9e0b6330004..c3378c0c8b1 100644 --- a/usr.sbin/config/pack.c +++ b/usr.sbin/config/pack.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pack.c,v 1.2 1996/03/25 15:55:11 niklas Exp $ */ -/* $NetBSD: pack.c,v 1.2 1996/03/03 17:28:32 thorpej Exp $ */ +/* $OpenBSD: pack.c,v 1.3 1996/04/21 23:40:21 deraadt Exp $ */ +/* $NetBSD: pack.c,v 1.3 1996/03/17 06:29:33 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * diff --git a/usr.sbin/config/scan.l b/usr.sbin/config/scan.l index 9f211c640b1..d79648c34d7 100644 --- a/usr.sbin/config/scan.l +++ b/usr.sbin/config/scan.l @@ -1,8 +1,8 @@ %{ -/* $OpenBSD: scan.l,v 1.2 1996/03/25 15:55:12 niklas Exp $ */ -/* $NetBSD: scan.l,v 1.2 1996/03/03 17:28:34 thorpej Exp $ */ +/* $OpenBSD: scan.l,v 1.3 1996/04/21 23:40:23 deraadt Exp $ */ +/* $NetBSD: scan.l,v 1.4 1996/03/17 06:29:35 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -87,6 +87,7 @@ WORD [A-Za-z_][-A-Za-z_0-9]* /* plain keywords */ and { return AND; } at { return AT; } +attach { return ATTACH; } compile-with { return COMPILE_WITH; } config { return CONFIG; } define { return DEFINE; } @@ -107,6 +108,7 @@ options { return OPTIONS; } root { return ROOT; } swap { return SWAP; } vector { return VECTOR; } +with { return WITH; } /* keywords with values */ config-dependent { yylval.val = FI_CONFIGDEP; return FFLAG; } diff --git a/usr.sbin/config/sem.c b/usr.sbin/config/sem.c index d0a69b5bfb1..cdd67f47e42 100644 --- a/usr.sbin/config/sem.c +++ b/usr.sbin/config/sem.c @@ -1,7 +1,7 @@ -/* $OpenBSD: sem.c,v 1.2 1996/03/25 15:55:13 niklas Exp $ */ -/* $NetBSD: sem.c,v 1.2 1996/03/03 17:28:37 thorpej Exp $ */ +/* $OpenBSD: sem.c,v 1.3 1996/04/21 23:40:25 deraadt Exp $ */ +/* $NetBSD: sem.c,v 1.8 1996/03/17 21:12:03 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -69,7 +69,9 @@ static struct hashtab *devitab; /* etc */ static struct attr errattr; static struct devbase errdev; +static struct deva errdeva; static struct devbase **nextbase; +static struct deva **nextdeva; static struct config **nextcf; static struct devi **nextdevi; static struct devi **nextpseudo; @@ -85,7 +87,7 @@ static struct devi *newdevi __P((const char *, int, struct devbase *d)); static struct devi *getdevi __P((const char *)); static const char *concat __P((const char *, int)); static int split __P((const char *, size_t, char *, size_t, int *)); -static void selectbase __P((struct devbase *)); +static void selectbase __P((struct devbase *, struct deva *)); static int onlist __P((struct nvlist *, void *)); static const char **fixloc __P((const char *, struct attr *, struct nvlist *)); @@ -99,6 +101,9 @@ initsem() allbases = NULL; nextbase = &allbases; + alldevas = NULL; + nextdeva = &alldevas; + cfhashtab = ht_new(); allcf = NULL; nextcf = &allcf; @@ -238,21 +243,19 @@ addtoattr(l, dev) { register struct nvlist *n; - n = newnv(NULL, NULL, dev, 0); - n->nv_next = l; + n = newnv(NULL, NULL, dev, 0, l); return (n); } /* - * Device a device, giving its allowable parent attachments, if any. - * This may (or may not) also define an interface attribute and/or refer - * to existing attributes. There may be a list of vectors. + * Define a device. This may (or may not) also define an interface + * attribute and/or refer to existing attributes. */ void -defdev(dev, ispseudo, atlist, vectors, loclist, attrs) +defdev(dev, ispseudo, loclist, attrs) register struct devbase *dev; int ispseudo; - struct nvlist *atlist, *vectors, *loclist, *attrs; + struct nvlist *loclist, *attrs; { register struct nvlist *nv; register struct attr *a; @@ -278,39 +281,14 @@ defdev(dev, ispseudo, atlist, vectors, loclist, attrs) loclist = NULL; /* defattr disposes of them for us */ if (defattr(dev->d_name, nv)) goto bad; - nv = newnv(dev->d_name, NULL, getattr(dev->d_name), 0); - nv->nv_next = attrs; - attrs = nv; + attrs = newnv(dev->d_name, NULL, getattr(dev->d_name), 0, + attrs); } /* Committed! Set up fields. */ dev->d_ispseudo = ispseudo; - dev->d_atlist = atlist; - dev->d_vectors = vectors; dev->d_attrs = attrs; - /* - * Turn the `at' list into interface attributes (map each - * nv_name to an attribute, or to NULL for root), and add - * this device to those attributes, so that children can - * be listed at this particular device if they are supported - * by that attribute. - */ - for (nv = atlist; nv != NULL; nv = nv->nv_next) { - if (nv->nv_name == NULL) { - nv->nv_ptr = NULL; /* at root */ - continue; - } - nv->nv_ptr = a = getattr(nv->nv_name); - if (a == &errattr) - continue; /* already complained */ - if (!a->a_iattr) - error("%s cannot be at plain attribute `%s'", - dev->d_name, a->a_name); - else - a->a_devs = addtoattr(a->a_devs, dev); - } - /* * For each interface attribute this device refers to, add this * device to its reference list. This makes, e.g., finding all @@ -323,8 +301,6 @@ defdev(dev, ispseudo, atlist, vectors, loclist, attrs) } return; bad: - nvfreel(atlist); - nvfreel(vectors); nvfreel(loclist); nvfreel(attrs); } @@ -359,11 +335,11 @@ badname: dev->d_next = NULL; dev->d_isdef = 0; dev->d_major = NODEV; - dev->d_atlist = NULL; - dev->d_vectors = NULL; dev->d_attrs = NULL; dev->d_ihead = NULL; dev->d_ipp = &dev->d_ihead; + dev->d_ahead = NULL; + dev->d_app = &dev->d_ahead; dev->d_umax = 0; *nextbase = dev; nextbase = &dev->d_next; @@ -373,6 +349,143 @@ badname: return (dev); } +/* + * Define some of a device's allowable parent attachments. + * There may be a list of vectors and a list of (plain) attributes. + */ +void +defdevattach(deva, dev, atlist, vectors, attrs) + register struct deva *deva; + struct devbase *dev; + struct nvlist *atlist, *vectors, *attrs; +{ + register struct nvlist *nv; + register struct attr *a; + register struct deva *da; + + if (dev == &errdev) + goto bad; + if (deva == NULL) + deva = getdevattach(dev->d_name); + if (deva == &errdeva) + goto bad; + if (!dev->d_isdef) { + error("attaching undefined device `%s'", dev->d_name); + goto bad; + } + if (deva->d_isdef) { + error("redefinition of `%s'", deva->d_name); + goto bad; + } + if (dev->d_ispseudo) { + error("pseudo-devices can't attach"); + goto bad; + } + + deva->d_isdef = 1; + if (has_errobj(attrs, &errattr)) + goto bad; + for (nv = attrs; nv != NULL; nv = nv->nv_next) { + a = nv->nv_ptr; + if (a == &errattr) + continue; /* already complained */ + if (a->a_iattr) + error("`%s' is not a plain attribute", a->a_name); + } + + /* Committed! Set up fields. */ + deva->d_attrs = attrs; + deva->d_atlist = atlist; + deva->d_vectors = vectors; + deva->d_devbase = dev; + + /* + * Turn the `at' list into interface attributes (map each + * nv_name to an attribute, or to NULL for root), and add + * this device to those attributes, so that children can + * be listed at this particular device if they are supported + * by that attribute. + */ + for (nv = atlist; nv != NULL; nv = nv->nv_next) { + if (nv->nv_name == NULL) + nv->nv_ptr = a = NULL; /* at root */ + else + nv->nv_ptr = a = getattr(nv->nv_name); + if (a == &errattr) + continue; /* already complained */ + + /* + * Make sure that an attachment spec doesn't + * already say how to attach to this attribute. + */ + for (da = dev->d_ahead; da != NULL; da = da->d_bsame) + if (onlist(da->d_atlist, a)) + error("attach at `%s' already done by `%s'", + a ? a->a_name : "root", da->d_name); + + if (a == NULL) + continue; /* at root; don't add */ + if (!a->a_iattr) + error("%s cannot be at plain attribute `%s'", + dev->d_name, a->a_name); + else + a->a_devs = addtoattr(a->a_devs, dev); + } + + /* attach to parent */ + *dev->d_app = deva; + dev->d_app = &deva->d_bsame; + return; +bad: + nvfreel(atlist); + nvfreel(vectors); + nvfreel(attrs); +} + +/* + * Look up a device attachment. Also makes sure it is a reasonable + * name, i.e., does not contain digits or special characters. + */ +struct deva * +getdevattach(name) + const char *name; +{ + register u_char *p; + register struct deva *deva; + + p = (u_char *)name; + if (!isalpha(*p)) + goto badname; + while (*++p) { + if (!isalnum(*p) && *p != '_') + goto badname; + } + if (isdigit(*--p)) { +badname: + error("bad device attachment name `%s'", name); + return (&errdeva); + } + deva = ht_lookup(devatab, name); + if (deva == NULL) { + deva = emalloc(sizeof *deva); + deva->d_name = name; + deva->d_next = NULL; + deva->d_bsame = NULL; + deva->d_isdef = 0; + deva->d_devbase = NULL; + deva->d_atlist = NULL; + deva->d_vectors = NULL; + deva->d_attrs = NULL; + deva->d_ihead = NULL; + deva->d_ipp = &deva->d_ihead; + *nextdeva = deva; + nextdeva = &deva->d_next; + if (ht_insert(devatab, name, deva)) + panic("getdeva(%s)", name); + } + return (deva); +} + /* * Look up an attribute. */ @@ -421,7 +534,7 @@ exclude(nv, name, what) return (0); } -/* +/* * Map things like "ra0b" => makedev(major("ra"), 0*maxpartitions + 'b'-'a'). * Handle the case where the device number is given but there is no * corresponding name, and map NULL to the default. @@ -453,7 +566,7 @@ resolve(nvp, name, what, dflt, part) min = (minor(dflt->nv_int) / maxpartitions) + part; d = makedev(maj, min); } - *nvp = nv = newnv(NULL, NULL, NULL, d); + *nvp = nv = newnv(NULL, NULL, NULL, d, NULL); } if (nv->nv_int != NODEV) { /* @@ -607,10 +720,12 @@ newdevi(name, unit, d) i->i_base = d; i->i_next = NULL; i->i_bsame = NULL; + i->i_asame = NULL; i->i_alias = NULL; i->i_at = NULL; i->i_atattr = NULL; i->i_atdev = NULL; + i->i_atdeva = NULL; i->i_locs = NULL; i->i_cfflags = 0; i->i_lineno = currentline(); @@ -634,11 +749,14 @@ adddev(name, at, loclist, flags) register struct devbase *ib; /* i->i_base */ register struct devbase *ab; /* not NULL => at another dev */ register struct nvlist *nv; + register struct deva *iba; /* devbase attachment used */ const char *cp; int atunit; char atbuf[NAMESIZE]; + int hit; ab = NULL; + iba = NULL; if (at == NULL) { /* "at root" */ if ((i = getdevi(name)) == NULL) @@ -649,7 +767,13 @@ adddev(name, at, loclist, flags) * bother?). Make sure this device can be at root. */ ib = i->i_base; - if (!onlist(ib->d_atlist, NULL)) { + hit = 0; + for (iba = ib->d_ahead; iba != NULL; iba = iba->d_bsame) + if (onlist(iba->d_atlist, NULL)) { + hit = 1; + break; + } + if (!hit) { error("%s's cannot attach to the root", ib->d_name); goto bad; } @@ -664,38 +788,78 @@ adddev(name, at, loclist, flags) goto bad; ib = i->i_base; cp = intern(atbuf); - if ((attr = ht_lookup(attrtab, cp)) == NULL) { - /* - * Have to work a bit harder to see whether we have - * something like "tg0 at esp0" (where esp is merely - * not an attribute) or "tg0 at nonesuch0" (where - * nonesuch is not even a device). - */ - if ((ab = ht_lookup(devbasetab, cp)) == NULL) { - error("%s at %s: `%s' unknown", - name, at, atbuf); - goto bad; - } - /* - * See if the named parent carries an attribute - * that allows it to supervise device ib. - */ - for (nv = ab->d_attrs; nv != NULL; nv = nv->nv_next) { - attr = nv->nv_ptr; - if (onlist(attr->a_devs, ib)) - goto ok; - } - attr = &errattr;/* now onlist below will fail */ - } - if (!onlist(attr->a_devs, ib)) { - error("%s's cannot attach to %s's", ib->d_name, atbuf); + + /* + * Devices can attach to two types of things: Attributes, + * and other devices (which have the appropriate attributes + * to allow attachment). + * + * (1) If we're attached to an attribute, then we don't need + * look at the parent base device to see what attributes + * it has, and make sure that we can attach to them. + * + * (2) If we're attached to a real device (i.e. named in + * the config file), we want to remember that so that + * at cross-check time, if the device we're attached to + * is missing but other devices which also provide the + * attribute are present, we don't get a false "OK." + * + * (3) If the thing we're attached to is an attribute + * but is actually named in the config file, we still + * have to remember its devbase. + */ + + /* Figure out parent's devbase, to satisfy case (3). */ + ab = ht_lookup(devbasetab, cp); + + /* Find out if it's an attribute. */ + attr = ht_lookup(attrtab, cp); + + /* Make sure we're _really_ attached to the attr. Case (1). */ + if (attr != NULL && onlist(attr->a_devs, ib)) + goto findattachment; + + /* + * Else a real device, and not just an attribute. Case (2). + * + * Have to work a bit harder to see whether we have + * something like "tg0 at esp0" (where esp is merely + * not an attribute) or "tg0 at nonesuch0" (where + * nonesuch is not even a device). + */ + if (ab == NULL) { + error("%s at %s: `%s' unknown", + name, at, atbuf); goto bad; } + + /* + * See if the named parent carries an attribute + * that allows it to supervise device ib. + */ + for (nv = ab->d_attrs; nv != NULL; nv = nv->nv_next) { + attr = nv->nv_ptr; + if (onlist(attr->a_devs, ib)) + goto findattachment; + } + error("%s's cannot attach to %s's", ib->d_name, atbuf); + goto bad; + +findattachment: + /* find out which attachment it uses */ + hit = 0; + for (iba = ib->d_ahead; iba != NULL; iba = iba->d_bsame) + if (onlist(iba->d_atlist, attr)) { + hit = 1; + break; + } + if (!hit) + panic("adddev: can't figure out attachment"); } ok: if ((i->i_locs = fixloc(name, attr, loclist)) == NULL) goto bad; - if (i->i_unit == STAR && ib->d_vectors != NULL) { + if (i->i_unit == STAR && iba->d_vectors != NULL) { error("%s's cannot be *'d as they have preset vectors", ib->d_name); goto bad; @@ -703,9 +867,14 @@ ok: i->i_at = at; i->i_atattr = attr; i->i_atdev = ab; + i->i_atdeva = iba; i->i_atunit = atunit; i->i_cfflags = flags; - selectbase(ib); + + *iba->d_ipp = i; + iba->d_ipp = &i->i_asame; + + selectbase(ib, iba); /* all done, fall into ... */ bad: nvfreel(loclist); @@ -736,7 +905,7 @@ addpseudo(name, number) i = newdevi(name, number - 1, d); /* foo 16 => "foo0..foo15" */ if (ht_insert(devitab, name, i)) panic("addpseudo(%s)", name); - selectbase(d); + selectbase(d, NULL); *nextpseudo = i; nextpseudo = &i->i_next; npseudo++; @@ -863,8 +1032,9 @@ split(name, nlen, base, bsize, aunit) * attributes for "optional foo". */ static void -selectbase(d) +selectbase(d, da) register struct devbase *d; + register struct deva *da; { register struct attr *a; register struct nvlist *nv; @@ -874,6 +1044,14 @@ selectbase(d) a = nv->nv_ptr; (void)ht_insert(selecttab, a->a_name, (char *)a->a_name); } + if (da != NULL) { + (void)ht_insert(selecttab, da->d_name, (char *)da->d_name); + for (nv = da->d_attrs; nv != NULL; nv = nv->nv_next) { + a = nv->nv_ptr; + (void)ht_insert(selecttab, a->a_name, + (char *)a->a_name); + } + } } /* diff --git a/usr.sbin/config/sem.h b/usr.sbin/config/sem.h index 131762f7a47..ede56255b01 100644 --- a/usr.sbin/config/sem.h +++ b/usr.sbin/config/sem.h @@ -1,7 +1,7 @@ -/* $OpenBSD: sem.h,v 1.2 1996/03/25 15:55:14 niklas Exp $ */ -/* $NetBSD: sem.h,v 1.2 1996/03/03 17:28:39 thorpej Exp $ */ +/* $OpenBSD: sem.h,v 1.3 1996/04/21 23:40:27 deraadt Exp $ */ +/* $NetBSD: sem.h,v 1.4 1996/03/17 06:29:40 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -51,8 +51,11 @@ void setdefmaxusers __P((int, int, int)); void setmaxusers __P((int)); int defattr __P((const char *, struct nvlist *)); void defdev __P((struct devbase *, int, struct nvlist *, + struct nvlist *)); +void defdevattach __P((struct deva *, struct devbase *, struct nvlist *, struct nvlist *, struct nvlist *)); struct devbase *getdevbase __P((const char *name)); +struct deva *getdevattach __P((const char *name)); struct attr *getattr __P((const char *name)); void setmajor __P((struct devbase *d, int n)); void addconf __P((struct config *)); diff --git a/usr.sbin/config/util.c b/usr.sbin/config/util.c index ca6b2eddb22..c9db10cda80 100644 --- a/usr.sbin/config/util.c +++ b/usr.sbin/config/util.c @@ -1,7 +1,7 @@ -/* $OpenBSD: util.c,v 1.2 1996/03/25 15:55:16 niklas Exp $ */ -/* $NetBSD: util.c,v 1.2 1996/03/03 17:28:41 thorpej Exp $ */ +/* $OpenBSD: util.c,v 1.3 1996/04/21 23:40:28 deraadt Exp $ */ +/* $NetBSD: util.c,v 1.4 1996/03/17 11:50:16 cgd Exp $ */ -/* +/* * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -60,7 +60,7 @@ static void nomem __P((void)); static void vxerror __P((const char *, int, const char *, va_list)); -/* +/* * Malloc, with abort on error. */ void * @@ -74,7 +74,7 @@ emalloc(size) return (p); } -/* +/* * Realloc, with abort on error. */ void * @@ -120,10 +120,11 @@ path(file) static struct nvlist *nvhead; struct nvlist * -newnv(name, str, ptr, i) +newnv(name, str, ptr, i, next) const char *name, *str; void *ptr; int i; + struct nvlist *next; { register struct nvlist *nv; @@ -131,7 +132,7 @@ newnv(name, str, ptr, i) nv = emalloc(sizeof(*nv)); else nvhead = nv->nv_next; - nv->nv_next = NULL; + nv->nv_next = next; nv->nv_name = name; if (ptr == NULL) nv->nv_str = str; diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c index cbd802895f2..454ac052562 100644 --- a/usr.sbin/edquota/edquota.c +++ b/usr.sbin/edquota/edquota.c @@ -42,7 +42,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)edquota.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: edquota.c,v 1.4 1996/01/07 05:28:04 deraadt Exp $"; +static char *rcsid = "$Id: edquota.c,v 1.5 1996/04/21 23:40:32 deraadt Exp $"; #endif /* not lint */ /* @@ -87,7 +87,8 @@ main(argc, argv) extern int optind; register long id, protoid; register int quotatype, tmpfd; - char *protoname, ch; + char *protoname; + int ch; int tflag = 0, pflag = 0; if (argc < 2) @@ -97,7 +98,7 @@ main(argc, argv) exit(1); } quotatype = USRQUOTA; - while ((ch = getopt(argc, argv, "ugtp:")) != EOF) { + while ((ch = getopt(argc, argv, "ugtp:")) != -1) { switch(ch) { case 'p': protoname = optarg; diff --git a/usr.sbin/gspa/gspahextoc/Makefile b/usr.sbin/gspa/gspahextoc/Makefile index f0b26756dde..af3c76f0c9a 100644 --- a/usr.sbin/gspa/gspahextoc/Makefile +++ b/usr.sbin/gspa/gspahextoc/Makefile @@ -2,5 +2,6 @@ PROG= gspahextoc SRCS= gspahextoc.l NOMAN= noman LDADD= -ll +DPADD= ${LIBL} .include diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c index 734871cc68e..037851a05ff 100644 --- a/usr.sbin/lpr/lpr/lpr.c +++ b/usr.sbin/lpr/lpr/lpr.c @@ -1,3 +1,6 @@ +/* $OpenBSD: lpr.c,v 1.2 1996/04/21 23:40:42 deraadt Exp $ */ +/* $NetBSD: lpr.c,v 1.10 1996/03/21 18:12:25 jtc Exp $ */ + /* * Copyright (c) 1983, 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -112,7 +115,7 @@ static int test __P((char *)); uid_t uid, euid; -void +int main(argc, argv) int argc; char *argv[]; diff --git a/usr.sbin/lpr/lptest/lptest.c b/usr.sbin/lpr/lptest/lptest.c index 5ce80b5d4fa..7916eb5c240 100644 --- a/usr.sbin/lpr/lptest/lptest.c +++ b/usr.sbin/lpr/lptest/lptest.c @@ -1,3 +1,6 @@ +/* $OpenBSD: lptest.c,v 1.2 1996/04/21 23:40:46 deraadt Exp $ */ +/* $NetBSD: lptest.c,v 1.5 1996/03/21 18:13:20 jtc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -48,7 +51,7 @@ static char sccsid[] = "@(#)lptest.c 8.1 (Berkeley) 6/6/93"; /* * lptest -- line printer test program (and other devices). */ -void +int main(argc, argv) int argc; char **argv; diff --git a/usr.sbin/lpr/pac/pac.c b/usr.sbin/lpr/pac/pac.c index fb0bf675650..ac8abc21374 100644 --- a/usr.sbin/lpr/pac/pac.c +++ b/usr.sbin/lpr/pac/pac.c @@ -1,3 +1,6 @@ +/* $OpenBSD: pac.c,v 1.3 1996/04/21 23:40:48 deraadt Exp $ */ +/* $NetBSD: pac.c,v 1.7 1996/03/21 18:21:20 jtc Exp $ */ + /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -100,7 +103,7 @@ static struct hent *lookup __P((char [])); static int qucmp __P((const void *, const void *)); static void rewrite __P((void)); -void +int main(argc, argv) int argc; char **argv; diff --git a/usr.sbin/named/dig/Makefile b/usr.sbin/named/dig/Makefile index 4c8e492136d..c16b9a6dfbd 100644 --- a/usr.sbin/named/dig/Makefile +++ b/usr.sbin/named/dig/Makefile @@ -1,12 +1,14 @@ -# $NetBSD: Makefile,v 1.1 1996/02/02 15:26:15 mrg Exp $ +# $NetBSD: Makefile,v 1.2 1996/03/31 13:55:34 mrg Exp $ # from: $Id: Makefile,v 8.1 1994/12/15 06:23:45 vixie Exp .PATH: ${.CURDIR}/../nslookup \ - ${.CURDIR}/../man + ${.CURDIR}/../man \ + ${.CURDIR}/../../../lib/libc/net PROG= dig -SRCS= dig.c list.c subr.c debug.c send.c -CFLAGS+= -I${.CURDIR}/.. +SRCS= dig.c list.c subr.c debug.c send.c gethostnamadr.c res_init.c \ + res_mkquery.c res_query.c res_send.c +CFLAGS+= -I${.CURDIR}/.. -DDEBUG .include .include "../../Makefile.inc" diff --git a/usr.sbin/named/named-xfer/named-xfer.c b/usr.sbin/named/named-xfer/named-xfer.c index 8df110816e7..98363bc2c8a 100644 --- a/usr.sbin/named/named-xfer/named-xfer.c +++ b/usr.sbin/named/named-xfer/named-xfer.c @@ -1,4 +1,4 @@ -/* $NetBSD: named-xfer.c,v 1.1 1996/02/02 15:29:42 mrg Exp $ */ +/* $NetBSD: named-xfer.c,v 1.2 1996/03/21 18:24:16 jtc Exp $ */ /* * The original version of xfer by Kevin Dunlap. @@ -139,7 +139,7 @@ static const char *soa_zinfo __P((struct zoneinfo *, u_char *, u_char*)); extern char *optarg; extern int optind, getopt(); -void +int main(argc, argv) int argc; char *argv[]; diff --git a/usr.sbin/named/named/ns_main.c b/usr.sbin/named/named/ns_main.c index bd5ef38daff..5bfa26afe96 100644 --- a/usr.sbin/named/named/ns_main.c +++ b/usr.sbin/named/named/ns_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: ns_main.c,v 1.1 1996/02/02 15:28:51 mrg Exp $ */ +/* $NetBSD: ns_main.c,v 1.2 1996/03/21 18:24:11 jtc Exp $ */ #if !defined(lint) && !defined(SABER) static char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91"; @@ -159,7 +159,7 @@ usage() } /*ARGSUSED*/ -void +int main(argc, argv, envp) int argc; char *argv[], *envp[]; diff --git a/usr.sbin/pppd/Makefile b/usr.sbin/pppd/Makefile index c171acc470a..13b90421f20 100644 --- a/usr.sbin/pppd/Makefile +++ b/usr.sbin/pppd/Makefile @@ -1,4 +1,5 @@ -# $OpenBSD: Makefile,v 1.3 1996/03/25 15:55:29 niklas Exp $ +# $OpenBSD: Makefile,v 1.4 1996/04/21 23:41:13 deraadt Exp $ +# $NetBSD: Makefile,v 1.12 1996/03/19 03:03:04 jtc Exp $ PROG= pppd SRCS= main.c magic.c fsm.c lcp.c ipcp.c upap.c chap.c md5.c ccp.c \ @@ -14,6 +15,7 @@ BINOWN= root LDADD= -lutil #DPADD= ${LIBCRYPT} ${LIBUTIL} DPADD= ${LIBUTIL} -CFLAGS+= -DHAVE_PATHS_H +CFLAGS+= -I. -I${.CURDIR} -DHAVE_PATHS_H +CLEANFILES=y.tab.h grammar.c scanner.c .include diff --git a/usr.sbin/pppd/auth.c b/usr.sbin/pppd/auth.c index ca66c3cb161..458a8f90612 100644 --- a/usr.sbin/pppd/auth.c +++ b/usr.sbin/pppd/auth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth.c,v 1.2 1996/03/25 15:55:30 niklas Exp $ */ +/* $OpenBSD: auth.c,v 1.3 1996/04/21 23:41:16 deraadt Exp $ */ /* * auth.c - PPP authentication and phase control. @@ -35,7 +35,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: auth.c,v 1.2 1996/03/25 15:55:30 niklas Exp $"; +static char rcsid[] = "$OpenBSD: auth.c,v 1.3 1996/04/21 23:41:16 deraadt Exp $"; #endif #include @@ -166,7 +166,7 @@ link_down(unit) if (protp->protocol != PPP_LCP && protp->lowerdown != NULL) (*protp->lowerdown)(unit); if (protp->protocol < 0xC000 && protp->close != NULL) - (*protp->close)(unit); + (*protp->close)(unit, "LCP link down"); } num_np_open = 0; num_np_up = 0; @@ -910,7 +910,7 @@ ip_addr_check(addr, addrs) if (ptr_mask != NULL) *ptr_mask = '/'; - if (a == -1L) + if (a == 0xffffffff) syslog (LOG_WARNING, "unknown host %s in auth. address list", addrs->word); diff --git a/usr.sbin/pppd/ccp.c b/usr.sbin/pppd/ccp.c index 5effc67caf0..074ab4a70e7 100644 --- a/usr.sbin/pppd/ccp.c +++ b/usr.sbin/pppd/ccp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccp.c,v 1.2 1996/03/25 15:55:32 niklas Exp $ */ +/* $OpenBSD: ccp.c,v 1.3 1996/04/21 23:41:18 deraadt Exp $ */ /* * ccp.c - PPP Compression Control Protocol. @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: ccp.c,v 1.2 1996/03/25 15:55:32 niklas Exp $"; +static char rcsid[] = "$OpenBSD: ccp.c,v 1.3 1996/04/21 23:41:18 deraadt Exp $"; #endif #include @@ -145,8 +145,15 @@ ccp_open(unit) if (f->state != OPENED) ccp_flags_set(unit, 1, 0); - if (!ANY_COMPRESS(ccp_wantoptions[unit])) + + /* + * Find out which compressors the kernel supports before + * deciding whether to open in silent mode. + */ + ccp_resetci(f); + if (!ANY_COMPRESS(ccp_gotoptions[unit])) f->flags |= OPT_SILENT; + fsm_open(f); } diff --git a/usr.sbin/pppd/main.c b/usr.sbin/pppd/main.c index 527cb2913fd..96acea3b2a9 100644 --- a/usr.sbin/pppd/main.c +++ b/usr.sbin/pppd/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.5 1996/03/25 15:55:49 niklas Exp $ */ +/* $OpenBSD: main.c,v 1.6 1996/04/21 23:41:21 deraadt Exp $ */ /* * main.c - Point-to-Point Protocol main module @@ -20,7 +20,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: main.c,v 1.5 1996/03/25 15:55:49 niklas Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.6 1996/04/21 23:41:21 deraadt Exp $"; #endif #include @@ -139,7 +139,7 @@ struct protent *protocols[] = { NULL }; -void +int main(argc, argv) int argc; char *argv[]; @@ -1006,7 +1006,7 @@ run_program(prog, args, must_exist) /* SysV recommends a second fork at this point. */ - execve(prog, args); + execv(prog, args); if (must_exist || errno != ENOENT) syslog(LOG_WARNING, "Can't execute %s: %m", prog); _exit(-1); diff --git a/usr.sbin/pppd/options.c b/usr.sbin/pppd/options.c index fe87b40de0b..6ed99da6de8 100644 --- a/usr.sbin/pppd/options.c +++ b/usr.sbin/pppd/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.2 1996/03/25 15:55:51 niklas Exp $ */ +/* $OpenBSD: options.c,v 1.3 1996/04/21 23:41:23 deraadt Exp $ */ /* * options.c - handles option processing for PPP. @@ -20,7 +20,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: options.c,v 1.2 1996/03/25 15:55:51 niklas Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.3 1996/04/21 23:41:23 deraadt Exp $"; #endif #include @@ -178,6 +178,7 @@ static int setipcpaccl __P((void)); static int setipcpaccr __P((void)); static int setlcpechointv __P((char **)); static int setlcpechofails __P((char **)); +static int noccp __P((void)); static int setbsdcomp __P((char **)); static int setnobsdcomp __P((void)); static int setdeflate __P((char **)); @@ -296,6 +297,7 @@ static struct cmd { {"chap-interval", 1, setchapintv}, /* Set interval for rechallenge */ {"ipcp-accept-local", 0, setipcpaccl}, /* Accept peer's address for us */ {"ipcp-accept-remote", 0, setipcpaccr}, /* Accept peer's address for it */ + {"-ccp", 0, noccp}, /* Disable CCP negotiation */ {"bsdcomp", 1, setbsdcomp}, /* request BSD-Compress */ {"-bsdcomp", 0, setnobsdcomp}, /* don't allow BSD-Compress */ {"deflate", 1, setdeflate}, /* request Deflate compression */ @@ -1761,6 +1763,13 @@ setchapintv(argv) return int_option(*argv, &chap[0].chal_interval); } +static int +noccp() +{ + ccp_protent.enabled_flag = 0; + return 1; +} + static int setbsdcomp(argv) char **argv; diff --git a/usr.sbin/pppd/pppd.8 b/usr.sbin/pppd/pppd.8 index db7abfd61ee..1d140bfef63 100644 --- a/usr.sbin/pppd/pppd.8 +++ b/usr.sbin/pppd/pppd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pppd.8,v 1.3 1996/03/25 15:55:54 niklas Exp $ +.\" $OpenBSD: pppd.8,v 1.4 1996/04/21 23:41:26 deraadt Exp $ .\" manual page [] for pppd 2.0 .\" SH section heading .\" SS subsection heading @@ -208,6 +208,13 @@ compression in the corresponding direction. Disables BSD-Compress compression; \fBpppd\fR will not request or agree to compress packets using the BSD-Compress scheme. .TP +.B -ccp +Disable CCP (Compression Control Protocol) negotiation. This option +should only be required if the peer is buggy and gets confused by +requests from +.I pppd +for CCP negotiation. +.TP .B +chap Require the peer to authenticate itself using CHAP [Cryptographic Handshake Authentication Protocol] authentication. diff --git a/usr.sbin/pppd/pppstats/pppstats.c b/usr.sbin/pppd/pppstats/pppstats.c index fc6a541bcc8..21c79f4d2a0 100644 --- a/usr.sbin/pppd/pppstats/pppstats.c +++ b/usr.sbin/pppd/pppstats/pppstats.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pppstats.c,v 1.2 1996/03/25 15:56:05 niklas Exp $ */ +/* $OpenBSD: pppstats.c,v 1.3 1996/04/21 23:41:32 deraadt Exp $ */ /* * print PPP statistics: @@ -30,7 +30,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: pppstats.c,v 1.2 1996/03/25 15:56:05 niklas Exp $"; +static char rcsid[] = "$OpenBSD: pppstats.c,v 1.3 1996/04/21 23:41:32 deraadt Exp $"; #endif #include @@ -118,9 +118,9 @@ get_ppp_cstats(csp) err(1, "couldn't get PPP compression stats"); } - -#define V(offset) (cur.offset - old.offset) -#define W(offset) (ccs.offset - ocs.offset) +#define MAX0(a) ((int)(a) > 0? (a): 0) +#define V(offset) MAX0(cur.offset - old.offset) +#define W(offset) MAX0(ccs.offset - ocs.offset) #define RATIO(c, i, u) ((c) == 0? 1.0: (u) / ((double)(c) + (i))) #define CRATE(x) RATIO(W(x.comp_bytes), W(x.inc_bytes), W(x.unc_bytes)) diff --git a/usr.sbin/pppd/sys-bsd.c b/usr.sbin/pppd/sys-bsd.c index d4912257164..d8891d71f41 100644 --- a/usr.sbin/pppd/sys-bsd.c +++ b/usr.sbin/pppd/sys-bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys-bsd.c,v 1.2 1996/03/25 15:55:57 niklas Exp $ */ +/* $OpenBSD: sys-bsd.c,v 1.3 1996/04/21 23:41:29 deraadt Exp $ */ /* * sys-bsd.c - System-dependent procedures for setting up @@ -23,7 +23,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: sys-bsd.c,v 1.2 1996/03/25 15:55:57 niklas Exp $"; +static char rcsid[] = "$OpenBSD: sys-bsd.c,v 1.3 1996/04/21 23:41:29 deraadt Exp $"; #endif /* @@ -78,6 +78,7 @@ static unsigned char inbuf[512]; /* buffer for chars read from loopback */ static int sockfd; /* socket for doing interface ioctls */ static int if_is_up; /* the interface is currently up */ +static u_int32_t ifaddrs[2]; /* local and remote addresses we set */ static u_int32_t default_route_gateway; /* gateway addr for default route */ static u_int32_t proxy_arp_addr; /* remote addr for proxy arp */ @@ -122,7 +123,8 @@ sys_cleanup() ioctl(sockfd, SIOCSIFFLAGS, &ifr); } } - + if (ifaddrs[0] != 0) + cifaddr(0, ifaddrs[0], ifaddrs[1]); if (default_route_gateway) cifdefaultroute(0, default_route_gateway); if (proxy_arp_addr) @@ -983,6 +985,8 @@ sifaddr(u, o, h, m) syslog(LOG_WARNING, "Couldn't set interface address: Address already exists"); } + ifaddrs[0] = o; + ifaddrs[1] = h; return 1; } @@ -997,6 +1001,7 @@ cifaddr(u, o, h) { struct ifaliasreq ifra; + ifaddrs[0] = 0; strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); SET_SA_FAMILY(ifra.ifra_addr, AF_INET); ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o; diff --git a/usr.sbin/quotaon/quotaon.c b/usr.sbin/quotaon/quotaon.c index c3267a989a9..bb0fdc0aeb0 100644 --- a/usr.sbin/quotaon/quotaon.c +++ b/usr.sbin/quotaon/quotaon.c @@ -42,7 +42,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)quotaon.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: quotaon.c,v 1.4 1996/01/07 05:28:05 deraadt Exp $"; +static char *rcsid = "$Id: quotaon.c,v 1.5 1996/04/21 23:41:36 deraadt Exp $"; #endif /* not lint */ /* @@ -69,11 +69,12 @@ main(argc, argv) char **argv; { register struct fstab *fs; - char ch, *qfnp, *whoami, *rindex(); + char *qfnp, *whoami, *rindex(); long argnum, done = 0; int i, offmode = 0, errs = 0; extern char *optarg; extern int optind; + int ch; whoami = rindex(*argv, '/') + 1; if (whoami == (char *)1) @@ -85,7 +86,7 @@ main(argc, argv) whoami); exit(1); } - while ((ch = getopt(argc, argv, "avug")) != EOF) { + while ((ch = getopt(argc, argv, "avug")) != -1) { switch(ch) { case 'a': aflag++; diff --git a/usr.sbin/rarpd/rarpd.c b/usr.sbin/rarpd/rarpd.c index 6b7a0f7d2c7..fc875e0cd45 100644 --- a/usr.sbin/rarpd/rarpd.c +++ b/usr.sbin/rarpd/rarpd.c @@ -1,3 +1,6 @@ +/* $OpenBSD: rarpd.c,v 1.3 1996/04/21 23:41:38 deraadt Exp $ */ +/* $NetBSD: rarpd.c,v 1.12 1996/03/21 18:28:23 jtc Exp $ */ + /* * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -25,8 +28,7 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char rcsid[] = -"@(#) $Id: rarpd.c,v 1.2 1995/11/15 07:04:09 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: rarpd.c,v 1.3 1996/04/21 23:41:38 deraadt Exp $"; #endif @@ -100,7 +102,7 @@ int aflag = 0; /* listen on "all" interfaces */ int dflag = 0; /* print debugging messages */ int fflag = 0; /* don't fork */ -void +int main(argc, argv) int argc; char **argv; diff --git a/usr.sbin/rdate/rdate.8 b/usr.sbin/rdate/rdate.8 index 1492764717a..4d140d9dbf0 100644 --- a/usr.sbin/rdate/rdate.8 +++ b/usr.sbin/rdate/rdate.8 @@ -1,5 +1,5 @@ -.\" $OpenBSD: rdate.8,v 1.3 1996/03/25 15:56:09 niklas Exp $ -.\" $NetBSD: rdate.8,v 1.3 1996/02/22 06:59:17 thorpej Exp $ +.\" $OpenBSD: rdate.8,v 1.4 1996/04/21 23:41:41 deraadt Exp $ +.\" $NetBSD: rdate.8,v 1.4 1996/04/08 20:55:17 jtc Exp $ .\" .\" Copyright (c) 1994 Christos Zoulas .\" All rights reserved. @@ -44,7 +44,7 @@ displays and sets the local date and time from the host name or address given as the argument. It uses the RFC868 protocol which is usually implemented as a built-in service of -.Xr inetd 1 +.Xr inetd 1 . .Pp Available options: .Pp @@ -59,5 +59,5 @@ Use the call to gradually skew the local time to the remote time rather than just hopping. .Sh SEE ALSO -.Xr inetd 1 +.Xr inetd 1 , .Xr adjtime 2 diff --git a/usr.sbin/rdate/rdate.c b/usr.sbin/rdate/rdate.c index 77353e392fb..25e90fe7959 100644 --- a/usr.sbin/rdate/rdate.c +++ b/usr.sbin/rdate/rdate.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rdate.c,v 1.3 1996/03/25 15:56:10 niklas Exp $ */ -/* $NetBSD: rdate.c,v 1.3 1996/02/22 06:59:18 thorpej Exp $ */ +/* $OpenBSD: rdate.c,v 1.4 1996/04/21 23:41:42 deraadt Exp $ */ +/* $NetBSD: rdate.c,v 1.4 1996/03/16 12:37:45 pk Exp $ */ /* * Copyright (c) 1994 Christos Zoulas @@ -42,7 +42,7 @@ #if 0 from: static char rcsid[] = "$NetBSD: rdate.c,v 1.3 1996/02/22 06:59:18 thorpej Exp $"; #else -static char rcsid[] = "$OpenBSD: rdate.c,v 1.3 1996/03/25 15:56:10 niklas Exp $"; +static char rcsid[] = "$OpenBSD: rdate.c,v 1.4 1996/04/21 23:41:42 deraadt Exp $"; #endif #endif /* lint */ @@ -172,7 +172,7 @@ main(argc, argv) if (slidetime) (void) fprintf(stdout, "%s: adjust local clock by %d seconds\n", - adjustment); + __progname, adjustment); } return 0; } diff --git a/usr.sbin/repquota/repquota.c b/usr.sbin/repquota/repquota.c index 0715aae99a3..ec07841efe4 100644 --- a/usr.sbin/repquota/repquota.c +++ b/usr.sbin/repquota/repquota.c @@ -42,7 +42,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)repquota.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: repquota.c,v 1.4 1996/01/07 05:28:06 deraadt Exp $"; +static char *rcsid = "$Id: repquota.c,v 1.5 1996/04/21 23:41:45 deraadt Exp $"; #endif /* not lint */ /* @@ -88,9 +88,10 @@ main(argc, argv) long i, argnum, done = 0; extern char *optarg; extern int optind; - char ch, *qfnp; + char *qfnp; + int ch; - while ((ch = getopt(argc, argv, "aguv")) != EOF) { + while ((ch = getopt(argc, argv, "aguv")) != -1) { switch(ch) { case 'a': aflag++; diff --git a/usr.sbin/rpc.bootparamd/bootparamd.c b/usr.sbin/rpc.bootparamd/bootparamd.c index 1bbfc2b5ce7..19204685db8 100644 --- a/usr.sbin/rpc.bootparamd/bootparamd.c +++ b/usr.sbin/rpc.bootparamd/bootparamd.c @@ -6,7 +6,7 @@ * Various small changes by Theo de Raadt * Parser rewritten (adding YP support) by Roland McGrath * - * $Id: bootparamd.c,v 1.1.1.1 1995/10/18 08:48:05 deraadt Exp $ + * $Id: bootparamd.c,v 1.2 1996/04/21 23:41:48 deraadt Exp $ */ #include @@ -67,7 +67,7 @@ main(argc, argv) struct hostent *he; struct stat buf; char *optstring; - char c; + int c; progname = rindex(argv[0], '/'); if (progname) @@ -75,7 +75,7 @@ main(argc, argv) else progname = argv[0]; - while ((c = getopt(argc, argv, "dsr:f:")) != EOF) + while ((c = getopt(argc, argv, "dsr:f:")) != -1) switch (c) { case 'd': debug = 1; diff --git a/usr.sbin/rpc.pcnfsd/pcnfsd_print.c b/usr.sbin/rpc.pcnfsd/pcnfsd_print.c index 397805f2bff..4b3394cebba 100644 --- a/usr.sbin/rpc.pcnfsd/pcnfsd_print.c +++ b/usr.sbin/rpc.pcnfsd/pcnfsd_print.c @@ -170,7 +170,7 @@ mode_t oldmask; oldmask = umask(0); (void)mkdir(sp_name, dir_mode); /* ignore the return code */ rc = mkdir(pathname, dir_mode); /* DON'T ignore this return code */ - umask(oldmak); + umask(oldmask); if((rc < 0 && errno != EEXIST) || (stat(pathname, &statbuf) != 0) || !(statbuf.st_mode & S_IFDIR)) { @@ -316,7 +316,7 @@ char scratch[512]; */ (void)sprintf(tempstr, "rpc.pcnfsd: ps630 filter disabled for %s\n", pathname); - msg_out(tmpstr); + msg_out(tempstr); return(PS_RES_FAIL); } /* diff --git a/usr.sbin/sa/main.c b/usr.sbin/sa/main.c index c42482e2d11..331596b9cd5 100644 --- a/usr.sbin/sa/main.c +++ b/usr.sbin/sa/main.c @@ -33,7 +33,7 @@ static char copright[] = "@(#) Copyright (c) 1994 Christopher G. Demetriou\n\ All rights reserved.\n"; -static char rcsid[] = "$Id: main.c,v 1.1.1.1 1995/10/18 08:48:07 deraadt Exp $"; +static char rcsid[] = "$Id: main.c,v 1.2 1996/04/21 23:41:57 deraadt Exp $"; #endif /* @@ -79,7 +79,7 @@ main(argc, argv) int argc; char **argv; { - char ch; + int ch; int error; while ((ch = getopt(argc, argv, "abcdDfijkKlmnqrstuv:")) != -1) diff --git a/usr.sbin/spray/Makefile b/usr.sbin/spray/Makefile index 60d8b8e766b..cd4cd737c3d 100644 --- a/usr.sbin/spray/Makefile +++ b/usr.sbin/spray/Makefile @@ -1,7 +1,8 @@ -# $Id: Makefile,v 1.1.1.1 1995/10/18 08:48:21 deraadt Exp $ +# $OpenBSD: Makefile,v 1.2 1996/04/21 23:42:04 deraadt Exp $ PROG= spray MAN= spray.8 -LDADD= -lrpcsvc +LDADD+= -lrpcsvc +DPADD+= ${LIBRPCSVC} .include diff --git a/usr.sbin/timed/timed/correct.c b/usr.sbin/timed/timed/correct.c index ec00df17889..701b57605cb 100644 --- a/usr.sbin/timed/timed/correct.c +++ b/usr.sbin/timed/timed/correct.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)correct.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.1.1.1 $" +#ident "$Revision: 1.2 $" #endif #include "globals.h" @@ -58,7 +58,7 @@ correct(long avdelta) { struct hosttbl *htp; int corr; - struct timeval adjlocal; + struct timeval adjlocal, tmptv; struct tsp to; struct tsp *answer; @@ -76,11 +76,17 @@ correct(long avdelta) || corr >= MAXADJ*1000 || corr <= -MAXADJ*1000) { htp->need_set = 0; - (void)gettimeofday(&to.tsp_time,0); - timeradd(&to.tsp_time, &adjlocal, &to.tsp_time); + (void)gettimeofday(&tmptv,0); + timeradd(&tmptv, &adjlocal, &tmptv); + to.tsp_time.tv_sec = tmptv.tv_sec; + to.tsp_time.tv_usec = tmptv.tv_usec; to.tsp_type = TSP_SETTIME; } else { - mstotvround(&to.tsp_time, corr); + tmptv.tv_sec = to.tsp_time.tv_sec ; + tmptv.tv_usec = to.tsp_time.tv_usec ; + mstotvround(&tmptv, corr); + to.tsp_time.tv_sec = tmptv.tv_sec; + to.tsp_time.tv_usec = tmptv.tv_usec; to.tsp_type = TSP_ADJTIME; } (void)strcpy(to.tsp_name, hostname); diff --git a/usr.sbin/timed/timed/master.c b/usr.sbin/timed/timed/master.c index a77e6edbf44..51f8f407306 100644 --- a/usr.sbin/timed/timed/master.c +++ b/usr.sbin/timed/timed/master.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)master.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.1.1.1 $" +#ident "$Revision: 1.2 $" #endif #include "globals.h" @@ -367,7 +367,7 @@ mchgdate(struct tsp *msg) { char tname[MAXHOSTNAMELEN]; char olddate[32]; - struct timeval otime, ntime; + struct timeval otime, ntime, tmptv; (void)strcpy(tname, msg->tsp_name); @@ -394,7 +394,9 @@ mchgdate(struct tsp *msg) logwtmp(&otime, &msg->tsp_time); #else logwtmp("|", "date", ""); - (void)settimeofday(&msg->tsp_time, 0); + tmptv.tv_sec = msg->tsp_time.tv_sec; + tmptv.tv_usec = msg->tsp_time.tv_usec; + (void)settimeofday(&tmptv, 0); logwtmp("}", "date", ""); #endif /* sgi */ spreadtime(); @@ -500,6 +502,7 @@ spreadtime() struct hosttbl *htp; struct tsp to; struct tsp *answer; + struct timeval tmptv; /* Do not listen to the consensus after forcing the time. This is because * the consensus takes a while to reach the time we are dictating. @@ -508,7 +511,9 @@ spreadtime() for (htp = self.l_fwd; htp != &self; htp = htp->l_fwd) { to.tsp_type = TSP_SETTIME; (void)strcpy(to.tsp_name, hostname); - (void)gettimeofday(&to.tsp_time, 0); + (void)gettimeofday(&tmptv, 0); + to.tsp_time.tv_sec = tmptv.tv_sec; + to.tsp_time.tv_usec = tmptv.tv_usec; answer = acksend(&to, &htp->addr, htp->name, TSP_ACK, 0, htp->noanswer); if (answer == 0) { @@ -766,7 +771,7 @@ newslave(struct tsp *msg) { struct hosttbl *htp; struct tsp *answer, to; - struct timeval now; + struct timeval now, tmptv; if (!fromnet || fromnet->status != MASTER) return; @@ -785,7 +790,9 @@ newslave(struct tsp *msg) || now.tv_sec < fromnet->slvwait.tv_sec) { to.tsp_type = TSP_SETTIME; (void)strcpy(to.tsp_name, hostname); - (void)gettimeofday(&to.tsp_time, 0); + (void)gettimeofday(&tmptv, 0); + to.tsp_time.tv_sec = tmptv.tv_sec; + to.tsp_time.tv_usec = tmptv.tv_usec; answer = acksend(&to, &htp->addr, htp->name, TSP_ACK, 0, htp->noanswer); diff --git a/usr.sbin/timed/timed/slave.c b/usr.sbin/timed/timed/slave.c index c60491c5169..6076a94f483 100644 --- a/usr.sbin/timed/timed/slave.c +++ b/usr.sbin/timed/timed/slave.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)slave.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.1.1.1 $" +#ident "$Revision: 1.2 $" #endif #include "globals.h" @@ -76,7 +76,7 @@ slave() struct sockaddr_in taddr; char tname[MAXHOSTNAMELEN]; struct tsp *msg, to; - struct timeval ntime, wait; + struct timeval ntime, wait, tmptv; time_t tmpt; struct tsp *answer; int timeout(); @@ -295,7 +295,9 @@ loop: logwtmp(&otime, &msg->tsp_time); #else logwtmp("|", "date", ""); - (void)settimeofday(&msg->tsp_time, 0); + tmptv.tv_sec = msg->tsp_time.tv_sec; + tmptv.tv_usec = msg->tsp_time.tv_usec; + (void)settimeofday(&tmptv, 0); logwtmp("}", "date", ""); #endif /* sgi */ syslog(LOG_NOTICE, diff --git a/usr.sbin/timed/timed/timed.c b/usr.sbin/timed/timed/timed.c index 7a200909467..d568223171e 100644 --- a/usr.sbin/timed/timed/timed.c +++ b/usr.sbin/timed/timed/timed.c @@ -42,7 +42,7 @@ static char sccsid[] = "@(#)timed.c 5.1 (Berkeley) 5/11/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.1.1.1 $" +#ident "$Revision: 1.2 $" #endif /* sgi */ #define TSPTYPES @@ -147,7 +147,7 @@ main(int argc, char **argv) struct nets *nt; struct sockaddr_in server; u_short port; - char c; + int c; extern char *optarg; extern int optind, opterr; #ifdef sgi @@ -183,7 +183,7 @@ main(int argc, char **argv) #endif /* sgi */ opterr = 0; - while ((c = getopt(argc, argv, "Mtdn:i:F:G:P:")) != EOF) { + while ((c = getopt(argc, argv, "Mtdn:i:F:G:P:")) != -1) { switch (c) { case 'M': Mflag = 1;