Home | History | Annotate | only in /src/sbin
History log of /src/sbin
RevisionDateAuthorComments
 1.142 24-Feb-2025  martin Centralize the test for platforms that HAVE_EFI_RT
 1.141 24-Feb-2025  martin Restrict building of the efi userland tool to architectures providing
efi runtime serivces.
 1.140 24-Feb-2025  christos New efi program from Anon Ymous.
 1.139 06-Jun-2022  nia branches: 1.139.4;
revert bits and pieces I accidentally included in my last commit

from hannken
 1.138 06-Jun-2022  nia build system: Revert all the recent additions of MK[...] knobs that
allow conditionally disabling the building of certain user space
programs in the 'base' set.

There is not enough consensus that this is the right way and a few
people had strong objections, see source-changes-d@.
 1.137 27-May-2022  nia mk: Add a MKLFS flag for excluding the log-structured filesystem userspace
tools from the build.
 1.136 06-Apr-2022  reinoud Add the fsck_udf(8) tool to the build and release
 1.135 24-Feb-2022  mrg enable blkdiscard(8) build.
 1.134 30-Sep-2018  jmcneill Install mount_qemufwcfg everywhere instead of just x86.
 1.133 31-Jul-2018  khorben Add a port of the umb(4) driver from OpenBSD

The umb(4) driver provides support for USB MBIM (Mobile Broadband
Interface Model) devices.

MBIM devices establish connections via cellular networks such as GPRS,
UMTS, and LTE. They appear as a regular point-to-point network interface, transporting raw IP frames.

Required configuration parameters like PIN and APN have to be set with
umbctl(8), a new tool specific to this driver. The IP address is configured
automatically; the default route and DNS server information have to be set
separately.

The driver is not fully functional yet, it is therefore still marked as
experimental and disabled by default. Any help welcome to complete it!

Tested on NetBSD/amd64, with a Sierra Wireless EM7345 LTE modem on a Lenovo
ThinkPad T440s. No functional change expected otherwise.
 1.132 14-Jan-2018  christos branches: 1.132.2; 1.132.4;
Add mount_autofs
 1.131 25-Nov-2017  jmcneill Build and install mount_qemufwcfg on i386 and amd64
 1.130 27-May-2017  bouyer merge the bouyer-socketcan branch to HEAD.

CAN stands for Controller Area Network, a broadcast network used
in automation and automotive fields. For example, the NMEA2000 standard
developped for marine devices uses a CAN network as the link layer.

This is an implementation of the linux socketcan API:
https://www.kernel.org/doc/Documentation/networking/can.txt
you can also see can(4).

This adds a new socket family (AF_CAN) and protocol (PF_CAN),
as well as the canconfig(8) utility, used to set timing parameter of
CAN hardware. Also inclued is a driver for the CAN controller
found in the allwinner A20 SoC (I tested it with an Olimex lime2 board,
connected with PIC18-based CAN devices).

There is also the canloop(4) pseudo-device, which allows to use
the socketcan API without CAN hardware.

At this time the CANFD part of the linux socketcan API is not implemented.
Error frames are not implemented either. But I could get the cansend and
canreceive utilities from the canutils package to build and run with minimal
changes. tcpudmp(8) can also be used to record frames, which can be
decoded with etherreal.
 1.129 01-Jul-2016  christos branches: 1.129.4;
cgdconfig does not need crypto.
 1.128 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.127 11-Sep-2014  roy Remove rtsol(8) and rtsold(8) as their functionality is in dhcpcd(8).
Remove rtsol(8) from rc.d/network.
Add -w seconds command to ifconfig to wait for N seconds for until DAD
has finished on all addresses.
Use ifconfig -w in rc.d/network instead of a forced sleep.

As discussed on tech-net@
 1.126 25-Dec-2013  christos moved to external
 1.125 28-Oct-2013  mbalmer link luactl(8) to the build
 1.124 23-Mar-2013  christos pdisk has moved
 1.123 24-Nov-2011  ahoka branches: 1.123.6;
Import mount_chfs for CHFS.
 1.122 15-Nov-2011  riz Build and install new in-kernel iscsi initiator kernel module and associated
binaries (iscsid, iscsictl) if MKISCSI != no. Initiator can also be built
into a kernel by adding 'pseudo-device iscsi' in kernel configuration.
 1.121 29-Aug-2011  mrg branches: 1.121.2;
add the device publish daemon, written by jmcneill@.

listens on drvctl for new devices and invokes MAKEDEV for them.

missing:
- manual page
- rc.d script
- more testing

but it works well enough to make new disk nodes appear in /dev when
netbsd sees them and they're missing. you will need to make sure
you have a new /dev/MAKEDEV for this to work properly (postinstall
should handle this normally, of course.)


thanks jared!
 1.120 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.119 08-Feb-2011  haad Initial import of libdm and dmctl to tree. libdm library can be used
to access, manage and manipulate device-mapper driver. Which opens us bunch
of new possibilities like

dm-multipath device target
dm-crypt device target
dm-ccd compatibility layer

With this import I'm bringing in dmctl tool for working with dm driver ,too.
I plan to replace gpl2 licensed dmsetup command with our dmctl tool in near
feature. It can also by placed to /rescue where we was not able to put
dmsetup because of licensing problems.

With libdm in tree we can now write RUMP atf test suite for dm driver to
ensure LVM subsystem stability as time goes.

Reviewed by: blymn@ and rmind@
Oked: by no objections on tech-userlevel@
 1.118 13-Jan-2011  haad branches: 1.118.2;
Move chown from usr.sbin to sbin and chgrp from usr.bin to bin directories.
This was discussed and oked on tech-userlevel I have run full build release,
test anita cycle with this patch.
 1.117 30-Oct-2010  haad Add resize_ffs tool to build, change default behaviour to grow filesystem
to device size. Add parameter -s to specify size if user want to shrink
filesystem.

Apply some KNF, remove dead unused code.

Oked by christos@.
 1.116 10-Mar-2010  abs Relegate edlabel to use in extremely memory constrained install
ramdisks and prefer disklabel elsewhere.
Based on discussion on affected port lists (port-sparc port-sparc64
port-sun3 port-sun2 port-atari port-mvme68k).
All listed ports plus amd64 test built after change
 1.115 14-Jan-2010  pooka Descend into mount_puffs.
 1.114 18-Jul-2009  reinoud Import read-only part of the NiLFS (v2) implementation for NetBSD. It has been
tested with a DEBUG+DIAGNOSTIC+LOCKDEBUG kernel. To summerise NiLFS, i'll
repeat my posting to tech-kern here:

NiLFS stands for New implementation of Logging File System; LFS done
right they claim :) It is at version 2 now and is being developed by NTT, the
Japanese telecom company and recently put into the linux source tree. See
http://www.nilfs.org. The on-disc format is not completely frozen and i expect
at least one minor revision to come in time.

The benefits of NiLFS are build-in fine-grained checkpointing, persistent
snapshots, multiple mounts and very large file and media support. Every
checkpoint can be transformed into a snapshot and v.v. It is said to perform
very well on flash media since it is not overwriting pieces apart from a
incidental update of the superblock, but that might change. It is accompanied
by a cleaner to clean up the segments and recover lost space.

My work is not a port of the linux code; its a new implementation. Porting the
code would be more work since its very linux oriented and never written to be
ported outside linux. The goal is to be fully interchangable. The code is non
intrusive to other parts of the kernel. It is also very light-weight.

The current state of the code is read-only access to both clean and dirty
NiLFS partitions. On mounting a dirty partition it rolls forward the log to
the last checkpoint. Full read-write support is however planned!

Just as the linux code, mount_nilfs allows for the `head' to be mounted
read/write and allows multiple read-only snapshots/checkpoint mounts next to
it.

By allowing the RW mount at a different snapshot for read-write it should be
possible eventually to revert back to a previous state; i.e. try to upgrade a
system and being able to revert to the exact state prior to the upgrade.

Compared to other FS's its pretty light-weight, suitable for embedded use and
on flash media. The read-only code is currently 17kb object code on
NetBSD/i386. I doubt the read-write code will surpass the 50 or 60. Compared
this to FFS being 156kb, UDF being 84 kb and NFS being 130kb. Run-time memory
usage is most likely not very different from other uses though maybe a bit
higher than FFS.
 1.113 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.112 27-Jul-2008  joerg branches: 1.112.2;
Update build glue for dhcpcd 4.0.0rc3 and move it to
src/external/dhcpcd.

Make dhcpcd quiet by default when run from rc.
 1.111 24-May-2008  joerg Hook dhcpcd into build.
 1.110 14-May-2008  reinoud Import writing part of the UDF file system making optical media like CD's
and DVD's behave like floppy discs. Writing is supported upto and including
version 2.01; version 2.50 and 2.60 will follow.

Also extending the UDF implementation to support symbolic links and
hardlinks.

Added are the mmcformat(8) tool to format rewritable CD/DVD discs and
newfs_udf(8).

Limitations:
all operations can be performed on the file system though the
sheduling is currently optimised for archiving workloads.

mv(1)/rename(2) is currently only implemented for non-directories.
 1.109 09-Feb-2008  jmmv branches: 1.109.4; 1.109.6; 1.109.8;
Descend into modstat if MKMODULAR is set.
 1.108 09-Jan-2008  simonb Remove support for NetBSD/pc532.
 1.107 17-Nov-2007  tsutsui branches: 1.107.2;
Descend into newfs_ext2fs(8).
 1.106 29-Jun-2007  rumble branches: 1.106.4;
Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.105 01-May-2007  bouyer Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.104 06-Mar-2007  dillo Complete rename of hfsp to hfs, requested by thorpej.
 1.103 05-Mar-2007  dillo Integrate apmlabel and HFS+ file system.
 1.102 01-Mar-2007  martin Add a tool to scan disks for BSD disklabels (might be from different
archs) and add wedges for them. Similar to the kernel options
DKWEDGE_AUTODISCOVER and DKWEDGE_METHOD_BSDLABEL, and actually reusing
most of that code.

This means, for example, you can plug a sparc64 disk into an i386, run
this tool and mount the partitions (provided your kernel has the FFS_EI
option).
 1.101 15-Oct-2006  christos branches: 1.101.2;
hook in gpt
 1.100 23-Jul-2006  bouyer Add a /dev/amr* control file for amr(4) devices, which allows sending raw
commands to the controller.
Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and individual
drives).
From FreeBSD, with some adjustements by Andrew Doran and me.
 1.99 25-Feb-2006  christos remove vinum
 1.98 02-Feb-2006  reinoud Initial import of a UDF file system implementation for NetBSD.

Finally the logic glue and the set distribution lists modifications.
 1.97 29-Dec-2005  tsutsui Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.96 06-Dec-2005  skrll Remove lmcctl.
 1.95 10-Sep-2005  jmmv Initial addition of tmpfs, an efficient memory file-system. This project
was developed as part of Google's Summer of Code 2005 program. This
change adds the kernel code, the mount_tmpfs utility, a regression test
suite and does all other related changes to integrate these.

The file-system is still *experimental*. Therefore, it is disabled by
default in all kernels. However, as typically done, a commented-out
entry is added in them to ease its setup.

Note that I haven't commited the required mountd(8) changes to be able
to export tmpfs file-systems because NFS support is still very unstable
and because, before enabling it, I'd like to do some other changes.

OK'ed by my project mentor, William Studenmund (wrstuden@).
 1.94 15-Jun-2005  xtraeme Add scan_ffs(8) from OpenBSD, it was modified to support FFSv2
for NetBSD (with different blocksizes). Utility to find
FFSv1 and FFSv2 partitions on disks, useful to recover lost
disklabels.

Reviewed by christos.
 1.93 01-May-2005  lukem Test USE_INET6 instead of MKINET6 for various apps.
Part of PR 30092 from Jukka Salmi.
 1.92 23-Apr-2005  perseant Provide a resize_lfs(8), including kernel and cleaner support. The current
implementation requires the fs to be mounted while resizing. Tested in both
directions, and everything appears to work happily, but ymmv.
 1.91 10-Jan-2005  lukem branches: 1.91.2;
remove unnecessary comment
 1.90 11-Nov-2004  yamt move pf reachover makefiles into usr.sbin/pf. ok'ed by itojun.

before:
sbin/pfctl
usr.sbin/authpf
usr.sbin/spamdb
libexec/ftp-proxy
libexec/spamd
libexec/spamd-setup
libexec/spamlogd
after:
usr.sbin/pf/pfctl
usr.sbin/pf/authpf
usr.sbin/pf/spamdb
usr.sbin/pf/ftp-proxy
usr.sbin/pf/spamd
usr.sbin/pf/spamd-setup
usr.sbin/pf/spamlogd
 1.89 11-Nov-2004  christos add mount_ptyfs
 1.88 19-Aug-2004  drochner +drvctl
 1.87 22-Jun-2004  itojun PF from openbsd 3.5
massage pfctl to compile/run on netbsd. put reachover makefile for pfctl
into src/sbin.
reviewed by matt, perry, christos
 1.86 03-Jan-2004  lukem Don't build cgdconfig when MKCRYPTO==no.
Fixes [bin/18552].
 1.85 07-Dec-2003  matt Make building IPv6 support controllable by MKINET6
 1.84 10-Oct-2003  grog Hook Vinum into build.
 1.83 18-Feb-2003  jdolecek add mount_smbfs(8)
 1.82 19-Jan-2003  jdolecek fix typo on mount_ext2fs line
 1.81 19-Jan-2003  jdolecek do not link all mount programs into single image; the total size difference
isn't really that huge now that these are compiled as dynamic
 1.80 23-Nov-2002  blymn Renamed the verified exec fingerprint loader.
 1.79 29-Oct-2002  blymn Added fingerprint loader tool for verified exec.
 1.78 04-Oct-2002  elric include cgdconfig(8) in the build.
 1.77 09-Jul-2002  dbj get pdisk compiling on macppc and mac68k
 1.76 09-Jan-2002  thorpej Descend into dkctl.
 1.75 10-Dec-2001  martin Move /usr/sbin/pppoectl to /sbin/pppoectl, so we can call it from
ifconfig.pppoe* files.

Rename the source directory and files to match the primary purpose
of this utility - probably noone is using this for ISDN now anymore,
as isdnd has simpler ways to acomplish the same.
 1.74 17-Aug-2001  thorpej Descend into brconfig/
 1.73 14-Feb-2001  minoura Descend to mount_* subdirs when cleandir, in addition to clean and distclean.
 1.72 16-Nov-2000  jdolecek also visit mount_* for 'make clean' and 'make distclean'
Pointed out by Minoura Makoto in private e-mail.
 1.71 13-Nov-2000  jdolecek add mount_* to SUBDIR for 'make obj', so that the obj directories get
created and used. Some ramdisks compile individual mount_* commands
directly and hence need the obj dirs setup in order to allow shared
source tree.
Noted in private mail by Andrew Brown <atatat@atatdot.net>.
 1.70 04-Nov-2000  thorpej Visit wdogctl.
 1.69 30-Oct-2000  jdolecek mount(8) now includes code for all mount_*(8) but mount_portal(8) and
mount_mfs(8); the mount_*(8) are hardlinked to mount (appropriate mount routine
is called depending on program name) - this saves approx. 1.7MB of /sbin
space
mount.c: make all local symbols static
 1.68 13-Jun-2000  itojun move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.67 15-Mar-2000  soren branches: 1.67.2;
mbrlabel moves to /sbin.
 1.66 20-Jan-2000  wrstuden Add mount_overlay.
 1.65 17-Jan-2000  itojun move sysctl to /sbin/sysctl. symlink from /usr/sbin/sysctl
is supplied for backward compatibility.

add /sbin/sysctl to base/mi (does not remove /usr/sbin/sysctl
as we have a symlink)
 1.64 23-Nov-1999  mrg move rcorder to sbin.
 1.63 20-Nov-1999  lukem add newbtconf (missed by darrenr)
 1.62 01-Oct-1999  perseant Working version of aborted dump{,_lfs} join.
 1.61 30-Sep-1999  perseant Undo broken dump{,_lfs} changes, part 2.
 1.60 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.59 02-Jul-1999  itojun branches: 1.59.2;
rtsol: Throw IPv6 router solicitation to request autoconfiguration
(to be used on end host).
 1.58 01-Jul-1999  itojun ping for IPv6. try
ping6 ::1
on you node.
 1.57 06-May-1999  christos Add mount_ntfs
 1.56 25-Mar-1999  explorer Enable lmcctl
 1.55 18-Mar-1999  thorpej Goodbye: newlfs
Hello: newfs_lfs, fsck_lfs
 1.54 30-Jan-1999  veego Add the ldconfig SUBDIR for all platforms so ldconfig(8) is available on
a shared /usr/share directory.
src/sbin/ldconfig/Makefile has allready an check to build the ldconfig
programm only on a.out platforms.
 1.53 28-Dec-1998  hannken Add subdir wsconsctl.
 1.52 15-Dec-1998  pk Build ldconfig on non-ELF platforms.
 1.51 15-Dec-1998  ws Typo
 1.50 19-Nov-1998  kenh wdctl -> atactl
 1.49 19-Nov-1998  kenh Build wdctl(8).
 1.48 13-Nov-1998  oster Added raidctl to the list of things to build.
 1.47 15-Oct-1998  thorpej Build scsictl.
 1.46 14-Aug-1998  mark Added mount_filecore.
 1.45 13-Oct-1997  explorer compile rndctl
 1.44 23-Jul-1997  mikel alphabetize
 1.43 23-Jun-1997  veego quotacheck has MOVED to usr.sbin.
 1.42 23-Jun-1997  mrg move man pages into share/man.
 1.41 20-Jun-1997  pk `dump', `dumplfs' and `quotacheck' have moved to /usr/sbin
 1.40 13-Jun-1997  thorpej Remove swapon, add swapctl
 1.39 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.38 12-Apr-1997  mrg ipf is now in usr.sbin/ipf/ipf
 1.37 31-Mar-1997  jonathan Update sbin and usr.sbin Makefiles for mountd, nfsd, nfsiod in /usr/sbin.
 1.36 29-Mar-1997  thorpej Build fdisk on the PowerPC.
 1.35 07-Mar-1997  christos Added fsirand
 1.34 01-Mar-1997  christos Added newfs_msdos
 1.33 08-Jan-1997  veego Add ipf.
 1.32 23-Sep-1996  christos Put fsck back.
 1.31 28-May-1996  mrg sparc uses edlabel also.
 1.30 27-May-1996  leo Atari also uses edlabel.
 1.29 14-May-1996  ws branches: 1.29.4;
Add fsck utility for msdosfs
 1.28 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.27 30-Mar-1996  cgd since the only difference between the old 'savecore' and the new one
is savecore.c, move it back into the 'savecore' dir (renamed as
savecore_old.c) so that the build is more 'normal,' and more like what
it used to be.
 1.26 16-Mar-1996  leo New libkvm/savecore implementation. With the following differences:
1) savecore will not access the dump or live-kernel directly. It
will always use the kvm-functions. Allowing it to work on kernels
that don't have a 1-1 PA-VA mapping.
2) the kvm-lib has some additional functions to accomplish 1
- kvm_dump_mkheader()
- kvm_dump_wrtheader()
- kvm_dump_inval()
3) the file formats of the dump generated by the kernel and the dump
generated by savecore have been changed. The file format now looks
like the format produced for 'normal' core dumps.
Ports not yet supporting the new kvm-format will be using libkvm.old/
savecore.old for the time being.
 1.25 10-Oct-1995  gwr Fix my typo
 1.24 09-Oct-1995  thorpej Build fsdb(8).
 1.23 08-Oct-1995  gwr On the sun3, add SUBDIR+= edlabe
 1.22 17-Aug-1995  thorpej Build ccdconfig.
 1.21 12-Jul-1995  cgd add mount_ffs(8). reorganize, to seperate the file system mount commands,
and to make it more clear what programs are dependent on a particular file
systems's format.
 1.20 18-Mar-1995  cgd halt(8) has been assimilated (into reboot(8)).
 1.19 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.18 08-Jun-1994  mycroft Various.
 1.17 03-Jun-1994  chopps add mount_ados
 1.16 22-Apr-1994  cgd add bim
 1.15 30-Mar-1994  cgd add ttyflags
 1.14 12-Jan-1994  cgd new mount_ programs
 1.13 03-Nov-1993  cgd chown no longer here
 1.12 24-Aug-1993  cgd little point in having mount_procfs if you don't make it...
 1.11 31-Jul-1993  mycroft Add RCS indentifiers.
 1.10 28-Jul-1993  cgd incorporate changes from 0-9-base to 0-9-ALPHA
 1.9 07-Jun-1993  cgd branches: 1.9.2;
add support for terry lambert's loadable kernel modules.
needs a bit of cleanup, but overall: SLICK!
 1.8 09-Apr-1993  cgd fixed bug that i created when updating for new entries
 1.7 09-Apr-1993  cgd added mount_pcfs, quotacheck, and fdisk. fdisk is i386 specific.
(patch 111)
 1.6 05-Apr-1993  cgd moved chown into sbin from usr.sbin
 1.5 28-Mar-1993  cgd merged mount_fdesc and mount_kernfs into mount_miscfs
 1.4 23-Mar-1993  cgd added support for mount_kernfs and mount_fdesc
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Jul-1997  mikel import 4.4BSD-Lite2 versions
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.2.2 20-Jul-1993  cgd break mount_miscfs into mount_kernfs and mount_fdesc
 1.9.2.1 20-Jul-1993  cgd note mount_pcfs -> mount_msdos change
 1.29.4.2 28-Jun-1996  jtc Backslashes don't seem to work in make conditionals
 1.29.4.1 28-Jun-1996  jtc Pulled up from rev 1.31 by request from Leo Weppelman
 1.59.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.67.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.91.2.4 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.91.2.3 11-Aug-2006  riz Pull up following revision(s) via patch (requested by ghen in ticket #1460):
distrib/sets/lists/base/mi: revision 1.556, 1.565
distrib/sets/lists/man/mi: revision 1.792, 1.814
sbin/Makefile: revision 1.94
sbin/scan_ffs/Makefile: revision 1.1-1.3, 1.5-1.7
sbin/scan_ffs/scan_ffs.c: revision 1.1-1.9
sbin/scan_ffs/scan_ffs.8: revision 1.1-1.6 via patch
Add scan_ffs(8) from OpenBSD, modified for NetBSD to support FFSv2 and
LFS (scan_lfs(8)). Utility to find FFSv1, FFSv2 and LFS partitions on
disks, useful to recover lost disklabels.
 1.91.2.2 30-Jul-2006  tron Apply patch (requested by bouyer in ticket #1431):
- Add a /dev/amr* control file for amr(4) devices, which allows sending
raw commands to the controller.
- Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and
individual drives).
 1.91.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.101.2.1 08-May-2007  pavel Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.106.4.2 23-Mar-2008  matt sync with HEAD
 1.106.4.1 09-Jan-2008  matt sync with HEAD
 1.107.2.3 18-Feb-2008  mjf Add some devfs code that's been sitting in my local tree for a while.

devfsd(8) is now the first daemon to be started after init(8). It tracks
device insertion (will eventually track removal) and devfs mounts.

Currently, we can mount multiple device file systems and have device
special files pushed into the mounts automatically, though, the device
special files aren't created with the correct major/minor number pairs
yet.

More work to come soon.
 1.107.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.107.2.1 08-Dec-2007  mjf Add devfs daemon. This daemon parses a config file which contains "rules"
that specify the attributes of device special files that will appear in
the device file system.
 1.109.8.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.109.8.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.109.6.2 04-Jun-2008  yamt sync with head
 1.109.6.1 18-May-2008  yamt sync with head.
 1.109.4.4 17-Jan-2009  mjf Sync with HEAD.
 1.109.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.109.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.109.4.1 21-Feb-2008  mjf Start where the mjf-devfs branch left off.
 1.112.2.1 18-Nov-2011  sborrill Pull up the following revisions(s) (requested by riz in ticket #1690):
distrib/sets/lists/base/mi patch
distrib/sets/lists/man/mi patch
sbin/Makefile patch
sbin/resize_ffs/Makefile patch
sbin/resize_ffs/TODO patch
sbin/resize_ffs/resize_ffs.8 patch
sbin/resize_ffs/resize_ffs.c patch

Fix resize_ffs(8) so that growing and shrinking all FFSv1
(including byteswapped) and growing FFSv2 file systems is supported.
 1.118.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.121.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.121.2.1 17-Apr-2012  yamt sync with head
 1.123.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.123.6.1 23-Jun-2013  tls resync from head
 1.129.4.1 17-Apr-2017  bouyer Add canconfig(8), an utility to configure CAN interfaces.
Compile-tested only.
 1.132.4.1 10-Jun-2019  christos Sync with HEAD
 1.132.2.2 20-Oct-2018  pgoyette Sync with head
 1.132.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.139.4.2 02-Aug-2025  perseant Sync with HEAD
 1.139.4.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.25 12-May-2024  rillig lint: suppress "used but not defined" for bin, sbin, usr.bin, usr.sbin

These diagnostics are emitted by lint2, and like all diagnostics from
lint2, they don't affect the exit status.

In libc, lint cannot handle the renamings from namespace.h, generating
many false positive diagnostics since 'libc_function' is used but
'_libc_function' is defined. Until this situation is handled properly,
suppress this diagnostic.
 1.24 20-Apr-2024  rillig {usr.,}{s,}bin: replace LINT_SUPPORTED with the standard NOLINT

While here, re-enable lint in those cases where lint was skipped due to
a bug in interpreting abstract types, which was fixed in cgram.y 1.469
from 2023-08-02.
 1.23 14-Sep-2021  rillig sbin: enable lint for almost all programs

The programs fsck_lfs and newfs_lfs both trigger a longstanding bug in
lint that is difficult to fix, so ignore them for now.

For resize_ffs, lint thinks that 'struct fs' is incomplete, but GCC and
Clang accept it. Needs further investigation.
 1.22 21-Mar-2012  matt Default to WARNS=5
 1.21 11-Apr-2009  lukem branches: 1.21.6;
Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.20 08-Oct-2006  peter branches: 1.20.28; 1.20.32;
WFORMAT is no more...
 1.19 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.18 27-Sep-2002  thorpej Revert previous; the change that required it will be done differently.
 1.17 27-Sep-2002  thorpej Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.
 1.16 27-Aug-2002  lukem Implement MKDYNAMICROOT, which currently defaults to "no", but will
be changed in the future to "yes".

If MKDYNAMICROOT == "no", there is no change from existing behaviour
of a static /bin and /sbin (and a few programs in elsewhere).

If MKDYNAMICROOT == "yes", the following changes occur:
in <bsd.own.mk>:
SHLIBDIR?= /lib
SHLINKDIR?= /lib
in various Makefiles, the following entry is DISABLED.
LDSTATIC?=-static
This results in all programs (except those "standalone" programs built
in sys/arch/*/stand) are linked dynamically, the shared linker is moved
from /usr/libexec to /lib (with a compat symlink), and the shared
libraries used by /bin and /sbin programs are moved from /usr/lib to
/lib (with compat symlinks).
 1.15 05-Dec-2001  lukem enable WARNS?=2
 1.14 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.13 02-Mar-1998  cgd branches: 1.13.2; 1.13.10;
pull bsd.own.mk in before LDSTATIC?=-static, so that LDSTATIC can be
overridden by bsd.own.mk/mk.conf.
 1.12 10-Oct-1997  mikel allow overrides of LDSTATIC, from Soren S. Jorvang in PR bin/4178
 1.11 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 30-Dec-1993  cgd get rid of *very* bogus addition to CFLAGS
 1.8 08-Nov-1993  cgd use LDSTATIC, not LDFLAGS any more
 1.7 03-Nov-1993  cgd add 'LDFLAGS+= -static'
 1.6 01-Oct-1993  mycroft Use ${.CURDIR}/.., in case we're inside an obj dir while compiling.
 1.5 07-Sep-1993  ws Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Jul-1997  mikel import 4.4BSD-Lite2 versions
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.10.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.13.2.1 10-Oct-2000  he Pull up revision 1.14 (requested by is):
Format string cleanup.
 1.20.32.1 27-Aug-2009  matt Change LDSTATIC?= -static to LDSTATIC+= -static so MKDYNAMICROOT=no works again.
 1.20.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.6.1 17-Apr-2012  yamt sync with head
 1.1 23-Jul-2006  bouyer branches: 1.1.2;
Add a /dev/amr* control file for amr(4) devices, which allows sending raw
commands to the controller.
Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and individual
drives).
From FreeBSD, with some adjustements by Andrew Doran and me.
 1.1.2.2 30-Jul-2006  tron Apply patch (requested by bouyer in ticket #1431):
- Add a /dev/amr* control file for amr(4) devices, which allows sending
raw commands to the controller.
- Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and
individual drives).
 1.1.2.1 23-Jul-2006  tron file Makefile was added on branch netbsd-3 on 2006-07-30 16:38:58 +0000
 1.4 11-Sep-2016  sevan Spelling mistake.
Bump date.
 1.3 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.2 23-Jul-2006  wiz branches: 1.2.2;
Drop trailing whitespace.
 1.1 23-Jul-2006  bouyer Add a /dev/amr* control file for amr(4) devices, which allows sending raw
commands to the controller.
Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and individual
drives).
From FreeBSD, with some adjustements by Andrew Doran and me.
 1.2.2.2 30-Jul-2006  tron Apply patch (requested by bouyer in ticket #1431):
- Add a /dev/amr* control file for amr(4) devices, which allows sending
raw commands to the controller.
- Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and
individual drives).
 1.2.2.1 23-Jul-2006  tron file amrctl.8 was added on branch netbsd-3 on 2006-07-30 16:38:58 +0000
 1.13 03-Nov-2024  rillig sbin, usr.bin, usr.sbin: remove redundant getopt declarations

No binary change, except for assertion line numbers in tprof.
 1.12 06-Sep-2020  mrg branches: 1.12.8;
avoid calling printf() %s with NULL.
 1.11 27-Aug-2018  sevan Remove reference to -c flag which was never implemented.
 1.10 23-Mar-2014  dholland branches: 1.10.18; 1.10.24; 1.10.26;
don't use sprintf
 1.9 18-May-2012  jakllsch branches: 1.9.2;
Don't exit on ioctl failure, instead let the caller handle it.
This is needed so that we can detect failure of the 40LD firmware
interface and fall back to the 8LD interface.
 1.8 18-May-2012  jakllsch Add $NetBSD$ to header, and add __RCSID.
 1.7 18-May-2012  jakllsch Use C99 fixed width integer types.
 1.6 18-May-2012  jakllsch Use err(3) instead of perror(3) + exit(3).
Additionally, use symbolic EXIT_FAILURE.
 1.5 18-May-2012  jakllsch Use __arraycount instead of identical local macro.
 1.4 18-May-2012  jakllsch constify number to string lookup tables
 1.3 27-Aug-2011  joerg branches: 1.3.2;
staticfy. Use __dead.
 1.2 16-Mar-2009  lukem fix sign-compare issues
 1.1 23-Jul-2006  bouyer branches: 1.1.2; 1.1.32;
Add a /dev/amr* control file for amr(4) devices, which allows sending raw
commands to the controller.
Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and individual
drives).
From FreeBSD, with some adjustements by Andrew Doran and me.
 1.1.32.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.1.2.2 30-Jul-2006  tron Apply patch (requested by bouyer in ticket #1431):
- Add a /dev/amr* control file for amr(4) devices, which allows sending
raw commands to the controller.
- Add a amrctl(8) control tool, which for now only allows to get status
from the adapter (status of adapter, logical volumes and and
individual drives).
 1.1.2.1 23-Jul-2006  tron file amrctl.c was added on branch netbsd-3 on 2006-07-30 16:38:59 +0000
 1.3.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.2.1 23-May-2012  yamt sync with head.
 1.9.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.26.1 10-Jun-2019  christos Sync with HEAD
 1.10.24.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.10.18.1 28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #992):

external/bsd/top/dist/top.1.in: revision 1.11
sbin/gpt/main.c: revision 1.12
sbin/amrctl/amrctl.c: revision 1.11
bin/df/df.c: revision 1.93
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.21
sbin/fsck_ext2fs/main.c: revision 1.38
bin/ksh/ksh.Man: revision 1.26
bin/ln/ln.c: revision 1.40
bin/df/df.1: revision 1.48
bin/df/df.1: revision 1.49

Document the WCPU field.

Match SYNOPSIS with usage()

-G cannot be specified alongside -i or -P.
Heads up by <leot>

Add -l to SYNOPSIS

Update usage to include -w

Match sequence as per SYNOPSIS in manual

Remove reference to -c flag which was never implemented.

Remove references to -c flag which was never included.

Add the -T flag to usage()
 1.12.8.1 02-Aug-2025  perseant Sync with HEAD
 1.2 21-Mar-2012  riz Remove ${NETBSDSRCDIR}/sys/lib/libkern from .PATH; there are no
source files from there compiled.
 1.1 05-Mar-2007  dillo branches: 1.1.1;
Initial revision
 1.1.1.1 05-Mar-2007  dillo branches: 1.1.1.1.36;
Utility to add Apple Partition Map partitions to disklabel, based
on mbrlabel.
 1.1.1.1.36.1 17-Apr-2012  yamt sync with head
 1.3 25-Jun-2007  rumble Nuke extra comma in Xrefs.
 1.2 19-May-2007  wiz Sort options. Bump date.
 1.1 05-Mar-2007  dillo branches: 1.1.1;
Initial revision
 1.1.1.1 05-Mar-2007  dillo Utility to add Apple Partition Map partitions to disklabel, based
on mbrlabel.
 1.3 19-Oct-2013  christos fix unused variable warnings.
 1.2 27-Aug-2011  joerg branches: 1.2.2; 1.2.8;
staticfy. Use __nodead
 1.1 05-Mar-2007  dillo branches: 1.1.1;
Initial revision
 1.1.1.1 05-Mar-2007  dillo Utility to add Apple Partition Map partitions to disklabel, based
on mbrlabel.
 1.2.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 24-Jul-2008  dholland Fix this to not need -Wno-pointer-sign. Make it pass -Wsign-compare too,
while I'm at it.
 1.5 21-Jul-2008  gmcgarry Add HAVE_PCC tests for -Wno-pointer-sign.
 1.4 11-May-2006  mrg branches: 1.4.20; 1.4.24;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.3 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.2 20-Jan-2005  xtraeme Kill __P(), remove main() prototype; WARNS=2
 1.1 19-Nov-1998  kenh wdctl -> atactl
 1.4.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.4.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.32 24-May-2022  andvar fix various typos in comments, docs and log messages.
 1.31 31-May-2019  wiz New sentence, new line.
 1.30 31-May-2019  mlelstv Mention SATL support.
 1.29 03-Mar-2019  mrg - smart vendor support now does try to guess the vendor,
adjust the BUGS to suit
- claim some copyright
 1.28 05-Dec-2018  wiz Remove trailing whitespace.
 1.27 05-Dec-2018  mrg "smart status" already obtains the ata parameters to check if smart
is actually supported, so we can attempt to guess a vendor smart
table from the model name. add basic support for all the micron /
crucial disk names i could find, and add a couple more micron
specific values.

XXX: probably should add regex support for matching, and probably
should be more restrictive with the current matches.
 1.26 03-Nov-2018  wiz Use more appropriate macros. Make a sentence easier to read.
 1.25 31-Oct-2018  mrg extend "smart status" command to "smart status [vendor]", and supply a
"Micron" (for Micron/Crucial) list with their documented values.

this allows the vendor-specific data to be used.

there appears to be no simple way to automatically determine the right
vendor to use -- identify data seems to be the only obvious way and
that data can be and is changed by OEMs. (eg, a disk may be listed as
being "dell", but dell don't make disks.) as such, no attempt is made
to automatically determine if a vendor list should be used.
 1.24 09-Jan-2013  riastradh branches: 1.24.28; 1.24.30;
Add some ATA SECURITY commands to atactl(8).
 1.23 30-Apr-2008  martin branches: 1.23.20; 1.23.26;
Convert TNF licenses to new 2 clause variant
 1.22 18-Nov-2007  christos branches: 1.22.8; 1.22.10;
From Marco Trillo (marcotrillo at gmail dot com):
Add Advanced power management in atactl(8)
 1.21 12-Apr-2005  wiz branches: 1.21.10;
Improve formatting.
 1.20 12-Apr-2005  drochner document the "security" command
 1.19 10-Oct-2004  wiz branches: 1.19.2;
Bump date for "offline" description.
 1.18 08-Oct-2004  soren Add offline command to usage() and man page.
 1.17 16-Sep-2004  erh Add a couple cross-references to make similar ctl commands easier to find.
 1.16 02-Aug-2004  wiz No leading zeroes in date string.
 1.15 01-Aug-2004  bouyer Add infrastructure for ATA bus commands, and implement the reset bus command.
 1.14 20-Dec-2003  lha Extend SMART status to print temperature. Add support for printing
selftest log (but no code it start selftest yet).
 1.13 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.12 06-Aug-2002  wiz Ispell. Drop .Pp before .Sh.
 1.11 06-Aug-2002  soren s/smart info/smart status/ to better fit in with the standard's feature set.
 1.10 05-Aug-2002  soren Add ATA SMART reporting support from Ben Collver in kern/12787.
 1.9 16-Nov-2001  wiz Sort sections.
 1.8 05-Jun-2001  wiz Drop arguments of .Os.
 1.7 01-Mar-2000  hubertf fix typo: he -> the
 1.6 19-Oct-1999  soren Fix pastos.
 1.5 24-Feb-1999  jwise branches: 1.5.4;
Code to check for cooked device names was failing even if it succeeded in
opening the cooked device. Also some typos.

Fixes part of PR bin/6883 from Soren S. Jorvang.
 1.4 31-Jan-1999  msaitoh s/.Ic/.Cm/
 1.3 30-Jan-1999  msaitoh Fix some roff bugs.
We should use 'Ic' for internal command.
 1.2 23-Nov-1998  kenh Implement a new command: "checkpower". Returns the current power management
mode of an ATA device.
 1.1 19-Nov-1998  kenh wdctl -> atactl
 1.5.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.2.2 15-Apr-2005  tron Pull up revision 1.21 (requested by drochner in ticket #156):
Improve formatting.
 1.19.2.1 15-Apr-2005  tron Pull up revision 1.20 (requested by drochner in ticket #156):
document the "security" command
 1.21.10.1 09-Jan-2008  matt sync with HEAD
 1.22.10.1 18-May-2008  yamt sync with head.
 1.22.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.26.1 25-Feb-2013  tls resync with head
 1.23.20.1 23-Jan-2013  yamt sync with head
 1.24.30.1 10-Jun-2019  christos Sync with HEAD
 1.24.28.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.24.28.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.86 23-Feb-2025  jakllsch atap_logical_align is already what we want, we don't have to subtract it
from the logical blocks per physical block number.
 1.85 20-Dec-2020  jmcneill branches: 1.85.8;
Managment -> Management
 1.84 07-Dec-2020  mrg micron SMART 202 is percent lifetime used not remaining.

almost gave myself a heart attack when my server said 7% remaining!
 1.83 30-May-2019  mlelstv branches: 1.83.2;
Add support for ATA command pass-through to SCSI devices.
 1.82 03-Mar-2019  mrg - smart vendor support now does try to guess the vendor,
adjust the BUGS to suit
- claim some copyright
 1.81 03-Mar-2019  mrg add a samsung specific SMART table with:

235 - POR Recovery Count
243 - SATA Downshift Count
244 - Thermal Throttle Status
245 - Timed Workload Media Wear
251 - NAND Writes

all 5 turn up on newer samsung SSDs, though 3 of them all
read 65535 for me across muliplte devices.
 1.80 01-Mar-2019  mrg add some intel specific smart values, and be more specific for
a bunch of micron/crucial values.
 1.79 05-Dec-2018  mrg "smart status" already obtains the ata parameters to check if smart
is actually supported, so we can attempt to guess a vendor smart
table from the model name. add basic support for all the micron /
crucial disk names i could find, and add a couple more micron
specific values.

XXX: probably should add regex support for matching, and probably
should be more restrictive with the current matches.
 1.78 31-Oct-2018  mrg extend "smart status" command to "smart status [vendor]", and supply a
"Micron" (for Micron/Crucial) list with their documented values.

this allows the vendor-specific data to be used.

there appears to be no simple way to automatically determine the right
vendor to use -- identify data seems to be the only obvious way and
that data can be and is changed by OEMs. (eg, a disk may be listed as
being "dell", but dell don't make disks.) as such, no attempt is made
to automatically determine if a vendor list should be used.
 1.77 04-Oct-2016  mrg branches: 1.77.12; 1.77.14;
add SMART 249: Total Raw NAND Writes (1GiB units), sourced from
intel spec sheets.
 1.76 10-May-2016  mrg branches: 1.76.2;
update the micron smart codes for 247/248 to match data i found in
micron's "TN-FD-33: M510DC SSD SMART Implementation Introduction"
document.

these two values can be used to calculate the write amplication
factor:

WAF = ( A247 + A248 ) / A247
 1.75 21-Sep-2015  mrg add smart IDs 210, 246, 247 and 248 (Micron):
+ { 210, "Successful RAIN Recovery Count", NULL },
+ { 246, "Total Host Sector Writes", NULL },
+ { 247, "Contact Factory (Micron)", NULL },
+ { 248, "Contact Factory (Micron)", NULL },

(eek i hope 247 and 248 don't move.)
 1.74 15-Oct-2014  mrg add a whole bunch of S.M.A.R.T. status i found around various sources.

now nothing on my new SSD is unknown, except #249.
 1.73 09-Dec-2013  wiz branches: 1.73.4;
Fix typo ("then" instead of "than")
 1.72 30-Oct-2013  drochner -recognize CF cards by the magic value in inquiry data
-kill CFG_ATAPI_MASK, didn't see anything in the specs supporting
that it exists
 1.71 06-Aug-2013  soren TRIM showed up sometime between ATA-7 and ATA-8.
 1.70 03-Aug-2013  soren Don't use \t to align text columns.
Add a few attribute descriptions.
 1.69 08-Feb-2013  jakllsch Decode 6Gbps signaling SATA capability in IDENTIFY DEVICE data.
 1.68 09-Jan-2013  riastradh Add some ATA SECURITY commands to atactl(8).
 1.67 19-Oct-2012  drochner Implement experimental support to pass notifications that a file
was deleted from the filesystem to the disk driver, commonly
known as "discard" or "trim".
fs/driver support is in ffs and ata wd for now.
This is what was posted here:
http://mail-index.netbsd.org/tech-kern/2012/02/28/msg012813.html
with minor cleanup, and the global switch replaced by a mount option.
 1.66 31-Oct-2011  jakllsch branches: 1.66.2; 1.66.4; 1.66.8;
Constify structure pointed to by getataparams() return value.
 1.65 31-Oct-2011  jakllsch Remove write-only variable.
 1.64 31-Oct-2011  jakllsch Wrap or shorten lines longer than 80 columns.
 1.63 24-Oct-2011  jakllsch use C99 fixed-width integer types
 1.62 24-Oct-2011  jakllsch constify
 1.61 24-Oct-2011  jakllsch change lines containing only whitespace to empty lines,
remove trailing whitespace
 1.60 27-Aug-2011  joerg staticfy. Use __dead.
 1.59 19-Jan-2011  nisimura fix mislabelled S.M.A.R.T. lifetime temperature record reading.
 1.58 14-Jan-2011  nisimura fix a mysterious indent lossage roaming around for last couple of years.
 1.57 13-Mar-2010  mrg add SMART code 187: "Reported uncorrect". from smartmontools.
 1.56 25-Jan-2010  jakllsch Add display of Long Physical Sector and Long Logical Sectors feature set
information to atactl identify output.

Also:
- remove caddr_t cast
- warn about invalid IDENTIFY data checksum (when possible)
- humanize capacity in power-of-10 format
- remove semi-pointless ATAPI check
- slightly rework command queue depth output to be less conversational
 1.55 08-Jun-2009  jakllsch Improve "identify" output slightly:
- Capitialize "Name" in World Wide Name.
- Print the World Wide Name if it exists.
- Use LBA48 maximum address when available for "total sectors" output.
- So that geometry will display on more drives, don't be as strict when
checking for non-ATAPI devices. (This seemed to be an issue on at least
one instance of a Caviar SE16 drive.)
- Check more carefully for valid/relevant queue depth before printing it.
- Increment the queue depth by one for display.

While here, wrap some long lines that I should have had wrapped before they
were commited in rev. 1.46.
 1.54 06-Jun-2009  mlelstv make space for a trailing \0 in model,revision and serial buffers.
 1.53 16-Mar-2009  lukem fix sign-compare issues
 1.52 25-Aug-2008  dholland branches: 1.52.2; 1.52.4; 1.52.8;
Add two missing SMART attributes; PR 37967 from Henry Bent. Also add a
third I found while digging around, and fix one whose name was typoed.
 1.51 24-Jul-2008  dholland Fix this to not need -Wno-pointer-sign. Make it pass -Wsign-compare too,
while I'm at it.
 1.50 28-Apr-2008  martin branches: 1.50.2;
Remove clause 3 and 4 from TNF licenses
 1.49 15-Dec-2007  perry branches: 1.49.4; 1.49.6;
replace instances of __attribute__((__packed__)) with __packed
 1.48 18-Nov-2007  christos branches: 1.48.2;
From Marco Trillo (marcotrillo at gmail dot com):
Add Advanced power management in atactl(8)
 1.47 04-Nov-2007  xtraeme Fix typo in SATA features: Perservation -> Preservation.
 1.46 21-Aug-2007  bouyer branches: 1.46.2;
Improved SATA support, from Jonathan A. Kollasch in PR bin/36772:
* use full 5-bit command queue depth that SATA supports
* decode SATA bits
 1.45 16-Oct-2006  christos add missing initializers
 1.44 24-Sep-2006  xtraeme It's WDCC_SECURITY_FREEZE not WCDD_SECURITY_FREEZE.

Noticed by Sergey Svishchev.
 1.43 23-Sep-2006  xtraeme Do not print "SMART not supported" when SMART was disabled, this
fixes PR bin/18666.
 1.42 25-Feb-2006  wiz Fix some typos.
 1.41 29-Nov-2005  dbj fix byteswap of log revision structure check, improve error printout
 1.40 29-Nov-2005  dbj add newline termination on error message
 1.39 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.38 12-Apr-2005  drochner Implement a "security" command with subcommands to query the status of
the "security" extension and to "freeze" it. With the security extension
frozen, disk passwords cannot be set anymore, until the next hard reset.
Normally, this is the business of the BIOS, but older/buggy/embedded
BIOSes don't care. This leaves the (theoretical) possibility that a
malicious program in posession of superuser rights sets a disk password,
rendering the disk useless (or at least uneconomical to recover from).
Inspired by an article in the german "ct" magazine.
Being here, consolidate the implementations of IDENTIFY into one, and
fix an obvious alignment problem.
 1.37 20-Jan-2005  xtraeme branches: 1.37.2;
Kill __P(), remove main() prototype; WARNS=2
 1.36 17-Jan-2005  dogcow Add missing SMART attribute (6, Read channel margin)
 1.35 17-Nov-2004  fvdl * don't swap the WDSMART_CYL value, it isn't needed
* swap the 16- and 32 bit fields of the SMART structures (where used)

Makes SMART commands work on big-endian systems.
 1.34 08-Oct-2004  soren Add offline command to usage() and man page.
 1.33 08-Oct-2004  mycroft Combine the listing of enabled/disabled features with the general listing of
features.
Add an "smart error-log" command to display the SMART error-log.
Add an "offline" command to run offline selftests.
 1.32 10-Sep-2004  atatat Add some more attribute "names", taken from

http://freepgs.com/smart/attributes.php

which gets them from smartmontools as maintained by Bruce Allen.

Note that some of these attributes should be "named" differently
depending on the drive (point for future work?), but at least now
there are names for some of the one that were missing them.
 1.31 10-Sep-2004  atatat White space police
 1.30 01-Aug-2004  bouyer Add infrastructure for ATA bus commands, and implement the reset bus command.
 1.29 28-Mar-2004  mycroft Print the raw SMART values always. These are important in a bunch of cases --
e.g. for the load cycle count and power-cycle count.

Also, consistently treat the raw values as unsigned.
 1.28 14-Mar-2004  wiz It's extension, not extention. From Miod Vallat (miod at online fr).
 1.27 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.26 30-Dec-2003  thorpej No longer need to include <dev/ic/wdcreg.h>
 1.25 30-Dec-2003  thorpej Don't need to include atavar.h
 1.24 20-Dec-2003  lha Extend SMART status to print temperature. Add support for printing
selftest log (but no code it start selftest yet).
 1.23 30-Nov-2003  yamt display more capabilities for "identify" command.
 1.22 21-Oct-2003  fvdl Fix various uses of NULL that should have been 0.
 1.21 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.20 13-Sep-2002  mycroft Allow the enable command if SMART is not enabled. Duh.
Also, just blindly allow the disable command.
 1.19 15-Aug-2002  soren Typo.
 1.18 15-Aug-2002  mycroft Correct the check for whether SMART is enabled.
 1.17 06-Aug-2002  soren Print symbolic names for SMART STATUS attributes.
 1.16 06-Aug-2002  soren s/smart info/smart status/ to better fit in with the standard's feature set.
 1.15 05-Aug-2002  soren Add ATA SMART reporting support from Ben Collver in kern/12787.
 1.14 07-Sep-2001  simonb Use the command set/feature *enabled* words when displaying what
command sets and features are enabled.
 1.13 07-Sep-2001  simonb ANSIfy.
 1.12 28-Aug-2001  ad errx() prints the newline for you.
 1.11 19-Feb-2001  cgd convert to use getprogname()
 1.10 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.9 13-Jul-2000  ad Back out previous two - didn't follow the code properly.
 1.8 13-Jul-2000  ad Fix previous. From Micheal Eriksson <eramore@era-t.ericsson.se>.
 1.7 06-Jul-2000  ad printf fmt string without %s, from OpenBSD.
 1.6 01-Nov-1999  soren branches: 1.6.6;
Fix typo.
 1.5 29-Oct-1999  soren Sync with scsictl: rearrange usage() and print list of commands.
 1.4 24-Feb-1999  jwise branches: 1.4.2; 1.4.4;
Code to check for cooked device names was failing even if it succeeded in
opening the cooked device. Also some typos.

Fixes part of PR bin/6883 from Soren S. Jorvang.
 1.3 23-Nov-1998  kenh Implement a new command: "checkpower". Returns the current power management
mode of an ATA device.
 1.2 20-Nov-1998  kenh Fix a warning that shows up on big-endian machines.
 1.1 19-Nov-1998  kenh wdctl -> atactl
 1.4.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.2.1 10-Oct-2000  he Pull up revision 1.10 (requested by is):
Format string cleanup.
 1.6.6.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.37.2.1 15-Apr-2005  tron Pull up revision 1.38 (requested by drochner in ticket #156):
Implement a "security" command with subcommands to query the status of
the "security" extension and to "freeze" it. With the security extension
frozen, disk passwords cannot be set anymore, until the next hard reset.
Normally, this is the business of the BIOS, but older/buggy/embedded
BIOSes don't care. This leaves the (theoretical) possibility that a
malicious program in posession of superuser rights sets a disk password,
rendering the disk useless (or at least uneconomical to recover from).
Inspired by an article in the german "ct" magazine.
Being here, consolidate the implementations of IDENTIFY into one, and
fix an obvious alignment problem.
 1.46.2.2 09-Jan-2008  matt sync with HEAD
 1.46.2.1 06-Nov-2007  matt sync with HEAD
 1.48.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.49.6.1 18-May-2008  yamt sync with head.
 1.49.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.49.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.50.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.52.8.1 21-Apr-2010  matt sync to netbsd-5
 1.52.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.52.2.1 06-Jun-2009  bouyer Pull up following revision(s) (requested by mlelstv in ticket #794):
sbin/atactl/atactl.c: revision 1.54
make space for a trailing \0 in model,revision and serial buffers.
 1.66.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.66.8.2 25-Feb-2013  tls resync with head
 1.66.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.66.4.2 07-Dec-2014  martin Pull up following revision(s) (requested by mrg in ticket #1206):
sbin/atactl/atactl.c: revision 1.70 and 1.74

Don't use \t to align text columns.
Add a few attribute descriptions.
Add various S.M.A.R.T. status attributes.
 1.66.4.1 18-Feb-2013  riz Pull up following revision(s) (requested by jakllsch in ticket #830):
sbin/atactl/atactl.c: revision 1.69
Decode 6Gbps signaling SATA capability in IDENTIFY DEVICE data.
 1.66.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.66.2.2 23-Jan-2013  yamt sync with head
 1.66.2.1 30-Oct-2012  yamt sync with head
 1.73.4.1 09-Nov-2014  snj Pull up following revision(s) (requested by mrg in ticket #196):
sbin/atactl/atactl.c: revision 1.74
add a whole bunch of S.M.A.R.T. status i found around various sources.
now nothing on my new SSD is unknown, except #249.
 1.76.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.77.14.1 10-Jun-2019  christos Sync with HEAD
 1.77.12.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.77.12.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.83.2.1 12-Dec-2020  martin Pull up following revision(s) (requested by mrg in ticket #1148):

sbin/atactl/atactl.c: revision 1.84

micron SMART 202 is percent lifetime used not remaining.

almost gave myself a heart attack when my server said 7% remaining!
 1.85.8.1 02-Aug-2025  perseant Sync with HEAD
 1.15 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.14 08-Aug-2004  christos warns = 3
 1.13 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.12 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.11 18-Mar-1998  bouyer Add support for non-native endian ffs.
 1.10 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.9 01-Aug-1997  christos Fix warnings.
Use warn(3) and err(3) instead of printf+perror
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 22-Dec-1994  cgd specify man pages the new way.
 1.6 11-Jun-1994  mycroft Fix up RCS ids.
 1.5 10-Jun-1994  pk Update to 4.4-lite.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.15 16-Nov-2001  wiz Sort sections.
 1.14 05-Jun-2001  wiz Drop arguments of .Os.
 1.13 06-May-2001  wiz Improve wording of a sentence. misc/10893 by Jim Bernard, part 2.
 1.12 02-Oct-2000  hubertf We don't ship format(8), so don't x-ref it.
 1.11 29-Apr-1998  fair branches: 1.11.10;
fix bad .Xr references
 1.10 15-Sep-1997  lukem can now use '.Nm "" :'
 1.9 14-Sep-1997  lukem use .Nm appropriately
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 03-Nov-1994  jtc Misc manpages fixes (PR #551)
 1.6 11-Jun-1994  mycroft Fix up RCS ids.
 1.5 10-Jun-1994  pk Update to 4.4-lite.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.10.1 02-Oct-2000  hubertf Pull up rev. 1.12 to netbsd-1-5 branch, OK'd by thorpej:

> We don't ship format(8), so don't x-ref it.
 1.35 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.34 05-Sep-2016  sevan Drop main() prototype.
 1.33 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.32 16-Mar-2009  lukem branches: 1.32.6; 1.32.12;
fix sign-compare issues
 1.31 29-Dec-2008  christos branches: 1.31.2;
fix dev_t format.
 1.30 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.29 08-Aug-2004  christos branches: 1.29.26; 1.29.30;
cleanup some lint
remove unused variables
XXX: fs.h macros are not portable in ansi.
 1.28 08-Aug-2004  christos - fix broken superblock finding code was wrong.
- ansify, KNF
- if the filesystem was not modified, don't ask the user to fsck.
 1.27 27-Mar-2004  dsl Don't require ffsv2 suberblocks to have FS_FLAGS_UPDATED set
 1.26 21-Mar-2004  dsl When searching for the superblock, check that the fs_sblockloc field
matches the location we read it from to ensure we don't have one of the
alternate superblocks.
Fixes part of PR kern/24809
 1.25 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.24 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.23 13-Jul-2003  itojun use bounded string op
 1.22 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.21 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.20 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.19 19-Feb-2001  cgd convert to use getprogname()
 1.18 04-Feb-2001  christos fix nested extern
 1.17 30-Jul-1999  drochner branches: 1.17.8;
don't use the result of a readdir() after closedir(), from
Christian Groessler per PR bin/8107
 1.16 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.15 18-Mar-1998  bouyer Add support for non-native endian ffs.
 1.14 16-Sep-1997  lukem resolve sccsid conflict
 1.13 14-Sep-1997  lukem * don't use register
* warnx() doesn't need trailing \n
 1.12 01-Aug-1997  christos Fix warnings.
Use warn(3) and err(3) instead of printf+perror
 1.11 21-Sep-1996  scottr Since the filesystem is mounted on the block device, we need to use
the character device instead. Closes PRs 897, 994, 2719, and 2769, but
somewhat differently.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 30-Jan-1995  mycroft Don't mix stat flags and inode flags.
 1.8 31-Oct-1994  cgd Add string.h
 1.7 11-Jun-1994  mycroft Fix up RCS ids.
 1.6 10-Jun-1994  pk Update to 4.4-lite.
 1.5 15-Dec-1993  jtc Update to use <dirent.h>.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.17.8.1 25-Nov-2001  he Pull up revision 1.20 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.29.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.29.26.2 17-Jan-2009  mjf Sync with HEAD.
 1.29.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.31.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.32.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.32.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5 16-Jan-2015  christos kill 1 copy of strtonum.
 1.4 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.3 02-Jan-2008  xtraeme branches: 1.3.12;
Rewrite bioctl(8) and add support for the following features:

- Ability to add/remove hot-spare disks (previously only 'add' was accepted).
- Ability to add/remove pass-through disks.
- Ability to create/remove RAID volumes with optional size, stripe, level,
member disks and others.
- Ability to start/stop consistency checks in a RAID volume.
- Ability to show only information about physical disks, volumes or both.

Rather than using multiple flags, the utility has been modified to use
the same mode than dkctl(8) (and maybe others), i.e:

$ ./bioctl
usage: bioctl device command [arg [...]]
Available commands:
show [disks] | [volumes]
alarm [enable] | [disable] | [silence] | [test]
blink start | stop [channel:target[.lun]]
hotspare add | remove channel:target.lun
passthru add DISKID | remove channel:target.lun
check start | stop VOLID
create volume VOLID DISKIDs [SIZE] STRIPE RAID_LEVEL channel:target.lun
remove volume VOLID channel:target.lun
$

I'll add support for other features soon.
 1.2 04-Nov-2007  xtraeme branches: 1.2.2;
- Remove the code for softraid, it's unlikely that NetBSD will support
this because we do have a working raidframe(4).
- Miscellaneous cleanups and make the code WARNS=4 compliant.
- Removed all stuff that doesn't apply to NetBSD.
 1.1 01-May-2007  bouyer branches: 1.1.2; 1.1.6; 1.1.8;
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.1.8.3 15-Oct-2007  riz Clean up after a mistake I made pulling up ticket #1838. We
really only need one copy of each new file. :-)
 1.1.8.2 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.1.8.1 01-May-2007  riz file Makefile was added on branch netbsd-3 on 2007-10-15 05:09:52 +0000
 1.1.6.2 09-Jan-2008  matt sync with HEAD
 1.1.6.1 06-Nov-2007  matt sync with HEAD
 1.1.2.4 10-Dec-2010  bouyer Remove spurious -I/usr/src/sys introduced by patch from ticket 1175.
This cause build failure in some cases.
 1.1.2.3 29-Aug-2008  bouyer Apply patch, requested by christos in tickets #1175:
sys/dev/bio.c patch
sys/dev/biovar.h patch
sys/dev/pci/arcmsr.c patch
sys/dev/pci/arcmsrvar.h patch
sbin/bioctl/Makefile patch
sbin/bioctl/bioctl.8 patch
sbin/bioctl/bioctl.c patch
sbin/bioctl/dehumanize_number.c patch
sbin/bioctl/strtonum.c patch
sbin/bioctl/strtonum.h patch

Port bioctl(8) and arcmsr(4) from current:
bioctl(8): Rewritten to handle new features like creating/removing
hot-spare, pass-through disks and RAID volumes, start/stop
consistency checks in volumes and others.
arcmsr(4): Added support to create/remove hot-spare, pass-through
disks and RAID volumes, start/stop consistency checks
in volumes as well as showing information about physical
disks (even if they are marked as hot-spare, pass-through
or unused).
 1.1.2.2 08-May-2007  pavel branches: 1.1.2.2.2;
Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.1.2.1 01-May-2007  pavel branches: 1.1.2.1.2;
file Makefile was added on branch netbsd-4 on 2007-05-08 10:45:04 +0000
 1.1.2.2.2.1 04-Sep-2008  skrll Sync with netbsd-4.
 1.1.2.1.2.1 locked by: joerg; 01-May-2007  skrll file Makefile was added on branch netbsd-4 on 2008-09-04 08:46:43 +0000
 1.2.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.25 08-May-2019  wiz Sort SEE ALSO.
 1.24 08-May-2019  cnst bioctl(8): Xr ataraid(4), mpii(4) && mfii(4);
 1.23 03-Jul-2017  wiz branches: 1.23.6;
Remove workaround for ancient HTML generation code.
 1.22 11-Sep-2016  sevan Note which version it appeared in before the rewrite.
Bump date.
 1.21 30-Sep-2014  wiz Add comma in enumeration.
 1.20 30-Sep-2014  pettai Add mpt reference, as support for this device was added recently
 1.19 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.18 20-Jul-2013  wiz Use Mt for email addresses.
 1.17 25-Apr-2011  wiz branches: 1.17.4; 1.17.10; 1.17.14;
Add serial comma.
 1.16 25-May-2008  mhitch Add ciss(4) to drivers supporting bio(4) and bioctl(8).
 1.15 16-Mar-2008  wiz branches: 1.15.2; 1.15.4;
Various improvements (mdoc, wording, punctuation).
 1.14 16-Mar-2008  xtraeme Xref cac(4).
 1.13 03-Mar-2008  christos fix example (from anon ymous)
 1.12 03-Mar-2008  xtraeme Typo in previous.
 1.11 03-Mar-2008  xtraeme Improve usage() and manpage commands/args.
 1.10 02-Feb-2008  xtraeme branches: 1.10.2; 1.10.4;
Add two examples to create and remove a RAID volume in a supported
controller... such as arcmsr(4) for now.
 1.9 11-Jan-2008  xtraeme New bioctl(8) first appeared on 5.0 not 4.1.
 1.8 02-Jan-2008  xtraeme Rewrite bioctl(8) and add support for the following features:

- Ability to add/remove hot-spare disks (previously only 'add' was accepted).
- Ability to add/remove pass-through disks.
- Ability to create/remove RAID volumes with optional size, stripe, level,
member disks and others.
- Ability to start/stop consistency checks in a RAID volume.
- Ability to show only information about physical disks, volumes or both.

Rather than using multiple flags, the utility has been modified to use
the same mode than dkctl(8) (and maybe others), i.e:

$ ./bioctl
usage: bioctl device command [arg [...]]
Available commands:
show [disks] | [volumes]
alarm [enable] | [disable] | [silence] | [test]
blink start | stop [channel:target[.lun]]
hotspare add | remove channel:target.lun
passthru add DISKID | remove channel:target.lun
check start | stop VOLID
create volume VOLID DISKIDs [SIZE] STRIPE RAID_LEVEL channel:target.lun
remove volume VOLID channel:target.lun
$

I'll add support for other features soon.
 1.7 05-Dec-2007  xtraeme branches: 1.7.2;
- Remove -D flag... it's useless (it was removed in OpenBSD as well).
- Use errx(3) in the appropiate function rather than warn(4) and
returning EXIT_SUCCESS all the time.
- Remove another case where it checks the device passed string will be
the same than in bv_dev.
 1.6 05-Dec-2007  xtraeme Mention arcmsr(4) in SEE ALSO.
 1.5 04-Nov-2007  xtraeme - Remove the code for softraid, it's unlikely that NetBSD will support
this because we do have a working raidframe(4).
- Miscellaneous cleanups and make the code WARNS=4 compliant.
- Removed all stuff that doesn't apply to NetBSD.
 1.4 09-Sep-2007  wiz branches: 1.4.2;
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
 1.3 09-Sep-2007  bouyer Fix typo.
 1.2 07-May-2007  xtraeme branches: 1.2.2; 1.2.6;
Remove an extra comma.
 1.1 01-May-2007  bouyer Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.2.6.3 23-Mar-2008  matt sync with HEAD
 1.2.6.2 09-Jan-2008  matt sync with HEAD
 1.2.6.1 06-Nov-2007  matt sync with HEAD
 1.2.2.4 29-Aug-2008  bouyer Apply patch, requested by christos in tickets #1175:
sys/dev/bio.c patch
sys/dev/biovar.h patch
sys/dev/pci/arcmsr.c patch
sys/dev/pci/arcmsrvar.h patch
sbin/bioctl/Makefile patch
sbin/bioctl/bioctl.8 patch
sbin/bioctl/bioctl.c patch
sbin/bioctl/dehumanize_number.c patch
sbin/bioctl/strtonum.c patch
sbin/bioctl/strtonum.h patch

Port bioctl(8) and arcmsr(4) from current:
bioctl(8): Rewritten to handle new features like creating/removing
hot-spare, pass-through disks and RAID volumes, start/stop
consistency checks in volumes and others.
arcmsr(4): Added support to create/remove hot-spare, pass-through
disks and RAID volumes, start/stop consistency checks
in volumes as well as showing information about physical
disks (even if they are marked as hot-spare, pass-through
or unused).
 1.2.2.3 11-Sep-2007  xtraeme Pull up following revision(s) (requested by bouyer in ticket #874):
sbin/bioctl/bioctl.8: revision 1.3
Fix typo.
 1.2.2.2 08-May-2007  pavel branches: 1.2.2.2.2;
Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.2.2.1 07-May-2007  pavel file bioctl.8 was added on branch netbsd-4 on 2007-05-08 10:45:03 +0000
 1.2.2.2.2.2 04-Sep-2008  skrll Sync with netbsd-4.
 1.2.2.2.2.1 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.4.2.3 15-Oct-2007  riz Clean up after a mistake I made pulling up ticket #1838. We
really only need one copy of each new file. :-)
 1.4.2.2 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.4.2.1 09-Sep-2007  riz file bioctl.8 was added on branch netbsd-3 on 2007-10-15 05:09:52 +0000
 1.7.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.7.2.1 05-Dec-2007  mjf file bioctl.8 was added on branch mjf-devfs on 2008-02-18 21:04:16 +0000
 1.10.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.10.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.10.2.1 24-Mar-2008  keiichi sync with head.
 1.15.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.15.2.1 04-Jun-2008  yamt sync with head
 1.17.14.1 23-Jul-2013  riastradh sync with HEAD
 1.17.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.23.6.1 10-Jun-2019  christos Sync with HEAD
 1.20 04-Aug-2023  rin bioctl(8): bio_show_volumes(): Do not return pointer to stack.

Found by GCC 12.
 1.19 10-May-2022  msaitoh bioctl(8): Don't print garbage bv_seconds.

This bug was added in bioctl.c rev. 1.7.

Before:
Volume Status Size Device/Label Level Stripe
 1.18 04-Feb-2019  mrg branches: 1.18.2;
- bump buffer sizes to avoid potential truncation issues
 1.17 16-Jan-2015  christos branches: 1.17.8; 1.17.16;
kill 1 copy of strtonum.
 1.16 15-Nov-2014  joerg Skip vendor if the string is empty.
 1.15 29-Aug-2011  joerg branches: 1.15.20;
Use __dead
 1.14 25-May-2011  joerg Simplify
 1.13 20-Feb-2010  ahoka Fix two problems with argc handling in bioctl(8), which makes
bioctl(8) dump core if expected arguments are not passed in.

Closes PR bin/39946 (patch by Juan RP).
 1.12 18-Jan-2009  lukem fix -Wsign-compare issues
 1.11 03-Mar-2008  xtraeme Improve usage() and manpage commands/args.
 1.10 03-Mar-2008  xtraeme - Fix total user specified and free disk size based on the RAID level.
- Adapt for BIOC_SVOL_RAID01 and BIOC_SVOL_RAID10 levels.
 1.9 01-Mar-2008  xtraeme On RAID 1 volumes and when bv_stripe_size is 0 make it print 'N/A', like:

$ sudo bioctl arcmsr0 show volumes
Volume Status Size Device/Label Level Stripe
 1.8 29-Feb-2008  xtraeme bio_setstate_consistency: zero out the struct before anything else,
and fix argv argument for strtoul().
 1.7 02-Jan-2008  xtraeme branches: 1.7.2; 1.7.4;
Rewrite bioctl(8) and add support for the following features:

- Ability to add/remove hot-spare disks (previously only 'add' was accepted).
- Ability to add/remove pass-through disks.
- Ability to create/remove RAID volumes with optional size, stripe, level,
member disks and others.
- Ability to start/stop consistency checks in a RAID volume.
- Ability to show only information about physical disks, volumes or both.

Rather than using multiple flags, the utility has been modified to use
the same mode than dkctl(8) (and maybe others), i.e:

$ ./bioctl
usage: bioctl device command [arg [...]]
Available commands:
show [disks] | [volumes]
alarm [enable] | [disable] | [silence] | [test]
blink start | stop [channel:target[.lun]]
hotspare add | remove channel:target.lun
passthru add DISKID | remove channel:target.lun
check start | stop VOLID
create volume VOLID DISKIDs [SIZE] STRIPE RAID_LEVEL channel:target.lun
remove volume VOLID channel:target.lun
$

I'll add support for other features soon.
 1.6 07-Dec-2007  xtraeme branches: 1.6.2;
Add BIOC_SVMIGRATING to bio(4) and bioctl(8) to report if a volume
is migrating currently showing the percentage.

Update arcmsr(4) to report this, like:

$ sudo ./bioctl -h arcmsr0
Volume Status Size Device
arcmsr0 0 Migrating 698G ARC-1210-VOL#00 RAID 5 7% done
0 Online 234G 0:0.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
1 Online 234G 0:1.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
2 Online 234G 0:2.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
3 Online 234G 0:3.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
$
 1.5 05-Dec-2007  xtraeme There's no need to waste 14 spaces in the third element when the
the human output is requested, align it at most 4 spaces.

I'd also make the human output the default but not sure everybody will
agree...
 1.4 05-Dec-2007  xtraeme - Remove -D flag... it's useless (it was removed in OpenBSD as well).
- Use errx(3) in the appropiate function rather than warn(4) and
returning EXIT_SUCCESS all the time.
- Remove another case where it checks the device passed string will be
the same than in bv_dev.
 1.3 05-Dec-2007  xtraeme Do not enforce that passed device string will be the same than the
one in bv_dev, which in some drivers like arcmsr(4) it contains the
volume name.

While I'm here, fix the formatting output so that it fits with arcmsr(4),
like:

$ sudo bioctl -h arcmsr0
Volume Status Size Device
arcmsr0 0 Building 698G ARC-1210-VOL#00 RAID5 96% done
0 Online 234G 0:0.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
1 Online 234G 0:1.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
2 Online 234G 0:2.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
3 Online 234G 0:3.0 noencl <WDC WD2500YS-01SHB1 20.06C06>
$
 1.2 04-Nov-2007  xtraeme - Remove the code for softraid, it's unlikely that NetBSD will support
this because we do have a working raidframe(4).
- Miscellaneous cleanups and make the code WARNS=4 compliant.
- Removed all stuff that doesn't apply to NetBSD.
 1.1 01-May-2007  bouyer branches: 1.1.2; 1.1.6; 1.1.8;
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.1.8.3 15-Oct-2007  riz Clean up after a mistake I made pulling up ticket #1838. We
really only need one copy of each new file. :-)
 1.1.8.2 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.1.8.1 01-May-2007  riz file bioctl.c was added on branch netbsd-3 on 2007-10-15 05:09:51 +0000
 1.1.6.3 23-Mar-2008  matt sync with HEAD
 1.1.6.2 09-Jan-2008  matt sync with HEAD
 1.1.6.1 06-Nov-2007  matt sync with HEAD
 1.1.2.3 29-Aug-2008  bouyer Apply patch, requested by christos in tickets #1175:
sys/dev/bio.c patch
sys/dev/biovar.h patch
sys/dev/pci/arcmsr.c patch
sys/dev/pci/arcmsrvar.h patch
sbin/bioctl/Makefile patch
sbin/bioctl/bioctl.8 patch
sbin/bioctl/bioctl.c patch
sbin/bioctl/dehumanize_number.c patch
sbin/bioctl/strtonum.c patch
sbin/bioctl/strtonum.h patch

Port bioctl(8) and arcmsr(4) from current:
bioctl(8): Rewritten to handle new features like creating/removing
hot-spare, pass-through disks and RAID volumes, start/stop
consistency checks in volumes and others.
arcmsr(4): Added support to create/remove hot-spare, pass-through
disks and RAID volumes, start/stop consistency checks
in volumes as well as showing information about physical
disks (even if they are marked as hot-spare, pass-through
or unused).
 1.1.2.2 08-May-2007  pavel branches: 1.1.2.2.2;
Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.1.2.1 01-May-2007  pavel branches: 1.1.2.1.2;
file bioctl.c was added on branch netbsd-4 on 2007-05-08 10:45:03 +0000
 1.1.2.2.2.1 04-Sep-2008  skrll Sync with netbsd-4.
 1.1.2.1.2.1 01-May-2007  skrll file bioctl.c was added on branch netbsd-4 on 2008-09-04 08:46:43 +0000
 1.6.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.6.2.1 07-Dec-2007  mjf file bioctl.c was added on branch mjf-devfs on 2008-02-18 21:04:16 +0000
 1.7.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.7.2.1 24-Mar-2008  keiichi sync with head.
 1.15.20.1 14-May-2015  snj Pull up following revision(s) (requested by joerg in ticket #758):
bin/ksh/Makefile: revision 1.31
bin/ps/print.c: revision 1.123
external/bsd/iscsi/dist/src/lib/parameters.c: revision 1.4
external/bsd/iscsi/dist/src/lib/target.c: revision 1.9
external/gpl2/lvm2/dist/lib/commands/toolcontext.c: revision 1.8
external/gpl2/lvm2/dist/lib/format1/import-export.c: revision 1.2
gnu/dist/texinfo/makeinfo/xml.c: revision 1.2
sbin/bioctl/bioctl.c: revision 1.16
usr.sbin/isdn/isdnd/msghdl.c: revision 1.12
Drop pointer checks that are always true.
--
Comment out impossible code.
--
Remove tautologic check.
--
Skip vendor if the string is empty.
Use l_wmesg if the string is not empty. Don't bother checking l_name for
nullness.
--
Array can't be null.
--
Show display if it is not empty.
--
Make cast warnings for clang non-fatal.
 1.17.16.1 10-Jun-2019  christos Sync with HEAD
 1.17.8.1 15-May-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1741):

sbin/bioctl/bioctl.c: revision 1.19

bioctl(8): Don't print garbage bv_seconds.

This bug was added in bioctl.c rev. 1.7.

Before:
Volume Status Size Device/Label Level Stripe
 1.18.2.1 14-May-2022  martin Pull up following revision(s) (requested by msaitoh in ticket #1449):

sbin/bioctl/bioctl.c: revision 1.19

bioctl(8): Don't print garbage bv_seconds.

This bug was added in bioctl.c rev. 1.7.

Before:
Volume Status Size Device/Label Level Stripe
 1.1 29-Aug-2008  bouyer branches: 1.1.2; 1.1.4;
file dehumanize_number.c was initially added on branch netbsd-4.
 1.1.4.2 04-Sep-2008  skrll Sync with netbsd-4.
 1.1.4.1 29-Aug-2008  skrll file dehumanize_number.c was added on branch wrstuden-fixsa on 2008-09-04 08:46:43 +0000
 1.1.2.1 29-Aug-2008  bouyer Apply patch, requested by christos in tickets #1175:
sys/dev/bio.c patch
sys/dev/biovar.h patch
sys/dev/pci/arcmsr.c patch
sys/dev/pci/arcmsrvar.h patch
sbin/bioctl/Makefile patch
sbin/bioctl/bioctl.8 patch
sbin/bioctl/bioctl.c patch
sbin/bioctl/dehumanize_number.c patch
sbin/bioctl/strtonum.c patch
sbin/bioctl/strtonum.h patch

Port bioctl(8) and arcmsr(4) from current:
bioctl(8): Rewritten to handle new features like creating/removing
hot-spare, pass-through disks and RAID volumes, start/stop
consistency checks in volumes and others.
arcmsr(4): Added support to create/remove hot-spare, pass-through
disks and RAID volumes, start/stop consistency checks
in volumes as well as showing information about physical
disks (even if they are marked as hot-spare, pass-through
or unused).
 1.2 16-Jan-2015  christos kill 1 copy of strtonum.
 1.1 01-May-2007  bouyer branches: 1.1.2; 1.1.8;
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.1.8.3 15-Oct-2007  riz Clean up after a mistake I made pulling up ticket #1838. We
really only need one copy of each new file. :-)
 1.1.8.2 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.1.8.1 01-May-2007  riz file strtonum.c was added on branch netbsd-3 on 2007-10-15 05:09:51 +0000
 1.1.2.3 29-Aug-2008  bouyer Apply patch, requested by christos in tickets #1175:
sys/dev/bio.c patch
sys/dev/biovar.h patch
sys/dev/pci/arcmsr.c patch
sys/dev/pci/arcmsrvar.h patch
sbin/bioctl/Makefile patch
sbin/bioctl/bioctl.8 patch
sbin/bioctl/bioctl.c patch
sbin/bioctl/dehumanize_number.c patch
sbin/bioctl/strtonum.c patch
sbin/bioctl/strtonum.h patch

Port bioctl(8) and arcmsr(4) from current:
bioctl(8): Rewritten to handle new features like creating/removing
hot-spare, pass-through disks and RAID volumes, start/stop
consistency checks in volumes and others.
arcmsr(4): Added support to create/remove hot-spare, pass-through
disks and RAID volumes, start/stop consistency checks
in volumes as well as showing information about physical
disks (even if they are marked as hot-spare, pass-through
or unused).
 1.1.2.2 08-May-2007  pavel branches: 1.1.2.2.2;
Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.1.2.1 01-May-2007  pavel branches: 1.1.2.1.2;
file strtonum.c was added on branch netbsd-4 on 2007-05-08 10:45:02 +0000
 1.1.2.2.2.1 04-Sep-2008  skrll Sync with netbsd-4.
 1.1.2.1.2.1 locked by: joerg; 01-May-2007  skrll file strtonum.c was added on branch netbsd-4 on 2008-09-04 08:46:43 +0000
 1.2 16-Jan-2015  christos kill 1 copy of strtonum.
 1.1 01-May-2007  bouyer branches: 1.1.2; 1.1.8;
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
 1.1.8.3 15-Oct-2007  riz Clean up after a mistake I made pulling up ticket #1838. We
really only need one copy of each new file. :-)
 1.1.8.2 15-Oct-2007  riz Pull up following revisions via patch (requested by bouyer in ticket #1838):
distrib/sets/lists/man/mi: revision 1.997
sbin/bioctl/strtonum.c: revision 1.1
sys/dev/Makefile: revision 1.25
sys/arch/amd64/conf/GENERIC: revision 1.139
sbin/bioctl/strtonum.h: revision 1.1
sys/dev/bio.c: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
share/man/man4/bio.4: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sys/sys/envsys.h: revision 1.11
sbin/bioctl/bioctl.8: revision 1.3
sbin/bioctl/bioctl.8: revision 1.4
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
distrib/sets/lists/base/mi: revision 1.704
sys/conf/majors: revision 1.34
share/man/man4/Makefile: revision 1.426
etc/MAKEDEV.tmpl: revision 1.86
sys/arch/i386/conf/GENERIC: revision 1.825
distrib/sets/lists/comp/mi: revision 1.1022
sys/conf/files: revision 1.839
usr.sbin/envstat/envstat.c: revision 1.24
sbin/Makefile: revision 1.105
sys/dev/ic/mfi.c: revision 1.4
sys/dev/biovar.h: revision 1.1
sys/dev/ic/mfivar.h: revision 1.4
sbin/bioctl/Makefile: revision 1.1
Fix typo.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.
Fix Dd argument (use full month names).
Use more markup.
Comment out references to safte(4) and softraid(4), which don't exist in
NetBSD.
Remove trailing whitespace.
Use macros instead of characters for HTML output (replace ">", "<"
with \*[Gt], \*[Lt]).
Sort sections.
Create /dev/bio
 1.1.8.1 01-May-2007  riz file strtonum.h was added on branch netbsd-3 on 2007-10-15 05:09:51 +0000
 1.1.2.3 29-Aug-2008  bouyer Apply patch, requested by christos in tickets #1175:
sys/dev/bio.c patch
sys/dev/biovar.h patch
sys/dev/pci/arcmsr.c patch
sys/dev/pci/arcmsrvar.h patch
sbin/bioctl/Makefile patch
sbin/bioctl/bioctl.8 patch
sbin/bioctl/bioctl.c patch
sbin/bioctl/dehumanize_number.c patch
sbin/bioctl/strtonum.c patch
sbin/bioctl/strtonum.h patch

Port bioctl(8) and arcmsr(4) from current:
bioctl(8): Rewritten to handle new features like creating/removing
hot-spare, pass-through disks and RAID volumes, start/stop
consistency checks in volumes and others.
arcmsr(4): Added support to create/remove hot-spare, pass-through
disks and RAID volumes, start/stop consistency checks
in volumes as well as showing information about physical
disks (even if they are marked as hot-spare, pass-through
or unused).
 1.1.2.2 08-May-2007  pavel branches: 1.1.2.2.2;
Pull up following revision(s) (requested by bouyer in ticket #603):
distrib/sets/lists/base/mi: revision 1.704
distrib/sets/lists/comp/mi: revision 1.1022
distrib/sets/lists/man/mi: revision 1.997
doc/CHANGES: revision 1.839
sbin/Makefile: patch
sbin/bioctl/Makefile: revision 1.1
sbin/bioctl/bioctl.8: revision 1.1
sbin/bioctl/bioctl.c: revision 1.1
sbin/bioctl/strtonum.c: revision 1.1
sbin/bioctl/strtonum.h: revision 1.1
share/man/man4/Makefile: revision 1.426
share/man/man4/bio.4: revision 1.1
sys/arch/amd64/conf/GENERIC: revision 1.139
sys/arch/i386/conf/GENERIC: revision 1.825
sys/arch/i386/conf/XEN2_DOM0: revision 1.25
sys/conf/files: revision 1.839
sys/conf/majors: patch
sys/dev/Makefile: revision 1.25
sys/dev/bio.c: patch
sys/dev/biovar.h: patch
sys/dev/ic/mfi.c: revision 1.4-1.5
sys/dev/ic/mfivar.h: revision 1.4
sys/sys/envsys.h: revision 1.11
usr.sbin/envstat/envstat.c: revision 1.24
Add bio(4) and associated bioctl(8) from OpenBSD, a driver control block
device controllers, and more specifically raid controllers.
Add a new sensor type, ENVSYS_DRIVE, to report drive status. From OpenBSD.
Add bio and sysmon support to mfi(4). This allow userland to query
status for drives and logical volumes attached to a mfi(4) controller. While
there fix some debug printfs in mfi so they compile.
Add bio(4) to amd64 and i386 GENERIC.

note bio(4), envsys(4) DRIVE, and mfi(4) support for both.

tred->sensor is a u_int.
 1.1.2.1 01-May-2007  pavel branches: 1.1.2.1.2;
file strtonum.h was added on branch netbsd-4 on 2007-05-08 10:45:03 +0000
 1.1.2.2.2.1 04-Sep-2008  skrll Sync with netbsd-4.
 1.1.2.1.2.1 locked by: joerg; 01-May-2007  skrll file strtonum.h was added on branch netbsd-4 on 2008-09-04 08:46:43 +0000
 1.1 07-Feb-2022  mrg convert my fdiscard-stuff.c into blkdiscard.c and give it a UI
that matches the linux-util version.

comes in two forms: blkdiscard equivalent, and the (almost)
original interface i used (the "-s" option is conflicting and
i've switched to only the not yet implemented secure erase
option.) the only real difference is that "fdiscard" mode
requires the -R flag to do something, vs blkdiscard needs the
-n flag to not do anything.


not yet hooked into the build or sets. would like more testing
on it to be performed before doing that (but soon.)
 1.3 25-Jan-2024  mrg blkdiscard: avoid asserting when passed a bsd disklabel raw device

PR#57856 shows when using blkdiscard on eg, /dev/ld0 it asserts because
'0' is not between 'a' and 'p'. switch this to using DISKPART() on the
returned st_rdev, so it works on 'ld0c' or 'ld0' (rawpart=2.)
 1.2 15-Oct-2022  andvar branches: 1.2.2;
fix various typos in documentation and comments.
mainly in words functionality, functional, function.
 1.1 07-Feb-2022  mrg convert my fdiscard-stuff.c into blkdiscard.c and give it a UI
that matches the linux-util version.

comes in two forms: blkdiscard equivalent, and the (almost)
original interface i used (the "-s" option is conflicting and
i've switched to only the not yet implemented secure erase
option.) the only real difference is that "fdiscard" mode
requires the -R flag to do something, vs blkdiscard needs the
-n flag to not do anything.


not yet hooked into the build or sets. would like more testing
on it to be performed before doing that (but soon.)
 1.2.2.1 03-Feb-2024  martin Pull up following revision(s) (requested by mrg in ticket #565):

sbin/blkdiscard/blkdiscard.c: revision 1.2
sbin/blkdiscard/blkdiscard.c: revision 1.3
sbin/blkdiscard/blkdiscard.8: revision 1.3

determine the tty width instead off writing 100 chars before a new line.

blkdiscard: avoid asserting when passed a bsd disklabel raw device

PR#57856 shows when using blkdiscard on eg, /dev/ld0 it asserts because
'0' is not between 'a' and 'p'. switch this to using DISKPART() on the
returned st_rdev, so it works on 'ld0c' or 'ld0' (rawpart=2.)
 1.4 08-Feb-2024  andvar fix misplaced or missing "e" in words with "ment" ending (argument, implement,
increment, decrement, alignment), in comments, documentation, log messages.
 1.3 25-Jan-2024  mrg blkdiscard: avoid asserting when passed a bsd disklabel raw device

PR#57856 shows when using blkdiscard on eg, /dev/ld0 it asserts because
'0' is not between 'a' and 'p'. switch this to using DISKPART() on the
returned st_rdev, so it works on 'ld0c' or 'ld0' (rawpart=2.)
 1.2 25-Jan-2024  mrg determine the tty width instead off writing 100 chars before a new line.
 1.1 07-Feb-2022  mrg branches: 1.1.2;
convert my fdiscard-stuff.c into blkdiscard.c and give it a UI
that matches the linux-util version.

comes in two forms: blkdiscard equivalent, and the (almost)
original interface i used (the "-s" option is conflicting and
i've switched to only the not yet implemented secure erase
option.) the only real difference is that "fdiscard" mode
requires the -R flag to do something, vs blkdiscard needs the
-n flag to not do anything.


not yet hooked into the build or sets. would like more testing
on it to be performed before doing that (but soon.)
 1.1.2.1 03-Feb-2024  martin Pull up following revision(s) (requested by mrg in ticket #565):

sbin/blkdiscard/blkdiscard.c: revision 1.2
sbin/blkdiscard/blkdiscard.c: revision 1.3
sbin/blkdiscard/blkdiscard.8: revision 1.3

determine the tty width instead off writing 100 chars before a new line.

blkdiscard: avoid asserting when passed a bsd disklabel raw device

PR#57856 shows when using blkdiscard on eg, /dev/ld0 it asserts because
'0' is not between 'a' and 'p'. switch this to using DISKPART() on the
returned st_rdev, so it works on 'ld0c' or 'ld0' (rawpart=2.)
 1.3 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.2 20-Jan-2005  xtraeme Remove main() prototype; WARNS=3
 1.1 17-Aug-2001  thorpej Configuration utility for bridge(4) devices.
 1.22 03-Sep-2024  uwe brconfig(8): tweak markup
 1.21 03-Sep-2024  ozaki-r brconfig: add protect/-protect commands

It marks/clears a specified interface "protected".
 1.20 19-Jul-2020  wiz branches: 1.20.6; 1.20.8;
Remove unused Pp. Sort SEE ALSO.
 1.19 19-Jul-2020  maxv sync with reality
 1.18 05-Jan-2015  msaitoh Add missing "addr" and "static" commands.
 1.17 08-Jan-2007  wiz branches: 1.17.20; 1.17.38; 1.17.56;
Bump date for previous.
 1.16 07-Jan-2007  isaki Sync with reality. The default timeout is 1200 sec.
 1.15 14-Dec-2006  reed Mention pfil(9). Reword slightly for "ipf" option as filters IPv6
also (and ICMP is implied) and that other types are blocked.

Point to pf(4) and pfil man pages.

Based on discussion in January 2006 on tech-kern. (This has been
in my tree for around 11 months.)

This part of my work to change this (and related to use) pfil (instead
of ipf). That is done back then but needs some testing.
 1.14 11-Oct-2006  pooka lower value mean higher priority for bridges
+ fix off-by-one

Tobias Nygren, bin/34781
 1.13 12-Jan-2006  wiz Improve a sentence.
 1.12 11-Jan-2006  agc Minor fix - correct a typo
 1.11 29-Apr-2003  wiz Remove superfluous +. From FUKAUMI Naoki in PR 21390.
 1.10 19-Mar-2003  wiz Bump date for last change; new sentence, new line.
 1.9 19-Mar-2003  bouyer Fix 2 bugs:
- initialise stp when the bridge is turned up, without this stp will keep
all interfaces disabled in a sequence like:
brconfig bridge0 add if0 add if1 stp if0 stp if1 up
- s/BRDGSPRI/BRDGSIFPRIO in brconfig.c:cmd_ifpriority()

add a command (ifpathcost) to change the stp path cost of the STP path cost of
an interface. Display the interface path cost with the others STP parameters.
 1.8 03-Mar-2003  wiz New sentence, new line.
 1.7 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.6 15-Feb-2003  perseant Add ipf packet-filtering option to if_bridge. The option is controlled at
compile-time by BRIDGE_IPF, and at runtime by brconfig with the {ipf,-ipf}
option on a per-bridge basis.

As a side-effect, add PFIL_HOOKS processing to if_bridge.
 1.5 06-Nov-2002  enami Fix typo.
 1.4 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.3 16-Nov-2001  wiz branches: 1.3.2;
Sort sections, use standard section headers.
 1.2 16-Nov-2001  wiz Whitespace nits
 1.1 17-Aug-2001  thorpej Configuration utility for bridge(4) devices.
 1.3.2.2 30-Jun-2003  grant Pull up revision 1.10 (requested by bouyer in ticket #1355):

Bump date for last change; new sentence, new line.
 1.3.2.1 30-Jun-2003  grant Apply patch (requested by bouyer in ticket #1355):

Fix 2 bugs:
- initialise stp when the bridge is turned up, without this stp will
keep all interfaces disabled in a sequence like:
brconfig bridge0 add if0 add if1 stp if0 stp if1 up
- s/BRDGSPRI/BRDGSIFPRIO in brconfig.c:cmd_ifpriority()

add a command (ifpathcost) to change the stp path cost of the STP path
cost of an interface. Display the interface path cost with the others
STP parameters.
 1.17.56.1 08-Jan-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #391):
sbin/brconfig/brconfig.8: revision 1.18
Add missing "addr" and "static" commands.
 1.17.38.1 16-Jan-2015  snj Pull up following revision(s) (requested by msaitoh in ticket #1228):
sbin/brconfig/brconfig.8: revision 1.18
Add missing "addr" and "static" commands.
 1.17.20.1 23-Jan-2015  martin Pull up following revision(s) (requested by msaitoh in ticket #1941):
sbin/brconfig/brconfig.8: revision 1.18
Add missing "addr" and "static" commands.
 1.20.8.1 02-Aug-2025  perseant Sync with HEAD
 1.20.6.1 05-Sep-2024  martin Pull up following revision(s) (requested by ozaki-r in ticket #818):

sys/net/if_bridgevar.h: revision 1.39
sbin/brconfig/brconfig.c: revision 1.18
tests/net/if_bridge/unicast.pcap.uue: revision 1.1
tests/net/if_bridge/t_bridge.sh: revision 1.20
sbin/brconfig/brconfig.8: revision 1.21
tests/net/if_bridge/t_bridge.sh: revision 1.21
sys/net/if_bridge.c: revision 1.194
tests/net/if_bridge/Makefile: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1336
tests/net/if_bridge/broadcast.pcap.uue: revision 1.1

bridge: implement interface protection

It enables a feature similar to "protected-port" or "isolation" in some
router products by marking member interfaces protected; when a frame
arrives on a protected interface and is being forwarded to another
protected interface, the frame will be discarded.

The code is developed by the SEIL team at IIJ.

tests: dedup test scripts like others

brconfig: add protect/-protect commands

It marks/clears a specified interface "protected".
tests, bridge: add tests for interface protection

The original author of the test is k-goda@IIJ. ozaki-r improved
the test slightly.

distrib: install uuencoded pcap files for testing
 1.18 03-Sep-2024  ozaki-r brconfig: add protect/-protect commands

It marks/clears a specified interface "protected".
 1.17 01-Jun-2015  matt branches: 1.17.26; 1.17.28;
Use the new BRDGGIFS and BRDGRTS cmds which just use ifdrv directly.
 1.16 28-May-2015  joerg constness doesn't increase by applying more const.
 1.15 28-May-2015  matt Constify an array of strings.
 1.14 23-Aug-2012  drochner the address expire counter is just a time difference; it can turn
negative after the timer expired until the entry is deleted.
make it signed, so that we don't get output like
"00:1b:78:12:50:46 wm0 18446744073709551349 flags=0<>"
 1.13 29-Aug-2011  joerg branches: 1.13.2;
static + __dead
 1.12 16-Mar-2009  lukem fix sign-compare issues
 1.11 20-Mar-2006  christos branches: 1.11.30;
Coverity CID 774: Don't increment a pointer *before* testing it for NULL!
 1.10 20-Mar-2005  yamt remove IFFBITS definition. now net/if.h has it.

PR/29748 from FUKAUMI Naoki.
 1.9 20-Jan-2005  xtraeme Remove main() prototype; WARNS=3
 1.8 28-Oct-2004  dsl Add (unsigned char) to isdidgit call
 1.7 19-Sep-2003  itojun realloc pedant
 1.6 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.5 19-Mar-2003  bouyer Fix 2 bugs:
- initialise stp when the bridge is turned up, without this stp will keep
all interfaces disabled in a sequence like:
brconfig bridge0 add if0 add if1 stp if0 stp if1 up
- s/BRDGSPRI/BRDGSIFPRIO in brconfig.c:cmd_ifpriority()

add a command (ifpathcost) to change the stp path cost of the STP path cost of
an interface. Display the interface path cost with the others STP parameters.
 1.4 27-Feb-2003  perseant Make BRIDGE_IPF an option, and document it. Add it (commented) to GENERIC.
Let brconfig tell whether the bridge is using the ipfilter hook, or not.
 1.3 15-Feb-2003  perseant Add ipf packet-filtering option to if_bridge. The option is controlled at
compile-time by BRIDGE_IPF, and at runtime by brconfig with the {ipf,-ipf}
option on a per-bridge basis.

As a side-effect, add PFIL_HOOKS processing to if_bridge.
 1.2 06-Nov-2002  enami Fix typo in error message.
 1.1 17-Aug-2001  thorpej branches: 1.1.2;
Configuration utility for bridge(4) devices.
 1.1.2.1 30-Jun-2003  grant Apply patch (requested by bouyer in ticket #1355):

Fix 2 bugs:
- initialise stp when the bridge is turned up, without this stp will
keep all interfaces disabled in a sequence like:
brconfig bridge0 add if0 add if1 stp if0 stp if1 up
- s/BRDGSPRI/BRDGSIFPRIO in brconfig.c:cmd_ifpriority()

add a command (ifpathcost) to change the stp path cost of the STP path
cost of an interface. Display the interface path cost with the others
STP parameters.
 1.11.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.13.2.1 30-Oct-2012  yamt sync with head
 1.17.28.1 02-Aug-2025  perseant Sync with HEAD
 1.17.26.1 05-Sep-2024  martin Pull up following revision(s) (requested by ozaki-r in ticket #818):

sys/net/if_bridgevar.h: revision 1.39
sbin/brconfig/brconfig.c: revision 1.18
tests/net/if_bridge/unicast.pcap.uue: revision 1.1
tests/net/if_bridge/t_bridge.sh: revision 1.20
sbin/brconfig/brconfig.8: revision 1.21
tests/net/if_bridge/t_bridge.sh: revision 1.21
sys/net/if_bridge.c: revision 1.194
tests/net/if_bridge/Makefile: revision 1.4
distrib/sets/lists/tests/mi: revision 1.1336
tests/net/if_bridge/broadcast.pcap.uue: revision 1.1

bridge: implement interface protection

It enables a feature similar to "protected-port" or "isolation" in some
router products by marking member interfaces protected; when a frame
arrives on a protected interface and is being forwarded to another
protected interface, the frame will be discarded.

The code is developed by the SEIL team at IIJ.

tests: dedup test scripts like others

brconfig: add protect/-protect commands

It marks/clears a specified interface "protected".
tests, bridge: add tests for interface protection

The original author of the test is k-goda@IIJ. ozaki-r improved
the test slightly.

distrib: install uuencoded pcap files for testing
 1.2 27-May-2017  bouyer merge the bouyer-socketcan branch to HEAD.

CAN stands for Controller Area Network, a broadcast network used
in automation and automotive fields. For example, the NMEA2000 standard
developped for marine devices uses a CAN network as the link layer.

This is an implementation of the linux socketcan API:
https://www.kernel.org/doc/Documentation/networking/can.txt
you can also see can(4).

This adds a new socket family (AF_CAN) and protocol (PF_CAN),
as well as the canconfig(8) utility, used to set timing parameter of
CAN hardware. Also inclued is a driver for the CAN controller
found in the allwinner A20 SoC (I tested it with an Olimex lime2 board,
connected with PIC18-based CAN devices).

There is also the canloop(4) pseudo-device, which allows to use
the socketcan API without CAN hardware.

At this time the CANFD part of the linux socketcan API is not implemented.
Error frames are not implemented either. But I could get the cansend and
canreceive utilities from the canutils package to build and run with minimal
changes. tcpudmp(8) can also be used to record frames, which can be
decoded with etherreal.
 1.1 17-Apr-2017  bouyer branches: 1.1.2;
file Makefile was initially added on branch bouyer-socketcan.
 1.1.2.1 17-Apr-2017  bouyer Add canconfig(8), an utility to configure CAN interfaces.
Compile-tested only.
 1.3 29-May-2017  wiz New sentence, new line. Fix typos. More consistent grammar.
Comment out empty EXAMPLES section. Remove unnecessary macros.
 1.2 27-May-2017  bouyer merge the bouyer-socketcan branch to HEAD.

CAN stands for Controller Area Network, a broadcast network used
in automation and automotive fields. For example, the NMEA2000 standard
developped for marine devices uses a CAN network as the link layer.

This is an implementation of the linux socketcan API:
https://www.kernel.org/doc/Documentation/networking/can.txt
you can also see can(4).

This adds a new socket family (AF_CAN) and protocol (PF_CAN),
as well as the canconfig(8) utility, used to set timing parameter of
CAN hardware. Also inclued is a driver for the CAN controller
found in the allwinner A20 SoC (I tested it with an Olimex lime2 board,
connected with PIC18-based CAN devices).

There is also the canloop(4) pseudo-device, which allows to use
the socketcan API without CAN hardware.

At this time the CANFD part of the linux socketcan API is not implemented.
Error frames are not implemented either. But I could get the cansend and
canreceive utilities from the canutils package to build and run with minimal
changes. tcpudmp(8) can also be used to record frames, which can be
decoded with etherreal.
 1.1 17-Apr-2017  bouyer branches: 1.1.2;
file canconfig.8 was initially added on branch bouyer-socketcan.
 1.1.2.2 20-Apr-2017  bouyer Implement listenonly and loopback flags.
Fix do_canflag()
 1.1.2.1 17-Apr-2017  bouyer Add canconfig(8), an utility to configure CAN interfaces.
Compile-tested only.
 1.2 27-May-2017  bouyer merge the bouyer-socketcan branch to HEAD.

CAN stands for Controller Area Network, a broadcast network used
in automation and automotive fields. For example, the NMEA2000 standard
developped for marine devices uses a CAN network as the link layer.

This is an implementation of the linux socketcan API:
https://www.kernel.org/doc/Documentation/networking/can.txt
you can also see can(4).

This adds a new socket family (AF_CAN) and protocol (PF_CAN),
as well as the canconfig(8) utility, used to set timing parameter of
CAN hardware. Also inclued is a driver for the CAN controller
found in the allwinner A20 SoC (I tested it with an Olimex lime2 board,
connected with PIC18-based CAN devices).

There is also the canloop(4) pseudo-device, which allows to use
the socketcan API without CAN hardware.

At this time the CANFD part of the linux socketcan API is not implemented.
Error frames are not implemented either. But I could get the cansend and
canreceive utilities from the canutils package to build and run with minimal
changes. tcpudmp(8) can also be used to record frames, which can be
decoded with etherreal.
 1.1 17-Apr-2017  bouyer branches: 1.1.2;
file canconfig.c was initially added on branch bouyer-socketcan.
 1.1.2.4 21-Apr-2017  bouyer Fix humanize_number() usage.
Display more user-friendly operational parameters (baud rate, tq value,
number of tq).
 1.1.2.3 20-Apr-2017  bouyer Implement listenonly and loopback flags.
Fix do_canflag()
 1.1.2.2 19-Apr-2017  bouyer Make output better
Fix setting timings parameters
 1.1.2.1 17-Apr-2017  bouyer Add canconfig(8), an utility to configure CAN interfaces.
Compile-tested only.
 1.9 27-Apr-2013  christos one less kvm groveller. Use sysctl to get ccd info.
 1.8 28-May-2007  tls branches: 1.8.36; 1.8.42;
Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.7 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.6 20-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.5 11-Jun-2002  grant add ccd.conf(5)
 1.4 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.3 20-Jul-1997  thorpej Build with WARNS.
 1.2 16-May-1996  thorpej Use getmaxpartitions() and getrawpartition() from libutil, not homegrown
versions.
 1.1 17-Aug-1995  thorpej Configuration utility for the ccd.
 1.8.42.1 23-Jun-2013  tls resync from head
 1.8.36.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5 13-Aug-2014  apb Interleave 0 means concatenate serially, do not interleave.
This information was in the ccd(4) man page, but not
in ccdconfig(8) or ccd.conf(5).
 1.4 17-May-2005  grant move to my now standard 3-clause BSD license (remove advertising clause)
 1.3 11-Jun-2002  wiz Seems I was overzealous. Undo part of last, noted by grant.
 1.2 11-Jun-2002  wiz Fix copyright, and some minor mdoc improvements.
 1.1 11-Jun-2002  grant add ccd.conf(5)
 1.27 13-Aug-2014  apb Interleave 0 means concatenate serially, do not interleave.
This information was in the ccd(4) man page, but not
in ccdconfig(8) or ccd.conf(5).
 1.26 27-Apr-2013  christos one less kvm groveller. Use sysctl to get ccd info.
 1.25 22-Aug-2009  joerg branches: 1.25.6; 1.25.12;
Fix markup
 1.24 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.23 17-Oct-2003  lukem branches: 1.23.32; 1.23.34;
Support CCDF_NOLABEL. Document what CCDF_UNIFORM actually does.
 1.22 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.21 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.20 11-Jun-2002  grant add ccd.conf(5)
 1.19 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.18 16-Nov-2001  wiz Whitespace nits
 1.17 20-Aug-2001  wiz precede, not preceed.
 1.16 26-Jul-2001  wiz concatinate -> concatenate
 1.15 05-Jun-2001  wiz Drop arguments of .Os.
 1.14 11-Aug-1999  thorpej Garbage-collect CCDF_SWAP; no longer used, and doesn't make any sense
with the UVM swap code.
 1.13 13-Nov-1998  thorpej CCDF_MIRROR is nuked from orbit.
 1.12 31-Jul-1998  thorpej Remove the stats printing code. Now that the ccd driver uses the pool
allocator, there are no more stats that it keeps.
 1.11 01-Dec-1997  lukem use fparseln() instead of fgets(), improve man page
 1.10 24-Nov-1997  lukem use Bl -column, fix .Nx usage
 1.9 11-Oct-1997  enami - Use .Nm "" instead of .Nm ccdconfig in SYNOPSYS.
- Delete the period at the end of ``SEE ALSO'' list.
 1.8 10-Oct-1997  lukem all but the first .Nm in SYNOPSIS need to be spelt out. [bin/4256]
 1.7 15-Sep-1997  lukem fix use of .Nm
 1.6 31-Jul-1997  jtc Fix files using old TNF copyright notice
 1.5 30-Jan-1997  thorpej Add support to display the ccd-specific statistics kept by the ccd
driver.
 1.4 28-Feb-1996  thorpej Copyright assigned to The NetBSD Foundation.
 1.3 01-Feb-1996  thorpej Add experimental data mirroring support, derived from code written by
Satoshi Asami and Nisha Talagala. For details on using data mirroring,
see the ccd(4) manual page.
 1.2 11-Nov-1995  thorpej Fix handling of "-M core" and "-N system"; a real brain-o on my part.
Fix related typo in manual page.
 1.1 17-Aug-1995  thorpej branches: 1.1.2;
Configuration utility for the ccd.
 1.1.2.1 11-Nov-1995  thorpej Update from trunk; fix -M and -N.
 1.23.34.1 18-May-2008  yamt sync with head.
 1.23.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.12.1 23-Jun-2013  tls resync from head
 1.25.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.58 06-Oct-2020  mlelstv Use raw device for configuring units. This is necessary as
having a block device opened prevents autodiscovery of wedges.
 1.57 06-Sep-2020  mrg rework error message to never call printf() %s with NULL.
 1.56 07-Dec-2014  mlelstv branches: 1.56.18;
Make ccdconfig resolve wedge names.
 1.55 17-Aug-2014  apb Don't print ccd_size with %zu; it no longer has type size_t.
Instead, cast to uintmax_t and print with %ju.
 1.54 16-Aug-2014  sborrill Switch size_t to uint64_t in appropriate places to ensure that ccd(4) works
with component and total sizes of > 2TB.
Add COMPAT_60 code for platforms where this alters userland-accessible
structures.
Make kernel print device information when a ccd configured.
Fix some typos in comments.
 1.53 03-May-2013  christos branches: 1.53.6;
avoid initialization bug in vax gcc: int i; foo(&i);
 1.52 27-Apr-2013  christos one less kvm groveller. Use sysctl to get ccd info.
 1.51 27-Aug-2011  joerg branches: 1.51.2; 1.51.4; 1.51.8;
static. __dead.
 1.50 04-Jan-2011  wiz Fix file descriptor leak. Found by cppcheck.
 1.49 16-Mar-2009  lukem fix sign-compare issues
 1.48 20-Jul-2008  lukem branches: 1.48.2; 1.48.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.47 28-Apr-2008  martin branches: 1.47.2;
Remove clause 3 and 4 from TNF licenses
 1.46 16-Oct-2006  christos branches: 1.46.18; 1.46.20;
c99 initializers
 1.45 20-Mar-2006  christos Delete an obvious free(NULL) pointed out by erh.
 1.44 20-Mar-2006  christos Coverity CID's 1853, 1852, 1851: Plug memory leaks.
 1.43 17-Mar-2006  hubertf Fix minor ressource leak

Coverity CID 1855
OK'd by thorpej
 1.42 16-Feb-2006  lukem * The kernel's struct ccd_softc has extra structure members over the
userland version; provide another ccd global variable (ccd_softc_elemsize)
containing the kernel's size, and use that it ccdconfig(8) to convert the
kernel's ccd_softc into userland versions.
Fixes 'ccdconfig -g'.
* Use DISKUNIT() instead of home-grown cruft to determine the `N' of "ccdN".
Fixes 'ccdconfig -g ccd1'.
* Use (void *) instead of (char *) in the calls to kvm_read().

XXX: ccd could be converted from nlist to sysctl. "Someone else's yak shave".
 1.41 08-Sep-2005  drochner namespace sanity: no need to include <sys/device.h>
 1.40 20-Jan-2005  xtraeme branches: 1.40.2;
Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.39 28-Oct-2004  dsl Add (unsigned char) to isdigit()
 1.38 17-Oct-2003  lukem Support CCDF_NOLABEL. Document what CCDF_UNIFORM actually does.
 1.37 08-Oct-2003  itojun use asprintf David Hill
 1.36 08-Oct-2003  itojun plug memory leak. David Hill
 1.35 19-Sep-2003  itojun realloc pedant
 1.34 19-Feb-2001  cgd convert to use getprogname()
 1.33 28-Jan-2001  thorpej Sprinkle some const.
 1.32 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.31 07-Jul-2000  itojun warnx?/errx? audit. don't pass variable/function return value alone.
use with "%s". from openbsd.
 1.30 09-Jun-2000  enami branches: 1.30.2;
Sync with rev. 1.19 of vnconfig.c.
 1.29 16-Feb-2000  enami branches: 1.29.2;
Define __POOL_EXPOSE almost at the beginning, instead of just before
dev/vndvar.h or dev/ccdvar.h so that struct pool is always available
regardless of multiple inclusion. Actually, ccdconfig.c compiles without
this change but ...
 1.28 11-Aug-1999  thorpej Garbage-collect CCDF_SWAP; no longer used, and doesn't make any sense
with the UVM swap code.
 1.27 01-Apr-1999  ross branches: 1.27.2;
Define __POOL_EXPOSE for this nlist-groveling program.
 1.26 21-Jan-1999  thorpej update for changes to the ccd_softc.
 1.25 12-Jan-1999  thorpej Update for changes to ccdvar.h
 1.24 13-Nov-1998  thorpej CCDF_MIRROR is nuked from orbit.
 1.23 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.22 10-Aug-1998  msaitoh delete an obsolete usage
 1.21 31-Jul-1998  thorpej Remove the stats printing code. Now that the ccd driver uses the pool
allocator, there are no more stats that it keeps.
 1.20 06-Jul-1998  mrg - change setgid kmem programs (that lend themselves to this) so setegid(getgid())
and the top, and then set the effective gid back to kmem around the call to
kvm_openfiles(). this reduces the time group kmem is available.
- for those above that also allow this, setgid(getgid()) after the call to
kvm_openfiles() to fully revoke priviledges.
- some KNF
- use err(3) over fprintf(3) in some places
 1.19 03-Feb-1998  mrg use warn() properly.
 1.18 30-Dec-1997  mycroft The output of `ccdconfig -g' is supposed to be a valid configuration file.
Prefix two messages with `# ' so they're comments.
 1.17 30-Dec-1997  mrg reset the gid before calling fopen() on the config file. stops people
having read kmem access. from rotel@indigo.ie (who obtained it from
openbsd).
 1.16 05-Dec-1997  thorpej Fix type problems on the Alpha.
 1.15 01-Dec-1997  lukem use fparseln() instead of fgets(), improve man page
 1.14 14-Sep-1997  lukem branches: 1.14.2;
use memset instead of bzero
 1.13 31-Jul-1997  jtc Fix files using old TNF copyright notice
 1.12 23-Jul-1997  thorpej Clean up usage of __COPYRIGHT() macro.
 1.11 20-Jul-1997  thorpej Case size_t to "long" for printing, and use %ld for the format.
 1.10 20-Jul-1997  thorpej - Use __COPYRIGHT() and __RCSID().
- Fix compiler warnings.
 1.9 21-Apr-1997  mrg be safe with buffers.
 1.8 30-Jan-1997  thorpej Add support to display the ccd-specific statistics kept by the ccd
driver.
 1.7 06-Jun-1996  thorpej Discard setgid privelidges if not reading the running kernel, as suggested
in PR #2485 from Mike Grupenhoff <ashmir@umiacs.umd.edu>.
 1.6 16-May-1996  thorpej branches: 1.6.4;
Use getmaxpartitions() and getrawpartition() from libutil, not homegrown
versions.
 1.5 28-Feb-1996  thorpej Copyright assigned to The NetBSD Foundation.
 1.4 01-Feb-1996  thorpej Add experimental data mirroring support, derived from code written by
Satoshi Asami and Nisha Talagala. For details on using data mirroring,
see the ccd(4) manual page.
 1.3 11-Nov-1995  thorpej Fix handling of "-M core" and "-N system"; a real brain-o on my part.
Fix related typo in manual page.
 1.2 23-Aug-1995  thorpej branches: 1.2.2;
Fix up a printf(), from Chris P. Ross.
 1.1 17-Aug-1995  thorpej Configuration utility for the ccd.
 1.2.2.1 11-Nov-1995  thorpej Update from trunk; fix -M and -N.
 1.6.4.1 06-Jun-1996  thorpej Update from trunk:

Discard setgid privilidges if not reading the running kernel, as suggested
in PR #2485 from Mike Grupenhoff <ashmir@umiacs.umd.edu>.
 1.14.2.2 30-Dec-1997  mycroft Pull up revision 1.18.
 1.14.2.1 30-Dec-1997  mrg pull up rev 1.16->1.17 from trunk
 1.27.2.1 10-Oct-2000  he Pull up revision 1.32 (requested by is):
Format string cleanup.
 1.29.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.30.2.2 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.30.2.1 27-Jul-2000  itojun pullup (approved by releng-1-5)
printf-like format pedant. do not pass string variable alone. use "%s".
from openbsd.

/cvsroot/basesrc/sbin/swapctl/swapctl.c 1.14 -> 1.15
/cvsroot/basesrc/sbin/ping6/ping6.c 1.15 -> 1.16
/cvsroot/basesrc/sbin/disklabel/disklabel.c 1.84 -> 1.85
/cvsroot/basesrc/sbin/ccdconfig/ccdconfig.c 1.30 -> 1.31
 1.40.2.1 20-Feb-2006  tron Pull up following revision(s) (requested by lukem in ticket #1178):
sys/dev/ccd.c: revision 1.108
sbin/ccdconfig/ccdconfig.c: revision 1.42
* The kernel's struct ccd_softc has extra structure members over the
userland version; provide another ccd global variable (ccd_softc_elemsize)
containing the kernel's size, and use that it ccdconfig(8) to convert the
kernel's ccd_softc into userland versions.
Fixes 'ccdconfig -g'.
* Use DISKUNIT() instead of home-grown cruft to determine the `N' of "ccdN".
Fixes 'ccdconfig -g ccd1'.
* Use (void *) instead of (char *) in the calls to kvm_read().
XXX: ccd could be converted from nlist to sysctl. "Someone else's yak shave".
 1.46.20.1 18-May-2008  yamt sync with head.
 1.46.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.46.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.47.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.48.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.48.2.1 27-Aug-2014  msaitoh Pull up following revision(s) (requested by sborrill in ticket #1919):
sbin/ccdconfig/ccdconfig.c 1.54 via patch
sys/dev/ccd.c 1.152 via patch
sys/dev/ccdvar.h 1.34 via patch

Switch size_t to uint64_t in appropriate places to ensure that ccd(4)
works with component and total sizes of > 2TB.
Make kernel print device information when a ccd configured.
Fix some typos in comments.
 1.51.8.1 23-Jun-2013  tls resync from head
 1.51.4.1 27-Aug-2014  msaitoh Pull up following revision(s) (requested by sborrill in ticket #1113):
sbin/ccdconfig/ccdconfig.c 1.54 via patch
sys/dev/ccd.c 1.152 via patch
sys/dev/ccdvar.h 1.34 via patch

Switch size_t to uint64_t in appropriate places to ensure that ccd(4)
works with component and total sizes of > 2TB.
Make kernel print device information when a ccd configured.
Fix some typos in comments.
 1.51.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.53.6.2 09-Dec-2014  martin Pull up following revision(s) (requested by mlelstv in ticket #305):
sbin/ccdconfig/ccdconfig.c: revision 1.56
Make ccdconfig resolve wedge names.
 1.53.6.1 18-Aug-2014  martin Pull up following revision(s) (requested by sborrill in ticket #38):
sys/dev/ccd.c: revision 1.152
sbin/ccdconfig/ccdconfig.c: revision 1.54
sbin/ccdconfig/ccdconfig.c: revision 1.55
sys/dev/ccdvar.h: revision 1.34
Switch size_t to uint64_t in appropriate places to ensure that ccd(4) works
with component and total sizes of > 2TB.
Add COMPAT_60 code for platforms where this alters userland-accessible
structures.
Make kernel print device information when a ccd configured.
Fix some typos in comments.
Don't print ccd_size with %zu; it no longer has type size_t.
Instead, cast to uintmax_t and print with %ju.
 1.56.18.1 11-Oct-2020  martin Pull up following revision(s) (requested by mlelstv in ticket #1110):

sys/dev/dkwedge/dk.c: revision 1.102
sys/dev/ccd.c: revision 1.185
sbin/ccdconfig/ccdconfig.c: revision 1.58

Use raw device for configuring units. This is necessary as
having a block device opened prevents autodiscovery of wedges.

Fix ioctl locking. Add dkdriver.

Check dkdriver before calling a driver function.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 31-Jul-1997  jtc branches: 1.3.46; 1.3.48;
Fix files using old TNF copyright notice
 1.2 28-Feb-1996  thorpej Copyright assigned to The NetBSD Foundation.
 1.1 17-Aug-1995  thorpej Configuration utility for the ccd.
 1.3.48.1 18-May-2008  yamt sync with head.
 1.3.46.1 02-Jun-2008  mjf Sync with HEAD.
 1.23 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.22 12-Aug-2022  riastradh branches: 1.22.2;
cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.21 17-May-2022  christos Use the Makefile.inc from libargon2 (fixes the vax build that requires
a compiler hack).
 1.20 16-May-2022  christos make things behave just like before the libcrypt symbol renaming:
The normal cgdconfig binary is built with threads and the crunched one
in rescue without.
 1.19 16-May-2022  christos Re-enable threads; apparently we get different results depending if we are
threaded or not... This tastes like a bug.
 1.18 15-May-2022  christos Build argon2 inline so that crunched programs work. I also disabled threads
for now; we can put them back if needed.
 1.17 28-Nov-2021  christos -lpthread to LDADD (fixes lint build)
 1.16 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.15 01-Jul-2016  christos replace openssl HMAC(3) with our hmac(3).
 1.14 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.13 19-Dec-2009  pooka Use RUMP_ACTION to avoid having to specify the same information
in the Makefiles of all the consumers.
 1.12 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.11 20-Apr-2009  drochner define YY_NO_INPUT where appropriate, from Kurt J. Lidl per PR misc/41160
 1.10 24-Jul-2008  dholland branches: 1.10.4;
Adjust this to not need -Wno-pointer-sign.
 1.9 21-Jul-2008  gmcgarry Add HAVE_PCC tests for -Wno-pointer-sign.
 1.8 16-Feb-2008  matt branches: 1.8.4; 1.8.8;
Change incorrect usage of CFLAGS to CPPFLAGS
 1.7 11-May-2006  mrg branches: 1.7.10; 1.7.12;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.6 25-Feb-2006  simonb We link against libl and liby, so depend on them too.
 1.5 09-Mar-2005  christos Add -lcrypt where -lcrypto is specified.
 1.4 17-Apr-2003  thorpej We need -I., too.
 1.3 17-Apr-2003  fvdl -I. -> -I${.CURDIR}
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.7.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.7.10.1 23-Mar-2008  matt sync with HEAD
 1.8.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.10.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.4 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.3 05-Dec-2010  pooka mirror change of -lrumpcrypto ==> -lrumpkern_crypto
 1.2 19-Dec-2009  pooka Use RUMP_ACTION to avoid having to specify the same information
in the Makefiles of all the consumers.
 1.1 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.1 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.1 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.3 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.2 13-Oct-2009  pooka fix prototypes of function pointers to varargs syscalls
 1.1 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.4 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.3 13-Oct-2009  pooka fix prototypes of function pointers to varargs syscalls
 1.2 10-Sep-2009  pooka fix LP64 builds. yay, C type system.

patch from Joachim Kuebart
 1.1 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.2 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.1 19-Dec-2009  pooka Use RUMP_ACTION to avoid having to specify the same information
in the Makefiles of all the consumers.
 1.59 09-Oct-2024  riastradh cgdconfig(8): Estimate verify methods' false accept probabilities.

An addendum following discussion around:

PR bin/58212: cgdconfig(8): Add zfs verification method
 1.58 12-May-2024  christos branches: 1.58.2;
PR/58212: Malte Dehling: Add zfs verification method
 1.57 12-Aug-2022  riastradh branches: 1.57.2;
cgdconfig(8): Handle -P/-S for shared keys with -G too.

This way you can convert an existing parameters file to one that is
derived from a shared key, and derive other subkeys for other disks
from the same shared key.

cgdconfig -G -S -o /etc/cgd/wd0.shared /etc/cgd/wd0
cgdconfig -G -S -o /etc/cgd/wd1.shared \
-P /etc/cgd/wd0.shared /etc/cgd/wd1

This way, if you enter the same new password both times, wd0.shared
and wd1.shared generate the same keys as wd0 and wd1, but only need
one password entry with `cgdconfig -C'.
 1.56 12-Aug-2022  riastradh cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.55 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.54 12-Aug-2022  riastradh cgdconfig(8): New -T operation prints all generated keys in cgd.conf.

For testing purposes.
 1.53 12-Aug-2022  riastradh cgdconfig(8): New -t operation just prints the derived key in base64.

For testing purposes.
 1.52 04-Dec-2021  nia cgdconfig.8: Use argon2id in examples
 1.51 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.50 30-Apr-2021  nia cgdconfig.8: use gpt in examples, it's more versatile for this use case
 1.49 18-Apr-2021  maya The -n flag is useless with -g, don't mention it.

From rudolf in PR misc/36243
 1.48 11-Dec-2020  riastradh Touch up cgdconfig(8) man page.

- Suggest adiantum first.
- Remove references to Blowfish.
- Clarify that ivmethod is relevant only for ancient compatibility.
 1.47 23-Jun-2020  wiz Use Nm.
 1.46 23-Jun-2020  nia cgdconfig.8: remove references to using cgd for swap

this is potentially misleading now that the kernel does swap encryption
 1.45 23-Jun-2020  nia cgdconfig.8: Reflect actual behaviour of /dev/(u)random
 1.44 29-Dec-2018  wiz Sort SEE ALSO.
 1.43 28-Dec-2018  alnsn s/Dec/December/.
 1.42 27-Dec-2018  alnsn Document that cgd.conf supports NAME=label and ROOT.<suffix> targets.

XXX Default paramsfile for NAME=label is /etc/cgd/dkNN (resolved wedge
partition) and /etc/cgd/ROOT.<suffix> for ROOT.<suffix>. This isn't yet
documented. IMO, it should be the other way around: /etc/cgd/label
for the former and /et/cgd/[root-device] for the latter.
 1.41 01-Sep-2018  prlw1 typo
 1.40 09-May-2018  kre branches: 1.40.2;

With the change to use getpass_r the 128 byte passphrase limit no
longer applies, so update the BUGS section here to reflect that change.
The limit now is 1023 whichever method is used to fetch the passphrase.
 1.39 09-May-2018  alnsn Add '-e' option (echo the passphrase) and wipe the passphrase after use.

XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.
 1.38 09-May-2018  wiz Add commas in enumeration.
 1.37 09-May-2018  kre Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.

While here fix man page synopses and a few other odds and ends.
 1.36 11-Sep-2016  sevan branches: 1.36.6; 1.36.12;
Spelling mistake.
Bump date.
 1.35 14-Dec-2014  wiz Bump date for previous. Fix typo.
 1.34 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.33 05-Dec-2012  wiz Whitespace.
New sentence, new line.
 1.32 05-Dec-2012  christos add cgdconfig -l like vnconfig -l
 1.31 03-Jul-2011  dholland branches: 1.31.2; 1.31.8;
fix typo
 1.30 30-Mar-2010  joerg \\ -> \e
 1.29 19-Oct-2009  wiz Document -n, from Jukka Ruohonen in private mail.
Bump date.
 1.28 12-Sep-2008  christos PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV
 1.27 13-May-2008  wiz Bump date for previous.
 1.26 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.25 10-May-2008  elric Add -p flag to retrieve passphrases from stdin. This is mainly aimed
at programatic use where the caller wants to be able to use PKCS#5.

Disable looping on invalid verifications unless both a passphrase method
is in use and the -p flag is not specified.

Update man page to document -p flag.
 1.24 30-Apr-2008  martin branches: 1.24.2;
Convert TNF licenses to new 2 clause variant
 1.23 23-Feb-2007  rumble branches: 1.23.12; 1.23.14;
Add a DIAGNOSTICS section and explain that the error message "could not
calibrate pkcs5_pbkdf2" could have resulted due to dynamic changes in cpu
clock frequency.
 1.22 15-Oct-2004  salo Correct the omission in 're-enter' verification method addition in EXAMPLES.
 1.21 13-Aug-2004  wiz Bump date for previous, and re-add some flags that were removed in the
previous commit without a mention in the commit message, and which are
still in the usage.
 1.20 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.19 04-Jul-2004  elric Add options to SYNOPSIS.

Addresses PR misc/26065.
 1.18 17-Mar-2004  wiz branches: 1.18.2;
Drop trailing whitespace; new sentence, new line.
 1.17 17-Mar-2004  dan Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.16 23-Sep-2003  wiz Add article.
 1.15 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.14 27-Jun-2003  wiz Remove superfluous "".
 1.13 16-Apr-2003  wiz Bump date for last-but-one; remove superfluous .Pp.
 1.12 15-Apr-2003  elric Fix typo. params files are not stored in /dev/cgd/
 1.11 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.10 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.9 19-Jan-2003  atatat The next release will be 2.0, not 1.7.
 1.8 13-Oct-2002  elric At the suggestion of wiz@, we remove the lines that mention that the
lack of the feature added earlier today was a bug.
 1.7 12-Oct-2002  elric Add documentation for verification methods. Specify defaults for IV
method, keygen method and verification method.
 1.6 07-Oct-2002  wiz Begin new sentence in upper case.
 1.5 05-Oct-2002  grant cgdconfig first appeared in NetBSD 1.7 (for now).
 1.4 05-Oct-2002  grant New sentence, new line. Some mdoc cleanup, other minor nits.
 1.3 05-Oct-2002  dan note some other caveats and uses
 1.2 04-Oct-2002  dan channelling wiz
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.18.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.23.14.1 18-May-2008  yamt sync with head.
 1.23.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.23.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.24.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.31.8.1 25-Feb-2013  tls resync with head
 1.31.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.36.12.3 18-Jan-2019  pgoyette Synch with HEAD
 1.36.12.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.36.12.1 21-May-2018  pgoyette Sync with HEAD
 1.36.6.2 07-Aug-2018  martin Pull up following revision(s) (requested by alnsn in ticket #958):

sbin/cgdconfig/cgdconfig.c: revision 1.46
sbin/cgdconfig/cgdconfig.c: revision 1.47
sbin/cgdconfig/cgdconfig.c: revision 1.48
sbin/cgdconfig/cgdconfig.8: revision 1.39
sbin/cgdconfig/cgdconfig.8: revision 1.40

Add '-e' option (echo the passphrase) and wipe the passphrase after use.
XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.

Missed one change when doing a manual merge of my patch with kre's commit.

use explicit_memset(3)

With the change to use getpass_r the 128 byte passphrase limit no
longer applies, so update the BUGS section here to reflect that change.
The limit now is 1023 whichever method is used to fetch the passphrase.
 1.36.6.1 31-Jul-2018  martin Pull up following revision(s) (requested by kre in ticket #946):

sbin/cgdconfig/cgdconfig.c: revision 1.42
sbin/cgdconfig/cgdconfig.c: revision 1.43
sbin/cgdconfig/cgdconfig.c: revision 1.44
sbin/cgdconfig/cgdconfig.c: revision 1.45
sbin/cgdconfig/cgdconfig.8: revision 1.37
sbin/cgdconfig/cgdconfig.8: revision 1.38

Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).

Fix usage for rump. Fixes test breakage caused by previous commit.
Check arg count in configure() at entry, rather than later.

This avoids the stupid null deref I added a couple of commits
ago (on bad usage) and also simplifies the rest of the routine
which no longer needs to check the arg count nearly as much.
Thanks to Alexander Nasonov for finding the null deref bug.

Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.
While here fix man page synopses and a few other odds and ends.
Add commas in enumeration.
 1.40.2.1 10-Jun-2019  christos Sync with HEAD
 1.57.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.58.2.1 02-Aug-2025  perseant Sync with HEAD
 1.63 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.62 29-Apr-2024  riastradh cgdconfig(8): KNF in cgdconfig.c.

No functional change intended.
 1.61 17-Nov-2022  chs branches: 1.61.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.60 13-Sep-2022  riastradh cgdconfig(8): Restore loop for password re-entry for non-shared keys.

Fixes mistake in previous which changed the semantics in the case
where _no_ keys are shared.
 1.59 30-Aug-2022  riastradh cgdconfig(8): Gracefully handle failed verification with shared keys.

The first time each key is verified, if verification fails, we chuck
the failed key and try again with passphrase re-entry.

But if a key has already been verified, and verification fails,
assume something is wrong with the disk and fail.
 1.58 12-Aug-2022  riastradh cgdconfig(8): Handle -P/-S for shared keys with -G too.

This way you can convert an existing parameters file to one that is
derived from a shared key, and derive other subkeys for other disks
from the same shared key.

cgdconfig -G -S -o /etc/cgd/wd0.shared /etc/cgd/wd0
cgdconfig -G -S -o /etc/cgd/wd1.shared \
-P /etc/cgd/wd0.shared /etc/cgd/wd1

This way, if you enter the same new password both times, wd0.shared
and wd1.shared generate the same keys as wd0 and wd1, but only need
one password entry with `cgdconfig -C'.
 1.57 12-Aug-2022  riastradh cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.56 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.55 12-Aug-2022  riastradh cgdconfig(8): New -T operation prints all generated keys in cgd.conf.

For testing purposes.
 1.54 12-Aug-2022  riastradh cgdconfig(8): New -t operation just prints the derived key in base64.

For testing purposes.
 1.53 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.52 16-Jun-2021  riastradh cgdconfig(8): Fail more gracefully than SIGSEGV if shell_cmd fails.
 1.51 18-Apr-2021  maya The -n flag is useless with -g, don't mention it.

From rudolf in PR misc/36243
 1.50 10-Apr-2019  kre KNF, 80 column police, a few other tidy ups (use if (ret == 0) rather
than if (!ret) when ret is not a boolean, and test fopen result against
NULL, for example).

NFCI.
 1.49 10-Apr-2019  kre PR bin/53999 from rudolf (eq.cz)

Fix cgdconfig to report verification failures with gpt and mbr
verification methods (and not treat them as silent hard errors).
This also causes the cgd to be unconfigured when one of those
verification methods fails.

Add ATF tests to check that bad verification is reported, and
does not leave the cgd configured.

Patches from the PR applied.
 1.48 09-May-2018  alnsn branches: 1.48.2;
use explicit_memset(3)
 1.47 09-May-2018  alnsn Missed one change when doing a manual merge of my patch with kre's commit.
 1.46 09-May-2018  alnsn Add '-e' option (echo the passphrase) and wipe the passphrase after use.

XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.
 1.45 09-May-2018  kre Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.

While here fix man page synopses and a few other odds and ends.
 1.44 09-May-2018  kre Check arg count in configure() at entry, rather than later.
This avoids the stupid null deref I added a couple of commits
ago (on bad usage) and also simplifies the rest of the routine
which no longer needs to check the arg count nearly as much.

Thanks to Alexander Nasonov for finding the null deref bug.
 1.43 06-May-2018  kre Fix usage for rump. Fixes test breakage caused by previous commit.
 1.42 05-May-2018  kre Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).
 1.41 10-Jan-2017  christos branches: 1.41.6; 1.41.12;
Need <sys/stat.h> for S_IFBLK.
 1.40 22-Nov-2015  christos branches: 1.40.2;
Don't chdir to the config directory; just form the parameters file with a
path if needed.
 1.39 14-Dec-2014  christos fix possibly uninitialized variable.
 1.38 14-Dec-2014  christos avoid local variable shadowing devname.
 1.37 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.36 14-Dec-2014  mlelstv support wedge names.

The default param file for a wedge is still named after the device (dkN)
which might be unpredictable. Use an explicit param file instead.
 1.35 09-Jun-2013  christos List all cgd's no matter if they are not contiguously allocated
 1.34 05-Dec-2012  christos add cgdconfig -l like vnconfig -l
 1.33 29-Aug-2011  joerg branches: 1.33.2; 1.33.8;
Use __dead
 1.32 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.31 02-Dec-2010  elric Remove a line that was intended only for my personal testing and that
breaks things.
 1.30 02-Dec-2010  elric In -G, refuse to operate if KEYGEN_URANDOM is specified as we already do
for KEYGEN_RANDOMKEY.

Print a warning if such a refusal is made---this will help the user understand
why there is an error.

Patch provided by: Taylor R Campbell <campbell+netbsd@mumble.net>.
 1.29 27-Nov-2010  elric Remove trailing whitespace (patch provided by: Taylor R Campbell
<campbell+netbsd@mumble.net>)
 1.28 08-Sep-2009  pooka * allow specification of kernel operations vector
* make it possible to build cgdconfig as a library
 1.27 24-Jul-2008  christos PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV

Add "encblkno1" IV type to encrypt only once, rename old "encblkno" to
"encblkno8" for clarity, and make "encblkno" an alias for "encblkno8"
for backward compatibility.
 1.26 24-Jul-2008  dholland bzero the passphrase before freeing it, to discourage chill attacks.
 1.25 24-Jul-2008  dholland Adjust this to not need -Wno-pointer-sign.
 1.24 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.23 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.22 10-May-2008  elric Add -p flag to retrieve passphrases from stdin. This is mainly aimed
at programatic use where the caller wants to be able to use PKCS#5.

Disable looping on invalid verifications unless both a passphrase method
is in use and the -p flag is not specified.

Update man page to document -p flag.
 1.21 28-Apr-2008  martin branches: 1.21.2;
Remove clause 3 and 4 from TNF licenses
 1.20 06-Nov-2007  martin branches: 1.20.8; 1.20.10;
Do not use %d for size_t
 1.19 06-Nov-2007  christos 3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.18 06-Feb-2007  cbiere branches: 1.18.4;
Fixed format string in opendisk_werror() which was wrong since my previous
commit.
 1.17 06-Feb-2007  cbiere * 1 -> EXIT_FAILURE.
* Replaced atoi() with parse_int().
* Use an enum for ACTION_* instead of #define.
* Use strdup() or asnprintf() instead of strlcpy() to avoid truncation.
* pread() returns ssize_t not int.
* Suppress "unused parameter" warnings.
* verify_disklabel(): Pass the correct size to disklabel_scan().
* verify_ffs():
* Don't indicate success if pread() fails.
* Check the amount of bytes read.
* Don't cast buf to (struct fs *), it's not aligned.
* eliminate_cores(): No need for a temporary variable.
 1.16 27-Jun-2005  christos - constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.15 30-Mar-2005  elric setprogname(3) needs to come before calls to err(3).
 1.14 30-Mar-2005  elric Lock all memory.
 1.13 30-Mar-2005  elric Turn off core dumps.
 1.12 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.11 10-Aug-2004  rumble In getkey(), check the return values of the various keygen functions
and abort if necessary. Also, check for errors in its callers and
handle them gracefully.

OK'd by elric.
 1.10 17-Mar-2004  dan branches: 1.10.2;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.9 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.8 17-May-2003  itojun use strlcpy
 1.7 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.6 24-Mar-2003  elric Quick bugfix:
o need to do keygen_filldefaults() in generate_convert no
matter what, not only if there are no existing keygen
methods in the new parameters.
 1.5 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.4 28-Oct-2002  elric bugfix: was still pulling random bits from /dev/random when generating
a paramsfile of type randomkey which does not need them. Pointed out
by dan@netbsd.org.
 1.3 12-Oct-2002  elric Add the concept of a verification method which allows cgdconfig(8)
to reprompt for the passphrase if the key does not meet certain
criteria. The currently implemented methods are ``none'' and
``disklabel''. The first behaves in the original fashion, the
second will scan for a disklabel on the cgd after configuration
and if it does not find a disklabel then it will reprompt for the
password and reconfigure the disk.
 1.2 12-Oct-2002  elric Small usage enhancement: open the cgd before prompting for the passphrase
so that errors can be reported w/o asking for the passphrase unnec.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.10.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.18.4.4 23-Mar-2008  matt sync with HEAD
 1.18.4.3 08-Jan-2008  matt Pull in changes from HEAD to make compile
 1.18.4.2 08-Nov-2007  matt sync with HEAD
 1.18.4.1 06-Nov-2007  matt sync with HEAD
 1.20.10.1 18-May-2008  yamt sync with head.
 1.20.8.2 28-Sep-2008  mjf Sync with HEAD.
 1.20.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.33.8.2 23-Jun-2013  tls resync from head
 1.33.8.1 25-Feb-2013  tls resync with head
 1.33.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.33.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.40.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.41.12.1 21-May-2018  pgoyette Sync with HEAD
 1.41.6.2 07-Aug-2018  martin Pull up following revision(s) (requested by alnsn in ticket #958):

sbin/cgdconfig/cgdconfig.c: revision 1.46
sbin/cgdconfig/cgdconfig.c: revision 1.47
sbin/cgdconfig/cgdconfig.c: revision 1.48
sbin/cgdconfig/cgdconfig.8: revision 1.39
sbin/cgdconfig/cgdconfig.8: revision 1.40

Add '-e' option (echo the passphrase) and wipe the passphrase after use.
XXX Using memset for wiping isn't a good idea because memset is likely
optimised away by gcc. This should be revisited.

Missed one change when doing a manual merge of my patch with kre's commit.

use explicit_memset(3)

With the change to use getpass_r the 128 byte passphrase limit no
longer applies, so update the BUGS section here to reflect that change.
The limit now is 1023 whichever method is used to fetch the passphrase.
 1.41.6.1 31-Jul-2018  martin Pull up following revision(s) (requested by kre in ticket #946):

sbin/cgdconfig/cgdconfig.c: revision 1.42
sbin/cgdconfig/cgdconfig.c: revision 1.43
sbin/cgdconfig/cgdconfig.c: revision 1.44
sbin/cgdconfig/cgdconfig.c: revision 1.45
sbin/cgdconfig/cgdconfig.8: revision 1.37
sbin/cgdconfig/cgdconfig.8: revision 1.38

Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).

Fix usage for rump. Fixes test breakage caused by previous commit.
Check arg count in configure() at entry, rather than later.

This avoids the stupid null deref I added a couple of commits
ago (on bad usage) and also simplifies the rest of the routine
which no longer needs to check the arg count nearly as much.
Thanks to Alexander Nasonov for finding the null deref bug.

Fix missing -p in usage message (noted by Christoph Badura, thanks),
and update -l usage as well.
While here fix man page synopses and a few other odds and ends.
Add commas in enumeration.
 1.48.2.1 10-Jun-2019  christos Sync with HEAD
 1.61.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.2 22-Nov-2015  christos Don't chdir to the config directory; just form the parameters file with a
path if needed.
 1.1 08-Sep-2009  pooka Remember to add cgdconfig.h too.
 1.1 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.1 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.7 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.6 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.5 29-Oct-2009  christos use %option instead of #define YY_NO_...
 1.4 28-Oct-2009  christos no unput
 1.3 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.2 28-Apr-2008  martin branches: 1.2.2;
Remove clause 3 and 4 from TNF licenses
 1.1 24-Mar-2003  elric branches: 1.1.32; 1.1.34;
substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1.34.1 18-May-2008  yamt sync with head.
 1.1.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.6 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.5 17-Jul-2008  drochner include <stdlib.h> explicitely, for exit(), getprogname() etc.
(it happens to be pulled in by the yacc skeleton, but we shouldn't
rely on this)
 1.4 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.3 28-Apr-2008  martin branches: 1.3.2;
Remove clause 3 and 4 from TNF licenses
 1.2 27-Jun-2005  christos branches: 1.2.20; 1.2.22;
- constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.1 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.2.22.1 18-May-2008  yamt sync with head.
 1.2.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.2.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.2 16-Feb-2008  matt yyerror returns void, not int
 1.1 27-Jun-2005  christos branches: 1.1.10; 1.1.12;
- constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.1.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.10.1 23-Mar-2008  matt sync with HEAD
 1.1 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.1 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.35 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.34 12-Aug-2022  riastradh branches: 1.34.2;
cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.33 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.32 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.31 03-Jun-2021  prlw1 Make adiantum a first class citizen
 1.30 30-Dec-2018  mlelstv branches: 1.30.8;
Avoid crash when no algorithm is specified in parameter file.
 1.29 11-Dec-2016  alnsn branches: 1.29.12; 1.29.14;
Add aes-xts to cgdconfig(8).
 1.28 24-Nov-2015  christos branches: 1.28.2;
CID 1340063: fix TOCTOU
 1.27 22-Nov-2015  christos Don't chdir to the config directory; just form the parameters file with a
path if needed.
 1.26 16-Jun-2015  christos fix error messages containing \n
 1.25 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.24 12-Sep-2008  christos PR/39525: Joachim Schueth, Frederik Sausmikat:
cgd inadvertently encrypts blkno eight times to generate IV
 1.23 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.22 28-Apr-2008  martin branches: 1.22.2;
Remove clause 3 and 4 from TNF licenses
 1.21 11-Nov-2007  christos branches: 1.21.8; 1.21.10;
simplify and fix the combination code. Hi pooka.
 1.20 06-Nov-2007  christos 3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.19 06-Feb-2007  cbiere branches: 1.19.4;
Use warn() and warnx().
 1.18 06-Feb-2007  cbiere crypt_defaults_lookup():
* Avoid comparison of int with unsigned.
* Simplified.
 1.17 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.16 26-Aug-2006  christos Programs that use efun.
 1.15 17-Mar-2006  elad Proper bounds check, found by Coverity, CID 1468.
 1.14 27-Jun-2005  christos - constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.13 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.12 04-Jan-2005  elric Fix comment. We're using microseconds not milliseconds.
 1.11 04-Jan-2005  elric Fix bits vs. bytes problem in call to calibration routine.
 1.10 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.9 17-Mar-2004  dan branches: 1.9.2;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.8 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.7 13-Jul-2003  itojun die if asprintf fails to malloc
 1.6 10-Apr-2003  elric If reading an old style parameters file then default a missing
keygen_iteration to 128. This will not default the iteration count
on a new style parameter file as it is an error in the new style
to fail to specify the iteration count.

Addresses PR: bin/21056
 1.5 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.4 04-Dec-2002  elric Make iteration count for PKCS#5 settable in the parameters files.
 1.3 30-Nov-2002  lukem tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
 1.2 12-Oct-2002  elric Add the concept of a verification method which allows cgdconfig(8)
to reprompt for the passphrase if the key does not meet certain
criteria. The currently implemented methods are ``none'' and
``disklabel''. The first behaves in the original fashion, the
second will scan for a disklabel on the cgd after configuration
and if it does not find a disklabel then it will reprompt for the
password and reconfigure the disk.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.9.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.19.4.2 09-Jan-2008  matt sync with HEAD
 1.19.4.1 06-Nov-2007  matt sync with HEAD
 1.21.10.1 18-May-2008  yamt sync with head.
 1.21.8.2 28-Sep-2008  mjf Sync with HEAD.
 1.21.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.2.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.22.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.28.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.29.14.1 10-Jun-2019  christos Sync with HEAD
 1.29.12.1 18-Jan-2019  pgoyette Synch with HEAD
 1.30.8.1 06-Jun-2021  cjep sync with head
 1.34.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.15 12-May-2024  christos PR/58212: Malte Dehling: Add zfs verification method
 1.14 12-Aug-2022  riastradh branches: 1.14.2;
cgdconfig(8): Add support for generating shared-key parameters files.

Usage model:

- Generate a parameters file that supports sharing its main key:

cgdconfig -g -S -o /etc/cgd/wd0e -V gpt adiantum

- Make another parameters file that uses the same shared main key but
derives an independent subkey from it:

cgdconfig -g -S -P /etc/cgd/wd0e -o /etc/cgd/ld1e \
-V disklabel aes-cbc 256
 1.13 12-Aug-2022  riastradh cgdconfig(8): Add support for shared keys.

New clause `shared <id> algorithm <alg> subkey <info>' in a keygen
block enables `cgdconfig -C' to reuse a key between different params
files, so you can, e.g., use a single password for multiple disks.
This is better than simply caching the password itself because:

- Hashing the password is expensive, so it should only be done once.

Suppose your budget is time t before you get bored, and you
calibrate password hash parameters to unlock n disks before you get
bored waiting for `cgdconfig -C'.

. With n password hashings the adversary's cost goes up only by a
factor of t/n.
. With one password hashing and n subkeys the adversary's cost goes
up by a factor of n.

And if you ever add a disk, rehashing it will make `cgdconfig -C'
go over budget, whereas another subkey adds negligible cost to you.

- Subkeys work for other types of keygen blocks, like shell_cmd,
which could be used to get a key from a hardware token that needs a
button press.

The <info> parameter must be different for each params file;
everything else in the keygen block must be the same. With this
clause, the keygen block determines a shared key used only to derive
keys; the actual key used by cgdconfig is derived from the shared key
by the specified algorithm.

The only supported algorithm is hkdf-hmac-sha256, which uses
HKDF-Expand of RFC 5869 instantiated with SHA-256.

Example:

algorithm aes-cbc;
iv-method encblkno1;
keylength 128;
verify_method none;
keygen pkcs5_pbkdf2/sha1 {
iterations 39361;
salt AAAAgMoHiYonye6KogdYJAobCHE=;
shared "pw" algorithm hkdf-hmac-sha256
subkey AAAAgFlw0BMQ5gY+haYkZ6JC+yY=;
};

The key used for this disk will be derived by

HKDF-HMAC-SHA256_k(WXDQExDmBj6FpiRnokL7Jg==),

where k is the outcome of PBKDF2-SHA1 with the given parameters.

Note that <info> encodes a four-byte prefix giving the big-endian
length in bits of the info argument to HKDF, just like all other bit
strings in cgdconfig parameters files.

If you have multiple disks configured using the same keygen block
except for the info parameter, `cgdconfig -C' will only prompt once
for your passphrase, generate a shared key k with PBKDF2 as usual,
and then reuse it for each of the disks.
 1.12 22-Nov-2021  nia cgdconfig(8): Add an argon2id password-based key generation method

This provides an extra level of side-channel and cracking resistance
compared to the pre-existing pkcs5_pbkdf2/sha1 method used for
password-based disk encryption.

Several new keygen parameters are supported:

memory (integer, in kilobytes)
parallelism (integer, usually the number of CPU cores)
version (integer, usually 19...)

We do our best to calibrate these automatically when the paramsfile
is initially generated.

lgtm riastradh@
 1.11 14-Dec-2014  mlelstv Add validation methods "mbr" and "gpt" for disks without a valid disklabel.
 1.10 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.9 28-Apr-2008  martin branches: 1.9.2;
Remove clause 3 and 4 from TNF licenses
 1.8 06-Nov-2007  christos branches: 1.8.8; 1.8.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.7 13-Aug-2004  tv branches: 1.7.16;
Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.6 17-Mar-2004  dan branches: 1.6.2;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.5 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.4 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.3 04-Dec-2002  elric Make iteration count for PKCS#5 settable in the parameters files.
 1.2 12-Oct-2002  elric Add the concept of a verification method which allows cgdconfig(8)
to reprompt for the passphrase if the key does not meet certain
criteria. The currently implemented methods are ``none'' and
``disklabel''. The first behaves in the original fashion, the
second will scan for a disklabel on the cgd after configuration
and if it does not find a disklabel then it will reprompt for the
password and reconfigure the disk.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.6.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.7.16.1 06-Nov-2007  matt sync with HEAD
 1.8.10.1 18-May-2008  yamt sync with head.
 1.8.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.2.1 11-Oct-2024  martin Pull up following revision(s) (requested by riastradh in ticket #941):

sbin/cgdconfig/params.c: revision 1.35
sbin/cgdconfig/params.h: revision 1.15
sbin/cgdconfig/cgdconfig.c: revision 1.62
sbin/cgdconfig/cgdconfig.c: revision 1.63
sbin/cgdconfig/cgdconfig.8: revision 1.58
sbin/cgdconfig/cgdconfig.8: revision 1.59
sbin/cgdconfig/Makefile: revision 1.23

cgdconfig(8): KNF in cgdconfig.c.
No functional change intended.

PR/58212: Malte Dehling: Add zfs verification method

cgdconfig(8): Estimate verify methods' false accept probabilities.
An addendum following discussion around:
PR bin/58212: cgdconfig(8): Add zfs verification method
 1.17 22-Nov-2021  nia cgdconfig(8): add some console feedback when calculating the number
of pkcs5_pbkdf2 iterations
 1.16 01-Jul-2016  christos replace openssl HMAC(3) with our hmac(3).
 1.15 27-Nov-2010  elric Remove trailing whitespace (patch provided by: Taylor R Campbell
<campbell+netbsd@mumble.net>)
 1.14 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.13 21-Apr-2008  christos PR/28627: Andreas Gustafsson: Try 5 times to calibrate before failing. Should
fix issues with CPU's that don't produce consistent timing output due to code
morphing or power-savings.
 1.12 06-Nov-2007  martin branches: 1.12.8; 1.12.10;
size_t != unsigned int - so don't pass the address of the former when a
pointer to the latter is expected.
 1.11 06-Nov-2007  christos 3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.10 27-Jan-2007  cbiere branches: 1.10.4;
Replaced int_encode() with be32enc().
 1.9 26-Aug-2006  christos Programs that use efun.
 1.8 11-May-2006  mrg HMAC() wants unsigned int pointer for the final argument; make it so.
 1.7 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.6 04-Jan-2005  elric s/milliseconds/microseconds/ in comments and a variable because it is
misleading to say one when we've been meaning the other.
 1.5 17-Mar-2004  dan Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.4 25-Sep-2003  cb back out revision 1.3. this should not have been committed yet,
since it breaks backward compatibility.

noticed by recht@
 1.3 23-Sep-2003  cb add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.10.4.2 08-Nov-2007  matt sync with HEAD
 1.10.4.1 06-Nov-2007  matt sync with HEAD
 1.12.10.1 18-May-2008  yamt sync with head.
 1.12.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4 06-Nov-2007  christos branches: 1.4.8; 1.4.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.3 17-Mar-2004  dan branches: 1.3.22;
Fix a longstanding algorithmic flaw in PKCS#5 key generation.

The existing pkcs5_pbdkf2 keygen method is retained functionally
as-is, for compatibility with existing params files. The corrected
algorithm, which is now the default for new params file generation, is
called pkcs5_pbkdf2/sha1.

NB. The backwards compatibility for the miscreant keygen method will
be removed at the same time as support for the previous parameters
file syntax. Sometime between now and then, users should update their
params files using -G, which will create a new params file including
an xor value so that the resulting generated key is the same; they
should also

Problem discovery and 2-char algorithm fix by Charles Blundell, messy
compat goop by me, long complicated names by Roland Dowdeswell.

Update manpage accordingly and bump date.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.3.22.1 06-Nov-2007  matt sync with HEAD
 1.4.10.1 18-May-2008  yamt sync with head.
 1.4.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.1 14-Dec-2010  pooka Convert from the oldstyle cgd_kops.op_open to the newstyle prog_open
and define RUMPPRG. Get rid of the Makefile.inc stuff, since it was
useful only for the oldstyle regime.
 1.21 20-Mar-2012  matt Convert to C89 function definitions
 1.20 11-Apr-2009  lukem branches: 1.20.6;
fix sign-compare issues
 1.19 11-May-2008  elric branches: 1.19.4;
Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.18 28-Apr-2008  martin branches: 1.18.2;
Remove clause 3 and 4 from TNF licenses
 1.17 06-Nov-2007  christos branches: 1.17.8; 1.17.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.16 06-Feb-2007  cbiere branches: 1.16.4;
memxor(): Fixed size_t/int mismatch.
 1.15 26-Aug-2006  christos Programs that use efun.
 1.14 11-May-2006  mrg __b64_pton() wants unsigned char *.
 1.13 22-Mar-2006  christos Coverity CID 2753: Free the correct variable.
 1.12 22-Mar-2006  christos fix compile problem.
 1.11 22-Mar-2006  christos Coverity CID 1593: Plug memory leak
 1.10 20-Mar-2006  christos Coverity CID 1203: Check return code of b64_ntop().
 1.9 27-Jun-2005  christos - constify.
- don't dup extern declarations on each file because they end up being
inconsistent (yyerror).
 1.8 02-Jun-2005  lukem Avoid dereferencing/free()ing invalid pointers if the random device
cannot be opened.
Detected with gcc -Wuninitialized.
(The bug was fixed in rev 1.4 by rumble but reintroduced in rev 1.5 by tv !)
 1.7 30-Mar-2005  elric one more malloc -> emalloc.
 1.6 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.5 13-Aug-2004  tv branches: 1.5.2;
Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.4 10-Aug-2004  rumble Avoid dereferencing/free()ing invalid pointers if the random device
cannot be opened.

OK'd by elric.
 1.3 23-Sep-2003  cb branches: 1.3.2;
add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.3.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.5.2.1 14-Jun-2005  tron Pull up revision 1.8 (requested by lukem in ticket #404):
Avoid dereferencing/free()ing invalid pointers if the random device
cannot be opened.
Detected with gcc -Wuninitialized.
(The bug was fixed in rev 1.4 by rumble but reintroduced in rev 1.5 by tv !)
 1.16.4.1 06-Nov-2007  matt sync with HEAD
 1.17.10.1 18-May-2008  yamt sync with head.
 1.17.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.20.6.1 17-Apr-2012  yamt sync with head
 1.9 11-May-2008  elric Add a new keygen method which will execute an external command and
take its output as the key. I've been meaning to do this for quite
a while...
 1.8 28-Apr-2008  martin branches: 1.8.2;
Remove clause 3 and 4 from TNF licenses
 1.7 06-Nov-2007  christos branches: 1.7.8; 1.7.10;
3 month roland feedback timeout:
- Pass lint
- knf
- convert ints to size_t's
 1.6 26-Aug-2006  christos branches: 1.6.8;
Programs that use efun.
 1.5 30-Mar-2005  christos Centralize error checking for malloc,calloc,strdup.
 1.4 13-Aug-2004  tv Add "urandomkey" key generation method as described in PR kern/22766;
useful for configuring a throwaway key for cgd-on-swap at boot time.
 1.3 23-Sep-2003  cb branches: 1.3.2;
add a new verification method that prompts for the pkcs#5 pbkdf2
passphrase again and checks the generated key against the original.
 1.2 24-Mar-2003  elric substantial rototill of the code.

o added new features:
o -G: generate a new paramsfile that produces the same
key as the old paramsfile,
o ffs verify_method,
o multiple keygen methods that are xor'ed together
(for n-factor authentication), and
o calibrating the iteration count of PKCS#5 PBKDF2 to
the current machine's speed.
o changed paramsfile format to allow for the new features.
o replaced open-coded parser with yacc grammar.
o lots of supporting changes.
o updated documentation to reflect new features and new
paramsfile format.
 1.1 04-Oct-2002  elric Initial checkin of cgdconfig(8), a program to configure a cgd.
 1.3.2.1 13-Aug-2004  tv Oy, sometimes CVS sticky tags hurt. Revert urandomkey; that should be on HEAD.
 1.6.8.1 06-Nov-2007  matt sync with HEAD
 1.7.10.1 18-May-2008  yamt sync with head.
 1.7.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1 14-Mar-2001  thorpej Add a chkconfig(8) utility for managing rc.conf.d settings. Written
by Dan Mercer <dmercer@zembu.com>, inspired by the similar command that
appears in IRIX.
 1.6 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.5 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.4 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.3 05-Jun-2001  wiz Drop arguments of .Os.
 1.2 03-Apr-2001  wiz Add section to .Xr.
 1.1 14-Mar-2001  thorpej Add a chkconfig(8) utility for managing rc.conf.d settings. Written
by Dan Mercer <dmercer@zembu.com>, inspired by the similar command that
appears in IRIX.
 1.3 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.2 04-Jan-2003  wiz Spell output with two ts.
 1.1 14-Mar-2001  thorpej Add a chkconfig(8) utility for managing rc.conf.d settings. Written
by Dan Mercer <dmercer@zembu.com>, inspired by the similar command that
appears in IRIX.
 1.6 13-Jan-2011  haad Use SYMLINKS, I'm not sure why I ahve commited old version of my patch, but
it should be ok now. Thanks to tron@ for pointing at this issue.
 1.5 13-Jan-2011  haad Move chown from usr.sbin to sbin and chgrp from usr.bin to bin directories.
This was discussed and oked on tech-userlevel I have run full build release,
test anita cycle with this patch.
 1.4 03-Nov-1993  mycroft Clean up deleted files.
 1.3 01-Aug-1993  mycroft Add RCS identifiers.
 1.2 05-Apr-1993  cgd made link to chgrp relative
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10 20-May-2023  pgoyette ALso fix chgrp Synopsis to include -d option
 1.9 04-May-2023  pgoyette Add a -d flag to avoid changing a file's owner/group to the current
value. This avoids some unnecessary operations on the file.

As discussed on tech-userlevel@
 1.8 04-Jul-2017  wiz Add EXIT STATUS section. Use Ex.
 1.7 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.6 17-Dec-2013  apb In all man pages that say:

The -H, -L and -P options are ignored unless the -R option is
specified. In addition, these options override each other and the
command's actions are determined by the last one specified.

Add:

The default is as if the -P option had been specified.
 1.5 22-Oct-2012  christos support --reference=rfile
 1.4 13-Jan-2011  haad branches: 1.4.6; 1.4.12;
Move chown from usr.sbin to sbin and chgrp from usr.bin to bin directories.
This was discussed and oked on tech-userlevel I have run full build release,
test anita cycle with this patch.
 1.3 03-Nov-1993  mycroft Clean up deleted files.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.4.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.1 30-Oct-2012  yamt sync with head
 1.14 20-May-2023  pgoyette dd -d to the Synopsis
 1.13 04-May-2023  pgoyette Add a -d flag to avoid changing a file's owner/group to the current
value. This avoids some unnecessary operations on the file.

As discussed on tech-userlevel@
 1.12 04-Jul-2017  wiz Add EXIT STATUS section. Use Ex. Sort sections.
 1.11 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.10 11-Sep-2016  sevan Document the version chown first appeared.
Replace contractions highlighted by textproc/igor.
Bump date.
 1.9 12-Jul-2016  wiz Bump date for previous.
 1.8 12-Jul-2016  zafer improve description regarding symbolic links. ok @wiz.
 1.7 17-Dec-2013  apb In all man pages that say:

The -H, -L and -P options are ignored unless the -R option is
specified. In addition, these options override each other and the
command's actions are determined by the last one specified.

Add:

The default is as if the -P option had been specified.
 1.6 23-Oct-2012  wiz + ly
 1.5 22-Oct-2012  christos support --reference=rfile
 1.4 13-Jan-2011  haad branches: 1.4.6; 1.4.12;
Move chown from usr.sbin to sbin and chgrp from usr.bin to bin directories.
This was discussed and oked on tech-userlevel I have run full build release,
test anita cycle with this patch.
 1.3 03-Nov-1993  mycroft Clean up deleted files.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.4.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.6.1 30-Oct-2012  yamt sync with head
 1.12 04-May-2023  christos KNF: no space after ( and before ), constants on the RHS (like everywhere else
in this file).
 1.11 04-May-2023  martin Cast -1 to expected type and fix a edititing mishap to make this build.
 1.10 04-May-2023  pgoyette Add a -d flag to avoid changing a file's owner/group to the current
value. This avoids some unnecessary operations on the file.

As discussed on tech-userlevel@
 1.9 28-Apr-2023  pgoyette Fix typo in comment
 1.8 24-Oct-2012  enami The id chgrp command is required to change is not uid but gid.
 1.7 23-Oct-2012  christos - use {g,s}etprogname()
- fix usage
 1.6 22-Oct-2012  christos support --reference=rfile
 1.5 29-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 13-Jan-2011  haad Move chown from usr.sbin to sbin and chgrp from usr.bin to bin directories.
This was discussed and oked on tech-userlevel I have run full build release,
test anita cycle with this patch.
 1.3 03-Nov-1993  mycroft Clean up deleted files.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.5.2.1 30-Oct-2012  yamt sync with head
 1.15 26-Jul-2009  dholland Remove gross hack and attendant need for -fno-strict-aliasing.
 1.14 29-Aug-2008  gmcgarry Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.13 11-May-2006  mrg branches: 1.13.20; 1.13.24;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.12 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.11 20-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=3
 1.10 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.9 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.8 18-Mar-1998  bouyer Add support for non-native endian FFS.
Clear the clean flag in the SB when an inode has been cleared.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.13.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.9 12-Sep-2016  sevan Actually, V6 included clri before 3BSD.
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/man/man8/clri.8
Amend HISTORY once more.
Bump date.
 1.8 11-Sep-2016  sevan Document the version clri first appeared.
Bump date.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 05-Jun-2001  wiz Drop arguments of .Os.
 1.5 06-Apr-1999  cgd change:
.Sh "SEE ALSO"
to:
.Sh SEE ALSO
The doc macros check for the latter (actually just for 'SEE' as the first
argument to .Sh) to set the section header SEE ALSO flag, which modifies
some behaviour (e.g. references done with .Rs/.Re).
 1.4 14-Sep-1997  lukem - fix use of .Nm
- deprecate use of register
- cleanup for WARNS=1
 1.3 11-Jul-1997  mikel icheck(8) and ncheck(8) Went Away a *long* time ago
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.26 26-Feb-2023  andvar s/superblok/superblock/ in comment.
 1.25 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.24 30-Aug-2015  mlelstv Calculate sector size from superblock and use that instead of DEV_BSIZE.
 1.23 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.22 26-Jul-2009  dholland branches: 1.22.6; 1.22.12;
Remove gross hack and attendant need for -fno-strict-aliasing.
 1.21 16-Mar-2009  lukem fix sign-compare issues
 1.20 20-Jul-2008  lukem branches: 1.20.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.19 20-Jan-2005  xtraeme branches: 1.19.26; 1.19.30;
Kill __P(), ANSIfy, remove main() prototype; WARNS=3
 1.18 27-Mar-2004  dsl Don'r check FS_FLAGS_UPDATED for ffsv2
 1.17 21-Mar-2004  dsl When searching for the superblock, check that the fs_sblockloc field
matches the location we read it from to ensure we don't have one of the
alternate superblocks.
Fixes part of PR kern/24809
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.15 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.14 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.13 25-Aug-1998  ross branches: 1.13.10;
from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.12 18-Mar-1998  bouyer Add support for non-native endian FFS.
Clear the clean flag in the SB when an inode has been cleared.
 1.11 16-Sep-1997  lukem resolve sccsid conflict
 1.10 14-Sep-1997  lukem - fix use of .Nm
- deprecate use of register
- cleanup for WARNS=1
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 30-Jan-1995  mycroft Make this more type safe.
 1.7 23-Sep-1994  mycroft err(3)/warn(3) cleanup
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.10.1 25-Nov-2001  he Pull up revision 1.14 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.19.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.20.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5 15-Feb-2015  christos let's make this compile again.
 1.4 11-Aug-2013  dholland branches: 1.4.4;
These pass WARNS=5, so don't set WARNS=4
 1.3 11-Jan-2013  mlelstv Provide a script for devpubd(8) that creates symlinks for each dk(4)
device under /dev/wedges so that you can access them by name.
 1.2 06-Sep-2011  riz branches: 1.2.2; 1.2.8;
Build and install the skeleton manpage for devpubd - it's better than
nothing.
 1.1 29-Aug-2011  mrg add the device publish daemon, written by jmcneill@.

listens on drvctl for new devices and invokes MAKEDEV for them.

missing:
- manual page
- rc.d script
- more testing

but it works well enough to make new disk nodes appear in /dev when
netbsd sees them and they're missing. you will need to make sure
you have a new /dev/MAKEDEV for this to work properly (postinstall
should handle this normally, of course.)


thanks jared!
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 25-Feb-2013  tls resync with head
 1.2.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.2.1 23-Jan-2013  yamt sync with head
 1.4.4.1 17-Feb-2015  martin Pull up following revision(s) (requested by jmcneill in ticket #525):
sbin/devpubd/hooks/01-makedev: revision 1.2
sbin/devpubd/devpubd-run-hooks.in: revision 1.3
sbin/devpubd/Makefile: revision 1.5
sbin/devpubd/hooks/02-wedgenames: revision 1.2
sbin/devpubd/devpubd.c: revision 1.3
sbin/devpubd/devpubd.c: revision 1.4
At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.
Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
let's make this compile again.
 1.4 05-Aug-2021  kre Expunge bogus (implementation defined / unspecified) uses of $@ in
scripts. $@ is unspecified except when used in a place where
field splitting can occur (which is never in an assignment),
X=$@ (with or without double quotes) is simply wrong.

Use $* instead of $@ in such places, or as here, simply change
the way things are done (very very slightly) and DTRT.
 1.3 15-Feb-2015  jmcneill At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.

Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
 1.2 04-Dec-2011  jmcneill branches: 1.2.18;
exit 0 on success
 1.1 29-Aug-2011  mrg branches: 1.1.2;
add the device publish daemon, written by jmcneill@.

listens on drvctl for new devices and invokes MAKEDEV for them.

missing:
- manual page
- rc.d script
- more testing

but it works well enough to make new disk nodes appear in /dev when
netbsd sees them and they're missing. you will need to make sure
you have a new /dev/MAKEDEV for this to work properly (postinstall
should handle this normally, of course.)


thanks jared!
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.18.1 17-Feb-2015  martin Pull up following revision(s) (requested by jmcneill in ticket #525):
sbin/devpubd/hooks/01-makedev: revision 1.2
sbin/devpubd/devpubd-run-hooks.in: revision 1.3
sbin/devpubd/Makefile: revision 1.5
sbin/devpubd/hooks/02-wedgenames: revision 1.2
sbin/devpubd/devpubd.c: revision 1.3
sbin/devpubd/devpubd.c: revision 1.4
At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.
Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
let's make this compile again.
 1.7 24-Feb-2020  wiz New sentence, new line. Bump date for previous.
 1.6 24-Feb-2020  mlelstv Add one-shot mode.
 1.5 11-Sep-2016  sevan branches: 1.5.14;
Document the version devpubd first appeared.
Bump date.
 1.4 12-Jan-2013  wiz Bump date for previous.
 1.3 11-Jan-2013  mlelstv Provide a script for devpubd(8) that creates symlinks for each dk(4)
device under /dev/wedges so that you can access them by name.
 1.2 22-Nov-2012  reed Add some details about the hook scripts.
 1.1 29-Aug-2011  wiz branches: 1.1.2; 1.1.8;
Add minimal devpubd man page, not hooked into the build yet.

XXX: someone should write drvctl(4)
 1.1.8.1 25-Feb-2013  tls resync with head
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.5.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.7 21-Jun-2021  christos fix proplib deprecation
 1.6 24-Feb-2020  mlelstv Add one-shot mode.
 1.5 06-Feb-2020  kamil Stop including unused header <sys/poll.h>
 1.4 15-Feb-2015  christos branches: 1.4.16;
let's make this compile again.
 1.3 15-Feb-2015  jmcneill At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.

Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
 1.2 16-Sep-2011  joerg branches: 1.2.20;
Use __dead. Save a pointer.
 1.1 29-Aug-2011  mrg add the device publish daemon, written by jmcneill@.

listens on drvctl for new devices and invokes MAKEDEV for them.

missing:
- manual page
- rc.d script
- more testing

but it works well enough to make new disk nodes appear in /dev when
netbsd sees them and they're missing. you will need to make sure
you have a new /dev/MAKEDEV for this to work properly (postinstall
should handle this normally, of course.)


thanks jared!
 1.2.20.1 17-Feb-2015  martin Pull up following revision(s) (requested by jmcneill in ticket #525):
sbin/devpubd/hooks/01-makedev: revision 1.2
sbin/devpubd/devpubd-run-hooks.in: revision 1.3
sbin/devpubd/Makefile: revision 1.5
sbin/devpubd/hooks/02-wedgenames: revision 1.2
sbin/devpubd/devpubd.c: revision 1.3
sbin/devpubd/devpubd.c: revision 1.4
At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.
Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
let's make this compile again.
 1.4.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 05-Aug-2021  kre Expunge bogus (implementation defined / unspecified) uses of $@ in
scripts. $@ is unspecified except when used in a place where
field splitting can occur (which is never in an assignment),
X=$@ (with or without double quotes) is simply wrong.

Use $* instead of $@ in such places, or as here, simply change
the way things are done (very very slightly) and DTRT.
 1.2 15-Feb-2015  jmcneill At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.

Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
 1.1 29-Aug-2011  mrg branches: 1.1.20;
add the device publish daemon, written by jmcneill@.

listens on drvctl for new devices and invokes MAKEDEV for them.

missing:
- manual page
- rc.d script
- more testing

but it works well enough to make new disk nodes appear in /dev when
netbsd sees them and they're missing. you will need to make sure
you have a new /dev/MAKEDEV for this to work properly (postinstall
should handle this normally, of course.)


thanks jared!
 1.1.20.1 17-Feb-2015  martin Pull up following revision(s) (requested by jmcneill in ticket #525):
sbin/devpubd/hooks/01-makedev: revision 1.2
sbin/devpubd/devpubd-run-hooks.in: revision 1.3
sbin/devpubd/Makefile: revision 1.5
sbin/devpubd/hooks/02-wedgenames: revision 1.2
sbin/devpubd/devpubd.c: revision 1.3
sbin/devpubd/devpubd.c: revision 1.4
At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.
Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
let's make this compile again.
 1.8 08-Aug-2021  martin Fix obvious editor mishap in previous
 1.7 05-Aug-2021  kre Obliterate bogus $@ usage.

While here, fix some quoting, change some style, and attempt
to properly handle wedge names with embedded newlines, and those
that end with a '/' character (not particularly happy with the
solution to that last one, but it is better than it was).

Is there a reason that characters that need encoding in wedge names
(white space, and more) are encoded as %%XX (XX is the hex value of
the char - but 2 % chars? Why?). That remains unchanged, but as
the script already relied upon sh's $'...' quoting, I think we can rely
upon printf as well, so replace the old (very elegant, but slow) encoding
function with a much simpler one (does the same thing).
 1.6 09-Jan-2021  mlelstv Also replace calls to dirname.
 1.5 09-Jan-2021  mlelstv Remove need for awk/sed/readlink tools.
 1.4 15-Aug-2016  mlelstv Avoid error message when /dev/wedges doesn't exist yet.
 1.3 01-Mar-2015  mlelstv safely update existing wedge links
 1.2 15-Feb-2015  jmcneill At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.

Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
 1.1 11-Jan-2013  mlelstv branches: 1.1.2; 1.1.6; 1.1.12;
Provide a script for devpubd(8) that creates symlinks for each dk(4)
device under /dev/wedges so that you can access them by name.
 1.1.12.2 07-Mar-2015  snj Pull up following revision(s) (requested by mlelstv in ticket #561):
sbin/devpubd/hooks/02-wedgenames: revision 1.3
safely update existing wedge links
 1.1.12.1 17-Feb-2015  martin Pull up following revision(s) (requested by jmcneill in ticket #525):
sbin/devpubd/hooks/01-makedev: revision 1.2
sbin/devpubd/devpubd-run-hooks.in: revision 1.3
sbin/devpubd/Makefile: revision 1.5
sbin/devpubd/hooks/02-wedgenames: revision 1.2
sbin/devpubd/devpubd.c: revision 1.3
sbin/devpubd/devpubd.c: revision 1.4
At startup, instead of doing run-hooks for each device, call run-hooks
once with a list of all found devices. This lets us batch calls to MAKEDEV
which results in a noticeable improvement in Raspberry Pi boot time.
Run the initial device enumeration hooks before detaching from the foreground,
ensuring that any required devices have been created before the rc.d script
exits.
let's make this compile again.
 1.1.6.2 25-Feb-2013  tls resync with head
 1.1.6.1 11-Jan-2013  tls file 02-wedgenames was added on branch tls-maxphys on 2013-02-25 00:28:04 +0000
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 11-Jan-2013  yamt file 02-wedgenames was added on branch yamt-pagecache on 2013-01-23 00:05:28 +0000
 1.75 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.74 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.73 24-Jan-2018  skrll branches: 1.73.4;
Remove port-acorn26

OK core@
 1.72 31-Jan-2016  christos fix broken patch
 1.71 31-Jan-2016  christos PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)
 1.70 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.69 30-Aug-2011  bouyer branches: 1.69.2; 1.69.8;
Add getlabelusesmbr(), as proposed in
http://mail-index.netbsd.org/tech-userlevel/2011/08/25/msg005404.html
This is used by disk tools such as disklabel(8) to dynamically decide is
the undelyling platform uses a disklabel-in-mbr-partition or not
(instead of using a compile-time list of ports).
getlabelusesmbr() reads the sysctl kern.labelusesmbr, takes its value from the
machdep #define LABELUSESMBR.
For evbmips, make LABELUSESMBR 1 if the platform uses pmon
as bootloader, and 0 (the previous value) otherwise.
 1.68 18-Aug-2011  phx Define USE_MBR for ofppc.
 1.67 12-Feb-2011  dholland Disable COMPAT_386BSD_MBRPART. The code is still here if anyone needs it
for some reason. (But I have no idea why that would be -- if you have one
of these really ancient partitions and you're about to run disklabel, you
can easily run fdisk first and change the partition type to NetBSD.)

As it stands, the code will munch FreeBSD installs under some
circumstances, which is really not acceptable behavior.

The code, along with the kernel support that's been disabled by
default for several years, and some related but less dangerous code in
sysinst, should prboably be removed entirely after -6 is branched.

Discussed on tech-kern and tech-userlevel; closes PR 44496.

This is also almost certainly the cause of PR 42521 and PR 38841.
 1.66 13-Dec-2009  nakayama branches: 1.66.2;
System utilities, boot programs and kernel modules are machine
(port) specific not CPU, so use MACHINE not MACHINE_ARCH.
 1.65 05-Dec-2009  pooka Remove support for NetBSD/playstation2.
 1.64 28-Nov-2009  tsutsui Don't use #ifdef __${MACHINE_ARCH}__ to enable machine dependent features.
Instead, use proper macro defined in Makefile per ${MACHINE_ARCH}.

__${MACHINE_ARCH}__ doesn't represent an architecture of tool's target
but an architecture of binaries being compiled, so required features
are not prolery enabled or unintentionally enabled on certain host
and target combinations during src/tools build.
 1.63 28-Nov-2009  tsutsui Make dreamcast, evbsh3, and mmeye use -DUSE_MBR.
All of these ports use src/sys/arch/sh3/sh3/disksubr.c
which is MBR aware.
 1.62 14-Feb-2009  abs Convert more MACHINE tests to MACHINE_ARCH
 1.61 11-Mar-2008  aymeric branches: 1.61.6; 1.61.8;
The hpcsh kernel does for sure USE_MBR. Make disklabel use it too on hpcsh.
With this, it is possible to bootstrap a MBR partitioned CF card without
partitioning and disklabelling it first on another platform.
 1.60 18-Dec-2006  nonaka branches: 1.60.4; 1.60.10; 1.60.12;
zaurus use MBR partition info.
 1.59 01-Sep-2006  uwe New NetBSD/landisk port uses MBR too.
 1.58 19-Oct-2005  dsl Rototil the way disklabel -r reads and writes labels.
In particular the 'read' part plays 'hunt the disklabel' in order to get a
label into a local buffer - from where it can be displayed/edited.
The 'write' part makes a separate scan of the disk looking for places to
write the label.
The main changes are:
- It can no longer write the first 8k of the mbr to the pbr (or v.v.)
- All labels on the disk (that it can find) get updated during a write
- With -A all the labels are displayed (inc. those deleted by -D)
- Addition of -D which will delete (by one's complimenting dk_magic{2}) and
existing labels before writing labels to the expected locations.
- -v gives some verbose output to stderr, -vv more etc
A better basis for processing incorrect endian labels, or labels from other
architectures.
 1.57 23-Jun-2005  fvdl If HOSTPROG is empty, do not pull in libutil, since we do not need it in that
case, and several host platforms do not have libutil. Fixes the build of
these programs as host tools on platforms without libutil.
 1.56 17-Jun-2005  dsl Rip out the support for writing bootstrap code. installboot(8) contains
support for hp300, hp700 and vax, $MACHINE is never arm32.
Fix usage output to only contain progname() once - bug introduced in rev 1.89
 1.55 12-Jun-2005  dyoung Make disklabel(8) into a host-tool, "nbdisklabel." Move disklabel.c
to main.c to avoid a name collision with lib/libc/gen/disklabel.c
when we build nbdisklabel. Still todo: commit host-tool build
infrastructure to src/tools/disklabel/.
 1.54 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.53 20-Jan-2005  xtraeme WARNS=2
 1.52 13-Oct-2004  gavan Initial import of iyonix port.

The Iyonix is a desktop machine from Castle Technology, based on a 600MHz
XScale[tm] 80321 processor.

* Uses the bootloader from NetBSD/acorn32, which is now 32-bit compatible.
* Currently boots multiuser with a serial console.
* Device support is not yet complete.

With help from abs.
 1.51 28-Jun-2004  jkunz Add hp700 MD options for proper boot code handling.
 1.50 18-Jan-2004  lukem * Enable SAVEBOOTAREA on i386 and amd64 (by merging the Makefile
controls with the section for the other MBR-using platforms that
already enable this)
* Don't prompt the user to "erase the previous contents of the disk"
when there's no NetBSD MBR partition; SAVEBOOTAREA is sufficient.

These fixes mean that you can create a disklabel (on an i386/amd64) on a disk
that doesn't have a NetBSD MBR partition without trashing the existing MBR.
The previous behaviour was extremely annoying when working with media such
as FAT-formatted CF cards, and didn't really protect people with such from
accidentally trashing part of sector 1 of such disks, and made it extremely
easy to trash sectors 0..15 of those disks instead.
 1.49 10-Nov-2003  fvdl Bring back disklabel -B for now, since hp300 installboot isn't ready
for prime time yet.
 1.48 08-Nov-2003  dsl Rip out all the '-B bootblock' support, everything should use installboot(8).
(can only affect arm32, hp300 and vax ports, and doesn't affect sysinst).
 1.47 02-Nov-2003  shin playstation2 needs MBR support in disklabel(8).
 1.46 26-Apr-2003  fvdl x86_64 -> amd64
 1.45 11-Dec-2002  fvdl Handle MBRs for x86_64.
 1.44 28-Jul-2002  manu Enable USE_MBR for all arm ports.
 1.43 18-Jun-2002  itojun USE_MBR on macppc too
 1.42 24-Mar-2002  bjh21 Rename arm26 -> acorn26.
 1.41 29-Nov-2001  bjh21 Rather than making FileCore boot block support conditional on __arm32__, make
it conditional on USE_ACORN, and define that if MACHINE is arm26 or acorn32.
This is less than optimal, and maybe we should define it for all ARM systems,
but then disklabel handling across architectures is generally a mess at the
moment.
 1.40 19-Nov-2001  minoura Preserve the boot area on x68k.
 1.39 24-Dec-2000  lukem move showinfo() and showpartition() into separate file, for use by
other programs. slightly change argument signature so that globals
aren't depended upon.
 1.38 02-May-2000  soren branches: 1.38.4;
MBR on cobalt too.
 1.37 02-May-2000  nonaka also use mbr partition table on prep.
 1.36 31-Jan-2000  soda - use MBR partition table also on arc.
- use defined(USE_MBR) instead of defined(__i386__), like hpcmips and arc.
 1.35 09-Jan-2000  shin Add '-DSAVEBOOTAREA' to keep MBR partition information
when NetBSD partition starts at sector 0.
Closes PR:port-hpcmips/9146.
 1.34 11-Oct-1999  shin add hpcmips support (MBR)
 1.33 03-Jun-1999  cgd branches: 1.33.2;
On NetBSD/alpha, go out of the way to read the boot area's contents if -r
is specified, so that the boot blocks aren't clobbered when writing labels.
 1.32 09-Apr-1999  kleink Update a pasto-ed comment.
 1.31 21-Jan-1999  pk branches: 1.31.2;
Enable non-cylinder-aligned partition warning on sparc[64] & sun3.
See also PR#6853.
 1.30 02-Mar-1998  drochner Handle new MBR partition ID on i386. Put all code which decides about
usability of an entry to one place, use same algorithm as kernel (ie,
check signature).
 1.29 18-Oct-1997  mark branches: 1.29.2;
Define NUMBOOT=1 for the arm32 port.
 1.28 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.27 25-Sep-1997  lukem switch to using opendisk(3) from libutil
 1.26 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.25 30-Jun-1997  christos Fix warnings.
 1.24 07-Jun-1997  perry i386 now uses "installboot" for installing boot blocks. Comment out
the CFLAGS+= -DNUMBOOT=2 for now.
 1.23 18-Mar-1997  christos Remove -g
 1.22 18-Mar-1997  christos Off by one.
 1.21 14-Mar-1997  perry Nuke obsolete special case .if for amigas.
 1.20 09-Mar-1997  christos Jason says: Use getmaxpartitions(3) to determine the number of partitions
allowed in this architecture.
 1.19 08-Mar-1997  christos Add -i (interactive mode to create/edit labels) inspired by the SunOS/Solaris
format/partition command.
 1.18 17-Oct-1995  cgd don't define NUMBOOT on the alpha, any more. boot block installation
is now done by /usr/mdec/installboot.
 1.17 23-Apr-1995  ragge Changed to use only one bootblock file on VAX.
 1.16 18-Apr-1995  ragge Added vax for 2-file boot blocks.
 1.15 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.14 11-Feb-1995  cgd NUMBOOT == 2 on the alpha, too.
 1.13 22-Dec-1994  cgd kill unnecessary .include.
 1.12 22-Dec-1994  cgd specify man pages the new way.
 1.11 20-Dec-1994  cgd pull in bsd.own.mk by hand, early, so NOMAN= can be defined there.
 1.10 22-Sep-1994  mycroft Finish 4.4-Lite merge, and convert to use err(3)/warn(3) functions.
 1.9 24-Jun-1994  hpeyerl disklabel(8) from 4.4 merged with our old disklabel(8) by John Brezak
(brezak@apollo.hp.com). hp300's can now disklabel by themselves.
 1.8 12-Feb-1994  chopps added -D${MACHINE} for amiga's becuase of differing sizeof (struct disklabel)
 1.7 01-Aug-1993  mycroft Add RCS identifiers.
 1.6 18-Jul-1993  mycroft Use ${COPY}, not -c for install.
 1.5 25-Apr-1993  mycroft Don't build man page if NOMAN set.
 1.4 10-Apr-1993  cgd make user the cat5 dir exists before trying to install man page there.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.29.2.1 23-Nov-1998  cgd pull up rev 1.30 from trunk (jonathan)
 1.31.2.1 21-Jun-1999  perry pullup 1.32->1.33 (cgd)
 1.33.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.38.4.1 26-Feb-2001  he Pull up revision 1.39 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.60.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.60.10.1 24-Mar-2008  keiichi sync with head.
 1.60.4.1 23-Mar-2008  matt sync with HEAD
 1.61.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.61.6.1 08-Mar-2011  riz Pull up following revision(s) (requested by dholland in ticket #1561):
sbin/disklabel/Makefile: revision 1.67
Disable COMPAT_386BSD_MBRPART. The code is still here if anyone needs it
for some reason. (But I have no idea why that would be -- if you have one
of these really ancient partitions and you're about to run disklabel, you
can easily run fdisk first and change the partition type to NetBSD.)
As it stands, the code will munch FreeBSD installs under some
circumstances, which is really not acceptable behavior.
The code, along with the kernel support that's been disabled by
default for several years, and some related but less dangerous code in
sysinst, should prboably be removed entirely after -6 is branched.
Discussed on tech-kern and tech-userlevel; closes PR 44496.
This is also almost certainly the cause of PR 42521 and PR 38841.
 1.66.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.69.8.1 23-Jun-2013  tls resync from head
 1.69.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.73.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 31-Jan-2016  christos PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)
 1.4 18-Jul-2015  htodd Fix build.
 1.3 17-Jul-2015  tsutsui Fix botch in "make disklabel a MI tool" changes in rev 1.2.

After that chanage, "MAXPARTITIONS" constant is not for the target port.
If host's MAXPARTITIONS is larger than a value of the target label and
target endianness is different from the build host, bswaplabel() could
overwrite data beyond the disklabel and primary boot stored after
LABELSECTOR in images might be corrupted.

This fixes boot failure of sun2 liveimage built by
"build.sh -U -m sun2 release live-image"
on TME.

Should be pulled up to netbsd-7.
 1.2 03-May-2013  matt branches: 1.2.6;
Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.1 05-Jan-2010  tsutsui branches: 1.1.6; 1.1.12;
Add necessary byteswap ops for tools disklabel(8) used with -F option
(treating a target disk as a regular file and suppressing ioctl(2)s)
on reading/writing disklabel in a target file.
This allows cross build enviroment creating bootable disk images
for targets in different endian.
No functional changes to native (non-tools) disklabel(8) command.

Closes PR toolchain/42357.
 1.1.12.1 23-Jun-2013  tls resync from head
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.6.1 30-Jul-2015  martin Pull up following revision(s) (requested by tsutsui in ticket #891):
sbin/disklabel/bswap.c: revision 1.3-1.4

Fix botch in "make disklabel a MI tool" changes in rev 1.2.

After that chanage, "MAXPARTITIONS" constant is not for the target port.
If host's MAXPARTITIONS is larger than a value of the target label and
target endianness is different from the build host, bswaplabel() could
overwrite data beyond the disklabel and primary boot stored after
LABELSECTOR in images might be corrupted.

This fixes boot failure of sun2 liveimage built by
"build.sh -U -m sun2 release live-image"
on TME.

Fix build.
 1.3 31-Jan-2016  christos PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)
 1.2 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.1 05-Jan-2010  tsutsui branches: 1.1.6; 1.1.12;
Add necessary byteswap ops for tools disklabel(8) used with -F option
(treating a target disk as a regular file and suppressing ioctl(2)s)
on reading/writing disklabel in a target file.
This allows cross build enviroment creating bootable disk images
for targets in different endian.
No functional changes to native (non-tools) disklabel(8) command.

Closes PR toolchain/42357.
 1.1.12.1 23-Jun-2013  tls resync from head
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31 28-Aug-2022  hgutch Change back various occurrences of \*[Le], \*[Ge] (less/greater equal)
and \*(ua (upwards arrow) to literal "<=", ">=" and "^" whenever
appropriate (e.g., in code examples).
 1.30 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.29 15-Oct-2016  snj revert part of revision 1.28. "e.g." is correct. bad igor!
 1.28 11-Sep-2016  sevan Grammar fix suggested by textproc/igor.
Syntax fix highlighted by mandoc -Tlint.
Bump date.
 1.27 25-Feb-2006  christos branches: 1.27.68;
mark vinum as obsolete.
 1.26 21-Sep-2005  tsutsui Sync DK types and FS types with <sys/disklabel.h>.

XXX: More other stuff should be sync'ed?
 1.25 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.24 13-Jul-2003  lukem xref dkctl(8)
 1.23 16-Apr-2003  wiz Use
.In header.h
instead of
.Fd #include \*[Lt]header.h\*[Gt]
Much easier to read and write, and supported by groff for ages.
Okayed by ross.
 1.22 12-Dec-2002  scw Use getlabel{sector,offset}() instead of LABEL{SECTOR,OFFSET}.
 1.21 02-Oct-2002  wiz partition, not parition (by Adrian Mrva). file system instead of filesystem.
 1.20 28-Sep-2002  dbj add FS_APPLEUFS
part of PR #17345
 1.19 28-Sep-2002  dbj tweak indentation on FS_JFS2 comment
 1.18 28-Sep-2002  dbj add DTYPE_JFS2 and FS_JFS2 for IBM Journaled File System
this is to match FreeBSD's disklabel.h revision 1.73
FreeBSD change was requested by Hiten Pandya <hiten@uk.FreeBSD.org>
 1.17 28-Sep-2002  dbj fix DTYPE_LD comment
 1.16 28-Sep-2002  dbj add DTYPE_LD to match disklabel.h
 1.15 08-Feb-2002  ross branches: 1.15.2;
Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.14 16-Nov-2001  wiz Use .Pp for new paragraphs.
 1.13 06-Jan-2001  cgd #warn is _not_ the GCC CPP directive that gives a warning, #warning is.
(this code has, apparently, always been wrong, but current GCC is kind
enough to warn about unknown CPP directives.)
 1.12 13-Jul-2000  msaitoh s/ ar / are /
 1.11 05-Apr-2000  enami branches: 1.11.4;
Introduce new filesystem type FS_CCD so that an operator can mark the
ccd component partition. Note that the ccd driver still allows partitions
of any types as components since an on-disk BSD disklabel isn't available
on some port.
 1.10 16-Mar-2000  enami Sync disklabel.5 with disklabel.h and dkio.h more closely.
 1.9 11-Feb-2000  oster Note the "RAID" partition type.
 1.8 13-Aug-1999  bouyer Sync with sys/disklabel.h
 1.7 29-Apr-1998  fair fix bad .Xr references
 1.6 28-Apr-1998  fair Principally, change foo(N) to .Xr foo N
Also, do some other mdoc tagging.
 1.5 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.4 03-Jul-1996  pk Update.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 05-Feb-1995  cgd docs follow code.
 1.1 22-Dec-1994  cgd specify man pages the new way.
 1.11.4.2 26-Feb-2001  he Pull up revision 1.13 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.11.4.1 21-Sep-2000  msaitoh pullup revision 1.12 (approved by releng-1.5):

s/ ar / are /
 1.15.2.3 09-Sep-2003  tron Pull up revision 1.18 (requested by tv in ticket #1454):
add DTYPE_JFS2 and FS_JFS2 for IBM Journaled File System
this is to match FreeBSD's disklabel.h revision 1.73
FreeBSD change was requested by Hiten Pandya <hiten@uk.FreeBSD.org>
 1.15.2.2 09-Sep-2003  tron Pull up revision 1.17 (requested by tv in ticket #1454):
fix DTYPE_LD comment
 1.15.2.1 09-Sep-2003  tron Pull up revision 1.16 (requested by tv in ticket #1454):
add DTYPE_LD to match disklabel.h
 1.27.68.1 04-Nov-2016  pgoyette Sync with HEAD
 1.6 22-Dec-1994  mycroft Clean up deleted files.
 1.5 24-Jun-1994  hpeyerl disklabel(8) from 4.4 merged with our old disklabel(8) by John Brezak
(brezak@apollo.hp.com). hp300's can now disklabel by themselves.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.70 02-Jul-2019  wiz Sort and unify a bit. Add more macros.
 1.69 02-Jul-2019  mlelstv Add options to define labelsector and -offset and number of slices.
Make options to chose alternate label position for systems using MBR
more intuitive. -m now selects mode with MBR, -n selects mode without,
independent of the machine defaults.
 1.68 03-Jul-2017  wiz branches: 1.68.6;
Remove workaround for ancient HTML generation code.
 1.67 11-Sep-2016  sevan Remove ignored Pp macro, highlighted by mandoc -Tlint.
 1.66 11-Sep-2016  sevan Document the version disklabel first appeared.
Fix spelling mistakes.
Replace contraction.
Bump date.
 1.65 29-Apr-2015  christos Add missing doc flags (B,M,m)
 1.64 02-Aug-2011  wiz Sort sections. Remove comma in enumeration of two items.
 1.63 25-Jul-2011  christos mention that we don't handle more than 2TB disks/partitions.
 1.62 28-Nov-2009  abs Shuffle the order of examples to put the interactive option (-i) ahead
of $EDITOR and "disklabel -w -r /dev/rsd0c sd2212 foo"
 1.61 27-Jan-2007  perry As pointed out by James Wetterau, we wish to complement, as in the
logical operation, rather than compliment, as in praise, the magic
number of the disk.

There are probably other instances of this in the tree. We should fix
them.
 1.60 26-Nov-2006  jmmv Add a '-l' flag and a 'L' command to interactive mode to list all known
file system types. (Similar to what fdisk does for partition types.)

Closes PR bin/12954.
 1.59 04-Feb-2006  wiz Use more markup, fix xref, serial comma, other misc. fixes.
 1.58 29-Jan-2006  dsl Update/rewrite to match reality and in a muchmore succinct format.
 1.57 19-Jun-2005  wiz Quote Fr so options are sorted properly.
 1.56 17-Jun-2005  dsl Rip out the support for writing bootstrap code. installboot(8) contains
support for hp300, hp700 and vax, $MACHINE is never arm32.
Fix usage output to only contain progname() once - bug introduced in rev 1.89
 1.55 15-Jun-2005  dsl Rip out the references to the installation of more than one bootstrap file.
Only arm32 needs the -B stuff at all, all other ports use installboot(8).
 1.54 28-May-2004  snj Bump date for last. Put the exit EXIT STATUS section in the right place.
New sentence, new line. Correct two typos.
 1.53 28-May-2004  erh Make it possible to distinguish between exit values that indicate errors,
and those that are warnings. Document the exit statuses in the man page.
 1.52 20-Mar-2004  wiz Single-letter options do not need a line each; add more
commas; drop trailing whitespace; use Pa where appropriate.
 1.51 19-Mar-2004  dyoung Add flag -F to disklabel. Flag -F indicates that the target of the
disklabel operation is a file, not a disk. With -t disktab and -T
disktype, the user may tell disklabel the "geometry" for the file.
 1.50 18-Mar-2004  wiz Add Xref to mscdlabel, bump date.
 1.49 10-Nov-2003  fvdl Bring back disklabel -B for now, since hp300 installboot isn't ready
for prime time yet.
 1.48 08-Nov-2003  dsl Rip out all the '-B bootblock' support, everything should use installboot(8).
(can only affect arm32, hp300 and vax ports, and doesn't affect sysinst).
 1.47 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.46 13-Jul-2003  lukem xref dkctl(8)
 1.45 06-May-2003  wiz Bump date for last.
 1.44 02-May-2003  gmcgarry Document -I option. From Richard Rauch <rauch@math.rice.edu>
in PR#11890.
 1.43 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.42 21-Oct-2002  rtr Removed "disklabel -I [-r] [-C] disk" from SYNOPSIS.

The code does not permit usage of the -I flag without either -e or -i.
 1.41 28-Sep-2002  wiz mdoc nits. New sentence, new line. Remove a comment about tahoe.
 1.40 19-Aug-2002  enami Fix an argument to -width option of .Bl macro.
 1.39 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.38 14-Dec-2001  fredette The sun2 also requires partitions in integer cylinders.
 1.37 24-Nov-2001  perry Note in far more places that -B is only supported on some platforms.
 1.36 16-Nov-2001  wiz Simplify markup in one place, and sort sections and SEE ALSO.
 1.35 05-Jun-2001  wiz Drop arguments of .Os.
 1.34 14-Nov-2000  abs xref (disklabel.8, fdisk.8, mbrlabel.8) as appropriate
 1.33 08-Oct-2000  christos allow -I -i to install a new label interactively.
 1.32 12-Aug-2000  jhawk "boostrap" => "bootstrap"
 1.31 13-Jul-2000  hubertf 'disklabel -i' on a disk without a label recommends to use -I. Document
that in the usage.
 1.30 31-May-2000  fvdl branches: 1.30.2;
Add a -I flag which, combined with -e, gives the user the opportunity
to edit and create a new label on a virgin disk.
 1.29 09-Mar-2000  hubertf branches: 1.29.2;
s/comprised/composed/, per PR 9586 by Seebs <seebs@ged.plethora.net>
 1.28 31-Jan-2000  soda mention that hpcmips and arc use `d' as RAW_PART.
 1.27 03-Jun-1999  cgd kill some bogus comments about -r: it _does not_ cause the boot area to
be clobbered. since 4.4-Lite(?) disklabel.c has gone to extra effort
to avoid clobbering the boot area when using -r, but the 4.4-Lite manual
pages were apparently not updated to note that!
 1.26 09-Apr-1999  kleink Update for sparc64.
 1.25 07-Mar-1999  mycroft branches: 1.25.2;
Clean up SYNOPSIS formatting.
 1.24 19-Jan-1999  abs Add '-f disktab' option to disklabel, via lib/6623 from
Greg A. Woods <woods@most.weird.com>. (Very) slightly tweaked disklabel.8
 1.23 27-Apr-1998  fair Clarify the documentation of the "-B" option, inspired by PR#5262.
Contrary to the PR, the "-B" option does work, but not on all platforms.
 1.22 01-Jan-1998  enami Add missing -C flag in SYNOPSIS
 1.21 01-Jan-1998  enami Fix typo; the flag for interactive disklabel creation is not -e but -i.
Also, make the description of -C flag into separate paragraph.
 1.20 18-Oct-1997  fair additional sun3/sparc warning about the "-r" option.
 1.19 14-Oct-1997  fair add a warning about sun3 and sparc systems requiring partitions in integer cylinders or the boot ROMs get upset, per PR#3267. Is that it?
 1.18 11-Oct-1997  enami - Use .Nm "" instead of .Nm disklabel in SYNOPSIS.
- Do a trick to remove whitespace before close paren from generated output.
- Delete space at the end of line.
 1.17 10-Oct-1997  lukem all but the first .Nm in SYNOPSIS need to be spelt out. [bin/4256]
 1.16 14-Sep-1997  lukem - cleanup use of .Nm
- xref installboot(8)
- deprecate register
 1.15 02-Jul-1997  mikel s/except/accept/, from John F. Woods in PR bin/3802
 1.14 29-May-1997  cgd Fix broken uses of Dd. Both the mdoc and mdoc.samples pages agree:
.Dd is supposed to be invoked like:
.Dd month day, year
e.g. ".Dd January 25, 1989", rather than:
.Dd "month day, year"
which is what these pages did.
 1.13 08-Mar-1997  christos Add -i (interactive mode to create/edit labels) inspired by the SunOS/Solaris
format/partition command.
 1.12 02-Oct-1996  christos PR/1551: clarify usage in manual page
PR/2452: add -t option to print label in disktab(5) format.
Misc cleanups...
 1.11 29-Jun-1996  pk Allow display and editing of partition size & offset fields in
<cyl/track/sector> format. This format is always excepted on input
(`-e' and `-R'); to display it use `-C'.
 1.10 16-Jan-1996  hpeyerl PR487. From John Kohl. (more examples and some corrections)
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 22-Sep-1994  mycroft Finish 4.4-Lite merge, and convert to use err(3)/warn(3) functions.
 1.7 24-Jun-1994  hpeyerl disklabel(8) from 4.4 merged with our old disklabel(8) by John Brezak
(brezak@apollo.hp.com). hp300's can now disklabel by themselves.
 1.6 14-Jan-1994  jtc Fix spelling errors
 1.5 05-Aug-1993  jtc Update to -mandoc macros
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25.2.1 21-Jun-1999  perry pullup 1.26->1.27 (cgd): Kill bogus comments about -r
 1.29.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.30.2.4 26-Feb-2001  he Pull up revision 1.34 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.30.2.3 18-Oct-2000  tv Pullup 1.30-1.33 [christos]:
typo and new doc for -I usage
 1.30.2.2 12-Aug-2000  jhawk Pullup rev 1.32, approved by thorpej:
"boostrap" => "bootstrap"
 1.30.2.1 13-Jul-2000  hubertf Pull up into 1.5, approved by thorpej:
Documenting where to use disklabel -I

disklabel.8: 1.30 -> 1.31
disklabel.c: 1.85 -> 1.86
 1.68.6.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.136 12-Jun-2005  dyoung Make disklabel(8) into a host-tool, "nbdisklabel." Move disklabel.c
to main.c to avoid a name collision with lib/libc/gen/disklabel.c
when we build nbdisklabel. Still todo: commit host-tool build
infrastructure to src/tools/disklabel/.
 1.135 12-Nov-2004  hubertf Translate an error message from C to english.

Before: disklabel: warning, partition g: offset % cylinder-size != 0
After: disklabel: warning, partition g: not starting on cylinder boundary
 1.134 13-Jul-2004  enami Warn overlapping partitions (except the one marked as FS_UNUSED).
Address PR#10777.
 1.133 24-Jun-2004  enami A variable referenced isn't `write only'.
Wrap long line and fix some indent while here.
 1.132 22-Jun-2004  abs Fix some interesting disklabel lossage:

If the input to 'disklabel' (non -i) referenced a partition two or more
larger than that permitted by npartitions it would error out with 'bad
partition name' (and the option given to re-edit if -e). If a partition one
larger was used it would be dropped from the disklabel with a warning and the
label written anyway! The (off by one) check for a bad partition name was
against npartitions anyway, rather than MAXPARTITIONS. npartitions was just
read from the disklabel and could have been set to an arbitrary value.

Given 'disklabel -i' sets npartitions automatically, make the normal case
check partition names against MAXPARTITIONS, and if necessary increase
npartitions to the size needed to hold the last partition used.

While here remove two 'write only' uses of a 'part' variable.
 1.131 28-May-2004  erh Make it possible to distinguish between exit values that indicate errors,
and those that are warnings. Document the exit statuses in the man page.
 1.130 19-Mar-2004  dyoung branches: 1.130.2;
Add flag -F to disklabel. Flag -F indicates that the target of the
disklabel operation is a file, not a disk. With -t disktab and -T
disktype, the user may tell disklabel the "geometry" for the file.
 1.129 14-Mar-2004  christos Fix remaining issues:
- use getulong everywhere for proper range checking
- fix error checking in getulong
 1.128 13-Mar-2004  dsl Fix breakage of last commit (disklabel -R just plain didn't work!)
Convert two large nasty #defines into much smaller (still nasty) #defines
that call proper functions.
Fixes PR 24765
 1.127 29-Feb-2004  itojun use strtoul() instead of atoi(). have proper range check for each fields.
 1.126 18-Jan-2004  lukem * Enable SAVEBOOTAREA on i386 and amd64 (by merging the Makefile
controls with the section for the other MBR-using platforms that
already enable this)
* Don't prompt the user to "erase the previous contents of the disk"
when there's no NetBSD MBR partition; SAVEBOOTAREA is sufficient.

These fixes mean that you can create a disklabel (on an i386/amd64) on a disk
that doesn't have a NetBSD MBR partition without trashing the existing MBR.
The previous behaviour was extremely annoying when working with media such
as FAT-formatted CF cards, and didn't really protect people with such from
accidentally trashing part of sector 1 of such disks, and made it extremely
easy to trash sectors 0..15 of those disks instead.
 1.125 18-Jan-2004  dsl Use correct sector number when the netbsd partition is in the extended
partition chain (and not the first extended partition).
 1.124 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.123 11-Dec-2003  dyoung fix spelling, s/extented/extended/
 1.122 15-Nov-2003  bouyer Commit changes proposed on tech-kern Thu, 6 Nov 2003
- factor out disksubr.c between sun3, sparc and sparc64. Keep the sun3
groveling code to find a NetBSD disklabel in the first sector (so that it
can find a label at the old sun3 LABELOFFSET) as a fallback is not
label at LABELOFFSET, or sun label is present.
- Fix the sun3 LABELOFFSET (was 64, but the kernel wrote the NetBSD label at
128)
- Make next68k disksubr.c always write a next-compatible disklabel.
- remove #ifdef __sparc__ hack from disklabel(8), and change it to issue
a DIOCWDINFO after writing the disklabel to the raw partition in the
-r/-I case (so that the kernel can convert the label if needed).
 1.121 10-Nov-2003  fvdl Bring back disklabel -B for now, since hp300 installboot isn't ready
for prime time yet.
 1.120 08-Nov-2003  dsl Rip out all the '-B bootblock' support, everything should use installboot(8).
(can only affect arm32, hp300 and vax ports, and doesn't affect sysinst).
 1.119 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.118 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.117 04-Aug-2003  dsl Read correct sector when following extended partition chain.
Require extended partition chain to be through increasing sector numbers
in order to abort loops.
 1.116 13-Jul-2003  itojun use bounded copy (a few unbounded copy remains - need work)
 1.115 07-Jul-2003  dsl Allow for the netbsd partition being in the extended partition list.
 1.114 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.113 16-Jan-2003  kleink Rename `sigset' locals to avoid symbol shadowing warning.
 1.112 06-Jan-2003  wiz writable, not writeable.
 1.111 12-Dec-2002  scw Use getlabel{sector,offset}() instead of LABEL{SECTOR,OFFSET}.
 1.110 11-Dec-2002  fvdl Handle MBRs for x86_64.
 1.109 05-Dec-2002  jonb While cleaning up other places that invoked $EDITOR, noticed that
this one had all the infrastructure of fork/exec/wait, like the
others, but called system instead of exec creating an extra PID
and associated memory usage during the edit.
 1.108 18-Nov-2002  rtr Fix bug causing segmentation fault when no fs type specified
 1.107 28-Sep-2002  dbj add FS_APPLEUFS
part of PR #17345
 1.106 18-Jun-2002  itojun need disklabel_mbr.h for USE_MBR build
 1.105 27-May-2002  drochner display / read the p_cdsession field in the FS_ISO9660 case
 1.104 14-May-2002  thorpej Alpha boot block stuff has moved to <sys/bootblock.h>
 1.103 09-Apr-2002  mycroft Make this build again after the alpha/disklabel.h and dev/dec/dec_boot.h
changes.
 1.102 14-Feb-2002  kleink When accessing the MBR magic as a 16-bit value, consider its on-disk
layout would be little-endian, too.
 1.101 13-Dec-2001  reinoud Remove `const' attribute from writelabel prototype and function to make it
compile again on Alpha.
 1.100 29-Nov-2001  bjh21 Rather than making FileCore boot block support conditional on __arm32__, make
it conditional on USE_ACORN, and define that if MACHINE is arm26 or acorn32.
This is less than optimal, and maybe we should define it for all ARM systems,
but then disklabel handling across architectures is generally a mess at the
moment.
 1.99 19-Oct-2001  lukem minor WARNS=2 stuff
 1.98 15-Jun-2001  nonaka Fix big-endian vs. MBR parameters.
 1.97 29-Mar-2001  drochner Don't error out if the mbr cannot be read.
This makes "disklabel cd0" working also on platforms with MBR support.
 1.96 19-Feb-2001  cgd convert to use getprogname()
 1.95 08-Jan-2001  fvdl When -I is specified, we mean to initialize the label if it's not there
already. So, don't fail if there appears to be a corrupt label or
no 'fake' label; get the 'default' label (which is generated
from DIOCGDEFLABEL) instead.
 1.94 03-Jan-2001  enami Test read(2) failure by read(..., sizeof(n)) != sizeof(n) instead of
< sizeof(n) to avoid unwanted type promotion.
 1.93 03-Jan-2001  enami Kill whitespace at the end of line.
 1.92 24-Dec-2000  lukem move showinfo() and showpartition() into separate file, for use by
other programs. slightly change argument signature so that globals
aren't depended upon.
 1.91 24-Dec-2000  lukem - convert to KNF ANSI style guide
- reorder arguments of runcmd(), getnum(), defnum() to be consistent
with other functions (pass struct disklabel * first)
 1.90 27-Nov-2000  perseant Change "cpg" to "cpg/sgs" in the printed partition table header, in an
attempt to avoid confusion. (PR #9230)
 1.89 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.88 08-Oct-2000  christos allow -I -i to install a new label interactively.
 1.87 14-Aug-2000  lukem * use strcasecmp() instead of strcmp() so that filesystem type and disk type
searchs (amongst others) are case insensitive.
* in interactive mode (-i), when editing entries display supported disk types
and filesystem types when given `?' (when ``[?]'' appears in the prompt
this feature is supported for the question).
* support `m' as a suffix equivalent to `M'
* in interactive mode, be a bit more sensible about handling errors and EOF
* implement dumpnames(), which takes a char ** and size, and displays
as per ls -F (sorted, listed vertically) but indented by one tab
* don't assume d_typename and d_packname are NUL terminated
* fix up some comments and some warning messages (bad cut & pastos :)
* deprecate deffstypename() and getfstypename()
* be consistent when using sizeof()
 1.86 13-Jul-2000  hubertf 'disklabel -i' on a disk without a label recommends to use -I. Document
that in the usage.
 1.85 07-Jul-2000  itojun warnx?/errx? audit. don't pass variable/function return value alone.
use with "%s". from openbsd.
 1.84 31-May-2000  fvdl branches: 1.84.2;
Add a -I flag which, combined with -e, gives the user the opportunity
to edit and create a new label on a virgin disk.
 1.83 27-May-2000  jdolecek add system(3) for spawning the editor - this is handy when EDITOR is set to
something like 'editor arg1 arg2 ...'
 1.82 25-May-2000  thorpej branches: 1.82.2;
Provide some information when confirming "Write outside MBR partition".
 1.81 31-Jan-2000  soda - use MBR partition table also on arc.
- use defined(USE_MBR) instead of defined(__i386__), like hpcmips and arc.
 1.80 18-Jan-2000  perseant disklabel now understands the p_sgs partition field (shift to compute
segment size from block size).

newfs_lfs now reads the disklabel to find segment, block, and fragment
sizes. Because reading this info from the wrong fs type could result in
very poor fs layout (e.g. ffs has "16" where the segshift would go,
resulting in 512-*megabyte* segments for 8K blocks), newfs_lfs refuses
to create a filesystem on a partition not labeled "4.4LFS".

Man pages for newfs_lfs updated to reflect this change.
 1.79 20-Dec-1999  fair change "millisecond" to "microsecond" for headswitch and track seek
comments, to resolve PR 8189. This makes the documentation for these
fields consistent. Not that it matters - a grep of syssrc shows that
these fields aren't actually used for anything and should probably be
GC'd.
 1.78 26-Nov-1999  mrg allow changing partition info from inside the interactive handler.
 1.77 12-Oct-1999  shin Fix typo. ('_i386__' -> '__i386__')
Pointed by D'Arcy J.M. Cain, thanks.
 1.76 11-Oct-1999  shin add hpcmips support (MBR)
 1.75 17-Sep-1999  ross branches: 1.75.2;
don't unbalance { } pairs with #ifdefs or ctags(1) gets confused
 1.74 21-Jul-1999  kleink Try $TMPDIR before resorting to _PATH_TMP.
 1.73 04-Jun-1999  is Make BSDLFS a EXT2FS-like filesystem, that is, dont print or parse the cpg
field.
According to disklabel.h, its LFS semantics are "segment shift" (log2(segment
size)), but in the code it is used nowhere, and there are even plans to
allow non-poweroftwo segment sizes, so it won't ever work.
While at this, simplify the disktab-like output routine... here, currently,
BSDFFS, BSDLFS, EX2FS and ADOS do the same, so don't duplicate the code.
 1.72 03-Jun-1999  is Print bsize and fsize in disktab-format output also for LFS and ADOS.
 1.71 03-Jun-1999  is Print/parse block size, fragment size and cpg for FS_BSDLFS and FS_ADOS.
(cpg has different semantics for LFS and ADOS, but is in use.)
XXX The disktab reading/disktab format output writing needs still to be done.
 1.70 03-Jun-1999  cgd On NetBSD/alpha, go out of the way to read the boot area's contents if -r
is specified, so that the boot blocks aren't clobbered when writing labels.
 1.69 03-May-1999  christos Add a 'chain' command in interactive mode that allows you to vary the
size of the partitions, while the starting point gets adjusted automagically.
This chaining works for partitions that are not 'unused'.
 1.68 30-Apr-1999  abs STRICT_ALIGNMENT only applies to the start of partitions, not length.
 1.67 29-Apr-1999  wrstuden Fix disklabel -t to work with disks that don't end on a cylinder. Before it
wasn't adding a "su" entry, so when the disktab was read, the sectors per
unit was initialized to "nc"*"sc" which was wrong.

Fixes PR/7446 reported by Matthias Buelow <mkb@altair.mayn.de>.
 1.66 26-Apr-1999  abs Allow partitions to extend to the end of the disk, even when
STRICT_CYLINDER_ALIGNMENT defined. This allows existing valid disklabels
to work (including those generated by sysinst).
 1.65 09-Apr-1999  bouyer If checklabel() failed, the label has not been written, so exit(1).
 1.64 05-Apr-1999  cgd instead of coding an alpha boot block checksum routine here, use
the macro now provided by disklabel.h
 1.63 27-Jan-1999  thorpej branches: 1.63.2;
Use <sys/disklabel_mbr.h>
 1.62 21-Jan-1999  pk Enable non-cylinder-aligned partition warning on sparc[64] & sun3.
See also PR#6853.
 1.61 19-Jan-1999  abs Add '-f disktab' option to disklabel, via lib/6623 from
Greg A. Woods <woods@most.weird.com>. (Very) slightly tweaked disklabel.8
 1.60 12-Nov-1998  christos Adjust for DKTYPENAME changes.
 1.59 10-Aug-1998  perry bzero->memset, bcopy->memcpy, bcmp->memcmp
 1.58 04-Aug-1998  drochner -fix some lint warnings
-fix overflow conditions (PR bin/5534, Zdenek Salvet <salvet@ics.muni.cz>)
(+ one more: can VAX SMD drives be >4G?)
-fix output of "*" at odd end cylinder number (not odd size)
-break some lines >80 cols
 1.57 27-Jul-1998  mycroft Shift column headers into the right position.
 1.56 26-Jul-1998  mycroft const poisoning.
 1.55 07-Jun-1998  mark Fix from Chris Demetriou to modify the way in which arm32 filecore
checksums are calculated paying attention to the fact that the way
the checksum works a sectors filled with a single byte value will
always checksum correctly.
 1.54 26-Mar-1998  cgd when reading the MBR, seek to DOSBBSECTOR * DEV_BSIZE rather than just
DOSBBSECTOR. DOSBBSECTOR is 0 so it doesn't really matter, but the former
is what was really intended.
 1.53 26-Mar-1998  cgd in makebootarea() (if NUMBOOT is nonzero), before reading the contents
of the old boot area so that 'disklabel -r -w' won't clobber anything,
be sure to seek to the offset of the boot area (like readlabel() does).
Otherwise, if the machine has code which looks up machine-dependent label
bits, the offset read from will be incorrect, and disklabel will end up
secretly replacing the boot area with other data (which probably doesn't
look like a boot block). The only port this currently affects is
NetBSD/arm32, because it's the only one of the three ports that use
NUMBOOT > 0 that has MD label grovelling code.
 1.52 25-Mar-1998  cgd factor out some more common bits into 'confirm', and make it a bit more
bullet-proof. also, make the arm32 #ifdefs a bit more consistent with
the i386 #ifdefs (without actually changing the behaviour of the code).
 1.51 24-Mar-1998  cgd use warnx when warning about an old BSD partition ID (i386 MBR code),
since err/warn seem to be used consistently throughout the code, rather
than fprintf.
 1.50 24-Mar-1998  cgd KNF arm32-specific label-grovelling code. Also, clean up error messages
(errx instead of err, kill bogus newlines, make error messages look more
"normal").
 1.49 02-Mar-1998  drochner Handle new MBR partition ID on i386. Put all code which decides about
usability of an entry to one place, use same algorithm as kernel (ie,
check signature).
 1.48 01-Jan-1998  enami Fix usage; -i and -C flags are alway effective regardless of NUMBOOT.
 1.47 19-Oct-1997  pk branches: 1.47.2;
On the sparc, do not write to the raw disk at all if `-r' is on.
 1.46 17-Oct-1997  mark Added support for filecore partitions on arm32 platforms.
 1.45 13-Oct-1997  bouyer The number of fs types is FSMAXTYPES not DKMAXTYPES.
Correct read of formatted file (used with -e or -R) so that fstype with
spaces will work. Also enlarge the fstype field by 2 chars so that
"Linux Ext2" will not be truncated.
 1.44 30-Sep-1997  phil Backout prototype of opendisk.
 1.43 30-Sep-1997  phil Add a prototype for opendisk().
 1.42 25-Sep-1997  lukem switch to using opendisk(3) from libutil
 1.41 16-Sep-1997  lukem fix sccsid conflict
 1.40 10-Jul-1997  veego Define boot1 if NUMBOOT > 1.
Noticed in pr#3850, but fixed differently.
 1.39 30-Jun-1997  christos Fix warnings.
 1.38 16-Mar-1997  lukem use mkstemp() instead of mktemp()
 1.37 08-Mar-1997  christos Add -i (interactive mode to create/edit labels) inspired by the SunOS/Solaris
format/partition command.
 1.36 20-Oct-1996  thorpej Add missing '}', from David Carrel <carrel@ipsec.com>, PR #2873.
 1.35 02-Oct-1996  christos PR/1551: clarify usage in manual page
PR/2452: add -t option to print label in disktab(5) format.
Misc cleanups...
 1.34 10-Aug-1996  explorer Fix disklabel to deal with some syntax errors a little better.

Mostly, when someone specifies a partition entry like:

c: 1295850 0
or
g: 1295850 0 4.2BSD

disklabel would dump core. Now it generates a warning like it should
in the first case and complains about too few fields in the second.

Perhaps I should just default to unused in the first case, but this prevents
core dumps. (pr bin/2659)
 1.33 10-Aug-1996  explorer Don't display cylinder comments if the number of cylinders is zero. This
closes pr bin/2683.
 1.32 29-Jun-1996  pk On the sparc on an extra DIOCWDINFO after writing to the raw device.
 1.31 29-Jun-1996  pk Allow display and editing of partition size & offset fields in
<cyl/track/sector> format. This format is always accepted on input
(`-e' and `-R'); to display it use `-C'.
 1.30 14-Mar-1996  ghudson Include the total number of sectors in the text representation of
the label; calculating based on the disk geometry is not always
accurate (notably, for SCSI disks). Also be a bit more careful
about printing out fixed-width types.
 1.29 26-Jun-1995  jtc sys/errno.h -> errno.h
sys/signal.h -> signal.h
 1.28 29-Apr-1995  mycroft Make sure to reset signal mask on errors.
 1.27 22-Mar-1995  cgd make sure that the alpha boot block is checksummed in a way more
acceptable to charles; #ifdef it, and do it explicitly here, rather
than doing a WDINFO ioctl for the -r case.
 1.26 22-Mar-1995  mycroft Don't do a DIOCWDINFO after already writing the label.
 1.25 21-Mar-1995  mycroft Use POSIX signals.
 1.24 19-Mar-1995  cgd re-order the DIOCWLABEL in the rflag case, so it actually works right.
 1.23 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.22 10-Feb-1995  cgd do the DIOCWDINFO in writelabel() even if -r is specified.
On most machines it's redundant, but it gives others the chance to
take special actions, e.g. updating a checksum.
 1.21 30-Jan-1995  mycroft Fix typos, and minor cosmetic changes.
 1.20 12-Jan-1995  mycroft Change the magic question to an absolute, flat lie that should hopefully make
people think twice before toying with it. B-P
 1.19 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.18 30-Sep-1994  mycroft Clean up this festering pile of rotten code a bit. To wit:
* Add prototypes.
* Remove a strange and apparently pointless bit of code propagated
from 386BSD.
* Collapse NOWRITE and WRITEABLE into one.
* Use the same algorithm as the kernel for finding the label.
* Redo some of the parsing more sanely.
 1.17 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.16 22-Sep-1994  mycroft Finish 4.4-Lite merge, and convert to use err(3)/warn(3) functions.
 1.15 20-Jul-1994  brezak Fix i386 disklabel bug
 1.14 05-Jul-1994  deraadt branches: 1.14.2;
usage message with less surprise
 1.13 24-Jun-1994  hpeyerl disklabel(8) from 4.4 merged with our old disklabel(8) by John Brezak
(brezak@apollo.hp.com). hp300's can now disklabel by themselves.
 1.12 13-Jun-1994  cgd fix include file
 1.11 21-Mar-1994  cgd don't core so easily
 1.10 06-Dec-1993  cgd 386BSD -> NetBSD and/or i386
 1.9 02-Dec-1993  mycroft We said we're going to default to `n', now do it!
 1.8 13-Oct-1993  mycroft Check boundary of *c* partition against the DOS partition table, not the *a*
partition, as we might want the latter to not necessarily be at the beginning
of the NetBSD section.
 1.7 07-Aug-1993  cgd merge in changes from netbsd-0-9-ALPHA2
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 18-Apr-1993  mycroft branches: 1.5.2;
Cleanup for GCC 2.
 1.4 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.3 22-Mar-1993  cgd added rcs ids to all files
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 04-Aug-1993  cgd patch from terry@uieosa.csl.uiuc.edu to deal with an uninitialized
pointer bug.
 1.14.2.2 20-Jul-1994  cgd update from trunk; better fix.
 1.14.2.1 20-Jul-1994  cgd don't clobber i386 BIOS labels. from tim@introl.introl.com.
a bit of a hack -- a better fix will go in the trunk in a day or two.
 1.47.2.2 20-Jan-1999  cgd pull up rev 1.48 from trunk (via patch). (drochner)
 1.47.2.1 23-Nov-1998  cgd pull up rev 1.49 from trunk (jonathan)
 1.63.2.6 10-Oct-2000  he Pull up revision 1.89 (via patch, requested by is):
Format string cleanup.
 1.63.2.5 22-Jun-1999  perry pullup 1.70->1.73 (is)
 1.63.2.4 21-Jun-1999  perry pullup 1.69->1.70 (cgd)
 1.63.2.3 30-Apr-1999  perry pullup 1.67->1.68 (David Brownlee)
 1.63.2.2 29-Apr-1999  perry pullup 1.65->1.66 (abs), 1.66->1.67 (wrstuden)
 1.63.2.1 09-Apr-1999  bouyer Pull up 1.64->1.65: If we didn't write the label because checklabel() failed,
exit with a non-zero status.
 1.75.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.82.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.84.2.7 16-Aug-2001  tv Pullup [drochner]:

sbin/disklabel/disklabel.c 1.97

Make disklabel viewing work on platforms that use MBR, for devices
without a valid MBR (such as CD-ROMs).
 1.84.2.6 26-Feb-2001  he Pull up revisions 1.90-1.95 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.84.2.5 18-Oct-2000  tv Pullup 1.84-1.87 [christos]:
cleanup c syntax (sizeof parentheses)
 1.84.2.4 18-Oct-2000  tv Pullup 1.88 (with 1.89) [christos]:
Allow -i with -I.
 1.84.2.3 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.84.2.2 27-Jul-2000  itojun pullup (approved by releng-1-5)
printf-like format pedant. do not pass string variable alone. use "%s".
from openbsd.

/cvsroot/basesrc/sbin/swapctl/swapctl.c 1.14 -> 1.15
/cvsroot/basesrc/sbin/ping6/ping6.c 1.15 -> 1.16
/cvsroot/basesrc/sbin/disklabel/disklabel.c 1.84 -> 1.85
/cvsroot/basesrc/sbin/ccdconfig/ccdconfig.c 1.30 -> 1.31
 1.84.2.1 13-Jul-2000  hubertf Pull up into 1.5, approved by thorpej:
Documenting where to use disklabel -I

disklabel.8: 1.30 -> 1.31
disklabel.c: 1.85 -> 1.86
 1.130.2.1 11-Sep-2004  he Pull up revisions 1.132-1.133 (requested by abs in ticket #825):
Fix an off-by-one error in calculating how many partitions
are allowed, and also fix which value we use to compare the
maximum number of partitions against.
 1.14 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.13 05-Jan-2010  tsutsui branches: 1.13.6; 1.13.12;
Add necessary byteswap ops for tools disklabel(8) used with -F option
(treating a target disk as a regular file and suppressing ioctl(2)s)
on reading/writing disklabel in a target file.
This allows cross build enviroment creating bootable disk images
for targets in different endian.
No functional changes to native (non-tools) disklabel(8) command.

Closes PR toolchain/42357.
 1.12 24-Oct-2009  tsutsui - u_short -> uint16_t
- KNF a bit
 1.11 12-Jun-2005  dyoung Make disklabel(8) into a host-tool, "nbdisklabel." Move disklabel.c
to main.c to avoid a name collision with lib/libc/gen/disklabel.c
when we build nbdisklabel. Still todo: commit host-tool build
infrastructure to src/tools/disklabel/.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.9 24-Dec-2000  lukem - convert to KNF ANSI style guide
- reorder arguments of runcmd(), getnum(), defnum() to be consistent
with other functions (pass struct disklabel * first)
 1.8 14-Sep-1997  lukem branches: 1.8.12;
- cleanup use of .Nm
- xref installboot(8)
- deprecate register
 1.7 30-Jun-1997  christos Fix warnings.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Sep-1994  mycroft Finish 4.4-Lite merge, and convert to use err(3)/warn(3) functions.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.12.1 26-Feb-2001  he Pull up revision 1.9 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.13.12.1 23-Jun-2013  tls resync from head
 1.13.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.5 05-Jan-2010  tsutsui branches: 1.5.6; 1.5.12;
Add necessary byteswap ops for tools disklabel(8) used with -F option
(treating a target disk as a regular file and suppressing ioctl(2)s)
on reading/writing disklabel in a target file.
This allows cross build enviroment creating bootable disk images
for targets in different endian.
No functional changes to native (non-tools) disklabel(8) command.

Closes PR toolchain/42357.
 1.4 24-Oct-2009  tsutsui - u_short -> uint16_t
- KNF a bit
 1.3 24-Dec-2000  lukem - convert to KNF ANSI style guide
- reorder arguments of runcmd(), getnum(), defnum() to be consistent
with other functions (pass struct disklabel * first)
 1.2 09-Jan-1998  perry branches: 1.2.10;
RCS Id Police.
 1.1 30-Jun-1997  christos Fix warnings.
 1.2.10.1 26-Feb-2001  he Pull up revision 1.3 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.5.12.1 23-Jun-2013  tls resync from head
 1.5.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.12 17-Jan-2013  christos move dk_ioctl to a header file for the benefit of x-building.
 1.11 21-Oct-2009  snj branches: 1.11.6; 1.11.12;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.10 26-Nov-2006  jmmv Add a '-l' flag and a 'L' command to interactive mode to list all known
file system types. (Similar to what fdisk does for partition types.)

Closes PR bin/12954.
 1.9 19-Oct-2005  dsl Rototil the way disklabel -r reads and writes labels.
In particular the 'read' part plays 'hunt the disklabel' in order to get a
label into a local buffer - from where it can be displayed/edited.
The 'write' part makes a separate scan of the disk looking for places to
write the label.
The main changes are:
- It can no longer write the first 8k of the mbr to the pbr (or v.v.)
- All labels on the disk (that it can find) get updated during a write
- With -A all the labels are displayed (inc. those deleted by -D)
- Addition of -D which will delete (by one's complimenting dk_magic{2}) and
existing labels before writing labels to the expected locations.
- -v gives some verbose output to stderr, -vv more etc
A better basis for processing incorrect endian labels, or labels from other
architectures.
 1.8 13-Dec-2001  reinoud Remove `const' attribute from writelabel prototype and function to make it
compile again on Alpha.
 1.7 26-May-2001  christos - KNF printlabel.c
- add a function to print only one partition's info.
- print the partition information if it was modified in interactive mode.
- improve on the chaining code. [still assumes that partition offsets increase
monotonically]. We could check for overlap too.
 1.6 24-Dec-2000  lukem move showinfo() and showpartition() into separate file, for use by
other programs. slightly change argument signature so that globals
aren't depended upon.
 1.5 24-Dec-2000  lukem - convert to KNF ANSI style guide
- reorder arguments of runcmd(), getnum(), defnum() to be consistent
with other functions (pass struct disklabel * first)
 1.4 26-Nov-1999  mrg branches: 1.4.4;
allow changing partition info from inside the interactive handler.
 1.3 03-May-1999  christos branches: 1.3.4;
Add a 'chain' command in interactive mode that allows you to vary the
size of the partitions, while the starting point gets adjusted automagically.
This chaining works for partitions that are not 'unused'.
 1.2 30-Jun-1997  christos Fix warnings.
 1.1 08-Mar-1997  christos Add -i (interactive mode to create/edit labels) inspired by the SunOS/Solaris
format/partition command.
 1.3.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.4.1 26-Feb-2001  he Pull up revisions 1.5-1.6 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.11.12.2 23-Jun-2013  tls resync from head
 1.11.12.1 25-Feb-2013  tls resync with head
 1.11.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.6.1 23-Jan-2013  yamt sync with head
 1.40 03-Nov-2021  nia disklabel(8): convert malloc(x * y) to reallocarr
 1.39 31-Jan-2016  christos PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)
 1.38 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.37 17-Jan-2013  christos move dk_ioctl to a header file for the benefit of x-building.
 1.36 15-Jan-2013  christos - simplify getinput.
- add adjust command.
 1.35 06-Jan-2011  apb branches: 1.35.6; 1.35.12;
Change printf formats to match the data type of the values being
printed. There's now a lot of PRIu16 and PRIu32, some PRIu8, some
SCNu32, and a few cases where %u and %d were reversed. Multiplication
of 32-bit and 8-bit values is cast to uint64_t and printed with PRIu64.

Inspired by a report from Patrick Welche on current-users.
 1.34 28-May-2010  dholland Change getnum() to use intmax_t instead of int, so it doesn't overflow
between 2^31 and 2^32. Adjust call sites accordingly. PR 43354.
 1.33 28-Nov-2009  abs - Display "Enter '?' for help" when starting interactive mode
- Use %.40g rather than %g when printing sectors and MB for existing
partition size/offset.
Changes [1.93802e+06c, 1953525105s, 953870M]:
to: [1938021c, 1953525105s, 953869.6875M]:
 1.32 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.31 16-Mar-2009  lukem fix sign-compare issues
 1.30 26-Nov-2006  jmmv branches: 1.30.26; 1.30.28; 1.30.32;
Add a '-l' flag and a 'L' command to interactive mode to list all known
file system types. (Similar to what fdisk does for partition types.)

Closes PR bin/12954.
 1.29 18-Mar-2006  dsl Avoid indexing beyond the end of a malloced array.
Rework loop to be less confusing.
Coverty 519 made me read this code, but this isn't the 'bug' it found.
 1.28 17-Mar-2006  rumble Gracefully handle out of memory condition.
 1.27 19-Oct-2005  dsl Rototil the way disklabel -r reads and writes labels.
In particular the 'read' part plays 'hunt the disklabel' in order to get a
label into a local buffer - from where it can be displayed/edited.
The 'write' part makes a separate scan of the disk looking for places to
write the label.
The main changes are:
- It can no longer write the first 8k of the mbr to the pbr (or v.v.)
- All labels on the disk (that it can find) get updated during a write
- With -A all the labels are displayed (inc. those deleted by -D)
- Addition of -D which will delete (by one's complimenting dk_magic{2}) and
existing labels before writing labels to the expected locations.
- -v gives some verbose output to stderr, -vv more etc
A better basis for processing incorrect endian labels, or labels from other
architectures.
 1.26 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.25 12-Jun-2005  dyoung Make disklabel(8) into a host-tool, "nbdisklabel." Move disklabel.c
to main.c to avoid a name collision with lib/libc/gen/disklabel.c
when we build nbdisklabel. Still todo: commit host-tool build
infrastructure to src/tools/disklabel/.
 1.24 07-Apr-2005  christos Recognize more units and be more helpful when we enter bad units.
 1.23 29-Dec-2003  jdc Add missing ' in prompt text.
Pointed out by Allen Briggs.
 1.22 29-Dec-2003  jdc Add the ability to define a partition as starting after another partition.
If chaining is on, display all changed partitions (not just this one).

OK'ed by Christos.
 1.21 20-Oct-2003  pooka Handle partition offset and size as unsigned entities.
 1.20 29-Jun-2002  grant disallow creation of partitions which start beyond (or extend beyond)
the end of the disk.
 1.19 19-Oct-2001  lukem branches: 1.19.2;
minor WARNS=2 stuff
 1.18 26-May-2001  christos - KNF printlabel.c
- add a function to print only one partition's info.
- print the partition information if it was modified in interactive mode.
- improve on the chaining code. [still assumes that partition offsets increase
monotonically]. We could check for overlap too.
 1.17 24-Dec-2000  lukem move showinfo() and showpartition() into separate file, for use by
other programs. slightly change argument signature so that globals
aren't depended upon.
 1.16 24-Dec-2000  lukem - convert to KNF ANSI style guide
- reorder arguments of runcmd(), getnum(), defnum() to be consistent
with other functions (pass struct disklabel * first)
 1.15 04-Sep-2000  lukem in cmd_name(), put the default prompt into a temporary buffer rather
than overwrite the existing d_packname. noted by enami@.
 1.14 14-Aug-2000  lukem * use strcasecmp() instead of strcmp() so that filesystem type and disk type
searchs (amongst others) are case insensitive.
* in interactive mode (-i), when editing entries display supported disk types
and filesystem types when given `?' (when ``[?]'' appears in the prompt
this feature is supported for the question).
* support `m' as a suffix equivalent to `M'
* in interactive mode, be a bit more sensible about handling errors and EOF
* implement dumpnames(), which takes a char ** and size, and displays
as per ls -F (sorted, listed vertically) but indented by one tab
* don't assume d_typename and d_packname are NUL terminated
* fix up some comments and some warning messages (bad cut & pastos :)
* deprecate deffstypename() and getfstypename()
* be consistent when using sizeof()
 1.13 17-Dec-1999  abs branches: 1.13.4;
Use '$' instead of '-' to select remainder of disk interactively
 1.12 17-Dec-1999  abs When setting size of partitions interactively allow '-' for remainder of disk
 1.11 26-Nov-1999  mrg allow changing partition info from inside the interactive handler.
 1.10 05-Sep-1999  abs branches: 1.10.4;
Accept 'Y' for label disk as well as 'y'
 1.9 03-May-1999  christos Add a 'chain' command in interactive mode that allows you to vary the
size of the partitions, while the starting point gets adjusted automagically.
This chaining works for partitions that are not 'unused'.
 1.8 12-Nov-1998  christos branches: 1.8.2;
Adjust for DKTYPENAME changes.
 1.7 13-Oct-1997  bouyer The number of fs types is FSMAXTYPES not DKMAXTYPES.
Correct read of formatted file (used with -e or -R) so that fstype with
spaces will work. Also enlarge the fstype field by 2 chars so that
"Linux Ext2" will not be truncated.
 1.6 18-Sep-1997  enami Don't pass return value of writelabel() to strerror(), since
the value is not a errno but just 0 or 1.
 1.5 30-Jun-1997  christos Fix warnings.
 1.4 18-Mar-1997  christos Off by one.
 1.3 09-Mar-1997  christos fix reversed test for maxpartitions.
 1.2 09-Mar-1997  christos Jason says: Use getmaxpartitions(3) to determine the number of partitions
allowed in this architecture.
 1.1 08-Mar-1997  christos Add -i (interactive mode to create/edit labels) inspired by the SunOS/Solaris
format/partition command.
 1.8.2.2 17-Dec-1999  he Pull up revisions 1.12-1.13 (requested by abs):
When setting size of partitions interactively, allow '$'
for the remainder of the disk.
 1.8.2.1 10-Sep-1999  he Pull up revision 1.10:
'Label disk?' prompt should check for 'Y' as well as 'y'. (abs)
 1.10.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.4.2 26-Feb-2001  he Pull up revisions 1.16-1.17 (requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.13.4.1 18-Oct-2000  tv Pullup 1.13-1.15 [christos]:
supported disk types printout, sizeof parentheses, better error messages.
 1.19.2.1 29-Jun-2002  lukem Pull up revision 1.20 (requested by grant in ticket #402):
disallow creation of partitions which start beyond (or extend beyond)
the end of the disk.
 1.30.32.1 20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.30.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.30.26.1 12-Jun-2010  riz Pull up following revision(s) (requested by dholland in ticket #1410):
sbin/disklabel/interact.c: revision 1.34
Change getnum() to use intmax_t instead of int, so it doesn't overflow
between 2^31 and 2^32. Adjust call sites accordingly. PR 43354.
 1.35.12.2 23-Jun-2013  tls resync from head
 1.35.12.1 25-Feb-2013  tls resync with head
 1.35.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.35.6.1 23-Jan-2013  yamt sync with head
 1.59 19-Jan-2025  tsutsui Add an entry of (belated) virt68k. Required to build live-image.

XXX: should be added to https://www.netbsd.org/developers/new-port.html
 1.58 15-May-2024  tsutsui branches: 1.58.2;
Fix an old bug in NATIVELABEL_ONLY case in PR/50729 by me. (sigh)

'disklabel -r -w' writes a disklabel at a wrong sector in
NATIVELABEL_ONLY && !LABELUSESMBR && LABELSECTOR != 0 case
if the target disk doesn't have a valid disklabel, due to
incorrect LABEL_OFFSET value.

Found and investigated on NetBSD/hp300 bootable CD tests.
Maybe this affects ports that use distrib/utils/x_disklabel
but have no MBR support, i.e. only NetBSD/hp300 10.0 and
NetBSD/ews4800mips 9.0 and later.

Should be pulled up to netbsd-10 and netbsd-9.
 1.57 03-Nov-2021  nia branches: 1.57.2;
disklabel(8): convert malloc(x * y) to reallocarr
 1.56 29-May-2021  christos first check, then copy
 1.55 29-Sep-2020  msaitoh branches: 1.55.2;
s/occurence/occurrence/
 1.54 29-Sep-2020  msaitoh s/parition/partition/
 1.53 03-Aug-2019  isaki Fix a trivial wrong comment. x68k's arch is not m68010.
 1.52 03-Jul-2019  mlelstv branches: 1.52.2;
Fix NATIVELABEL_ONLY build.
 1.51 02-Jul-2019  mlelstv Add options to define labelsector and -offset and number of slices.
Make options to chose alternate label position for systems using MBR
more intuitive. -m now selects mode with MBR, -n selects mode without,
independent of the machine defaults.
 1.50 27-Jun-2018  kamil branches: 1.50.2;
Avoid misaligned access in disklabel(8) in find_label()

Introduce a new helper variable tlp and use it for memory access.

Detected with MKSANITIZER/UBSan

A patch by <christos>
 1.49 01-Apr-2018  ryo Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)
 1.48 24-Jan-2018  skrll branches: 1.48.2;
Remove port-acorn26

OK core@
 1.47 09-Mar-2017  chs use warnx() rather than warn() in a case where errno is not relevant.
 1.46 31-Jan-2016  christos branches: 1.46.2; 1.46.4;
PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)
 1.45 27-Apr-2015  christos fix mistake in previous
 1.44 25-Apr-2015  christos make table smaller in size.
 1.43 02-Jan-2015  christos Fix the 3 programs that use DTYPE_ (disklabel disk types) constants from the
kernel. Two of them are inside ifdefs.
 1.42 19-Sep-2014  matt Add OpenRISC 1000 & UCB RISC-V platform support.
 1.41 10-Aug-2014  apb Fix typo in "dreamcast" port name.
 1.40 10-Aug-2014  matt Changes to existing files to enable building AARCH64 userland.
evbarm64-el
This is clang only. While gcc4.8 supports aarch64, no netbsd support has
been written for aarch64 with gcc4.8.
 1.39 15-Jul-2014  joerg Print uint32_t field as such.
 1.38 24-Feb-2014  skrll branches: 1.38.2;
Rename NetBSD/hp700 to NetBSD/hppa.

Unfortunately our VCS isn't very helpful here.
 1.37 22-Aug-2013  matt Add m68000/coldfire.
Add evbcf.
 1.36 11-Aug-2013  riz A number of new earm MACHINE_ARCH have shown up recently; make sure
we can deduce their endianness.
 1.35 15-May-2013  christos %td is for ptrdiff_t not for off_t
 1.34 13-May-2013  christos CVE 1020933: Prevent integer overflow by using wider type
 1.33 13-May-2013  christos CVE 1020935: Prevent overflow
 1.32 05-May-2013  skrll Add an arch_endian entry for x86_64.
 1.31 03-May-2013  matt Make sure to initialize byteorder if native.
 1.30 03-May-2013  matt Fix tpyos.
 1.29 03-May-2013  matt Make disklabel a MI tool. It will use MACHINE/MACHINE_ARCH to determine
the disklabel params as well as allowing command-line options of -M <machine>
and -B {le,be} to specify MACHINE and byteorder to be used.
 1.28 17-Jan-2013  christos move dk_ioctl to a header file for the benefit of x-building.
 1.27 08-Apr-2012  cyber branches: 1.27.2;
PR bin/45744
from Julian Fagir
Removing options that have had implementations removed.

-b: removed in -r1.4
-s: removed in -r1.2
 1.26 30-Aug-2011  bouyer branches: 1.26.2;
Add getlabelusesmbr(), as proposed in
http://mail-index.netbsd.org/tech-userlevel/2011/08/25/msg005404.html
This is used by disk tools such as disklabel(8) to dynamically decide is
the undelyling platform uses a disklabel-in-mbr-partition or not
(instead of using a compile-time list of ports).
getlabelusesmbr() reads the sysctl kern.labelusesmbr, takes its value from the
machdep #define LABELUSESMBR.
For evbmips, make LABELUSESMBR 1 if the platform uses pmon
as bootloader, and 0 (the previous value) otherwise.
 1.25 29-Aug-2011  joerg Use __dead
 1.24 06-Jan-2011  apb Change printf formats to match the data type of the values being
printed. There's now a lot of PRIu16 and PRIu32, some PRIu8, some
SCNu32, and a few cases where %u and %d were reversed. Multiplication
of 32-bit and 8-bit values is cast to uint64_t and printed with PRIu64.

Inspired by a report from Patrick Welche on current-users.
 1.23 06-Jan-2011  christos match printf formats and types from Patrick Welche
 1.22 05-Jan-2010  tsutsui Add necessary byteswap ops for tools disklabel(8) used with -F option
(treating a target disk as a regular file and suppressing ioctl(2)s)
on reading/writing disklabel in a target file.
This allows cross build enviroment creating bootable disk images
for targets in different endian.
No functional changes to native (non-tools) disklabel(8) command.

Closes PR toolchain/42357.
 1.21 28-Nov-2009  tsutsui Don't use #ifdef __${MACHINE_ARCH}__ to enable machine dependent features.
Instead, use proper macro defined in Makefile per ${MACHINE_ARCH}.

__${MACHINE_ARCH}__ doesn't represent an architecture of tool's target
but an architecture of binaries being compiled, so required features
are not prolery enabled or unintentionally enabled on certain host
and target combinations during src/tools build.
 1.20 04-May-2009  mhitch fix sign-compare issues in vax-specific code.
 1.19 20-Jul-2008  lukem branches: 1.19.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.18 28-Apr-2008  martin branches: 1.18.2;
Remove clause 3 and 4 from TNF licenses
 1.17 05-Jun-2007  dyoung branches: 1.17.12; 1.17.14;
Let the operator use the DISKLABELSECTOR and DISKLABELOFFSET
environment variables to override the sector number, and the
bytes-offset in the sector, where disklabel(8) writes a disklabel.

If disklabel(8) was compiled as a host tool, then the defaults
still come from the port's LABELOFFSET and LABELSECTOR #defines.
Otherwise, the defaults still come from the sysctls, kern.labelsector
and kern.labeloffset.

This change helps me create a bootable CompactFlash image with both
a Master Boot Record (MBR) and a BSD disklabel for the RouterBOARD
153. The RB 153 is an evbmips board with a CompactFlash slot. It
searches the MBR on a CompactFlash card for a partition containing
an ELF kernel. When disklabel(8) is built for evbmips, it will
ordinarily overwrite an MBR with the BSD disklabel.
 1.16 12-Apr-2007  matt Remove defunct B from getopt string.
 1.15 08-Feb-2007  drochner include <signal.h> where signal(3) is used
 1.14 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.13 26-Nov-2006  jmmv Add a '-l' flag and a 'L' command to interactive mode to list all known
file system types. (Similar to what fdisk does for partition types.)

Closes PR bin/12954.
 1.12 25-Jun-2006  christos GCC4 fixes from Mike Pumford
 1.11 11-Jun-2006  christos PR/33695: Arnaud Lacombe: Add compatibility syntax for FreeBSD interoperability.
 1.10 07-Jun-2006  christos fix gcc warning.
 1.9 18-Mar-2006  dsl Coverty 521: fclose() temporary file used when editing label.
 1.8 07-Dec-2005  jmc Fix acorn builds
 1.7 20-Oct-2005  dsl Fix alpha build - pointed out by Kurt Schreiner on port-alpha
 1.6 19-Oct-2005  dsl Rototil the way disklabel -r reads and writes labels.
In particular the 'read' part plays 'hunt the disklabel' in order to get a
label into a local buffer - from where it can be displayed/edited.
The 'write' part makes a separate scan of the disk looking for places to
write the label.
The main changes are:
- It can no longer write the first 8k of the mbr to the pbr (or v.v.)
- All labels on the disk (that it can find) get updated during a write
- With -A all the labels are displayed (inc. those deleted by -D)
- Addition of -D which will delete (by one's complimenting dk_magic{2}) and
existing labels before writing labels to the expected locations.
- -v gives some verbose output to stderr, -vv more etc
A better basis for processing incorrect endian labels, or labels from other
architectures.
 1.5 27-Aug-2005  uwe When building as host tool don't include "../../include/util.h".

getlabel{offset,sector} and opendisk functions declared in that file
are not used in this case anyway, and <util.h> pulls in unwatned
includes (e.g. <utmpx.h> doesn't exist on FreeBSD 4.*).

XXX: We can probably undo the #if !HAVE_NBTOOL_CONFIG_H kludge in
<util.h> now.
 1.4 17-Jun-2005  dsl Rip out the support for writing bootstrap code. installboot(8) contains
support for hp300, hp700 and vax, $MACHINE is never arm32.
Fix usage output to only contain progname() once - bug introduced in rev 1.89
 1.3 15-Jun-2005  dsl Remove the never changed 'bootxx' variable
 1.2 15-Jun-2005  dsl Remove all the code that was under 'NUMBOOT > 1' nothing has set that for
a long time.
 1.1 12-Jun-2005  dyoung Make disklabel(8) into a host-tool, "nbdisklabel." Move disklabel.c
to main.c to avoid a name collision with lib/libc/gen/disklabel.c
when we build nbdisklabel. Still todo: commit host-tool build
infrastructure to src/tools/disklabel/.
 1.17.14.1 18-May-2008  yamt sync with head.
 1.17.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.17.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.26.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26.2.2 23-Jan-2013  yamt sync with head
 1.26.2.1 17-Apr-2012  yamt sync with head
 1.27.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.27.2.2 23-Jun-2013  tls resync from head
 1.27.2.1 25-Feb-2013  tls resync with head
 1.38.2.1 10-Aug-2014  tls Rebase.
 1.46.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.46.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.48.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.48.2.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.50.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.52.2.1 17-Jun-2024  martin Pull up following revision(s) (requested by tsutsui in ticket #1841):

sbin/disklabel/main.c: revision 1.58

Fix an old bug in NATIVELABEL_ONLY case in PR/50729 by me. (sigh)
'disklabel -r -w' writes a disklabel at a wrong sector in
NATIVELABEL_ONLY && !LABELUSESMBR && LABELSECTOR != 0 case
if the target disk doesn't have a valid disklabel, due to
incorrect LABEL_OFFSET value.

Found and investigated on NetBSD/hp300 bootable CD tests.
Maybe this affects ports that use distrib/utils/x_disklabel
but have no MBR support, i.e. only NetBSD/hp300 10.0 and
NetBSD/ews4800mips 9.0 and later.
 1.55.2.1 31-May-2021  cjep sync with head
 1.57.2.1 17-Jun-2024  martin Pull up following revision(s) (requested by tsutsui in ticket #692):

sbin/disklabel/main.c: revision 1.58

Fix an old bug in NATIVELABEL_ONLY case in PR/50729 by me. (sigh)
'disklabel -r -w' writes a disklabel at a wrong sector in
NATIVELABEL_ONLY && !LABELUSESMBR && LABELSECTOR != 0 case
if the target disk doesn't have a valid disklabel, due to
incorrect LABEL_OFFSET value.

Found and investigated on NetBSD/hp300 bootable CD tests.
Maybe this affects ports that use distrib/utils/x_disklabel
but have no MBR support, i.e. only NetBSD/hp300 10.0 and
NetBSD/ews4800mips 9.0 and later.
 1.58.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 21-Jul-1999  kleink Try $TMPDIR before resorting to _PATH_TMP.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Sep-1994  mycroft Finish 4.4-Lite merge, and convert to use err(3)/warn(3) functions.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16 06-Jan-2011  apb Change printf formats to match the data type of the values being
printed. There's now a lot of PRIu16 and PRIu32, some PRIu8, some
SCNu32, and a few cases where %u and %d were reversed. Multiplication
of 32-bit and 8-bit values is cast to uint64_t and printed with PRIu64.

Inspired by a report from Patrick Welche on current-users.
 1.15 18-Jan-2009  apb Remove local definitions of PRIxxxx macros in favour of the
centralised definitions from tools/compat/compat_defs.h, which
are included via nbtool_config.h.
 1.14 27-Aug-2005  uwe Oops, brain fart. PRIu32 should be "u", not "d".
 1.13 27-Aug-2005  uwe Define PRIu32 in host environments that don't have it defined.
Define it to "d", as we are unlikely to support hosts where int is
smaller than 32 bits anyway :).
 1.12 12-Jun-2005  dyoung Make disklabel(8) into a host-tool, "nbdisklabel." Move disklabel.c
to main.c to avoid a name collision with lib/libc/gen/disklabel.c
when we build nbdisklabel. Still todo: commit host-tool build
infrastructure to src/tools/disklabel/.
 1.11 28-Feb-2004  dsl Print everything unsigned - helps a bit for disks with [2^31..2^32) sectors.
 1.10 29-Dec-2003  jdc If a partition is adjusted so that it falls off the end of the disk, display
a '+' character (aka the '*').

OK'ed by Christos.
 1.9 20-Oct-2003  pooka Partition size and offset inside the disklabel are unsigned. Print
them as unsigned so that we don't print negative values when we're
halfway through.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 04-Aug-2003  dsl Make output fit into 80 columns when a partition doesn't end on a cylinder
boundary.
 1.6 01-Jul-2003  simonb Line up the cylinder numbers in the printlabel output a bit better.
 1.5 28-Sep-2002  dbj add FS_APPLEUFS
part of PR #17345
 1.4 27-May-2002  drochner display / read the p_cdsession field in the FS_ISO9660 case
 1.3 19-Oct-2001  lukem minor WARNS=2 stuff
 1.2 26-May-2001  christos - KNF printlabel.c
- add a function to print only one partition's info.
- print the partition information if it was modified in interactive mode.
- improve on the chaining code. [still assumes that partition offsets increase
monotonically]. We could check for overlap too.
 1.1 24-Dec-2000  lukem branches: 1.1.2;
move showinfo() and showpartition() into separate file, for use by
other programs. slightly change argument signature so that globals
aren't depended upon.
 1.1.2.2 26-Feb-2001  he Pull up revision 1.1 (new, requested by lukem):
Several fixes and enhancements:
o with ``-I'', initialize the label if it's not there, it's
corrupt, or there's no ``fake'' label.
o correct partition table header
o move some functions into a separate file for other programs
to use
o fix examples and cross references
o various cleanups
 1.1.2.1 24-Dec-2000  he file printlabel.c was added on branch netbsd-1-5 on 2001-02-26 22:25:44 +0000
 1.7 06-Aug-2011  dholland Use explicit cast instead of -Wno-pointer-sign. The site in question is
already marked XXX so there's not much point in whitewashing it.
 1.6 20-Jun-2011  mrg remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.5 29-Aug-2008  gmcgarry branches: 1.5.16;
Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.4 11-May-2006  mrg branches: 1.4.20; 1.4.24;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.3 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.2 20-Jan-2005  xtraeme ANSIfy; WARNS=3
 1.1 09-Jan-2002  thorpej dkctl(8) -- a program to manupulate disks. It currently supports
the disk cache-related ioctls.
 1.4.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.4.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.5.16.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.30 14-Sep-2024  mlelstv Expose DIOCGMEDIASIZE, DIOCGSECTORSIZE with new getgeometry command.
 1.29 30-Mar-2020  wiz branches: 1.29.8;
Teach dk(4) about ZFS.

"looks ok" mlelstv
 1.28 07-Jan-2018  wiz branches: 1.28.4;
Bump date for previous.
 1.27 07-Jan-2018  kre PR bin/52905

Document, and properly implement, the -q and -e options to dkctl xxN listwedges.
(implementation fix supplied by Petar Bogdanovic.)
 1.26 06-Jan-2016  wiz branches: 1.26.8;
Sort commands so I can find stuff.
 1.25 05-Nov-2014  wiz New sentence, new line. Bump date for previous.
 1.24 04-Nov-2014  mlelstv Add 'makewedges' option to autodiscover wedges from a changed label.
 1.23 04-Jan-2011  wiz branches: 1.23.24;
Use Nm. Bump date for previous.
 1.22 04-Jan-2011  spz add notes what 'device' is and also rub in that addwedge doesn't
create stuff on disk a bit more.
 1.21 18-May-2010  wiz Mention that dkctl(8) does not modify on-disk data, and add xrefs to
fdisk(8) and gpt(8). Bump date.
 1.20 02-Aug-2009  wiz Bump date for previous. Add comma in enumeration. Use Pp for paragraph
separation.
 1.19 30-Jul-2009  spz list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
 1.18 07-Feb-2009  uebayasi - Display cache, strategy, and list of wedges if no command is specified in
the command line.
- Sort list of wedges.

Posted on tech-userlevel a while ago, no objections then.
 1.17 12-Jan-2006  wiz branches: 1.17.4; 1.17.16; 1.17.28; 1.17.30; 1.17.32;
Improve description of strategy command a bit.
Increase list width a bit for less unnecessary line breaks.
 1.16 26-Dec-2005  yamt add a functionality to get/switch bufq strategy.
based on a patch from Juan RP.
 1.15 25-Sep-2004  wiz Improve formatting.
 1.14 25-Sep-2004  snj Bump date for last.
 1.13 25-Sep-2004  thorpej Add commands to create, delete, and query the configuration of wedges.
 1.12 16-Sep-2004  erh Add a couple cross-references to make similar ctl commands easier to find.
 1.11 30-Aug-2004  wiz Bump date for improved bad sector
description.
 1.10 30-Aug-2004  drochner mention that the "badsector" subcommend depends on the WD_BADSECTOR
kernel option
 1.9 13-Jul-2003  lukem also reference disklabel(5)
 1.8 16-Apr-2003  wiz New sentence, new line.
 1.7 16-Apr-2003  wiz Drop superfluous .Pp; bump date for last.
 1.6 15-Apr-2003  darrenr Add a note to "retry" option about device requirements.
 1.5 15-Apr-2003  darrenr Implement (and document!) "dkctl <dev> badsector .." to `manage' the bad
sector information in the kernel. Doing this uncovered some shortcomings
that should have been pretty obvious with the code committed prior, addressing
the major kludge with a new struct - disk_bacsecinfo to be passed into
DIOCBSLIST.
 1.4 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.3 01-Jul-2002  yamt add a new command, "keeplabel".
 1.2 09-Jan-2002  wiz Grammar fix, and drop a trailing comma in SEE ALSO section.
 1.1 09-Jan-2002  thorpej dkctl(8) -- a program to manupulate disks. It currently supports
the disk cache-related ioctls.
 1.17.32.1 21-Apr-2010  matt sync to netbsd-5
 1.17.30.1 14-Aug-2009  snj Pull up following revision(s) (requested by spz in ticket #887):
sbin/dkctl/dkctl.8: revision 1.19, 1.20
list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
 1.17.28.1 14-Aug-2009  snj Pull up following revision(s) (requested by spz in ticket #887):
sbin/dkctl/dkctl.8: revision 1.19
list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
 1.17.16.2 18-Aug-2009  bouyer Pull up following revision(s) (requested by spz in ticket #1350):
sbin/dkctl/dkctl.8: revision 1.20
Bump date for previous. Add comma in enumeration. Use Pp for paragraph
separation.
 1.17.16.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by spz in ticket #1350):
sbin/dkctl/dkctl.c: revision 1.18
sbin/dkctl/dkctl.8: revision 1.19
list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.17.4.2 18-Aug-2009  bouyer Pull up following revision(s) (requested by spz in ticket #1350):
sbin/dkctl/dkctl.8: revision 1.20
Bump date for previous. Add comma in enumeration. Use Pp for paragraph
separation.
 1.17.4.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by spz in ticket #1350):
sbin/dkctl/dkctl.c: revision 1.18
sbin/dkctl/dkctl.8: revision 1.19
list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.23.24.1 11-Nov-2014  martin Pull up following revision(s) (requested by mlelstv in ticket #201):
sbin/dkctl/dkctl.8: revision 1.24
sbin/dkctl/dkctl.8: revision 1.25
sys/dev/scsipi/sd.c: revision 1.310
sys/dev/ata/wd.c: revision 1.415
sbin/dkctl/dkctl.c: revision 1.21
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.315
sys/dev/ld.c: revision 1.78
sys/dev/vnd.c: revision 1.234
sys/dev/dksubr.c: revision 1.54
sys/sys/dkio.h: revision 1.20
sys/dev/dkwedge/dk.c: revision 1.74
Add ioctl to autodiscover wedges.
Implement DIOCMWEDGES ioctl that triggers wedge autodiscovery.
Also fix a reference counting bug and clean up some code.
support DIOCMWEDGES ioctl.
Add 'makewedges' option to autodiscover wedges from a changed label.
New sentence, new line. Bump date for previous.
 1.26.8.1 11-Apr-2018  martin Pull up following revision(s) (requested by kre in ticket #737):

sbin/dkctl/dkctl.8: revision 1.27
sbin/dkctl/dkctl.8: revision 1.28
sbin/dkctl/dkctl.c: revision 1.26

PR bin/52905

Document, and properly implement, the -q and -e options to dkctl xxN listwedges.
(implementation fix supplied by Petar Bogdanovic.)

Bump date for previous.
 1.28.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.29.8.1 02-Aug-2025  perseant Sync with HEAD
 1.27 14-Sep-2024  mlelstv Expose DIOCGMEDIASIZE, DIOCGSECTORSIZE with new getgeometry command.
 1.26 07-Jan-2018  kre branches: 1.26.16;

PR bin/52905

Document, and properly implement, the -q and -e options to dkctl xxN listwedges.
(implementation fix supplied by Petar Bogdanovic.)
 1.25 05-Apr-2017  jdolecek branches: 1.25.4;
write info about DKCACHE_FUA, DKCACHE_DPO in disk_getcache()
 1.24 10-Jan-2017  christos branches: 1.24.2;
missing <sys/stat.h>
 1.23 06-Jan-2016  wiz branches: 1.23.2;
Sort command list in usage.
 1.22 23-Nov-2014  christos - pass the proper argument vector so that subcommands can use getopt.
- add -q and -e for listwedges.
 1.21 04-Nov-2014  mlelstv Add 'makewedges' option to autodiscover wedges from a changed label.
 1.20 27-Aug-2011  joerg branches: 1.20.20;
staticfy. __dead.
 1.19 06-Aug-2011  dholland Use explicit cast instead of -Wno-pointer-sign. The site in question is
already marked XXX so there's not much point in whitewashing it.
 1.18 02-Aug-2009  spz make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.17 07-Feb-2009  uebayasi - Display cache, strategy, and list of wedges if no command is specified in
the command line.
- Sort list of wedges.

Posted on tech-userlevel a while ago, no objections then.
 1.16 17-Jun-2006  christos branches: 1.16.4; 1.16.16; 1.16.28; 1.16.30; 1.16.32;
fix typo
 1.15 16-Jun-2006  elad strcpy -> strlcpy

okay christos
 1.14 17-Mar-2006  dsl Fix build breakage, split assignment and test for ease of reading.
 1.13 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.12 26-Dec-2005  yamt add a functionality to get/switch bufq strategy.
based on a patch from Juan RP.
 1.11 20-Jan-2005  xtraeme ANSIfy; WARNS=3
 1.10 28-Sep-2004  martin Use PRI* format strings to print 64 bit data types.
 1.9 25-Sep-2004  thorpej Add commands to create, delete, and query the configuration of wedges.
 1.8 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.7 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.6 16-Apr-2003  martin Until timeval.tv_sec becomes a time_t, we can't pass a pointer to
it to ctime(). tv_sec is long, while time_t is int on some archs.
 1.5 16-Apr-2003  dsl Fix printf formats and kill unused variable to make it compile
 1.4 15-Apr-2003  darrenr Don't forget to increment the iterator when going around a loop
 1.3 15-Apr-2003  darrenr Implement (and document!) "dkctl <dev> badsector .." to `manage' the bad
sector information in the kernel. Doing this uncovered some shortcomings
that should have been pretty obvious with the code committed prior, addressing
the major kludge with a new struct - disk_bacsecinfo to be passed into
DIOCBSLIST.
 1.2 01-Jul-2002  yamt add a new command, "keeplabel".
 1.1 09-Jan-2002  thorpej dkctl(8) -- a program to manupulate disks. It currently supports
the disk cache-related ioctls.
 1.16.32.1 21-Apr-2010  matt sync to netbsd-5
 1.16.30.1 14-Aug-2009  snj Pull up following revision(s) (requested by spz in ticket #887):
sbin/dkctl/dkctl.c: revision 1.18
make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.16.28.1 14-Aug-2009  snj Pull up following revision(s) (requested by spz in ticket #887):
sbin/dkctl/dkctl.c: revision 1.18
make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.16.16.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by spz in ticket #1350):
sbin/dkctl/dkctl.c: revision 1.18
sbin/dkctl/dkctl.8: revision 1.19
list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.16.4.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by spz in ticket #1350):
sbin/dkctl/dkctl.c: revision 1.18
sbin/dkctl/dkctl.8: revision 1.19
list the partition types addwedge understands, so you don't need to utsl
to find out what strings to use here
fixes PR 37252
make dkctl conform to its man page and print the device name on addwedge
when the addition was successful (as well as indicating success).
 1.20.20.1 11-Nov-2014  martin Pull up following revision(s) (requested by mlelstv in ticket #201):
sbin/dkctl/dkctl.8: revision 1.24
sbin/dkctl/dkctl.8: revision 1.25
sys/dev/scsipi/sd.c: revision 1.310
sys/dev/ata/wd.c: revision 1.415
sbin/dkctl/dkctl.c: revision 1.21
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.315
sys/dev/ld.c: revision 1.78
sys/dev/vnd.c: revision 1.234
sys/dev/dksubr.c: revision 1.54
sys/sys/dkio.h: revision 1.20
sys/dev/dkwedge/dk.c: revision 1.74
Add ioctl to autodiscover wedges.
Implement DIOCMWEDGES ioctl that triggers wedge autodiscovery.
Also fix a reference counting bug and clean up some code.
support DIOCMWEDGES ioctl.
Add 'makewedges' option to autodiscover wedges from a changed label.
New sentence, new line. Bump date for previous.
 1.23.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.23.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.24.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.25.4.1 11-Apr-2018  martin Pull up following revision(s) (requested by kre in ticket #737):

sbin/dkctl/dkctl.8: revision 1.27
sbin/dkctl/dkctl.8: revision 1.28
sbin/dkctl/dkctl.c: revision 1.26

PR bin/52905

Document, and properly implement, the -q and -e options to dkctl xxN listwedges.
(implementation fix supplied by Petar Bogdanovic.)

Bump date for previous.
 1.26.16.1 02-Aug-2025  perseant Sync with HEAD
 1.3 23-Jan-2016  christos Define _KERNTYPES for things that need it.
 1.2 02-Mar-2007  riz Use CPPFLAGS, not COPTS, and ${NETBSDSRCDIR}, not "../..". This
should fix OBJDIR builds. (Hi, martin!)
 1.1 01-Mar-2007  martin Add a tool to scan disks for BSD disklabels (might be from different
archs) and add wedges for them. Similar to the kernel options
DKWEDGE_AUTODISCOVER and DKWEDGE_METHOD_BSDLABEL, and actually reusing
most of that code.

This means, for example, you can plug a sparc64 disk into an i386, run
this tool and mount the partitions (provided your kernel has the FFS_EI
option).
 1.3 10-Nov-2021  msaitoh s/endianess/endianness/
 1.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.1 01-Mar-2007  martin branches: 1.1.12; 1.1.14;
Add a tool to scan disks for BSD disklabels (might be from different
archs) and add wedges for them. Similar to the kernel options
DKWEDGE_AUTODISCOVER and DKWEDGE_METHOD_BSDLABEL, and actually reusing
most of that code.

This means, for example, you can plug a sparc64 disk into an i386, run
this tool and mount the partitions (provided your kernel has the FFS_EI
option).
 1.1.14.1 18-May-2008  yamt sync with head.
 1.1.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 11-Apr-2020  jdolecek adjust to work with updated dkwedge_bsdlabel.c - provide geteblk() and
brelse() which just allocate/free the memory
 1.4 08-Jun-2017  chs branches: 1.4.6;
use a minimal "struct disk" in userland rather than the full kernel structure.
needed due to upcoming sys/disk.h changes needed for ZFS.
 1.3 27-Aug-2011  joerg Mark usage as static and dead.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 01-Mar-2007  martin branches: 1.1.12; 1.1.14;
Add a tool to scan disks for BSD disklabels (might be from different
archs) and add wedges for them. Similar to the kernel options
DKWEDGE_AUTODISCOVER and DKWEDGE_METHOD_BSDLABEL, and actually reusing
most of that code.

This means, for example, you can plug a sparc64 disk into an i386, run
this tool and mount the partitions (provided your kernel has the FFS_EI
option).
 1.1.14.1 18-May-2008  yamt sync with head.
 1.1.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.6.1 21-Apr-2020  martin Sync with HEAD
 1.3 01-Jan-2013  dsl Explicitly include sys/ioctl.h
 1.2 28-Apr-2008  martin branches: 1.2.20; 1.2.26;
Remove clause 3 and 4 from TNF licenses
 1.1 01-Mar-2007  martin branches: 1.1.12; 1.1.14;
Add a tool to scan disks for BSD disklabels (might be from different
archs) and add wedges for them. Similar to the kernel options
DKWEDGE_AUTODISCOVER and DKWEDGE_METHOD_BSDLABEL, and actually reusing
most of that code.

This means, for example, you can plug a sparc64 disk into an i386, run
this tool and mount the partitions (provided your kernel has the FFS_EI
option).
 1.1.14.1 18-May-2008  yamt sync with head.
 1.1.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.26.1 25-Feb-2013  tls resync with head
 1.2.20.1 23-Jan-2013  yamt sync with head
 1.5 08-Jun-2017  chs use a minimal "struct disk" in userland rather than the full kernel structure.
needed due to upcoming sys/disk.h changes needed for ZFS.
 1.4 15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.3 27-Aug-2011  joerg branches: 1.3.2;
Mark usage as static and dead.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 01-Mar-2007  martin branches: 1.1.12; 1.1.14;
Add a tool to scan disks for BSD disklabels (might be from different
archs) and add wedges for them. Similar to the kernel options
DKWEDGE_AUTODISCOVER and DKWEDGE_METHOD_BSDLABEL, and actually reusing
most of that code.

This means, for example, you can plug a sparc64 disk into an i386, run
this tool and mount the partitions (provided your kernel has the FFS_EI
option).
 1.1.14.1 18-May-2008  yamt sync with head.
 1.1.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.1 08-Feb-2011  haad branches: 1.1.2;
Initial import of libdm and dmctl to tree. libdm library can be used
to access, manage and manipulate device-mapper driver. Which opens us bunch
of new possibilities like

dm-multipath device target
dm-crypt device target
dm-ccd compatibility layer

With this import I'm bringing in dmctl tool for working with dm driver ,too.
I plan to replace gpl2 licensed dmsetup command with our dmctl tool in near
feature. It can also by placed to /rescue where we was not able to put
dmsetup because of licensing problems.

With libdm in tree we can now write RUMP atf test suite for dm driver to
ensure LVM subsystem stability as time goes.

Reviewed by: blymn@ and rmind@
Oked: by no objections on tech-userlevel@
 1.1.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.1.2.1 08-Feb-2011  bouyer file Makefile was added on branch bouyer-quota2 on 2011-02-08 18:09:39 +0000
 1.2 08-Feb-2011  wiz branches: 1.2.2;
Fix typos.
 1.1 08-Feb-2011  haad Initial import of libdm and dmctl to tree. libdm library can be used
to access, manage and manipulate device-mapper driver. Which opens us bunch
of new possibilities like

dm-multipath device target
dm-crypt device target
dm-ccd compatibility layer

With this import I'm bringing in dmctl tool for working with dm driver ,too.
I plan to replace gpl2 licensed dmsetup command with our dmctl tool in near
feature. It can also by placed to /rescue where we was not able to put
dmsetup because of licensing problems.

With libdm in tree we can now write RUMP atf test suite for dm driver to
ensure LVM subsystem stability as time goes.

Reviewed by: blymn@ and rmind@
Oked: by no objections on tech-userlevel@
 1.2.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.2.2.1 08-Feb-2011  bouyer file README was added on branch bouyer-quota2 on 2011-02-08 18:09:39 +0000
 1.5 04-Jun-2017  abhinav Fix typo
 1.4 11-Sep-2016  sevan Mention author in AUTHORS section.
Bump date.
 1.3 21-Feb-2011  njoly Small typo in macro (Ii -> It).
 1.2 08-Feb-2011  wiz branches: 1.2.2;
Improve a bit.
 1.1 08-Feb-2011  haad Initial import of libdm and dmctl to tree. libdm library can be used
to access, manage and manipulate device-mapper driver. Which opens us bunch
of new possibilities like

dm-multipath device target
dm-crypt device target
dm-ccd compatibility layer

With this import I'm bringing in dmctl tool for working with dm driver ,too.
I plan to replace gpl2 licensed dmsetup command with our dmctl tool in near
feature. It can also by placed to /rescue where we was not able to put
dmsetup because of licensing problems.

With libdm in tree we can now write RUMP atf test suite for dm driver to
ensure LVM subsystem stability as time goes.

Reviewed by: blymn@ and rmind@
Oked: by no objections on tech-userlevel@
 1.2.2.3 05-Mar-2011  bouyer Sync with HEAD
 1.2.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.2.2.1 08-Feb-2011  bouyer file dmctl.8 was added on branch bouyer-quota2 on 2011-02-08 18:09:39 +0000
 1.6 09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.5 16-Jun-2015  christos fix error messages containing \n
 1.4 19-Oct-2013  christos fix unused variable warnings.
 1.3 27-Aug-2011  joerg branches: 1.3.2; 1.3.8;
static. dead.
 1.2 08-Feb-2011  pgoyette branches: 1.2.2;
Use PRIu64 to fix build on amd64 (and presumably other 64-bit ports)
 1.1 08-Feb-2011  haad Initial import of libdm and dmctl to tree. libdm library can be used
to access, manage and manipulate device-mapper driver. Which opens us bunch
of new possibilities like

dm-multipath device target
dm-crypt device target
dm-ccd compatibility layer

With this import I'm bringing in dmctl tool for working with dm driver ,too.
I plan to replace gpl2 licensed dmsetup command with our dmctl tool in near
feature. It can also by placed to /rescue where we was not able to put
dmsetup because of licensing problems.

With libdm in tree we can now write RUMP atf test suite for dm driver to
ensure LVM subsystem stability as time goes.

Reviewed by: blymn@ and rmind@
Oked: by no objections on tech-userlevel@
 1.2.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.2.2.1 08-Feb-2011  bouyer file dmctl.c was added on branch bouyer-quota2 on 2011-02-08 18:09:39 +0000
 1.3.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12 05-Sep-2005  dsl Make is worthwhile haveing #ifdef SMALL by making the Makefile set it when
SMALLPROG is defined (eg by src/distrib/commonMakefile.crunch).
Shrink SMALL version even more.
 1.11 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.10 20-Jan-2005  xtraeme Remove main() prototype; WARNS=2
 1.9 16-Jun-2000  simonb Oops, forgot to commit this file - actually remove the kmem setgid bit.
 1.8 18-Mar-1995  cgd branches: 1.8.14;
convert to new RCS Id conventions; reduce my headache
 1.7 22-Dec-1994  cgd specify man pages the new way.
 1.6 11-May-1994  cgd clean up import
 1.5 28-Jan-1994  cgd needs -lkvm, not -lutil
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 11-May-1994  cgd oops
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.14.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26 30-Oct-2018  kre Correct the 6 second offset issue between the time reported by
dmesg -T and the actual time a message was produced, noted on
current-users by Geoff Wing (Oct 27, 2018).

The size of the offset would depend upon architecture, and processor,
but was the delay from starting the clocks to initialising the time
of day (after mounting root, in case that is needed).

Change the kernel to set boottime to be the time at which the
clocks were started, rather than the time at which it is init'd
(by subtracting the interval between).

Correct dmesg to properly compute the ToD based upon the
boottime (which is a timespec, not a timeval, and has been
since Jan 2009) and the time logged in the message.

Note that this can (rarely) be 1 second earlier than date reports.
This occurs when the time when the message was logged was actually
in the next second, but the timecounters have not yet processed
the tick, and so the time of the last tick, near the end of the
previous second, is reported instead. Since times are always
truncated, rather than rounded, it is occasionally possible to
observe that disparity (if you try hard enough).

IOW: sys/kern/subr_prf.c:addtstamp() uses getnanouptime() rather
than nanouptime().

Note in dmesg(8) that -T conversions are gibberish other than
when the message comes from current the running kernel. (It
could be fixed when -M is used, for messages generated by the
kernel whose corpse is being observed. But hasn't been...)
 1.25 20-Sep-2018  kre s/or/of/ (a common typo of mine) and s/or// (too many of them.)
 1.24 20-Sep-2018  wiz Remove a comma and some trailing whitespace.
 1.23 19-Sep-2018  christos changes from kre@
- pass intmax to fmtydhmsf instead of time_t to avoid extra conversions.
- make -TTT mean "always keep 3 decimal digits of duration precision" (ie:
always print ms) (including trailing 0's, even .000 if it happens)
- make -T (all forms) be subject to the locale (obey the radix character)
- don't print ymd, since that would require calendar calculations to get
right.
 1.22 19-Sep-2018  christos add -TT printing ISO 8601 duration
 1.21 14-Apr-2018  kre branches: 1.21.2;

Minor wording change (no date bump needed.)
 1.20 11-Apr-2018  wiz Sort flags in SYNOPSIS.
 1.19 10-Apr-2018  christos match the linux dmesg flags.
 1.18 01-Apr-2018  christos Handle new timestamp sequences.
 1.17 11-Sep-2016  sevan branches: 1.17.12;
dmesg first appeared in 3BSD
http://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/src/cmd/dmesg.c
Bump date.
 1.16 30-Apr-2004  wiz Bump date for previous; add comma in SEE ALSO; use Dv instead of Em.
 1.15 30-Apr-2004  briggs Talk a little about the system message buffer and cross-reference
MSGBUFSIZE in options(4).
 1.14 07-Aug-2003  agc branches: 1.14.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.13 05-Jun-2001  wiz branches: 1.13.2;
Drop arguments of .Os.
 1.12 20-Jun-2000  simonb branches: 1.12.2;
The default core file is /dev/mem, not /dev/kmem.
 1.11 29-Apr-2000  abs branches: 1.11.2;
Mention /var/run/dmesg.boot
 1.10 14-Sep-1997  lukem branches: 1.10.4;
- cleanup for WARNS=1
- cleanup .Nm usage
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 06-Aug-1994  jtc vmunix -> netbsd (PR #375)
 1.7 11-May-1994  cgd branches: 1.7.2;
clean up import
 1.6 01-Aug-1993  mycroft Add RCS indentifiers.
 1.5 13-Jun-1993  mycroft Add FILES section.
 1.4 13-Jun-1993  mycroft Update file names.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 11-May-1994  cgd oops
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.1 06-Aug-1994  mycroft update from trunk
 1.10.4.1 22-May-2000  he Pull up revision 1.11 (requested by abs):
Mention /var/run/dmesg.boot.
 1.11.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.2.2 20-Jun-2000  simonb The default core file is /dev/mem, not /dev/kmem.
 1.12.2.1 20-Jun-2000  simonb file dmesg.8 was added on branch netbsd-1-5 on 2000-06-20 01:47:04 +0000
 1.13.2.1 13-Aug-2004  jmc Pullup rev 1.15-1.16 (requested by briggs in ticket #1728)

Talk a little about the system message buffer and cross-reference
MSGBUFSIZE in options(4).
 1.14.2.1 04-Aug-2004  he Pull up revisions 1.15-1.16 (requested by briggs in ticket #727):
Expand description of the system message buffer, and cross-reference
MSGBUFSIZE in options(4). Bump date and some minor cleanup.
Part of fix for PR#26439.
 1.17.12.4 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.17.12.3 30-Sep-2018  pgoyette Ssync with HEAD
 1.17.12.2 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.17.12.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.21.2.1 10-Jun-2019  christos Sync with HEAD
 1.51 06-Aug-2022  rin Assert postts only if we really obtained a timestamp.
 1.50 06-Aug-2022  rin Do not declare unused tstamp for SMALL. NFC.
 1.49 06-Aug-2022  rin Get back to the statically-allocated tbuf.

If a string is longer than tbuf, it cannot be a timestamp.
Therefore, no need for buffering anymore in this case.
 1.48 06-Aug-2022  rin Oops, fix thinko in the previous.
 1.47 06-Aug-2022  rin Do not discard \[.*\] which is not identified as a timestamp.
 1.46 06-Aug-2022  rin KNF. Do not unnecessarily define ADDC() for SMALL. No binary changes.
 1.45 01-Jan-2020  kre Make recent change build for SMALL builds as well as normal ones.
 1.44 31-Dec-2019  tsutsui Fix dmesg(8) to preserve leading whitespaces of kernel messages.

Closes PR/54729.
 1.43 04-Jun-2019  kre branches: 1.43.2;

Delete a redundant (useless) assignment. NFCI.
 1.42 04-Jun-2019  kre PR toolchain/54269

Make a SMALL dmesg even smaller.

When compiled -DSMALL, dmesg does nothing at all with the kernel
timestamps (it processes no options to be told what would be the
user's desire) so make it truly do (almost) nothing, rather than
some botched partial processing of them.

The "almost" is that a SMALL dmesg will now ignore spaces at the
beginning of each new message line ... those are (vanishingly)
unlikely to occur, as the kernel puts the timestamp (which starts
with '[' there) - fixing this would have meant even more #ifdef's
as the code that ignores that leading space is the only remaining
thing that (in a SMALL) dmesg looks at the value of the "tstamp"
variable, and if we don't keep some use of it, gcc complains...

These changes affect only SMALL dmesg (as installed on boot
floppies, etc) and have no intended effect on the version that's
installed on a normal (full size) running system.
 1.41 30-Oct-2018  kre Correct the 6 second offset issue between the time reported by
dmesg -T and the actual time a message was produced, noted on
current-users by Geoff Wing (Oct 27, 2018).

The size of the offset would depend upon architecture, and processor,
but was the delay from starting the clocks to initialising the time
of day (after mounting root, in case that is needed).

Change the kernel to set boottime to be the time at which the
clocks were started, rather than the time at which it is init'd
(by subtracting the interval between).

Correct dmesg to properly compute the ToD based upon the
boottime (which is a timespec, not a timeval, and has been
since Jan 2009) and the time logged in the message.

Note that this can (rarely) be 1 second earlier than date reports.
This occurs when the time when the message was logged was actually
in the next second, but the timecounters have not yet processed
the tick, and so the time of the last tick, near the end of the
previous second, is reported instead. Since times are always
truncated, rather than rounded, it is occasionally possible to
observe that disparity (if you try hard enough).

IOW: sys/kern/subr_prf.c:addtstamp() uses getnanouptime() rather
than nanouptime().

Note in dmesg(8) that -T conversions are gibberish other than
when the message comes from current the running kernel. (It
could be fixed when -M is used, for messages generated by the
kernel whose corpse is being observed. But hasn't been...)
 1.40 20-Sep-2018  kre Whitespace. NFC.
 1.39 20-Sep-2018  kre Use the locale's numeric radix character ("decimal point") more generally
(in !SMALL versions of dmesg).
 1.38 20-Sep-2018  kre Remove #if 0'd code that somehow got mangled in the (somewhat messy)
commit process and ended up being a syntax error...
 1.37 19-Sep-2018  christos changes from kre@
- pass intmax to fmtydhmsf instead of time_t to avoid extra conversions.
- make -TTT mean "always keep 3 decimal digits of duration precision" (ie:
always print ms) (including trailing 0's, even .000 if it happens)
- make -T (all forms) be subject to the locale (obey the radix character)
- don't print ymd, since that would require calendar calculations to get
right.
 1.36 19-Sep-2018  kre Allow a third use of -T to force .NNN (always three digits) in -TT
(ISO8601 durations) format for timestamps - that is,not dropping trailing 0's.
 1.35 19-Sep-2018  kre In -TT mode (ISO8601 duration timestamps) print milliseconds as
decimal fractions of a second (as they should be) rather than integer
milliseconds (ie nnn.1means nnn seconds and 1/10 of a second, not
nnn seconds, and 1 millisecond). While here convert some inappropriate
time_t usage to intmax_t which works better (int, or long, would probably
work just as well).
 1.34 19-Sep-2018  christos add -TT printing ISO 8601 duration
 1.33 14-Apr-2018  kre branches: 1.33.2;

Make timestamp reading code adapt to whatever precision (up to
nanoseconds, 9 digits) the kernel happens to send in the timestamps
in log messages.

Output (numeric) timestamps (when produced) are unchanged and always
in microseconds (for now).
 1.32 11-Apr-2018  wiz Update usage.
 1.31 10-Apr-2018  christos match the linux dmesg flags.
 1.30 02-Apr-2018  christos eat NUL's first so that the state machine is not altered by them.
 1.29 01-Apr-2018  christos handle log being before timestamp...
 1.28 01-Apr-2018  christos Handle new timestamp sequences.
 1.27 29-Aug-2011  joerg branches: 1.27.40;
Use __dead
 1.26 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.25 16-Oct-2006  christos branches: 1.25.18; 1.25.22;
c99 initializer
 1.24 05-Sep-2005  dsl Make is worthwhile haveing #ifdef SMALL by making the Makefile set it when
SMALLPROG is defined (eg by src/distrib/commonMakefile.crunch).
Shrink SMALL version even more.
 1.23 20-Jan-2005  xtraeme Remove main() prototype; WARNS=2
 1.22 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.21 05-Jun-2002  augustss Make it possible to see \ in dmesg.
 1.20 20-Jun-2000  simonb branches: 1.20.2;
If "SMALL" is defined don't include kvm support, primarily for install
media.
 1.19 16-Jun-2000  simonb Don't check namelist when choosing to use the sysctl interface.
 1.18 16-Jun-2000  simonb ANSIfy.
 1.17 16-Jun-2000  simonb Use new KERN_MSGBUF sysctl if running on a live kernel, and remove
setgid kmem bit from executable.
 1.16 05-Jul-1998  mrg branches: 1.16.8;
discard privs as soon as possible.
 1.15 20-Sep-1997  enami Cosmetic change;

- indent continuation line by four space.
- put an empty line at the beginning of function which has no local variable.
 1.14 20-Sep-1997  enami Fix revived bug, described in PR#3285. But use a bit simple way;
Use loop count instead of hackery pointer play.
 1.13 20-Sep-1997  enami Don't include <sys/cdefs.h> twice in same file.
 1.12 19-Sep-1997  leo Commit userland part of pr-1891.
 1.11 14-Sep-1997  lukem - cleanup for WARNS=1
- cleanup .Nm usage
 1.10 03-May-1997  mjacob We need a hint of *what* address is bad on the kvm_read. Also,
there are two reads- one for the msgbuf pointer, and then that
for what it points to.
 1.9 06-Mar-1997  thorpej Don't get stuck in an infinite loop if the msgbuf index is 0 or 1, from
enami tsugutomo <enami@ba2.so-net.or.jp>, PR #3285.
 1.8 18-Mar-1995  cgd branches: 1.8.6;
convert to new RCS Id conventions; reduce my headache
 1.7 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.6 11-May-1994  cgd clean up import
 1.5 13-Oct-1993  jtc #include <unistd.h>, so getopt(), optarg, opterr, optind, and optopt
declarations can be removed from <stdlib.h>.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 11-May-1994  cgd oops
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.6.1 06-Mar-1997  thorpej Pull up from trunk:

Don't get stuck in an infinite loop if the msgbuf index is 0 or 1, from
enami tsugutomo <enami@ba2.so-net.or.jp>, PR #3285.
 1.16.8.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.20.2.2 20-Jun-2000  simonb If "SMALL" is defined don't include kvm support, primarily for install
media.
 1.20.2.1 20-Jun-2000  simonb file dmesg.c was added on branch netbsd-1-5 on 2000-06-20 01:49:21 +0000
 1.25.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.25.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.27.40.4 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.27.40.3 30-Sep-2018  pgoyette Ssync with HEAD
 1.27.40.2 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.27.40.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.33.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.33.2.1 10-Jun-2019  christos Sync with HEAD
 1.43.2.1 05-Jan-2020  martin Pull up following revision(s) (requested by tsutsui in ticket #601):

sbin/dmesg/dmesg.c: revision 1.44
sbin/dmesg/dmesg.c: revision 1.45

Fix dmesg(8) to preserve leading whitespaces of kernel messages.
Closes PR/54729.

Make recent change build for SMALL builds as well as normal ones.
 1.4 22-Sep-2006  thorpej - Add a new DRVCTLCOMMAND ioctl to /dev/drvctl. This is a generic
"execute a command" ioctl that takes a dictionary as an argument
(specifying the command and arguments) and returns a dictionary
with the results (error code, optional error message, optional
result data).

- Define and implement a "get-properties" command for DRVCTLCOMMAND
that returns the properties dictionary of the specified device.

- Add a -p flag to drvctl(8) to fetch and display the properties of
the specified device.

This is a great example of how to use prop_dictionary_sendrecv_ioctl().
 1.3 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.2 20-Jan-2005  xtraeme ANSIfy; WARNS=3
 1.1 18-Aug-2004  drochner add a little utility to exercise the rescan / detach autoconf functions
 1.20 07-Aug-2019  wiz Remove superfluous Pp.
 1.19 06-Aug-2019  mrg add an example about reattaching USB devices
 1.18 11-Sep-2016  sevan branches: 1.18.14;
Document the version drvctl appeard.
Reword bad sentence.
Remove space in License.
Bump date.
 1.17 08-Aug-2015  mrg add an example for rescanning ATA busses.
 1.16 13-May-2015  mlelstv Add documentation for the drvctl driver and add reference.
Fixes PR 49895.
 1.15 25-Feb-2015  wiz Bump date for previous.
New sentence, new line.
 1.14 24-Feb-2015  mlelstv Let drvctl -p select elements from an array property by numeric index.
 1.13 16-Jan-2012  pgoyette branches: 1.13.18;
Enhance drvctl -p processing to handle new autoconfig info in property
dictionaries.
 1.12 07-Aug-2011  jmcneill branches: 1.12.2;
add the -t option that modifies -l behaviour to recursively scan for
child devices and print them in tree format:

$ drvctl -lt usb0
uhub0
uhub6
uhidev0
ukbd0
wskbd1
uhidev1
ums0
wsmouse1
uhid0
ubt0
 1.11 07-Aug-2011  jmcneill add an optional argument to the -p flag that lets you extract specific
property values from the command-line:

$ drvctl -p wd0 disk-info/geometry/cylinders-per-unit
620181
$ drvctl -p wd0 device-driver device-unit
wd
0
$ drvctl -p wd0 nonexistent || echo "not found"
not found
 1.10 20-Apr-2009  wiz Document -n.
 1.9 20-Apr-2009  wiz Add -n to usage. Now it just needs to be documented.
 1.8 20-Apr-2009  wiz Bump date for previous. Remove trailing whitespace.
 1.7 20-Apr-2009  dyoung Add flag -n to suppress the first column of drvctl -l output.
 1.6 04-Apr-2009  joerg If drvctl -l is used without argument, print the root device nodes.
 1.5 16-Feb-2008  dyoung branches: 1.5.10; 1.5.12; 1.5.16;
Document -l, -Q, -R, and -S.
 1.4 10-Mar-2007  christos branches: 1.4.4; 1.4.6;
drvctl 4 does not exist.
 1.3 22-Sep-2006  thorpej branches: 1.3.2; 1.3.4;
- Add a new DRVCTLCOMMAND ioctl to /dev/drvctl. This is a generic
"execute a command" ioctl that takes a dictionary as an argument
(specifying the command and arguments) and returns a dictionary
with the results (error code, optional error message, optional
result data).

- Define and implement a "get-properties" command for DRVCTLCOMMAND
that returns the properties dictionary of the specified device.

- Add a -p flag to drvctl(8) to fetch and display the properties of
the specified device.

This is a great example of how to use prop_dictionary_sendrecv_ioctl().
 1.2 18-Aug-2004  wiz New sentence, new line.
 1.1 18-Aug-2004  drochner add a little utility to exercise the rescan / detach autoconf functions
 1.3.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.3.2.1 31-Jul-2007  liamjfoy Pull up following revision(s) (requested by jnemeth in ticket #805):
sbin/drvctl/drvctl.8: revision 1.4
drvctl 4 does not exist.
 1.4.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.4.4.1 23-Mar-2008  matt sync with HEAD
 1.5.16.1 21-Apr-2010  matt sync to netbsd-5
 1.5.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.5.10.3 12-Aug-2011  riz Pull up following revision(s) (requested by jmcneill in ticket #1656):
sbin/drvctl/drvctl.8: revision 1.11
sbin/drvctl/drvctl.8: revision 1.12
sbin/drvctl/drvctl.c: revision 1.11
sbin/drvctl/drvctl.c: revision 1.12
add an optional argument to the -p flag that lets you extract specific
property values from the command-line:
$ drvctl -p wd0 disk-info/geometry/cylinders-per-unit
620181
$ drvctl -p wd0 device-driver device-unit
wd
0
$ drvctl -p wd0 nonexistent || echo &quot;not found&quot;
not found
add the -t option that modifies -l behaviour to recursively scan for
child devices and print them in tree format:
$ drvctl -lt usb0
uhub0
uhub6
uhidev0
ukbd0
wskbd1
uhidev1
ums0
wsmouse1
uhid0
ubt0
 1.5.10.2 06-Jun-2009  bouyer Pull up following revision(s) (requested by dyoung in ticket #736):
sbin/drvctl/drvctl.8: revisions 1.7 - 1.10
sbin/drvctl/drvctl.c: revision 1.7 via patch, 1.9, 1.10
fix sign-compare issues
Add flag -n to suppress the first column of drvctl -l output.
Mention -n in usage.
Bump date for previous. Remove trailing whitespace.
Add -n to usage. Now it just needs to be documented.
Document -n.
 1.5.10.1 03-May-2009  snj Pull up following revision(s) (requested by joerg in ticket #675):
sbin/drvctl/drvctl.8: revision 1.6
sbin/drvctl/drvctl.c: revision 1.8 via patch
If drvctl -l is used without argument, print the root device nodes.
 1.12.2.1 17-Apr-2012  yamt sync with head
 1.13.18.1 07-Mar-2015  snj Pull up following revision(s) (requested by mlelstv in ticket #562):
sbin/drvctl/drvctl.8: revision 1.14
sbin/drvctl/drvctl.c: revision 1.17
Let drvctl -p select elements from an array property by numeric index.
 1.18.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.23 03-Nov-2024  rillig sbin, usr.bin, usr.sbin: remove redundant getopt declarations

No binary change, except for assertion line numbers in tprof.
 1.22 21-Aug-2022  mlelstv branches: 1.22.4;
When extracting properties, don't bail for non-existent or invalid path
elements, but continue with next properry.
 1.21 11-Jun-2020  thorpej Update for proplib(3) API changes.
 1.20 14-Feb-2018  jakllsch Revert functional changes in previous, at expense of strict KNF conformance.
 1.19 07-Jan-2018  christos KNF.
 1.18 07-Dec-2015  pgoyette synch usage() with the man page.
 1.17 24-Feb-2015  mlelstv Let drvctl -p select elements from an array property by numeric index.
 1.16 17-Jan-2012  wiz branches: 1.16.18;
Add -n to usage.
 1.15 16-Jan-2012  pgoyette Enhance drvctl -p processing to handle new autoconfig info in property
dictionaries.
 1.14 19-Oct-2011  dyoung branches: 1.14.2;
Don't print the silly header, "Properties for device `xxx0':", before
the device properties if the -n option was given.
 1.13 29-Aug-2011  joerg Use __dead
 1.12 07-Aug-2011  jmcneill add the -t option that modifies -l behaviour to recursively scan for
child devices and print them in tree format:

$ drvctl -lt usb0
uhub0
uhub6
uhidev0
ukbd0
wskbd1
uhidev1
ums0
wsmouse1
uhid0
ubt0
 1.11 07-Aug-2011  jmcneill add an optional argument to the -p flag that lets you extract specific
property values from the command-line:

$ drvctl -p wd0 disk-info/geometry/cylinders-per-unit
620181
$ drvctl -p wd0 device-driver device-unit
wd
0
$ drvctl -p wd0 nonexistent || echo "not found"
not found
 1.10 20-Apr-2009  dyoung Mention -n in usage.
 1.9 20-Apr-2009  dyoung Add flag -n to suppress the first column of drvctl -l output.
 1.8 04-Apr-2009  joerg If drvctl -l is used without argument, print the root device nodes.
 1.7 16-Mar-2009  lukem fix sign-compare issues
 1.6 27-Jan-2008  dyoung branches: 1.6.10; 1.6.12; 1.6.16;
Patch /dev/drvctl and drvctl(8) to let us suspend/resume device
sub-trees, and to let us list the children of a device.

While I am here, add -p to the drvctl(8) usage message.
 1.5 22-Sep-2006  thorpej branches: 1.5.8; 1.5.10;
- Add a new DRVCTLCOMMAND ioctl to /dev/drvctl. This is a generic
"execute a command" ioctl that takes a dictionary as an argument
(specifying the command and arguments) and returns a dictionary
with the results (error code, optional error message, optional
result data).

- Define and implement a "get-properties" command for DRVCTLCOMMAND
that returns the properties dictionary of the specified device.

- Add a -p flag to drvctl(8) to fetch and display the properties of
the specified device.

This is a great example of how to use prop_dictionary_sendrecv_ioctl().
 1.4 02-Jun-2005  lukem Fix an uninitialized variable issue.
Found with gcc -Wuninitialized.
 1.3 20-Jan-2005  xtraeme branches: 1.3.2;
ANSIfy; WARNS=3
 1.2 18-Aug-2004  wiz Sync usage with man page.
 1.1 18-Aug-2004  drochner add a little utility to exercise the rescan / detach autoconf functions
 1.3.2.1 14-Jun-2005  tron Pull up revision 1.4 (requested by lukem in ticket #401):
Fix an uninitialized variable issue.
Found with gcc -Wuninitialized.
 1.5.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.8.1 23-Mar-2008  matt sync with HEAD
 1.6.16.1 21-Apr-2010  matt sync to netbsd-5
 1.6.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.6.10.4 14-Aug-2011  riz Pull up following revision(s) (requested by jmcneill in ticket #1659):
sbin/drvctl/drvctl.c: patch
Fix the build problem introduced by pullup ticket #1656.
 1.6.10.3 12-Aug-2011  riz Pull up following revision(s) (requested by jmcneill in ticket #1656):
sbin/drvctl/drvctl.8: revision 1.11
sbin/drvctl/drvctl.8: revision 1.12
sbin/drvctl/drvctl.c: revision 1.11
sbin/drvctl/drvctl.c: revision 1.12
add an optional argument to the -p flag that lets you extract specific
property values from the command-line:
$ drvctl -p wd0 disk-info/geometry/cylinders-per-unit
620181
$ drvctl -p wd0 device-driver device-unit
wd
0
$ drvctl -p wd0 nonexistent || echo &quot;not found&quot;
not found
add the -t option that modifies -l behaviour to recursively scan for
child devices and print them in tree format:
$ drvctl -lt usb0
uhub0
uhub6
uhidev0
ukbd0
wskbd1
uhidev1
ums0
wsmouse1
uhid0
ubt0
 1.6.10.2 06-Jun-2009  bouyer Pull up following revision(s) (requested by dyoung in ticket #736):
sbin/drvctl/drvctl.8: revisions 1.7 - 1.10
sbin/drvctl/drvctl.c: revision 1.7 via patch, 1.9, 1.10
fix sign-compare issues
Add flag -n to suppress the first column of drvctl -l output.
Mention -n in usage.
Bump date for previous. Remove trailing whitespace.
Add -n to usage. Now it just needs to be documented.
Document -n.
 1.6.10.1 03-May-2009  snj Pull up following revision(s) (requested by joerg in ticket #675):
sbin/drvctl/drvctl.8: revision 1.6
sbin/drvctl/drvctl.c: revision 1.8 via patch
If drvctl -l is used without argument, print the root device nodes.
 1.14.2.1 17-Apr-2012  yamt sync with head
 1.16.18.1 07-Mar-2015  snj Pull up following revision(s) (requested by mlelstv in ticket #562):
sbin/drvctl/drvctl.8: revision 1.14
sbin/drvctl/drvctl.c: revision 1.17
Let drvctl -p select elements from an array property by numeric index.
 1.22.4.1 02-Aug-2025  perseant Sync with HEAD
 1.43 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.42 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.41 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.40 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.39 10-Aug-2012  joerg branches: 1.39.32;
Don't depend on HAVE_GCC being always defined.
 1.38 07-Apr-2012  christos use getfsspecname()
 1.37 20-Jun-2011  mrg branches: 1.37.2;
remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.36 11-Apr-2009  lukem branches: 1.36.4;
Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.35 29-Aug-2008  gmcgarry branches: 1.35.4;
Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.34 10-Aug-2008  simonb Remove adding -g to CFLAGS and LDFLAGS. Ancient debug bogon?
 1.33 11-May-2006  mrg branches: 1.33.20; 1.33.24;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.32 19-Apr-2005  hannken Snapshot support for dump(8):

- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.

- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.

Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.31 02-Apr-2003  fvdl branches: 1.31.6;
Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.30 27-Mar-2003  lukem Use "wall -g operator" (instead of private code) to broadcast() messages to
members of the operator group.
Don't install "setgid tty", and remove now unnecessary gid/egid swapping.
Remove utmp trawling code pulled in from usr.bin/who.
The Code is now simpler, and more portable (without the utmp cruft) too.

This is derived from similar work in OpenBSD.
 1.29 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.28 02-Aug-2002  christos support utmpx
 1.27 25-Dec-2001  lukem document more of the debug options
 1.26 23-Dec-2001  lukem nuke trailing whitespace
 1.25 01-Oct-1999  perseant Working version of aborted dump{,_lfs} join.
 1.24 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.23 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.22 23-Mar-1999  bouyer branches: 1.22.4;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.21 09-Mar-1999  bouyer Handle "nodump" flag on directories, by not dumping any files or directories
under it. Based on some parts of PR 6705 by Brian Grayson.
In the Makefile, add (commented out) debug options that can be turned on.
 1.20 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.19 18-Mar-1998  bouyer Add support for non-native byte order FFS. The dump is in filesystem byte
order, restore already knows how to byteswap dumps.
 1.18 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.17 27-May-1997  mrg enable rcmd(). garbage collect.
 1.16 18-Mar-1995  cgd branches: 1.16.4;
convert to new RCS Id conventions; reduce my headache
 1.15 22-Dec-1994  cgd specify man pages the new way.
 1.14 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.13 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.12 14-Nov-1993  cgd from Thomas Eberhardt <thomas@mathematik.uni-Bremen.de>:
Some reordering and modifications in the Makefiles for sh, dump,
restore to get dependicies right. The README in /usr/share/mk
states that it's a Bad Thing(tm) to add something after
.include <bsd.prog.mk>, but this seems the only way to get the
dependencies right.
 1.11 12-Nov-1993  cgd oops again; fix that last
 1.10 12-Nov-1993  cgd oops; fix that last
 1.9 12-Nov-1993  cgd add LDSTATIC
 1.8 01-Aug-1993  mycroft Add RCS identifiers.
 1.7 18-Jul-1993  mycroft Use ${COPY}, not -c for install.
 1.6 18-Apr-1993  mycroft Okay, so I was confused (but only a little).
 1.5 18-Apr-1993  mycroft Make rdump target match normal program target.
(This should probably be in a separate directory, no?)
 1.4 08-Apr-1993  cgd make install copy
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.4.1 17-Feb-1997  mrg this program is not setuid in the new-rcmd-world-order
 1.22.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.31.6.1 21-Apr-2005  tron Pull up revision 1.32 (requested by hannken in ticket #184):
Snapshot support for dump(8):
- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.
- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.
Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.33.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.33.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.35.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.36.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.37.2.2 30-Oct-2012  yamt sync with head
 1.37.2.1 17-Apr-2012  yamt sync with head
 1.39.32.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.72 19-Aug-2019  perseant Add -D flag to allow the user to specify an alternate dumpdates file.
Closes PR #54469.
 1.71 25-Mar-2019  wiz Bump date for previous.
 1.70 25-Mar-2019  manu Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry

This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.
 1.69 15-Jul-2018  dholland Document what rdump is (was once) for. PR 53442.
 1.68 15-Aug-2016  sevan branches: 1.68.6; 1.68.12; 1.68.14;
dump was there from v4.
Confirmed from the TUHS hosted copies of man pages.
Bump date.
 1.67 24-Aug-2015  bouyer Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.66 28-Apr-2015  prlw1 Fix typos
 1.65 29-Aug-2012  dholland branches: 1.65.10;
Use more markup, fix English usage.
 1.64 19-Feb-2012  wiz Sort option descriptions a bit more.
 1.63 19-Feb-2012  christos PR/45735: Bug Hunting: The dump(8) manpage, as well as the program's `usage'-line,
needs improvement
 1.62 05-Nov-2010  hannken branches: 1.62.6; 1.62.8;
File system snapshots are no longer experimental.
 1.61 14-May-2010  jruoho Use a list for the list of bugs.
 1.60 26-Feb-2010  wiz -i does not take an argument. Remove unnecessary Bk/Ek. New sentence, new line.
 1.59 26-Feb-2010  christos PR/42883: Greywolf: Add -i flag which brings "true incremental" capability.
 1.58 30-Jan-2009  enami Use indent-synopsis instead of iS register. The latter is a register
used in BSD derived .Nm implementation.
 1.57 12-Aug-2008  simonb We don't need to dump WAPBL log files - don't dump files with SF_LOG
flag set, and document this.
 1.56 11-Sep-2005  wiz branches: 1.56.20; 1.56.24;
Argument is read-blocksize, not "read blocksize". From YOMURA Masanori in private mail.
 1.55 19-Apr-2005  wiz Sort SEE ALSO.
 1.54 19-Apr-2005  hannken Snapshot support for dump(8):

- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.

- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.

Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.53 07-Aug-2003  agc branches: 1.53.6;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.52 26-May-2003  lukem * Document $RCMD_CMD in environ(7).
* Cross-reference rcmd(1), rcmd(3), and environ(7) as appropriate.

Should fix [bin/21670] from Geoff Wing.
 1.51 27-Mar-2003  lukem Use "wall -g operator" (instead of private code) to broadcast() messages to
members of the operator group.
Don't install "setgid tty", and remove now unnecessary gid/egid swapping.
Remove utmp trawling code pulled in from usr.bin/who.
The Code is now simpler, and more portable (without the utmp cruft) too.

This is derived from similar work in OpenBSD.
 1.50 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.49 04-Feb-2003  perry "Utilize" has exactly the same meaning as "use," but it is more
difficult to read and understand. Most manuals of English style
therefore say that you should use "use".
 1.48 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.47 26-Feb-2002  wiz Typo fix, from jslag@prop.walkerart.org via OpenBSD.
 1.46 21-Jan-2002  wiz Fix typo in macro.
 1.45 07-Jan-2002  bouyer For -l: specify the timeout on the command line (in seconds) instead of
hardwiring it to 2s, as suggested on tech-userlevel.
 1.44 30-Dec-2001  lukem Add -a to "auto-size" the tape, rather than relying upon other options
to define the tape size. Requires the tape driver to either return ENOSPC
at end of media, or 0 when a write is attempted (such as the "early warning"
support in st(4) enabled with "mt eew 1"). From FreeBSD.
 1.43 14-Dec-2001  bouyer Add a -l (autoload) flag. For multivolume dumps, this makes dump eject the
tape when a volume is full, and try to reopen the tape drive for 2 mn.
To be used with tape changers which load the next tape when the current one is
ejected.
While I'm there fix eject handling for remote tape.
 1.42 07-Dec-2001  wiz One '\' too many.
 1.41 16-Nov-2001  lukem relax the restriction on -F that the file system image argument must be a
regular file
 1.40 15-Oct-2001  wiz Whitespace fixes, sort SEE ALSO, sort sections.
 1.39 15-Oct-2001  blymn Add the capability for dump to print timestamps on all informational
messages.
 1.38 14-Aug-2001  lukem - implement -F, which indicates that files-to-dump is a regular file
containing a file system image (instead of being a single file as
part of a subtree dump)
- use "file system" instead of "filesystem" or "file-system"
 1.37 05-Jun-2001  wiz Drop arguments of .Os.
 1.36 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.35 07-May-2001  tron Add a new option "e" to "dump" which allows to eject tapes automatically
if a tape change is required.
 1.34 01-Jul-1999  abs branches: 1.34.8;
Note the default tape device is taken from _PATH_DEFTAPE in /usr/include/paths.h
 1.33 28-Jun-1999  abs Default device is nrst0 not rst0
 1.32 23-Mar-1999  bouyer branches: 1.32.2;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.31 09-Mar-1999  bouyer Handle "nodump" flag on directories, by not dumping any files or directories
under it. Based on some parts of PR 6705 by Brian Grayson.
In the Makefile, add (commented out) debug options that can be turned on.
 1.30 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.29 03-Jan-1999  lukem s/1998/1999/
 1.28 03-Jan-1999  lukem add support for '-L label', which file(1) and restore(1) can extract
from the header.
mostly based on [bin/6715] from Brian Grayson <bgrayson@ece.utexas.edu>
 1.27 02-Jan-1999  tron Add reference to "st(4)" as suggested by Brian Grayson in PR bin/6713.
 1.26 11-Aug-1998  frueauf A dump level above 0 saves new or modified files since the last dump of
a lower level, not the same level. Fixes pr 5402 by Kevin Sullivan.
 1.25 03-Jul-1998  fair PR#5697 + nroff cleanup
 1.24 29-Apr-1998  fair fix bad .Xr references
 1.23 28-Apr-1998  fair Change occurrences of "UNIX" to .Ux or .At as appropriate.
 1.22 11-Nov-1997  mrg add missing .Nm sections.
 1.21 20-Oct-1997  enami branches: 1.21.2;
Fix .Nm usage.
 1.20 18-Sep-1997  lukem Various changes from Brian Grayson <bgrayson@ece.utexas.edu> in [bin/4103]
* exit after providing an estimate if -S was given. the PR used -e,
but checking around indicated prior art in Solaris usin -S.
* remove superfluous 'DUMP:' prefix in two messages
* initialise blocksperfile explicitly (not necessary, but everything
else in that section gets initialised, so be consistant :)
* display the ``pretty'' name of the dumped directory, so the user
knows if it's a subset or not
 1.19 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.18 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.17 05-Jun-1997  lukem cleanup xrefs
 1.16 05-Jun-1997  lukem * Add the ability to dump specific files & directories of a single
filesystem. This uses fts(3) to access the directory structure (and
not the raw device), so the standard access permissions are adhered
to (unlike dumping an entire filesystem, which just requires read
access to the raw disk device).
* Support SIGINFO status reporting.
* Remove now unused variables that previously stored the (e)uid.
* Be more informative in a couple of error messages.
 1.15 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h>
change doco references/examples from /dev/rmt* to /dev/rst*
 1.14 05-Feb-1996  mrg support $TAPE. update manual to reflect reality (#1937).
 1.13 02-Feb-1996  phil Add /dev/rst* to FILES section. (pr 601) (Matches mt man page.)
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 21-Feb-1995  mycroft Fix an old formatting glitch.
 1.10 20-Feb-1995  mycroft Use getopt(3), with obsolete() from restore(8) for backward compatibility.
 1.9 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.8 28-Jan-1994  jtc More spelling errors.
 1.7 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.6 30-Nov-1993  jtc Use ".At v6" macro instead of spelling out "Version 6 AT&T UNIX".
 1.5 20-Aug-1993  jtc Dump is now in /sbin.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.2.1 11-Nov-1997  mrg pull up from trunk: add missing .Nm sections.
 1.32.2.1 02-Jul-1999  perry pullup 1.32->1.33 (abs): Correct default device from /dev/rst0 to /dev/nrst0
 1.34.8.3 16-Jan-2002  he Pull up revision 1.44 (via patch, requested by bouyer):
Add an ``-a'' option to ``auto-size'' the tape, rather than
relying upon other options to define the tape size.
 1.34.8.2 16-Jan-2002  he Pull up revisions 1.43,1.45 (via patch, requested by bouyer):
Implement ``-l <timeout>'' option for use with e.g. autochangers.
 1.34.8.1 09-May-2001  he Pull up revision 1.35 (requested by tron):
Add a new option ``e'' to dump which directs it to eject tapes
automatically if a tape change is required.
 1.53.6.2 21-Apr-2005  tron Pull up revision 1.55 (requested by hannken in ticket #184):
Sort SEE ALSO.
 1.53.6.1 21-Apr-2005  tron Pull up revision 1.54 (requested by hannken in ticket #184):
Snapshot support for dump(8):
- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.
- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.
Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.56.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.56.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.62.8.1 08-Mar-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1331):
sbin/dump/dump.8: revision 1.67 via patch
sbin/dump/main.c: revision 1.72
sbin/dump/rcache.c: revision 1.25
Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.62.6.2 30-Oct-2012  yamt sync with head
 1.62.6.1 17-Apr-2012  yamt sync with head
 1.65.10.1 06-Nov-2015  riz Pull up following revision(s) (requested by bouyer in ticket #990):
sbin/dump/rcache.c: revision 1.25
sbin/dump/dump.8: revision 1.67
sbin/dump/main.c: revision 1.72
Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.68.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.68.14.1 10-Jun-2019  christos Sync with HEAD
 1.68.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.68.6.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.60 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.59 03-Dec-2020  kre PR bin/55834

count blocks written in unsigned 64 bit counter
rather than signed int which overflows after 2^31-1
blocks (2TiB) after which neither the 5 minute
status updates or SIGINFO (^T) reports are issued
until the negative numbers increase past 0 and
wildly inaccurate reports would be written.
 1.58 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.57 25-Mar-2019  manu branches: 1.57.2;
Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry

This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.
 1.56 01-Mar-2019  christos Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.55 03-Feb-2019  mrg - mark Exit() __dead
- bump a buffer size to avoid possible truncation
- adding missing fallthru comment
 1.54 16-Nov-2015  christos branches: 1.54.8; 1.54.16;
- update NAME_MAX to match the kernel.
- add a comment about where the constant is used.
 1.53 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.52 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.51 15-Jun-2013  christos handle new lfs split
 1.50 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.49 13-Jan-2013  dholland Use __printflike.
 1.48 13-Jan-2013  dholland Add some const.
 1.47 05-May-2012  christos branches: 1.47.2;
remove ancient crap
 1.46 26-Feb-2010  christos branches: 1.46.6;
PR/42883: Greywolf: Add -i flag which brings "true incremental" capability.
 1.45 16-Feb-2008  matt Fix some inconsisent/conflicting definitions and missing parameters
 1.44 26-Oct-2006  hannken branches: 1.44.8; 1.44.10;
When using a snapshot take the snapshot raw device on further open.

Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)

Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.43 24-Jun-2006  perseant Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.42 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.41 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.40 27-Jun-2005  christos sprinkle const
 1.39 21-Apr-2004  christos branches: 1.39.2; 1.39.4; 1.39.6;
Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.38 15-Mar-2004  lukem Adjust tstart_volume (volume start time) by the time spent in query(),
similar to the adjustment for tstart_writing made in optr.c rev 1.4.
Should fix PR bin/19711 from matthew green.
 1.37 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.36 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.35 27-Mar-2003  lukem Use "wall -g operator" (instead of private code) to broadcast() messages to
members of the operator group.
Don't install "setgid tty", and remove now unnecessary gid/egid swapping.
Remove utmp trawling code pulled in from usr.bin/who.
The Code is now simpler, and more portable (without the utmp cruft) too.

This is derived from similar work in OpenBSD.
 1.34 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.33 30-Dec-2001  lukem Add -a to "auto-size" the tape, rather than relying upon other options
to define the tape size. Requires the tape driver to either return ENOSPC
at end of media, or 0 when a write is attempted (such as the "early warning"
support in st(4) enabled with "mt eew 1"). From FreeBSD.
 1.32 25-Dec-2001  lukem Fixes from FreeBSD:
- Fix error if first tape was write protected. Fix NetBSD PRs 4754 and 6098.
- Make dump exit codes confirm to manual page.
- Use \a instead of \7 to make noise.
- Fix estimated number of tapes for huge dumps to cartridges.
- Use <sys/queue.h> SLIST_* instead of home-rolled lists.
- Do not exit if unable to read or create /etc/dumpdates.
- Support output (tape) device returning ENOSPC for end-of-media on a write.

Fixes by me:
- Remove unused ddates_in.
- Don't dump core if SIGINFO is received before 1 second has elapsed.
- Only process SIGINFO in current "active" child.
- Don't dump core in -w if dumpdates wasn't readable and ddatev == NULL
- Minor KNF; wrap some lines
 1.31 22-Dec-2001  lukem - use correct type for minTime in findlru() (size_t instead of int)
- clean up whitespace
 1.30 14-Dec-2001  bouyer Add a -l (autoload) flag. For multivolume dumps, this makes dump eject the
tape when a volume is full, and try to reopen the tape drive for 2 mn.
To be used with tape changers which load the next tape when the current one is
ejected.
While I'm there fix eject handling for remote tape.
 1.29 15-Oct-2001  blymn Add the capability for dump to print timestamps on all informational
messages.
 1.28 14-Aug-2001  lukem s/filesystem/file system/
 1.27 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.26 27-May-2001  lukem knf to ansi
 1.25 12-May-2001  tron Fix bug in new "e" option: only eject tape if it is full, not if the dump
was finished.
 1.24 07-May-2001  tron Add a new option "e" to "dump" which allows to eject tapes automatically
if a tape change is required.
 1.23 04-Feb-2001  christos restore needs the rcmd operations.
 1.22 04-Feb-2001  christos fix redundant decls
 1.21 13-Dec-2000  scw `dev_bsize' needs to be declared extern.
 1.20 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.19 01-Oct-1999  perseant branches: 1.19.6;
Working version of aborted dump{,_lfs} join.
 1.18 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.17 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.16 23-Mar-1999  bouyer branches: 1.16.2; 1.16.4;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.15 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.14 18-Mar-1998  bouyer Add support for non-native byte order FFS. The dump is in filesystem byte
order, restore already knows how to byteswap dumps.
 1.13 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.12 15-Sep-1997  lukem remove __dead
 1.11 05-Jun-1997  lukem * Add the ability to dump specific files & directories of a single
filesystem. This uses fts(3) to access the directory structure (and
not the raw device), so the standard access permissions are adhered
to (unlike dumping an entire filesystem, which just requires read
access to the raw disk device).
* Support SIGINFO status reporting.
* Remove now unused variables that previously stored the (e)uid.
* Be more informative in a couple of error messages.
 1.10 10-Apr-1997  lukem Implement changes from [bin/1915]
* 'w' and 'W' display the year
* verbosity additions displaying total & per-volume transfer times and rates
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.5 02-Dec-1993  mycroft Avoid core dumping if /etc/dumpdates is not present. Note that only file
systems listed in dumpdates are display by `dump w' and `dump W'; this is
probably a bug.
Original bug reported by John Brezak <brezak@ch.hp.com>.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.16.2.1 10-Oct-2000  he Pull up revision 1.20 (requested by is):
Format string cleanup.
 1.19.6.8 28-Mar-2002  he Pull up revision 1.27 (via patch, requested by bouyer):
Improve behaviour when a path is given:
1) check if the path is an unmounted file system listed in fstab
2) check if it is a path to a mounted file system not listed in fstab
Fixes PR#15790.
 1.19.6.7 17-Jan-2002  he Pull up revision 1.23 (via patch, requested by bouyer):
Fix the ``Implement -l <timeout>'' pull-up;
restore needs the rcmd operation.
 1.19.6.6 16-Jan-2002  he Pull up revision 1.33 (via patch, requested by bouyer):
Add an ``-a'' option to ``auto-size'' the tape, rather than
relying upon other options to define the tape size.
 1.19.6.5 16-Jan-2002  he Pull up revisions 1.31-1.32 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.19.6.4 16-Jan-2002  he Pull up revision 1.30 (via patch, requested by bouyer):
Implement ``-l <timeout>'' option for use with e.g. autochangers.
 1.19.6.3 15-May-2001  he Pull up revision 1.25 (requested by tron):
Fix bug in new ``e'' option: only eject tape if it is full, not
if the dump was finished.
 1.19.6.2 09-May-2001  he Pull up revision 1.24 (requested by tron):
Add a new option ``e'' to dump which directs it to eject tapes
automatically if a tape change is required.
 1.19.6.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.39.6.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.39.4.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.39.2.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.44.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.44.8.1 23-Mar-2008  matt sync with HEAD
 1.46.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.46.6.2 23-Jan-2013  yamt sync with head
 1.46.6.1 23-May-2012  yamt sync with head.
 1.47.2.2 23-Jun-2013  tls resync from head
 1.47.2.1 25-Feb-2013  tls resync with head
 1.54.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.54.16.1 10-Jun-2019  christos Sync with HEAD
 1.54.8.2 07-Dec-2020  martin Pull up following revision(s) (requested by kre in ticket #1630):

sbin/dump/dump.h: revision 1.59
sbin/dump/main.c: revision 1.78

PR bin/55834

count blocks written in unsigned 64 bit counter
rather than signed int which overflows after 2^31-1
blocks (2TiB) after which neither the 5 minute
status updates or SIGINFO (^T) reports are issued
until the negative numbers increase past 0 and
wildly inaccurate reports would be written.
 1.54.8.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.57.2.1 06-Dec-2020  martin Pull up following revision(s) (requested by kre in ticket #1139):

sbin/dump/dump.h: revision 1.59
sbin/dump/main.c: revision 1.78

PR bin/55834

count blocks written in unsigned 64 bit counter
rather than signed int which overflows after 2^31-1
blocks (2TiB) after which neither the 5 minute
status updates or SIGINFO (^T) reports are issued
until the negative numbers increase past 0 and
wildly inaccurate reports would be written.
 1.5 22-Dec-1993  mycroft Clean up deleted files.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7 22-Dec-1993  mycroft Clean up deleted files.
 1.6 02-Dec-1993  mycroft Change the four inode loops to the form:
for (ino = 1; ino <= maxino; ino++)
Based on a bug fix from Havard Eidnes <Havard.Eidnes@runit.sintef.no> and
suggestion by Chris Torek <torek@horse.ee.lbl.gov>.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 20-Apr-1993  mycroft Don't overrun end of argv.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 22-Dec-1993  mycroft Clean up deleted files.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 20-Apr-1993  mycroft Don't dereference NULL pointer.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.37 15-Jun-2013  christos handle new lfs split
 1.36 13-Jan-2013  dholland Use <ctype.h> functions correctly.
 1.35 13-Jan-2013  dholland Add some const.
 1.34 29-Aug-2011  joerg branches: 1.34.2; 1.34.8;
Use __dead
 1.33 11-Apr-2009  lukem fix sign-compare issue
 1.32 18-Dec-2006  christos branches: 1.32.22;
Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.31 27-Jun-2005  christos sprinkle const
 1.30 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.29 25-Dec-2001  lukem Fixes from FreeBSD:
- Fix error if first tape was write protected. Fix NetBSD PRs 4754 and 6098.
- Make dump exit codes confirm to manual page.
- Use \a instead of \7 to make noise.
- Fix estimated number of tapes for huge dumps to cartridges.
- Use <sys/queue.h> SLIST_* instead of home-rolled lists.
- Do not exit if unable to read or create /etc/dumpdates.
- Support output (tape) device returning ENOSPC for end-of-media on a write.

Fixes by me:
- Remove unused ddates_in.
- Don't dump core if SIGINFO is received before 1 second has elapsed.
- Only process SIGINFO in current "active" child.
- Don't dump core in -w if dumpdates wasn't readable and ddatev == NULL
- Minor KNF; wrap some lines
 1.28 23-Dec-2001  lukem unifdef sunos
 1.27 14-Dec-2001  bouyer Add a -l (autoload) flag. For multivolume dumps, this makes dump eject the
tape when a volume is full, and try to reopen the tape drive for 2 mn.
To be used with tape changers which load the next tape when the current one is
ejected.
While I'm there fix eject handling for remote tape.
 1.26 01-Nov-2001  lukem fix -Wshadow warnings
 1.25 28-May-2001  lukem unifdef !__STDC__ (missed in previous)
 1.24 27-May-2001  lukem knf to ansi
 1.23 26-May-2001  lukem use strdup appropriately
 1.22 04-Feb-2001  christos fix redundant decls
 1.21 30-Jul-1998  thorpej branches: 1.21.10;
Turn on TCP_NODELAY on the remote tape socket, from FreeBSD. Here is the
commit message from Bill Fenner:

Turn on TCP_NODELAY on the remote socket, to turn off sender silly window
syndrome avoidance. The combination of SWS avoidance and ack-every-other
causes low throughput if the block size divided by the MSS is odd (which
is true with the default block size and MSS).
Turning on TCP_NODELAY disables the Nagle algorithm and sender SWS avoidance.
The rdump request/response protocol can not invoke Nagle and cannot cause
SWS, so this has no negative effects.

Also, put back the code that sets the TOS to "throughput", which seems to
have been erroneously removed during the Lite-2 merge.
 1.20 30-Mar-1998  mrg use <errno.h>
 1.19 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.18 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.17 05-Jun-1997  mrg fix PR#3710, reported by Tatoku Ogaito <tacha@trap.fukui-med.ac.jp>.
- don't pass pw->pw_name into functions; make a copy.
 1.16 05-Jun-1997  lukem * Add the ability to dump specific files & directories of a single
filesystem. This uses fts(3) to access the directory structure (and
not the raw device), so the standard access permissions are adhered
to (unlike dumping an entire filesystem, which just requires read
access to the raw disk device).
* Support SIGINFO status reporting.
* Remove now unused variables that previously stored the (e)uid.
* Be more informative in a couple of error messages.
 1.15 27-May-1997  mrg enable rcmd(). garbage collect.
 1.14 26-May-1997  mrg use orcmd() for now.
 1.13 21-Apr-1997  mrg be safe with buffers.
 1.12 15-Apr-1997  lukem remove use of "register".
 1.11 05-Nov-1996  thorpej - If rcmd() fails, don't do any of the setsockopt() calls.
- Since the TCP_MAXSEG setsockopt can only descrease the MSS, and never
increase it, do an IP_TOS:IPTOS_THROUGHPUT setsockopt instead, since
dump is a bulk transfer.
Submitted by Bill Fenner <fenner@parc.xerox.com>.
 1.10 15-Mar-1996  scottr Be more paranoid with our effective uid.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.7 23-Sep-1994  mycroft err(3)/warn(3) cleanup
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.10.2 16-Jan-2002  he Pull up revisions 1.28-1.29 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.21.10.1 16-Jan-2002  he Pull up revision 1.27 (via patch, requested by bouyer):
Implement ``-l <timeout>'' option for use with e.g. autochangers.
 1.32.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.34.8.2 23-Jun-2013  tls resync from head
 1.34.8.1 25-Feb-2013  tls resync with head
 1.34.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.34.2.1 23-Jan-2013  yamt sync with head
 1.5 22-Dec-1993  mycroft Clean up deleted files.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8 22-Dec-1993  mycroft Clean up deleted files.
 1.7 02-Dec-1993  mycroft Change the four inode loops to the form:
for (ino = 1; ino <= maxino; ino++)
Based on a bug fix from Havard Eidnes <Havard.Eidnes@runit.sintef.no> and
suggestion by Chris Torek <torek@horse.ee.lbl.gov>.
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 13-Jun-1993  mycroft Add support for fast symlinks.
 1.4 09-Apr-1993  cgd from patch 110, by bostic:
dump not mapping last inode in fs
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.24 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.23 01-Mar-2019  christos Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.22 23-Jun-2013  dholland branches: 1.22.20; 1.22.28;
fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.21 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.20 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.19 13-Jan-2013  dholland Use static; remove unused global var this uncovered.
 1.18 20-Jul-2008  lukem branches: 1.18.18; 1.18.24;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.17 18-Dec-2006  christos branches: 1.17.12; 1.17.16;
Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.16 27-Mar-2004  dsl Don't require ffsv2 fs have FS_FLAGS_UPDATED set
 1.15 24-Mar-2004  ws After determining whether the filesystem is byte swapped,
we better return that fact to the caller.
 1.14 21-Mar-2004  dsl When searching for the superblock, don't pick an ffsv1 superblock from the
location where we expect to find an ffsv2 superblock.
It could be the first alternate for a ffsv1 filesystem with 64k blocks.
Fixes part of PR kern/24809
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.12 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.11 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.10 23-Dec-2001  lukem unifdef sunos
 1.9 22-Dec-2001  lukem - use correct type for minTime in findlru() (size_t instead of int)
- clean up whitespace
 1.8 01-Nov-2001  lukem fix -Wshadow warnings
 1.7 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.6 14-Aug-2001  lukem s/filesystem/file system/dump.h
 1.5 28-May-2001  lukem unifdef !__STDC__ (missed in previous)
 1.4 27-May-2001  lukem knf to ansi
 1.3 01-Oct-1999  perseant branches: 1.3.4; 1.3.8;
Working version of aborted dump{,_lfs} join.
 1.2 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.1 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.3.8.3 17-Jan-2002  he Pull up revision 1.7 (requested by he):
Fix compile problem after last round of pullups.
The already-pulled-up 1.7 was inadvertently undone by the previous patch.
 1.3.8.2 16-Jan-2002  he Pull up revisions 1.9-1.10 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.3.8.1 25-Nov-2001  he Pull up revision 1.7 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.3.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.17.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.18.24.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.24.2 23-Jun-2013  tls resync from head
 1.18.24.1 25-Feb-2013  tls resync with head
 1.18.18.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.18.1 23-Jan-2013  yamt sync with head
 1.22.28.1 10-Jun-2019  christos Sync with HEAD
 1.22.20.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.22 25-Mar-2019  manu Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry

This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.
 1.21 01-Mar-2019  christos Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.20 15-Jun-2013  christos branches: 1.20.20; 1.20.28;
handle new lfs split
 1.19 13-Jan-2013  dholland Add some const.
 1.18 11-Mar-2010  christos branches: 1.18.6; 1.18.12;
PR/42952: The Grey Wolf: Fix for "true incremental". Don't overload level
9, use a new level "i" which is logically 10.
 1.17 26-Feb-2010  christos PR/42883: Greywolf: Add -i flag which brings "true incremental" capability.
 1.16 19-May-2006  christos Coverity CID 3275: Plug memory leak.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 16-Nov-2002  itojun use strlcpy. use sizeof() instead of xxLEN to avoid de-synchronization
 1.13 25-Dec-2001  lukem Fixes from FreeBSD:
- Fix error if first tape was write protected. Fix NetBSD PRs 4754 and 6098.
- Make dump exit codes confirm to manual page.
- Use \a instead of \7 to make noise.
- Fix estimated number of tapes for huge dumps to cartridges.
- Use <sys/queue.h> SLIST_* instead of home-rolled lists.
- Do not exit if unable to read or create /etc/dumpdates.
- Support output (tape) device returning ENOSPC for end-of-media on a write.

Fixes by me:
- Remove unused ddates_in.
- Don't dump core if SIGINFO is received before 1 second has elapsed.
- Only process SIGINFO in current "active" child.
- Don't dump core in -w if dumpdates wasn't readable and ddatev == NULL
- Minor KNF; wrap some lines
 1.12 23-Dec-2001  lukem unifdef sunos
 1.11 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.10 28-May-2001  lukem unifdef !__STDC__ (missed in previous)
 1.9 27-May-2001  lukem knf to ansi
 1.8 22-Apr-1998  bouyer branches: 1.8.10;
PR bin/5346 from haszlaki@UAccess.NET:
After parsing the entries from /etc/dumpdates, remember ou entrie, in order
to print the date after /etc/dumpdates has been rewritten.
 1.7 01-Apr-1998  kleink Need <time.h> for ctime() prototype.
 1.6 18-Mar-1998  bouyer Add support for non-native byte order FFS. The dump is in filesystem byte
order, restore already knows how to byteswap dumps.
 1.5 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.4 15-Apr-1997  lukem remove use of "register".
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 22-Dec-1993  cgd branches: 1.1.1;
new version from CSRG, via BSDI, with fixes
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.8.10.1 16-Jan-2002  he Pull up revisions 1.12-1.13 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.18.12.2 23-Jun-2013  tls resync from head
 1.18.12.1 25-Feb-2013  tls resync with head
 1.18.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.6.1 23-Jan-2013  yamt sync with head
 1.20.28.1 10-Jun-2019  christos Sync with HEAD
 1.20.20.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.79 04-Oct-2024  rillig dump: suppress lint warning about "effectively discards 'const'"
 1.78 03-Dec-2020  kre branches: 1.78.8;

PR bin/55834

count blocks written in unsigned 64 bit counter
rather than signed int which overflows after 2^31-1
blocks (2TiB) after which neither the 5 minute
status updates or SIGINFO (^T) reports are issued
until the negative numbers increase past 0 and
wildly inaccurate reports would be written.
 1.77 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.76 19-Aug-2019  perseant Add -D flag to allow the user to specify an alternate dumpdates file.
Closes PR #54469.
 1.75 25-Mar-2019  manu branches: 1.75.2;
Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry

This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.
 1.74 01-Mar-2019  christos Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.73 24-Aug-2015  bouyer branches: 1.73.8; 1.73.16;
Consistently use iswap64() and 64bit intermediate variable, as well as
64bit formats for c_tapea. Fixes tape useage report for large filesystems.
 1.72 24-Aug-2015  bouyer Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.71 08-Sep-2013  mlelstv branches: 1.71.4;
Fix handling of NAME aliases in /etc/fstab.
 1.70 15-Jun-2013  christos handle new lfs split
 1.69 07-Apr-2012  christos branches: 1.69.2;
factor out rawname() from dump, fsck, savecore.
 1.68 07-Apr-2012  christos use getfsspecname()
 1.67 19-Feb-2012  christos PR/45735: Bug Hunting: The dump(8) manpage, as well as the program's `usage'-line,
needs improvement
 1.66 11-Mar-2010  christos branches: 1.66.6; 1.66.8;
PR/42952: The Grey Wolf: Fix for "true incremental". Don't overload level
9, use a new level "i" which is logically 10.
 1.65 26-Feb-2010  christos PR/42883: Greywolf: Add -i flag which brings "true incremental" capability.
 1.64 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.63 26-Oct-2006  hannken branches: 1.63.18; 1.63.22;
When using a snapshot take the snapshot raw device on further open.

Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)

Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.62 24-Jun-2006  perseant Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.61 19-Apr-2006  hannken Emit "a snapshot of" message for snap_internal case too.
 1.60 18-Mar-2006  christos Coverity CID 2297: Fix memory leak.
 1.59 27-Jun-2005  christos sprinkle const
 1.58 19-Apr-2005  hannken Snapshot support for dump(8):

- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.

- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.

Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.57 21-Apr-2004  christos branches: 1.57.2;
Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.56 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.55 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.54 27-Mar-2003  lukem Use "wall -g operator" (instead of private code) to broadcast() messages to
members of the operator group.
Don't install "setgid tty", and remove now unnecessary gid/egid swapping.
Remove utmp trawling code pulled in from usr.bin/who.
The Code is now simpler, and more portable (without the utmp cruft) too.

This is derived from similar work in OpenBSD.
 1.53 17-Nov-2002  itojun should be safer to cast to u_long than to cast down to int
 1.52 17-Nov-2002  tsutsui Add a cast to sizeof in printf() arg since _BSD_SIZE_T is unsigned long
on some ports.
 1.51 16-Nov-2002  itojun use strlcpy. use sizeof() instead of xxLEN to avoid de-synchronization
 1.50 07-Jan-2002  bouyer For -l: specify the timeout on the command line (in seconds) instead of
hardwiring it to 2s, as suggested on tech-userlevel.
 1.49 30-Dec-2001  lukem Add -a to "auto-size" the tape, rather than relying upon other options
to define the tape size. Requires the tape driver to either return ENOSPC
at end of media, or 0 when a write is attempted (such as the "early warning"
support in st(4) enabled with "mt eew 1"). From FreeBSD.
 1.48 25-Dec-2001  lukem Fixes from FreeBSD:
- Fix error if first tape was write protected. Fix NetBSD PRs 4754 and 6098.
- Make dump exit codes confirm to manual page.
- Use \a instead of \7 to make noise.
- Fix estimated number of tapes for huge dumps to cartridges.
- Use <sys/queue.h> SLIST_* instead of home-rolled lists.
- Do not exit if unable to read or create /etc/dumpdates.
- Support output (tape) device returning ENOSPC for end-of-media on a write.

Fixes by me:
- Remove unused ddates_in.
- Don't dump core if SIGINFO is received before 1 second has elapsed.
- Only process SIGINFO in current "active" child.
- Don't dump core in -w if dumpdates wasn't readable and ddatev == NULL
- Minor KNF; wrap some lines
 1.47 23-Dec-2001  lukem clean up from time_t -> int32_t change in dumprestore.h
 1.46 23-Dec-2001  lukem unifdef sunos
 1.45 23-Dec-2001  lukem nuke trailing whitespace
 1.44 22-Dec-2001  lukem - use correct type for minTime in findlru() (size_t instead of int)
- clean up whitespace
 1.43 20-Dec-2001  soren Another little mistake, spotted by wiz.
 1.42 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.41 14-Dec-2001  bouyer Add a -l (autoload) flag. For multivolume dumps, this makes dump eject the
tape when a volume is full, and try to reopen the tape drive for 2 mn.
To be used with tape changers which load the next tape when the current one is
ejected.
While I'm there fix eject handling for remote tape.
 1.40 16-Nov-2001  lukem relax the restriction on -F that the file system image argument must be a
regular file
 1.39 15-Oct-2001  blymn Add the capability for dump to print timestamps on all informational
messages.
 1.38 14-Aug-2001  lukem - implement -F, which indicates that files-to-dump is a regular file
containing a file system image (instead of being a single file as
part of a subtree dump)
- use "file system" instead of "filesystem" or "file-system"
 1.37 08-Aug-2001  david Patch to drop setgid tty privs until forking for operator notification
 1.36 17-Jul-2001  mrg reset uid & gid around calling rmthost().
 1.35 16-Jul-2001  mrg display what signal, not "unknown"
 1.34 03-Jun-2001  hannken Assign a saved copy of dt->fs_file to mountpoint. dt->fs_file will be freed
otherwise resulting in a wrong spcl.c_filesys .
 1.33 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.32 27-May-2001  lukem more KNF
 1.31 27-May-2001  lukem knf to ansi
 1.30 12-May-2001  tron Add "e" option to usage message. Problem pointed out by Takahiro Kambe
in private e-mail.
 1.29 12-May-2001  tron Fix bug in new "e" option: only eject tape if it is full, not if the dump
was finished.
 1.28 07-May-2001  tron Add a new option "e" to "dump" which allows to eject tapes automatically
if a tape change is required.
 1.27 13-Dec-2000  scw Global variables don't need to be initialised to zero.
 1.26 11-Oct-2000  briggs Fix format warnings
 1.25 01-Oct-1999  perseant branches: 1.25.6;
Working version of aborted dump{,_lfs} join.
 1.24 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.23 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.22 23-Mar-1999  bouyer branches: 1.22.2; 1.22.4;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.21 03-Jan-1999  lukem add support for '-L label', which file(1) and restore(1) can extract from the
header. mostly based on [bin/6715] from Brian Grayson <bgrayson@ece.utexas.edu>

old filesystems don't have fs_qbmask and fs_qfmask set in the superblock;
fudge them as per code in /sys/ufs/ffs/ffs_vfsops.c::ffs_oldfscompat().
bug and suggested fix from Robert Elz <kre@munnari.OZ.AU> in [bin/6610]
XXX: there may be other variables required as well...
 1.20 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.19 06-Jul-1998  mrg - use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.18 18-Mar-1998  bouyer Add support for non-native byte order FFS. The dump is in filesystem byte
order, restore already knows how to byteswap dumps.
 1.17 18-Sep-1997  lukem Various changes from Brian Grayson <bgrayson@ece.utexas.edu> in [bin/4103]
* exit after providing an estimate if -S was given. the PR used -e,
but checking around indicated prior art in Solaris usin -S.
* remove superfluous 'DUMP:' prefix in two messages
* initialise blocksperfile explicitly (not necessary, but everything
else in that section gets initialised, so be consistant :)
* display the ``pretty'' name of the dumped directory, so the user
knows if it's a subset or not
 1.16 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.15 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.14 05-Jun-1997  lukem * Add the ability to dump specific files & directories of a single
filesystem. This uses fts(3) to access the directory structure (and
not the raw device), so the standard access permissions are adhered
to (unlike dumping an entire filesystem, which just requires read
access to the raw disk device).
* Support SIGINFO status reporting.
* Remove now unused variables that previously stored the (e)uid.
* Be more informative in a couple of error messages.
 1.13 27-May-1997  mrg enable rcmd(). garbage collect.
 1.12 21-Apr-1997  mrg be safe with buffers.
 1.11 15-Apr-1997  lukem remove use of "register".
 1.10 10-Apr-1997  lukem Implement changes from [bin/1915]
* 'w' and 'W' display the year
* verbosity additions displaying total & per-volume transfer times and rates
 1.9 27-Feb-1997  mikel set bflag so that 'dump bd M N' works properly. fix from Juergen
Hannken-Illjes in PR bin/3254.
 1.8 15-Mar-1996  scottr Be more paranoid with our effective uid.
 1.7 05-Feb-1996  mrg support $TAPE. update manual to reflect reality (#1937).
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 20-Feb-1995  mycroft Use getopt(3), with obsolete() from restore(8) for backward compatibility.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.2 28-Mar-1994  cgd don't segv if called with no options!
 1.1 22-Dec-1993  cgd branches: 1.1.1;
new version from CSRG, via BSDI, with fixes
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.22.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.22.2.1 11-Oct-2000  he Pull up revision 1.26 (requested by he):
Format string cleanup.
 1.25.6.8 28-Mar-2002  he Pull up revisions 1.33-1.34 (via patch, requested by bouyer):
Improve behaviour when a path is given:
1) check if the path is an unmounted file system listed in fstab
2) check if it is a path to a mounted file system not listed in fstab
Fixes PR#15790.
 1.25.6.7 16-Jan-2002  he Pull up revision 1.49 (via patch, requested by bouyer):
Add an ``-a'' option to ``auto-size'' the tape, rather than
relying upon other options to define the tape size.
 1.25.6.6 16-Jan-2002  he Pull up revisions 1.46-1.48 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.25.6.5 16-Jan-2002  he Pull up revisions 1.41,1.50 (via patch, requested by bouyer):
Implement ``-l <timeout>'' option for use with e.g. autochangers.
 1.25.6.4 08-Aug-2001  jhawk Pull up revision 1.37 via patch (requested by david):
Temporarily drop setgid (for setgid tty) privileges, but restore them
if we fork to perform an operator notification. Generalize pre-existing
#ifdef RDUMP code.
 1.25.6.3 15-May-2001  he Pull up revision 1.29 (requested by tron):
Fix bug in new ``e'' option: only eject tape if it is full, not
if the dump was finished.
 1.25.6.2 09-May-2001  he Pull up revision 1.28 (requested by tron):
Add a new option ``e'' to dump which directs it to eject tapes
automatically if a tape change is required.
 1.25.6.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.57.2.3 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.57.2.2 21-Apr-2006  tron branches: 1.57.2.2.2;
Pull up following revision(s) (requested by hannken in ticket #1283):
sbin/dump/main.c: revision 1.61
Emit "a snapshot of" message for snap_internal case too.
 1.57.2.1 21-Apr-2005  tron branches: 1.57.2.1.2;
Pull up revision 1.58 (requested by hannken in ticket #184):
Snapshot support for dump(8):
- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.
- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.
Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.57.2.2.2.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.57.2.1.2.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.63.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.63.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.66.8.2 08-Mar-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1332):
sbin/dump/main.c: revision 1.73
sbin/dump/tape.c: revision 1.54
Consistently use iswap64() and 64bit intermediate variable, as well as
64bit formats for c_tapea. Fixes tape useage report for large filesystems.
 1.66.8.1 08-Mar-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1331):
sbin/dump/dump.8: revision 1.67 via patch
sbin/dump/main.c: revision 1.72
sbin/dump/rcache.c: revision 1.25
Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.66.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.66.6.1 17-Apr-2012  yamt sync with head
 1.69.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.69.2.1 23-Jun-2013  tls resync from head
 1.71.4.2 06-Nov-2015  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/dump/tape.c: revision 1.54
sbin/dump/main.c: revision 1.73
Consistently use iswap64() and 64bit intermediate variable, as well as
64bit formats for c_tapea. Fixes tape useage report for large filesystems.
 1.71.4.1 06-Nov-2015  riz Pull up following revision(s) (requested by bouyer in ticket #990):
sbin/dump/rcache.c: revision 1.25
sbin/dump/dump.8: revision 1.67
sbin/dump/main.c: revision 1.72
Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.73.16.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.73.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.73.16.1 10-Jun-2019  christos Sync with HEAD
 1.73.8.2 07-Dec-2020  martin Pull up following revision(s) (requested by kre in ticket #1630):

sbin/dump/dump.h: revision 1.59
sbin/dump/main.c: revision 1.78

PR bin/55834

count blocks written in unsigned 64 bit counter
rather than signed int which overflows after 2^31-1
blocks (2TiB) after which neither the 5 minute
status updates or SIGINFO (^T) reports are issued
until the negative numbers increase past 0 and
wildly inaccurate reports would be written.
 1.73.8.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.75.2.1 06-Dec-2020  martin Pull up following revision(s) (requested by kre in ticket #1139):

sbin/dump/dump.h: revision 1.59
sbin/dump/main.c: revision 1.78

PR bin/55834

count blocks written in unsigned 64 bit counter
rather than signed int which overflows after 2^31-1
blocks (2TiB) after which neither the 5 minute
status updates or SIGINFO (^T) reports are issued
until the negative numbers increase past 0 and
wildly inaccurate reports would be written.
 1.78.8.1 02-Aug-2025  perseant Sync with HEAD
 1.44 14-Mar-2022  mlelstv Silently ignore fstab entries with NAME= entries that cannot be resolved.
Fixes PR 56249.
 1.43 01-Mar-2019  christos branches: 1.43.2;
Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.42 08-Sep-2013  mlelstv branches: 1.42.18; 1.42.26;
Fix handling of NAME aliases in /etc/fstab.
 1.41 15-Jun-2013  christos handle new lfs split
 1.40 13-Jan-2013  dholland Use more static.
 1.39 13-Jan-2013  dholland Add some const.
 1.38 07-Apr-2012  christos branches: 1.38.2;
factor out rawname() from dump, fsck, savecore.
 1.37 07-Apr-2012  christos use getfsspecname()
 1.36 18-Dec-2006  christos branches: 1.36.36;
Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.35 24-Jun-2006  perseant Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.34 27-Jun-2005  christos sprinkle const
 1.33 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.32 15-Mar-2004  lukem Adjust tstart_volume (volume start time) by the time spent in query(),
similar to the adjustment for tstart_writing made in optr.c rev 1.4.
Should fix PR bin/19711 from matthew green.
 1.31 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.30 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.29 27-Mar-2003  lukem Use "wall -g operator" (instead of private code) to broadcast() messages to
members of the operator group.
Don't install "setgid tty", and remove now unnecessary gid/egid swapping.
Remove utmp trawling code pulled in from usr.bin/who.
The Code is now simpler, and more portable (without the utmp cruft) too.

This is derived from similar work in OpenBSD.
 1.28 18-Aug-2002  yamt save/restore errno in signal handlers.
 1.27 16-Aug-2002  itojun defend against malicious line in ut_line, which could cause unwanted
writes to anything under /dev. revoke setuid/gid privs earlier.
From: xs@kittenz.org
 1.26 02-Aug-2002  christos support utmpx
 1.25 25-Dec-2001  lukem Fixes from FreeBSD:
- Fix error if first tape was write protected. Fix NetBSD PRs 4754 and 6098.
- Make dump exit codes confirm to manual page.
- Use \a instead of \7 to make noise.
- Fix estimated number of tapes for huge dumps to cartridges.
- Use <sys/queue.h> SLIST_* instead of home-rolled lists.
- Do not exit if unable to read or create /etc/dumpdates.
- Support output (tape) device returning ENOSPC for end-of-media on a write.

Fixes by me:
- Remove unused ddates_in.
- Don't dump core if SIGINFO is received before 1 second has elapsed.
- Only process SIGINFO in current "active" child.
- Don't dump core in -w if dumpdates wasn't readable and ddatev == NULL
- Minor KNF; wrap some lines
 1.24 24-Dec-2001  lukem For dump_lfs(8), in getfstab(), only "lfs" (instead of "ufs" or "ffs").
Fix from Minoura Makoto in [bin/10525].
 1.23 23-Dec-2001  lukem nuke trailing whitespace
 1.22 22-Dec-2001  lukem - use correct type for minTime in findlru() (size_t instead of int)
- clean up whitespace
 1.21 01-Nov-2001  lukem fix -Wshadow warnings
 1.20 25-Oct-2001  lukem in msg(), don't call va_list using functions twice in a row without calling
va_start() in between; reorder code so that we call vsnprintf and then
just fputs that buffer. crank the size of lastmsg whilst we're here
problem noted by Hideo Saito in [bin/14348].
 1.19 15-Oct-2001  blymn Add the capability for dump to print timestamps on all informational
messages.
 1.18 08-Aug-2001  david Patch to drop setgid tty privs until forking for operator notification
 1.17 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.16 28-May-2001  lukem unifdef !__STDC__ (missed in previous)
 1.15 27-May-2001  lukem knf to ansi
 1.14 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.13 01-Apr-1998  kleink branches: 1.13.2; 1.13.10;
Need <time.h> for time(), localtime() and ctime() prototypes.
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.11 27-May-1997  mrg fix off by one bug.
 1.10 21-Apr-1997  thorpej Don't need to account for space for NUL, as it's included in the
sizeof(_PATH_DEV), noted by Chris Demetriou <cgd@netbsd.org>
 1.9 21-Apr-1997  thorpej Add missing `-', noted by Erik Fair <fair@cesium.clock.org> on
current-users.
 1.8 21-Apr-1997  mrg be safe with buffers.
 1.7 15-Apr-1997  lukem remove use of "register".
 1.6 10-Apr-1997  lukem Implement changes from [bin/1915]
* 'w' and 'W' display the year
* verbosity additions displaying total & per-volume transfer times and rates
 1.5 16-Jan-1997  perry fix pr 2977 -- only try to dump ufs/ffs partitions
 1.4 18-May-1996  jtk Adjust the base for time estimates to ignore time we spent waiting
for operator input.
enhancements from PR #900
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 22-Dec-1993  cgd branches: 1.1.1;
new version from CSRG, via BSDI, with fixes
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.13.10.4 28-Mar-2002  he Pull up revision 1.17 (via patch, requested by bouyer):
Improve behaviour when a path is given:
1) check if the path is an unmounted file system listed in fstab
2) check if it is a path to a mounted file system not listed in fstab
Fixes PR#15790.
 1.13.10.3 16-Jan-2002  he Pull up revision 1.25 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.13.10.2 08-Aug-2001  jhawk Pull up revision 1.18 via patch (requested by david):
Temporarily drop setgid (for setgid tty) privileges, but restore them
if we fork to perform an operator notification. Generalize pre-existing
#ifdef RDUMP code.
 1.13.10.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.13.2.1 10-Oct-2000  he Pull up revision 1.14 (requested by is):
Format string cleanup.
 1.36.36.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.36.2 23-Jan-2013  yamt sync with head
 1.36.36.1 17-Apr-2012  yamt sync with head
 1.38.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.2.2 23-Jun-2013  tls resync from head
 1.38.2.1 25-Feb-2013  tls resync with head
 1.42.26.1 10-Jun-2019  christos Sync with HEAD
 1.42.18.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.43.2.1 21-Aug-2023  martin Pull up following revision(s) (requested by manu in ticket #1717):

sbin/dump/optr.c: revision 1.44

Silently ignore fstab entries with NAME= entries that cannot be resolved.

Fixes PR 56249.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 27-Mar-2003  lukem Use "wall -g operator" (instead of private code) to broadcast() messages to
members of the operator group.
Don't install "setgid tty", and remove now unnecessary gid/egid swapping.
Remove utmp trawling code pulled in from usr.bin/who.
The Code is now simpler, and more portable (without the utmp cruft) too.

This is derived from similar work in OpenBSD.
 1.9 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h>
change doco references/examples from /dev/rmt* to /dev/rst*
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 20-Jan-1995  mycroft Use /etc/rmt explicitly.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25 24-Aug-2015  bouyer Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.24 15-Jun-2013  christos branches: 1.24.6;
handle new lfs split
 1.23 27-Jan-2010  spz branches: 1.23.6; 1.23.8; 1.23.12;
range-check what we assign to int cachebufs from calculations with
uint64_t usermem. This only becomes relevant if you have several TB of RAM.
Promoting cachebufs to uint64_t is not necessary as it gets limited to
(currently) 512 anyway.

fixes the last issue of PR: 19852
 1.22 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.21 13-Sep-2003  simonb branches: 1.21.32; 1.21.34;
Use HW_USERMEM64 to fetch the amount of memory available.
 1.20 19-Apr-2003  tls The sysctl returning the amount of memory in the system returns "int",
which is silly. Luckily, it really does return the correct result if
interpreted as an unsigned int. This change lets dump work on 32-bit
systems that have more than 2GB of RAM.
 1.19 06-Feb-2003  enami No need to print same error message twice in the same line.
 1.18 06-Feb-2003  enami Check lseek error correctly (i.e., use == -1 rather than < 0).
 1.17 04-Feb-2003  enami Fix typo I've introduced while cleaning up for commit.
 1.16 04-Feb-2003  enami - Fix daddr_t print format inside ifdef DIAGNOSTIC.
- Start scan cache entry just filled, rather than starting from top.
 1.15 04-Feb-2003  enami Convert `nblksread' to in terms of device block size. This restores
originally intended behaviour (see tech-userlevel archive around 1999 March).
 1.14 04-Feb-2003  enami Cosmetic changes.
 1.13 03-Feb-2003  hannken Merge "struct cheader" and "struct cdesc" into an union.
No more alignment problems if the alignment of these two differs.

Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.12 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.11 19-Feb-2002  lukem branches: 1.11.2;
rcsid
 1.10 23-Dec-2001  lukem nuke trailing whitespace
 1.9 22-Dec-2001  lukem When using the read cache in bread(), ensure that the current (sub)block
isn't past the end of the file system.

Should fix the "spins forever but doing nothing" bug that dump
would occasionally have.
 1.8 22-Dec-2001  lukem - use correct type for minTime in findlru() (size_t instead of int)
- clean up whitespace
 1.7 22-Dec-2001  lukem In rawread(), add back a check to ensure that dump doesn't try to read
past EOM and fail with "short read error". This check was part of
traverse.c::bread(), and was removed when that function was migrated
to rcache.c::rawread() as part of the "read cache" functionality.

This should fix the problem with dump barfing on "short read" when "-r 0",
but I'm still debugging the problem where dump gets to a point and
"does nothing" when the read cache is being used.
 1.6 27-May-2001  lukem knf to ansi
 1.5 11-Oct-2000  briggs Fix format warnings
 1.4 01-Oct-1999  perseant branches: 1.4.6;
Working version of aborted dump{,_lfs} join.
 1.3 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.2 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.1 23-Mar-1999  bouyer branches: 1.1.2; 1.1.4;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.1.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.1.2.1 11-Oct-2000  he Pull up revision 1.5 (requested by he):
Format string cleanup.
 1.4.6.2 16-Jan-2002  he Pull up revisions 1.7-1.10 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.4.6.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.11.2.1 16-Jun-2003  grant Pull up revision 1.20 (requested by rafal in ticket #1272):

The sysctl returning the amount of memory in the system returns "int",
which is silly. Luckily, it really does return the correct result if
interpreted as an unsigned int. This change lets dump work on 32-bit
systems that have more than 2GB of RAM.
 1.21.34.1 18-May-2008  yamt sync with head.
 1.21.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.23.12.1 23-Jun-2013  tls resync from head
 1.23.8.1 08-Mar-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1331):
sbin/dump/dump.8: revision 1.67 via patch
sbin/dump/main.c: revision 1.72
sbin/dump/rcache.c: revision 1.25
Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.23.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.6.1 06-Nov-2015  riz Pull up following revision(s) (requested by bouyer in ticket #990):
sbin/dump/rcache.c: revision 1.25
sbin/dump/dump.8: revision 1.67
sbin/dump/main.c: revision 1.72
Default the read block size (-k default value) to kern.maxphys (usually
64k these days). This gives a noticable performance boost on large filesystems.
 1.5 01-Mar-1995  mycroft Clean up deleted files.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7 03-Feb-2019  mrg - mark Exit() __dead
- bump a buffer size to avoid possible truncation
- adding missing fallthru comment
 1.6 24-Feb-2011  hannken branches: 1.6.44;
fss(4): Allow FSSIOCSET to set the initial flags. Add a new flag
"FSS_UNLINK_ON_CREATE" to unlink the backing store before
the snapshot gets created.

With this change dump(8) no longer dumps the zero-sized, but named
snapshot it is working on. Same applies to fsck_ffs(8).
 1.5 11-Apr-2010  hannken branches: 1.5.2;
Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.

While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.4 28-Apr-2008  martin branches: 1.4.4;
Remove clause 3 and 4 from TNF licenses
 1.3 26-Oct-2006  hannken branches: 1.3.18; 1.3.20;
When using a snapshot take the snapshot raw device on further open.

Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)

Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2 19-Apr-2005  hannken branches: 1.2.2;
Fix copyright date for previous.
 1.1 19-Apr-2005  hannken Snapshot support for dump(8):

- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.

- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.

Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.4 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.3 21-Apr-2005  tron branches: 1.2.2.3.2; 1.2.2.3.4;
Pull up revision 1.2 (requested by hannken in ticket #184):
Fix copyright date for previous.
 1.2.2.2 21-Apr-2005  tron Pull up revision 1.1 (requested by hannken in ticket #184):
Snapshot support for dump(8):
- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.
- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.
Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.1 19-Apr-2005  tron file snapshot.c was added on branch netbsd-3 on 2005-04-21 19:04:41 +0000
 1.2.2.3.4.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.3.2.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.3.20.1 18-May-2008  yamt sync with head.
 1.3.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.4.1 18-Jun-2011  bouyer Pull up following revision(s) (requested by hannken in ticket #1627):
sys/kern/vfs_wapbl.c: revisions 1.41-1.42
sbin/dump/snapshot.c: revisions 1.6 (patch)
share/man/man4/fss.4: revisions 1.15 (patch)
sys/dev/fss.c: revisions 1.73 (patch)
sys/dev/fssvar.h: revisions 1.25
usr.sbin/fssconfig/fssconfig.c: revisions 1.7
sys/ufs/ffs/ffs_balloc.c: revisions 1.54
sys/ufs/ffs/ffs_snapshot.c: revisions 1.90, 1.98, 1.100-1.101, 1.103-1.110, 1.111, 1.112-1.115 (patch)

- Try to keep snapshot indirect blocks contiguous. This speeds up snapshot
creation by a factor of ~3 and reduces the file system suspension time by
a factor of ~5.

- Refine the scope of WAPBL transactions and the limit for deallocations in
one transaction so we should no longer get a "wapbl_flush: current
transaction too big to flush" panic when creating or removing snapshots
on larger logging disks.

- fss(4): Allow FSSIOCSET to set the initial flags. Add a new flag
"FSS_UNLINK_ON_CREATE" to unlink the backing store before the snapshot
gets created. With this change dump(8) no longer dumps the zero-sized,
but named snapshot it is working on.
 1.5.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.6.44.1 10-Jun-2019  christos Sync with HEAD
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 26-Oct-2006  hannken branches: 1.3.18; 1.3.20;
When using a snapshot take the snapshot raw device on further open.

Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)

Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2 19-Apr-2005  hannken branches: 1.2.2;
Fix copyright date for previous.
 1.1 19-Apr-2005  hannken Snapshot support for dump(8):

- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.

- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.

Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.4 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.3 21-Apr-2005  tron branches: 1.2.2.3.2; 1.2.2.3.4;
Pull up revision 1.2 (requested by hannken in ticket #184):
Fix copyright date for previous.
 1.2.2.2 21-Apr-2005  tron Pull up revision 1.1 (requested by hannken in ticket #184):
Snapshot support for dump(8):
- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.
- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.
Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.1 19-Apr-2005  tron file snapshot.h was added on branch netbsd-3 on 2005-04-21 19:04:41 +0000
 1.2.2.3.4.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.2.2.3.2.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.3.20.1 18-May-2008  yamt sync with head.
 1.3.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.57 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.56 07-Jun-2021  hannken Bitmaps (TS_BITS and TS_CLRI) dont use the "c_addr" array as they
cannot have holes. As bitmaps are written without TS_ADDR records
"c_count" may be larger than the "c_addr" size resulting in a
segmentation violation reading "c_addr" beyond its end.

Compute "blks" for TS_INODE and TS_ADDR only -- its used for multi
volume dumps and the bitmaps must both be on the first volume.
 1.55 01-Mar-2019  christos branches: 1.55.2;
Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.54 24-Aug-2015  bouyer branches: 1.54.8; 1.54.16;
Consistently use iswap64() and 64bit intermediate variable, as well as
64bit formats for c_tapea. Fixes tape useage report for large filesystems.
 1.53 15-Jun-2013  christos branches: 1.53.6;
handle new lfs split
 1.52 13-Jan-2013  dholland Use void * for I/O functions and remove no-longer-needed casts.
 1.51 13-Jan-2013  dholland Add some const.
 1.50 16-Sep-2011  plunky branches: 1.50.2; 1.50.4; 1.50.8;
NULL does not need a cast, here
 1.49 16-Feb-2008  matt Fix some inconsisent/conflicting definitions and missing parameters
 1.48 18-Dec-2006  christos branches: 1.48.4; 1.48.6;
Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.47 26-Oct-2006  hannken When using a snapshot take the snapshot raw device on further open.

Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)

Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.46 24-Jun-2006  perseant Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.45 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.44 08-Aug-2004  lukem branches: 1.44.2; 1.44.4; 1.44.6;
Signal handlers should manipulate 'volatile sig_atomic_t' instead of 'int'.
 1.43 15-Mar-2004  lukem Adjust tstart_volume (volume start time) by the time spent in query(),
similar to the adjustment for tstart_writing made in optr.c rev 1.4.
Should fix PR bin/19711 from matthew green.
 1.42 18-Feb-2004  hannken Avoid signal race condition. If a slave gets the SIGUSR2 signal between
the "setjmp" and the "ready = 1" statements the slave will pause forever
and the complet dump hangs.

Fixes PR #24453
 1.41 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.40 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.39 16-Jan-2003  kleink Rename `sigset' locals to avoid symbol shadowing warning.
 1.38 18-Aug-2002  yamt save/restore errno in signal handlers.
 1.37 07-Jan-2002  bouyer For -l: specify the timeout on the command line (in seconds) instead of
hardwiring it to 2s, as suggested on tech-userlevel.
 1.36 30-Dec-2001  lukem Add -a to "auto-size" the tape, rather than relying upon other options
to define the tape size. Requires the tape driver to either return ENOSPC
at end of media, or 0 when a write is attempted (such as the "early warning"
support in st(4) enabled with "mt eew 1"). From FreeBSD.
 1.35 25-Dec-2001  lukem Fixes from FreeBSD:
- Fix error if first tape was write protected. Fix NetBSD PRs 4754 and 6098.
- Make dump exit codes confirm to manual page.
- Use \a instead of \7 to make noise.
- Fix estimated number of tapes for huge dumps to cartridges.
- Use <sys/queue.h> SLIST_* instead of home-rolled lists.
- Do not exit if unable to read or create /etc/dumpdates.
- Support output (tape) device returning ENOSPC for end-of-media on a write.

Fixes by me:
- Remove unused ddates_in.
- Don't dump core if SIGINFO is received before 1 second has elapsed.
- Only process SIGINFO in current "active" child.
- Don't dump core in -w if dumpdates wasn't readable and ddatev == NULL
- Minor KNF; wrap some lines
 1.34 23-Dec-2001  lukem unifdef sunos
 1.33 23-Dec-2001  lukem nuke trailing whitespace
 1.32 22-Dec-2001  lukem - use correct type for minTime in findlru() (size_t instead of int)
- clean up whitespace
 1.31 14-Dec-2001  bouyer Add a -l (autoload) flag. For multivolume dumps, this makes dump eject the
tape when a volume is full, and try to reopen the tape drive for 2 mn.
To be used with tape changers which load the next tape when the current one is
ejected.
While I'm there fix eject handling for remote tape.
 1.30 01-Nov-2001  lukem fix -Wshadow warnings
 1.29 14-Aug-2001  lukem s/filesystem/file system/dump.h
 1.28 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.27 28-May-2001  lukem unifdef !__STDC__ (missed in previous)
 1.26 27-May-2001  lukem knf to ansi
 1.25 12-May-2001  tron Fix bug in new "e" option: only eject tape if it is full, not if the dump
was finished.
 1.24 07-May-2001  tron Add a new option "e" to "dump" which allows to eject tapes automatically
if a tape change is required.
 1.23 11-Oct-2000  he Better fix for format warnings.
The type of time_t varies between ports, so we need to cast
before printing. It appears to be sufficient and safe to use (int).
 1.22 11-Oct-2000  briggs Fix format warnings
 1.21 01-Oct-1999  perseant branches: 1.21.6;
Working version of aborted dump{,_lfs} join.
 1.20 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.19 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.18 23-Mar-1999  bouyer branches: 1.18.2; 1.18.4;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.17 18-Jul-1998  lukem use AF_LOCAL instead of AF_UNIX
 1.16 18-Mar-1998  bouyer Add support for non-native byte order FFS. The dump is in filesystem byte
order, restore already knows how to byteswap dumps.
 1.15 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.14 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.13 15-Sep-1997  lukem remove __dead
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.11 05-Jun-1997  lukem * Add the ability to dump specific files & directories of a single
filesystem. This uses fts(3) to access the directory structure (and
not the raw device), so the standard access permissions are adhered
to (unlike dumping an entire filesystem, which just requires read
access to the raw disk device).
* Support SIGINFO status reporting.
* Remove now unused variables that previously stored the (e)uid.
* Be more informative in a couple of error messages.
 1.10 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h>
change doco references/examples from /dev/rmt* to /dev/rst*
 1.9 15-Apr-1997  lukem remove use of "register".
 1.8 10-Apr-1997  lukem Implement changes from [bin/1915]
* 'w' and 'W' display the year
* verbosity additions displaying total & per-volume transfer times and rates
 1.7 21-Mar-1995  mycroft Use POSIX signals.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 31-Oct-1994  cgd correct return values.
 1.4 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.3 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.2 09-Mar-1994  cgd light clean, and don't forget to close remote tape when aborting.
Inspired by Andreas Schulz.
 1.1 22-Dec-1993  cgd branches: 1.1.1;
new version from CSRG, via BSDI, with fixes
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.18.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.2.2 11-Oct-2000  he Pull up revision 1.23 (requested by he):
Format string cleanup.
 1.18.2.1 11-Oct-2000  he Pull up revision 1.22 (requested by he):
Format string cleanup.
 1.21.6.6 16-Jan-2002  he Pull up revision 1.36 (via patch, requested by bouyer):
Add an ``-a'' option to ``auto-size'' the tape, rather than
relying upon other options to define the tape size.
 1.21.6.5 16-Jan-2002  he Pull up revisions 1.32-1.35 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.21.6.4 16-Jan-2002  he Pull up revisions 1.31,1.37 (requested by bouyer):
Implement ``-l <timeout>'' option for use with e.g. autochangers.
 1.21.6.3 15-May-2001  he Pull up revision 1.25 (requested by tron):
Fix bug in new ``e'' option: only eject tape if it is full, not
if the dump was finished.
 1.21.6.2 09-May-2001  he Pull up revision 1.24 (requested by tron):
Add a new option ``e'' to dump which directs it to eject tapes
automatically if a tape change is required.
 1.21.6.1 17-Oct-2000  tv Pullup 1.22 [releng] and 1.23 [he]:
Fix format warnings.
The type of time_t varies between ports, so we need to cast
before printing. It appears to be sufficient and safe to use (int).
 1.44.6.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.44.4.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.44.2.1 11-Nov-2006  bouyer Pull up following revision(s) (requested by hannken in ticket #1573):
sbin/dump/snapshot.h: revision 1.3 via patch
sbin/dump/snapshot.c: revision 1.3 via patch
sbin/dump/main.c: revision 1.63 via patch
sbin/dump/tape.c: revision 1.47 via patch
sbin/dump/dump.h: revision 1.44 via patch
When using a snapshot take the snapshot raw device on further open.
Fixes PR #34923 dump(8) only dumps a corefile with -X (snapshots)
Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.48.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.48.4.1 23-Mar-2008  matt sync with HEAD
 1.50.8.2 23-Jun-2013  tls resync from head
 1.50.8.1 25-Feb-2013  tls resync with head
 1.50.4.1 08-Mar-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1332):
sbin/dump/main.c: revision 1.73
sbin/dump/tape.c: revision 1.54
Consistently use iswap64() and 64bit intermediate variable, as well as
64bit formats for c_tapea. Fixes tape useage report for large filesystems.
 1.50.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.50.2.1 23-Jan-2013  yamt sync with head
 1.53.6.1 06-Nov-2015  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/dump/tape.c: revision 1.54
sbin/dump/main.c: revision 1.73
Consistently use iswap64() and 64bit intermediate variable, as well as
64bit formats for c_tapea. Fixes tape useage report for large filesystems.
 1.54.16.1 10-Jun-2019  christos Sync with HEAD
 1.54.8.2 08-Jun-2021  martin Pull up following revision(s) (requested by hannken in ticket #1683):

sbin/dump/tape.c: revision 1.56

Bitmaps (TS_BITS and TS_CLRI) dont use the "c_addr" array as they
cannot have holes. As bitmaps are written without TS_ADDR records
"c_count" may be larger than the "c_addr" size resulting in a
segmentation violation reading "c_addr" beyond its end.

Compute "blks" for TS_INODE and TS_ADDR only -- its used for multi
volume dumps and the bitmaps must both be on the first volume.
 1.54.8.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.55.2.1 08-Jun-2021  martin Pull up following revision(s) (requested by hannken in ticket #1283):

sbin/dump/tape.c: revision 1.56

Bitmaps (TS_BITS and TS_CLRI) dont use the "c_addr" array as they
cannot have holes. As bitmaps are written without TS_ADDR records
"c_count" may be larger than the "c_addr" size resulting in a
segmentation violation reading "c_addr" beyond its end.

Compute "blks" for TS_INODE and TS_ADDR only -- its used for multi
volume dumps and the bitmaps must both be on the first volume.
 1.56 07-Aug-2023  mrg fix always true conditional by removing the address-of operator.

found by GCC 12.
 1.55 26-Jan-2022  christos PR/56643: Paul Goyette: Disable the last block adjustment for now. It seems
to break restore.
 1.54 07-Jul-2021  christos PR/56270: Matthias Scheler: dump fails on ffsv1: Zero c_extsize since ffsv1
does not support extended attributes.
 1.53 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.52 01-Mar-2019  christos Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.
 1.51 03-Feb-2019  mrg - mark Exit() __dead
- bump a buffer size to avoid possible truncation
- adding missing fallthru comment
 1.50 15-Jun-2013  christos branches: 1.50.20; 1.50.28;
handle new lfs split
 1.49 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.48 12-Aug-2008  simonb branches: 1.48.18; 1.48.24;
We don't need to dump WAPBL log files - don't dump files with SF_LOG
flag set, and document this.
 1.47 24-Jun-2006  perseant branches: 1.47.20; 1.47.24;
Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.46 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.45 19-Aug-2005  christos 64 bit inode changes
 1.44 25-May-2004  hannken Add ffs internal snapshots. Written by Marshall Kirk McKusick for FreeBSD.

- Not enabled by default. Needs kernel option FFS_SNAPSHOT.
- Change parameters of ffs_blkfree.
- Let the copy-on-write functions return an error so spec_strategy
may fail if the copy-on-write fails.
- Change genfs_*lock*() to use vp->v_vnlock instead of &vp->v_lock.
- Add flag B_METAONLY to VOP_BALLOC to return indirect block buffer.
- Add a function ffs_checkfreefile needed for snapshot creation.
- Add special handling of snapshot files:
Snapshots may not be opened for writing and the attributes are read-only.
Use the mtime as the time this snapshot was taken.
Deny mtime updates for snapshot files.
- Add function transferlockers to transfer any waiting processes from
one lock to another.
- Add vfsop VFS_SNAPSHOT to take a snapshot and make it accessible through
a vnode.
- Add snapshot support to ls, fsck_ffs and dump.

Welcome to 2.0F.

Approved by: Jason R. Thorpe <thorpej@netbsd.org>
 1.43 24-Mar-2004  hannken Make the computation of estimated blocks work for frag size != 1024.
 1.42 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.41 01-May-2003  fvdl Fix byteswapping issues in dirindir(); mostly from Enami Tsugutomo.
 1.40 01-May-2003  fvdl Swap the right disk block in mapdirs() for the UFS1 case. From Enami.
 1.39 08-Apr-2003  fvdl Since the size passed in may be different from the fs blocksize, just
allocate a buffer each time instead of using a static one.
 1.38 08-Apr-2003  fvdl dblk should be static. Fixes PR 21020, by Geoff Wing. Patch supplied
by him.
 1.37 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.36 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.35 30-Sep-2002  lukem Add fix from FreeBSD traverse.c 1.16:
Files in subdirectories of directories that have the nodump flag set
are sometimes incorrectly being dumped.

The problem arises because the subdirectory only gets its entry
cleared from usedinomap if it is also present in dumpinomap, and it is
the absence of a directory in usedinomap that internally indicates
that the directory is under the effects of UF_NODUMP (either directly
or inherited).

FreeBSD PR: 32414
Submitted by: David C Lawrence <tale@dd.org>
 1.34 23-Dec-2001  lukem unifdef sunos
 1.33 01-Nov-2001  lukem fix -Wshadow warnings
 1.32 14-Aug-2001  lukem s/filesystem/file system/dump.h
 1.31 28-May-2001  lukem * improve parsing of file-systems-to-dump when a path is given:
- if it's a path to an unmounted file-system listed in /etc/fstab, use
that instead of assuming the user wanted a subtree dump of the parent
directory. this restores the behaviour of dump before the subtree
dumping code went in.
- if it's a path to a mounted file-system which is not in /etc/fstab,
use the info from getmntinfo(3). previously, dump would choke.
* implement error checked malloc(), calloc(), strdup(), and use
appropriately (some of the calloc()s weren't being checked)
* use 'file-system' instead of 'filesystem' in the man page
 1.30 28-May-2001  lukem unifdef !__STDC__ (missed in previous)
 1.29 27-May-2001  lukem knf to ansi
 1.28 01-Oct-1999  perseant branches: 1.28.6;
Working version of aborted dump{,_lfs} join.
 1.27 30-Sep-1999  perseant Back out changes made on the 29th, not at all the changes I intended to commit.
(I don't know how I did it though ... I'll figure it out tonight.)
I'll reapply this, in a working form, this evening.
 1.26 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.25 05-May-1999  sommerfe branches: 1.25.2;
Avoid byte overflow in block estimate for large files
 1.24 23-Mar-1999  bouyer branches: 1.24.2;
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.
 1.23 09-Mar-1999  bouyer Handle "nodump" flag on directories, by not dumping any files or directories
under it. Based on some parts of PR 6705 by Brian Grayson.
In the Makefile, add (commented out) debug options that can be turned on.
 1.22 28-Dec-1998  lukem fix estimate of blocks for subsets.
fix from Brian Grayson <bgrayson@ece.utexas.edu> in [bin/6607]
 1.21 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.20 18-Mar-1998  bouyer Add support for non-native byte order FFS. The dump is in filesystem byte
order, restore already knows how to byteswap dumps.
 1.19 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.18 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.17 05-Jun-1997  lukem * Add the ability to dump specific files & directories of a single
filesystem. This uses fts(3) to access the directory structure (and
not the raw device), so the standard access permissions are adhered
to (unlike dumping an entire filesystem, which just requires read
access to the raw disk device).
* Support SIGINFO status reporting.
* Remove now unused variables that previously stored the (e)uid.
* Be more informative in a couple of error messages.
 1.16 15-Apr-1997  lukem remove use of "register".
 1.15 30-Nov-1996  cgd patches from Tom I Helbekkmo <tih@nhh.no> to deal with type-size issues,
so this works (better, at least) on 64-bit machines (e.g. alpha).
 1.14 18-Jun-1995  cgd branches: 1.14.6;
update for posixified stat structure
 1.13 11-Jun-1995  mycroft Back out previous change.
 1.12 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.11 27-Mar-1995  mycroft Fix another bogus cast.
 1.10 27-Mar-1995  mycroft Remove incorrect cast on lseek() return value.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 30-Jan-1995  mycroft Don't mix stat flags and inode flags.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 17-Sep-1994  mycroft Correct typo; IFMT -> S_IFMT.
 1.5 14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 25-Apr-1994  cgd change some #ifdef's.
 1.2 14-Jan-1994  cgd fix for() starting condition in mapfiles()
 1.1 22-Dec-1993  cgd branches: 1.1.1;
new version from CSRG, via BSDI, with fixes
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.14.6.1 06-Dec-1996  rat Pullup request from Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu>

>Make dump and restore usable on the alpha
 1.24.2.1 05-May-1999  perry pullup 1.24->1.25 (sommerfeld)
 1.25.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.28.6.1 16-Jan-2002  he Pull up revision 1.34 (via patch, requested by bouyer):
Various fixes:
o Fix error if first tape is write-protected; fixes PR#4754 and PR#6098
o Make error codes conform to manual page
o Use \a to make noise
o Fix estimated number of tapes for huge dumps to cartridges
o Use <sys/queue.h> SLIST_* macros instead of homegrown variants
o Do not exit if unable to read/create /etc/dumpdates
o Support output (tape) device returning ENOSPC for end-of-media on write
o Don't dump core if SIGINFO is received before 1 second has elapsed
o Only process SIGINFO in currently active child
o Ensure current (sub)block isn't past end of file system -- fixes
"spins forever but does nothing" bug.
o Some other minor fixes (types, whitespace, KNF, unifdef sunos, ...)
 1.47.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.47.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.48.24.2 23-Jun-2013  tls resync from head
 1.48.24.1 25-Feb-2013  tls resync with head
 1.48.18.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.48.18.1 23-Jan-2013  yamt sync with head
 1.50.28.1 10-Jun-2019  christos Sync with HEAD
 1.50.20.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.17 15-Jun-2013  christos handle new lfs split
 1.16 13-Jan-2013  dholland Add some const.
 1.15 07-Aug-2003  agc branches: 1.15.56; 1.15.62;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.13 27-May-2001  lukem knf to ansi
 1.12 04-Feb-1998  christos Use strptime() instead of a home grown parser.
 1.11 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
* comment out some unused(?) functions
 1.10 15-Apr-1997  lukem remove use of "register".
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 28-Dec-1994  mycroft Sync with CSRG.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 24-Dec-1993  jtc Replace emitl(), a function that converts a struct tm to a time_t, with
a call to C library function mktime(), which does the exact same thing
(using basically the same algorithm too).
 1.5 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15.62.2 23-Jun-2013  tls resync from head
 1.15.62.1 25-Feb-2013  tls resync with head
 1.15.56.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.56.1 23-Jan-2013  yamt sync with head
 1.21 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.20 14-Apr-2021  mrg build lfs_node.c with -O3 on ia64 to avoid assembler overflow issues.
 1.19 07-Sep-2020  mrg remove GCC_NO_ADDR_OF_PACKED_MEMBER for several subdir builds
that are now handled by lfs_accessors.h internally.
 1.18 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.17 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.16 15-Jun-2013  christos branches: 1.16.28;
revert part of previous commit
 1.15 15-Jun-2013  christos fix compilation
 1.14 07-Apr-2012  christos branches: 1.14.2;
use getfsspecname()
 1.13 14-Aug-2011  christos branches: 1.13.2;
use a union to eliminate strict alias warnings.
 1.12 22-Jun-2011  mrg apply some -Wno-error and/or -fno-strict-aliasing.


all of this should be looked at closer, but some of them are not
very trivial.
 1.11 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.10 13-Feb-2009  uebayasi Comment out CFLAGS+=-g.
 1.9 27-Apr-2008  tsutsui branches: 1.9.4; 1.9.6;
Enable gcc optimization on m68000 (sun2) again with minimum hacks.
gcc -O0 generates a bit fat binaries.
 1.8 09-Feb-2008  mrg branches: 1.8.4; 1.8.6;
make all sun2 use -O0 and move most of the hacks out into just 3 files.
 1.7 24-Jun-2006  mrg branches: 1.7.10; 1.7.12;
work around some GCC4 internal problems on m68000 platform.
document the hack, and update another GCC4 list.
 1.6 19-Apr-2005  hannken Snapshot support for dump(8):

- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.

- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.

Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.5 27-Mar-2003  lukem branches: 1.5.6;
Remove "setgid tty" and references to utmp code from usr.bin/who.
 1.4 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.3 02-Aug-2002  scw Fix dump_lfs build following recent utmp changes.
 1.2 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.1 29-Sep-1999  perseant branches: 1.1.4; 1.1.10;
Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.1.10.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.1.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.6.1 21-Apr-2005  tron Pull up revision 1.6 (requested by hannken in ticket #184):
Snapshot support for dump(8):
- New option `-x backup' takes the dump from a snapshot backed up by `backup'.
The snapshot will be deleted on exit.
- New option `-X' as a synonym for `-x mountpoint' where `mountpoint' is the
file system to be dumped.
Reviewed and Approved by: Manuel Bouyer <bouyer@netbsd.org>
 1.7.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.7.10.1 23-Mar-2008  matt sync with HEAD
 1.8.6.1 18-May-2008  yamt sync with head.
 1.8.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.9.4.1 08-Dec-2010  riz Pull up following revision(s) (requested by uwe in ticket #1490):
usr.bin/mkdep/Makefile: revision 1.16
sbin/dump_lfs/Makefile: revision 1.10
usr.sbin/services_mkdb/Makefile: revision 1.5
sbin/ifconfig/Makefile: revision 1.40
usr.sbin/racoonctl/Makefile: revision 1.3
sbin/sysctl/Makefile: revision 1.18
Comment out CFLAGS+=-g.
Disable debug.
 1.13.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.2.1 17-Apr-2012  yamt sync with head
 1.14.2.1 23-Jun-2013  tls resync from head
 1.16.28.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.19 25-Mar-2019  wiz Bump date for previous.
 1.18 25-Mar-2019  manu Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry

This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.
 1.17 07-Jun-2017  abhinav branches: 1.17.6;
s/filesystem/file system/
 1.16 08-Apr-2012  wiz branches: 1.16.24;
Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.15 30-Jan-2009  enami branches: 1.15.8;
Use indent-synopsis instead of iS register. The latter is a register
used in BSD derived .Nm implementation.
 1.14 24-Jun-2006  wiz Use Dv for a macro; new sentence, new line.
 1.13 24-Jun-2006  perseant Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.12 13-Jul-2004  wiz Add description for -l, from dump(8).
Addresses PR 26066 by Kouichirou Hiratsuka.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 26-May-2003  lukem * Document $RCMD_CMD in environ(7).
* Cross-reference rcmd(1), rcmd(3), and environ(7) as appropriate.

Should fix [bin/21670] from Geoff Wing.
 1.9 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.8 04-Feb-2003  perry "Utilize" has exactly the same meaning as "use," but it is more
difficult to read and understand. Most manuals of English style
therefore say that you should use "use".
 1.7 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.6 21-Jan-2002  wiz Fix typo in macro.
 1.5 07-Dec-2001  wiz One '\' too many.
 1.4 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.3 16-Nov-2001  wiz Whitespace nits
 1.2 05-Jun-2001  wiz Drop arguments of .Os.
 1.1 29-Sep-1999  perseant branches: 1.1.4;
Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.1.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.8.1 17-Apr-2012  yamt sync with head
 1.16.24.1 29-Mar-2019  martin Pull up following revision(s) (requested by manu in ticket #1221):

sbin/dump/tape.c: revision 1.55
sbin/dump_lfs/dump_lfs.8: revision 1.18
sbin/dump/dump.h: revision 1.56
sbin/dump/dump.8: revision 1.69
sbin/dump/dump.h: revision 1.57
sbin/dump/ffs_inode.c: revision 1.23
sbin/dump/optr.c: revision 1.43
sbin/dump/itime.c: revision 1.21
sbin/dump/main.c: revision 1.74
sbin/dump/itime.c: revision 1.22
sbin/dump/main.c: revision 1.75
sbin/dump/dump.8: revision 1.70
sbin/dump/traverse.c: revision 1.52
sbin/dump/dump.8: revision 1.71

Document what rdump is (was once) for. PR 53442.

Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

Add -U flag to dump(8) and dump_lfs(8) to specify dumpdates entry
This address situations where dump(8) cannot figure out the device being
dumped. It also allows tracking of subvolume dumps by using virtual
device as dumpdates entry.

Bump date for previous.
 1.17.6.1 10-Jun-2019  christos Sync with HEAD
 1.29 12-May-2024  msaitoh s/unitialized/uninitialized/
 1.28 15-Oct-2015  dholland Make dump recognize lfs64.

For now at least it will refuse to touch it though as it needs to be
taught more abstraction about directory entries; currently it blindly
uses struct direct from ffs and will croak on the lfs64 64-bit inode
numbers.
 1.27 21-Sep-2015  dholland Fix some assorted 32-bit assumptions not yet otherwise handled.

Also apply patch to fix the overt problem in PR 50246: newfs was
calculating ifpb wrong for volumes with non-default block sizes.
 1.26 01-Sep-2015  dholland The ifile's inode number is constant. (it is always 1)

Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
 1.25 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.24 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.23 02-Aug-2015  dholland Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.22 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.21 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.20 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.19 19-Jun-2013  dholland Make this build again. hi christos
 1.18 15-Jun-2013  christos fix compilation
 1.17 08-Jun-2013  dholland Add unsafe hacks to make this build going forward.

XXX: unsafe hacks are unsafe -- dump needs to be cleaned up to make
XXX: it more fs-independent.
 1.16 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.15 14-Aug-2011  christos branches: 1.15.2; 1.15.8;
use a union to eliminate strict alias warnings.
 1.14 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.13 28-Sep-2006  perseant branches: 1.13.18; 1.13.22;
Call fcntl on the file descriptor *before* closing it.
 1.12 24-Jun-2006  perseant Change LFCNWRAP{STOP,GO} to make them more suitable for snapshotting; in
particular, the caller can now choose whether to wait for the condition
to be met, and if the caller of LFCNWRAPSTOP dies or otherwise closes
the descriptor, the filesystem is started again. Updated the ckckp
regression test to use the new semantics.

dump_lfs(8) now uses the fcntls to implement LFS-style snapshotting through
the -X flag, addressing PR#33457 albeit not using fss(4). Fixed a couple
other problems with dump_lfs that manifested themselves during testing.
 1.11 18-Jun-2005  lukem be consistent in XXXGCC -Wuninitialized fixes ...
 1.10 16-Jun-2005  jmc Mark an sh3 gcc unitialized variable w. XXGCC
 1.9 06-Feb-2005  perry ANSIfy a function declaration, remove obsolete "register" declaration.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.6 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.5 25-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.4 02-Nov-2001  lukem fix -Wshadow warnings
 1.3 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.2 01-Oct-1999  perseant branches: 1.2.4; 1.2.10;
Working version of aborted dump{,_lfs} join.
 1.1 29-Sep-1999  perseant Adapt dump(8) to use filestore-independent (but still ufs-specific)
replacements for NINDIR, fsbtodb, etc. Create dump_lfs by adding a few
LFS-filestore-specific routines. As described in PR#8317.
 1.2.10.2 10-Jul-2001  perseant Check both superblocks. If the fsb unit in the proto-superblock is > 8k,
look first for the true primary superblock at fs->lfs_sboffs[0].
 1.2.10.1 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.2.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.13.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.15.8.2 23-Jun-2013  tls resync from head
 1.15.8.1 25-Feb-2013  tls resync with head
 1.15.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.2.1 23-Jan-2013  yamt sync with head
 1.3 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.2 25-Feb-2025  rillig efi: don't use compound expressions as initializers

Lint doesn't like them, even though GCC accepts them.

No binary change.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.3 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.2 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.4 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.3 27-Feb-2025  christos make this compile with clang.
 1.2 25-Feb-2025  rillig efi: don't use compound expressions as initializers

Lint doesn't like them, even though GCC accepts them.

No binary change.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.2 30-Mar-2025  riastradh efi(8)/efi(9): Rename EFI_VARNAME_MAXLENGTH -> EFI_VARNAME_MAXBYTES.

This should help avoid potential confusion over the units.

No functional change intended.

Prompted by (but will not fix):

PR kern/59235: efi(8) panics
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.3 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.2 27-Feb-2025  christos make this compile with clang.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.4 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.3 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.2 24-Feb-2025  martin Fix a few printf formats
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.6 02-Mar-2025  riastradh efi(8): Avoid hard-coding sizeof(devpath_t) as magic constants.
 1.5 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.4 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.3 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.2 27-Feb-2025  christos make this compile with clang.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.6 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.5 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.4 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.3 25-Feb-2025  christos fix the build
 1.2 24-Feb-2025  martin Fix a few printf formats
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.5 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.4 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.3 25-Feb-2025  christos fix the build
 1.2 24-Feb-2025  martin Fix a few printf formats
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.2 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.3 24-Feb-2025  uwe efi(8): brush up markup a bit (mostly consistent use of .Va)

XXX: The manpage should really make up its mind whether it wants to
call the boot number(s) "hexnum", "####", or "bootnum".
 1.2 24-Feb-2025  uwe efi.8: g/c duplicate rcs id line
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.4 30-Mar-2025  riastradh efi(8)/efi(9): Rename EFI_VARNAME_MAXLENGTH -> EFI_VARNAME_MAXBYTES.

This should help avoid potential confusion over the units.

No functional change intended.

Prompted by (but will not fix):

PR kern/59235: efi(8) panics
 1.3 30-Mar-2025  riastradh efi(8): EFI_VARNAME_MAXLENGTH is in bytes, not CHAR16.

Same with struct efi_var_ioc::namesize.

This shouldn't change the semantics of the program -- it was just
allocating twice the maximum buffer space that the kernel would ever
actually use; now it only allocates exactly the maximum buffer space
that the kernel will ever actually use.

Prompted by (but will not fix):

PR kern/59235: efi(8) panics
 1.2 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.2 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.5 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.4 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.3 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.2 24-Feb-2025  martin Fix a few printf formats
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.5 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.4 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.3 27-Feb-2025  jakllsch fix build
 1.2 27-Feb-2025  christos make this compile with clang.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.4 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.3 02-Mar-2025  riastradh efi(8): Break overlong lines.
 1.2 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.5 02-Mar-2025  riastradh efi(8): Break more overlong lines.
 1.4 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.3 27-Feb-2025  christos make this compile with clang.
 1.2 25-Feb-2025  christos fix the build
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.2 27-Feb-2025  christos make this compile with clang.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.3 02-Mar-2025  riastradh efi(8): Nix trailing whitespace.
 1.2 25-Feb-2025  christos fix the build
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.1 24-Feb-2025  christos New efi program from Anon Ymous.
 1.9 24-Mar-1997  christos - Makefile cleanups
 1.8 18-Oct-1996  thorpej Use ${INSTALL}.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.12 16-Nov-2001  wiz Sort SEE ALSO.
 1.11 16-Nov-2001  wiz Whitespace nits
 1.10 05-Jun-2001  wiz Drop arguments of .Os.
 1.9 29-Apr-1998  fair fix bad .Xr references
 1.8 15-Sep-1997  lukem fixup .Nm usage
 1.7 14-Sep-1997  lukem fix capitalisation
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.45 03-Jan-2025  rillig fdisk: remove unreachable options 'T' and 't', fix lint warnings
 1.44 03-Jun-2023  lukem branches: 1.44.2;
bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.43 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.42 05-May-2012  tsutsui branches: 1.42.32;
Don't use "#if defined(__i386__) || defined(__x86_64__)" conditionals
in C source file to define option features.
Define proper options in each Makefile per ${MACHINE_ARCH} variable instead.

Previously if a host is x86 and it has /usr/mdec/mbr file in its system,
tools fdisk implicitly installs it as mbr bootcode even for !x86 targets.
 1.41 27-Nov-2009  tsutsui branches: 1.41.6; 1.41.8;
Remove fdisk/mbr for macppc which was blindly pulled from OpenBSD.
It just fakes MBR partition map which contains 1MB FAT16B partition
and ~1GB OpenBSD partition, and we can always create necessary
MBR partitions for OpenFirmware by the fdisk(8) command itself.
 1.40 01-Jun-2009  christos Delete GPT partitions if we overwrite with MBR to avoid confusion with disks
that have both MBR and a secondary left over GPT partition signature. From
Mike M. Volokhov
 1.39 06-Apr-2009  lukem remove mispelt WARNS. (it will be set in ../Makefile.inc "soon")
 1.38 29-Nov-2007  dsl branches: 1.38.2; 1.38.16;
Make this compile without -Wno-pointer-sign
(Needs updated bootblock.h)
 1.37 10-Mar-2007  apb branches: 1.37.4;
WARNS= 4
 1.36 12-May-2006  mrg don't do the -Wno-pointer-sign dance for host programs.
 1.35 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.34 23-Jun-2005  fvdl If HOSTPROG is empty, do not pull in libutil, since we do not need it in that
case, and several host platforms do not have libutil. Fixes the build of
these programs as host tools on platforms without libutil.
 1.33 12-Jun-2005  dyoung Turn fdisk(8) into a host tool. Still todo: commit the host-tool
build infrastructure to src/tools/fdisk/.
 1.32 22-May-2005  lukem Make fdisk(8) available on all platforms, since MS-DOS partitioning
is the de-facto standard for many removable media types.
 1.31 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.30 20-Jan-2005  xtraeme Remove main() prototype; WARNS=2
 1.29 13-Oct-2004  gavan Initial import of iyonix port.

The Iyonix is a desktop machine from Castle Technology, based on a 600MHz
XScale[tm] 80321 processor.

* Uses the bootloader from NetBSD/acorn32, which is now 32-bit compatible.
* Currently boots multiuser with a serial console.
* Device support is not yet complete.

With help from abs.
 1.28 30-Apr-2003  dsl Don't descend into mbr_bootsel.
i386/and64 mbr code is built in arch i386/stand/mbr
 1.27 26-Apr-2003  fvdl x86_64 -> amd64
 1.26 23-Nov-2002  fvdl Compile mbr and mbr_bootsel on x86_64
 1.25 26-Jul-2002  manu Added fdisk on hpcarm
 1.24 17-Jun-2002  itojun fdisk is now useful for macppc, build it
 1.23 09-May-2002  uch add hpcsh
 1.22 03-Apr-2002  thorpej Build fdisk(8) on netwinder.
 1.21 27-Feb-2002  scw fdisk(8) is needed on mvmeppc since PPCBUG uses PeeCee-style MBR
partition info when booting from disk.
 1.20 15-Oct-2001  uch playstation2 support
 1.19 02-May-2000  nonaka also install on prep.
 1.18 19-Mar-2000  soren Also install on cobalt.
 1.17 31-Jan-2000  soda Build fdisk also on arc
 1.16 25-Sep-1999  enami Oops, needs an operator.
 1.15 25-Sep-1999  enami Build fdisk also on hpcmips.
 1.14 25-Sep-1999  enami Don't decend into the subdirectory mbr_bootsel except i386,
since it currently doesn't contain MI thing and not compile
on ofppc box (thanks Wolfgang) and probably on bebox box.
 1.13 02-Jul-1999  sakamoto branches: 1.13.2;
Build fdisk on bebox and ofppc(replaced powerpc).
 1.12 02-May-1999  ross Since fdisk/mbr contains a man page, we need to descend into it regardless
of which ${MACHINE} we are.
 1.11 15-Apr-1999  fvdl Add and build a bootselecting MBR (i386).
 1.10 15-Oct-1998  ws branches: 1.10.2;
Separate master bootcode from fdisk.
 1.9 25-Sep-1997  lukem switch to using opendisk(3) from libutil
 1.8 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.7 14-Sep-1997  lukem * support ``short'' names of disks (e.g, ``sd0'') instead of requiring
the full name (e.g, ``/dev/rsd0d'') a la disklabel(8) (where the code
was effectively lifted from ;-)
* prefix hexadecimal numbers in output with '0x'
 1.6 05-Sep-1997  phil -- add -b flag for setting fdisk's idea of BIOS geometry from command line
-- cleanup so WARNS=1 works
-- man page updated to reality.
 1.5 23-Jun-1997  mrg move man pages into share/man.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 22-Dec-1994  cgd specify man pages the new way.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 09-Apr-1993  cgd added a 386bsd fdisk program, by julian elischer. (patch 111)
 1.10.2.2 02-May-1999  perry pullup 1.11->1.12 (fvdl)
 1.10.2.1 18-Apr-1999  fvdl Pull up bootselector mods, as approved by releng.
 1.13.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.37.4.1 09-Jan-2008  matt sync with HEAD
 1.38.16.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.38.2.2 29-Nov-2007  dsl Make this compile without -Wno-pointer-sign
(Needs updated bootblock.h)
 1.38.2.1 29-Nov-2007  dsl file Makefile was added on branch mjf-devfs on 2007-11-29 23:19:26 +0000
 1.41.8.1 12-Jun-2012  riz Pull up following revision(s) (requested by tsutsui in ticket #315):
sbin/fdisk/fdisk.c: revision 1.141
sbin/fdisk/fdisk.c: revision 1.142
tools/fdisk/Makefile: revision 1.5
tools/fdisk/Makefile: revision 1.7
sbin/fdisk/Makefile: revision 1.42
Don't use "#if defined(__i386__) || defined(__x86_64__)" conditionals
in C source file to define option features.
Define proper options in each Makefile per ${MACHINE_ARCH} variable instead.
Previously if a host is x86 and it has /usr/mdec/mbr file in its system,
tools fdisk implicitly installs it as mbr bootcode even for !x86 targets.
Use ${DESTDIR}/usr/mdec for DEFAULT_BOOTDIR on tools fdisk(8)
rather than unknown build host's /usr/mdec directory.
XXX: no option to leave MBR bootcode empty on x86 targets
 1.41.6.1 23-May-2012  yamt sync with head.
 1.42.32.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.44.2.1 02-Aug-2025  perseant Sync with HEAD
 1.93 03-Jan-2025  rillig fdisk: remove unreachable options 'T' and 't', fix lint warnings
 1.92 24-May-2020  wiz branches: 1.92.8;
Use Nx, fix formatting nit.
 1.91 24-May-2020  jmcneill Add -g flag to preserve GPT headers when updating MBR.
 1.90 15-Dec-2019  wiz Fix xrefs.
 1.89 14-Dec-2019  christos PR/54756: germain: Avoid confusion caused by overuse of the word "file" both
as a noun and an argument name.
 1.88 09-Apr-2019  tnn mention that -B is used to set the timeout for mbr_bootsel
 1.87 27-Jan-2017  abhinav branches: 1.87.12;
Fix spelling of simultaneous.
 1.86 11-Sep-2016  sevan branches: 1.86.2;
- Document the HISTORY of fdisk based on the original post to comp.unix.bsd by
Julian Elischer [1] and the Mach 2.5 Installation notes [2].
I was unable to pin point the exact version of Mach the fdisk utility appeared
as I didn't find documentation older than version 2.5 & no source code or repo
history. fdisk utility appears as a separate utility[3] in v2.5. Due to this,
I've avoided stating the exact version fdisk first appeared in Mach.
- Make correction pointed by textproc/igor
- Bump date

[1] https://groups.google.com/forum/#!searchin/comp.unix.bsd/14-Dec-89$20Robert$20Baron$20(rvb)$20at$20Carnegie-Mellon$20University%7Csort:relevance/comp.unix.bsd/Hhi45vAHxDg

[2] ftp://ftp.mcs.vuw.ac.nz/doc/misc/mach-i386-doc/i386_install.ps
[3] ftp://ftp.mcs.vuw.ac.nz/doc/misc/mach-i386-doc/i386_manpages.ps
 1.85 04-Apr-2014  wiz branches: 1.85.8;
-s:
If the optional arguments are not provided, they stay as before or
use the same defaults as the interactive mode, if new.

(feel free to improve)
 1.84 04-Apr-2014  wiz Fix a bug in previous and update detailed -s description.
 1.83 03-Apr-2014  wiz Update SYNOPSIS.
Christos, please check.
 1.82 31-Mar-2014  martin Bring back the playstation2 port - now that a toolchain for it is
available again.
 1.81 06-Oct-2013  apb Suggest using -b 1023/255/63 for modern disks where the BIOS is
configured to use LBA-Assisted translation.
 1.80 06-Oct-2012  wiz Revert my previous commit, I misunderstood the intention.
Noted by njoly.
 1.79 05-Oct-2012  wiz Previous slightly more consistently.
 1.78 05-Oct-2012  njoly Fix indented blocks rendering with mandoc. Switch from .in unsupported
macro to .Bd/.Ed ones. While here kill some unneeded .Pp/.br macros.
 1.77 08-Apr-2012  wiz branches: 1.77.2;
Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.76 06-Apr-2012  christos support sector sizes > 512.
 1.75 04-Jan-2012  wiz Remove trailing whitespace.
 1.74 31-Dec-2011  riz According to most other OSes and documentation sources, an MBR has
one "extended" partition and the partitions inside that are "logical"
partitions. Make fdisk(8) man page follow suit.

Patch from Julian Fagir in PR#45695.
 1.73 01-Dec-2011  wiz Remove trailing whitespace.
 1.72 01-Dec-2011  christos Add a flag to support writing overlapping partitions and explain why.
 1.71 25-Apr-2011  wiz branches: 1.71.4;
Use Nx.
 1.70 07-Apr-2010  wiz Minor punctuation fixes, improve and sort SYNOPSIS, sort flag descriptions.
From Bug Hunting in PR 43130.
 1.69 23-Dec-2009  dsl Add info for -A ptn_alignment[/ptn_0_offset]
 1.68 17-Dec-2009  pooka Use implicit -F for regular files, much like disklabel(8).
 1.67 05-Dec-2009  pooka Remove support for NetBSD/playstation2.
 1.66 29-Nov-2009  tsutsui Add a bunch of useful typical examples. Also use appropriate markup there.
 1.65 28-Nov-2009  tsutsui Update -u usage to follow changes in fdisk.c rev 1.125:
>> Allow MB, GB and CYL (not just M, G and C) and lower case.
>> Don't output a splurious 'd' before "cyl".
>> Fixes PR/37414.

XXX "NNcy" is also allowed?
 1.64 28-Nov-2009  tsutsui Clarify description of -f and -u options.
(-u means updating partition data, not interactive mode)
 1.63 14-Oct-2009  joerg Do not use .Xo / .Xc without a good reason.
 1.62 10-Aug-2009  yamt an example.
 1.61 02-Jul-2009  snj Small grammar tweak.
 1.60 01-Jun-2009  christos Delete GPT partitions if we overwrite with MBR to avoid confusion with disks
that have both MBR and a secondary left over GPT partition signature. From
Mike M. Volokhov
 1.59 20-Jan-2008  dsl Note the existance of mbr_com0 and mbr_com0_9600.
 1.58 23-Dec-2007  apb Remove note about the first track being reserved for the BIOS (it's
not), and replace it with a note about the first partition traditionally
beginning in the second track of the first cylinder.
 1.57 23-Dec-2007  apb Report the first active partition.
 1.56 20-May-2007  wiz branches: 1.56.4; 1.56.6;
Plural fix.
 1.55 11-Mar-2007  apb Bump date for previous.
 1.54 10-Mar-2007  apb Document the new checks for whether a PBR is bootable.
Also add more detail in the introduction, and a few
more references.
 1.53 24-Sep-2006  wiz branches: 1.53.2;
Use more macros. New sentence, new line.
 1.52 24-Sep-2006  jmcneill PR# 28660: how to remove bootmenu text from some partition
 1.51 07-Apr-2005  dsl Allow partition sizes to be input in GB
 1.50 13-Jul-2004  uwe s/Nm/Nx/, as it's NetBSD that has ports, not fdisk.
 1.49 13-Jul-2004  wiz Bump date for previous; new sentence, new line;
sort list of ports where fdisk is available.
 1.48 13-Jul-2004  darcy Add note top man page explaining that fdisk is not used on all platforms
and list the ones that is is.

Partial fix to PR#25943
 1.47 22-Mar-2004  lukem Use .Pp instead of .br as appropriate.
(This needs more work)
 1.46 20-Mar-2004  wiz Nm needs no argument; also, correct wrong Nm usage.
 1.45 19-Mar-2004  snj Bump date for last. Use Sq for single quotes. Drop trailing space.
New sentence, new line. Sort xrefs. Fix a spelling error.
 1.44 19-Mar-2004  dyoung Add flag -F, options -t disktab and -T disktype to fdisk. Flag -F
indicates that the target of the fdisk operation is a file, not a
disk. With -t and -T, the user tells fdisk the geometry for the
file If the default geometry that fdisk will "fake up" for a file
are not satisfactory, the user may tell the geometry to fdisk using
-t disktab -T disktype.
 1.43 06-Oct-2003  lukem be consistent about "MS-DOS"
 1.42 03-Jun-2003  joda add missing . before Fl
 1.41 06-May-2003  wiz MBR, not mbr.
 1.40 01-May-2003  dsl Change a couple of .Em to .Ar
 1.39 01-May-2003  wiz Replace some raw roff with mdoc.
 1.38 01-May-2003  wiz Improve formatting for [/bootmenu], requested by dsl; add some commas.
 1.37 01-May-2003  dsl a mbr -> an mbr
 1.36 01-May-2003  wiz Drop trailing space.
 1.35 30-Apr-2003  dsl Rototilled fdisk that supports:
- editing of the extended partition list
- user friendly default start/size for new partitions
- partition start/size input in sectors, cylinders or MB
- bootsel menu names configured with paritition bounds
- partition update loop asks used which partition to change
(instead of asking about each partition in turn).
- detection (and erroring) of overlapped partitions.
- automatic installation of correct mbr_xxx code (after prompting user)
 1.34 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.33 09-Feb-2003  wiz Drop trailing space (in last).
 1.32 09-Feb-2003  perry Slightly clarify/improve the documentation for the -B (boot selector)
option
 1.31 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.30 26-Mar-2002  christos PR/16073: Jachym _Freza_ Holecek: Add the ability to list known partition types.
While I am here, KNF a bit.
 1.29 05-Mar-2002  wiz Drop duplicate .Pp.
 1.28 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.27 13-Jan-2002  fair Cross-link fdisk(8), mbr(8), and mbrlabel(8) in the SEE ALSO sections,
as suggested in PR 14288. Also add a little white space to mbr(8) to
make it a little more readable.
 1.26 16-Nov-2001  wiz Whitespace nits
 1.25 05-Jun-2001  wiz Drop arguments of .Os.
 1.24 18-Dec-2000  lukem list the options in a specific options list (as per the `traditional'
man page). i find this much easier to read than option descriptions
scattered amongst paragraphs of text.
 1.23 14-Nov-2000  abs xref (disklabel.8, fdisk.8, mbrlabel.8) as appropriate
 1.22 07-Jun-2000  augustss Note that sysid 0 marks a partition as unused.
 1.21 11-Oct-1999  hubertf branches: 1.21.4;
Add note that "fdisk -i" is the same as "fdisk /mbr" on MSDOS.
 1.20 21-Sep-1999  simonb branches: 1.20.2;
Fix tyop and clean up usage of commas a little.
 1.19 02-May-1999  fvdl Remove confusing entry about cylinder boundaries.
 1.18 17-Apr-1999  fvdl Make the bootselector configurable by fdisk. Add a -B flag to this
effect (i386 only of course). Also change one branch in the
bootselector code to an explicit 16 bit one, and check both
the boot menu and partition tables to see if the partition
requested by the user should be booted. This check just in case,
should the bootselector menu and partition table get out of sync
somehow. (mmm, bytesqueezing)
 1.17 07-Mar-1999  mycroft branches: 1.17.2;
Clean up SYNOPSIS formatting.
 1.16 15-Oct-1998  ws Separate master bootcode from fdisk.
 1.15 28-Sep-1998  ws Automagically initialize boot code and partition table if not yet valid.
Don't touch the partition table on -i, if previously valid.
 1.14 19-Feb-1998  drochner update for new partition ID
 1.13 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.12 26-Nov-1997  ross Typos, English.
 1.11 14-Sep-1997  lukem branches: 1.11.2;
correct use of various mdoc macros to cleanup resultant man page
 1.10 05-Sep-1997  phil -- add -b flag for setting fdisk's idea of BIOS geometry from command line
-- cleanup so WARNS=1 works
-- man page updated to reality.
 1.9 11-Aug-1997  phil Upgrade for non-interactive use. Interactive use is nearly unchanged.
-i no longer implies -u, -i now does not use the entire first track
because some BIOSes refuse to boot from a partition in the first track.
-s renamed to -S, new -s for non-interactive setting of a partition's
id, offset and size. Updated documentation to match.
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 23-Sep-1994  mycroft Clean up a bit more.
 1.6 23-Sep-1994  mycroft Clean this up a bit.
 1.5 28-Jan-1994  jtc More spelling errors.
 1.4 14-Jan-1994  jtc Fix spelling errors
 1.3 06-Dec-1993  cgd 386bsd -> NetBSD
 1.2 02-Aug-1993  mycroft Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1 09-Apr-1993  cgd added a 386bsd fdisk program, by julian elischer. (patch 111)
 1.11.2.1 27-Nov-1997  mellon Pull rev 1.12 up from trunk (ross)
 1.17.2.3 21-Nov-1999  he Pull up revision 1.20 (requested by simonb):
Fix typo and clean up usage of commas a little.
 1.17.2.2 02-May-1999  perry pullup 1.18->1.19 (fvdl)
 1.17.2.1 18-Apr-1999  fvdl Pull up bootselector mods, as approved by releng.
 1.20.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.4.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.53.2.1 22-Mar-2007  jdc Pull up revisions 1.54-1.55 (requested by apb in ticket #513).

Document the new checks for whether a PBR is bootable.
Also add more detail in the introduction, and a few
more references.

Bump date for previous.
 1.56.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.56.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.56.4.2 23-Mar-2008  matt sync with HEAD
 1.56.4.1 09-Jan-2008  matt sync with HEAD
 1.71.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.71.4.2 30-Oct-2012  yamt sync with head
 1.71.4.1 17-Apr-2012  yamt sync with head
 1.77.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.77.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.85.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.86.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.87.12.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.87.12.1 10-Jun-2019  christos Sync with HEAD
 1.92.8.1 02-Aug-2025  perseant Sync with HEAD
 1.163 24-Feb-2025  andvar s/sightly/slightly/ and s/sligtly/slightly/ in documentation and comment.
 1.162 03-Jan-2025  rillig fdisk: remove unreachable options 'T' and 't', fix lint warnings
 1.161 02-Apr-2022  mlelstv branches: 1.161.4;
Avoid crashes with invalid or tiny sector sizes.
 1.160 03-Nov-2021  nia fdisk(8): Convert realloc(x * y) to reallocarr. Eliminate temp variables.
 1.159 24-May-2020  wiz Add -g to usage.
 1.158 24-May-2020  jmcneill Add -g flag to preserve GPT headers when updating MBR.
 1.157 07-Oct-2019  christos print the name of the disk causing the error.
 1.156 14-Nov-2018  mlelstv In validate_bootsel, the code assumed that arr[j][i] can be accessed
with something like arr[0][j*ARRAYWIDTH+i]. gcc no longer allows such
hacks and discards the code silently because of undefined behaviour.
 1.155 27-Aug-2018  sevan Add missing -z flag to usage()
 1.154 02-Oct-2017  joerg branches: 1.154.2; 1.154.4;
Really don't include ioctl code for tools build.
 1.153 22-Nov-2015  christos branches: 1.153.8;
explain how to clear an entry (without reading the source)
 1.152 16-Jun-2015  christos a few more \n's in errors
 1.151 16-Jun-2015  christos fix error messages containing \n
 1.150 04-Apr-2014  christos remove debugging.
 1.149 03-Apr-2014  christos instead of using ugly -1's make args optional
 1.148 01-Apr-2014  christos default to something reasonable (like the interactive mode does) instead
of 0 when -1 is specified for the start or size.
 1.147 30-Mar-2014  christos Allow -1 values in the -s <sysid>/<start>/<size> indicate use the previous
values. For example:
fdisk -f -i /dev/rsd0d # initialize mbr and create an msdos partition.
fdisk -f -u -0 -a -s 169/-1/-1 /dev/rsd0d # converts the msdos partition
to a netbsd one, and makes it active.
 1.146 10-Mar-2014  jakllsch Always print the MBR drive serial number, even if it's 0.
 1.145 14-Apr-2013  jakllsch Improve support for logical sector sizes greater than 512.
 1.144 13-Feb-2013  christos Don't produce spurious errors when creating labels on files.
 1.143 09-Feb-2013  christos CID/979997: missing va_end()
 1.142 05-Jun-2012  tsutsui branches: 1.142.2;
Use ${DESTDIR}/usr/mdec for DEFAULT_BOOTDIR on tools fdisk(8)
rather than unknown build host's /usr/mdec directory.

XXX: no option to leave MBR bootcode empty on x86 targets
 1.141 05-May-2012  tsutsui Don't use "#if defined(__i386__) || defined(__x86_64__)" conditionals
in C source file to define option features.
Define proper options in each Makefile per ${MACHINE_ARCH} variable instead.

Previously if a host is x86 and it has /usr/mdec/mbr file in its system,
tools fdisk implicitly installs it as mbr bootcode even for !x86 targets.
 1.140 06-Apr-2012  christos support sector sizes > 512.
 1.139 15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.138 02-Dec-2011  christos branches: 1.138.2;
Also ignore out of space conditions for -I so we can create overlapping
partitions on a full disk. Document and add it to the options.
 1.137 02-Dec-2011  enami Add missing -F flag and -I flag in usage. Sort the order to match
manpage.
 1.136 02-Dec-2011  christos put the error check in the conditional where it belongs.
 1.135 01-Dec-2011  christos Add a flag to support writing overlapping partitions and explain why.
 1.134 28-Aug-2011  gson branches: 1.134.2;
fix the sparc build
 1.133 27-Aug-2011  christos one static is enough, otherwise you risk zapping yourself.
 1.132 27-Aug-2011  joerg staticfy. __dead.
 1.131 08-May-2011  pgoyette Fix parsing of -A option so that the [/ptn_0_offset] part is optional, as
described in the man page.
 1.130 23-Dec-2009  dsl Put #endif in correct place - fixes PR/42500
Update usage() for -A, and rename one of the variables for clarity.
 1.129 22-Dec-2009  dsl Add support for partition being aligned on non-cylinder boundaries.
Info can be specified with -A parameter.
Default is based on how the first partition is defined.
For empty disks larger than 128GB (arbitrary figure) use 1MB alignment.
 1.128 22-Dec-2009  dsl Editing partitions larger than 1TB works better if 'decimal' returns
64 bit integer values!
 1.127 20-Dec-2009  dsl Add a large comment about disk geometries.
Rename (with #defines) the variables use for aligning partitions to
separate them from the bios geometry.
All in advance of allowing other partition alignments (eg 2048 sectors).
 1.126 17-Dec-2009  pooka Use implicit -F for regular files, much like disklabel(8).
 1.125 04-Nov-2009  dsl Allow MB, GB and CYL (not just M, G and C) and lower case.
Don't output a splurious 'd' before "cyl".
Fixes PR/37414.
Patch in PR is wrong!
 1.124 31-Oct-2009  dsl Make absence of /usr/mdec/mbr only a warning.
Fixes PR/26510
 1.123 05-Aug-2009  dsl Change arguments to decimal() to be int64_t.
They need to be able to hold disk sector numbers > 2^31 and also -1.
Should fix PR/34807
 1.122 02-Jun-2009  christos make this compile one non mbr machines (move #define to the general section)
 1.121 01-Jun-2009  christos Delete GPT partitions if we overwrite with MBR to avoid confusion with disks
that have both MBR and a secondary left over GPT partition signature. From
Mike M. Volokhov
 1.120 20-Apr-2009  drochner also fix a comment wrt use of the csysid/cstart/csize vars
 1.119 20-Apr-2009  sborrill When using -s flag, read start and size as unsigned to allow for larger
disks. (Thanks to drochner@ for catching it).
 1.118 06-Apr-2009  lukem fix sign-compare issues
 1.117 18-Jan-2009  apb branches: 1.117.2;
Remove local definitions of PRIxxxx macros in favour of the
centralised definitions from tools/compat/compat_defs.h, which
are included via nbtool_config.h.
 1.116 09-Mar-2008  tnn branches: 1.116.6;
mbr_dsn is unsigned, print it as such.
 1.115 25-Jan-2008  dsl branches: 1.115.2; 1.115.4;
Add support for mbr code with ascii keycodes
 1.114 20-Jan-2008  tsutsui - add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes"

Should close PR bin/37656.
 1.113 23-Dec-2007  apb Track zero is not strictly reserved for the BIOS, that's just a
convention, so don't make it an error in check_overlap(). Sector 0 is
reserved for the MBR, so make that an error in check_overlap().
 1.112 23-Dec-2007  apb Report the first active partition.
 1.111 23-Dec-2007  apb If the partition is unused, then attempting to decode the PBR would
actually decode the MBR from sector 0 of the disk. Don't do it if
v_flag < 3.
 1.110 29-Nov-2007  dsl branches: 1.110.2;
Make this compile without -Wno-pointer-sign
(Needs updated bootblock.h)
 1.109 29-Nov-2007  dsl Change -F to not use opendisk().
Don't change default to the boot volume until after we've found we aren't
doing -F.
For tool-fdisk enforce -F and use #defines to make code that can no
longer possibly execute compile.
 1.108 18-Nov-2007  apb Remove unwanted ">" from a printed message.
 1.107 28-Oct-2007  tsutsui Don't print Drive serial number if -S (setting shell variables) is specified.
 1.106 04-Sep-2007  tls This program is a host tool, so when we use newfangled C features like
PRIxyz we have to ensure it still builds on hosts with Old compilers.
Noticed while building a cross-toolchain on FreeBSD 4.
 1.105 05-Jul-2007  dsl branches: 1.105.4;
Preserve the mbr 'driver serial number' when copying in the netbsd
mbr code. Should leave windows vista bootable.
Print the dsn from the mbr, not each pbr.
 1.104 26-Apr-2007  christos PR/36223: Milos Negovanovic: Don't ask if we want to install mbr_bootselect
with -f.
 1.103 10-Mar-2007  apb Try to check whether each partition is bootable. If not,
always print an error message. If bootable and -v flag was
specified, print a success message. If -v flag was specified
more than once, also try to decode more information from
the PBR.

Input from dsl and bad.
 1.102 25-Nov-2006  dsl branches: 1.102.2;
Report the last sector number of a partition, instead of that of the first
of the next - with appropriate discarding of the head/sector values
if the partition is cylinder aligned.
Fixes PR 26921
 1.101 02-Jun-2006  christos PR/33633: Yoshito Komatsu: /sbin/fdisk does not work
Downgrade error getting heads to a warning.
 1.100 21-May-2006  christos PR/33522: Peter Bex: Sanity checks to avoid zerodivide.
 1.99 18-Mar-2006  dsl Appease Coverty CID 7449. Avoid close(-1) in error path.
 1.98 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.97 14-Feb-2006  dyoung So that we can build a full-featured fdisk cross-tool with -DBOOTSEL,
condition the definition of DEFAULT_BOOTxxx variables and SCAN_xxx
on defined(BOOTSEL), instead of defined(__i386__) || defined(__x86_64__).

While I'm here, only build get_diskname in the same conditions as
get_geometry is built, since only the latter calls the former.
 1.96 29-Jan-2006  dsl Byteswap the constant MBR_{BS_}MAGIC throughout, should genetate better code.
Except that non all architectures have that optimisation :-(
 1.95 07-Oct-2005  uwe PRI* macros should not contain percent sign.
While here, conditionalise use of "lld" for PRId64 on HAVE_LONG_LONG.
 1.94 07-Oct-2005  dogcow Fix cross-compilation on FreeBSD 4.x (and other OSes) where PRId64 isn't
defined.
 1.93 27-Aug-2005  uwe When building as host tool don't include "../../include/util.h".

opendisk() declared in that file is not used in this case anyway, and
<util.h> pulls in unwatned includes (e.g. <utmpx.h> doesn't exist on
FreeBSD 4.*).
 1.92 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.91 12-Jun-2005  dyoung Turn fdisk(8) into a host tool. Still todo: commit the host-tool
build infrastructure to src/tools/fdisk/.
 1.90 12-Jun-2005  dyoung For portability, use standard types: s/uint/unsigned int/,
s/ulong/unsigned long/, s/u_int8_t/uint8_t/.
 1.89 07-Apr-2005  dsl Allow partition sizes to be input in GB
 1.88 20-Jan-2005  xtraeme branches: 1.88.2;
Remove main() prototype; WARNS=2
 1.87 18-Nov-2004  wiz Fix typo in error message, reported by Nicolas Joly in PR 28347.
 1.86 15-Nov-2004  christos Use the 1st element's size as the argument to bsearch.
 1.85 12-Nov-2004  christos Use ptype table from <sys/bootblock.h>
 1.84 10-Nov-2004  christos Add 0xBF for Solaris. From Larry Lee <lclee at west.sun.com>
 1.83 28-Oct-2004  dsl Add (unsigned char) to isdigit() calls
 1.82 12-Sep-2004  dsl Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.81 30-Jul-2004  dbj check sysctl error return on both calls.
this prevents sysctl from coredumping if the second call fails while the
first succeeds. This isn't supposed to happen, but there is another bug
in the i386 kernel implementation of sysctl machdep.diskinfo that excites this
 1.80 19-May-2004  dyoung Insert missing space so fdisk prints "primary partition table
invalid, no magic in sector 0", not "primarypartition ...".
 1.79 10-May-2004  dsl Use the disk size from the device driver, not the bios when checking
whether partitions are valid.
Stops problems with broken BIOS, fixes PR bin/25491
 1.78 08-May-2004  dsl Don't output the 'Installed bootfile doesn't support required options'
message when we are updating the mbr code because the user did fdisk -i ...
 1.77 24-Mar-2004  lukem branches: 1.77.2;
Only examine mbr_bootsel* #ifdef BOOTSEL.
Noted on current-users@ by Markus Hennecke.
 1.76 22-Mar-2004  lukem Move mbr_bootsel from offset 404 to offset 400 in struct mbr_sector to
leave 4 bytes for the Windows NT Drive Serial Number (DSN) at 440-443
(as mbr_sector.mbr_dsn).

Ensure that all the MBR & PBR code reserves space for mbr_sector.mbr_dsn.

Leave the bootsel magic number at 444-445 as mbr_sector.mbr_bootsel_magic
(instead of mbr_sector.mbr_bootsel.mbrbs_magic), but use 0xb5e1 (MBR_BS_MAGIC)
instead of 0xaa55 (MBR_MAGIC) to indicate that this change has occurred.

Rework MBR_BS_NEWMBR to mean "mbr_bootsel has moved to 400".

Modify fdisk(8) to automatically relocate the mbr_bootsel from 404 to 400
if mbr_bootsel_magic is the old value (0xaa55), and unset MBR_BS_NEWMBR
to flag that new mbr_bootsel code must be used if updating the MBR.


These changes fixes a problem where Windows 2000 or Windows XP would corrupt
the last 3 bytes + NUL of MBR partition 3's bootsel name if the bootsel name
was 5 characters long, replacing bytes 6-9 with the DSN.
Also, by explicitly reserving the space for the DSN we prevent problems in the
future if non bootsel MBR or PBR code had other information at bytes 440-443.
 1.75 19-Mar-2004  dyoung Add flag -F, options -t disktab and -T disktype to fdisk. Flag -F
indicates that the target of the fdisk operation is a file, not a
disk. With -t and -T, the user tells fdisk the geometry for the
file If the default geometry that fdisk will "fake up" for a file
are not satisfactory, the user may tell the geometry to fdisk using
-t disktab -T disktype.
 1.74 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.73 21-Nov-2003  lukem Add "DISK" to -S output.
 1.72 11-Oct-2003  lukem unconditionally #define DEFAULT_BOOTDIR. should fix non-x86 builds
 1.71 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.70 19-Sep-2003  itojun realloc pedant
 1.69 29-Aug-2003  dsl Define and use PRIdaddr for printing disk block numbers.
Should fix bin/22638 for compilation on amd64.
 1.68 10-Aug-2003  dsl Put cylinder number 1023 into the mbr for sectors beyond the CHS limit
(rather than encoding the highest CHS addressable sector).
 1.67 14-Jul-2003  dsl Fix code that detects bios geometry from mbr table.
 1.66 07-Jul-2003  dsl Only look at each pair of CHS values once when trying to guess geometry.
 1.65 17-May-2003  itojun asprintf is easier
 1.64 14-May-2003  dsl delete a diagnostic printf that was accidentally left in
 1.63 01-May-2003  bjh21 Remove some unused variabled from get_params_to_use() in the !i386 && !amd64
case.
 1.62 30-Apr-2003  dsl Rototilled fdisk that supports:
- editing of the extended partition list
- user friendly default start/size for new partitions
- partition start/size input in sectors, cylinders or MB
- bootsel menu names configured with paritition bounds
- partition update loop asks used which partition to change
(instead of asking about each partition in turn).
- detection (and erroring) of overlapped partitions.
- automatic installation of correct mbr_xxx code (after prompting user)
 1.61 30-Apr-2003  dsl Move some definitions from fdisk.c to disklabel_mbr.h so they don't have
to be duplicated elsewhere (eg in mbr.S).
Modify fdisk.c so that it builds with the new disklabel.h
 1.60 01-Apr-2003  fvdl Fix range check for the default boot option case.
 1.59 10-Jan-2003  jmmv Print missing newline in two bootselector-related messages. Approved by wiz.
 1.58 30-Nov-2002  fvdl Enable bootselector code for x86_64.
XXX the ifdef-ed parts should be split off into a seperate file.
 1.57 24-Nov-2002  fvdl Avoid format warning for off_t printf.
 1.56 08-Oct-2002  jdarrow Make the -l flage more useful, by actually printing the systype number
alongside the sysid string (instead of just the array index of the
struct part_type they are found in).

Now fdisk -l shows the familiar 169 for NetBSD, 165 for FreeBSD or
386BSD or old NetBSD, and other possibly-familiar (131 for Linux native,
015 for Ext. Partition - LBA) values in with their correct numbers.
 1.55 27-Sep-2002  dbj add partition type 0xaf for Apple HFS.
 1.54 08-Aug-2002  soren Clean up printf->err conversions.
 1.53 05-Jun-2002  yamt exit on EOF from stdin.
 1.52 03-Apr-2002  thorpej branches: 1.52.2;
Build fdisk(8) on netwinder.
 1.51 26-Mar-2002  christos nicer printing.
 1.50 26-Mar-2002  christos PR/16073: Jachym _Freza_ Holecek: Add the ability to list known partition types.
While I am here, KNF a bit.
 1.49 04-Mar-2002  dbj add "Apple UFS" and "Apple Boot" partition ids used by Darwin
 1.48 07-Nov-2001  lukem if sysctl kern.root_device is availalbe, use that the default device
(rather than /dev/rwd0d). display the disk device used when printing
the partition table.
 1.47 01-Nov-2001  lukem opendisk(3) checks the device type for us
 1.46 16-Apr-2001  lukem add fix by Minoura Makoto to correctly support recursive extended partitions.
the offset of an extended sub-partition is the offset of the top-level
extended partition, not the partition before it (this is annoying, and
makes `clean' recursive mbr descent difficult). fixes PRs 11829 and 12677.
 1.45 24-Dec-2000  lukem use MBR_IS_EXTENDED() instead of local test (which was missing a test case)
 1.44 19-Dec-2000  lukem * Recursively print out extended partition entries. An extended partition is
effectively an MBR with it's own partition table which contains another
4 `slots', each of which can be another extended partition...
This involved reworking some of the internal functions.
* Use off_t appropriately (so we can manipulate sectors past 4GB).
* Tweak to compile with WARNS=2
 1.43 19-Dec-2000  lukem convert to ANSI KNF
 1.42 06-Jul-2000  thorpej When fetching the disk's hardware geometry, first attempt the
DIOCGDEFLABEL ioctl, then fall back onto the DIOCGDINFO ioctl
if that fails. This ensures that we will get the actual hardware
geometry info rather than any bogus info that might have been
previously written to the disk's label area.
 1.41 14-Jun-2000  wiz branches: 1.41.2;
Fix QNX partition IDs, confirmed by looking at FreeBSD's fdisk.
Note: 77 == 0x4d
 1.40 27-May-2000  fvdl Truncate the CHS values correctly in case a partition boundary exceeds
their range.
 1.39 31-Jan-2000  soda branches: 1.39.2;
Build fdisk also on arc
 1.38 06-Sep-1999  soren Update usage().
Prevent buffer overflows when configuring boot selector.
Cycle through partitions when entering boot names.
Use '<UNUSED>' consistently.

Reviewed by: fvdl
 1.37 04-Jun-1999  thorpej Make sure the boot selector actually gets updated if you only change
the timeout and/or the default menu choice.
 1.36 02-May-1999  fvdl Make check if we need int13 extensions for the bootselector more correct.
 1.35 28-Apr-1999  fvdl Only use int13 extensions if the sectors can not be read through the
older CHS interface. This works around stupid BIOSs who report that
int13 extensions are present and functional, but fail when you actually
use them. Like Adaptec SCSI BIOSs.

For the bootselector, there was no space to get the CHS info from
the BIOS. Instead, use a flag that can be set by fdisk. fdisk will
set it if one of the partitions on the disk is out of CHS reach
for this disk/BIOS, so that the bootselector will use int13 extensions.
This isn't so bad, because it needs to be configured via fdisk anyway.

Change the mbr manualpage to reflect some shorter error messages.
 1.34 17-Apr-1999  fvdl Make the bootselector configurable by fdisk. Add a -B flag to this
effect (i386 only of course). Also change one branch in the
bootselector code to an explicit 16 bit one, and check both
the boot menu and partition tables to see if the partition
requested by the user should be booted. This check just in case,
should the bootselector menu and partition table get out of sync
somehow. (mmm, bytesqueezing)
 1.33 09-Feb-1999  perry branches: 1.33.2;
add BeOS entry, from URA Hiroshi, PR 6974
 1.32 27-Jan-1999  thorpej Use <sys/disklabel_mbr.h>.
 1.31 08-Nov-1998  jonathan Set otherwise-unused global variable `disksectors' to disklabel.d_secperunit.
Change fdisk -S to emit disksectors as DLSIZE (for benefit of sysinst.)
 1.30 15-Oct-1998  ws Separate master bootcode from fdisk.
 1.29 02-Oct-1998  ws Completely zero out a partition table entry,
if type, start and size are given as zero.
 1.28 28-Sep-1998  ws Automagically initialize boot code and partition table if not yet valid.
Don't touch the partition table on -i, if previously valid.
 1.27 10-Aug-1998  rvb Dont report more than 1023 cylinders for DOS/BIOS because
the code below will truncate to a 10 bit field. This
can cause major problems later for DOS.
 1.26 25-Feb-1998  drochner Use the new NetBSD partition ID for first time setup of an MBR.
 1.25 19-Feb-1998  drochner Add new NetBSD partition ID.
Update information about partition types - add missing types, insert
"reserved" for IDs which are marked as "officially reserved" in other
lists.
Sources of information:
-"How it Works -- Partition Tables" by Hale Landis <hlandis@ibm.net>
-Ralph Brown's interrupt list
 1.24 07-Feb-1998  ghudson When estimating the number of cylinders in the BIOS geometry, use the
total number of sectors as reported by disklabel.d_secperunit rather
than multiplying out the disklabel geometry, which is less accurate.
 1.23 02-Feb-1998  mikel Don't print "DOS partition initialized" if -S set; from Nathan
Williams in PR bin/4893.
 1.22 22-Dec-1997  enami Add missing cast. This is a minimum fix to avoid overflow which causes
core dumps with some disk geometry.
 1.21 30-Sep-1997  phil branches: 1.21.2;
Backout the prototype of opendisk().
 1.20 30-Sep-1997  phil Prototype opendisk().
 1.19 25-Sep-1997  lukem switch to using opendisk(3) from libutil
 1.18 14-Sep-1997  lukem * support ``short'' names of disks (e.g, ``sd0'') instead of requiring
the full name (e.g, ``/dev/rsd0d'') a la disklabel(8) (where the code
was effectively lifted from ;-)
* prefix hexadecimal numbers in output with '0x'
 1.17 11-Sep-1997  phil Don't print some things if -f flag given.
 1.16 05-Sep-1997  phil -- add -b flag for setting fdisk's idea of BIOS geometry from command line
-- cleanup so WARNS=1 works
-- man page updated to reality.
 1.15 11-Aug-1997  phil Upgrade for non-interactive use. Interactive use is nearly unchanged.
-i no longer implies -u, -i now does not use the entire first track
because some BIOSes refuse to boot from a partition in the first track.
-s renamed to -S, new -s for non-interactive setting of a partition's
id, offset and size. Updated documentation to match.
 1.14 29-Jul-1997  phil Add code for a -s flag where the output is a series of VAL=xyz lines
so /bin/sh can "eval `fdisk -s`" and get variables defined with the
fdisk information.
 1.13 24-Jun-1997  perry Add a whole lot of MBR partition types, derived from a couple of sources
including Linux.
Is there a master list of this somewhere?
 1.12 29-Mar-1997  thorpej Make this work on big-endian systems, such as the PowerPC. From
Wolfgang Solfrank <ws@tools.de>
 1.11 04-Oct-1995  ghudson Add code to look at the existing partition entries to deduce the
translated geometry of the disk. This code will only change the
disk geometry if it can find a geometry which is consistent with
all partition entries, so it's very conservative about choosing
a new disk geometry. Under some circumstances, it will choose a
number of cylinders which is a little lower than it needs to be,
but this code is enough so that you can create new partitions
with the correct physical addresses.

The right solution to this problem is to have the boot loader
communicate the BIOS geometry of each disk to the kernel, in a
manner similar to the symbol table, and then provide a kernel
interface to get at that information. I'm unfortunately not
really qualified to make such a change, and I want something
that works better than the status quo.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 13-Jan-1995  mycroft Recognize Linux file systems correctly.
 1.8 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.7 20-Oct-1994  mycroft Allow `partitioning' of a regaular file.
 1.6 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.5 23-Sep-1994  mycroft Clean up a bit more.
 1.4 23-Sep-1994  mycroft Clean this up a bit.
 1.3 06-Dec-1993  cgd 386bsd -> NetBSD
 1.2 02-Aug-1993  mycroft Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1 09-Apr-1993  cgd added a 386bsd fdisk program, by julian elischer. (patch 111)
 1.21.2.4 16-Nov-1998  cgd pull up rev 1.25 from trunk (jonathan)
 1.21.2.3 24-Feb-1998  mellon Pull up 1.24 (ghudson)
 1.21.2.2 07-Feb-1998  mellon Pull up 1.23 (mycroft)
 1.21.2.1 22-Dec-1997  perry pullup from trunk to fix coredump (enami)
 1.33.2.4 01-Jun-2000  he Pull up revision 1.40 (requested by fvdl):
Fix a booting problem when int13 extensions are used (> 8GB),
and CHS values in MBRs were written from sysinst or fdisk that
some BIOSes (Adaptec SCSI BIOS 2.20 in particular) didn't like.
 1.33.2.3 22-Jun-1999  perry pullup 1.36->1.37 (thorpej): update boot selector only if it needs updating
 1.33.2.2 02-May-1999  perry pullup 1.34->1.36 (fvdl)
 1.33.2.1 18-Apr-1999  fvdl Pull up bootselector mods, as approved by releng.
 1.39.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.41.2.1 14-Feb-2002  he Pull up revision 1.42 (requested by itojun):
When fetching the disk's hardware geometry, first attempt the
DIOCGDEFLABEL ioctl, then fall back to the DIOCGDINFO ioctl.
This ensures that we will get the actual hardware geometry info
rather than any bogus info which might have been previously
written to the disk's label area.
 1.52.2.3 02-Jun-2003  tron Pull up revision 1.56 (requested by jdarrow in ticket #1206):
Make the -l flage more useful, by actually printing the systype number
alongside the sysid string (instead of just the array index of the
struct part_type they are found in).
Now fdisk -l shows the familiar 169 for NetBSD, 165 for FreeBSD or
386BSD or old NetBSD, and other possibly-familiar (131 for Linux native,
015 for Ext. Partition - LBA) values in with their correct numbers.
 1.52.2.2 02-Jun-2003  tron Pull up revision 1.55 (requested by jdarrow in ticket #1205):
add partition type 0xaf for Apple HFS.
 1.52.2.1 11-Jan-2003  jmc Pull up revisions 1.58-1.59 (requested by jmmv in ticket #1065)
Print missing newline in two bootselector-related messages.
 1.77.2.2 01-Dec-2005  riz Pull up following revision(s) (requested by tsutsui in ticket #10165):
sbin/fdisk/fdisk.c: revision 1.82 via patch
Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.77.2.1 16-Aug-2004  jmc branches: 1.77.2.1.2; 1.77.2.1.4;
Pullup rev 1.81 (requested by dbj in ticket #767)

Add support to pxeboot for reading the bios disk geometry
as well as fixing several related bugs that occur when the bios
geometry is not read by the boot loader.
 1.77.2.1.4.1 01-Dec-2005  riz Pull up following revision(s) (requested by tsutsui in ticket #10165):
sbin/fdisk/fdisk.c: revision 1.82 via patch
Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.77.2.1.2.1 01-Dec-2005  riz Pull up following revision(s) (requested by tsutsui in ticket #10165):
sbin/fdisk/fdisk.c: revision 1.82 via patch
Fix intuit_translated_geometry() calculation.
From Izumi Tsutsui in PR bin/26917
 1.88.2.2 30-May-2009  snj Pull up following revision(s) (requested by jnemeth in ticket #2018):
sbin/fdisk/fdisk.c: revision 1.104
PR/36223: Milos Negovanovic: Don't ask if we want to install mbr_bootselect
with -f.
 1.88.2.1 22-Feb-2008  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1897):
sbin/fdisk/fdisk.c: revisions 1.100, 1.101, 1.114
PR/33522: Peter Bex: Sanity checks to avoid zerodivide.
PR/33633: Yoshito Komatsu: /sbin/fdisk does not work
Downgrade error getting heads to a warning.
- add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes"
Should close PR bin/37656.
 1.102.2.5 03-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1053):
sbin/fdisk/fdisk.c: revision 1.107
Don't print Drive serial number if -S (setting shell variables) is specified.
 1.102.2.4 03-Feb-2008  riz Pull up following revision(s) (requested by tsutsui in ticket #1052):
sbin/fdisk/fdisk.c: revision 1.114
- add a sanity check to avoid possible division by zero
- adjust sector numbers _after_ "Sanity check the data against all zeroes"
Should close PR bin/37656.
 1.102.2.3 24-Aug-2007  liamjfoy Pull up following revision(s) (requested by dsl in ticket #832):
sbin/fdisk/fdisk.c: revision 1.105
Preserve the mbr 'driver serial number' when copying in the netbsd
mbr code. Should leave windows vista bootable.
Print the dsn from the mbr, not each pbr.
 1.102.2.2 28-Apr-2007  bouyer branches: 1.102.2.2.2;
Pull up following revision(s) (requested by christos in ticket #593):
sbin/fdisk/fdisk.c: revision 1.104
PR/36223: Milos Negovanovic: Don't ask if we want to install mbr_bootselect
with -f.
 1.102.2.1 22-Mar-2007  jdc Pull up revision 1.103 (requested by apb in ticket #513).

Try to check whether each partition is bootable. If not,
always print an error message. If bootable and -v flag was
specified, print a success message. If -v flag was specified
more than once, also try to decode more information from
the PBR.

Input from dsl and bad.
 1.102.2.2.2.2 03-Jun-2008  skrll Sync with netbsd-4.
 1.102.2.2.2.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.105.4.3 23-Mar-2008  matt sync with HEAD
 1.105.4.2 09-Jan-2008  matt sync with HEAD
 1.105.4.1 06-Nov-2007  matt sync with HEAD
 1.110.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.110.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.110.2.1 29-Nov-2007  mjf file fdisk.c was added on branch mjf-devfs on 2007-12-27 00:46:56 +0000
 1.115.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.115.2.1 24-Mar-2008  keiichi sync with head.
 1.116.6.3 09-Jan-2010  snj Pull up following revision(s) (requested by dsl in ticket #1207):
sbin/fdisk/fdisk.c: revision 1.128
Editing partitions larger than 1TB works better if 'decimal' returns
64 bit integer values!
 1.116.6.2 24-Dec-2009  snj Pull up following revision(s) (requested by dsl in ticket #1201):
sbin/fdisk/fdisk.c: revision 1.123
Change arguments to decimal() to be int64_t.
They need to be able to hold disk sector numbers > 2^31 and also -1.
Should fix PR/34807
 1.116.6.1 20-Apr-2009  snj branches: 1.116.6.1.4;
Pull up following revision(s) (requested by sborrill in ticket #712):
sbin/fdisk/fdisk.c: revision 1.119
When using -s flag, read start and size as unsigned to allow for larger
disks. (Thanks to drochner@ for catching it).
 1.116.6.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.117.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.134.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.134.2.3 30-Oct-2012  yamt sync with head
 1.134.2.2 23-May-2012  yamt sync with head.
 1.134.2.1 17-Apr-2012  yamt sync with head
 1.138.2.1 12-Jun-2012  riz Pull up following revision(s) (requested by tsutsui in ticket #315):
sbin/fdisk/fdisk.c: revision 1.141
sbin/fdisk/fdisk.c: revision 1.142
tools/fdisk/Makefile: revision 1.5
tools/fdisk/Makefile: revision 1.7
sbin/fdisk/Makefile: revision 1.42
Don't use "#if defined(__i386__) || defined(__x86_64__)" conditionals
in C source file to define option features.
Define proper options in each Makefile per ${MACHINE_ARCH} variable instead.
Previously if a host is x86 and it has /usr/mdec/mbr file in its system,
tools fdisk implicitly installs it as mbr bootcode even for !x86 targets.
Use ${DESTDIR}/usr/mdec for DEFAULT_BOOTDIR on tools fdisk(8)
rather than unknown build host's /usr/mdec directory.
XXX: no option to leave MBR bootcode empty on x86 targets
 1.142.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.142.2.2 23-Jun-2013  tls resync from head
 1.142.2.1 25-Feb-2013  tls resync with head
 1.153.8.1 28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #993):

sbin/fdisk/fdisk.c: revision 1.155

Add missing -z flag to usage()
 1.154.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.154.4.1 10-Jun-2019  christos Sync with HEAD
 1.154.2.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.154.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.161.4.1 02-Aug-2025  perseant Sync with HEAD
 1.18 05-Jun-2009  haad Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.17 26-Aug-2006  christos Programs that use efun.
 1.16 19-Aug-2004  christos Remove special case for RESCUEDIR
 1.15 23-Aug-2002  lukem if RESCUEDIR is defined, set _PATH_RESCUE to that
 1.14 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.13 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.12 11-Sep-1996  christos New version of filesystem independent fsck(8) program similar to mount(8).
 1.11 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 22-Dec-1994  cgd specify man pages the new way.
 1.8 30-Jun-1994  cgd deal with new share/doc strategy
 1.7 25-Jun-1994  cgd update for new doc-make/install strategy
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 28-Apr-1993  cgd i don't think we're in sys.386bsd any more...
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2 18-Mar-1998  bouyer This is now in libutil.
 1.1 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.18 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.17 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.16 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.15 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.14 28-Oct-1994  mycroft On a recursive call to fsck_readdir() through getpathname(), don't attempt to
fix a problem that's already being fixed.
 1.13 06-Oct-1994  mycroft dircheck() shouldn't be looking at d_type or d_namlen in blank entries
*at all*. Not only is it wrong, but it causes a serious problem on
little-endian machines, since after -c2 conversion, d_type will often
be > 15.
 1.12 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.11 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.10 20-Sep-1994  mycroft A correct fix for the byte order problem when reconnecting.
 1.9 29-Jul-1994  mycroft Fix oversight in last patch.
 1.8 28-Jul-1994  mycroft Fix byte-order problem with directory entry creation.
 1.7 08-Jun-1994  mycroft branches: 1.7.2;
Update from 4.4-Lite, with local changes.
 1.6 25-Apr-1994  cgd need <sys/time.h>
 1.5 05-Nov-1993  mycroft Patch from Bruce Evans to deal with file names with NULs in them.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.5 07-Nov-1994  cgd for patch #2
 1.7.2.4 06-Oct-1994  mycroft dircheck() shouldn't be looking at d_type or d_namlen in blank entries
*at all*. Not only is it wrong, but it causes a serious problem on
little-endian machines, since after -c2 conversion, d_type will often
be > 15.
 1.7.2.3 20-Sep-1994  mycroft A correct fix for the byte order problem when reconnecting.
 1.7.2.2 29-Jul-1994  cgd from trunk.
 1.7.2.1 28-Jul-1994  cgd from trunk.
 1.3 21-Jun-2015  dholland add missing rcsid
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 23-Feb-2008  christos branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.1.8.1 18-May-2008  yamt sync with head.
 1.1.6.3 02-Jun-2008  mjf Sync with HEAD.
 1.1.6.2 03-Apr-2008  mjf Sync with HEAD.
 1.1.6.1 23-Feb-2008  mjf file exitvalues.h was added on branch mjf-devfs2 on 2008-04-03 13:54:10 +0000
 1.1.4.2 24-Mar-2008  keiichi sync with head.
 1.1.4.1 23-Feb-2008  keiichi file exitvalues.h was added on branch keiichi-mipv6 on 2008-03-24 07:14:48 +0000
 1.1.2.2 23-Mar-2008  matt sync with HEAD
 1.1.2.1 23-Feb-2008  matt file exitvalues.h was added on branch matt-armv6 on 2008-03-23 00:44:23 +0000
 1.7 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.6 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.5 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.4 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 06-Dec-1994  cgd adjust; from jimj.
 1.1 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.41 18-Apr-2020  sevan grammar
 1.40 11-Sep-2016  wiz branches: 1.40.14;
file system police.
 1.39 11-Sep-2016  sevan Document the version fsck first appeared.
Bump date.
 1.38 28-Apr-2011  wiz New sentence, new line. Sort sections.
 1.37 18-Feb-2010  wiz Use Dq for double quotes; remove trailing whitespace.
 1.36 17-Feb-2010  christos Add -x <mountpoint> ``exclude'' option.
 1.35 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.34 24-Feb-2008  reed Fix typo.
 1.33 23-Feb-2008  christos Say what our exit values mean (this is not correct right now, because not
all fsck programs have been fixed but it will be soon).
 1.32 23-Feb-2007  rumble branches: 1.32.4; 1.32.10; 1.32.12;
Cross-reference fsck_lfs and fsck_ext2fs.
 1.31 19-Jan-2005  wiz Sort options.
 1.30 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.29 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.28 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.27 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.26 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.25 16-Nov-2001  wiz Sort SEE ALSO.
 1.24 18-Jun-2001  lukem - Don't attempt to fsck a file system that is mounted read-write unless -f
(force) is given. fsck(8) will return with a zero exit status if "fsck -p"
is used in this circumstance, but all other invocations (e.g, "fsck",
"fsck /filesystem", "fsck -p /filesystem") will return with a non-zero exit
status in this circumstance.
Per discussions with various people including Bill Sommerfeld.
- Use "file system" instead of "filesystem"
 1.23 18-Jun-2001  lukem -d is always compiled in; there's no specific #define to remove it
 1.22 05-Jun-2001  wiz Drop arguments of .Os.
 1.21 03-Apr-2001  wiz Xref exit 3, not 2. Whitespace fixes while I'm here.
 1.20 07-Mar-2001  fair Clarify the description of "preen" mode, per PR 12110
 1.19 10-Mar-1999  erh branches: 1.19.12;
Add missing .El
 1.18 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.17 09-Nov-1996  perry Fix more cosmetic problems -- changed .Nm fsck to just .Nm (thats the
whole point of the .Nm macro), replaced naked "fsck"s with .Nm's,
fixed another "the the", and .Dq'ed the "no" in the -t
description. Note that the description of -t is still ambiguous --
needs to be cleaned up by someone like Christos that actually knows it
well.
 1.16 09-Nov-1996  lukem fixed typos, from SAITOH Masanobu <msaitoh@spa.is.uec.ac.jp> in [misc/2924]
 1.15 22-Oct-1996  christos - Move some pieces from the fsck_ffs manual page that are appropriate for
fsck now.
- Correct the usage.
 1.14 03-Oct-1996  christos Document -f flag.
 1.13 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.12 11-Sep-1996  christos New version of filesystem independent fsck(8) program similar to mount(8).
 1.11 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.10 12-Jul-1995  cgd implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 13-Apr-1994  deraadt typo
 1.5 05-Aug-1993  jtc Updated to -mandoc macros.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.19.12.1 04-Apr-2001  he Pull up revision 1.21 (requested by wiz):
Some whitespace fixes.
 1.32.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.32.10.1 24-Mar-2008  keiichi sync with head.
 1.32.4.1 23-Mar-2008  matt sync with HEAD
 1.40.14.1 21-Apr-2020  martin Sync with HEAD
 1.53 24-Jan-2023  mlelstv Use opendisk when looking for filesystem type, otherwise the detection
only works if the correct device path is given as an argument.
 1.52 25-Oct-2014  mlelstv branches: 1.52.26;
fix logic that handles command line arguments. Now you can:

fsck /mnt/point
fsck dkX
fsck rdkX
fsck /dev/dkX
fsck /dev/rdkX
fsck NAME=wedge
 1.51 07-Apr-2012  christos branches: 1.51.10;
use getfsspecname()
 1.50 27-Aug-2011  joerg branches: 1.50.2;
Use __dead and __printflike.
 1.49 24-Feb-2010  hannken Dont pass option -x down to fsck_xxxfs.

Hi christos ...
 1.48 17-Feb-2010  christos Add -x <mountpoint> ``exclude'' option.
 1.47 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.46 17-Jul-2007  christos branches: 1.46.4; 1.46.10; 1.46.12;
kill MFSNAMELEN
 1.45 13-Dec-2006  christos Sprinkle volatile, instead of using the (void)&foo; which does not work on
gcc 4.
 1.44 16-Oct-2006  christos - add volatile
- static before const
 1.43 26-Aug-2006  christos Programs that use efun.
 1.42 20-Mar-2006  christos Coverity CID 1745: Fix memory leak.
 1.41 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.40 19-Jan-2005  xtraeme Add 'P' (progress meter flag) to getopt()'s optstring, remove
main() prototype.
 1.39 19-Jan-2005  wiz Sync usage with reality.
 1.38 13-Jan-2005  christos When we run with 'fsck -f -n' we should go over all the filesystems, not
exit on the first one that fails. Add a new flag CHECK_NOFIX so that we
specify -n, we keep going.
 1.37 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.36 25-Sep-2004  thorpej Try the DIOCGWEDGEINFO ioctl first. If that succeeds (i.e. the block
device is a wedge), use the partition type string from the dkwedge_info
structure to get the file system type.
 1.35 19-Aug-2004  christos Deal with RESCUEDIR
 1.34 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.33 20-Mar-2004  christos Remove my license.
 1.32 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.31 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.30 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.29 23-Aug-2002  lukem if _PATH_RESCUE is defined, try that before _PATH_SBIN & _PATH_USRSBIN
 1.28 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.27 01-Nov-2001  lukem fix a couple of -Wshadow warnings
 1.26 18-Jun-2001  lukem - Don't attempt to fsck a file system that is mounted read-write unless -f
(force) is given. fsck(8) will return with a zero exit status if "fsck -p"
is used in this circumstance, but all other invocations (e.g, "fsck",
"fsck /filesystem", "fsck -p /filesystem") will return with a non-zero exit
status in this circumstance.
Per discussions with various people including Bill Sommerfeld.
- Use "file system" instead of "filesystem"
 1.25 18-Jun-2001  lukem ansi knf
 1.24 18-Jun-2001  lukem use TAILQ_xxx instead of referencing tqh_xxx elements directly
 1.23 19-Feb-2001  cgd convert to use getprogname()
 1.22 04-Feb-2001  christos remove redundant declarations and nested externs.
 1.21 22-Apr-1999  abs Copy code across from newfs so that 'fsck sd0a' and similar will work.
 1.20 12-Nov-1998  christos Adjust for DKTYPENAME changes.
 1.19 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.18 26-Jul-1998  mycroft const poisoning.
 1.17 26-Jul-1998  mycroft const poisoning.
 1.16 31-Oct-1997  mycroft Rewrite catopt(), as in mount(8).
 1.15 31-Oct-1997  mycroft Format police.
 1.14 29-Oct-1997  christos PR/4384: Brian Grayson: Use real name for exec'ed child's argv[0]
 1.13 13-Oct-1997  bouyer branches: 1.13.2;
The number of fs types is FSMAXTYPES not DKMAXTYPES.
 1.12 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* prefix hex numbers with '0x'
 1.11 23-Jun-1997  mikel eliminate excess errx() argument
 1.10 20-Jun-1997  christos Move fscknames to <sys/disklabel.h> where they belong logically.
 1.9 07-Dec-1996  christos PR/3002: bug in my previous commit.
 1.8 05-Dec-1996  christos PR/2975: fsck lies to children about their program name
PR/2979: fsck is not smart enough about filesystems not in /etc/fstab
 1.7 03-Oct-1996  christos - Null terminate the argv vector [from ws]
- Dynamically allocate the argv vector
- Add -f global flag [from ws]
 1.6 28-Sep-1996  christos Fix typo.
 1.5 28-Sep-1996  christos Allow for an extra argument needed by quotacheck.
 1.4 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.3 27-Sep-1996  cgd fix up a debugging printf (was given its args in the wrong order), and
allow "ufs" in /etc/fstab to indicate MOUNT_UFS == MOUNT_FFS (for backward
compatibility).
 1.2 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.1 11-Sep-1996  christos New version of filesystem independent fsck(8) program similar to mount(8).
 1.13.2.1 31-Oct-1997  mellon Pull rev 1.14, 1.15 and 1.16 up from trunk (mycroft)
 1.46.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.46.10.1 24-Mar-2008  keiichi sync with head.
 1.46.4.1 23-Mar-2008  matt sync with HEAD
 1.50.2.1 17-Apr-2012  yamt sync with head
 1.51.10.1 11-Nov-2014  martin Pull up following revision(s) (requested by mlelstv in ticket #199):
sbin/newfs/newfs.c: revision 1.112
sbin/fsck/fsck.c: revision 1.52
fix logic that handles command line arguments. Now you can:
fsck /mnt/point
fsck dkX
fsck rdkX
fsck /dev/dkX
fsck /dev/rdkX
fsck NAME=wedge
Support wedge names.
before:
newfs dk1 - formats /dev/rdk1
newfs rdk1 - cannot open /dev/rrdk1
newfs /dev/dk1 - /dev/dk1 is a block-device, use raw device
newfs /dev/rdk1 - formats /dev/rdk1
now:
newfs dk1 - formats /dev/rdk1
newfs rdk1 - cannot open /dev/rrdk1
newfs /dev/dk1 - formats /dev/rdk1 (*)
newfs /dev/rdk1 - formats /dev/rdk1
newfs NAME=wedge - formats /dev/rdk1
(*) getfsspecname() returns the block device which must be translated.
Passing a block device manually cannot be distinguished from this case.
 1.52.26.1 22-Feb-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #93):

sbin/fsck/fsck.c: revision 1.53

Use opendisk when looking for filesystem type, otherwise the detection
only works if the correct device path is given as an argument.
 1.11 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.10 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.9 21-Mar-1995  cgd type sizes
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 02-May-1994  pk Prototype some things.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.27 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.26 21-Jun-2015  dholland branches: 1.26.16;
Add used-by comments on source files that are .PATH'd in from elsewhere.
 1.25 21-Jun-2015  dholland global variables should be declared extern.
 1.24 13-Jan-2013  mlelstv Support symlinks to a block device to resolve the name of the
corresponding raw device.
 1.23 08-Apr-2012  christos branches: 1.23.2;
Don't re-use the same buffer that we pass in for newname in the cooked->raw
conversion. Better variable names.
 1.22 07-Apr-2012  christos factor out rawname() from dump, fsck, savecore.
 1.21 07-Apr-2012  christos use getfsspecname()
 1.20 09-Jun-2011  christos branches: 1.20.2;
share more code.
 1.19 04-Feb-2010  christos branches: 1.19.4;
Centralize time printing and deal with ctime possibly returning NULL.
 1.18 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.17 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.16 26-Aug-2006  christos branches: 1.16.8; 1.16.16; 1.16.18;
Programs that use efun.
 1.15 05-Jun-2006  christos s/perror/perr/ so that we can make it varyadic. Overloading stdio's perror()
sneaky.
 1.14 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.12 28-Mar-2003  perseant Make vmsg non-static, so it can be used directly by fsck_lfs.
 1.11 09-Nov-2001  lukem use MAXPATHLEN instead of 32 as the size of the rawbuf
 1.10 18-Jun-2001  lukem ansi knf
 1.9 19-Feb-2001  cgd convert to use getprogname()
 1.8 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.7 30-Jul-1998  thorpej branches: 1.7.2; 1.7.12;
Cast pointer diffs to int for use in printf format width specifiers.
 1.6 26-Jul-1998  mycroft const poisoning.
 1.5 31-Oct-1997  mycroft Format police.
 1.4 14-Sep-1997  lukem branches: 1.4.2;
* cleanup for WARNS=1
* deprecate register
* prefix hex numbers with '0x'
 1.3 22-Oct-1996  christos Fix varyadic non ansi functions.
 1.2 03-Oct-1996  christos - Null terminate the argv vector [from ws]
- Dynamically allocate the argv vector
- Add -f global flag [from ws]
 1.1 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.4.2.1 31-Oct-1997  mellon Pull rev 1.5 up from trunk (mycroft)
 1.7.12.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.7.2.1 10-Oct-2000  he Pull up revision 1.8 (requested by is):
Format string cleanup.
 1.16.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.16.16.1 24-Mar-2008  keiichi sync with head.
 1.16.8.1 23-Mar-2008  matt sync with HEAD
 1.19.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.20.2.2 23-Jan-2013  yamt sync with head
 1.20.2.1 17-Apr-2012  yamt sync with head
 1.23.2.1 25-Feb-2013  tls resync with head
 1.26.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.21 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.20 21-Jun-2015  dholland branches: 1.20.16;
global variables should be declared extern.
 1.19 07-Apr-2012  christos factor out rawname() from dump, fsck, savecore.
 1.18 27-Aug-2011  joerg branches: 1.18.2;
Use __dead and __printflike.
 1.17 09-Jun-2011  christos fix compilation.
 1.16 09-Jun-2011  christos share more code.
 1.15 04-Feb-2010  christos branches: 1.15.4;
Centralize time printing and deal with ctime possibly returning NULL.
 1.14 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.13 15-Sep-2007  ragge __attribute -> __attribute__.
 1.12 26-Aug-2006  christos branches: 1.12.8;
Programs that use efun.
 1.11 05-Jun-2006  christos s/perror/perr/ so that we can make it varyadic. Overloading stdio's perror()
sneaky.
 1.10 13-Jan-2005  christos When we run with 'fsck -f -n' we should go over all the filesystems, not
exit on the first one that fails. Add a new flag CHECK_NOFIX so that we
specify -n, we keep going.
 1.9 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.8 28-Mar-2003  perseant Make vmsg non-static, so it can be used directly by fsck_lfs.
 1.7 18-Jun-2001  lukem - Don't attempt to fsck a file system that is mounted read-write unless -f
(force) is given. fsck(8) will return with a zero exit status if "fsck -p"
is used in this circumstance, but all other invocations (e.g, "fsck",
"fsck /filesystem", "fsck -p /filesystem") will return with a non-zero exit
status in this circumstance.
Per discussions with various people including Bill Sommerfeld.
- Use "file system" instead of "filesystem"
 1.6 18-Jun-2001  lukem ansi knf
 1.5 04-Feb-2001  christos remove redundant declarations and nested externs.
 1.4 26-Jul-1998  mycroft const poisoning.
 1.3 03-Oct-1996  christos - Null terminate the argv vector [from ws]
- Dynamically allocate the argv vector
- Add -f global flag [from ws]
 1.2 28-Sep-1996  christos Allow for an extra argument needed by quotacheck.
 1.1 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.12.8.1 06-Nov-2007  matt sync with HEAD
 1.15.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.18.2.1 17-Apr-2012  yamt sync with head
 1.20.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.18 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.17 17-Dec-1995  thorpej Squish some type bugs pointed out by Jonathan Stone.
 1.16 14-Dec-1995  thorpej Make this compile with -Werror.
 1.15 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.14 20-Mar-1995  mycroft Make sure to recreate the `..' entry in the root directory if missing.
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.11 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.10 14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.9 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.8 02-May-1994  pk Prototype some things.
 1.7 25-Apr-1994  cgd need <sys/time.h>
 1.6 18-Apr-1994  cgd kill some code if SMALL is defined...
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 13-Jun-1993  mycroft Add support for fast symlinks.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20 05-Apr-1996  cgd this file has moved; not properly checked in in previous commit.
 1.19 28-Nov-1995  jtc merge in changes from 1.1 release branch
 1.18 12-Jul-1995  cgd branches: 1.18.2;
recognize 'ffs' and 'ufs' as meaning the same thing.
 1.17 12-Jul-1995  cgd implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
 1.16 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.15 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.14 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.13 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.12 25-Apr-1994  cgd need <sys/time.h>
 1.11 06-Apr-1994  cgd kill the evil U word! from Mike Long <mike.long@analog.com>
 1.10 15-Oct-1993  cgd try again to keep it from rebooting endlessly
 1.9 06-Oct-1993  cgd set the 'clean' flag sometimes, but ignore it when deciding to clean
or not. this allows you to use this fsck and... reboot your system;
otherwise it would inf-loop rebooting and marking the FS clean,
which would then mark the fs modified, cause a reboot, etc.
 1.8 03-Oct-1993  mycroft #if 0 the fs_clean check for now.
 1.7 01-Oct-1993  mycroft Don't set clean flag if -n.
 1.6 01-Oct-1993  mycroft Initial count for fs_state is `FS_CLEANFREQ'.
 1.5 01-Oct-1993  mycroft Skip check if filesystem is marked clean and isn't too dusty, only with -p.
Set clean flag after checking a filesystem.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.2.1 01-Nov-1995  jtc complete ufs -> ffs change (From John Kohl; PR #1403)
 1.19 13-Apr-2025  jakllsch Add physical sector and alignment info to struct disk_geom and the
geometry plist, and handle in partutil.

Bump version for disk_geom addition.

Collect DIOCGSECTORALIGN handling into one place.
 1.18 02-Jan-2023  hannken branches: 1.18.2;
Change getdiskinfo() to no longer infer the partition from the device name.
Since 2016-06-16 we create disk devices "<type><<unit>" as an alias
for "<type><<unit><part>" where "<part>" is the raw partition.
These devices are treated as invalid partitions and a zero geometry
is returned.

Take the partition from "st_rdev" instead.

Fix for PR kern/57134: st_size of stat on vnd raw partition sometimes
is 0, causing newfs to fail
 1.17 28-Sep-2019  bad branches: 1.17.8;
initialize disc_dict to NULL.

otherwise, if DIOCGDISKINFO returns an error != ENXIO getdiskinfo() later
tries to prop_object_release() stack garbage.

found by rumpctrl tests using clang-7.
 1.16 18-Aug-2019  martin Properly release the disk properties dictionary we received via
ioctl.
Detected by leak sanitizer when building with MKSANITIZER=yes.
 1.15 03-Jun-2015  martin branches: 1.15.16; 1.15.18;
Make querying the disk geometry fail silently if called for a non-exitent
disk.
XXX: DIOCGDISKINFO returns strange error codes
 1.14 29-Dec-2014  christos abort earlier.
 1.13 29-Dec-2014  christos Provide a simple getdisksize() api for gpt(8).
 1.12 13-Apr-2013  jakllsch branches: 1.12.6;
Make getdiskinfo() always return correct dkwedge_info for the raw partition.

A real disk's raw partition does not implement DIOCGWEDGEINFO, but does
implement DIOCGDINFO. This was resulting in the returned wedge information
containing 32-bit-clamped values for size of the raw partition, with no
indication thereof.
 1.11 13-Nov-2011  christos branches: 1.11.6;
use getfstypename
 1.10 06-Mar-2010  christos branches: 1.10.6;
- use warn/err properly
- wrap long lines
 1.9 16-Jul-2009  dyoung Callers expect getdiskinfo() to return -1 on error, so do that.

Simplify getdiskinfo() a bit while I am here: don't save error
codes that we will never refer to again.
 1.8 14-Jun-2009  haad Remove bogus warn, which was printed when DIOCGDISKINFO failed.
 1.7 06-Jun-2009  haad Add support for devices which do not support DIOCGDISKINFO ioctl yet. This
change will restore fsck/newfs on vnd device.
 1.6 06-Jun-2009  haad Remove debug printfs.
 1.5 05-Jun-2009  haad Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.4 11-Apr-2009  lukem fix sign-compare issues
 1.3 28-Apr-2008  martin branches: 1.3.6;
Remove clause 3 and 4 from TNF licenses
 1.2 27-Aug-2006  christos branches: 1.2.18; 1.2.20;
add a const
 1.1 26-Aug-2006  christos - make preen recognize wedges and insert their parent disks in the disk list
so that we don't run multiple fsck's on the same spindle at the same time!
- Add some partition getting utilities that are wedge aware (soon to be able
to use the native geometry ioctl), so that we can fsck wedges.
 1.2.20.1 18-May-2008  yamt sync with head.
 1.2.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.10.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10.6.1 17-Apr-2012  yamt sync with head
 1.11.6.1 23-Jun-2013  tls resync from head
 1.12.6.1 25-May-2015  msaitoh Pull up following revision(s) (requested by jnemeth in ticket #793):
sbin/fsck/partutil.c: revision 1.13
sbin/fsck/partutil.h: revision 1.3
Provide a simple getdisksize() api for gpt(8).
 1.15.18.3 03-Jan-2023  martin Pull up following revision(s) (requested by hannken in ticket #1560):

sbin/fsck/partutil.c: revision 1.18

Change getdiskinfo() to no longer infer the partition from the device name.

Since 2016-06-16 we create disk devices "<type><<unit>" as an alias
for "<type><<unit><part>" where "<part>" is the raw partition.
These devices are treated as invalid partitions and a zero geometry
is returned.

Take the partition from "st_rdev" instead.

Fix for PR kern/57134: st_size of stat on vnd raw partition sometimes
is 0, causing newfs to fail
 1.15.18.2 09-Jan-2021  martin Pull up following revision(s) (requested by tsutsui in ticket #1184):

sbin/fsck/partutil.c: revision 1.17

initialize disk_dict to NULL.

otherwise, if DIOCGDISKINFO returns an error != ENXIO getdiskinfo() later
tries to prop_object_release() stack garbage.

found by rumpctrl tests using clang-7.
 1.15.18.1 18-Aug-2019  msaitoh Pull up following revision(s) (requested by martin in ticket #88):
sbin/fsck/partutil.c: revision 1.16
Properly release the disk properties dictionary we received via
ioctl.
Detected by leak sanitizer when building with MKSANITIZER=yes.
 1.15.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.17.8.1 03-Jan-2023  martin Pull up following revision(s) (requested by hannken in ticket #32):

sbin/fsck/partutil.c: revision 1.18

Change getdiskinfo() to no longer infer the partition from the device name.

Since 2016-06-16 we create disk devices "<type><<unit>" as an alias
for "<type><<unit><part>" where "<part>" is the raw partition.
These devices are treated as invalid partitions and a zero geometry
is returned.

Take the partition from "st_rdev" instead.

Fix for PR kern/57134: st_size of stat on vnd raw partition sometimes
is 0, causing newfs to fail
 1.18.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 29-Dec-2014  christos Provide a simple getdisksize() api for gpt(8).
 1.2 28-Apr-2008  martin branches: 1.2.40;
Remove clause 3 and 4 from TNF licenses
 1.1 26-Aug-2006  christos branches: 1.1.18; 1.1.20;
- make preen recognize wedges and insert their parent disks in the disk list
so that we don't run multiple fsck's on the same spindle at the same time!
- Add some partition getting utilities that are wedge aware (soon to be able
to use the native geometry ioctl), so that we can fsck wedges.
 1.1.20.1 18-May-2008  yamt sync with head.
 1.1.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.40.1 25-May-2015  msaitoh Pull up following revision(s) (requested by jnemeth in ticket #793):
sbin/fsck/partutil.c: revision 1.13
sbin/fsck/partutil.h: revision 1.3
Provide a simple getdisksize() api for gpt(8).
 1.15 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.14 18-Jan-1996  mycroft Use fs_csaddr to find the cg summary area. From der Mouse, PR 1366.
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.11 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.10 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.9 29-Jun-1994  ws Reads on raw disks are only guarranteed in multiples of the block size
 1.8 14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 25-Apr-1994  cgd need <sys/time.h>
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 13-Jun-1993  mycroft Add support for fast symlinks.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 28-Dec-1994  mycroft Change some spacing to match Kirk's view of the world.
 1.10 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.9 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.8 28-Oct-1994  mycroft Get the byte order right when creating `.' and `..' entries.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft branches: 1.6.2;
Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.1 07-Nov-1994  cgd for patch #2
 1.9 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.14 21-Mar-1995  cgd type sizes
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.11 18-Dec-1994  cgd light clean, and make it compile against new header files.
 1.10 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.9 28-Oct-1994  mycroft Use the S_IS*() macros, and make this compile again after Chris's changes to ufs.
 1.8 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.1 11-Sep-1996  christos New version of filesystem independent fsck(8) program similar to mount(8).
 1.32 21-Jun-2015  dholland Add used-by comments on source files that are .PATH'd in from elsewhere.
 1.31 07-Apr-2012  christos use getfsspecname()
 1.30 23-Feb-2008  christos branches: 1.30.22;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.29 26-Aug-2006  christos branches: 1.29.8; 1.29.16; 1.29.18;
- make preen recognize wedges and insert their parent disks in the disk list
so that we don't run multiple fsck's on the same spindle at the same time!
- Add some partition getting utilities that are wedge aware (soon to be able
to use the native geometry ioctl), so that we can fsck wedges.
 1.28 26-Aug-2006  christos Programs that use efun.
 1.27 13-Jan-2005  christos When we run with 'fsck -f -n' we should go over all the filesystems, not
exit on the first one that fails. Add a new flag CHECK_NOFIX so that we
specify -n, we keep going.
 1.26 28-Oct-2004  dsl Add (unsigned char) to isdigit() call
 1.25 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.24 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.23 01-Nov-2001  lukem fix a couple of -Wshadow warnings
 1.22 18-Jun-2001  lukem - Don't attempt to fsck a file system that is mounted read-write unless -f
(force) is given. fsck(8) will return with a zero exit status if "fsck -p"
is used in this circumstance, but all other invocations (e.g, "fsck",
"fsck /filesystem", "fsck -p /filesystem") will return with a non-zero exit
status in this circumstance.
Per discussions with various people including Bill Sommerfeld.
- Use "file system" instead of "filesystem"
 1.21 18-Jun-2001  lukem use TAILQ_xxx instead of referencing tqe_xxx elements directly
 1.20 18-Jun-2001  lukem ansi knf
 1.19 18-Jun-2001  lukem use TAILQ_xxx instead of referencing tqh_xxx elements directly
 1.18 26-Jul-1998  mycroft const poisoning.
 1.17 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.16 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* prefix hex numbers with '0x'
 1.15 28-Sep-1996  christos Allow for an extra argument needed by quotacheck.
 1.14 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.13 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.12 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.11 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.10 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.9 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.8 28-Oct-1994  mycroft Use the S_IS*() macros, and make this compile again after Chris's changes to ufs.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.29.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.29.16.1 24-Mar-2008  keiichi sync with head.
 1.29.8.1 23-Mar-2008  matt sync with HEAD
 1.30.22.1 17-Apr-2012  yamt sync with head
 1.5 11-Apr-2009  lukem fix sign-compare issues
 1.4 28-Apr-2008  martin branches: 1.4.6;
Remove clause 3 and 4 from TNF licenses
 1.3 14-Nov-2006  apb branches: 1.3.18; 1.3.20;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.2 10-May-2005  atatat If progress is disabled, don't clear the progress bar.
 1.1 13-Jan-2005  christos branches: 1.1.2;
Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.1.2.2 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.1.2.1 11-May-2005  tron Pull up revision 1.2 (requested by atatat in ticket #280):
If progress is disabled, don't clear the progress bar.
 1.3.20.1 18-May-2008  yamt sync with head.
 1.3.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 14-Nov-2006  apb branches: 1.2.18; 1.2.20;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.1 13-Jan-2005  christos branches: 1.1.2;
Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.1.2.1 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.2.20.1 18-May-2008  yamt sync with head.
 1.2.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.23 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.22 12-Jul-1995  cgd implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
 1.21 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.20 21-Mar-1995  cgd type sizes
 1.19 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.18 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.17 27-Dec-1994  mycroft Copy fs_maxcluster when comparing superblocks.
 1.16 18-Dec-1994  cgd light clean, and make it compile against new header files.
 1.15 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.14 28-Oct-1994  mycroft Use the S_IS*() macros, and make this compile again after Chris's changes to ufs.
 1.13 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.12 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.11 29-Jun-1994  ws Reads on raw disks are only guarranteed in multiples of the block size
 1.10 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.9 25-Apr-1994  cgd oops; changed comparison, but not field!
 1.8 25-Apr-1994  cgd need <sys/time.h>
 1.7 14-Apr-1994  cgd fs type names will soon be strings
 1.6 09-Apr-1994  deraadt from <dean@fsa.ca>: let "fsck /usr" work. also, if the user does
"fsck /dev/sd0a" attempt to map to the raw device name.
 1.5 01-Oct-1993  mycroft Skip check if filesystem is marked clean and isn't too dusty, only with -p.
Set clean flag after checking a filesystem.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.1 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.2 27-Sep-1996  christos - Rename util.c and util.h to fsutil.c and fsutil.h to avoid conflict with
<util.h>
- Change checkfstab so that the checkit function takes the name of the
mount point too (needed by quotacheck).
- Remove globals debug, verbose and preen
 1.1 23-Sep-1996  christos - added -T fstype:fsoptions per cgd's suggestion.
- handle parallelism in preening here using the original preening code from
fsck_ffs.
- move common code from fsck_ffs and fsck_msdos here.
 1.16 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.15 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.14 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 10-Feb-1995  cgd functions which are 'fake-varaargs' should be passed longs, not ints.
 1.11 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.10 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.9 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.8 02-May-1994  pk Prototype some things.
 1.7 25-Apr-1994  cgd need <sys/time.h>
 1.6 09-Apr-1994  deraadt if user does ie, "fsck /etc/group", then types ^C to the CONTINUE
prompt do not dump core. fix from <dean@fsa.ca> (who i will stop
hounding about bug fixes for an hour or two)
 1.5 28-Mar-1994  cgd kill extern'd lseek()
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18 31-Mar-2019  mlelstv No longer rely on data in disklabel to deduce alternate superblock
positions from block size. Instead use the same defaults as newfs_ext2fs.

Side effect is that fsck_ext2fs now works with wedges.
 1.17 04-Mar-2014  joerg branches: 1.17.26;
Make pointer NULL check non-fatal for a bogus condition.
 1.16 06-Aug-2011  dholland branches: 1.16.2; 1.16.8;
Avoid -Wno-pointer-sign.
 1.15 20-Jun-2011  mrg remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.14 29-Aug-2008  gmcgarry branches: 1.14.16;
Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.13 26-Aug-2006  christos branches: 1.13.18; 1.13.22;
Programs that use efun.
 1.12 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.11 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.10 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.9 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.8 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.7 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.6 18-Mar-1998  bouyer Use libutil rather than ../fsck/bswap.c
 1.5 11-Oct-1997  veego s/$FSCK/${FSCK}/
 1.4 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.3 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.2 16-Jun-1997  bouyer Don't compile with -g by default.
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.13.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.13.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.14.16.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.16.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.26.1 10-Jun-2019  christos Sync with HEAD
 1.28 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.27 09-Jun-2013  dholland Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.26 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.25 25-Nov-2012  jakllsch Catch up to the kernel with respect to Ext2 huge_file feature.
 1.24 25-Nov-2012  jakllsch e2di_nblock is (assuming the huge_file feature is not active) stored in
DEV_BSIZE units, not fs block size units.
 1.23 19-Oct-2009  bouyer branches: 1.23.6; 1.23.12;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.22 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.21 16-Mar-2008  lukem sync from fsck_ffs/dir.c 1.21:
lost+found directories are mode -1700
 1.20 16-Oct-2006  christos branches: 1.20.8; 1.20.16; 1.20.18;
use c99 initializers
 1.19 10-May-2006  mrg quell GCC 4.1 uninitialised variable warnings.

XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
 1.18 20-Mar-2006  christos Coverity CID 2299: Fix memory leak.
 1.17 20-Mar-2006  christos Coverity CID 2298: Fix memory leak.
 1.16 19-Aug-2005  christos 64 bit inode changes
 1.15 26-Jun-2005  christos more const.
 1.14 26-Jun-2005  christos constify.
 1.13 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.12 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.11 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.10 05-Oct-2003  bouyer More licence fixes, pointed out by Thomas Klausner.
 1.9 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 13-Jul-2003  itojun use bounded string op (one strcpy remains)
VS: ----------------------------------------------------------------------
 1.6 09-May-2002  simonb Don't bother testing if a uint8_t is > 256 -- that test is always false.
 1.5 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.4 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.3 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.20.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.20.16.1 24-Mar-2008  keiichi sync with head.
 1.20.8.1 23-Mar-2008  matt sync with HEAD
 1.23.12.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.12.2 23-Jun-2013  tls resync from head
 1.23.12.1 25-Feb-2013  tls resync with head
 1.23.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.23.6.2 23-Jan-2013  yamt sync with head
 1.23.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.8 25-Nov-2012  jakllsch Catch up to the kernel with respect to Ext2 huge_file feature.
 1.7 09-Jun-2011  christos branches: 1.7.2; 1.7.8;
share more code.
 1.6 26-Jun-2005  christos branches: 1.6.42;
constify.
 1.5 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.4 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.3 13-Jul-2003  itojun use bounded string op (one strcpy remains)
VS: ----------------------------------------------------------------------
 1.2 26-Jul-1998  mycroft const poisoning.
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.6.42.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.7.8.1 25-Feb-2013  tls resync with head
 1.7.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.17 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.16 15-Aug-2016  jdolecek branches: 1.16.14;
divorce list of features supported by fsck_ext2fs from the kernel;
while kernel might support e.g. extents, extra_isize or dir_nlink,
fsck could actually have no idea about the features
 1.15 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.14 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.13 26-Jun-2005  christos branches: 1.13.4; 1.13.20;
constify.
 1.12 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.11 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.10 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.9 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 29-Mar-2003  wiz Consistently spell occurrence with two rs.
 1.6 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.5 04-Feb-2001  christos fix nested extern and duplicate declarations
 1.4 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.3 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.2 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.13.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.13.4.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.16.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.21 27-Aug-2018  sevan Remove references to -c flag which was never included.
 1.20 11-Sep-2016  sevan branches: 1.20.6; 1.20.12; 1.20.14;
Document the author and the version fsck_ext2fs first appeared.
Bump date.
 1.19 21-Feb-2010  wiz Call the file system "ext2" consistently. Suggested by tsutsui.
 1.18 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.17 15-Mar-2009  joerg Fix markup.
 1.16 09-Oct-2008  wiz branches: 1.16.4;
Standardize.
 1.15 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.14 22-Mar-2004  bouyer branches: 1.14.16; 1.14.32;
Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.13 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.10 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.9 07-Feb-2002  ross Edit -mdoc usage.

* There is no -indent option to .Bd or .Bl, although you would
never know that from its frequent use in this tree. There is a
"-offset indent" combination that makes sense, and you can certainly
say "-width indent".

* Also, you can't markup the -width option argument, tho you CAN
use a callable macro. So "-width Ar filename" doesn't make sense,
but either "-width Ar" or "-width filename" does, as might something
like "-width xxfilename" for a little extra space.

* There are a lot of needlessly complex hanging tag macros in man4 used
to create simple item lists. Those should be simplified one of these
days before someone copies and edits yet another man4 page.
 1.8 16-Nov-2001  wiz Sort SEE ALSO.
 1.7 16-Nov-2001  wiz Whitespace nits
 1.6 05-Jun-2001  wiz Drop arguments of .Os.
 1.5 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.4 15-Sep-1997  lukem use .Nm correctly
 1.3 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.2 09-Jul-1997  mikel eliminate dangling FFS references
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.14.32.1 17-Jan-2009  mjf Sync with HEAD.
 1.14.16.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.16.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.20.14.1 10-Jun-2019  christos Sync with HEAD
 1.20.12.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.20.6.1 28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #992):

external/bsd/top/dist/top.1.in: revision 1.11
sbin/gpt/main.c: revision 1.12
sbin/amrctl/amrctl.c: revision 1.11
bin/df/df.c: revision 1.93
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.21
sbin/fsck_ext2fs/main.c: revision 1.38
bin/ksh/ksh.Man: revision 1.26
bin/ln/ln.c: revision 1.40
bin/df/df.1: revision 1.48
bin/df/df.1: revision 1.49

Document the WCPU field.

Match SYNOPSIS with usage()

-G cannot be specified alongside -i or -P.
Heads up by <leot>

Add -l to SYNOPSIS

Update usage to include -w

Match sequence as per SYNOPSIS in manual

Remove reference to -c flag which was never implemented.

Remove references to -c flag which was never included.

Add the -T flag to usage()
 1.37 04-Aug-2016  jdolecek rename struct ext2fs_dinode attribute e2di_dacl to correct
e2di_size_high; even Linux ext2 filesystem code actually uses it
unconditionally this way and ext4 code finally also calls it that way
in their struct definition too; if there was any trace of this for other
purpose it's long gone
 1.36 23-Jun-2013  dholland branches: 1.36.10;
Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.35 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.34 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.33 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.32 25-Nov-2012  jakllsch Catch up to the kernel with respect to Ext2 huge_file feature.
 1.31 04-Feb-2010  christos branches: 1.31.6; 1.31.12;
Centralize time printing and deal with ctime possibly returning NULL.
 1.30 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.29 06-Apr-2009  lukem fix sign-compare issues
 1.28 02-Mar-2009  tsutsui - add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
 1.27 24-Nov-2008  tsutsui branches: 1.27.2;
Handle 32 bit uid field on E2FS_REV1.
 1.26 24-Nov-2008  tsutsui Add missed byteswap ops against ext2fs_dinode members.
 1.25 24-Nov-2008  tsutsui Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
 1.24 24-Nov-2008  tsutsui - unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
 1.23 09-Oct-2008  christos branches: 1.23.2;
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.22 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.21 16-Nov-2007  tsutsui branches: 1.21.6; 1.21.8;
Add a workaround for incorrect "SUMMARY INFORMATIONS WRONG FOR CG #N"
and "BLK(S) MISSING IN BIT MAP #N" reports on newer ext2fs with
EXT2F_COMPAT_RESIZE feature by accounting blocks in EXT2_RESIZEINO.

XXX1: Should we account blocks allocated by all other reserved inodes?
XXX2: We should really check and fix EXT2_RESIZEINO accordingly.
 1.20 19-Aug-2005  christos branches: 1.20.4; 1.20.10;
64 bit inode changes
 1.19 26-Jun-2005  christos more const.
 1.18 26-Jun-2005  christos constify.
 1.17 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.16 05-Feb-2005  xtraeme Kill __P();
 1.15 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.14 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.13 05-Oct-2003  bouyer More licence fixes, pointed out by Thomas Klausner.
 1.12 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 13-Jul-2003  itojun use bounded string op (one strcpy remains)
VS: ----------------------------------------------------------------------
 1.9 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.8 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.7 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.6 17-Feb-1999  bouyer Properly handle FIFO (linux seems to puts something in the block addr fields
here) and a new field that can be different in the master superblock and
its first copy. From Tim Shepard.
 1.5 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.4 01-Apr-1998  kleink Need <time.h> for ctime() and time() prototypes.
 1.3 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.20.10.2 23-Mar-2008  matt sync with HEAD
 1.20.10.1 09-Jan-2008  matt sync with HEAD
 1.20.4.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.21.8.2 17-Jan-2009  mjf Sync with HEAD.
 1.21.8.1 03-Apr-2008  mjf Sync with HEAD.
 1.21.6.1 24-Mar-2008  keiichi sync with head.
 1.23.2.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1486):
sbin/fsck_ext2fs/setup.c: revision 1.26
sbin/newfs_ext2fs/mke2fs.c: revision 1.10
sbin/newfs_ext2fs/mke2fs.c: revision 1.11
sbin/newfs_ext2fs/mke2fs.c: revision 1.12
sbin/fsck_ext2fs/inode.c: revision 1.24
sys/lib/libsa/ext2fs.c: revision 1.6
sbin/newfs_ext2fs/extern.h: revision 1.3
sbin/fsck_ext2fs/inode.c: revision 1.25
sys/lib/libsa/ext2fs.c: revision 1.7
sbin/fsck_ext2fs/inode.c: revision 1.26
sys/ufs/ext2fs/ext2fs_inode.c: revision 1.68
sbin/fsck_ext2fs/inode.c: revision 1.27
sbin/fsck_ext2fs/inode.c: revision 1.28
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.18
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.19
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.5
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.2
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.6
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.3
sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.142
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.7
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.4
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.8
PR/40936: Frederik Sausmikat: ext2fs: add support for inodes > 128 bytes
Support variable inode sizes.
catch up with variable inode size.
Don't use e2fs_inode_size in superblock on E2FS_REV0 file system.
- accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
Use EXT2_DINODE_SIZE() to get offset of inode, not struct ext2fs_dinode array.
Fix botched logic in inodesize check.
Use inodesize to get offset of inode in one more place.
- add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
Sort options.
New sentence, new line.
Sort options in usage.
- unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
Add missed byteswap ops against ext2fs_dinode members.
Handle 32 bit uid field on E2FS_REV1.
 1.27.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.31.12.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.31.12.2 23-Jun-2013  tls resync from head
 1.31.12.1 25-Feb-2013  tls resync with head
 1.31.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31.6.2 23-Jan-2013  yamt sync with head
 1.31.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.36.10.1 06-Aug-2016  pgoyette Sync with HEAD
 1.41 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.40 15-Aug-2019  kamil fsck: Stop defining the same variable concurrently in bss and data

returntosingle was defined in multiple places:

- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.39 03-Feb-2019  mrg branches: 1.39.2;
- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.38 27-Aug-2018  sevan Remove references to -c flag which was never included.
 1.37 09-Jun-2011  christos branches: 1.37.34; 1.37.40; 1.37.42;
share more code.
 1.36 07-Jan-2010  christos branches: 1.36.4;
make this compile again.
 1.35 06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.34 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.33 16-Aug-2009  tron Ignore the "-P" option as intended to make this work with e.g.
"fsck_flags=-pP" in "/etc/rc.conf".

Patch supplied by Pierre Pronchery in PR bin/41490.
 1.32 12-Oct-2008  wiz branches: 1.32.2; 1.32.6; 1.32.8;
Don't use unicode in usage.
Noted by Anon Ymous.
 1.31 09-Oct-2008  wiz Sync usage with man page.
 1.30 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.29 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.28 16-Mar-2008  lukem branches: 1.28.4;
errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.27 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.26 16-Jul-2007  pooka branches: 1.26.4; 1.26.10; 1.26.12;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.25 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.24 08-Feb-2007  drochner include <signal.h> where signal(3) is used
 1.23 23-Sep-2005  jmmv branches: 1.23.4;
Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.22 19-Aug-2005  christos 64 bit inode changes
 1.21 26-Jun-2005  christos constify.
 1.20 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.19 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.18 13-May-2004  wiz Remove option letter from getopt string, since it does not
have a case handler below. From aaron@openbsd.
 1.17 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.16 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.15 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.14 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.13 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.10 19-Feb-2001  cgd convert to use getprogname()
 1.9 04-Feb-2001  christos fix nested extern and duplicate declarations
 1.8 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.7 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.6 26-Jul-1998  mycroft const poisoning.
 1.5 01-Apr-1998  kleink Need <time.h> for time() prototype.
 1.4 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.3 01-Oct-1997  enami Don't declare optind and optarg.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.23.4.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.26.12.3 17-Jan-2009  mjf Sync with HEAD.
 1.26.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.26.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.26.10.1 24-Mar-2008  keiichi sync with head.
 1.26.4.1 23-Mar-2008  matt sync with HEAD
 1.28.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.32.8.1 21-Apr-2010  matt sync to netbsd-5
 1.32.6.1 05-Sep-2009  bouyer Pull up following revision(s) (requested by tron in ticket #914):
sbin/fsck_ext2fs/main.c: revision 1.33
Ignore the "-P" option as intended to make this work with e.g.
"fsck_flags=3D-pP" in "/etc/rc.conf".
Patch supplied by Pierre Pronchery in PR bin/41490.
 1.32.2.1 05-Sep-2009  bouyer Pull up following revision(s) (requested by tron in ticket #914):
sbin/fsck_ext2fs/main.c: revision 1.33
Ignore the "-P" option as intended to make this work with e.g.
"fsck_flags=3D-pP" in "/etc/rc.conf".
Patch supplied by Pierre Pronchery in PR bin/41490.
 1.36.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.37.42.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.37.42.1 10-Jun-2019  christos Sync with HEAD
 1.37.40.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.37.34.1 28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #992):

external/bsd/top/dist/top.1.in: revision 1.11
sbin/gpt/main.c: revision 1.12
sbin/amrctl/amrctl.c: revision 1.11
bin/df/df.c: revision 1.93
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.21
sbin/fsck_ext2fs/main.c: revision 1.38
bin/ksh/ksh.Man: revision 1.26
bin/ln/ln.c: revision 1.40
bin/df/df.1: revision 1.48
bin/df/df.1: revision 1.49

Document the WCPU field.

Match SYNOPSIS with usage()

-G cannot be specified alongside -i or -P.
Heads up by <leot>

Add -l to SYNOPSIS

Update usage to include -w

Match sequence as per SYNOPSIS in manual

Remove reference to -c flag which was never implemented.

Remove references to -c flag which was never included.

Add the -T flag to usage()
 1.39.2.1 16-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #73):

sbin/fsck_lfs/main.c: revision 1.54
sbin/fsck_ext2fs/main.c: revision 1.40
sbin/fsck_ffs/main.c: revision 1.86

fsck: Stop defining the same variable concurrently in bss and data
returntosingle was defined in multiple places:
- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.26 21-Apr-2017  christos Fix previous properly (wrong variable was tested) thanks riastradh@
 1.25 21-Apr-2017  christos e2di_block is an array; can't be NULL, (clang)
 1.24 19-Jun-2013  dholland branches: 1.24.10;
Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.23 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.22 25-Nov-2012  jakllsch Catch up to the kernel with respect to Ext2 huge_file feature.
 1.21 04-Feb-2010  christos branches: 1.21.6; 1.21.12;
Centralize time printing and deal with ctime possibly returning NULL.
 1.20 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.19 06-Apr-2009  lukem fix sign-compare issues
 1.18 24-Nov-2008  tsutsui branches: 1.18.2;
Remove unnecessary casts.
 1.17 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.16 16-Nov-2007  tsutsui branches: 1.16.6; 1.16.8;
Add a workaround for incorrect "SUMMARY INFORMATIONS WRONG FOR CG #N"
and "BLK(S) MISSING IN BIT MAP #N" reports on newer ext2fs with
EXT2F_COMPAT_RESIZE feature by accounting blocks in EXT2_RESIZEINO.

XXX1: Should we account blocks allocated by all other reserved inodes?
XXX2: We should really check and fix EXT2_RESIZEINO accordingly.
 1.15 19-Aug-2005  christos branches: 1.15.10;
64 bit inode changes
 1.14 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.13 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.12 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.11 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.9 31-Jan-2000  bouyer Byteswap the group descriptors fields as well. Works again on big-endian
systems.
 1.8 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.7 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.6 17-Feb-1999  bouyer Properly handle FIFO (linux seems to puts something in the block addr fields
here) and a new field that can be different in the master superblock and
its first copy. From Tim Shepard.
 1.5 01-Apr-1998  kleink Need <time.h> for ctime() prototype.
 1.4 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.3 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.2 10-Jul-1997  mikel fix printf formats
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.15.10.2 23-Mar-2008  matt sync with HEAD
 1.15.10.1 09-Jan-2008  matt sync with HEAD
 1.16.8.2 17-Jan-2009  mjf Sync with HEAD.
 1.16.8.1 03-Apr-2008  mjf Sync with HEAD.
 1.16.6.1 24-Mar-2008  keiichi sync with head.
 1.18.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.12.2 23-Jun-2013  tls resync from head
 1.21.12.1 25-Feb-2013  tls resync with head
 1.21.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.21.6.2 23-Jan-2013  yamt sync with head
 1.21.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.24.10.1 26-Apr-2017  pgoyette Sync with HEAD
 1.8 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.7 06-Apr-2009  lukem fix sign-compare issues
 1.6 19-Jan-2005  xtraeme branches: 1.6.36;
Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.5 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.4 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.6.36.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.15 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.14 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.13 26-Jun-2005  christos branches: 1.13.10; 1.13.18; 1.13.20;
constify.
 1.12 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.11 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.10 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.9 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 13-Jul-2003  itojun use bounded string op (one strcpy remains)
VS: ----------------------------------------------------------------------
 1.6 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.5 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.4 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.3 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.13.20.1 03-Apr-2008  mjf Sync with HEAD.
 1.13.18.1 24-Mar-2008  keiichi sync with head.
 1.13.10.1 23-Mar-2008  matt sync with HEAD
 1.7 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.6 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.5 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.4 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.10 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.9 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.8 19-Aug-2005  christos branches: 1.8.10; 1.8.18; 1.8.20;
64 bit inode changes
 1.7 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.6 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.5 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.4 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.8.20.1 03-Apr-2008  mjf Sync with HEAD.
 1.8.18.1 24-Mar-2008  keiichi sync with head.
 1.8.10.1 23-Mar-2008  matt sync with HEAD
 1.20 26-Aug-2012  dholland stdlib.h, not malloc.h
 1.19 06-Aug-2011  dholland branches: 1.19.2;
Avoid -Wno-pointer-sign.
 1.18 06-Aug-2011  dholland Add static to a private function.
 1.17 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.16 06-Apr-2009  lukem fix sign-compare issues
 1.15 16-Mar-2008  lukem branches: 1.15.8;
errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.14 13-Nov-2007  tsutsui branches: 1.14.6; 1.14.8;
Use more proper aligned format in a debug function print_bmap().
 1.13 06-May-2006  christos branches: 1.13.10;
We don't need ext2fs_extern.h
 1.12 20-Mar-2006  christos branches: 1.12.2;
Coverity CID 2301: FIx memory leak.
 1.11 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.10 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.9 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.6 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.5 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.4 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.3 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.2 10-Jul-1997  mikel fix printf formats
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.12.2.3 20-Apr-2006  christos Don't include kauth.h
 1.12.2.2 19-Apr-2006  elad include kauth.h
 1.12.2.1 20-Mar-2006  elad file pass5.c was added on branch elad-kernelauth on 2006-04-19 18:49:08 +0000
 1.13.10.2 23-Mar-2008  matt sync with HEAD
 1.13.10.1 09-Jan-2008  matt sync with HEAD
 1.14.8.1 03-Apr-2008  mjf Sync with HEAD.
 1.14.6.1 24-Mar-2008  keiichi sync with head.
 1.15.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.19.2.1 30-Oct-2012  yamt sync with head
 1.10 16-Mar-2008  lukem Remove unused file.
 1.9 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.8 05-Jun-2006  christos branches: 1.8.10; 1.8.18; 1.8.20;
s/perror/perr
 1.7 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.6 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.5 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.3 13-Jul-2003  itojun use bounded string op (one strcpy remains)
VS: ----------------------------------------------------------------------
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.8.20.1 03-Apr-2008  mjf Sync with HEAD.
 1.8.18.1 24-Mar-2008  keiichi sync with head.
 1.8.10.1 23-Mar-2008  matt sync with HEAD
 1.39 31-Mar-2019  mlelstv Ignore EXT4 'kbytes written' field when validating alternate superblock.
 1.38 31-Mar-2019  mlelstv No longer rely on data in disklabel to deduce alternate superblock
positions from block size. Instead use the same defaults as newfs_ext2fs.

Side effect is that fsck_ext2fs now works with wedges.
 1.37 31-Mar-2019  mlelstv remove debug printfs from last commit.
 1.36 30-Mar-2019  mlelstv Ignore recorded last mount point when validating alternate superblocks.
Compute log_bsize correctly. This fixes computation of alternate
superblock addresses.
 1.35 15-Aug-2016  jdolecek branches: 1.35.14;
more informative debug output for unsupported features
 1.34 15-Aug-2016  jdolecek adjust inode size check to compare against EXT2_REV0_DINODE_SIZE, rather then sizeof(struct ext2fs_dinode), as the structure definition was expanded with the optional fields
 1.33 15-Aug-2016  jdolecek divorce list of features supported by fsck_ext2fs from the kernel;
while kernel might support e.g. extents, extra_isize or dir_nlink,
fsck could actually have no idea about the features
 1.32 04-Dec-2014  christos Instead of zerodivide, give a useful error message.
 1.31 23-Jun-2013  dholland branches: 1.31.6;
fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.30 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.29 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.28 16-Sep-2011  plunky branches: 1.28.2; 1.28.8;
NULL does not need a cast, here
 1.27 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.26 02-Mar-2009  tsutsui - add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
 1.25 16-Mar-2008  lukem branches: 1.25.6; 1.25.8;
errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.24 22-Dec-2007  tsutsui branches: 1.24.2; 1.24.4;
Use h2fs32() rather than fs2h32() on host to disk conversion.
 1.23 22-Dec-2007  tsutsui - use MINFREE defiend in <ufs/ext2fs/ext2fs.h>
- remove unnecessary casts
- unsigned -> unsigned int
- misc KNF
 1.22 22-Dec-2007  tsutsui Remove unused macro.
 1.21 13-Nov-2007  tsutsui branches: 1.21.2;
Fix e2fs_itpg calculation (a rounddown bug).
 1.20 16-Oct-2006  christos branches: 1.20.8;
comment out impossible code.
 1.19 26-Jun-2005  christos constify.
 1.18 09-Feb-2005  ws Add support for large files (>2GB).
Allow conversion of old filesystems to use this,
if they are already at revision 1.

There probably should be an option to turn revision 0 to revision 1.

Reviewed (in part) by Manuel (bouyer@).
 1.17 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.16 29-Oct-2004  dsl Add (unsigned char) cast to ctype function
Fix check for device name ending in [0-9a-h] (strchr(dev, 0) doesn't ever
return NULL - which is fortunate because the () were wrong as well!)
 1.15 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.14 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.12 28-Jan-2000  bouyer Correct bogons in filetype option support, and add support for the
sparse_super option.
 1.11 26-Jan-2000  bouyer First cut at ext2fs rev 1 support (as of mke2fs 1.18): supports the filetype
option read/write and the sparse option read-only.
 1.10 17-Feb-1999  bouyer branches: 1.10.2;
Properly handle FIFO (linux seems to puts something in the block addr fields
here) and a new field that can be different in the master superblock and
its first copy. From Tim Shepard.
 1.9 01-Feb-1999  bouyer Check malloc's return value before using the pointer.
 1.8 12-Nov-1998  christos Adjust for DKTYPENAME changes.
 1.7 26-Jul-1998  mycroft const poisoning.
 1.6 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.5 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.4 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.3 10-Jul-1997  mikel prototype calcsb()
 1.2 16-Jun-1997  bouyer The computed superblock size is bigger than SBSIZE, malloc() enouth
memory for it. Apparently, this bug was hidden by our malloc implementation.
Reported by Jason Downs.
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.10.2.1 01-Feb-2000  he Apply patch (requested by bouyer):
Add support for ext2fs revision 1, with read-only support for
the 'sparse_super' and 'filetype' options. Should fix PR#9088.
 1.20.8.2 23-Mar-2008  matt sync with HEAD
 1.20.8.1 09-Jan-2008  matt sync with HEAD
 1.21.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.24.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.24.2.1 24-Mar-2008  keiichi sync with head.
 1.25.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.25.6.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1486):
sbin/fsck_ext2fs/setup.c: revision 1.26
sbin/newfs_ext2fs/mke2fs.c: revision 1.10
sbin/newfs_ext2fs/mke2fs.c: revision 1.11
sbin/newfs_ext2fs/mke2fs.c: revision 1.12
sbin/fsck_ext2fs/inode.c: revision 1.24
sys/lib/libsa/ext2fs.c: revision 1.6
sbin/newfs_ext2fs/extern.h: revision 1.3
sbin/fsck_ext2fs/inode.c: revision 1.25
sys/lib/libsa/ext2fs.c: revision 1.7
sbin/fsck_ext2fs/inode.c: revision 1.26
sys/ufs/ext2fs/ext2fs_inode.c: revision 1.68
sbin/fsck_ext2fs/inode.c: revision 1.27
sbin/fsck_ext2fs/inode.c: revision 1.28
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.18
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.19
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.5
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.2
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.6
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.3
sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.142
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.7
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.4
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.8
PR/40936: Frederik Sausmikat: ext2fs: add support for inodes > 128 bytes
Support variable inode sizes.
catch up with variable inode size.
Don't use e2fs_inode_size in superblock on E2FS_REV0 file system.
- accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
Use EXT2_DINODE_SIZE() to get offset of inode, not struct ext2fs_dinode array.
Fix botched logic in inodesize check.
Use inodesize to get offset of inode in one more place.
- add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
Sort options.
New sentence, new line.
Sort options in usage.
- unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
Add missed byteswap ops against ext2fs_dinode members.
Handle 32 bit uid field on E2FS_REV1.
 1.28.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.8.2 23-Jun-2013  tls resync from head
 1.28.8.1 25-Feb-2013  tls resync with head
 1.28.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.28.2.1 23-Jan-2013  yamt sync with head
 1.31.6.1 14-Apr-2015  snj Pull up following revision(s) (requested by christos in ticket #688):
sbin/fsck_ext2fs/setup.c: revision 1.32
Instead of zerodivide, give a useful error message.
 1.35.14.1 10-Jun-2019  christos Sync with HEAD
 1.23 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.22 09-Jun-2011  christos branches: 1.22.2; 1.22.8;
share more code.
 1.21 07-Jan-2010  christos branches: 1.21.4;
make this compile again.
 1.20 06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.19 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.18 24-Nov-2008  tsutsui Remove unnecessary casts.
 1.17 16-Mar-2008  lukem errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.16 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.15 08-Feb-2007  drochner branches: 1.15.4; 1.15.10; 1.15.12;
include <signal.h> where signal(3) is used
 1.14 26-Jun-2005  christos constify.
 1.13 11-Feb-2005  simonb White space nit- don't put a space before/after increment/decrement
operators.
 1.12 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.11 22-Mar-2004  bouyer Fix disclaimer in my copyright. Pointed out by Thomas Klausner.
 1.10 05-Oct-2003  bouyer Remove references to University of California from my copyright notices.
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.8 13-Jul-2003  itojun use bounded string op (one strcpy remains)
VS: ----------------------------------------------------------------------
 1.7 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.6 04-Feb-2001  christos fix nested extern and duplicate declarations
 1.5 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.4 30-Mar-1998  mrg branches: 1.4.2; 1.4.10;
use extern int over extern
 1.3 09-Oct-1997  bouyer Ext2 metadata are always stored on disk in little-endian byte order,
so do byte-swapping on big-endian system. The byte-swap routines are in
fsck/bswap.c because they will also be used in fsck_ffs in future.
Tested on i386 and sparc.
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck()
* getopt returns -1 not EOF
* put a ) in the correct place in a printf, so that the argument gets
& 0xff, not the result of printf() itself...
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.4.10.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.4.2.1 10-Oct-2000  he Pull up revision 1.5 (requested by is):
Format string cleanup.
 1.15.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.15.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.15.10.1 24-Mar-2008  keiichi sync with head.
 1.15.4.1 23-Mar-2008  matt sync with HEAD
 1.21.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.22.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.51 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.50 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.49 11-Jun-2018  kamil Restore the MKGROFF=bo MKCXX=yes build

Mark the documentation in dc(1), gprof(1), rogue(6) and fsck_ffs(8) with
the .roff flag in SUBDIR.

Sponsored by <The NetBSD Foundation>
 1.48 08-Feb-2017  rin branches: 1.48.10;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.47 07-Feb-2017  rin Do not compile in progress.c when SMALLPROG is defined.
 1.46 23-Mar-2016  christos branches: 1.46.2; 1.46.4;
-O0 for pass1.c and vax
 1.45 05-Jul-2014  dholland Rework /usr/share/doc.

Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
- explicit use of soelim
- refer
- tbl
- pic
- eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
 1.44 10-Aug-2012  joerg branches: 1.44.2; 1.44.8;
Don't depend on HAVE_GCC being always defined.
 1.43 14-Aug-2011  christos branches: 1.43.2;
WARNS=4
 1.42 20-Jun-2011  mrg remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.41 06-Mar-2011  bouyer branches: 1.41.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.40 05-Jun-2009  haad branches: 1.40.2;
Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.39 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.38 30-Aug-2008  bouyer branches: 1.38.4;
Add fss(4) snapshot support to fsck_ffs(8) (via -x or -X options, like
dump(8)). This allows fsck_ffs -n to work on a snapshot of a R/W mounted
filesystem, and avoid errors related to filesystem activity.
 1.37 29-Aug-2008  gmcgarry Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.36 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.35 04-May-2008  tsutsui branches: 1.35.2; 1.35.4;
There is only one more file which requires HACKS for m68000,
so handle it in each Makefile rather than sys.mk.

These ICEs might be related with GCC Bugzilla Bug 32424
which is not resolved yet even in the upstream.
 1.34 09-Feb-2008  mrg branches: 1.34.4; 1.34.6;
make all sun2 use -O0 and move most of the hacks out into just 3 files.
 1.33 26-Aug-2006  christos branches: 1.33.8; 1.33.10;
- Deal with wedges and the new disk geometry structures, instead of using
struct disklabel.

Functionality lost:
1. struct disklabel used to be updated to contain bsize, fsize, cpg.
This information was used to locate the alternative superblock in
the filesystem if the primary superblock was corrupted. We need
to find a new place to store this information if we need this
functionality.
2. On vax SMD drives that contained bad sector lists, the newfs program
knew how to get the offset and skip to the correct location in order
to place the label.
 1.32 17-Aug-2006  christos Revert previous. It is not ready for public consumption.
 1.31 17-Aug-2006  christos Don't use || if you need &&.
 1.30 24-Jun-2006  mrg work around some GCC4 internal problems on m68000 platform.
document the hack, and update another GCC4 list.
 1.29 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.28 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.27 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.26 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.25 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.24 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.23 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.22 15-Jan-1999  bouyer branches: 1.22.4;
#include machine/bswap.h and remove -lutil.
 1.21 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.20 11-Oct-1997  mycroft Use bsd.subdir.mk as appropriate.
 1.19 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.18 21-Sep-1997  lukem remove -g from CFLAGS=
 1.17 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.16 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.15 06-May-1997  gwr Use .PATH.c: ...
 1.14 21-Feb-1997  mikel use += instead of = for CFLAGS
 1.13 27-Sep-1996  christos - util.h -> fsutil.h
 1.12 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.11 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 22-Dec-1994  cgd specify man pages the new way.
 1.8 30-Jun-1994  cgd deal with new share/doc strategy
 1.7 25-Jun-1994  cgd update for new doc-make/install strategy
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 28-Apr-1993  cgd i don't think we're in sys.386bsd any more...
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.22.4.1 19-Oct-1999  fvdl Add -I${.CURDIR}/../../sys for convenience. Should not be merged with
the trunk.
 1.33.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.33.8.1 23-Mar-2008  matt sync with HEAD
 1.34.6.1 18-May-2008  yamt sync with head.
 1.34.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.34.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.35.4.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.35.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.38.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.40.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.41.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.43.2.1 30-Oct-2012  yamt sync with head
 1.44.8.1 10-Aug-2014  tls Rebase.
 1.44.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.46.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.46.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.48.10.1 25-Jun-2018  pgoyette Sync with HEAD
 1.3 07-Oct-2023  rin Drop -O[01] hacks for vax; no longer necessary for patched GCC 10

PR port-vax/57646: Import major vax toolchain fix by Kalvis Duckmanton

XXXRO: GCC 12 may require hacks for a while, but it turned out that
GCC 12 should be treated differently from older versions; a lot of new
files need -O[01] flags, while some may no longer require it.

I will take a look later.

Note that these hacks are not required if Kalvis's patches for GCC 12
are applied.

Keep doc/HACKS entries for a while (will be sync with update for GCC 12).

diff --git a/crypto/external/bsd/openssh/lib/Makefile b/crypto/external/bsd/openssh/lib/Makefile
index 96a93f5e396..4e38be1b642 100644
--- a/crypto/external/bsd/openssh/lib/Makefile
+++ b/crypto/external/bsd/openssh/lib/Makefile
@@ -117,12 +117,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
# XXX
COPTS.channels.c+= -fno-strict-aliasing

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.poly1305.c+= -O0
-COPTS.umac.c+= -O0
-.endif
-
COPTS.hostfile.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.sshkey.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.cipher.c+= -Wno-error=deprecated-declarations
diff --git a/distrib/utils/x_ping/Makefile b/distrib/utils/x_ping/Makefile
index f1c452a0d60..8ee77580a3f 100644
--- a/distrib/utils/x_ping/Makefile
+++ b/distrib/utils/x_ping/Makefile
@@ -12,10 +12,6 @@ CPPFLAGS+= -I${SRCDIR} -DCRUNCHOPS
DPADD= ${LIBM}
LDADD= -lm

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>

.PATH: ${SRCDIR}
diff --git a/external/apache2/argon2/lib/libargon2/Makefile.inc b/external/apache2/argon2/lib/libargon2/Makefile.inc
index d3f4470c6c7..6a1dd146d7d 100644
--- a/external/apache2/argon2/lib/libargon2/Makefile.inc
+++ b/external/apache2/argon2/lib/libargon2/Makefile.inc
@@ -16,7 +16,3 @@ CFLAGS+= -pthread
LDADD+=-lpthread
DPADD+=${LIBPTHREAD}
.endif
-
-.if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-.endif
diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc
index 2f524358f46..d5da774f293 100644
--- a/external/bsd/jemalloc/lib/Makefile.inc
+++ b/external/bsd/jemalloc/lib/Makefile.inc
@@ -53,12 +53,6 @@ COPTS.ctl.c+=-Wno-error=stack-protector
COPTS.stats.c+=-Wno-error=stack-protector
COPTS.tcache.c+=-Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-# in merge_overlapping_regs, at regrename.c
-COPTS.arena.c+=-O0
-COPTS.extent.c+=-O0
-.endif
-
SRCS+=${JEMALLOC_SRCS}

jemalloc.d jemalloc.pico jemalloc.o jemalloc.ln jemalloc.po jemalloc.go: \
diff --git a/external/bsd/mdocml/lib/libmandoc/Makefile b/external/bsd/mdocml/lib/libmandoc/Makefile
index 40d7e29ae88..dfd3077a2c7 100644
--- a/external/bsd/mdocml/lib/libmandoc/Makefile
+++ b/external/bsd/mdocml/lib/libmandoc/Makefile
@@ -39,11 +39,6 @@ tbl_opts.c

MAN= mandoc.3

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.mdoc_macro.c+=-O0
-.endif
-
COPTS.man_validate.c+=-Wno-error=array-bounds

.include <bsd.lib.mk>
diff --git a/external/gpl3/binutils.old/lib/libbfd/Makefile b/external/gpl3/binutils.old/lib/libbfd/Makefile
index 03477232b55..74a354532fa 100644
--- a/external/gpl3/binutils.old/lib/libbfd/Makefile
+++ b/external/gpl3/binutils.old/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/binutils/lib/libbfd/Makefile b/external/gpl3/binutils/lib/libbfd/Makefile
index 00cb2b20081..a3f0c25fd35 100644
--- a/external/gpl3/binutils/lib/libbfd/Makefile
+++ b/external/gpl3/binutils/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/gcc.old/lib/Makefile.sanitizer b/external/gpl3/gcc.old/lib/Makefile.sanitizer
index efd36ae4bee..5173a5109a0 100644
--- a/external/gpl3/gcc.old/lib/Makefile.sanitizer
+++ b/external/gpl3/gcc.old/lib/Makefile.sanitizer
@@ -88,22 +88,3 @@ COPTS+=-fno-builtin -fno-exceptions -fno-rtti -funwind-tables

# Can't profile without it`
#-fomit-frame-pointer
-
-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_allocator.cc += -O1
-COPTS.sanitizer_common.cc += -O1
-COPTS.sanitizer_common_libcdep.cc += -O1
-COPTS.sanitizer_coverage_libcdep.cc += -O1
-COPTS.sanitizer_coverage_mapping_libcdep.cc += -O1
-COPTS.sanitizer_deadlock_detector1.cc += -O1
-COPTS.sanitizer_mac.cc += -O1
-COPTS.sanitizer_netbsd.cc += -O1
-COPTS.sanitizer_posix.cc += -O1
-COPTS.sanitizer_printf.cc += -O1
-COPTS.sanitizer_procmaps_common.cc += -O1
-COPTS.sanitizer_stackdepot.cc += -O1
-COPTS.sanitizer_symbolizer_libcdep.cc += -O1
-COPTS.sanitizer_symbolizer_report.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
diff --git a/external/gpl3/gcc.old/lib/libasan/Makefile b/external/gpl3/gcc.old/lib/libasan/Makefile
index 1e6f9608abe..3da7bbf2f58 100644
--- a/external/gpl3/gcc.old/lib/libasan/Makefile
+++ b/external/gpl3/gcc.old/lib/libasan/Makefile
@@ -49,14 +49,6 @@ LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
LIBDPLIBS+= pthread ${NETBSDSRCDIR}/lib/libpthread
CPPFLAGS+=-DCAN_SANITIZE_UB=0

-.if ${MACHINE_ARCH} == "vax"
-COPTS.asan_allocator.cc += -O1
-COPTS.asan_report.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
-
.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
COPTS.asan_interceptors.cc += -O1
.endif
diff --git a/external/gpl3/gcc.old/lib/liblsan/Makefile b/external/gpl3/gcc.old/lib/liblsan/Makefile
index 4578544a9a8..ddb7981077c 100644
--- a/external/gpl3/gcc.old/lib/liblsan/Makefile
+++ b/external/gpl3/gcc.old/lib/liblsan/Makefile
@@ -16,11 +16,6 @@ LSAN_SRCS+= \
lsan_linux.cc \
lsan_thread.cc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lsan_allocator.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= lsan
SRCS+= ${LSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/lib/libubsan/Makefile b/external/gpl3/gcc.old/lib/libubsan/Makefile
index 2e2faca7b1c..9de82550d14 100644
--- a/external/gpl3/gcc.old/lib/libubsan/Makefile
+++ b/external/gpl3/gcc.old/lib/libubsan/Makefile
@@ -26,10 +26,6 @@ UBSAN_SRCS= \
COPTS.${_s}.cc+=-frtti
.endfor

-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= ubsan
SRCS+= ${UBSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/usr.bin/cc1/Makefile b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
index c55e292ee8e..ff12a5be524 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
@@ -46,17 +46,6 @@ CPPFLAGS.default-c.c+= -I${BACKENDOBJ}
BUILDSYMLINKS+= ${GNUHOSTDIST}/gcc/config/sh/sh-c.cc sh-c.c
.endif

-.if ${MACHINE_CPU} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
index 3123ee0d60b..aab82ad3448 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
@@ -44,16 +44,8 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-.endif
+COPTS.c-cppbuiltin.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}
+COPTS.c-typeck.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}

.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
diff --git a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
index b9c108251c5..e04e8fc7f53 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
@@ -69,18 +69,6 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-COPTS.decl.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
index 7936efd3a5e..7c54559e21a 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
@@ -31,23 +31,6 @@ CHECKSUM_OBJS= ${LIBBACKTRACEOBJ}/libbacktrace.a \

CFLAGS+= -Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.call.c+=-O0
-COPTS.decl.c+=-O0
-COPTS.typeck2.c+=-O0
-COPTS.class.c+=-O0
-COPTS.typeck.c+=-O0
-COPTS.init.c+=-O0
-COPTS.semantics.c+=-O0
-COPTS.mangle.c+=-O0
-COPTS.constexpr.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1plus-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/gcc/Makefile b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
index 7a66d77ffc7..a5a4b1c3adf 100644
--- a/external/gpl3/gcc.old/usr.bin/gcc/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
@@ -25,9 +25,6 @@ ${SRCS}: ${GCCARCH}/defs.mk
.include <bsd.info.mk>

COPTS.gcc.c= -Wno-stack-protector
-.if ${MACHINE_ARCH} == "vax"
-COPTS.dse.c= -O1
-.endif

.PATH: ${DIST}/gcc ${DIST}/gcc/doc ${DIST}/gcc/c

diff --git a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
index 751d1513eec..33aeb1c9898 100644
--- a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
@@ -14,10 +14,6 @@ SRCS= decNumber.c decContext.c decimal32.c decimal64.c decimal128.c
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH} -I${DIST}/libdecnumber
CPPFLAGS+= -I${DIST}/libgcc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.include <bsd.lib.mk>

# Force using C++ for this
diff --git a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
index 90f44a9fcf6..fd251464fb7 100644
--- a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
@@ -24,11 +24,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.backtrace"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
DPADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} ${LIBINTL} ${LIBZ} ${LIBM}

diff --git a/external/gpl3/gcc.old/usr.bin/lto1/Makefile b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
index 4c49161a64c..340d3c6124f 100644
--- a/external/gpl3/gcc.old/usr.bin/lto1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
@@ -21,11 +21,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.libcpp"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTYOBJ}/libiberty.a
DPADD+= ${LIBIBERTYOBJ}/libiberty.a
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
diff --git a/external/gpl3/gdb.old/lib/libdecnumber/Makefile b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
index bcd4ae5b222..ce28811526b 100644
--- a/external/gpl3/gdb.old/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libdecnumber/Makefile b/external/gpl3/gdb/lib/libdecnumber/Makefile
index c95d36e3dfa..e3169865304 100644
--- a/external/gpl3/gdb/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd ${DIST}/libdecnumber/bid

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libgdb/Makefile b/external/gpl3/gdb/lib/libgdb/Makefile
index b87a515d13a..c118c363975 100644
--- a/external/gpl3/gdb/lib/libgdb/Makefile
+++ b/external/gpl3/gdb/lib/libgdb/Makefile
@@ -66,12 +66,6 @@ CFLAGS:= ${CXXFLAGS} -std=gnu++17 -Wno-error=stack-protector

ada-exp.c: ada-lex.c

-.if ${MACHINE} == "vax"
-. if ${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8
-COPTS.read.c+= -O0
-. endif
-.endif
-
# These are generated by implicit rules and are not easy to generate
CLEANDIRFILES+= \
ada-exp.c ada-lex.c \
diff --git a/external/mit/xorg/lib/gallium.old/Makefile b/external/mit/xorg/lib/gallium.old/Makefile
index 55b2fe3d1c1..bfa40c8974f 100644
--- a/external/mit/xorg/lib/gallium.old/Makefile
+++ b/external/mit/xorg/lib/gallium.old/Makefile
@@ -1211,10 +1211,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
# XXXGCC12
.if ${MACHINE_ARCH} == "m68k"
COPTS.st_glsl_to_tgsi.cpp += -O1
diff --git a/external/mit/xorg/lib/gallium/Makefile b/external/mit/xorg/lib/gallium/Makefile
index 6778a8c11c8..9f1422080fe 100644
--- a/external/mit/xorg/lib/gallium/Makefile
+++ b/external/mit/xorg/lib/gallium/Makefile
@@ -1428,10 +1428,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
COPTS.u_atomic.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-builtin-declaration-mismatch :}

.include <bsd.lib.mk>
diff --git a/external/mit/xorg/lib/libX11/Makefile.libx11 b/external/mit/xorg/lib/libX11/Makefile.libx11
index e103d9ace12..0e55c2a4732 100644
--- a/external/mit/xorg/lib/libX11/Makefile.libx11
+++ b/external/mit/xorg/lib/libX11/Makefile.libx11
@@ -471,11 +471,6 @@ COPTS.OpenDis.c+= -Wno-error # XXX xf86bigfstr.h
COPTS.XlibInt.c+= -Wno-error # XXX xcmiscstr.h
COPTS.XKBBind.c+= -Wno-deprecated-declarations # uses XKeycodeToKeysym

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.lcWrap.c+= -O0
-.endif
-
CWARNFLAGS.clang+= -Wno-string-plus-int

.include "${NETBSDSRCDIR}/external/mit/xorg/tools/makekeys/Makefile.makekeys"
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile
index e86a63aaea7..678537066ed 100644
--- a/games/gomoku/Makefile
+++ b/games/gomoku/Makefile
@@ -9,10 +9,6 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}

-.if ${MACHINE} == "vax"
-COPTS.pickmove.c += -O0
-.endif
-
#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index e9c53f23ae5..b919dac17c6 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -52,7 +52,3 @@ map: map.c
./map | plot > /dev/tty

.include <bsd.prog.mk>
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/i18n_module/UTF7/Makefile b/lib/i18n_module/UTF7/Makefile
index 712c1515d42..7136f7f0cc3 100644
--- a/lib/i18n_module/UTF7/Makefile
+++ b/lib/i18n_module/UTF7/Makefile
@@ -3,6 +3,3 @@
SRCPRE=citrus_
.include <bsd.lib.mk>

-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.citrus_utf7.c+= -O0
-.endif
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b2aea1e04b0..e60a2862d48 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -15,11 +15,6 @@ SRCS= blocksort.c huffman.c crctable.c randtable.c compress.c \
INCS= bzlib.h
INCSDIR= /usr/include

-# XXX huffman.c gets mis-compiled with 2.95.3
-.if ${MACHINE_ARCH} == "vax"
-COPTS+= -O0
-.endif
-
COPTS+= ${CC_WNO_IMPLICIT_FALLTHROUGH}

# XXX blocksort.c gets mis-compiled with 4.1
diff --git a/lib/libc/gdtoa/Makefile.inc b/lib/libc/gdtoa/Makefile.inc
index 132686fc33d..609da919803 100644
--- a/lib/libc/gdtoa/Makefile.inc
+++ b/lib/libc/gdtoa/Makefile.inc
@@ -44,10 +44,3 @@ SRCS+= dmisc.c \
.if ${MACHINE_ARCH} != "vax"
SRCS+= strtord.c
.endif
-
-# XXX revisit with newer GCC.
-# Ensure numbers like 0xffff319f5fa95963 print correctly
-# ("999999999999999.98", not garbage like "?A>C>@>C:BA;A><.:<")
-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index cb3f89d6d09..e9c8be820da 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -30,9 +30,6 @@ SRCS+= crypt-argon2.c
SRCS+= ${src}
COPTS.${src}+= -fvisibility=hidden
. endfor
-. if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-. endif
.endif

WARNS?= 5
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
index f5baae1e883..24f7e1121e5 100644
--- a/libexec/ld.elf_so/Makefile
+++ b/libexec/ld.elf_so/Makefile
@@ -141,10 +141,6 @@ CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector

-.if ${MACHINE_CPU} == "vax"
-COPTS.rtld.c+= -O0
-.endif
-
LDADD+= -Wl,--version-script=${.CURDIR}/symbols.map
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
diff --git a/sbin/fsck_ffs/Makefile.common b/sbin/fsck_ffs/Makefile.common
index 765638b2801..824e3bf2628 100644
--- a/sbin/fsck_ffs/Makefile.common
+++ b/sbin/fsck_ffs/Makefile.common
@@ -36,7 +36,3 @@ COPTS.ffs_appleufs.c+= -Wno-pointer-sign
.if ${MACHINE_ARCH} == "m68000"
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif
-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-.endif
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index c039f73a1eb..3b0331e5880 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -39,12 +39,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-COPTS.fsdb.c+= -O0
-.endif
-
CWARNFLAGS.gcc+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

.include <bsd.prog.mk>
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 40a44b9a038..ecfdbff4d3a 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -20,8 +20,4 @@ DPADD+=${LIBPROP}

.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mke2fs.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 4f33501ea7a..1f7f56e3ea5 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -12,8 +12,4 @@ CPPFLAGS+= -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax
index cf095d54a86..c483eaa644a 100644
--- a/sys/arch/vax/conf/Makefile.vax
+++ b/sys/arch/vax/conf/Makefile.vax
@@ -34,7 +34,6 @@ GENASSYM_CONF= ${VAX}/vax/genassym.cf
CPPFLAGS+= -D_VAX_INLINE_
AFLAGS+= -x assembler-with-cpp -fno-pic
CFLAGS+= -fno-pic
-COPTS.wsmux.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -O1 :}


##
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 718c97ce857..4ef3840c753 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -96,7 +96,3 @@ SRCS+= ufs.c
lib${LIB}.o:: ${OBJS:O} __buildstdlib

CPPFLAGS+= -Wno-pointer-sign
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.bootp.c+= -O0
-.endif
diff --git a/sys/lib/libz/Makefile b/sys/lib/libz/Makefile
index 6945c0da6c6..61fb7d4f652 100644
--- a/sys/lib/libz/Makefile
+++ b/sys/lib/libz/Makefile
@@ -25,7 +25,3 @@ CLEANFILES+= lib${LIB}.o
.include <bsd.lib.mk>

lib${LIB}.o:: ${OBJS:O} __buildstdlib
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.inftrees.c+= -O0
-.endif
diff --git a/sys/modules/lfs/Makefile b/sys/modules/lfs/Makefile
index 962538821a5..ea8f187e160 100644
--- a/sys/modules/lfs/Makefile
+++ b/sys/modules/lfs/Makefile
@@ -18,9 +18,4 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_inode.c ulfs_lookup.c \

WARNS= 3

-.if ${MACHINE} == "vax"
-# GCC 6.5 and 7.4 cannot compile this with -DDIAGNOSTIC and -O2/-O1
-COPTS.lfs_inode.c+= -O0
-.endif
-
.include <bsd.kmodule.mk>
diff --git a/sys/rump/fs/lib/liblfs/Makefile b/sys/rump/fs/lib/liblfs/Makefile
index abade3767d9..68b74c62502 100644
--- a/sys/rump/fs/lib/liblfs/Makefile
+++ b/sys/rump/fs/lib/liblfs/Makefile
@@ -17,9 +17,6 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_extattr.c \


CFLAGS+= -DLFS_KERNEL_RFW
-.if ${MACHINE_ARCH} == "vax"
-COPTS.lfs_inode.c+=-O0
-.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff --git a/usr.sbin/mtrace/Makefile b/usr.sbin/mtrace/Makefile
index aef09db6198..9c125c15265 100644
--- a/usr.sbin/mtrace/Makefile
+++ b/usr.sbin/mtrace/Makefile
@@ -12,10 +12,6 @@ PROG= mtrace
SRCS= igmp.c inet.c kern.c mtrace.c
MAN= mtrace.8

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mtrace.c=-O0
-.endif
-
BINMODE=4555
BINOWN= root

diff --git a/external/gpl3/gcc.old/usr.bin/backend/Makefile b/external/gpl3/gcc.old/usr.bin/backend/Makefile
index d69a26fe619..99e881c783d 100644
--- a/external/gpl3/gcc.old/usr.bin/backend/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/backend/Makefile
@@ -533,68 +533,9 @@ COPTS.insn-recog.c+=-Wno-error

.if ${GCC_MACHINE_ARCH} == "vax"
CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
-COPTS.builtins.c+=-O0
-COPTS.calls.c+=-O0
-COPTS.convert.c+=-O0
-COPTS.data-streamer-out.c+=-O0
-COPTS.dse.c+=-O0 # XXX port-vax/51967
-COPTS.dwarf2out.c+=-O0
-COPTS.expmed.c+=-O0
-COPTS.expr.c+=-O0 -Wno-error=tautological-compare
-COPTS.fixed-value.c+=-O0
-COPTS.fold-const.c+=-O0
-COPTS.generic-match.c+=-O0
-COPTS.gimple-fold.c+=-O0
-COPTS.gimple-match.c+=-O0
-COPTS.gimple-ssa-strength-reduction.c+=-O0
-COPTS.gimple-ssa-warn-restrict.c+=-O0
-COPTS.gimple.c+=-O0
-COPTS.internal-fn.c+=-O0
-COPTS.lto-streamer-out.c+=-O0
-COPTS.omp-low.c+=-O0
-COPTS.predict.c+=-O0
-COPTS.range-op.cc+=-O0
-COPTS.recog.c+=-O0
-COPTS.sanopt.c+=-O0
-COPTS.stmt.c+=-O0
-COPTS.stor-layout.c+=-O0
-COPTS.targhooks.c+=-O0
-COPTS.tree-affine.c+=-O0
-COPTS.tree-cfg.c+=-O0
-COPTS.tree-data-ref.c+=-O0
-COPTS.tree-eh.c+=-O0
-COPTS.tree-if-conv.c+=-O0
-COPTS.tree-object-size.c+=-O0
-COPTS.tree-parloops.c+=-O0
-COPTS.tree-predcom.c+=-O0
-COPTS.tree-pretty-print.c+=-O0
-COPTS.tree-ssa-alias.c+=-O0
-COPTS.tree-ssa-ccp.c+=-O0
-COPTS.tree-ssa-forwprop.c+=-O0
-COPTS.tree-ssa-loop-ivopts.c+=-O0
-COPTS.tree-ssa-loop-manip.c+=-O0
-COPTS.tree-ssa-loop-niter.c+=-O0
-COPTS.tree-ssa-math-opts.c+=-O0
-COPTS.tree-ssa-phiopt.c+= -O0
-COPTS.tree-ssa-pre.c+=-O0
-COPTS.tree-ssa-reassoc.c+=-O0
-COPTS.tree-ssa-strlen.c+=-O0
-COPTS.tree-ssa-uninit.c+=-O0
-COPTS.tree-ssa.c+=-O0
-COPTS.tree-switch-conversion.c+=-O0
-COPTS.tree-vect-data-refs.c+=-O0
-COPTS.tree-vect-loop-manip.c+=-O0
-COPTS.tree-vect-loop.c+=-O0
-COPTS.tree-vect-patterns.c+=-O0
-COPTS.tree-vect-stmts.c+=-O0
-COPTS.tree-vrp.c+=-O0
-COPTS.tree.c+=-O0
-COPTS.ubsan.c+=-O0
-COPTS.varasm.c+=-O0
-COPTS.vr-values.c+=-O0
-COPTS.web.c+=-O0
-COPTS.wide-int-range.cc+=-O0
-COPTS.wide-int.cc+=-O0
+
+COPTS.expmed.c+=-Wno-error=tautological-compare
+COPTS.expr.c+=-Wno-error=tautological-compare
.else
COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
.endif
 1.2 28-Oct-2019  christos branches: 1.2.8;
inode.c needs -O0 for vax
 1.1 08-Feb-2017  rin branches: 1.1.2; 1.1.4; 1.1.16;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.1.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.4.1 08-Feb-2017  bouyer file Makefile.common was added on branch bouyer-socketcan on 2017-04-21 16:53:13 +0000
 1.1.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.1 08-Feb-2017  pgoyette file Makefile.common was added on branch pgoyette-localcount on 2017-03-20 06:57:01 +0000
 1.2.8.1 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #394):

external/gpl3/binutils/dist/gas/config/tc-vax.h: revision 1.10
tools/gcc/Makefile: revision 1.109
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.16
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.17
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/recog.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/function.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/dse.c: revision 1.14 - 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.13
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.15
external/gpl3/gcc.old/dist/gcc/doc/tm.texi.in: revision 1.10
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.19
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.13
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.20
external/gpl3/gcc.old/dist/gcc/targhooks.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.15
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.13
external/gpl3/gcc.old/dist/gcc/doc/tm.texi: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.13
external/gpl3/gcc.old/dist/gcc/targhooks.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/target.def: revision 1.10
external/gpl3/gcc.old/dist/gcc/rtlanal.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/reload.c: revision 1.12
external/gpl3/gcc.old/usr.bin/gcc/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/lto-dump/Makefile: revision 1.3
external/gpl3/gcc.old/lib/Makefile.sanitizer: revision 1.7
external/gpl3/binutils.old/lib/libbfd/Makefile: revision 1.10
distrib/utils/x_ping/Makefile: revision 1.9
games/phantasia/Makefile: revision 1.38
external/apache2/argon2/lib/libargon2/Makefile.inc: revision 1.2
external/gpl3/gcc.old/lib/libubsan/Makefile: revision 1.8
external/bsd/mdocml/lib/libmandoc/Makefile: revision 1.13
sbin/ping/Makefile: revision 1.18
sbin/newfs_ext2fs/Makefile: revision 1.7
sys/lib/libz/Makefile: revision 1.24
sys/lib/libsa/Makefile: revision 1.97
external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile: revision 1.3
external/gpl3/gdb/lib/libgdb/Makefile: revision 1.36
sys/modules/lfs/Makefile: revision 1.11
external/mit/xorg/lib/gallium/Makefile: revision 1.51
external/gpl3/gdb.old/lib/libdecnumber/Makefile: revision 1.10
external/mit/xorg/lib/libX11/Makefile.libx11: revision 1.26
libexec/ld.elf_so/Makefile: revision 1.148
external/bsd/jemalloc/lib/Makefile.inc: revision 1.16
external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile: revision 1.14
crypto/external/bsd/openssh/lib/Makefile: revision 1.38
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.21
external/gpl3/gcc.old/usr.bin/cc1/Makefile: revision 1.12
external/gpl3/gcc.old/lib/libasan/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/cc1plus/Makefile: revision 1.13
lib/libcrypt/Makefile: revision 1.36
external/gpl3/gdb/lib/libdecnumber/Makefile: revision 1.5
lib/libc/gdtoa/Makefile.inc: revision 1.13
games/gomoku/Makefile: revision 1.13
sbin/fsdb/Makefile: revision 1.43
external/gpl3/gcc.old/usr.bin/lto1/Makefile: revision 1.9
external/mit/xorg/lib/gallium.old/Makefile: revision 1.8
lib/libbz2/Makefile: revision 1.22
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.12
usr.sbin/mtrace/Makefile: revision 1.14
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.13
sys/arch/vax/conf/Makefile.vax: revision 1.86
sys/rump/fs/lib/liblfs/Makefile: revision 1.18
sbin/fsck_ffs/Makefile.common: revision 1.3
external/gpl3/binutils/lib/libbfd/Makefile: revision 1.27
lib/i18n_module/UTF7/Makefile: revision 1.5
external/gpl3/gcc.old/lib/liblsan/Makefile: revision 1.7
doc/CHANGES (apply patch)
(all external/gpl3/gcc.old/ changes applied to external/gpl3/gcc/)

PR 57646: Import major vax toolchain fix.
 1.62 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.61 05-May-2019  christos Add a -z flag to zero out the up to 4 bytes of padding in directory entry
names (including the terminating NUL), as well as directory entries with
extra free space (d->d_reclen > UFS_DIRSIZ(d)).

Inspired from FreeBSD:
https://svnweb.freebsd.org/base?view=revision&revision=347066

While the kernel has been fixed to deal with the padding bytes (new
kernels will correctly zero out all the padding after the name), it
appears that there is still an issue with directory entries with extra
free space, since a newly created and populated filesystem gets modified
with "fsck_ffs -z".
 1.60 05-May-2019  christos simplify the endian byte-swapping code.
 1.59 08-Nov-2018  msaitoh "s/ are are / are /" in comment. No functional change.
 1.58 08-Feb-2017  rin branches: 1.58.10; 1.58.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.57 23-Jun-2013  dholland branches: 1.57.10; 1.57.14;
Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.56 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.55 09-Jun-2013  dholland Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.54 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.53 06-Mar-2011  bouyer branches: 1.53.4; 1.53.10;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.52 11-Apr-2009  lukem branches: 1.52.2;
fix sign-compare issues
 1.51 08-Jul-2008  simonb branches: 1.51.4;
Fix funny whitespace in a variable assignment.
 1.50 23-Feb-2008  christos branches: 1.50.4; 1.50.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.49 16-Oct-2006  christos branches: 1.49.8; 1.49.16; 1.49.18;
c99 initializers
 1.48 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.47 23-Dec-2005  yamt linkup: reparent() only when lost+found is created successfully.
 1.46 19-Aug-2005  christos 64 bit inode changes
 1.45 27-Jun-2005  christos sprinkle const.
 1.44 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.43 20-Jan-2005  xtraeme whitespace (pointed out by wiz@)
 1.42 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.41 08-Oct-2004  dbj have allocdir fail cleanly when allocino fails
 1.40 20-Jul-2004  mycroft Reduce memory usage slightly.
 1.39 10-Jan-2004  mrg - some KNF (80 cols)
- fix a printf format issue
 1.38 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.37 13-Jul-2003  itojun use bounded string op
 1.36 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.35 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.34 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.33 09-May-2002  simonb Don't bother testing if a uint8_t is > 256 -- that test is always false.
 1.32 23-Jan-2001  mycroft Fix a rather glaring byte-swapping bug: di_size is 64 bits, not 16.
 1.31 10-Jan-2001  mycroft Whoops; call propagate() with the right child inode number. (Doesn't break
anything, but it would have made reconnect less efficient.)
 1.30 10-Jan-2001  mycroft Abstract the code to attach a directory to its parent's child list into a
separate function, and call it from multiple places in linkup() to handle
reconnects and creation of /lost+found.
 1.29 09-Jan-2001  mycroft The reconnect algorithm was historically O(n^4).
Some years ago I made it O(n^2).
Someone helpfully made it O(n^4) again.
Today I'm making it O(n).
If that's not good enough, I don't know what else to do. B-)

Technical details:
* The graph traversal in propagate() is modified to be able to start from any
point in the tree. To handle certain exceptional cases, it is also modified
to work in two passes, marking the tree with a special tag and then changing
it to DFOUND.
* The reconnect case now modifies the child/sibling pointers and calls
propagate() to propagate the connection state starting with the reconnected
directory.

Pray that you never encounter a file system trashed enough for this to matter.
 1.28 14-Dec-2000  simonb Need an lfdir global variable now.
 1.27 03-Aug-2000  castor Fix an evil ugly bug which causes files placed into lost+found to
be inconsistent, and unremovable. From Ethan Solomita <ethan@geocast.com>.
Reviewed by fvdl.
 1.26 15-Nov-1999  fvdl branches: 1.26.4;
Changes for softdep code.
 1.25 18-Mar-1998  bouyer branches: 1.25.2; 1.25.4; 1.25.8;
Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.24 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.23 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.22 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.21 21-Apr-1997  mrg lost+found directories are mode -1700
 1.20 27-Sep-1996  christos - util.h -> fsutil.h
 1.19 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.18 11-Jun-1996  mycroft Use a different tree-walking algorithm in propagate().
 1.17 18-Mar-1995  cgd branches: 1.17.4;
convert to new RCS Id conventions; reduce my headache
 1.16 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.15 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.14 28-Oct-1994  mycroft On a recursive call to fsck_readdir() through getpathname(), don't attempt to
fix a problem that's already being fixed.
 1.13 06-Oct-1994  mycroft dircheck() shouldn't be looking at d_type or d_namlen in blank entries
*at all*. Not only is it wrong, but it causes a serious problem on
little-endian machines, since after -c2 conversion, d_type will often
be > 15.
 1.12 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.11 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.10 20-Sep-1994  mycroft A correct fix for the byte order problem when reconnecting.
 1.9 29-Jul-1994  mycroft Fix oversight in last patch.
 1.8 28-Jul-1994  mycroft Fix byte-order problem with directory entry creation.
 1.7 08-Jun-1994  mycroft branches: 1.7.2;
Update from 4.4-Lite, with local changes.
 1.6 25-Apr-1994  cgd need <sys/time.h>
 1.5 05-Nov-1993  mycroft Patch from Bruce Evans to deal with file names with NULs in them.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.5 07-Nov-1994  cgd for patch #2
 1.7.2.4 06-Oct-1994  mycroft dircheck() shouldn't be looking at d_type or d_namlen in blank entries
*at all*. Not only is it wrong, but it causes a serious problem on
little-endian machines, since after -c2 conversion, d_type will often
be > 15.
 1.7.2.3 20-Sep-1994  mycroft A correct fix for the byte order problem when reconnecting.
 1.7.2.2 29-Jul-1994  cgd from trunk.
 1.7.2.1 28-Jul-1994  cgd from trunk.
 1.17.4.1 10-Dec-1996  mycroft From trunk:
* Redo the tree-walking algorithm to make it O(n) rather than O(n^2).
* Fix some minor type size problems.
 1.25.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.25.2.1 22-Aug-2000  castor pullup changes between 1.26 and 1.27

revision 1.27
date: 2000/08/03 14:52:39; author: castor; state: Exp; lines: +12 -2
Fix an evil ugly bug which causes files placed into lost+found
to be inconsistent, and unremovable. From Ethan Solomita
<ethan@geocast.com>. Reviewed by fvdl.

pullup requested by Haavard Eidnes -- assuming that this was actually a
request from releng-1-4.
 1.26.4.2 24-Nov-2001  he Pull up revisions 1.28-1.32 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.26.4.1 03-Aug-2000  castor Pullup changes between 1.26 and 1.27 from -current.
Requested by castor. Approved by thorpej.

> revision 1.27
> date: 2000/08/03 14:52:39; author: castor; state: Exp; lines: +12 -2
> Fix an evil ugly bug which causes files placed into lost+found to
> be inconsistent, and unremovable. From Ethan Solomita <ethan@geocast.com>.
> Reviewed by fvdl.
 1.49.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.49.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.49.16.1 24-Mar-2008  keiichi sync with head.
 1.49.8.1 23-Mar-2008  matt sync with HEAD
 1.50.6.1 18-Jul-2008  simonb Sync with head.
 1.50.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.51.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.52.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.53.10.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.53.10.2 23-Jun-2013  tls resync from head
 1.53.10.1 25-Feb-2013  tls resync with head
 1.53.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.53.4.1 23-Jan-2013  yamt sync with head
 1.57.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.57.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.58.12.1 10-Jun-2019  christos Sync with HEAD
 1.58.10.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.29 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.28 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.27 09-Jun-2011  christos share more code.
 1.26 06-Mar-2011  bouyer branches: 1.26.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.25 13-Sep-2009  bouyer branches: 1.25.2;
Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.24 30-Aug-2008  bouyer branches: 1.24.2; 1.24.8;
Add fss(4) snapshot support to fsck_ffs(8) (via -x or -X options, like
dump(8)). This allows fsck_ffs -n to work on a snapshot of a R/W mounted
filesystem, and avoid errors related to filesystem activity.
 1.23 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.22 27-Jun-2005  christos branches: 1.22.20; 1.22.24; 1.22.26;
sprinkle const.
 1.21 20-Jan-2005  xtraeme whitespace (pointed out by wiz@)
 1.20 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.19 09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.18 13-Jul-2003  itojun use bounded string op
 1.17 06-Apr-2003  fvdl Write update some old fields when writing the superblock, similar to
ffs_oldfscompat_write() in the kernel. Use the old totals when
time < old_time (i.e. an old kernel or fsck wrote the filesystem last).
When setting the date back on a new kernel, that works out ok, since
new kernels always update both fields.
 1.16 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.15 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.14 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.13 04-Feb-2001  christos remove redundant declarations
 1.12 26-Jan-2001  thorpej In pass 5, check alternate superblocks for consistency with
the current in-core master superblock, and fix them up if
they're incorrect. Move the code that writes the alternate
superblocks if (cvtlevel || doswap) into pass 5 for efficiency.

Reviewd by Charles Hannum, and used by me to fix up a curdled
file system.
 1.11 09-Jan-2001  mycroft The reconnect algorithm was historically O(n^4).
Some years ago I made it O(n^2).
Someone helpfully made it O(n^4) again.
Today I'm making it O(n).
If that's not good enough, I don't know what else to do. B-)

Technical details:
* The graph traversal in propagate() is modified to be able to start from any
point in the tree. To handle certain exceptional cases, it is also modified
to work in two passes, marking the tree with a special tag and then changing
it to DFOUND.
* The reconnect case now modifies the child/sibling pointers and calls
propagate() to propagate the connection state starting with the reconnected
directory.

Pray that you never encounter a file system trashed enough for this to matter.
 1.10 26-Jul-1998  mycroft branches: 1.10.12;
const poisoning.
 1.9 26-Jul-1998  mycroft Remove redundant declaration.
 1.8 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.7 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.6 27-Sep-1996  christos - util.h -> fsutil.h
 1.5 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.4 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 06-Dec-1994  cgd adjust; from jimj.
 1.1 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.10.12.1 24-Nov-2001  he Pull up revisions 1.11-1.13 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.22.26.2 28-Jul-2008  simonb Add support for creating a WAPBL log in the filesystem. Will
create an in-filesystem log on first "mount -o log" if one doesn't
exist, and will then continue to use same log in the future. See
(soon to be added) wapbl(4) for more info.

Adds a new B_CONTIG low-level allocation flag that uses hints in
"struct ffs_inode_ext" to lay out an ffs file's data contiguously.

Thanks to Greg Oster for helping with the design of this and to
Antti Kantee for code review and suggestions.
 1.22.26.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.22.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.22.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.24.8.1 21-Apr-2010  matt sync to netbsd-5
 1.24.2.1 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1036):
sbin/fsck_ffs/extern.h: revision 1.25 via patch
sbin/fsck_ffs/setup.c: revision 1.88 via patch
sbin/fsck_ffs/wapbl.c: revision 1.4 via patch
sbin/tunefs/tunefs.c: revision 1.41 via patch
sys/ufs/ffs/ffs_vfsops.c: revision 1.252 via patch
sys/ufs/ffs/ffs_wapbl.c: revision 1.13 via patch
Allow tunefs to clear any type of WAPBL log, not only in-filesystem
ones. Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
If the WAPBL journal can't be read (ffs_wapbl_replay_start() fails),
mount the filesystem anyway if MNT_FORCE is present.
This allows to still boot single-user a system with a corrupted
WAPBL on /, and so get a chance to run fsck to fix it.
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.25.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.26.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2 21-Sep-1997  lukem unnecessary file from lite-2 merge
 1.1 16-Sep-1997  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 16-Sep-1997  lukem imported from lite-2
 1.59 04-Mar-2025  andvar s/ownerchip/ownership/ in comment.
 1.58 04-Jul-2023  riastradh branches: 1.58.2;
fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.57 14-Jan-2023  christos catch up with sign changes in the fs.h
 1.56 17-Nov-2022  chs branches: 1.56.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.55 18-Apr-2020  jdolecek add NO_IOBUF_ALIGNED to not pull aligned_alloc() for really constrained
boot media
 1.54 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.53 05-May-2019  christos Add a -z flag to zero out the up to 4 bytes of padding in directory entry
names (including the terminating NUL), as well as directory entries with
extra free space (d->d_reclen > UFS_DIRSIZ(d)).

Inspired from FreeBSD:
https://svnweb.freebsd.org/base?view=revision&revision=347066

While the kernel has been fixed to deal with the padding bytes (new
kernels will correctly zero out all the padding after the name), it
appears that there is still an issue with directory entries with extra
free space, since a newly created and populated filesystem gets modified
with "fsck_ffs -z".
 1.52 08-Feb-2017  rin branches: 1.52.12;
__empty -> __nothing
 1.51 08-Feb-2017  christos use __empty
 1.50 08-Feb-2017  rin Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.49 06-Mar-2011  bouyer branches: 1.49.26; 1.49.30;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.48 12-Sep-2010  drochner branches: 1.48.2;
minimal ansification/constification
 1.47 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.46 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.45 21-Apr-2006  skrll branches: 1.45.4; 1.45.10; 1.45.18; 1.45.20;
Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.44 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.43 27-Jun-2005  christos sprinkle const.
 1.42 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.41 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.40 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.39 20-Jul-2004  mycroft Reduce memory usage slightly.
 1.38 25-May-2004  hannken Add ffs internal snapshots. Written by Marshall Kirk McKusick for FreeBSD.

- Not enabled by default. Needs kernel option FFS_SNAPSHOT.
- Change parameters of ffs_blkfree.
- Let the copy-on-write functions return an error so spec_strategy
may fail if the copy-on-write fails.
- Change genfs_*lock*() to use vp->v_vnlock instead of &vp->v_lock.
- Add flag B_METAONLY to VOP_BALLOC to return indirect block buffer.
- Add a function ffs_checkfreefile needed for snapshot creation.
- Add special handling of snapshot files:
Snapshots may not be opened for writing and the attributes are read-only.
Use the mtime as the time this snapshot was taken.
Deny mtime updates for snapshot files.
- Add function transferlockers to transfer any waiting processes from
one lock to another.
- Add vfsop VFS_SNAPSHOT to take a snapshot and make it accessible through
a vnode.
- Add snapshot support to ls, fsck_ffs and dump.

Welcome to 2.0F.

Approved by: Jason R. Thorpe <thorpej@netbsd.org>
 1.37 09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.36 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.35 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.34 24-Apr-2003  fvdl Oops. The clearinode macro had the UFS2 case reversed, causing it to
zero out two inodes in the plain FFS case, since UFS2 dinodes are
twice as big.
 1.33 06-Apr-2003  fvdl Write update some old fields when writing the superblock, similar to
ffs_oldfscompat_write() in the kernel. Use the old totals when
time < old_time (i.e. an old kernel or fsck wrote the filesystem last).
When setting the date back on a new kernel, that works out ok, since
new kernels always update both fields.
 1.32 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.31 29-Mar-2003  wiz Consistently spell occurrence with two rs.
 1.30 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.29 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.28 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.27 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.26 15-Aug-2001  lukem - implement -F; treat provided filesystems as images in regular files
- replace "filesystem" with "file system" as appropriate
- grammar fixes
 1.25 15-Aug-2001  lukem minor whitespace cleanup
 1.24 04-Feb-2001  christos remove redundant declarations
 1.23 26-Jan-2001  thorpej In pass 5, check alternate superblocks for consistency with
the current in-core master superblock, and fix them up if
they're incorrect. Move the code that writes the alternate
superblocks if (cvtlevel || doswap) into pass 5 for efficiency.

Reviewd by Charles Hannum, and used by me to fix up a curdled
file system.
 1.22 09-Jan-2001  mycroft The reconnect algorithm was historically O(n^4).
Some years ago I made it O(n^2).
Someone helpfully made it O(n^4) again.
Today I'm making it O(n).
If that's not good enough, I don't know what else to do. B-)

Technical details:
* The graph traversal in propagate() is modified to be able to start from any
point in the tree. To handle certain exceptional cases, it is also modified
to work in two passes, marking the tree with a special tag and then changing
it to DFOUND.
* The reconnect case now modifies the child/sibling pointers and calls
propagate() to propagate the connection state starting with the reconnected
directory.

Pray that you never encounter a file system trashed enough for this to matter.
 1.21 13-Dec-2000  scw Some more `extern's for initialised globals.
 1.20 15-Nov-1999  fvdl branches: 1.20.4;
Update for softdep code.
 1.19 15-Jan-1999  bouyer branches: 1.19.4; 1.19.8;
#include machine/bswap.h and remove -lutil.
 1.18 23-Oct-1998  thorpej Use DINODE_SIZE rather than sizeof(struct dinode) and/or pointer arithmetic.
 1.17 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.16 21-Sep-1997  lukem a quad_t is an int64_t, not a u_int64_t...
 1.15 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.14 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.13 11-Oct-1996  thorpej Bug fix from Kirk McKusick <mckusick@McKusick.COM>:

Fix a bug in fsck_ffs where if a directory somehow develops a hole
(that is a block pointer that has a value of zero), fsck would give the
filesystem a clean bill of health, but the kernel would panic when
accessing the directory with the hole. Fsck now checks for holes
in directories. If found in preen mode, fsck fails. In manual
mode, it can be directed to shorten the directory to the beginning of
the hole. A more complete solution would be to allocate a block to fill
the hole. However, this is a lot more work for a `cannot happen' error,
so the extra effort seems unwarranted.
 1.12 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.11 11-Jun-1996  mycroft Use a different tree-walking algorithm in propagate().
 1.10 12-Apr-1995  mycroft branches: 1.10.4;
Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.9 21-Mar-1995  cgd type sizes
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 02-May-1994  pk Prototype some things.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.4.2 02-Mar-1997  mycroft Pull up changes from Kirk McKusick to check for holes in directories.
 1.10.4.1 10-Dec-1996  mycroft From trunk:
* Redo the tree-walking algorithm to make it O(n) rather than O(n^2).
* Fix some minor type size problems.
 1.19.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.20.4.2 25-Nov-2001  he Pull up revision 1.27 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.20.4.1 24-Nov-2001  he Pull up revisions 1.21-1.24 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.45.20.2 17-Jan-2009  mjf Sync with HEAD.
 1.45.20.1 03-Apr-2008  mjf Sync with HEAD.
 1.45.18.1 24-Mar-2008  keiichi sync with head.
 1.45.10.1 23-Mar-2008  matt sync with HEAD
 1.45.4.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.48.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.49.30.1 21-Apr-2017  bouyer Sync with HEAD
 1.49.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.52.12.3 21-Apr-2020  martin Sync with HEAD
 1.52.12.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.52.12.1 10-Jun-2019  christos Sync with HEAD
 1.56.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #162):

sbin/fsck_ffs/inode.c: revision 1.74
sbin/fsck_ffs/utilities.c: revision 1.68
sbin/fsck_ffs/fsck.h: revision 1.57
sbin/fsck_ffs/pass4.c: revision 1.30

catch up with sign changes in the fs.h
 1.58.2.1 02-Aug-2025  perseant Sync with HEAD
 1.52 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.51 05-May-2019  christos Add a -z flag to zero out the up to 4 bytes of padding in directory entry
names (including the terminating NUL), as well as directory entries with
extra free space (d->d_reclen > UFS_DIRSIZ(d)).

Inspired from FreeBSD:
https://svnweb.freebsd.org/base?view=revision&revision=347066

While the kernel has been fixed to deal with the padding bytes (new
kernels will correctly zero out all the padding after the name), it
appears that there is still an issue with directory entries with extra
free space, since a newly created and populated filesystem gets modified
with "fsck_ffs -z".
 1.50 11-Sep-2016  sevan branches: 1.50.14;
Document the version fsck_ffs first appeared.
Bump date.
 1.49 06-Mar-2012  wiz Mention scan_ffs -b.
Based on a patch by Matthew Mondor <mm_lists@pulsar-zone.net> on
tech-userlevel.
Bump date.
 1.48 14-May-2011  dholland branches: 1.48.4;
Improve documentation of FFS formats and format levels from PR 32100.
Prompted also by recent discussion on tech-kern. Bump date.
 1.47 29-Apr-2011  wiz Re-add -q description that got lost when -x was added.
Sort descriptions.
Bump date.
 1.46 07-May-2009  wiz New sentence, new line.
 1.45 07-May-2009  lukem Use "FFSv2" instead of "UFS2".
Expand the description of -c.
Xref dumpfs.
 1.44 09-Oct-2008  christos branches: 1.44.4;
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.43 30-Aug-2008  gdt Add an explanation of why one would want to use -x/-X, after
discussion with bouyer@.
 1.42 30-Aug-2008  bouyer Add fss(4) snapshot support to fsck_ffs(8) (via -x or -X options, like
dump(8)). This allows fsck_ffs -n to work on a snapshot of a R/W mounted
filesystem, and avoid errors related to filesystem activity.
 1.41 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.40 19-Jan-2005  wiz branches: 1.40.10; 1.40.26; 1.40.30; 1.40.32;
Sort options. Bump date for -P. Remove superfluous -.
 1.39 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.38 02-Jun-2004  fair Correct a misnumbering of options, as noted in PR 25784.
 1.37 05-May-2004  wiz Various improvements; mostly mention arguments of flags by name to
simplify the description and improve lists.
 1.36 09-Jan-2004  wiz branches: 1.36.2;
Update Dd for previous and fix a case.
 1.35 09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.34 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.33 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.32 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.31 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.30 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.29 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.28 07-Feb-2002  ross Edit -mdoc usage.

* There is no -indent option to .Bd or .Bl, although you would
never know that from its frequent use in this tree. There is a
"-offset indent" combination that makes sense, and you can certainly
say "-width indent".

* Also, you can't markup the -width option argument, tho you CAN
use a callable macro. So "-width Ar filename" doesn't make sense,
but either "-width Ar" or "-width filename" does, as might something
like "-width xxfilename" for a little extra space.

* There are a lot of needlessly complex hanging tag macros in man4 used
to create simple item lists. Those should be simplified one of these
days before someone copies and edits yet another man4 page.
 1.27 16-Nov-2001  wiz Sort SEE ALSO, whitespace nits.
 1.26 16-Nov-2001  lukem - changes to -F semantics:
- remove the restriction that filesystem must be a regular file
- don't try and read a disklabel
- use `p' (instead of `h') as the index of the last partition
 1.25 15-Aug-2001  lukem - implement -F; treat provided filesystems as images in regular files
- replace "filesystem" with "file system" as appropriate
- grammar fixes
 1.24 05-Jun-2001  wiz Drop arguments of .Os.
 1.23 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.22 25-May-1998  msaitoh fix typo.
 1.21 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.20 15-Sep-1997  lukem use .Nm correctly
 1.19 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.18 21-Apr-1997  mrg lost+found directories are mode -1700
 1.17 21-Apr-1997  lukem The fs level (ref: fsck -c ...) can be determined from the second
line of the output from dumpfs(8), not the first line. part of [bin/1353]
 1.16 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.15 27-Dec-1996  mikel fix reboot(8) xref
 1.14 26-Dec-1996  mikel eliminate obsolete references to mkfs(8);
from Klaus Klein <kleink@layla.inka.de>
 1.13 22-Oct-1996  christos Update this to reflect reality after the fsck/fsck_ffs split.
 1.12 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.11 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.10 12-Jul-1995  cgd implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 13-Apr-1994  deraadt typo
 1.5 05-Aug-1993  jtc Updated to -mandoc macros.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.36.2.1 06-Jun-2004  jdc Pull up revision 1.38 (via patch) (requested by fair in ticket #435).

Correct a misnumbering of options, as noted in PR 25784.
 1.40.32.1 28-Jul-2008  simonb Add support for creating a WAPBL log in the filesystem. Will
create an in-filesystem log on first "mount -o log" if one doesn't
exist, and will then continue to use same log in the future. See
(soon to be added) wapbl(4) for more info.

Adds a new B_CONTIG low-level allocation flag that uses hints in
"struct ffs_inode_ext" to lay out an ffs file's data contiguously.

Thanks to Greg Oster for helping with the design of this and to
Antti Kantee for code review and suggestions.
 1.40.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.40.26.2 17-Jan-2009  mjf Sync with HEAD.
 1.40.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.40.10.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.44.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.48.4.1 17-Apr-2012  yamt sync with head
 1.50.14.1 10-Jun-2019  christos Sync with HEAD
 1.79 25-Feb-2025  andvar Fix a few typos in the word 'offset' in comments and error message.
 1.78 05-Jul-2023  riastradh branches: 1.78.2;
Revert "fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.77 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.76 04-Jul-2023  riastradh fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.75 14-Jan-2023  kre Use %zu rather than %lu to print a size_t (should fix i386 build).

But, philosophical question, shouldn't the product of two size_t
variables really be an area_t, or something like that?
 1.74 14-Jan-2023  christos catch up with sign changes in the fs.h
 1.73 17-Apr-2020  jdolecek branches: 1.73.6;
align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) raw (character) device
 1.72 08-Feb-2017  rin branches: 1.72.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.71 05-Apr-2014  justin branches: 1.71.8; 1.71.12;
Iterate over fields of struct seperately to avoid warnings from pedantic compilers
 1.70 02-Dec-2013  bouyer Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.69 23-Jun-2013  dholland Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.68 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.67 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.66 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.65 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.64 06-Mar-2011  bouyer branches: 1.64.4; 1.64.6; 1.64.10; 1.64.12; 1.64.14;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.63 04-Feb-2010  christos branches: 1.63.2;
Centralize time printing and deal with ctime possibly returning NULL.
 1.62 11-Apr-2009  lukem fix sign-compare issues
 1.61 09-Oct-2008  christos branches: 1.61.4;
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.60 08-Jul-2008  simonb Fix funny whitespace in a variable assignment.
 1.59 23-Feb-2008  christos branches: 1.59.4; 1.59.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.58 12-Apr-2007  chs branches: 1.58.4; 1.58.10; 1.58.12;
apply revision 1.31 yet again:
"make sure that we don't try to allocate negative memory when blks == 0."
or on amd64, "make sure that we don't allocate 32 GB when blks == 0."
 1.57 21-Apr-2006  skrll branches: 1.57.4;
Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.56 19-Aug-2005  christos 64 bit inode changes
 1.55 27-Jun-2005  christos sprinkle const.
 1.54 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.53 30-Apr-2005  christos Remove stray " I" from message.
 1.52 30-Apr-2005  christos Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.51 20-Jan-2005  xtraeme branches: 1.51.2;
whitespace (pointed out by wiz@)
 1.50 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.49 08-Oct-2004  dbj when allocating inodes, such as for the lost+found directory,
extend the inostat array if needed. Otherwise, inoinfo() will
return the static "unallocated" inode template, which was
getting improperly modified.
Before this fix, any time the lost+found directory got created,
fsck would set all of the inode/directory counts wrong since
suddenly unallocated inodes would turn into directory inodes
 1.48 20-Jul-2004  mycroft Reduce memory usage slightly.
 1.47 25-May-2004  hannken Add ffs internal snapshots. Written by Marshall Kirk McKusick for FreeBSD.

- Not enabled by default. Needs kernel option FFS_SNAPSHOT.
- Change parameters of ffs_blkfree.
- Let the copy-on-write functions return an error so spec_strategy
may fail if the copy-on-write fails.
- Change genfs_*lock*() to use vp->v_vnlock instead of &vp->v_lock.
- Add flag B_METAONLY to VOP_BALLOC to return indirect block buffer.
- Add a function ffs_checkfreefile needed for snapshot creation.
- Add special handling of snapshot files:
Snapshots may not be opened for writing and the attributes are read-only.
Use the mtime as the time this snapshot was taken.
Deny mtime updates for snapshot files.
- Add function transferlockers to transfer any waiting processes from
one lock to another.
- Add vfsop VFS_SNAPSHOT to take a snapshot and make it accessible through
a vnode.
- Add snapshot support to ls, fsck_ffs and dump.

Welcome to 2.0F.

Approved by: Jason R. Thorpe <thorpej@netbsd.org>
 1.46 26-Apr-2004  dbj fix 64bit bug in chkrange()
problem noticed by nathanw
fix from freebsd
 1.45 03-Jan-2004  dbj branches: 1.45.2;
fix logic for handling symlinks in inodes when isappleufs
 1.44 03-Jan-2004  dbj when doing both -c 2 and -B, swap the blocks listed in the inode
of symlinks, since the swapping happens before the symlinks
are moved into the inode.
 1.43 03-Jan-2004  dbj fix paste-o in previous commit
 1.42 03-Jan-2004  dbj fix bugs with unsigned comparison ofs fs_maxsymlinklen
 1.41 19-Sep-2003  itojun realloc pedant
 1.40 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.39 13-Jul-2003  itojun use bounded string op
 1.38 08-Apr-2003  fvdl Swap the right blocks in an inode in the byteswapping case.
 1.37 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.36 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.35 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.34 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.33 12-Dec-1999  christos - ARGH /brick fvdl
- Put back the change from revision 1.31
 1.32 15-Nov-1999  fvdl Changes for softdep code.
 1.31 06-Sep-1999  christos branches: 1.31.4;
make sure that we don't try to allocate negative memory when blks == 0.
 1.30 23-Oct-1998  thorpej branches: 1.30.4;
Use DINODE_SIZE rather than sizeof(struct dinode) and/or pointer arithmetic.
 1.29 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.28 01-Apr-1998  kleink Need <time.h> for ctime() and time() prototypes.
 1.27 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.26 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.25 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.24 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.23 11-Oct-1996  thorpej Bug fix from Kirk McKusick <mckusick@McKusick.COM>:

Fix a bug in fsck_ffs where if a directory somehow develops a hole
(that is a block pointer that has a value of zero), fsck would give the
filesystem a clean bill of health, but the kernel would panic when
accessing the directory with the hole. Fsck now checks for holes
in directories. If found in preen mode, fsck fails. In manual
mode, it can be directed to shorten the directory to the beginning of
the hole. A more complete solution would be to allocate a block to fill
the hole. However, this is a lot more work for a `cannot happen' error,
so the extra effort seems unwarranted.
 1.22 27-Sep-1996  christos - util.h -> fsutil.h
 1.21 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.20 11-Jun-1996  mycroft Use a different tree-walking algorithm in propagate().
 1.19 25-May-1996  mycroft File sizes in FFS are u_int64_t.
 1.18 21-May-1996  mycroft branches: 1.18.2;
Adjust the logic a bit so we `nif' can't overflow.
 1.17 17-Dec-1995  thorpej Squish some type bugs pointed out by Jonathan Stone.
 1.16 14-Dec-1995  thorpej Make this compile with -Werror.
 1.15 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.14 20-Mar-1995  mycroft Make sure to recreate the `..' entry in the root directory if missing.
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.11 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.10 14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.9 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.8 02-May-1994  pk Prototype some things.
 1.7 25-Apr-1994  cgd need <sys/time.h>
 1.6 18-Apr-1994  cgd kill some code if SMALL is defined...
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 13-Jun-1993  mycroft Add support for fast symlinks.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.2.2 02-Mar-1997  mycroft Pull up changes from Kirk McKusick to check for holes in directories.
 1.18.2.1 10-Dec-1996  mycroft From trunk:
* Redo the tree-walking algorithm to make it O(n) rather than O(n^2).
* Fix some minor type size problems.
 1.30.4.2 26-Oct-1999  fvdl Fix some merge mistakes.
 1.30.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.31.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.45.2.1 28-Apr-2004  jmc branches: 1.45.2.1.2;
Pullup rev 1.46 (requested by dbj in ticket #202)

Fix 64bit bug in chkrange().
 1.45.2.1.2.1 01-May-2005  tron Pull up revision 1.52 (requested by christos in ticket #1493):
Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.51.2.1 01-May-2005  tron Pull up revision 1.52 (requested by christos in ticket #228):
Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.57.4.2 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.57.4.1 12-Apr-2007  bouyer Pull up following revision(s) (requested by chs in ticket #568):
sbin/fsck_ffs/inode.c: revision 1.58
apply revision 1.31 yet again:
"make sure that we don't try to allocate negative memory when blks == 0."
or on amd64, "make sure that we don't allocate 32 GB when blks == 0."
 1.58.12.3 17-Jan-2009  mjf Sync with HEAD.
 1.58.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.58.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.58.10.1 24-Mar-2008  keiichi sync with head.
 1.58.4.1 23-Mar-2008  matt sync with HEAD
 1.59.6.1 18-Jul-2008  simonb Sync with head.
 1.59.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.61.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.63.2.3 12-Feb-2011  bouyer Skip snapshot inodes for both block and inode quotas.
 1.63.2.2 12-Feb-2011  bouyer Snapshot inode doesn't count for block quotas.
 1.63.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.64.14.1 17-Dec-2013  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/fsck_ffs/inode.c: revision 1.70
Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.64.12.1 17-Dec-2013  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/fsck_ffs/inode.c: revision 1.70
Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.64.10.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.64.10.2 23-Jun-2013  tls resync from head
 1.64.10.1 25-Feb-2013  tls resync with head
 1.64.6.1 17-Dec-2013  riz Pull up following revision(s) (requested by bouyer in ticket #991):
sbin/fsck_ffs/inode.c: revision 1.70
Fix pasto in the !ufs2 case (use dp->dp1 and not of dp->dp2).
This would be a problem only when allocating a new data block and the
indir block is already allocated, which explains why automated tests didn't
find it.
Problem reported on tech-kern@ and fix tested by manu@.
 1.64.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.64.4.1 23-Jan-2013  yamt sync with head
 1.71.12.1 21-Apr-2017  bouyer Sync with HEAD
 1.71.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.72.12.1 21-Apr-2020  martin Sync with HEAD
 1.73.6.2 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #163):

sbin/fsck_ffs/inode.c: revision 1.75

Use %zu rather than %lu to print a size_t (should fix i386 build).
 1.73.6.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #162):

sbin/fsck_ffs/inode.c: revision 1.74
sbin/fsck_ffs/utilities.c: revision 1.68
sbin/fsck_ffs/fsck.h: revision 1.57
sbin/fsck_ffs/pass4.c: revision 1.30

catch up with sign changes in the fs.h
 1.78.2.1 02-Aug-2025  perseant Sync with HEAD
 1.92 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.91 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.90 17-Nov-2022  chs branches: 1.90.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.89 06-Apr-2020  martin Sync "common" declarations with ifdefs in header.
 1.88 06-Apr-2020  mrg dion't define endian as well as try to declare it as a variable.
 1.87 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.86 15-Aug-2019  kamil fsck: Stop defining the same variable concurrently in bss and data

returntosingle was defined in multiple places:

- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.85 05-May-2019  christos branches: 1.85.2;
Add a -z flag to zero out the up to 4 bytes of padding in directory entry
names (including the terminating NUL), as well as directory entries with
extra free space (d->d_reclen > UFS_DIRSIZ(d)).

Inspired from FreeBSD:
https://svnweb.freebsd.org/base?view=revision&revision=347066

While the kernel has been fixed to deal with the padding bytes (new
kernels will correctly zero out all the padding after the name), it
appears that there is still an issue with directory entries with extra
free space, since a newly created and populated filesystem gets modified
with "fsck_ffs -z".
 1.84 08-Feb-2017  rin branches: 1.84.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.83 16-Jun-2015  christos branches: 1.83.2; 1.83.4;
a few more \n's in errors
 1.82 16-Jun-2015  christos fix error messages containing \n
 1.81 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.80 29-Aug-2011  joerg branches: 1.80.2; 1.80.8;
Use __dead
 1.79 09-Jun-2011  christos share more code.
 1.78 06-Mar-2011  bouyer branches: 1.78.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.77 06-Feb-2011  njoly Do Skip device checks, which ends up parsing fstab, when working on a
filesystem image with -F option set.
 1.76 11-Apr-2010  hannken branches: 1.76.2;
Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.

While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.75 07-Jan-2010  christos make this compile again.
 1.74 06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.73 12-Oct-2008  wiz Don't use unicode in usage.
Noted by Anon Ymous.
 1.72 09-Oct-2008  wiz Sync usage with man page.
 1.71 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.70 30-Aug-2008  dogcow Make it compile. (HI BOUYER!)
 1.69 30-Aug-2008  bouyer Add fss(4) snapshot support to fsck_ffs(8) (via -x or -X options, like
dump(8)). This allows fsck_ffs -n to work on a snapshot of a R/W mounted
filesystem, and avoid errors related to filesystem activity.
 1.68 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.67 23-Feb-2008  christos branches: 1.67.4; 1.67.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.66 16-Jul-2007  pooka branches: 1.66.4; 1.66.10; 1.66.12;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.65 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.64 08-Feb-2007  drochner include <signal.h> where signal(3) is used
 1.63 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.62 14-Nov-2006  apb branches: 1.62.2;
Fix error in previous. Pass 1 needs to use progress_setrange(),
not progress_sethighlim().
 1.61 14-Nov-2006  apb Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.60 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.59 19-Aug-2005  christos 64 bit inode changes
 1.58 27-Jun-2005  christos sprinkle const.
 1.57 20-Jan-2005  xtraeme branches: 1.57.2;
whitespace (pointed out by wiz@)
 1.56 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.55 19-Jan-2005  wiz Add -P to usage.
 1.54 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.53 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.52 11-Oct-2004  dbj always print warning and return non-zero exit when there are unresolved inconsistencies.
 1.51 25-Jun-2004  wiz Add -a to usage. Closes PR 25916 by Kouichirou Hiratsuka.
 1.50 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.49 17-Jan-2004  dbj print warning if the user specifies a conversion level greater than implemented
 1.48 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.47 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.46 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.45 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.44 28-Jan-2003  mrg make this build on alpha after daddr_t->64bit
 1.43 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.42 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.41 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.40 15-Aug-2001  lukem - implement -F; treat provided filesystems as images in regular files
- replace "filesystem" with "file system" as appropriate
- grammar fixes
 1.39 23-Feb-2001  christos fix compile errors.
 1.38 19-Feb-2001  cgd convert to use getprogname()
 1.37 04-Feb-2001  christos remove redundant declarations
 1.36 26-Jan-2001  thorpej In pass 5, check alternate superblocks for consistency with
the current in-core master superblock, and fix them up if
they're incorrect. Move the code that writes the alternate
superblocks if (cvtlevel || doswap) into pass 5 for efficiency.

Reviewd by Charles Hannum, and used by me to fix up a curdled
file system.
 1.35 13-Dec-2000  mycroft Fix an annoyingly incorrect message.
 1.34 15-Nov-1999  fvdl branches: 1.34.4;
Changes for softdep code.
 1.33 26-Jul-1998  mycroft branches: 1.33.4; 1.33.8;
const poisoning.
 1.32 01-Apr-1998  kleink Need <time.h> for time() prototype.
 1.31 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.30 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.29 02-Nov-1997  mjacob Hmmm..fsck_ffs has to really be able to alwasy work, and if you've got
a *huge* (like 600GB) filesystem, you need to not be limited by resource
limits.
 1.28 01-Oct-1997  enami branches: 1.28.2;
Don't declare optind and optarg.
 1.27 24-Sep-1997  lukem for now, #ifdef out a couple of chunks that were added in the lite2 merge
 1.26 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.25 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.24 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.23 22-Oct-1996  christos - sort and remove unused options.
- If no filesystem is specified or an incorrect option, print usage information
 1.22 11-Oct-1996  thorpej Bug fix from Kirk McKusick <mckusick@McKusick.COM>:

Fix a bug in fsck_ffs where if a directory somehow develops a hole
(that is a block pointer that has a value of zero), fsck would give the
filesystem a clean bill of health, but the kernel would panic when
accessing the directory with the hole. Fsck now checks for holes
in directories. If found in preen mode, fsck fails. In manual
mode, it can be directed to shorten the directory to the beginning of
the hole. A more complete solution would be to allocate a block to fill
the hole. However, this is a lot more work for a `cannot happen' error,
so the extra effort seems unwarranted.
 1.21 27-Sep-1996  christos - util.h -> fsutil.h
 1.20 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.19 28-Nov-1995  jtc branches: 1.19.4;
merge in changes from 1.1 release branch
 1.18 12-Jul-1995  cgd branches: 1.18.2;
recognize 'ffs' and 'ufs' as meaning the same thing.
 1.17 12-Jul-1995  cgd implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
 1.16 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.15 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.14 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.13 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.12 25-Apr-1994  cgd need <sys/time.h>
 1.11 06-Apr-1994  cgd kill the evil U word! from Mike Long <mike.long@analog.com>
 1.10 15-Oct-1993  cgd try again to keep it from rebooting endlessly
 1.9 06-Oct-1993  cgd set the 'clean' flag sometimes, but ignore it when deciding to clean
or not. this allows you to use this fsck and... reboot your system;
otherwise it would inf-loop rebooting and marking the FS clean,
which would then mark the fs modified, cause a reboot, etc.
 1.8 03-Oct-1993  mycroft #if 0 the fs_clean check for now.
 1.7 01-Oct-1993  mycroft Don't set clean flag if -n.
 1.6 01-Oct-1993  mycroft Initial count for fs_state is `FS_CLEANFREQ'.
 1.5 01-Oct-1993  mycroft Skip check if filesystem is marked clean and isn't too dusty, only with -p.
Set clean flag after checking a filesystem.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.2.1 01-Nov-1995  jtc complete ufs -> ffs change (From John Kohl; PR #1403)
 1.19.4.1 02-Mar-1997  mycroft Pull up changes from Kirk McKusick to check for holes in directories.
 1.28.2.1 02-Nov-1997  mellon Pull rev 1.29 up from trunk (mjacob)
 1.33.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.33.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.34.4.2 25-Nov-2001  he Pull up revision 1.39 (requested by lukem):
Use int32_t for on-disk time_t representation.
Convert %q_ to %ll_ in print formats.
 1.34.4.1 24-Nov-2001  he Pull up revisions 1.35-1.37 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.57.2.2 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/main.c: revision 1.62
Fix error in previous. Pass 1 needs to use progress_setrange(),
not progress_sethighlim().
 1.57.2.1 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.62.2.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.66.12.3 17-Jan-2009  mjf Sync with HEAD.
 1.66.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.66.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.66.10.1 24-Mar-2008  keiichi sync with head.
 1.66.4.1 23-Mar-2008  matt sync with HEAD
 1.67.6.1 28-Jul-2008  simonb Sync with head.
 1.67.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.76.2.2 08-Feb-2011  bouyer Sync with HEAD
 1.76.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.78.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.80.8.1 25-Feb-2013  tls resync with head
 1.80.2.1 23-Jan-2013  yamt sync with head
 1.83.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.83.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.84.12.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.84.12.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.84.12.1 10-Jun-2019  christos Sync with HEAD
 1.85.2.1 16-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #73):

sbin/fsck_lfs/main.c: revision 1.54
sbin/fsck_ext2fs/main.c: revision 1.40
sbin/fsck_ffs/main.c: revision 1.86

fsck: Stop defining the same variable concurrently in bss and data
returntosingle was defined in multiple places:
- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.90.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.64 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.63 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.62 18-Nov-2022  martin branches: 1.62.2;
Fix clearing of permissions when finding unexpected extended attributs
for swapped endian file systems. Ok: chs
 1.61 17-Nov-2022  martin Make the "non-zero exattr fields" message show the inode number.
 1.60 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.59 19-Apr-2020  christos Enable the code to clean the extattr blocks
 1.58 13-Feb-2018  hannken branches: 1.58.4;
Treat an inode with "mode == 0" and "blocks != 0" as partially allocated
and clear it as ffs_newvnode() tests for "blocks == 0".
 1.57 08-Feb-2017  rin branches: 1.57.4;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.56 19-Oct-2013  christos branches: 1.56.8; 1.56.12;
fix unused variable warnings.
 1.55 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.54 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.53 19-Jun-2013  dholland blkoff() -> ffs_blkoff() stragglers
 1.52 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.51 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.50 06-Jan-2013  riastradh Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.49 14-Aug-2011  christos branches: 1.49.2; 1.49.4; 1.49.8; 1.49.10;
WARNS=4
 1.48 09-Jun-2011  christos share more code.
 1.47 06-Mar-2011  bouyer branches: 1.47.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.46 12-Oct-2008  christos branches: 1.46.2; 1.46.6; 1.46.10; 1.46.14; 1.46.16;
reallocate the correct amount. From Anon Ymous
 1.45 09-Oct-2008  christos Avoid allocating 2 x inospace and use realloc instead. This also saves a
large memcpy.
 1.44 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.43 14-Nov-2006  apb branches: 1.43.8; 1.43.16; 1.43.18;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.42 16-Oct-2006  christos comment out impossible code.
 1.41 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.40 05-Dec-2005  christos ndb is daddr_t which is 64 bits, by truncating it to j which is an int, it
can get negative causing segmentation faults. Check against this.
 1.39 19-Aug-2005  christos 64 bit inode changes
 1.38 08-Jun-2005  dbj add code to handle inodes with extended attribute blocks
this is currently turned off with "#ifdef notyet" since the
kernel will not correctly clean up extended attribute blocks on truncation

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.37 30-Apr-2005  christos Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.36 20-Jan-2005  xtraeme branches: 1.36.2;
whitespace (pointed out by wiz@)
 1.35 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.34 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.33 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.32 25-May-2004  hannken Add ffs internal snapshots. Written by Marshall Kirk McKusick for FreeBSD.

- Not enabled by default. Needs kernel option FFS_SNAPSHOT.
- Change parameters of ffs_blkfree.
- Let the copy-on-write functions return an error so spec_strategy
may fail if the copy-on-write fails.
- Change genfs_*lock*() to use vp->v_vnlock instead of &vp->v_lock.
- Add flag B_METAONLY to VOP_BALLOC to return indirect block buffer.
- Add a function ffs_checkfreefile needed for snapshot creation.
- Add special handling of snapshot files:
Snapshots may not be opened for writing and the attributes are read-only.
Use the mtime as the time this snapshot was taken.
Deny mtime updates for snapshot files.
- Add function transferlockers to transfer any waiting processes from
one lock to another.
- Add vfsop VFS_SNAPSHOT to take a snapshot and make it accessible through
a vnode.
- Add snapshot support to ls, fsck_ffs and dump.

Welcome to 2.0F.

Approved by: Jason R. Thorpe <thorpej@netbsd.org>
 1.31 03-Jan-2004  dbj branches: 1.31.4;
fix bugs with unsigned comparison ofs fs_maxsymlinklen
 1.30 03-Jan-2004  dbj increase size of buffer used for updating symlinks with -c 1
otherwise, the block read will blow the stack
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.28 02-Apr-2003  he On LP64 hosts, iswap64() result is "long int", so cast result to (long long)
before printing with %lld.
 1.27 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.26 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.25 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.24 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.23 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.22 15-Nov-1999  fvdl Changes for softdep code.
 1.21 18-Mar-1998  bouyer branches: 1.21.4; 1.21.8;
Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.20 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.19 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.18 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.17 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.16 27-Sep-1996  christos - util.h -> fsutil.h
 1.15 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.14 18-Jan-1996  mycroft Use fs_csaddr to find the cg summary area. From der Mouse, PR 1366.
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.11 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.10 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.9 29-Jun-1994  ws Reads on raw disks are only guarranteed in multiples of the block size
 1.8 14-Jun-1994  mycroft Fix compatibility with old fastlinks.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 25-Apr-1994  cgd need <sys/time.h>
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 13-Jun-1993  mycroft Add support for fast symlinks.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.21.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.31.4.1 01-May-2005  tron Pull up revision 1.37 (requested by christos in ticket #1493):
Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.36.2.3 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.36.2.2 07-Dec-2005  riz Pull up following revision(s) (requested by christos in ticket #1037):
sbin/fsck_ffs/pass1.c: revision 1.40
ndb is daddr_t which is 64 bits, by truncating it to j which is an int, it
can get negative causing segmentation faults. Check against this.
 1.36.2.1 01-May-2005  tron Pull up revision 1.37 (requested by christos in ticket #228):
Dammit, get rid of the debugging abort() calls. It is no fun to have a broken
fsck program on a busted filesystem.
 1.43.18.2 17-Jan-2009  mjf Sync with HEAD.
 1.43.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.43.16.1 24-Mar-2008  keiichi sync with head.
 1.43.8.1 23-Mar-2008  matt sync with HEAD
 1.46.16.1 13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.46.14.3 12-Feb-2011  bouyer Skip snapshot inodes for both block and inode quotas.
 1.46.14.2 12-Feb-2011  bouyer Snapshot inode doesn't count for block quotas.
 1.46.14.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.46.10.1 13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.46.6.1 13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.46.2.1 13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1837):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.47.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.49.10.1 13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #779):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.49.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.49.8.2 23-Jun-2013  tls resync from head
 1.49.8.1 25-Feb-2013  tls resync with head
 1.49.4.1 13-Jan-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #779):
sbin/fsck_ffs/pass1.c: revision 1.50
Show pass1 SIGINFO output on stderr like other passes, not on stdout.
 1.49.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.49.2.1 23-Jan-2013  yamt sync with head
 1.56.12.1 21-Apr-2017  bouyer Sync with HEAD
 1.56.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.57.4.1 15-Feb-2018  martin Pull up following revision(s) (requested by hannken in ticket #550):
sbin/fsck_ffs/pass1.c: revision 1.58
Treat an inode with "mode == 0" and "blocks != 0" as partially allocated
and clear it as ffs_newvnode() tests for "blocks == 0".
 1.58.4.1 21-Apr-2020  martin Sync with HEAD
 1.62.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.24 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.23 22-Jan-2013  dholland branches: 1.23.40;
Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.22 06-Mar-2011  bouyer branches: 1.22.4; 1.22.10;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.21 20-Jan-2005  xtraeme branches: 1.21.48;
whitespace (pointed out by wiz@)
 1.20 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.19 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.18 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.15 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.14 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.13 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.12 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.11 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.10 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.48.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.22.10.1 25-Feb-2013  tls resync with head
 1.22.4.1 23-Jan-2013  yamt sync with head
 1.23.40.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.53 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.52 27-Mar-2023  chs Apply this commit from FreeBSD:

commit 6bae6625e0e06816c80ac4971dfccf0643abe3f0
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Aug 17 14:19:59 2022 -0700

Improve handling of missing '.' and '..' in UFS directories.

The UFS filesystem expects to find '.' and '..' as the first two entries
in a directory. The kernel's UFS name cache can become quite confused
when these two entries are not present as the first two entries.

Prior to this change, when the fsck_ffs(8) utility detected that
'.' and/or '..' were missing, it would report them, but only offered
to replace them if the space at the beginning of the directory was
available. Otherwise it was left to the system administrator to
move the offending file(s) out of the way and then rerun fsck_ffs(8)
to create the '.' and '..' entries.

With this change, fsck_ffs(8) will always be able to create the '.'
and/or '..' entries. It moves any files in the way elsewhere in the
directory block. If there is no room in the directory block to which
to move them, they are placed in the lost+found directory.

Reported by: Peter Holm
Sponsored by: The FreeBSD Foundation
 1.51 08-Feb-2017  rin branches: 1.51.22;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.50 09-Jun-2013  dholland branches: 1.50.10; 1.50.14;
Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.49 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.48 14-Aug-2011  christos branches: 1.48.2; 1.48.8;
WARNS=4
 1.47 09-Jun-2011  christos share more code.
 1.46 06-Mar-2011  bouyer branches: 1.46.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.45 23-Feb-2008  christos branches: 1.45.20;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.44 14-Nov-2006  apb branches: 1.44.8; 1.44.16; 1.44.18;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.43 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.42 27-Jun-2005  christos sprinkle const.
 1.41 20-Jan-2005  xtraeme branches: 1.41.2;
whitespace (pointed out by wiz@)
 1.40 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.39 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.38 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.37 20-Jul-2004  mycroft Reduce memory usage slightly.
 1.36 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.35 13-Jul-2003  itojun use bounded string op
 1.34 09-Apr-2003  fvdl Correctly deal with directories that need indirect blocks by adding
some code I missed in the UFS2 commit. Should fix false positives
seen by fsck_ffs on clean filesystems.

Thanks to Takahiro Kambe for debugging help.
 1.33 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.32 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.31 06-May-2002  agc Make this compile on some of the more esoteric architectures.
 1.30 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.29 09-Jan-2001  mycroft The reconnect algorithm was historically O(n^4).
Some years ago I made it O(n^2).
Someone helpfully made it O(n^4) again.
Today I'm making it O(n).
If that's not good enough, I don't know what else to do. B-)

Technical details:
* The graph traversal in propagate() is modified to be able to start from any
point in the tree. To handle certain exceptional cases, it is also modified
to work in two passes, marking the tree with a special tag and then changing
it to DFOUND.
* The reconnect case now modifies the child/sibling pointers and calls
propagate() to propagate the connection state starting with the reconnected
directory.

Pray that you never encounter a file system trashed enough for this to matter.
 1.28 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.27 17-Nov-1999  mrg branches: 1.27.4;
fix lp64 lossage.
 1.26 15-Nov-1999  fvdl Changes for softdep code.
 1.25 23-Oct-1998  thorpej branches: 1.25.4; 1.25.8;
Use DINODE_SIZE rather than sizeof(struct dinode) and/or pointer arithmetic.
 1.24 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.23 21-Sep-1997  lukem reintroduce clarity changes made in rev1.14 that were lost in the lite2 merge
 1.22 21-Sep-1997  lukem remove some code that was obsoleted by mycroft's changes to
propagate() in dir.c rev 1.14.

this was accidentally re-introduced in the lite-2 merge, and could
cause filesystem corruption.
 1.21 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.20 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.19 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.18 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.17 27-Sep-1996  christos - util.h -> fsutil.h
 1.16 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.15 11-Jun-1996  mycroft Use a different tree-walking algorithm in propagate().
 1.14 21-May-1996  mycroft branches: 1.14.2;
Remove previous (incorrect) change, and tidy up a bit to make it
clearer what's going on.
 1.13 21-May-1996  mrg initalise dino to zero. pr#2098
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 28-Dec-1994  mycroft Change some spacing to match Kirk's view of the world.
 1.10 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.9 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.8 28-Oct-1994  mycroft Get the byte order right when creating `.' and `..' entries.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft branches: 1.6.2;
Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.1 07-Nov-1994  cgd for patch #2
 1.14.2.1 10-Dec-1996  mycroft From trunk:
* Redo the tree-walking algorithm to make it O(n) rather than O(n^2).
* Fix some minor type size problems.
 1.25.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.27.4.1 24-Nov-2001  he Pull up revision 1.29 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.41.2.1 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.44.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.44.16.1 24-Mar-2008  keiichi sync with head.
 1.44.8.1 23-Mar-2008  matt sync with HEAD
 1.45.20.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.46.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.48.8.2 23-Jun-2013  tls resync from head
 1.48.8.1 25-Feb-2013  tls resync with head
 1.48.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.48.2.1 23-Jan-2013  yamt sync with head
 1.50.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.50.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.51.22.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #164):

sbin/fsck_ffs/pass2.c: revision 1.52

Apply this commit from FreeBSD:
commit 6bae6625e0e06816c80ac4971dfccf0643abe3f0
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Aug 17 14:19:59 2022 -0700
Improve handling of missing '.' and '..' in UFS directories.
The UFS filesystem expects to find '.' and '..' as the first two entries
in a directory. The kernel's UFS name cache can become quite confused
when these two entries are not present as the first two entries.
Prior to this change, when the fsck_ffs(8) utility detected that
'.' and/or '..' were missing, it would report them, but only offered
to replace them if the space at the beginning of the directory was
available. Otherwise it was left to the system administrator to
move the offending file(s) out of the way and then rerun fsck_ffs(8)
to create the '.' and '..' entries.
With this change, fsck_ffs(8) will always be able to create the '.'
and/or '..' entries. It moves any files in the way elsewhere in the
directory block. If there is no room in the directory block to which
to move them, they are placed in the lost+found directory.
Reported by: Peter Holm
Sponsored by: The FreeBSD Foundation
 1.21 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.20 06-Mar-2011  bouyer branches: 1.20.4; 1.20.10;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.19 14-Nov-2006  apb branches: 1.19.40;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.18 13-Jan-2005  christos branches: 1.18.2;
Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.17 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.15 02-Apr-2003  he The new UFS2 code uses memset(), so include <string.h> for prototype.
 1.14 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.13 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.12 10-Jan-2001  mycroft Abstract the code to attach a directory to its parent's child list into a
separate function, and call it from multiple places in linkup() to handle
reconnects and creation of /lost+found.
 1.11 09-Jan-2001  mycroft The reconnect algorithm was historically O(n^4).
Some years ago I made it O(n^2).
Someone helpfully made it O(n^4) again.
Today I'm making it O(n).
If that's not good enough, I don't know what else to do. B-)

Technical details:
* The graph traversal in propagate() is modified to be able to start from any
point in the tree. To handle certain exceptional cases, it is also modified
to work in two passes, marking the tree with a special tag and then changing
it to DFOUND.
* The reconnect case now modifies the child/sibling pointers and calls
propagate() to propagate the connection state starting with the reconnected
directory.

Pray that you never encounter a file system trashed enough for this to matter.
 1.10 16-Sep-1997  lukem branches: 1.10.14;
resolve conflicts from lite-2 merge.
 1.9 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.14.1 24-Nov-2001  he Pull up revisions 1.11-1.12 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.18.2.1 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.19.40.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.20.10.1 25-Feb-2013  tls resync with head
 1.20.4.1 23-Jan-2013  yamt sync with head
 1.31 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.30 14-Jan-2023  christos catch up with sign changes in the fs.h
 1.29 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.28 23-Jun-2013  dholland branches: 1.28.38;
Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.27 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.26 06-Mar-2011  bouyer branches: 1.26.4; 1.26.10;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.25 31-Jul-2008  simonb branches: 1.25.14;
Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.24 23-Feb-2008  christos branches: 1.24.4; 1.24.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.23 14-Nov-2006  apb branches: 1.23.8; 1.23.16; 1.23.18;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.22 19-Aug-2005  christos 64 bit inode changes
 1.21 19-Jan-2005  xtraeme branches: 1.21.2;
Kill __P(), ANSIfy and WARNS=2
 1.20 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.19 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.18 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.17 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.16 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.15 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.14 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.13 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.12 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.11 27-Sep-1996  christos - util.h -> fsutil.h
 1.10 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.2.1 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.23.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.23.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.23.16.1 24-Mar-2008  keiichi sync with head.
 1.23.8.1 23-Mar-2008  matt sync with HEAD
 1.24.6.1 28-Jul-2008  simonb Add support for creating a WAPBL log in the filesystem. Will
create an in-filesystem log on first "mount -o log" if one doesn't
exist, and will then continue to use same log in the future. See
(soon to be added) wapbl(4) for more info.

Adds a new B_CONTIG low-level allocation flag that uses hints in
"struct ffs_inode_ext" to lay out an ffs file's data contiguously.

Thanks to Greg Oster for helping with the design of this and to
Antti Kantee for code review and suggestions.
 1.24.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.25.14.3 12-Feb-2011  bouyer Skip snapshot inodes for both block and inode quotas.
 1.25.14.2 12-Feb-2011  bouyer Snapshot inode doesn't count for block quotas.
 1.25.14.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.26.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.26.10.1 25-Feb-2013  tls resync with head
 1.26.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26.4.1 23-Jan-2013  yamt sync with head
 1.28.38.2 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #162):

sbin/fsck_ffs/inode.c: revision 1.74
sbin/fsck_ffs/utilities.c: revision 1.68
sbin/fsck_ffs/fsck.h: revision 1.57
sbin/fsck_ffs/pass4.c: revision 1.30

catch up with sign changes in the fs.h
 1.28.38.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.58 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.57 08-Jan-2023  chs ufs: more signed/unsigned fixes

Fix the previous signed/unsigned fixes to build on 32-bit,
including applying this commit from FreeBSD:

commit 2d34afcd04207cf3fa3d5b7f467a890eae75da41
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Sun Oct 25 21:04:07 2020 +0000

Use proper type (ino_t) for inode numbers to avoid improper sign extention
in the Pass 5 checks. The manifestation was fsck_ffs exiting with this error:

** Phase 5 - Check Cyl groups
fsck_ffs: inoinfo: inumber 18446744071562087424 out of range

The error only manifests itself for filesystems bigger than about 100Tb.

Reported by: Nikita Grechikhin <ngrechikhin at yandex.ru>
MFC after: 2 weeks
Sponsored by: Netflix
 1.56 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.55 17-Nov-2022  chs branches: 1.55.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.54 23-Jun-2013  dholland Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.53 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.52 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.51 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.50 26-Aug-2012  dholland branches: 1.50.2;
stdlib.h, not malloc.h
 1.49 14-Aug-2011  christos branches: 1.49.2;
WARNS=4
 1.48 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.47 14-Nov-2006  apb branches: 1.47.8; 1.47.16; 1.47.18;
Improve the progress bar displayed by fsck_ffs -p -P.

The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.

Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.46 27-Jun-2005  christos sprinkle const.
 1.45 20-Jan-2005  xtraeme branches: 1.45.2;
whitespace (pointed out by wiz@)
 1.44 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.43 13-Jan-2005  christos Use -DPROGRESS to enable the progress bar, don't depend on SMALL.
 1.42 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.41 09-Oct-2004  ragge Cast to (long long int) to make last change compile on amd64.
 1.40 08-Oct-2004  dbj if debug, print found/expected block & inode counts when incorrect
 1.39 09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.38 19-Sep-2003  itojun realloc pedant
 1.37 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.36 04-Apr-2003  fvdl When fixing the cstotal structure, use the right size to copy it back.
Also, remove some accidentally committed debug code from the previous
commit.
 1.35 04-Apr-2003  fvdl Initialize cg_irotor correctly in newcg, to avoid false positives
for bad cylinder groups.
 1.34 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.33 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.32 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.31 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.30 30-Jun-2002  dbj commit fix from pr bin/15449
this fixes FS_42POSTBLFMT compatibility
 1.29 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.28 10-Apr-2002  mycroft Some manual strength reduction.
 1.27 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.26 26-Jan-2001  thorpej In pass 5, check alternate superblocks for consistency with
the current in-core master superblock, and fix them up if
they're incorrect. Move the code that writes the alternate
superblocks if (cvtlevel || doswap) into pass 5 for efficiency.

Reviewd by Charles Hannum, and used by me to fix up a curdled
file system.
 1.25 09-Jan-2001  mycroft Make sure the rotor values are non-negative.
 1.24 14-Jul-2000  mycroft Add a missing newline in one message.
(The fact that I got this message using softdep should probably disturb
someone...)
 1.23 28-Nov-1999  bouyer branches: 1.23.4;
Add a missing '\n'.
 1.22 15-Nov-1999  fvdl Fix %d <-> long mismatch.
 1.21 15-Nov-1999  fvdl Changes for softdep code.
 1.20 25-Aug-1998  ross branches: 1.20.4; 1.20.8;
from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.19 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.18 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.17 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.16 27-Sep-1996  christos - util.h -> fsutil.h
 1.15 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.14 21-Mar-1995  cgd type sizes
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.11 18-Dec-1994  cgd light clean, and make it compile against new header files.
 1.10 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.9 28-Oct-1994  mycroft Use the S_IS*() macros, and make this compile again after Chris's changes to ufs.
 1.8 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.20.4.3 26-Oct-1999  fvdl Fix some merge mistakes.
 1.20.4.2 26-Oct-1999  fvdl Remove unused variable decl. From Ethan Solomita.
 1.20.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.23.4.3 25-Nov-2001  he Pull up revision 1.27 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.23.4.2 24-Nov-2001  he Pull up revisions 1.25-1.26 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.23.4.1 27-Jul-2000  mycroft Approved by thorpej:
Add a missing newline to message.

basesrc/sbin/fsck_ffs/pass5.c 1.23 -> 1.24
 1.45.2.1 20-Nov-2006  tron Pull up following revision(s) (requested by ghen in ticket #1590):
sbin/fsck_ffs/pass4.c: revision 1.23
sbin/fsck_ffs/pass5.c: revision 1.47
sbin/fsck_ffs/pass2.c: revision 1.44
sbin/fsck_ffs/pass1.c: revision 1.43
sbin/fsck_ffs/pass3.c: revision 1.19
sbin/fsck/progress.c: revision 1.3
sbin/fsck_ffs/main.c: revision 1.61
sbin/fsck/progress.h: revision 1.2
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
 1.47.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.47.16.1 24-Mar-2008  keiichi sync with head.
 1.47.8.1 23-Mar-2008  matt sync with HEAD
 1.49.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.49.2.2 23-Jan-2013  yamt sync with head
 1.49.2.1 30-Oct-2012  yamt sync with head
 1.50.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.50.2.1 25-Feb-2013  tls resync with head
 1.55.2.2 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #161):

sbin/fsck_ffs/setup.c: revision 1.106
sbin/fsck_ffs/pass5.c: revision 1.57

ufs: more signed/unsigned fixes

Fix the previous signed/unsigned fixes to build on 32-bit,
including applying this commit from FreeBSD:

commit 2d34afcd04207cf3fa3d5b7f467a890eae75da41
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Sun Oct 25 21:04:07 2020 +0000
Use proper type (ino_t) for inode numbers to avoid improper sign extention
in the Pass 5 checks. The manifestation was fsck_ffs exiting with this error:
** Phase 5 - Check Cyl groups
fsck_ffs: inoinfo: inumber 18446744071562087424 out of range
The error only manifests itself for filesystems bigger than about 100Tb.
Reported by: Nikita Grechikhin <ngrechikhin at yandex.ru>
MFC after: 2 weeks
Sponsored by: Netflix
 1.55.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.5 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.4 26-Aug-2012  dholland stdlib.h, not malloc.h
 1.3 07-Jun-2011  bouyer branches: 1.3.2;
Fix bad cut'n'paste in copyright. Pointed out by dyoung@
 1.2 06-Mar-2011  bouyer branches: 1.2.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.1 20-Jan-2011  bouyer branches: 1.1.2;
file pass6.c was initially added on branch bouyer-quota2.
 1.1.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.2.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.3.2.1 30-Oct-2012  yamt sync with head
 1.13 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.12 11-May-1996  mycroft Try looking up the file system name in fstab. From greywolf@starwolf.com,
slightly modified.
 1.11 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.10 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.9 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.8 28-Oct-1994  mycroft Use the S_IS*() macros, and make this compile again after Chris's changes to ufs.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 25-Apr-1994  cgd need <sys/time.h>
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.7 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.6 26-Aug-2012  dholland branches: 1.6.32;
stdlib.h, not malloc.h
 1.5 20-Mar-2012  matt Convert to C89 function definitions
 1.4 14-Aug-2011  christos branches: 1.4.2;
WARNS=4
 1.3 07-Jun-2011  bouyer Fix bad cut'n'paste in copyright. Pointed out by dyoung@
 1.2 06-Mar-2011  bouyer branches: 1.2.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.1 20-Jan-2011  bouyer branches: 1.1.2;
file quota2.c was initially added on branch bouyer-quota2.
 1.1.2.2 08-Feb-2011  bouyer Q2V_ -> QL_ rename
 1.1.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.2.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.4.2.2 30-Oct-2012  yamt sync with head
 1.4.2.1 17-Apr-2012  yamt sync with head
 1.6.32.1 10-Jun-2019  christos Sync with HEAD
 1.111 23-Jun-2025  christos join lines
 1.110 19-Jun-2025  mlelstv Don't truncate bitmap size to unsigned int, avoids crashes on filesystems
with more than 2^32 blocks.

Pullups
 1.109 05-Jul-2023  riastradh branches: 1.109.2;
Revert "fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.108 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.107 04-Jul-2023  riastradh fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.106 08-Jan-2023  chs ufs: more signed/unsigned fixes

Fix the previous signed/unsigned fixes to build on 32-bit,
including applying this commit from FreeBSD:

commit 2d34afcd04207cf3fa3d5b7f467a890eae75da41
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Sun Oct 25 21:04:07 2020 +0000

Use proper type (ino_t) for inode numbers to avoid improper sign extention
in the Pass 5 checks. The manifestation was fsck_ffs exiting with this error:

** Phase 5 - Check Cyl groups
fsck_ffs: inoinfo: inumber 18446744071562087424 out of range

The error only manifests itself for filesystems bigger than about 100Tb.

Reported by: Nikita Grechikhin <ngrechikhin at yandex.ru>
MFC after: 2 weeks
Sponsored by: Netflix
 1.105 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.104 17-Nov-2022  chs branches: 1.104.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.103 17-Apr-2020  jdolecek align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) raw (character) device
 1.102 05-Oct-2018  hannken branches: 1.102.2;
Add a test for duplicate inodes on the persistent snapshot list.
 1.101 08-Feb-2017  rin branches: 1.101.4; 1.101.10; 1.101.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.100 23-Jun-2013  dholland branches: 1.100.10; 1.100.14;
Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.99 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.98 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.97 09-Jun-2013  dholland Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.96 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.95 29-Jan-2012  nonaka branches: 1.95.6;
use FS_UFS[12]_MAGIC_SWAPPED instead of bswap32(FS_UFS[12]_MAGIC).
 1.94 14-Aug-2011  christos branches: 1.94.2;
WARNS=4
 1.93 09-Jun-2011  christos share more code.
 1.92 20-Mar-2011  bouyer branches: 1.92.2;
initialise memory allocated for uquot_user_hash & uquot_group_hash.
Pointed out by Nicolas Joly.
 1.91 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.90 31-Jan-2010  mlelstv branches: 1.90.2;
Skip handling of APPLEUFS_LABEL if it is smaller than a device block.
In particular:

- newfs will not try to erase the label
- fsck_ffs will not try to validate the label

This lets newfs and fsck work on 2048-byte-per-sector media.

Does Apple UFS support such media and how?
 1.89 27-Sep-2009  bouyer Restore changes from 1.86 and 1.87 after commit of 1.88.
 1.88 13-Sep-2009  bouyer Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.87 07-Apr-2009  mrg fix a logic error in the previous, as point out by frank kardel.
 1.86 25-Mar-2009  mrg don't ignore "fsck -f" when given with "-p" on a wapbl filesystem.
ie, "fsck -fp" actually forces the check in preen mode now.
 1.85 25-Feb-2009  christos don't copy the address of a pointer. Noticed by Anon Ymous
 1.84 30-Aug-2008  bouyer branches: 1.84.2; 1.84.4; 1.84.8;
Add fss(4) snapshot support to fsck_ffs(8) (via -x or -X options, like
dump(8)). This allows fsck_ffs -n to work on a snapshot of a R/W mounted
filesystem, and avoid errors related to filesystem activity.
 1.83 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.82 23-Feb-2008  christos branches: 1.82.4; 1.82.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.81 22-Aug-2007  christos branches: 1.81.2; 1.81.8; 1.81.10;
Avoid zero-divides from Anon Ymous
 1.80 26-Aug-2006  christos - Deal with wedges and the new disk geometry structures, instead of using
struct disklabel.

Functionality lost:
1. struct disklabel used to be updated to contain bsize, fsize, cpg.
This information was used to locate the alternative superblock in
the filesystem if the primary superblock was corrupted. We need
to find a new place to store this information if we need this
functionality.
2. On vax SMD drives that contained bad sector lists, the newfs program
knew how to get the offset and skip to the correct location in order
to place the label.
 1.79 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.78 27-Jun-2005  christos sprinkle const.
 1.77 02-Jun-2005  dbj for ufs2, assume FS_44INODEFMT
this is necessary for freebsd compatbility, since they do not initialize
the old field.
 1.76 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.75 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.74 29-Oct-2004  dsl Rewrite getdisklabelpart() to avoid problems with isdigit(*ch_ptr) and
an incorrect check for a (probably impossible) empty string.
Add comments to avoid confusion...
 1.73 14-Apr-2004  dbj add support for downgrading a filesystem fslevel from 4 to 3
 1.72 14-Apr-2004  dbj set fs_old_nrpos to 1 when doing -c4 upgrade.
This isn't used by kernel, but does affect cg layout slightly
 1.71 12-Apr-2004  dbj fix whitespace in debug printf
 1.70 21-Mar-2004  dsl branches: 1.70.2;
Don't use an ffsv1 superblock from 64k (SBLOCK_UFS2) when looking
for the main filesystem superblock.
64k is the offset of the first alternate if the blocksize if 64k.
Fixes part of PR kern/24809
 1.69 20-Jan-2004  dbj don't calculate fake superblock used for finding alternate superblocks
if the disklabel is missing the cpg parameter. Also print a warning
if this is skipped because of a missing fsize, frag or cpg disklabel parameter
this fixes a divide by zero error reported by martin@
 1.68 12-Jan-2004  dbj change the message "COVERTING TO FFSv2 SUPERBLOCK" to
"CONVERT TO NEW SUPERBLOCK LAYOUT" to help avoid confusion
 1.67 10-Jan-2004  mrg - some KNF (80 cols)
- fix a printf format issue
 1.66 09-Jan-2004  dbj use %#llx instead of %llx when printing incorrect qfmask or qbmask
 1.65 09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.64 02-Jan-2004  dbj add uuid field to apple ufs volume label
 1.63 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.62 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.61 11-Apr-2003  enami Correctly detect a UFS1 file system of non-native endian.
 1.60 06-Apr-2003  fvdl Write update some old fields when writing the superblock, similar to
ffs_oldfscompat_write() in the kernel. Use the old totals when
time < old_time (i.e. an old kernel or fsck wrote the filesystem last).
When setting the date back on a new kernel, that works out ok, since
new kernels always update both fields.
 1.59 05-Apr-2003  fvdl Skip checks for old 4.2BSD filesystem; as it stands, we can't deal with
writing them. Could be fixed, but doesn't have a high priority.
 1.58 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.57 21-Feb-2003  fvdl Only check relevant fields when comparing the superblock to an alternate
superblock. Avoids false positives should fsck_ffs be run on a filesystem
that was created after the UFS2 code has been merged.

This commit is mostly a forward compatibility patch that can be pulled
up in to the 1.6 branch.

From Kirk Mckusick in FreeBSD (setup.c rev. 1.30). Original commit message:
 1.56 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.55 05-Nov-2002  dbj check that a disklabel is valid before trying to extract partition
information from it when checking for apple ufs filesystems
 1.54 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.53 30-Jun-2002  dbj commit fix from pr bin/15449
this fixes FS_42POSTBLFMT compatibility
 1.52 19-Dec-2001  fvdl branches: 1.52.2;
Don't use the pendinginodes and pendingblocks fields in alternate
superblock comparison.
 1.51 16-Nov-2001  lukem - changes to -F semantics:
- remove the restriction that filesystem must be a regular file
- don't try and read a disklabel
- use `p' (instead of `h') as the index of the last partition
 1.50 18-Sep-2001  lukem add comments to make it clearer what cmpsblks() is doing
 1.49 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.48 03-Sep-2001  lukem no need to assign asb->fs_state twice in cmpsblks()
 1.47 03-Sep-2001  lukem deprecate fs_fscktime; we never used it.

in an effort to maintain compatibility with freebsd/openbsd/whatever,
i'm attempting to get the superblock format in sync, and freebsd uses
the int32_t at this position for `fs_pendinginodes'.

if we ever decide to implement fscktime functionality, we'll:
a) make sure to liaise with the other projects to reserve the same
spare field
b) actually implement the code this time ...

(this is also preparing us for other changes, like the new dirpref code)
 1.46 02-Sep-2001  lukem Incorporate fix by iedowse @ FreeBSD to allow disks with large numbers of
cylinder groups to work correctly, with minor modifications by me to work
with our FFS_EI code. From the FreeBSD commit message:

The ffs superblock includes a 128-byte region for use by temporary
in-core pointers to summary information. An array in this region
(fs_csp) could overflow on filesystems with a very large number of
cylinder groups (~16000 on i386 with 8k blocks). When this happens,
other fields in the superblock get corrupted, and fsck refuses to
check the filesystem.

Solve this problem by replacing the fs_csp array in 'struct fs'
with a single pointer, and add padding to keep the length of the
128-byte region fixed. Update the kernel and userland utilities
to use just this single pointer.

With this change, the kernel no longer makes use of the superblock
fields 'fs_csshift' and 'fs_csmask'. Add a comment to newfs/mkfs.c
to indicate that these fields must be calculated for compatibility
with older kernels.

Reviewed by: mckusick
 1.45 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.44 15-Aug-2001  lukem - implement -F; treat provided filesystems as images in regular files
- replace "filesystem" with "file system" as appropriate
- grammar fixes
 1.43 04-Jul-2001  hubertf EVEN IF YOU SCREAM, THE COMMANT IS STILL CALLED fsck_ffs !
 1.42 04-Feb-2001  christos remove redundant declarations
 1.41 26-Jan-2001  thorpej In pass 5, check alternate superblocks for consistency with
the current in-core master superblock, and fix them up if
they're incorrect. Move the code that writes the alternate
superblocks if (cvtlevel || doswap) into pass 5 for efficiency.

Reviewd by Charles Hannum, and used by me to fix up a curdled
file system.
 1.40 09-Jan-2001  mycroft Remove a bogus piece of code that was never used.
 1.39 09-Jan-2001  mycroft Try to cope with cs_ndir being wacky (too large or, particularly when using -b,
too damn small) by setting a minimum (1024) and maximum (maxino + 1). This
prevents certain operations getting REALLY slow when -b is used, and also
avoids overallocating memory if the superblock is hosed.
 1.38 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.37 15-Nov-1999  fvdl branches: 1.37.4;
Changes for softdep code.
 1.36 01-May-1999  is branches: 1.36.2; 1.36.6;
Fix typo.
 1.35 12-Nov-1998  christos Adjust for DKTYPENAME changes.
 1.34 26-Jul-1998  mycroft const poisoning.
 1.33 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.32 24-Sep-1997  lukem for now, #ifdef out a couple of chunks that were added in the lite2 merge
 1.31 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.30 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.29 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.28 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.27 27-Sep-1996  christos - util.h -> fsutil.h
 1.26 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.25 21-May-1996  mycroft Oops; use %x to print out masks, not %d.
 1.24 21-May-1996  mycroft Check fs_[bf]mask, fs_maxfilesize, fs_maxsymlinklen, and fs_q[bf]mask,
since incorrect values may cause the kernel to malfunction.
 1.23 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.22 12-Jul-1995  cgd implement a 'force check' flag, '-f'. I used the SunOS name, but the Digital
semantics. now:
(1) dirty file systems will always be checked; nothing new there.
(2) if not '-f' clean file systems will _NEVER_ be checked,
i.e. they won't be checked even if -p isn't specified. This
allows one to 'fsck -p ; fsck' to preen, then clean up
anything that 'fsck -p' barfs on, without waiting for the
clean file systems to be checked again.
(3) if '-f' clean file systems will ALWAYS be checked. This
allows people to put 'fsck -fp' into /etc/rc on systems
where they're leery of the FS clean flag state, need
the extra reliability, and can afford time 'wasted'
in checks.
The assumption made here is that if a file system is marked clean, it
_IS CLEAN_, really, and shouldn't be checked unless fsck is explicitly
told to (with -f). This should be a valid assumption, but may not be in
the presence of file system bugs. Documentation updated to note '-f'.
 1.21 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.20 21-Mar-1995  cgd type sizes
 1.19 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.18 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.17 27-Dec-1994  mycroft Copy fs_maxcluster when comparing superblocks.
 1.16 18-Dec-1994  cgd light clean, and make it compile against new header files.
 1.15 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.14 28-Oct-1994  mycroft Use the S_IS*() macros, and make this compile again after Chris's changes to ufs.
 1.13 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.12 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.11 29-Jun-1994  ws Reads on raw disks are only guarranteed in multiples of the block size
 1.10 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.9 25-Apr-1994  cgd oops; changed comparison, but not field!
 1.8 25-Apr-1994  cgd need <sys/time.h>
 1.7 14-Apr-1994  cgd fs type names will soon be strings
 1.6 09-Apr-1994  deraadt from <dean@fsa.ca>: let "fsck /usr" work. also, if the user does
"fsck /dev/sd0a" attempt to map to the raw device name.
 1.5 01-Oct-1993  mycroft Skip check if filesystem is marked clean and isn't too dusty, only with -p.
Set clean flag after checking a filesystem.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.36.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.36.2.2 26-Oct-1999  fvdl Fix some merge mistakes.
 1.36.2.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.37.4.5 25-Nov-2001  he Pull up revision 1.49 (requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.37.4.4 25-Nov-2001  he Pull up revision 1.47 (requested by lukem):
Deprecate unused fs_fscktime.
 1.37.4.3 25-Nov-2001  he Pull up revision 1.46 (requested by lukem):
Change fs_csp[] from being a fixed size to being an array sized
as required. This allows file systems with more than about 15500
cylinder groups (on 32-bit systems) to be used.
 1.37.4.2 25-Nov-2001  he Pull up revision 1.45 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.37.4.1 24-Nov-2001  he Pull up revisions 1.39-1.43 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.52.2.1 23-Feb-2003  jmc Pullup rev 1.57 (requested by fvdl in ticket #1180)
Only check relevant fields when comparing the superblock to an alternate
superblock. Avoids false positives should fsck_ffs be run on a filesystem
that was created after the UFS2 code has been merged.
 1.70.2.1 27-Apr-2004  jdc Pull up revisions 1.72-1.73 (requested by dbj in ticket #185)

Fix problems related to superblock upgrade issues which may be
experienced by -current users from 2003.
 1.81.10.2 28-Sep-2008  mjf Sync with HEAD.
 1.81.10.1 03-Apr-2008  mjf Sync with HEAD.
 1.81.8.1 24-Mar-2008  keiichi sync with head.
 1.81.2.1 23-Mar-2008  matt sync with HEAD
 1.82.6.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.82.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.84.8.1 21-Apr-2010  matt sync to netbsd-5
 1.84.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.84.2.1 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1036):
sbin/fsck_ffs/extern.h: revision 1.25 via patch
sbin/fsck_ffs/setup.c: revision 1.88 via patch
sbin/fsck_ffs/wapbl.c: revision 1.4 via patch
sbin/tunefs/tunefs.c: revision 1.41 via patch
sys/ufs/ffs/ffs_vfsops.c: revision 1.252 via patch
sys/ufs/ffs/ffs_wapbl.c: revision 1.13 via patch
Allow tunefs to clear any type of WAPBL log, not only in-filesystem
ones. Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
If the WAPBL journal can't be read (ffs_wapbl_replay_start() fails),
mount the filesystem anyway if MNT_FORCE is present.
This allows to still boot single-user a system with a corrupted
WAPBL on /, and so get a chance to run fsck to fix it.
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.90.2.2 17-Feb-2011  bouyer Move quota2_check_doquota() call so that an unclean, wapbl filesystem
will still be ckecked if a quota inode needs to be created.
 1.90.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.92.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.94.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.94.2.2 23-Jan-2013  yamt sync with head
 1.94.2.1 17-Apr-2012  yamt sync with head
 1.95.6.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.95.6.2 23-Jun-2013  tls resync from head
 1.95.6.1 25-Feb-2013  tls resync with head
 1.100.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.100.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.101.12.2 21-Apr-2020  martin Sync with HEAD
 1.101.12.1 10-Jun-2019  christos Sync with HEAD
 1.101.10.1 20-Oct-2018  pgoyette Sync with head
 1.101.4.1 09-Oct-2018  martin Pull up following revision(s) (requested by hannken in ticket #1051):

sbin/fsck_ffs/setup.c: revision 1.102

Add a test for duplicate inodes on the persistent snapshot list.
 1.102.2.1 12-Jul-2025  martin Pull up following revision(s) (requested by mlelstv in ticket #1964):

sbin/fsck_ffs/setup.c: revision 1.110 (patch)

Don't truncate bitmap size to unsigned int, avoids crashes on filesystems
with more than 2^32 blocks.
 1.104.2.3 12-Jul-2025  martin Pull up following revision(s) (requested by mlelstv in ticket #1135):

sbin/fsck_ffs/setup.c: revision 1.110

Don't truncate bitmap size to unsigned int, avoids crashes on filesystems
with more than 2^32 blocks.
 1.104.2.2 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #161):

sbin/fsck_ffs/setup.c: revision 1.106
sbin/fsck_ffs/pass5.c: revision 1.57

ufs: more signed/unsigned fixes

Fix the previous signed/unsigned fixes to build on 32-bit,
including applying this commit from FreeBSD:

commit 2d34afcd04207cf3fa3d5b7f467a890eae75da41
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Sun Oct 25 21:04:07 2020 +0000
Use proper type (ino_t) for inode numbers to avoid improper sign extention
in the Pass 5 checks. The manifestation was fsck_ffs exiting with this error:
** Phase 5 - Check Cyl groups
fsck_ffs: inoinfo: inumber 18446744071562087424 out of range
The error only manifests itself for filesystems bigger than about 100Tb.
Reported by: Nikita Grechikhin <ngrechikhin at yandex.ru>
MFC after: 2 weeks
Sponsored by: Netflix
 1.104.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.109.2.1 02-Aug-2025  perseant Sync with HEAD
 1.71 05-Jul-2023  riastradh Revert "fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.70 04-Jul-2023  riastradh fsck_ffs(8): Fix whitespace issues.

- Nix trailing whitespace.
- Omit excessive blank lines.
- Insert missing blank lines between $NetBSD$ and copyright.

No functional change intended.
 1.69 04-Jul-2023  riastradh fsck_ffs(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.68 14-Jan-2023  christos catch up with sign changes in the fs.h
 1.67 17-Nov-2022  chs branches: 1.67.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.66 17-Apr-2020  jdolecek align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) raw (character) device
 1.65 08-Feb-2017  rin branches: 1.65.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.64 19-Oct-2013  christos branches: 1.64.8; 1.64.12;
fix unused variable warnings.
 1.63 23-Jun-2013  dholland Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.62 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.61 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.60 09-Jun-2011  christos branches: 1.60.2; 1.60.8;
share more code.
 1.59 06-Mar-2011  bouyer branches: 1.59.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.58 07-Jan-2010  christos branches: 1.58.2;
make this compile again.
 1.57 06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.56 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.55 23-Feb-2008  christos branches: 1.55.4; 1.55.6;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.54 08-Feb-2007  drochner branches: 1.54.4; 1.54.10; 1.54.12;
include <signal.h> where signal(3) is used
 1.53 20-Mar-2006  christos Coverity CID 2074: Fix memory leak.
 1.52 23-Aug-2005  tron Use FFS_MAXNAMLEN instead of MAXNAMLEN.
 1.51 19-Aug-2005  christos 64 bit inode changes
 1.50 27-Jun-2005  christos sprinkle const.
 1.49 20-Jan-2005  xtraeme whitespace (pointed out by wiz@)
 1.48 19-Jan-2005  xtraeme Kill __P(), ANSIfy and WARNS=2
 1.47 12-Jun-2004  mycroft Use pread()/pwrite().
 1.46 13-Apr-2004  dbj fix range error when swapping postbl for compatibility
 1.45 15-Jan-2004  dbj branches: 1.45.2;
terminate preen message from previous with \n
 1.44 15-Jan-2004  dbj if the user specifies both -b and -p, then just go ahead and update
the primary superblock.
 1.43 09-Jan-2004  dbj do not upgrade superblock or set FS_FLAGS_UPDATED unless -c 4 option
is provided.
add compatibility for filesystems before FFSv2 integration
these patches are from pr port-macppc/23925 and should also
fix problems discussed in pr kern/21404 and pr kern/21283
 1.42 29-Dec-2003  dbj fix minor bug in buf cache statistic collecting
 1.41 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.40 13-Jul-2003  itojun use bounded string op
 1.39 14-Apr-2003  fvdl If an alternate superblock is used, update the standard one correctly.
 1.38 13-Apr-2003  yamt save and restore errno in signal handlers.
 1.37 06-Apr-2003  fvdl Write update some old fields when writing the superblock, similar to
ffs_oldfscompat_write() in the kernel. Use the old totals when
time < old_time (i.e. an old kernel or fsck wrote the filesystem last).
When setting the date back on a new kernel, that works out ok, since
new kernels always update both fields.
 1.36 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.35 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.34 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.33 06-May-2002  lukem If SIGINFO is received, display summary information to stderr.
Based on changes in FreeBSD, via Chuck Cranor <chuck@research.att.com>
 1.32 02-Sep-2001  lukem Incorporate fix by iedowse @ FreeBSD to allow disks with large numbers of
cylinder groups to work correctly, with minor modifications by me to work
with our FFS_EI code. From the FreeBSD commit message:

The ffs superblock includes a 128-byte region for use by temporary
in-core pointers to summary information. An array in this region
(fs_csp) could overflow on filesystems with a very large number of
cylinder groups (~16000 on i386 with 8k blocks). When this happens,
other fields in the superblock get corrupted, and fsck refuses to
check the filesystem.

Solve this problem by replacing the fs_csp array in 'struct fs'
with a single pointer, and add padding to keep the length of the
128-byte region fixed. Update the kernel and userland utilities
to use just this single pointer.

With this change, the kernel no longer makes use of the superblock
fields 'fs_csshift' and 'fs_csmask'. Add a comment to newfs/mkfs.c
to indicate that these fields must be calculated for compatibility
with older kernels.

Reviewed by: mckusick
 1.31 15-Aug-2001  lukem - implement -F; treat provided filesystems as images in regular files
- replace "filesystem" with "file system" as appropriate
- grammar fixes
 1.30 04-Feb-2001  christos remove redundant declarations
 1.29 09-Jan-2001  mycroft A minor tweak.
 1.28 09-Jan-2001  enami Don't swap cg_clustersum(cg)[0]. It doesn't actually exists and it's
actually tail of free block bitmap.

XXX swap_cg() should be shared with newfs.
 1.27 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.26 15-Nov-1999  fvdl branches: 1.26.4;
Changes for softdep code.
 1.25 06-May-1998  mycroft branches: 1.25.2; 1.25.4; 1.25.8;
copyback_cg() tried to copy too much if the cylinder group info was smaller
than 8k. From PR 5404.
 1.24 30-Mar-1998  mrg use extern int over extern
 1.23 18-Mar-1998  bouyer Add support for non-native byteorder FFS, and converting byteorder.
Also, be a bit more conservative with the clean flag: don't mark the FS
clean when we know there may still be errors (user anserwed 'n' to
a question, or fsck says "you must rerun fsck").
 1.22 24-Sep-1997  lukem for now, #ifdef out a couple of chunks that were added in the lite2 merge
 1.21 20-Sep-1997  lukem - don't indiscriminately include <stdlib.h> and <unistd.h> in "fsck.h"
- explicitly pull in <stdio.h>, <stdlib.h> and <unistd.h> in *.c as necessary
 1.20 16-Sep-1997  lukem resolve conflicts from lite-2 merge.
 1.19 14-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* cleanup manpage
* remove unused docheck() func
* prefix hex numbers with '0x'
* getopt returns -1 not EOF
 1.18 27-Sep-1996  christos - util.h -> fsutil.h
 1.17 23-Sep-1996  christos - fixed all printf formats [there were a lot of %l? <-> %? mistakes]
- added missing prototypes, and made local functions static
- removed parallel preening code; this is part of fsck(8)
- use printing utilities from fsck(8)
- Makefile does not make links to fsck and fsck.8
- removed -l maxparallel option. It has no meaning anymore.
 1.16 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.15 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.14 12-Apr-1995  mycroft Set the clean flag if necessary. If preening, don't check `clean' file
systems.
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 10-Feb-1995  cgd functions which are 'fake-varaargs' should be passed longs, not ints.
 1.11 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.10 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.9 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.8 02-May-1994  pk Prototype some things.
 1.7 25-Apr-1994  cgd need <sys/time.h>
 1.6 09-Apr-1994  deraadt if user does ie, "fsck /etc/group", then types ^C to the CONTINUE
prompt do not dump core. fix from <dean@fsa.ca> (who i will stop
hounding about bug fixes for an hour or two)
 1.5 28-Mar-1994  cgd kill extern'd lseek()
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.25.4.2 26-Oct-1999  fvdl Fix some merge mistakes.
 1.25.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.25.2.1 10-Oct-2000  he Pull up revision 1.27 (requested by is):
Format string cleanup.
 1.26.4.3 25-Nov-2001  he Pull up revision 1.32 (requested by lukem):
Change fs_csp[] from being a fixed size to being an array sized
as required. This allows file systems with more than about 15500
cylinder groups (on 32-bit systems) to be used.
 1.26.4.2 24-Nov-2001  he Pull up revisions 1.28-1.30 (requested by lukem):
Jumbo pullup for fsck_ffs:
o fix incorrect error message
o mark initialized globals with ``extern''
o make reconnect algorithm O(n) instead of O(n^4)
o remove dead code
o don't swap cg_clustersum(cg)[0], it's a bitmap
o ensure rotor values are positive
o some code restructuring
o fix byte swapping bug
o pass5: check alternate superblocks for consistency with in-core master
o fix usage message
 1.26.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.45.2.1 27-Apr-2004  jdc Pull up revision 1.46 (requested by dbj in ticket #185)

Fix problems related to superblock upgrade issues which may be
experienced by -current users from 2003.
 1.54.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.54.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.54.10.1 24-Mar-2008  keiichi sync with head.
 1.54.4.1 23-Mar-2008  matt sync with HEAD
 1.55.6.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.55.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.58.2.2 30-Jan-2011  bouyer Fix cut-n-paste: compare gid against gid, not uid.
 1.58.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.59.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.60.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.60.8.1 25-Feb-2013  tls resync with head
 1.60.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.60.2.1 23-Jan-2013  yamt sync with head
 1.64.12.1 21-Apr-2017  bouyer Sync with HEAD
 1.64.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.65.12.1 21-Apr-2020  martin Sync with HEAD
 1.67.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #162):

sbin/fsck_ffs/inode.c: revision 1.74
sbin/fsck_ffs/utilities.c: revision 1.68
sbin/fsck_ffs/fsck.h: revision 1.57
sbin/fsck_ffs/pass4.c: revision 1.30

catch up with sign changes in the fs.h
 1.6 25-Jul-2022  dholland Fix misleading fsck_ffs messages about wapbl journal replay.

Apparently fsck doesn't have a way to replay it to its internal memory
only. (Someone(TM) should implement this...)

This means that if you use -n, it can't replay the journal. But the
sequence of prints is such that it looks like it did. This is quite
misleading. Add an additional specific warning.
 1.5 06-Mar-2010  mlelstv When clearing a log on failure, not only ask the kernel to ignore an
existing log but to remove it on next mount.
 1.4 13-Sep-2009  bouyer Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.3 10-Nov-2008  joerg Reduce internals of WAPBL exposed to the rest of the system.
 1.2 31-Jul-2008  simonb branches: 1.2.2; 1.2.4; 1.2.6; 1.2.10;
Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.1 10-Jun-2008  simonb branches: 1.1.2;
file wapbl.c was initially added on branch simonb-wapbl.
 1.1.2.5 28-Jul-2008  simonb Add support for creating a WAPBL log in the filesystem. Will
create an in-filesystem log on first "mount -o log" if one doesn't
exist, and will then continue to use same log in the future. See
(soon to be added) wapbl(4) for more info.

Adds a new B_CONTIG low-level allocation flag that uses hints in
"struct ffs_inode_ext" to lay out an ffs file's data contiguously.

Thanks to Greg Oster for helping with the design of this and to
Antti Kantee for code review and suggestions.
 1.1.2.4 12-Jun-2008  martin License police
 1.1.2.3 11-Jun-2008  simonb Fix some whitespace and long line niggles.
 1.1.2.2 11-Jun-2008  simonb Fix a couple of typos. From wizd.
 1.1.2.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.2.10.1 21-Apr-2010  matt sync to netbsd-5
 1.2.6.1 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1036):
sbin/fsck_ffs/extern.h: revision 1.25 via patch
sbin/fsck_ffs/setup.c: revision 1.88 via patch
sbin/fsck_ffs/wapbl.c: revision 1.4 via patch
sbin/tunefs/tunefs.c: revision 1.41 via patch
sys/ufs/ffs/ffs_vfsops.c: revision 1.252 via patch
sys/ufs/ffs/ffs_wapbl.c: revision 1.13 via patch
Allow tunefs to clear any type of WAPBL log, not only in-filesystem
ones. Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
If the WAPBL journal can't be read (ffs_wapbl_replay_start() fails),
mount the filesystem anyway if MNT_FORCE is present.
This allows to still boot single-user a system with a corrupted
WAPBL on /, and so get a chance to run fsck to fix it.
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.2.4.3 17-Jan-2009  mjf Sync with HEAD.
 1.2.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.2.4.1 31-Jul-2008  mjf file wapbl.c was added on branch mjf-devfs2 on 2008-09-28 11:17:11 +0000
 1.2.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.2.1 31-Jul-2008  wrstuden file wapbl.c was added on branch wrstuden-revivesa on 2008-09-18 04:28:23 +0000
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.3 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.3 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.5 20-Aug-2001  wiz precede, not preceed.
 1.4 11-Oct-1996  thorpej Bug fix from Kirk McKusick <mckusick@McKusick.COM>:

Fix a bug in fsck_ffs where if a directory somehow develops a hole
(that is a block pointer that has a value of zero), fsck would give the
filesystem a clean bill of health, but the kernel would panic when
accessing the directory with the hole. Fsck now checks for holes
in directories. If found in preen mode, fsck fails. In manual
mode, it can be directed to shorten the directory to the beginning of
the hole. A more complete solution would be to allocate a block to fill
the hole. However, this is a lot more work for a `cannot happen' error,
so the extra effort seems unwarranted.
 1.3 05-Apr-1996  cgd branches: 1.3.4;
check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.3.4.1 02-Mar-1997  mycroft Pull up changes from Kirk McKusick to check for holes in directories.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.4 21-Nov-2001  wiz "than" instead of "then".
 1.3 05-Apr-1996  cgd check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.5 05-Jul-2014  dholland Reorg docs, part 3:
Move the documents that are papers to /usr/share/doc/papers.
Give them suitable names (including the author and year).

The key property of papers that distinguishes them from documentation
is that they're historical: they're published at a particular time and
aren't updated or maintained. (Except cosmetically.)

We should only ship papers that are of interest to users, either for
historical perspective or because they're the original research
writeup of stuff that went into the system and is still pertinent.

The ffs papers clearly meet this standard; the other one here (about
passwords, in 1978) is probably past its sell-by date.
 1.4 05-Jul-2014  dholland Rework /usr/share/doc.

Update the <bsd.doc.mk> infrastructure, and update the docs to match
the new infrastructure.

- Build and install text, ps, pdf, and/or html, not roff sources.

- Don't wire the chapter numbers into the build system, or use them in
the installed pathnames. This didn't matter much when the docs were a
museum, but now that we're theoretically going to start maintaining
them again, we're going to add and remove documents periodically and
having the chapter numbers baked in creates a lot of thrashing for no
purpose.

- Specify the document name explicitly, rather than implicitly in a
path. Use this name (instead of other random strings) as the name
of the installed files.

- Specify the document section, which is the subdirectory of
/usr/share/doc to install into.

- Allow multiple subdocuments. (That is, multiple documents in one
output directory.)

- Enumerate the .png files groff emits along with html so they can be
installed.

- Remove assorted hand-rolled rules for running roff and roff widgetry
and add enough variable settings to make these unnecessary. This
includes support for
- explicit use of soelim
- refer
- tbl
- pic
- eqn

- Forcibly apply at least minimal amounts of sanity to certain
autogenerated roff files.

- Don't exclude USD.doc, SMM.doc, and PSD.doc directories from the
build, as they now actually do stuff.

Note: currently we can't generate pdf. This turns out to be a
nontrivial problem with no immediate solution forthcoming. So for now,
as a workaround, install compressed .ps as the printable form.
 1.3 05-Apr-1996  cgd branches: 1.3.82; 1.3.94;
check in changes proposed in PR 2006 (approved by J.T.), to rename fsck
to fsck_ffs, so that in the future 'fsck' can be a wrapper than invokes
appropriate filesystem-specific checker programs. For now, the only
user-visible change is that the names have changed in the manual page
and in error messages; fsck and fsck.8 are now links to fsck_ffs and
fsck_ffs.8, until the rest of the transition is complete.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.3.94.1 10-Aug-2014  tls Rebase.
 1.3.82.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24 20-Apr-2024  rillig {usr.,}{s,}bin: replace LINT_SUPPORTED with the standard NOLINT

While here, re-enable lint in those cases where lint was skipped due to
a bug in interpreting abstract types, which was fixed in cgram.y 1.469
from 2023-08-02.
 1.23 14-Sep-2021  rillig sbin: enable lint for almost all programs

The programs fsck_lfs and newfs_lfs both trigger a longstanding bug in
lint that is difficult to fix, so ignore them for now.

For resize_ffs, lint thinks that 'struct fs' is incomplete, but GCC and
Clang accept it. Needs further investigation.
 1.22 07-Sep-2020  mrg remove GCC_NO_ADDR_OF_PACKED_MEMBER now lfs_accessors.h works.
 1.21 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.20 08-Jun-2013  dholland Redo these changes properly:
-r1.12 libexec/lfs_cleanerd/Makefile
-r1.15 sbin/fsck_lfs/Makefile
-r1.6 sbin/newfs_lfs/Makefile

hi ad@
 1.19 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.18 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.17 06-Aug-2009  pooka branches: 1.17.6; 1.17.12;
Define syscalls of lfs userspace tools (cleaner, mainly) through
a struct called kernelops, which contains standard system calls
for the normal case and rump system calls for the rump case.

Make it possible to run the lfs cleaner in a library fashion (taking
the quick route with the implementation).
 1.16 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.15 28-Dec-2007  ad branches: 1.15.12;
Make it build with src/sys from the vmlocking2 branch.
 1.14 26-Aug-2006  christos branches: 1.14.8; 1.14.10;
Programs that use efun.
 1.13 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.12 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.11 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.10 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.9 03-Jun-2005  lukem Disable -Wuninitialized on dir.c (until PR 30394 is addressed)
and pass6.c (until PR 30411 is addressed)
 1.8 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.7 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.6 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.5 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.4 19-Oct-2000  fvdl Disable VERBOSE_BLOCKMAP by default; it allocates huge amounts of
memory, causing immediate fsck_lfs failure for big filesystems.
 1.3 30-May-2000  perseant branches: 1.3.2;
Check for cycles in the inode free list, and for free inodes not on the free
list.
 1.2 16-May-2000  perseant branches: 1.2.2;
fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.2.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.3.2.1 19-Oct-2000  he Pull up revision 1.4 (requested by fvdl):
Fix a problem where fsck_lfs will dump core (runs out of memory)
on a file system above average in size.
 1.14.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.8.1 09-Jan-2008  matt sync with HEAD
 1.15.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.17.12.1 23-Jun-2013  tls resync from head
 1.17.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.21 03-Apr-2020  joerg branches: 1.21.8;
Avoid common symbols for fsck_lfs.
 1.20 30-Mar-2018  christos branches: 1.20.2;
PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.19 25-Aug-2016  christos branches: 1.19.6; 1.19.12;
PR/51440: Jose Luis Rodriguez Garcia: Use the standard queue.h macro instead
of playing with the TAILQ's entrails.
 1.18 18-Aug-2016  christos PR/51422: Jose Luis Rodriguez Garcia: completely remove B_NEEDCOMMIT
 1.17 18-Aug-2016  christos PR/51422: Jose Luis Rodriguez Garcia: Remove unnecessary assignment.
 1.16 31-Jul-2016  dholland PR 51264 Jose Luis Rodriguez Garcia: lfs userland bufcache rehash is broken
 1.15 29-Mar-2015  chopps branches: 1.15.2;
- Fix fallout for recent bread() change (removing cred arg).
 1.14 19-Oct-2013  christos branches: 1.14.4; 1.14.6; 1.14.10;
fix unused variable warnings.
 1.13 16-May-2008  hannken branches: 1.13.18; 1.13.24;
Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.12 28-Apr-2008  martin branches: 1.12.2;
Remove clause 3 and 4 from TNF licenses
 1.11 08-Oct-2007  ad branches: 1.11.8; 1.11.10;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.10 09-Nov-2006  christos branches: 1.10.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.9 19-Apr-2006  christos "struct ucred" should not be exposed to userland. Instead make it a "void *"
since it is not really used.
 1.8 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.7 20-May-2005  perseant Fail gracefully if we are asked to expand the buffer cache hash table size
when there is no memory available to do so. Use the uvnode's strategy
routine to retrieve data from the device, rather than always using pread().
Add a buffer header flag that specifies external management of the buffer's
data area.

All of this in support of a new cleaner, which is not included in this commit.
 1.6 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.5 06-Apr-2005  perseant Note that fsck_lfs may not know beforehand whether a given block is a
superblock or a segment summary, and tries both. These may be different
sizes. Fix a broken assertion that they are the same size.

Fixes PR # 29151.
 1.4 19-Mar-2005  perseant Buffer cache fixes: make sure we initialize all the hash lists, and allow
the cache to grow in size irrespective of how many buffers may be in the
locked queue, since we can't write those in any case. Prevents fsck_lfs
from spinning when it has too much to write.
 1.3 26-Feb-2005  perseant branches: 1.3.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.2 31-Mar-2003  perseant branches: 1.2.4;
Check inode free list tail pointer as well as head pointer, and write both
into the CLEANERINFO block of the Ifile as well as into the superblock.
Make preen update both superblocks.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.2.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.3.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.10.8.1 06-Nov-2007  matt sync with HEAD
 1.11.10.1 18-May-2008  yamt sync with head.
 1.11.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.13.24.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.13.18.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.10.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1612):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.14.6.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1612):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.14.4.1 06-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1612):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.15.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.19.12.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.19.6.1 08-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #855):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.20.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.21.8.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.21.8.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.14 30-Mar-2018  christos PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.13 18-Aug-2016  christos branches: 1.13.6; 1.13.12;
PR/51422: Jose Luis Rodriguez Garcia: completely remove B_NEEDCOMMIT
 1.12 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.11 16-May-2008  hannken branches: 1.11.38; 1.11.40; 1.11.44;
Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.10 28-Apr-2008  martin branches: 1.10.2;
Remove clause 3 and 4 from TNF licenses
 1.9 28-Dec-2007  ad branches: 1.9.4; 1.9.6;
Make it build with src/sys from the vmlocking2 branch.
 1.8 08-Oct-2007  ad branches: 1.8.2;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.7 03-May-2006  yamt branches: 1.7.10;
define dummy NOCRED by ourselves, rather than assuming that kernel headers
provide it.
 1.6 19-Apr-2006  christos "struct ucred" should not be exposed to userland. Instead make it a "void *"
since it is not really used.
 1.5 20-May-2005  perseant Fail gracefully if we are asked to expand the buffer cache hash table size
when there is no memory available to do so. Use the uvnode's strategy
routine to retrieve data from the device, rather than always using pread().
Add a buffer header flag that specifies external management of the buffer's
data area.

All of this in support of a new cleaner, which is not included in this commit.
 1.4 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.3 26-Feb-2005  perseant branches: 1.3.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.2 07-Aug-2003  agc branches: 1.2.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.2.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.3.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.7.10.2 09-Jan-2008  matt sync with HEAD
 1.7.10.1 06-Nov-2007  matt sync with HEAD
 1.8.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.9.6.1 18-May-2008  yamt sync with head.
 1.9.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.11.44.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1612):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.11.40.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1612):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.11.38.1 06-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1612):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.13.12.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.13.6.1 08-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #855):

sbin/fsck_lfs/bufcache.h: revision 1.14
sbin/fsck_lfs/bufcache.c: revision 1.20

PR/51418: Jose Luis Rodriguez Garcia: Fix incore src/sbin/fsck_lfs/bufcache.c
XXX: pullup-8, pullup-7
 1.47 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.46 21-Sep-2015  dholland branches: 1.46.16;
Add 64-bit directory entry structures, and adjust accessors accordingly.

The LFS64 directory entry has a 64-bit inode number. This is stored as
two 32-bit values to avoid inducing 64-bit alignment requirements.

The exposed type for manipulating directory entries is now
LFS_DIRHEADER, following the same convention as e.g. IFILE and SEGUSE.
(But with LFS_ on it, because.)
 1.45 21-Sep-2015  dholland Oops; LFS_DIRECTSIZ() is going to need the fs as an argument.

Also, it turns out that dirhash needs a compile-time-constant version
of LFS_DIRECTSIZ(LFS_MAXNAMLEN+1), independent of 64-vs-32, so create
LFS_MAXDIRENTRYSIZE for this. Sigh.
 1.44 20-Sep-2015  dholland Clean up struct lfs_dirtemplate.
 1.43 15-Sep-2015  dholland Pass around struct lfs_dirheader instead of struct lfs_direct.
 1.42 15-Sep-2015  dholland Add an accessor function for directory names.
 1.41 15-Sep-2015  dholland Add a function lfs_copydirname() to copy directory names in place; use
it in place of (variously) memcpy and strlcpy. (The latter isn't even
correct; was probably changed blindly from strncpy at some point.)

The new function zeroes the padding in the directory entry instead of
leaving trash behind.
 1.40 15-Sep-2015  dholland Tidyups/fixes preparatory to making d_name[] in struct lfs_direct size
0 instead of size LFS_MAXNAMLEN+1, and preparatory to having accessor
functions for d_name. In particular, don't create prototype entries
and copy them, and access the name field only for directory structures
that are in buffers with space for the name to exist.
 1.39 15-Sep-2015  dholland Add and use accessor functions for more of the directory entry fields.
 1.38 01-Sep-2015  dholland Add new accessors for the d_type and d_namlen fields of struct lfs_direct.
Napalm the old byteswap access logic for these.
 1.37 01-Sep-2015  dholland Use the lfs dinode accessors in place of the ufs-derived ones.
(Mostly.)

The ufs-derived ones are fake structure member macros, which are gross
and not very safe. Also, it seems that a lot of places in the lfs code
were using the ffsv1 branch of them unconditionally, and this way it's
guaranteed all those places have been updated.

Found while doing this: for non-devices, have getattr produce NODEV
in the rdev field instead of leaking the address of the first direct
block.
 1.36 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.35 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.34 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.33 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.32 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.31 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.30 08-Jun-2013  dholland DIRBLKSIZ -> LFS_DIRBLKSIZ
DIRECTSIZ -> LFS_DIRECTSIZ
DIRSIZ -> LFS_DIRSIZ
OLDDIRFMT -> LFS_OLDDIRFMT
NEWDIRFMT -> LFS_NEWDIRFMT
IFTODT -> LFS_IFTODT
DTTOIF -> LFS_DTTOIF
 1.29 08-Jun-2013  dholland struct direct -> struct lfs_direct
struct dirtemplate -> struct lfs_dirtemplate
struct odirtemplate -> struct lfs_odirtemplate
DT_* -> LFS_DT_*
 1.28 08-Jun-2013  dholland Stick LFS_ in front of IFMT, IFIFO, IFREG, etc. so as not to conflict
with the UFS copies of these symbols. (Which themselves ought to have
UFS_ stuck on.)
 1.27 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.26 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.25 16-Feb-2010  mlelstv branches: 1.25.6; 1.25.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.24 16-May-2008  hannken Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.23 16-Mar-2008  lukem branches: 1.23.2; 1.23.4;
errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.22 08-Oct-2007  ad branches: 1.22.6; 1.22.8;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.21 16-Oct-2006  christos branches: 1.21.8;
c99 initializers
 1.20 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.19 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.18 19-Aug-2005  christos 64 bit inode changes
 1.17 27-Jun-2005  christos more const.
 1.16 27-Jun-2005  christos constify
 1.15 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.14 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.13 05-Oct-2003  jdolecek fix NULL pointer pointer dereference in fileerror() when ino is NULL

problem reported and fix provided in PR kern/23065 by Gary Duzan, only
slightly adjusted to only do the VTOI() when needed
 1.12 03-Oct-2003  yamt write out modified directory entries to the correct place.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 13-Jul-2003  itojun use bounded string op
 1.9 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.8 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.7 23-May-2002  perseant Re-checksum the superblock whenever it is marked dirty.

Tested on alpha.
 1.6 09-May-2002  simonb branches: 1.6.2;
Don't bother testing if a uint8_t is > 256 -- that test is always false.
 1.5 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.4 14-Jun-2000  perseant branches: 1.4.4;
Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.3 23-May-2000  perseant branches: 1.3.2;
Convert to NetBSD source code style
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.3.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.4.1 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.6.2.1 02-Jun-2002  tv Pull up revision 1.7 (requested by perseant in ticket #131):
Re-checksum the superblock whenever it is marked dirty.
Tested on alpha.
 1.21.8.2 23-Mar-2008  matt sync with HEAD
 1.21.8.1 06-Nov-2007  matt sync with HEAD
 1.22.8.2 02-Jun-2008  mjf Sync with HEAD.
 1.22.8.1 03-Apr-2008  mjf Sync with HEAD.
 1.22.6.1 24-Mar-2008  keiichi sync with head.
 1.23.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.23.2.1 18-May-2008  yamt sync with head.
 1.25.12.2 23-Jun-2013  tls resync from head
 1.25.12.1 25-Feb-2013  tls resync with head
 1.25.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.25.6.1 23-Jan-2013  yamt sync with head
 1.46.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.16 03-Apr-2020  joerg branches: 1.16.8;
Avoid common symbols for fsck_lfs.
 1.15 03-Oct-2015  dholland branches: 1.15.16;
Remove a dead data structure.
 1.14 21-Sep-2015  dholland Add 64-bit directory entry structures, and adjust accessors accordingly.

The LFS64 directory entry has a 64-bit inode number. This is stored as
two 32-bit values to avoid inducing 64-bit alignment requirements.

The exposed type for manipulating directory entries is now
LFS_DIRHEADER, following the same convention as e.g. IFILE and SEGUSE.
(But with LFS_ on it, because.)
 1.13 15-Sep-2015  dholland Pass around struct lfs_dirheader instead of struct lfs_direct.
 1.12 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.11 08-Jun-2013  dholland struct direct -> struct lfs_direct
struct dirtemplate -> struct lfs_dirtemplate
struct odirtemplate -> struct lfs_odirtemplate
DT_* -> LFS_DT_*
 1.10 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.9 09-Jun-2011  christos branches: 1.9.2; 1.9.8;
share more code.
 1.8 27-Jun-2005  christos branches: 1.8.42;
constify
 1.7 18-Jul-2004  yamt remove a prototype of a non-exist function.
 1.6 13-Jul-2003  itojun use bounded string op
 1.5 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.4 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.3 23-May-2000  perseant Convert to NetBSD source code style
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.8.42.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.9.8.1 23-Jun-2013  tls resync from head
 1.9.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.16.8.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.16.8.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.27 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.26 03-Oct-2015  dholland branches: 1.26.16;
The per-inode state 'id_entryno' is used by pass1 for a block count,
so widen it to 'long long'. pass2 uses it for the number of entries in
a directory (IIUC) which does not need to be wider than int, but for
now let's not try to split into two fields. FUTURE...
 1.25 03-Oct-2015  dholland Use daddr_t instead of uint32_t for the in-memory copy of the inode
block pointers.
 1.24 03-Oct-2015  dholland Remove a dead data structure.
 1.23 21-Sep-2015  dholland Add 64-bit directory entry structures, and adjust accessors accordingly.

The LFS64 directory entry has a 64-bit inode number. This is stored as
two 32-bit values to avoid inducing 64-bit alignment requirements.

The exposed type for manipulating directory entries is now
LFS_DIRHEADER, following the same convention as e.g. IFILE and SEGUSE.
(But with LFS_ on it, because.)
 1.22 15-Sep-2015  dholland Pass around struct lfs_dirheader instead of struct lfs_direct.
 1.21 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.20 08-Jun-2013  dholland struct direct -> struct lfs_direct
struct dirtemplate -> struct lfs_dirtemplate
struct odirtemplate -> struct lfs_odirtemplate
DT_* -> LFS_DT_*
 1.19 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.18 09-Oct-2008  christos branches: 1.18.18; 1.18.24;
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.17 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.16 09-Nov-2006  christos branches: 1.16.2; 1.16.18; 1.16.20;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.15 27-Jun-2005  christos constify
 1.14 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.13 18-Jul-2004  yamt branches: 1.13.2;
zero-out dinode is not a proper way to 'clear' an lfs inode.
 1.12 20-Mar-2004  perseant change KES license to standard NetBSD license
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.9 29-Mar-2003  wiz Consistently spell occurrence with two rs.
 1.8 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.7 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.6 23-May-2002  perseant Re-checksum the superblock whenever it is marked dirty.

Tested on alpha.
 1.5 23-May-2000  perseant branches: 1.5.8;
Convert to NetBSD source code style
 1.4 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.3 20-Jan-2000  perseant Rename lfs_ifind so that it does not conflict with new kernel prototype.
Addresses PR #9253.
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant branches: 1.1.2;
Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.1.2.1 21-Jan-2000  he Pull up revision 1.3 (requested by perseant):
Fix name collision error due to recent kernel prototype updates.
Fixes PR#9253.
 1.5.8.1 02-Jun-2002  tv Pull up revision 1.6 (requested by perseant in ticket #131):
Re-checksum the superblock whenever it is marked dirty.
Tested on alpha.
 1.13.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.16.20.1 18-May-2008  yamt sync with head.
 1.16.18.2 17-Jan-2009  mjf Sync with HEAD.
 1.16.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.2.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.18.24.1 23-Jun-2013  tls resync from head
 1.18.18.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.27 14-Sep-2025  wiz fsck_lfs(8): add -i to SYNOPSIS, 'file system' police, bump date
 1.26 14-Sep-2025  perseant Document the -a and -i flags.
 1.25 12-Jul-2014  dholland Revert version 1.111 of sysinst/disks.c, which caused sysinst to
create lfs fstab entries with fsck disabled, and instead patch
fsck_lfs to exit successfully without doing anything when given the -p
(bootup preen) option. If you really want to do fsck_lfs -p, you can
do fsck_lfs -f -p to make it go.

This has been sitting in my todo queue since February 2010 and was
ok'd by the committer at the time. The original commit was based on
this post:
http://mail-index.netbsd.org/tech-kern/2010/02/09/msg007306.html

and I remain unconvinced that it's the right thing, but we can at
least do it properly and not ship a sysinst with -7 that creates
permanently wrong fstab files.

Note that this may cause problems for anyone who's taken -p out of the
bootup fsck flags; but doing that is wrong, so don't.
 1.24 18-Mar-2014  riastradh branches: 1.24.2;
Merge riastradh-drm2 to HEAD.
 1.23 20-Jul-2013  wiz Use Mt for email addresses.
 1.22 15-Mar-2009  joerg branches: 1.22.6; 1.22.12; 1.22.16;
Fix markup.
 1.21 09-Oct-2008  christos branches: 1.21.4;
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.20 14-Apr-2005  wiz branches: 1.20.4; 1.20.20;
Quote a word that would otherwise be interpreted as macro;
increase width argument to .Bl so that all options fit.
 1.19 14-Apr-2005  wiz Bump date for new -q; use Dq; capitalize NetBSD
in the usual way; new sentence, new line; some nits.
 1.18 14-Apr-2005  perseant Document "-f" (force check) flag. Implement and document "-q" (quiet).
 1.17 06-Jul-2004  wiz branches: 1.17.2;
Improve description of -b and -m.
 1.16 06-Jul-2004  wiz Document -m. It was already there, only commented out.
Bump date.

Addresses PR 26067 by Kouichirou Hiratsuka.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 16-Apr-2003  wiz Bump date for last.
 1.13 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.12 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.11 01-Oct-2002  wiz Use An, Aq for author markup.
 1.10 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.9 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.8 07-Feb-2002  ross Edit -mdoc usage.

* There is no -indent option to .Bd or .Bl, although you would
never know that from its frequent use in this tree. There is a
"-offset indent" combination that makes sense, and you can certainly
say "-width indent".

* Also, you can't markup the -width option argument, tho you CAN
use a callable macro. So "-width Ar filename" doesn't make sense,
but either "-width Ar" or "-width filename" does, as might something
like "-width xxfilename" for a little extra space.

* There are a lot of needlessly complex hanging tag macros in man4 used
to create simple item lists. Those should be simplified one of these
days before someone copies and edits yet another man4 page.
 1.7 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.6 05-Jun-2001  wiz Drop arguments of .Os.
 1.5 03-Apr-2001  wiz Xref newfs_lfs instead of newlfs; whitespace fixes while I'm here.
 1.4 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.3 16-May-2000  perseant branches: 1.3.4;
fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.2 19-Mar-1999  perseant "LFS" really stands for "Log-*structured* File System"
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.3.4.1 04-Apr-2001  he Pull up revisions 1.4-1.5 (requested by wiz):
Fix up various .Nm abuses.
Xref newfs_lfs instead of newlfs + whitespace fixes.
 1.17.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.20.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.20.4.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.21.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.16.1 23-Jul-2013  riastradh sync with HEAD
 1.22.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.2.1 10-Aug-2014  tls Rebase.
 1.17 14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.16 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.15 01-Sep-2015  dholland branches: 1.15.16;
Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.14 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.13 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.12 01-Sep-2006  perseant branches: 1.12.42; 1.12.48;
Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.11 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.10 27-Jun-2005  christos constify
 1.9 14-Apr-2005  perseant Document "-f" (force check) flag. Implement and document "-q" (quiet).
 1.8 07-Aug-2003  agc branches: 1.8.6;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.6 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.5 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.4 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.3 23-May-2000  perseant branches: 1.3.2;
Convert to NetBSD source code style
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.3.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.6.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.12.48.1 23-Jun-2013  tls resync from head
 1.12.42.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.70 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.69 10-Jun-2017  pgoyette branches: 1.69.6;
Update inode member i_flag --> i_state to keep up with kernel changes
 1.68 21-Sep-2015  dholland branches: 1.68.8;
Add 64-bit directory entry structures, and adjust accessors accordingly.

The LFS64 directory entry has a 64-bit inode number. This is stored as
two 32-bit values to avoid inducing 64-bit alignment requirements.

The exposed type for manipulating directory entries is now
LFS_DIRHEADER, following the same convention as e.g. IFILE and SEGUSE.
(But with LFS_ on it, because.)
 1.67 15-Sep-2015  dholland Pass around struct lfs_dirheader instead of struct lfs_direct.
 1.66 15-Sep-2015  dholland Add an accessor function for directory names.
 1.65 15-Sep-2015  dholland Tidyups/fixes preparatory to making d_name[] in struct lfs_direct size
0 instead of size LFS_MAXNAMLEN+1, and preparatory to having accessor
functions for d_name. In particular, don't create prototype entries
and copy them, and access the name field only for directory structures
that are in buffers with space for the name to exist.
 1.64 15-Sep-2015  dholland Add and use accessor functions for more of the directory entry fields.
 1.63 01-Sep-2015  dholland Add new accessors for the d_type and d_namlen fields of struct lfs_direct.
Napalm the old byteswap access logic for these.
 1.62 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.61 01-Sep-2015  dholland Use the lfs dinode accessors in place of the ufs-derived ones.
(Mostly.)

The ufs-derived ones are fake structure member macros, which are gross
and not very safe. Also, it seems that a lot of places in the lfs code
were using the ffsv1 branch of them unconditionally, and this way it's
guaranteed all those places have been updated.

Found while doing this: for non-devices, have getattr produce NODEV
in the rdev field instead of leaking the address of the first direct
block.
 1.60 19-Aug-2015  dholland Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.59 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.58 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.57 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.56 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.55 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.54 16-Jun-2015  christos fix error messages containing \n
 1.53 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.52 23-Mar-2014  dholland don't use sprintf
 1.51 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.50 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.49 08-Jun-2013  dholland DIRBLKSIZ -> LFS_DIRBLKSIZ
DIRECTSIZ -> LFS_DIRECTSIZ
DIRSIZ -> LFS_DIRSIZ
OLDDIRFMT -> LFS_OLDDIRFMT
NEWDIRFMT -> LFS_NEWDIRFMT
IFTODT -> LFS_IFTODT
DTTOIF -> LFS_DTTOIF
 1.48 08-Jun-2013  dholland struct direct -> struct lfs_direct
struct dirtemplate -> struct lfs_dirtemplate
struct odirtemplate -> struct lfs_odirtemplate
DT_* -> LFS_DT_*
 1.47 08-Jun-2013  dholland Stick LFS_ in front of IFMT, IFIFO, IFREG, etc. so as not to conflict
with the UFS copies of these symbols. (Which themselves ought to have
UFS_ stuck on.)
 1.46 08-Jun-2013  dholland Move the dinode (on-disk inode) structures to lfs.h, since they are
and will be obviously required by userland tools that need to read
the on-disk structures.

Also, DINODE{1,2}_SIZE -> LFS_DINODE{1,2}_SIZE.
 1.45 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.44 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.43 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.42 16-Feb-2010  mlelstv branches: 1.42.6; 1.42.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.41 04-Feb-2010  christos Centralize time printing and deal with ctime possibly returning NULL.
 1.40 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.39 16-May-2008  hannken Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.38 28-Apr-2008  martin branches: 1.38.2;
Remove clause 3 and 4 from TNF licenses
 1.37 08-Oct-2007  ad branches: 1.37.8; 1.37.10;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.36 09-Nov-2006  christos branches: 1.36.2; 1.36.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.35 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.34 19-Jul-2006  perseant On-disk inode accounting fix for roll-forward.
 1.33 19-Jul-2006  perseant Don't doubly free an inode remove_ino() during roll-forward.
 1.32 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.31 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.30 19-Aug-2005  christos 64 bit inode changes
 1.29 27-Jun-2005  christos more const.
 1.28 27-Jun-2005  christos constify
 1.27 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.26 25-Mar-2005  perseant "#define lfs_devvp lfs_unlockvp" for readability, since that's what we
use it for in fsck_lfs/newfs_lfs.
 1.25 06-Feb-2005  perry branches: 1.25.2;
ANSIfy a function declaration, remove obsolete "register" declarations.
 1.24 18-Jul-2004  yamt zero-out dinode is not a proper way to 'clear' an lfs inode.
 1.23 20-Mar-2004  perseant change KES license to standard NetBSD license
 1.22 03-Oct-2003  yamt make this work for big (ie. with indirect blocks) directories
without spurious 'EXTRA ..' errors.
 1.21 19-Sep-2003  itojun realloc pedant
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.19 13-Jul-2003  itojun use bounded string op
 1.18 12-Jul-2003  yamt in ckinode(), use idesc->id_number instead of dino.di_u.inumber
since the latter is invalid for pass2 and vget can return invalid vnode
for inode number 0.
 1.17 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.16 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.15 17-Feb-2003  perseant Add code to UBCify LFS. This is still behind "#ifdef LFS_UBC" for now
(there are still some details to work out) but expect that to go
away soon. To support these basic changes (creation of lfs_putpages,
lfs_gop_write, mods to lfs_balloc) several other changes were made, to
wit:

* Create a writer daemon kernel thread whose purpose is to handle page
writes for the pagedaemon, but which also takes over some of the
functions of lfs_check(). This thread is started the first time an
LFS is mounted.

* Add a "flags" parameter to GOP_SIZE. Current values are
GOP_SIZE_READ, meaning that the call should return the size of the
in-core version of the file, and GOP_SIZE_WRITE, meaning that it
should return the on-disk size. One of GOP_SIZE_READ or
GOP_SIZE_WRITE must be specified.

* Instead of using malloc(...M_WAITOK) for everything, reserve enough
resources to get by and use malloc(...M_NOWAIT), using the reserves if
necessary. Use the pool subsystem for structures small enough that
this is feasible. This also obsoletes LFS_THROTTLE.

And a few that are not strictly necessary:

* Moves the LFS inode extensions off onto a separately allocated
structure; getting closer to LFS as an LKM. "Welcome to 1.6O."

* Unified GOP_ALLOC between FFS and LFS.

* Update LFS copyright headers to correct values.

* Actually cast to unsigned in lfs_shellsort, like the comment says.

* Keep track of which segments were empty before the previous
checkpoint; any segments that pass two checkpoints both dirty and
empty can be summarily cleaned. Do this. Right now lfs_segclean
still works, but this should be turned into an effectless
compatibility syscall.
 1.14 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.13 23-May-2002  perseant Re-checksum the superblock whenever it is marked dirty.

Tested on alpha.
 1.12 25-Sep-2001  wiz branches: 1.12.2;
Add some \n to error messages.
 1.11 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.10 04-Feb-2001  christos branches: 1.10.2;
fix redundant decls
 1.9 06-Jan-2001  joff Fixed blockmap handling to properly use disk blocks rather than fragments.
Fixes an issue with fsck_lfs not detecting all duplicate blocks that may
exist in a corrupted filesystem.
 1.8 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.7 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.6 23-May-2000  perseant branches: 1.6.2;
Convert to NetBSD source code style
 1.5 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.4 20-Jan-2000  perseant Rename lfs_ifind so that it does not conflict with new kernel prototype.
Addresses PR #9253.
 1.3 03-Jul-1999  kleink RCS Id police.
 1.2 24-Mar-1999  nathanw branches: 1.2.2;
printf format fixes for Alpha.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.2.2.1 21-Jan-2000  he Pull up revision 1.4 (requested by perseant):
Fix name collision error due to recent kernel prototype updates.
Fixes PR#9253.
 1.6.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.10.2.3 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.10.2.2 30-Jun-2001  perseant Fixes, from joff, for correct compatibility operation of fsck_lfs, dumplfs,
lfs_cleanerd; correct usage message from dumplfs.
 1.10.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.12.2.1 02-Jun-2002  tv Pull up revision 1.13 (requested by perseant in ticket #131):
Re-checksum the superblock whenever it is marked dirty.
Tested on alpha.
 1.25.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.36.8.1 06-Nov-2007  matt sync with HEAD
 1.36.2.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.37.10.1 18-May-2008  yamt sync with head.
 1.37.8.2 17-Jan-2009  mjf Sync with HEAD.
 1.37.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.38.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.42.12.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.42.12.2 23-Jun-2013  tls resync from head
 1.42.12.1 25-Feb-2013  tls resync with head
 1.42.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.42.6.1 23-Jan-2013  yamt sync with head
 1.68.8.1 30-Oct-2017  snj Pull up following revision(s) (requested by maya in ticket #330):
sbin/fsck_lfs/inode.c: 1.69
sbin/fsck_lfs/lfs.c: 1.73
sbin/fsck_lfs/pass6.c: 1.50
sbin/fsck_lfs/segwrite.c: 1.46
sys/ufs/lfs/lfs.h: 1.202-1.203
sys/ufs/lfs/lfs_accessors.h: 1.48
sys/ufs/lfs/lfs_alloc.c: 1.136-1.137
sys/ufs/lfs/lfs_balloc.c: 1.94
sys/ufs/lfs/lfs_bio.c: 1.141
sys/ufs/lfs/lfs_extern.h: 1.113
sys/ufs/lfs/lfs_inode.c: 1.156-1.157
sys/ufs/lfs/lfs_inode.h: 1.20, 1.21, 1.23
sys/ufs/lfs/lfs_itimes.c: 1.20
sys/ufs/lfs/lfs_pages.c: 1.13-1.15
sys/ufs/lfs/lfs_rename.c: 1.22
sys/ufs/lfs/lfs_segment.c: 1.270-1.275
sys/ufs/lfs/lfs_subr.c: 1.94-1.97
sys/ufs/lfs/lfs_syscalls.c: 1.175
sys/ufs/lfs/lfs_vfsops.c: 1.360
sys/ufs/lfs/lfs_vnops.c: 1.316-1.321
sys/ufs/lfs/ulfs_inode.c: 1.20
sys/ufs/lfs/ulfs_inode.h: 1.24
sys/ufs/lfs/ulfs_lookup.c: 1.41
sys/ufs/lfs/ulfs_quota2.c: 1.31
sys/ufs/lfs/ulfs_readwrite.c: 1.24
sys/ufs/lfs/ulfs_vnops.c: 1.49-1.50
Update inode member i_flag --> i_state to keep up with kernel changes
Move definition of IN_ALLMOD near the flag it's a mask for.
Now we can see that it doesn't match all the flags, but changing that will
require more careful thought.
Correct confusion between i_flag and i_flags
These will have to be renamed.
Spotted by Riastradh, thanks!
Add an XXX about the missing flags so it's not buried in a commit
message.
now the XXX count for LFS is 260
Rename i_flag to i_state.
The similarity to i_flags has previously caused errors.
Use continue to denote the no-op loop to match netbsd style
newline for extra clarity.
It isn't safe to drain dirops with seglock held, it'll deadlock if there
are any dirops. drain before grabbing seglock.
lfs_dirops == 0 is always true (as we already drained dirops), so omit
that part of the comparison.
Fixes a lot of LFS deadlocks. PR kern/52301
Many thanks to dholland for help analyzing coredumps
Ifdef out KDASSERT which fires on my machine.
Deduplicate sanity check that seglock is held on segunlock
Revert r1.272 fix to PR kern/52301, the performance hit is making things
unusable.
change lfs_nextsegsleep and lfs_allclean_wakeup to use condvar
XXX had to use lfs_lock in lfs_segwait, removed kernel_lock, is this
appropriate?
fix buffer overflow/KASSERT when cookies are supplied
lfs no longer uses the ffs-style struct direct, use the correct minimum
size
from dholland
XXX more wrong
Consistently use {,UN}MARK_VNODE macros rather than function calls.
Not much point doing anything after a panic call
Ask some question about the code in a XXX comment
XXX question our double-flushing of dirops
Fix typo in comment
 1.69.6.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.4 17-Jun-2020  kamil Include explicitly <rump/rump_syscallshotgun.h> for previous indirect users
via <rump/rump.h>.
 1.3 13-Oct-2009  pooka fix prototypes of function pointers to varargs syscalls
 1.2 06-Aug-2009  pooka in const where available
 1.1 06-Aug-2009  pooka Define syscalls of lfs userspace tools (cleaner, mainly) through
a struct called kernelops, which contains standard system calls
for the normal case and rump system calls for the rump case.

Make it possible to run the lfs cleaner in a library fashion (taking
the quick route with the implementation).
 1.4 16-Feb-2010  mlelstv Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.3 13-Oct-2009  pooka fix prototypes of function pointers to varargs syscalls
 1.2 06-Aug-2009  pooka in const where available
 1.1 06-Aug-2009  pooka Define syscalls of lfs userspace tools (cleaner, mainly) through
a struct called kernelops, which contains standard system calls
for the normal case and rump system calls for the rump case.

Make it possible to run the lfs cleaner in a library fashion (taking
the quick route with the implementation).
 1.76 12-Oct-2025  perseant Look at the superblock magic number before attempting to read the address
of the first alternate out of it. If the magic number doesn't match one
of our known numbers, the primary is invalid and we have no way of locating
an alternate. Bail out in that case.

Makes fsck_lfs work for LFS64, at least in the minimal sense of being able
to report that a newly created LFS64 has no errors.
 1.75 03-Apr-2020  joerg branches: 1.75.8;
Avoid common symbols for fsck_lfs.
 1.74 12-Jun-2018  zafer branches: 1.74.2;
Remove duplicate assignments.
Fixes PR bin/51512 by Jose Luis Rodriguez Garcia
 1.73 10-Jun-2017  pgoyette branches: 1.73.4;
Update inode member i_flag --> i_state to keep up with kernel changes
 1.72 16-Sep-2016  christos branches: 1.72.6;
PR/51478: Jose Luis Rodriguez Garcia: Fix leak mem fsck_lfs/lfs.c
 1.71 20-Mar-2016  dholland branches: 1.71.2;
Comment out unused logic. PR 50973
 1.70 19-Feb-2016  riastradh Need <stdbool.h> for true/false.
 1.69 15-Oct-2015  dholland Enable lfs64 in fsck_lfs.
(and in everything else that uses this code)
 1.68 10-Oct-2015  dholland Track down and fix two missing uses of SEGSUM_FINFOBASE().
 1.67 03-Oct-2015  dholland Drop an explicit sign-extension in fsck that shouldn't be needed any
more.
 1.66 03-Oct-2015  dholland Add lfs_checkword type for reading checksum data out of structures.
This is always uint32_t, but having a name for it both makes things
clearer and avoids confusion about whether it should be 32 or 64 bit.

Note: deployed in only one place (that was erroneously tagged
ondisk32) so far.
 1.65 03-Oct-2015  dholland Fix hardwired 32-bit stuff in fsck:
- compute the maximum file size using LFS_BLKPTRSIZE()
- use the new IINFO in pass 6 instead of uint32_t pointers
- use accessors to read and write indirect blocks
 1.64 03-Oct-2015  dholland Apply IINFO in the other userland tools.
 1.63 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.62 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Part 2 of 3.
 1.61 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Part 1 of 3.
 1.60 01-Sep-2015  dholland The ifile's inode number is constant. (it is always 1)

Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
 1.59 01-Sep-2015  dholland Add byteswapping to the dinode accessors.

This prevents regressions in the ulfs code when switching to the new
accessors. Note that while adding byteswapping to the other accessors
is straightforward, I haven't done it yet; and that also is not enough
to make LFS_EI work, because there are places lying around that bypass
the accessors for one reason and another and all of them need to be
updated. That is going to have to wait for a later day as LFS_EI is
not on the critical path right now.
 1.58 01-Sep-2015  dholland Use the lfs dinode accessors in place of the ufs-derived ones.
(Mostly.)

The ufs-derived ones are fake structure member macros, which are gross
and not very safe. Also, it seems that a lot of places in the lfs code
were using the ffsv1 branch of them unconditionally, and this way it's
guaranteed all those places have been updated.

Found while doing this: for non-devices, have getattr produce NODEV
in the rdev field instead of leaking the address of the first direct
block.
 1.57 19-Aug-2015  dholland Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.56 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.55 12-Aug-2015  dholland Provide 32-bit and 64-bit versions of FINFO.

This also entailed sorting out part of struct segment, as that
contains a pointer into the current FINFO data.
 1.54 12-Aug-2015  dholland Make 32-bit and 64-bit versions of SEGSUM.
Also fix some of the FINFO handling as it's closely entangled.
 1.53 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.52 02-Aug-2015  dholland Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.51 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.50 02-Aug-2015  dholland Second batch of 64 -> 32 truncations in lfs, along with more minor
tidyups and corrections in passing.
 1.49 02-Aug-2015  dholland Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.
 1.48 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.47 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.46 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.45 31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.44 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.43 13-Jul-2014  dholland Revert previous; it doesn't work because all the lfs tools
promiscuously .PATH in each other's source files, and I haven't the
time or patience to deal with it tonight.
 1.42 12-Jul-2014  dholland Remove pointless function indirection through panic_func(). It was
initialized to one thing, and then set to another right at the top of
main and never changed again.
 1.41 19-Oct-2013  christos branches: 1.41.2;
fix unused variable warnings.
 1.40 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.39 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.38 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.37 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.36 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.35 12-Jul-2011  dholland branches: 1.35.2; 1.35.8;
Don't need to initialize (one of) the elements now in i_crap; nothing in
here touches that material.
 1.34 21-Jun-2011  mrg avoid code that looks like this:
x = x = y;
since GCC 4.5 complains about it having sequence point issues.
 1.33 21-Feb-2010  mlelstv branches: 1.33.4;
dev_bsize wasn't initialized. The actual value doesn't matter since
the same value is used to compute byte offsets into the special file
but a value of zero causes a division by zero.
 1.32 16-Feb-2010  mlelstv Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.31 06-Aug-2009  pooka Define syscalls of lfs userspace tools (cleaner, mainly) through
a struct called kernelops, which contains standard system calls
for the normal case and rump system calls for the rump case.

Make it possible to run the lfs cleaner in a library fashion (taking
the quick route with the implementation).
 1.30 22-Feb-2009  ad PR kern/26878 FFSv2 + softdep = livelock (no free ram)
PR kern/16942 panic with softdep and quotas
PR kern/19565 panic: softdep_write_inodeblock: indirect pointer #1 mismatch
PR kern/26274 softdep panic: allocdirect_merge: ...
PR kern/26374 Long delay before non-root users can write to softdep partitions
PR kern/28621 1.6.x "vp != NULL" panic in ffs_softdep.c:4653 while unmounting a softdep (+quota) filesystem
PR kern/29513 FFS+Softdep panic with unfsck-able file-corruption
PR kern/31544 The ffs softdep code appears to fail to write dirty bits to disk
PR kern/31981 stopping scsi disk can cause panic (softdep)
PR kern/32116 kernel panic in softdep (assertion failure)
PR kern/32532 softdep_trackbufs deadlock
PR kern/37191 softdep: locking against myself
PR kern/40474 Kernel panic after remounting raid root with softdep

Retire softdep, pass 2. As discussed and later formally announced on the
mailing lists.
 1.29 16-May-2008  hannken branches: 1.29.4;
Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.28 28-Apr-2008  martin branches: 1.28.2;
Remove clause 3 and 4 from TNF licenses
 1.27 08-Oct-2007  ad branches: 1.27.8; 1.27.10;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.26 09-Nov-2006  christos branches: 1.26.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.25 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.24 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.23 05-Jun-2006  christos fsck_lfs does not us fsutil.c; perhaps it should? revert to perror for now.
 1.22 05-Jun-2006  christos s/perror/perr
 1.21 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.20 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.19 13-Oct-2005  jmc Put back removed initializer. gcc on sh3 still doesn't get it correct...
 1.18 08-Oct-2005  chs avoid the need for a bogus initializer.
 1.17 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.16 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.15 07-Jun-2005  he Initialize metalbn in ufs_getlbns to appease -Wuninitialized.
Marked with XXXGCC for dreamcast (found while compiling for it).

Reviewed by lukem.
 1.14 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.13 23-May-2005  perseant Check some error conditions that would otherwise cause fsck_lfs to dump core.
Pointed out by Pavel Cahyna in a follow-on to PR #29151.
 1.12 23-Apr-2005  perseant Check parts of pass 5 even if only rolling forward. We can't check the true
segment holdings against the blocks held by the inodes, but we can still
check the cleanerinfo data against the segment table.
 1.11 12-Apr-2005  martin When creating an int hash value from pointer, go via intptr_t.
Fixes PR 29953.
 1.10 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.9 25-Mar-2005  perseant "#define lfs_devvp lfs_unlockvp" for readability, since that's what we
use it for in fsck_lfs/newfs_lfs.
 1.8 26-Feb-2005  perseant branches: 1.8.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.7 07-Aug-2003  agc branches: 1.7.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 12-Jul-2003  yamt in lfs_raw_vget(),
- don't leave references into free'ed memory region. (fix SIGBUSes)
- plug a memory leak.
 1.5 12-Jul-2003  yamt - don't assume that malloc'ed memory is zero-filled.
- LIST_INIT {dirty,clean} block lists.
 1.4 12-Jul-2003  yamt only read superblock (ie. struct dlfs) from disk and
initialize rest of struct lfs by hand.
(this shouldn't cause a real problem since if superblock is valid,
LFS_SBPAD-sizeof(struct dlfs) bytes after it is always zero-filled, though)

PR/22123 (Izumi Tsutsui)
 1.3 08-May-2003  petrov Fix format string. (no % in PRIx..).
 1.2 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.7.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.8.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.26.8.1 06-Nov-2007  matt sync with HEAD
 1.27.10.1 18-May-2008  yamt sync with head.
 1.27.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.28.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.29.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.33.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.35.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.35.8.2 23-Jun-2013  tls resync from head
 1.35.8.1 25-Feb-2013  tls resync with head
 1.35.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.35.2.1 23-Jan-2013  yamt sync with head
 1.41.2.1 10-Aug-2014  tls Rebase.
 1.71.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.72.6.1 30-Oct-2017  snj Pull up following revision(s) (requested by maya in ticket #330):
sbin/fsck_lfs/inode.c: 1.69
sbin/fsck_lfs/lfs.c: 1.73
sbin/fsck_lfs/pass6.c: 1.50
sbin/fsck_lfs/segwrite.c: 1.46
sys/ufs/lfs/lfs.h: 1.202-1.203
sys/ufs/lfs/lfs_accessors.h: 1.48
sys/ufs/lfs/lfs_alloc.c: 1.136-1.137
sys/ufs/lfs/lfs_balloc.c: 1.94
sys/ufs/lfs/lfs_bio.c: 1.141
sys/ufs/lfs/lfs_extern.h: 1.113
sys/ufs/lfs/lfs_inode.c: 1.156-1.157
sys/ufs/lfs/lfs_inode.h: 1.20, 1.21, 1.23
sys/ufs/lfs/lfs_itimes.c: 1.20
sys/ufs/lfs/lfs_pages.c: 1.13-1.15
sys/ufs/lfs/lfs_rename.c: 1.22
sys/ufs/lfs/lfs_segment.c: 1.270-1.275
sys/ufs/lfs/lfs_subr.c: 1.94-1.97
sys/ufs/lfs/lfs_syscalls.c: 1.175
sys/ufs/lfs/lfs_vfsops.c: 1.360
sys/ufs/lfs/lfs_vnops.c: 1.316-1.321
sys/ufs/lfs/ulfs_inode.c: 1.20
sys/ufs/lfs/ulfs_inode.h: 1.24
sys/ufs/lfs/ulfs_lookup.c: 1.41
sys/ufs/lfs/ulfs_quota2.c: 1.31
sys/ufs/lfs/ulfs_readwrite.c: 1.24
sys/ufs/lfs/ulfs_vnops.c: 1.49-1.50
Update inode member i_flag --> i_state to keep up with kernel changes
Move definition of IN_ALLMOD near the flag it's a mask for.
Now we can see that it doesn't match all the flags, but changing that will
require more careful thought.
Correct confusion between i_flag and i_flags
These will have to be renamed.
Spotted by Riastradh, thanks!
Add an XXX about the missing flags so it's not buried in a commit
message.
now the XXX count for LFS is 260
Rename i_flag to i_state.
The similarity to i_flags has previously caused errors.
Use continue to denote the no-op loop to match netbsd style
newline for extra clarity.
It isn't safe to drain dirops with seglock held, it'll deadlock if there
are any dirops. drain before grabbing seglock.
lfs_dirops == 0 is always true (as we already drained dirops), so omit
that part of the comparison.
Fixes a lot of LFS deadlocks. PR kern/52301
Many thanks to dholland for help analyzing coredumps
Ifdef out KDASSERT which fires on my machine.
Deduplicate sanity check that seglock is held on segunlock
Revert r1.272 fix to PR kern/52301, the performance hit is making things
unusable.
change lfs_nextsegsleep and lfs_allclean_wakeup to use condvar
XXX had to use lfs_lock in lfs_segwait, removed kernel_lock, is this
appropriate?
fix buffer overflow/KASSERT when cookies are supplied
lfs no longer uses the ffs-style struct direct, use the correct minimum
size
from dholland
XXX more wrong
Consistently use {,UN}MARK_VNODE macros rather than function calls.
Not much point doing anything after a panic call
Ask some question about the code in a XXX comment
XXX question our double-flushing of dirops
Fix typo in comment
 1.73.4.1 25-Jun-2018  pgoyette Sync with HEAD
 1.74.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.75.8.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.75.8.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.7 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.6 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.5 01-Apr-2005  he Move the definition of simple_lock() and simple_unlock() to a common
header, since more of the LFS macros now use these functions. Since
we're outside of the kernel, these are defined to be empty.
 1.4 25-Mar-2005  perseant "#define lfs_devvp lfs_unlockvp" for readability, since that's what we
use it for in fsck_lfs/newfs_lfs.
 1.3 26-Feb-2005  perseant branches: 1.3.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.2 02-Apr-2003  fvdl branches: 1.2.4;
Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.2.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.3.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.14 01-Sep-2015  dholland branches: 1.14.28;
Remove ulfs_daddr_t.
 1.13 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Part 2 of 3.
 1.12 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Part 1 of 3.
 1.11 19-Aug-2015  dholland Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.10 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.9 12-Aug-2015  dholland Provide 32-bit and 64-bit versions of FINFO.

This also entailed sorting out part of struct segment, as that
contains a pointer into the current FINFO data.
 1.8 12-Aug-2015  dholland Make 32-bit and 64-bit versions of SEGSUM.
Also fix some of the FINFO handling as it's closely entangled.
 1.7 13-Jul-2014  dholland Revert previous; it doesn't work because all the lfs tools
promiscuously .PATH in each other's source files, and I haven't the
time or patience to deal with it tonight.
 1.6 12-Jul-2014  dholland G/C my_vpanic().
 1.5 08-Jun-2013  dholland branches: 1.5.4;
Redo these changes properly:
-r1.12 libexec/lfs_cleanerd/Makefile
-r1.15 sbin/fsck_lfs/Makefile
-r1.6 sbin/newfs_lfs/Makefile

hi ad@
 1.4 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.3 28-Apr-2008  martin branches: 1.3.20; 1.3.26;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jul-2006  perseant branches: 1.2.20; 1.2.22;
Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.1 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.2.22.1 18-May-2008  yamt sync with head.
 1.2.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.26.1 23-Jun-2013  tls resync from head
 1.3.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.4.1 10-Aug-2014  tls Rebase.
 1.14.28.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.14.28.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.58 14-Sep-2025  wiz fsck_lfs: add -i to usage
 1.57 14-Sep-2025  perseant Document the -a and -i flags.
 1.56 14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.55 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.54 15-Aug-2019  kamil fsck: Stop defining the same variable concurrently in bss and data

returntosingle was defined in multiple places:

- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.53 03-Feb-2019  mrg branches: 1.53.2;
- add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.52 28-Jul-2015  dholland branches: 1.52.16;
Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.51 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.50 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.49 16-Jun-2015  christos fix error messages containing \n
 1.48 13-Jul-2014  dholland Revert previous; it doesn't work because all the lfs tools
promiscuously .PATH in each other's source files, and I haven't the
time or patience to deal with it tonight.
 1.47 12-Jul-2014  dholland Remove pointless function indirection through panic_func(). It was
initialized to one thing, and then set to another right at the top of
main and never changed again.
 1.46 12-Jul-2014  dholland Revert version 1.111 of sysinst/disks.c, which caused sysinst to
create lfs fstab entries with fsck disabled, and instead patch
fsck_lfs to exit successfully without doing anything when given the -p
(bootup preen) option. If you really want to do fsck_lfs -p, you can
do fsck_lfs -f -p to make it go.

This has been sitting in my todo queue since February 2010 and was
ok'd by the committer at the time. The original commit was based on
this post:
http://mail-index.netbsd.org/tech-kern/2010/02/09/msg007306.html

and I remain unconvinced that it's the right thing, but we can at
least do it properly and not ship a sysinst with -7 that creates
permanently wrong fstab files.

Note that this may cause problems for anyone who's taken -p out of the
bootup fsck flags; but doing that is wrong, so don't.
 1.45 08-Jun-2013  dholland branches: 1.45.4;
Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.44 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.43 09-Jun-2011  christos branches: 1.43.2; 1.43.8;
share more code.
 1.42 07-Jan-2010  christos branches: 1.42.4;
make this compile again.
 1.41 06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.40 12-Oct-2008  wiz Don't use unicode in usage.
Noted by Anon Ymous.
 1.39 09-Oct-2008  wiz Sync usage with man page.
 1.38 09-Oct-2008  christos Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.37 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.36 16-Jul-2007  pooka branches: 1.36.4; 1.36.10; 1.36.12;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.35 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.34 08-Feb-2007  drochner include <signal.h> where signal(3) is used
 1.33 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.32 01-Dec-2006  tls branches: 1.32.2;
Prompt before rolling forward, in interactive mode, so it's possible to fix
the filesystem but not roll forward possibly unwanted changes.
 1.31 09-Nov-2006  christos Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.30 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.29 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.28 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.27 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.26 19-Aug-2005  christos 64 bit inode changes
 1.25 27-Jun-2005  christos constify
 1.24 23-Apr-2005  perseant Check parts of pass 5 even if only rolling forward. We can't check the true
segment holdings against the blocks held by the inodes, but we can still
check the cleanerinfo data against the segment table.
 1.23 14-Apr-2005  wiz Sync usage with man page.
 1.22 14-Apr-2005  perseant Document "-f" (force check) flag. Implement and document "-q" (quiet).
 1.21 06-Apr-2005  perseant Correct phase 0 message
 1.20 19-Jan-2005  xtraeme branches: 1.20.2;
ANSIfy, WARNS=2
 1.19 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.18 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.17 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.16 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 29-Mar-2003  perseant Fix some accounting problems when preening, since preening skips phases
1-4 entirely. Make preen run phase 0, since the Ifile is so important
and the test so quick.
 1.13 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.12 28-Jan-2003  mrg make this build on alpha after daddr_t->64bit
 1.11 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.10 18-Aug-2001  ad getopt() returns -1 on error, not EOF.
 1.9 19-Feb-2001  cgd convert to use getprogname()
 1.8 04-Feb-2001  christos fix redundant decls
 1.7 11-Nov-2000  perseant Add "-f" flag to match fsck(8) manual page. This flag currently has no
effect. Fixes PR #11129.
 1.6 14-Jun-2000  perseant branches: 1.6.2;
Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.5 23-May-2000  perseant branches: 1.5.2;
Convert to NetBSD source code style
 1.4 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.3 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.1 03-Feb-2001  he Pull up revision 1.7 (requested by perseant):
Add compatibility option "-f" to fsck_lfs (PR #11129).
 1.20.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.32.2.1 24-Mar-2009  bouyer Pull up following revision(s) (requested by manu in ticket #1288):
sbin/fsck_lfs/inode.c: revision 1.40 via patch
sbin/fsck_ffs/fsck_ffs.8: revision 1.44 via patch
sbin/fsck_ext2fs/fsck.h: revision 1.14 via patch
sbin/fsck_ext2fs/main.c: revision 1.30 via patch
sbin/fsck_ffs/inode.c: revision 1.61 via patch
sbin/fsck_ffs/main.c: revision 1.71 via patch
sbin/fsck_ext2fs/inode.c: revision 1.23 via patch
sbin/fsck_lfs/fsck.h: revision 1.18 via patch
sbin/fsck_lfs/fsck_lfs.8: revision 1.21 via patch
sbin/fsck_lfs/main.c: revision 1.38 via patch
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.15 via patch
sbin/fsck_ffs/fsck.h: revision 1.47 via patch
Disable userid to username lookups by default. Add a -U flag to perform them.
In single user mode lookups that involve the network might not work and they
slow down fsck.
 1.36.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.36.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.36.10.1 24-Mar-2008  keiichi sync with head.
 1.36.4.1 23-Mar-2008  matt sync with HEAD
 1.42.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.43.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.8.1 23-Jun-2013  tls resync from head
 1.43.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.4.1 10-Aug-2014  tls Rebase.
 1.52.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.52.16.1 10-Jun-2019  christos Sync with HEAD
 1.53.2.1 16-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #73):

sbin/fsck_lfs/main.c: revision 1.54
sbin/fsck_ext2fs/main.c: revision 1.40
sbin/fsck_ffs/main.c: revision 1.86

fsck: Stop defining the same variable concurrently in bss and data
returntosingle was defined in multiple places:
- fsck_lfs/main.c
- fsck_ffs/main.c
- fsck_ext2fs/main.c
- fsck/fsutil.c

Keep the fsutil.c definition as the only one.

Detected during the build of telned with Address Sanitizer (MKSANITIZER).
 1.43 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.42 01-Sep-2015  dholland branches: 1.42.16;
Make the inode fields in the 64-bit superblock 64 bits wide.
Reasoning as before.

Note that I am not going through and checking for 64->32 truncations
in inode numbers; I'm sure there are quite a few, but that's a project
for later.
 1.41 23-Aug-2015  christos swap the formats too, not just the args.
 1.40 23-Aug-2015  dholland Fix reversed arguments to a print. nice and confusing...
 1.39 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.38 12-Aug-2015  dholland Make 32-bit and 64-bit versions of CLEANERINFO.

XXX: while this is written to disk, it seems like much of it would
XXX: be better set up as a commpage shared with the cleaner.
 1.37 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.36 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.35 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.34 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.33 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.32 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.31 28-Apr-2008  martin branches: 1.31.20; 1.31.26;
Remove clause 3 and 4 from TNF licenses
 1.30 08-Oct-2007  ad branches: 1.30.8; 1.30.10;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.29 09-Nov-2006  christos branches: 1.29.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.28 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.27 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.26 17-Mar-2006  perseant Make it compile again.
 1.25 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.24 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.23 20-Aug-2005  kent fix a compilation problem on LP64
 1.22 19-Aug-2005  christos 64 bit inode changes
 1.21 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.20 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.19 25-Mar-2005  perseant Make fsck_lfs optimize the inode free list, if it appears to have become
too disordered. This should improve file creation speed on aged filesystems.
Include code to disorder the list for debugging purposes, though this is
of course not compiled in by default.
 1.18 26-Feb-2005  perseant branches: 1.18.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.17 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.16 07-Aug-2003  agc branches: 1.16.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.15 31-Mar-2003  perseant Check inode free list tail pointer as well as head pointer, and write both
into the CLEANERINFO block of the Ifile as well as into the superblock.
Make preen update both superblocks.
 1.14 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.13 17-Feb-2003  perseant Add code to UBCify LFS. This is still behind "#ifdef LFS_UBC" for now
(there are still some details to work out) but expect that to go
away soon. To support these basic changes (creation of lfs_putpages,
lfs_gop_write, mods to lfs_balloc) several other changes were made, to
wit:

* Create a writer daemon kernel thread whose purpose is to handle page
writes for the pagedaemon, but which also takes over some of the
functions of lfs_check(). This thread is started the first time an
LFS is mounted.

* Add a "flags" parameter to GOP_SIZE. Current values are
GOP_SIZE_READ, meaning that the call should return the size of the
in-core version of the file, and GOP_SIZE_WRITE, meaning that it
should return the on-disk size. One of GOP_SIZE_READ or
GOP_SIZE_WRITE must be specified.

* Instead of using malloc(...M_WAITOK) for everything, reserve enough
resources to get by and use malloc(...M_NOWAIT), using the reserves if
necessary. Use the pool subsystem for structures small enough that
this is feasible. This also obsoletes LFS_THROTTLE.

And a few that are not strictly necessary:

* Moves the LFS inode extensions off onto a separately allocated
structure; getting closer to LFS as an LKM. "Welcome to 1.6O."

* Unified GOP_ALLOC between FFS and LFS.

* Update LFS copyright headers to correct values.

* Actually cast to unsigned in lfs_shellsort, like the comment says.

* Keep track of which segments were empty before the previous
checkpoint; any segments that pass two checkpoints both dirty and
empty can be summarily cleaned. Do this. Right now lfs_segclean
still works, but this should be turned into an effectless
compatibility syscall.
 1.12 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.11 04-Feb-2002  perseant Use the correct size for inode blocks. This caused false data checksum
mispatches to be reported on v2 filesystems.
 1.10 02-Nov-2001  lukem fix -Wshadow warning
 1.9 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.8 05-Jan-2001  lukem branches: 1.8.2;
use %ll_ instead of the less standard %q_
 1.7 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.6 30-May-2000  perseant Check for cycles in the inode free list, and for free inodes not on the free
list.
 1.5 23-May-2000  perseant branches: 1.5.2;
Convert to NetBSD source code style
 1.4 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.3 03-Jul-1999  kleink RCS Id police.
 1.2 24-Mar-1999  nathanw printf format fixes for Alpha.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.2.2 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.8.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.16.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.18.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.29.8.1 06-Nov-2007  matt sync with HEAD
 1.30.10.1 18-May-2008  yamt sync with head.
 1.30.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.31.26.2 23-Jun-2013  tls resync from head
 1.31.26.1 25-Feb-2013  tls resync with head
 1.31.20.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31.20.1 23-Jan-2013  yamt sync with head
 1.42.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.47 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.46 23-Feb-2020  riastradh Fix userland references to LFS_ORPHAN_NEXTFREE.

Forgot to grep for these or do a full distribution build, oops!
 1.45 03-Oct-2015  dholland branches: 1.45.16; 1.45.18;
The per-inode state 'id_entryno' is used by pass1 for a block count,
so widen it to 'long long'. pass2 uses it for the number of entries in
a directory (IIUC) which does not need to be wider than int, but for
now let's not try to split into two fields. FUTURE...
 1.44 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.43 01-Sep-2015  dholland The ifile's inode number is constant. (it is always 1)

Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
 1.42 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.41 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.40 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.39 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.38 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.37 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.36 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.35 08-Jun-2013  dholland DIRBLKSIZ -> LFS_DIRBLKSIZ
DIRECTSIZ -> LFS_DIRECTSIZ
DIRSIZ -> LFS_DIRSIZ
OLDDIRFMT -> LFS_OLDDIRFMT
NEWDIRFMT -> LFS_NEWDIRFMT
IFTODT -> LFS_IFTODT
DTTOIF -> LFS_DTTOIF
 1.34 08-Jun-2013  dholland Stick LFS_ in front of IFMT, IFIFO, IFREG, etc. so as not to conflict
with the UFS copies of these symbols. (Which themselves ought to have
UFS_ stuck on.)
 1.33 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.32 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.31 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.30 16-Feb-2010  mlelstv branches: 1.30.6; 1.30.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.29 08-Oct-2007  ad Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.28 09-Nov-2006  christos branches: 1.28.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.27 16-Oct-2006  christos comment out/delete impossible code
 1.26 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.25 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.24 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.23 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.22 19-Aug-2005  christos 64 bit inode changes
 1.21 27-Jun-2005  christos constify
 1.20 06-Feb-2005  perry remove obsolete "register" declarations.
 1.19 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.18 18-Jul-2004  yamt zero-out dinode is not a proper way to 'clear' an lfs inode.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 12-Jul-2003  yamt fix a null dereference on stale inode.
 1.15 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.14 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.13 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.12 25-Sep-2001  wiz Add some \n to error messages.
 1.11 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.10 06-Jan-2001  joff branches: 1.10.2;
Fixed blockmap handling to properly use disk blocks rather than fragments.
Fixes an issue with fsck_lfs not detecting all duplicate blocks that may
exist in a corrupted filesystem.
 1.9 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.8 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.7 30-May-2000  perseant Check for cycles in the inode free list, and for free inodes not on the free
list.
 1.6 23-May-2000  perseant branches: 1.6.2;
Convert to NetBSD source code style
 1.5 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.4 20-Jan-2000  perseant Rename lfs_ifind so that it does not conflict with new kernel prototype.
Addresses PR #9253.
 1.3 03-Jul-1999  kleink RCS Id police.
 1.2 24-Mar-1999  nathanw branches: 1.2.2;
printf format fixes for Alpha.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.2.2.1 21-Jan-2000  he Pull up revision 1.4 (requested by perseant):
Fix name collision error due to recent kernel prototype updates.
Fixes PR#9253.
 1.6.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.10.2.1 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.28.8.1 06-Nov-2007  matt sync with HEAD
 1.30.12.2 23-Jun-2013  tls resync from head
 1.30.12.1 25-Feb-2013  tls resync with head
 1.30.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.30.6.1 23-Jan-2013  yamt sync with head
 1.45.18.1 17-Aug-2020  martin Pull up following revision(s) (requested by riastradh in ticket #1050):

sys/ufs/lfs/lfs_subr.c: revision 1.101
sys/ufs/lfs/lfs_subr.c: revision 1.102
sys/ufs/lfs/lfs_inode.c: revision 1.158
sys/ufs/lfs/lfs_inode.h: revision 1.25
sys/ufs/lfs/lfs_balloc.c: revision 1.95
sys/ufs/lfs/lfs_pages.c: revision 1.21
sys/ufs/lfs/lfs_vnops.c: revision 1.330
sys/ufs/lfs/lfs_alloc.c: revision 1.140 (patch)
sys/ufs/lfs/lfs_alloc.c: revision 1.141 (patch)
lib/libp2k/p2k.c: revision 1.72
sys/ufs/lfs/lfs.h: revision 1.205
sys/ufs/lfs/lfs.h: revision 1.206
sys/ufs/lfs/lfs_segment.c: revision 1.284
sys/ufs/lfs/lfs.h: revision 1.207
sys/ufs/lfs/lfs_segment.c: revision 1.285
sys/ufs/lfs/lfs_debug.c: revision 1.55
sys/ufs/lfs/lfs_rename.c: revision 1.23
usr.sbin/dumplfs/dumplfs.c: revision 1.65
sys/ufs/lfs/lfs_vfsops.c: revision 1.371
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.3
sys/ufs/lfs/lfs_vfsops.c: revision 1.372
sys/ufs/lfs/lfs_vfsops.c: revision 1.373
sbin/fsck_lfs/pass1.c: revision 1.46
sys/ufs/lfs/lfs_vnops.c: revision 1.326
sys/ufs/lfs/lfs_vnops.c: revision 1.327
sys/ufs/lfs/lfs_vfsops.c: revision 1.375 (patch)
sys/ufs/lfs/lfs_vnops.c: revision 1.328
sys/ufs/lfs/lfs_subr.c: revision 1.98
sys/ufs/lfs/lfs_extern.h: revision 1.116
sys/ufs/lfs/lfs_vnops.c: revision 1.329
sys/ufs/lfs/lfs_subr.c: revision 1.99
sys/ufs/lfs/lfs_extern.h: revision 1.117
sys/ufs/lfs/lfs_accessors.h: revision 1.49
sys/ufs/lfs/lfs_extern.h: revision 1.118
sys/rump/fs/lib/liblfs/Makefile: revision 1.15
sys/ufs/lfs/lfs_bio.c: revision 1.146 (patch)
sys/ufs/lfs/lfs_bio.c: revision 1.147
sys/ufs/lfs/lfs_subr.c: revision 1.100

Fix kassert in lfs by initializing vp first.

Use a marker node to iterate lfs_dchainhd / i_lfs_dchain.

I believe elements can be removed while the lock is dropped,
including the next node we're hanging on to.

Just use VOP_BWRITE for lfs_bwrite_log.
Hope this doesn't cause trouble with vfs_suspend.

Teach lfs to transition ro<->rw.

Prevent new dirops while we issue lfs_flush_dirops.

lfs_flush_dirops assumes (by KASSERT((ip->i_state & IN_ADIROP) == 0))
that vnodes on the dchain will not become involved in active dirops
even while holding no other locks (lfs_lock, v_interlock), so we must
set lfs_writer here. All other callers already set lfs_writer.

We set fs->lfs_writer++ without explicitly doing lfs_writer_enter
because
(a) we already waited for the dirops to drain, and
(b) we hold lfs_lock and cannot drop it before setting lfs_writer.

Assert lfs_writer where I think we can now prove it.

Serialize access to the splay tree with lfs_lock.

Change some cheap KDASSERT into KASSERT.

Take a reference and fix assertions in lfs_flush_dirops.
Fixes panic:
KASSERT((ip->i_state & IN_ADIROP) == 0) at lfs_vnops.c:1670
lfs_flush_dirops
lfs_check
lfs_setattr
VOP_SETATTR
change_mode
sys_fchmod
syscall

This assertion -- and the assertion that vp->v_uflag has VU_DIROP set
-- is valid only until we release lfs_lock, because we may race with
lfs_unmark_dirop which will remove the nodes and change the flags.

Further, vp itself is valid only as long as it is referenced, which it
is as long as it's on the dchain, but lfs_unmark_dirop drops the
dchain's reference.

Don't lfs_writer_enter while holding v_interlock.

There's no need to lfs_writer_enter at all here, as far as I can see.
lfs_flush_fs will do it for us.

Break deadlock in PR kern/52301.

The lock order is lfs_writer -> lfs_seglock. The problem in 52301 is
that lfs_segwrite violates this lock order by sometimes doing
lfs_seglock -> lfs_writer, either (a) when doing a checkpoint or (b),
opportunistically, when there are no dirops pending. Both cases can
deadlock, because dirops sometimes take the seglock (lfs_truncate,
lfs_valloc, lfs_vfree):
(a) There may be dirops pending, and they may be waiting for the
seglock, so we can't wait for them to complete while holding the
seglock.
(b) The test for fs->lfs_dirops == 0 happens unlocked, and the state
may change by the time lfs_writer_enter acquires lfs_lock.

To resolve this in each case:
(a) Do lfs_writer_enter before lfs_seglock, since we will need it
unconditionally anyway. The worst performance impact of this should
be that some dirops get delayed a little bit.
(b) Create a new lfs_writer_tryenter to use at this point so that the
test for fs->lfs_dirops == 0 and the acquisition of lfs_writer happen
atomically under lfs_lock.

Initialize/destroy lfs_allclean_wakeup in modcmd, not lfs_mountfs.

Fixes reloading lfs.kmod.

In lfs_update, hold lfs_writer around lfs_vflush.

Otherwise, we might do
lfs_vflush
-> lfs_seglock
-> lfs_segwait(SEGM_CKP)
-> lfs_writer_enter
which is the reverse of the lfs_writer -> lfs_seglock ordering.

Call lfs_orphan in lfs_rename while we're still in the dirop.
lfs_writer_enter can't fail; keep it simple and don't pretend it can.

Assert that mtsleep can't fail either -- it doesn't catch signals and
there's no timeout.

Teach LFS_ORPHAN_NEXTFREE about lfs64.

Dust off the orphan detection code and try to make it work.

Fix !DIAGNOSTIC compile

Fix userland references to LFS_ORPHAN_NEXTFREE.

Forgot to grep for these or do a full distribution build, oops!

Fix missing <sys/evcnt.h> by removing the evcnts instead.

Just wanted to confirm that a race might happen, and indeed it did.
These serve little diagnostic value otherwise.

OR into bp->b_cflags; don't overwrite.

CTASSERT lfs on-disk structure sizes.

Avoid misaligned access to lfs64 on-disk records in memory.
lfs64 directory entries are only 32-bit aligned in order to conserve
space in directory blocks, and we had a hack to stuff a 64-bit inode
in them. This replaces the hack by __aligned(4) __packed, and goes
further:

1. It's not clear that all the other lfs64 data structures are 64-bit
aligned on disk to begin with. We can go through these later and
upgrade them from
struct foo64 {
...
} __aligned(4) __packed;
union foo {
struct foo64 f64;
...
};
to
struct foo64 {
...
};
union foo {
struct foo64 f64 __aligned(8);
...
} __aligned(4) __packed;
if we really want to take advantage of 64-bit memory accesses.
However, the __aligned(4) __packed must remain on the union
because:
2. We access even the lfs32 data structures via a union that has
lfs64 members, and it turns out that compilers will assume access
through a union with 64-bit aligned members implies the whole
union has 64-bit alignment, even if we're only accessing a 32-bit
aligned member.

Fix clang build after packed lfs64 accessor change.

Suppress spurious address-of-packed error in rump lfs too.
 1.45.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.35 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.34 21-Sep-2015  dholland branches: 1.34.16;
Add 64-bit directory entry structures, and adjust accessors accordingly.

The LFS64 directory entry has a 64-bit inode number. This is stored as
two 32-bit values to avoid inducing 64-bit alignment requirements.

The exposed type for manipulating directory entries is now
LFS_DIRHEADER, following the same convention as e.g. IFILE and SEGUSE.
(But with LFS_ on it, because.)
 1.33 21-Sep-2015  dholland Oops; LFS_DIRECTSIZ() is going to need the fs as an argument.

Also, it turns out that dirhash needs a compile-time-constant version
of LFS_DIRECTSIZ(LFS_MAXNAMLEN+1), independent of 64-vs-32, so create
LFS_MAXDIRENTRYSIZE for this. Sigh.
 1.32 15-Sep-2015  dholland Pass around struct lfs_dirheader instead of struct lfs_direct.
 1.31 15-Sep-2015  dholland Add an accessor function for directory names.
 1.30 15-Sep-2015  dholland Add a function lfs_copydirname() to copy directory names in place; use
it in place of (variously) memcpy and strlcpy. (The latter isn't even
correct; was probably changed blindly from strncpy at some point.)

The new function zeroes the padding in the directory entry instead of
leaving trash behind.
 1.29 15-Sep-2015  dholland Tidyups/fixes preparatory to making d_name[] in struct lfs_direct size
0 instead of size LFS_MAXNAMLEN+1, and preparatory to having accessor
functions for d_name. In particular, don't create prototype entries
and copy them, and access the name field only for directory structures
that are in buffers with space for the name to exist.
 1.28 15-Sep-2015  dholland Add and use accessor functions for more of the directory entry fields.
 1.27 01-Sep-2015  dholland Add new accessors for the d_type and d_namlen fields of struct lfs_direct.
Napalm the old byteswap access logic for these.
 1.26 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.25 16-Jun-2015  christos a few more \n's in errors
 1.24 16-Jun-2015  christos fix error messages containing \n
 1.23 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.22 08-Jun-2013  dholland DIRBLKSIZ -> LFS_DIRBLKSIZ
DIRECTSIZ -> LFS_DIRECTSIZ
DIRSIZ -> LFS_DIRSIZ
OLDDIRFMT -> LFS_OLDDIRFMT
NEWDIRFMT -> LFS_NEWDIRFMT
IFTODT -> LFS_IFTODT
DTTOIF -> LFS_DTTOIF
 1.21 08-Jun-2013  dholland struct direct -> struct lfs_direct
struct dirtemplate -> struct lfs_dirtemplate
struct odirtemplate -> struct lfs_odirtemplate
DT_* -> LFS_DT_*
 1.20 08-Jun-2013  dholland Stick LFS_ in front of IFMT, IFIFO, IFREG, etc. so as not to conflict
with the UFS copies of these symbols. (Which themselves ought to have
UFS_ stuck on.)
 1.19 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.18 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.17 09-Nov-2006  christos branches: 1.17.42; 1.17.48;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.16 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.15 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.14 27-Jun-2005  christos constify
 1.13 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.12 06-Feb-2005  perry branches: 1.12.2;
remove obsolete "register" declarations.
 1.11 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.9 13-Jul-2003  itojun use bounded string op
 1.8 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.7 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.6 25-Sep-2001  wiz Add some \n to error messages.
 1.5 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.4 23-May-2000  perseant branches: 1.4.2;
Convert to NetBSD source code style
 1.3 03-Jul-1999  kleink RCS Id police.
 1.2 24-Mar-1999  nathanw printf format fixes for Alpha.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.17.48.2 23-Jun-2013  tls resync from head
 1.17.48.1 25-Feb-2013  tls resync with head
 1.17.42.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.42.1 23-Jan-2013  yamt sync with head
 1.34.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.13 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.12 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.11 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.10 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.9 01-Sep-2006  perseant branches: 1.9.42; 1.9.48;
Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.8 26-Feb-2005  perseant Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.7 06-Feb-2005  perry remove obsolete "register" declarations.
 1.6 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.5 07-Aug-2003  agc branches: 1.5.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.4 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.3 23-May-2000  perseant Convert to NetBSD source code style
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.5.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.9.48.2 23-Jun-2013  tls resync from head
 1.9.48.1 25-Feb-2013  tls resync with head
 1.9.42.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.42.1 23-Jan-2013  yamt sync with head
 1.28 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.27 01-Sep-2015  dholland branches: 1.27.16;
Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.26 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.25 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.24 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.23 16-Jun-2015  christos fix error messages containing \n
 1.22 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.21 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.20 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.19 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.18 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.17 16-Feb-2010  mlelstv branches: 1.17.6; 1.17.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.16 09-Nov-2006  christos Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.15 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.14 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.13 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.12 19-Aug-2005  christos 64 bit inode changes
 1.11 06-Feb-2005  perry remove obsolete "register" declarations.
 1.10 19-Jan-2005  xtraeme ANSIfy, WARNS=2
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.8 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.7 29-Mar-2003  perseant Fix some accounting problems when preening, since preening skips phases
1-4 entirely. Make preen run phase 0, since the Ifile is so important
and the test so quick.
 1.6 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.5 25-Sep-2001  wiz Add some \n to error messages.
 1.4 06-Jan-2001  joff Fixed blockmap handling to properly use disk blocks rather than fragments.
Fixes an issue with fsck_lfs not detecting all duplicate blocks that may
exist in a corrupted filesystem.
 1.3 23-May-2000  perseant Convert to NetBSD source code style
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.17.12.2 23-Jun-2013  tls resync from head
 1.17.12.1 25-Feb-2013  tls resync with head
 1.17.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.6.1 23-Jan-2013  yamt sync with head
 1.27.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.38 14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.37 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.36 01-Sep-2015  dholland branches: 1.36.16;
Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.35 03-Aug-2015  dholland Use intmax_t to print daddr_t; from sevan@.
 1.34 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.33 02-Aug-2015  dholland Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.
 1.32 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.31 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.30 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.29 31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.28 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.27 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.26 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.25 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.24 28-Apr-2008  martin branches: 1.24.20; 1.24.26;
Remove clause 3 and 4 from TNF licenses
 1.23 08-Oct-2007  ad branches: 1.23.8; 1.23.10;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.22 16-Oct-2006  christos branches: 1.22.8;
comment out/delete impossible code
 1.21 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.20 13-Aug-2006  bjh21 Fix typos in messages: SHOULE -> SHOULD
 1.19 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.18 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.17 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.16 23-Apr-2005  perseant Check parts of pass 5 even if only rolling forward. We can't check the true
segment holdings against the blocks held by the inodes, but we can still
check the cleanerinfo data against the segment table.
 1.15 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.14 19-Jan-2005  xtraeme branches: 1.14.2;
ANSIfy, WARNS=2
 1.13 14-May-2004  yamt pass5: dereference of an uninitialized pointer.
 1.12 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.11 23-Feb-2003  perseant Make the "-O" (start filesystem offset) flag to newfs_lfs work correctly,
and update fsck_lfs and dumplfs to deal with it. Note that while the argument
to -O is given in disk sectors, it must be a multiple of the fragment size,
and although it can be lower than the label or superblock, it can't intersect
either.
 1.10 23-May-2002  perseant Re-checksum the superblock whenever it is marked dirty.

Tested on alpha.
 1.9 13-Jul-2001  perseant branches: 1.9.2;
Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.8 21-Nov-2000  perseant branches: 1.8.2;
Check/fix accounting of lfs_dmeta. Patch from Jesse Off
<joff@gci-net.com> (PR #11534).
 1.7 13-Nov-2000  perseant Report, and detect and correct inconsistencies in, the number of clean
segments. Patches from Jesse Off <joff@gci-net.com> (PR #11470).
 1.6 09-Sep-2000  perseant Various bug-fixes to LFS, to wit:


Kernel:

* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.

If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.

* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.

* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.

* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().

lfs_cleanerd:

* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.

* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.

* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.

* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).

fsck_lfs:

* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.

newfs_lfs:

* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.

* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).

* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.

mount_lfs:

* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.

* Default to calling lfs_cleanerd with "-b -n 4".


[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
 1.5 30-May-2000  perseant branches: 1.5.2;
Check for cycles in the inode free list, and for free inodes not on the free
list.
 1.4 23-May-2000  perseant branches: 1.4.2;
Convert to NetBSD source code style
 1.3 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.5.2.2 03-Feb-2001  he Pull up revisions 1.7-1.8 (requested by perseant):
Report/fix lfs_nclean inconsistencies.
Report/fix lfs_dmeta inconsistencies.
 1.5.2.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.8.2.2 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.8.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.9.2.1 02-Jun-2002  tv Pull up revision 1.10 (requested by perseant in ticket #131):
Re-checksum the superblock whenever it is marked dirty.
Tested on alpha.
 1.14.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.22.8.1 06-Nov-2007  matt sync with HEAD
 1.23.10.1 18-May-2008  yamt sync with head.
 1.23.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.26.1 23-Jun-2013  tls resync from head
 1.24.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51 03-Apr-2020  joerg branches: 1.51.8;
Avoid common symbols for fsck_lfs.
 1.50 10-Jun-2017  pgoyette branches: 1.50.6;
Update inode member i_flag --> i_state to keep up with kernel changes
 1.49 03-Oct-2015  dholland branches: 1.49.8;
Fix hardwired 32-bit stuff in fsck:
- compute the maximum file size using LFS_BLKPTRSIZE()
- use the new IINFO in pass 6 instead of uint32_t pointers
- use accessors to read and write indirect blocks
 1.48 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.47 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Part 2 of 3.
 1.46 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Part 1 of 3.
 1.45 01-Sep-2015  dholland The ifile's inode number is constant. (it is always 1)

Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
 1.44 01-Sep-2015  dholland Use the lfs dinode accessors in place of the ufs-derived ones.
(Mostly.)

The ufs-derived ones are fake structure member macros, which are gross
and not very safe. Also, it seems that a lot of places in the lfs code
were using the ffsv1 branch of them unconditionally, and this way it's
guaranteed all those places have been updated.

Found while doing this: for non-devices, have getattr produce NODEV
in the rdev field instead of leaking the address of the first direct
block.
 1.43 19-Aug-2015  dholland Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.42 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.41 12-Aug-2015  dholland Provide 32-bit and 64-bit versions of FINFO.

This also entailed sorting out part of struct segment, as that
contains a pointer into the current FINFO data.
 1.40 12-Aug-2015  dholland Make 32-bit and 64-bit versions of SEGSUM.
Also fix some of the FINFO handling as it's closely entangled.
 1.39 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.38 02-Aug-2015  dholland Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.
 1.37 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.36 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.35 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.34 31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.33 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.32 19-Oct-2013  christos fix unused variable warnings.
 1.31 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.30 08-Jun-2013  dholland dp->di_u.inumber -> dp->di_inumber

Should have been part of the previous changeset that applied that
change to lfs.h. I'd quite like to know why the test build I ran
didn't trip on this.
 1.29 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.28 08-Jun-2013  dholland Move the dinode (on-disk inode) structures to lfs.h, since they are
and will be obviously required by userland tools that need to read
the on-disk structures.

Also, DINODE{1,2}_SIZE -> LFS_DINODE{1,2}_SIZE.
 1.27 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.26 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.25 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.24 05-Jan-2012  perseant branches: 1.24.6;
Correct fragment extension calculation in pass6, to avoid putting
negative block counts on inodes during roll-forward.
 1.23 16-Feb-2010  mlelstv branches: 1.23.6;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.22 16-May-2008  hannken Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.21 28-Apr-2008  martin branches: 1.21.2;
Remove clause 3 and 4 from TNF licenses
 1.20 10-Oct-2007  ad branches: 1.20.8; 1.20.10;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.
 1.19 08-Oct-2007  ad Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.18 09-Nov-2006  christos branches: 1.18.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.17 16-Oct-2006  christos comment out/delete impossible code
 1.16 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.15 19-Jul-2006  perseant On-disk inode accounting fix for roll-forward.
 1.14 19-Jul-2006  perseant Don't doubly free an inode remove_ino() during roll-forward.
 1.13 18-Jul-2006  perseant Quell uninitialized-variable warning that appeared when compiling for macppc.
 1.12 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.11 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.10 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.9 19-Aug-2005  christos 64 bit inode changes
 1.8 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.7 23-Apr-2005  perseant Check parts of pass 5 even if only rolling forward. We can't check the true
segment holdings against the blocks held by the inodes, but we can still
check the cleanerinfo data against the segment table.
 1.6 12-Apr-2005  perseant Take care preserving the integrity of the free list during roll forward.
Also, avoid freeing a deleted vnode twice when a file is remove during
roll forward.
 1.5 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.4 25-Mar-2005  perseant "#define lfs_devvp lfs_unlockvp" for readability, since that's what we
use it for in fsck_lfs/newfs_lfs.
 1.3 02-Apr-2003  fvdl branches: 1.3.6;
Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.2 29-Mar-2003  perseant Fix some accounting problems when preening, since preening skips phases
1-4 entirely. Make preen run phase 0, since the Ifile is so important
and the test so quick.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.3.6.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.18.8.1 06-Nov-2007  matt sync with HEAD
 1.20.10.1 18-May-2008  yamt sync with head.
 1.20.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.21.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.23.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.23.6.2 23-Jan-2013  yamt sync with head
 1.23.6.1 17-Apr-2012  yamt sync with head
 1.24.6.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.6.2 23-Jun-2013  tls resync from head
 1.24.6.1 25-Feb-2013  tls resync with head
 1.49.8.1 30-Oct-2017  snj Pull up following revision(s) (requested by maya in ticket #330):
sbin/fsck_lfs/inode.c: 1.69
sbin/fsck_lfs/lfs.c: 1.73
sbin/fsck_lfs/pass6.c: 1.50
sbin/fsck_lfs/segwrite.c: 1.46
sys/ufs/lfs/lfs.h: 1.202-1.203
sys/ufs/lfs/lfs_accessors.h: 1.48
sys/ufs/lfs/lfs_alloc.c: 1.136-1.137
sys/ufs/lfs/lfs_balloc.c: 1.94
sys/ufs/lfs/lfs_bio.c: 1.141
sys/ufs/lfs/lfs_extern.h: 1.113
sys/ufs/lfs/lfs_inode.c: 1.156-1.157
sys/ufs/lfs/lfs_inode.h: 1.20, 1.21, 1.23
sys/ufs/lfs/lfs_itimes.c: 1.20
sys/ufs/lfs/lfs_pages.c: 1.13-1.15
sys/ufs/lfs/lfs_rename.c: 1.22
sys/ufs/lfs/lfs_segment.c: 1.270-1.275
sys/ufs/lfs/lfs_subr.c: 1.94-1.97
sys/ufs/lfs/lfs_syscalls.c: 1.175
sys/ufs/lfs/lfs_vfsops.c: 1.360
sys/ufs/lfs/lfs_vnops.c: 1.316-1.321
sys/ufs/lfs/ulfs_inode.c: 1.20
sys/ufs/lfs/ulfs_inode.h: 1.24
sys/ufs/lfs/ulfs_lookup.c: 1.41
sys/ufs/lfs/ulfs_quota2.c: 1.31
sys/ufs/lfs/ulfs_readwrite.c: 1.24
sys/ufs/lfs/ulfs_vnops.c: 1.49-1.50
Update inode member i_flag --> i_state to keep up with kernel changes
Move definition of IN_ALLMOD near the flag it's a mask for.
Now we can see that it doesn't match all the flags, but changing that will
require more careful thought.
Correct confusion between i_flag and i_flags
These will have to be renamed.
Spotted by Riastradh, thanks!
Add an XXX about the missing flags so it's not buried in a commit
message.
now the XXX count for LFS is 260
Rename i_flag to i_state.
The similarity to i_flags has previously caused errors.
Use continue to denote the no-op loop to match netbsd style
newline for extra clarity.
It isn't safe to drain dirops with seglock held, it'll deadlock if there
are any dirops. drain before grabbing seglock.
lfs_dirops == 0 is always true (as we already drained dirops), so omit
that part of the comparison.
Fixes a lot of LFS deadlocks. PR kern/52301
Many thanks to dholland for help analyzing coredumps
Ifdef out KDASSERT which fires on my machine.
Deduplicate sanity check that seglock is held on segunlock
Revert r1.272 fix to PR kern/52301, the performance hit is making things
unusable.
change lfs_nextsegsleep and lfs_allclean_wakeup to use condvar
XXX had to use lfs_lock in lfs_segwait, removed kernel_lock, is this
appropriate?
fix buffer overflow/KASSERT when cookies are supplied
lfs no longer uses the ffs-style struct direct, use the correct minimum
size
from dholland
XXX more wrong
Consistently use {,UN}MARK_VNODE macros rather than function calls.
Not much point doing anything after a panic call
Ask some question about the code in a XXX comment
XXX question our double-flushing of dirops
Fix typo in comment
 1.50.6.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51.8.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.51.8.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.48 14-May-2020  msaitoh branches: 1.48.8;
Remove extra semicolon.
 1.47 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.46 10-Jun-2017  pgoyette branches: 1.46.6;
Update inode member i_flag --> i_state to keep up with kernel changes
 1.45 03-Oct-2015  dholland branches: 1.45.8;
Use IINFO in lfs_writeinode().
(both the kernel and the userland copies)
 1.44 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.43 01-Sep-2015  dholland Use the lfs dinode accessors in place of the ufs-derived ones.
(Mostly.)

The ufs-derived ones are fake structure member macros, which are gross
and not very safe. Also, it seems that a lot of places in the lfs code
were using the ffsv1 branch of them unconditionally, and this way it's
guaranteed all those places have been updated.

Found while doing this: for non-devices, have getattr produce NODEV
in the rdev field instead of leaking the address of the first direct
block.
 1.42 19-Aug-2015  dholland Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.41 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.40 12-Aug-2015  dholland Provide 32-bit and 64-bit versions of FINFO.

This also entailed sorting out part of struct segment, as that
contains a pointer into the current FINFO data.
 1.39 12-Aug-2015  dholland Make 32-bit and 64-bit versions of SEGSUM.
Also fix some of the FINFO handling as it's closely entangled.
 1.38 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.37 12-Aug-2015  dholland Make 32-bit and 64-bit versions of CLEANERINFO.

XXX: while this is written to disk, it seems like much of it would
XXX: be better set up as a commpage shared with the cleaner.
 1.36 02-Aug-2015  dholland Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.35 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.34 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.33 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.32 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.31 17-Jun-2015  christos add missing ;
 1.30 16-Jun-2015  christos fix error messages containing \n
 1.29 31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.28 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.27 19-Oct-2013  christos fix unused variable warnings.
 1.26 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.25 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.24 08-Jun-2013  dholland Move the dinode (on-disk inode) structures to lfs.h, since they are
and will be obviously required by userland tools that need to read
the on-disk structures.

Also, DINODE{1,2}_SIZE -> LFS_DINODE{1,2}_SIZE.
 1.23 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.22 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.21 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.20 16-Feb-2010  mlelstv branches: 1.20.6; 1.20.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.19 16-May-2008  hannken Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.18 28-Apr-2008  martin branches: 1.18.2;
Remove clause 3 and 4 from TNF licenses
 1.17 10-Oct-2007  ad branches: 1.17.8; 1.17.10;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.
 1.16 08-Oct-2007  ad Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.15 09-Nov-2006  christos branches: 1.15.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.14 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.13 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.12 23-May-2006  jnemeth Coverity CID 3447: Add extraneous checks to shut up Coverity.
 1.11 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.10 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.9 01-Apr-2005  he Move the definition of simple_lock() and simple_unlock() to a common
header, since more of the LFS macros now use these functions. Since
we're outside of the kernel, these are defined to be empty.
 1.8 25-Mar-2005  perseant "#define lfs_devvp lfs_unlockvp" for readability, since that's what we
use it for in fsck_lfs/newfs_lfs.
 1.7 26-Feb-2005  perseant branches: 1.7.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.6 24-Dec-2003  heas branches: 1.6.4;
Check result of malloc().
reviewed by Martin.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.4 12-Jul-2003  yamt don't use uninitialized variables.
PR/22123 (Izumi Tsutsui)
 1.3 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.2 31-Mar-2003  perseant Check inode free list tail pointer as well as head pointer, and write both
into the CLEANERINFO block of the Ifile as well as into the superblock.
Make preen update both superblocks.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.6.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.7.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.15.8.1 06-Nov-2007  matt sync with HEAD
 1.17.10.1 18-May-2008  yamt sync with head.
 1.17.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.20.12.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.20.12.2 23-Jun-2013  tls resync from head
 1.20.12.1 25-Feb-2013  tls resync with head
 1.20.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.20.6.1 23-Jan-2013  yamt sync with head
 1.45.8.1 30-Oct-2017  snj Pull up following revision(s) (requested by maya in ticket #330):
sbin/fsck_lfs/inode.c: 1.69
sbin/fsck_lfs/lfs.c: 1.73
sbin/fsck_lfs/pass6.c: 1.50
sbin/fsck_lfs/segwrite.c: 1.46
sys/ufs/lfs/lfs.h: 1.202-1.203
sys/ufs/lfs/lfs_accessors.h: 1.48
sys/ufs/lfs/lfs_alloc.c: 1.136-1.137
sys/ufs/lfs/lfs_balloc.c: 1.94
sys/ufs/lfs/lfs_bio.c: 1.141
sys/ufs/lfs/lfs_extern.h: 1.113
sys/ufs/lfs/lfs_inode.c: 1.156-1.157
sys/ufs/lfs/lfs_inode.h: 1.20, 1.21, 1.23
sys/ufs/lfs/lfs_itimes.c: 1.20
sys/ufs/lfs/lfs_pages.c: 1.13-1.15
sys/ufs/lfs/lfs_rename.c: 1.22
sys/ufs/lfs/lfs_segment.c: 1.270-1.275
sys/ufs/lfs/lfs_subr.c: 1.94-1.97
sys/ufs/lfs/lfs_syscalls.c: 1.175
sys/ufs/lfs/lfs_vfsops.c: 1.360
sys/ufs/lfs/lfs_vnops.c: 1.316-1.321
sys/ufs/lfs/ulfs_inode.c: 1.20
sys/ufs/lfs/ulfs_inode.h: 1.24
sys/ufs/lfs/ulfs_lookup.c: 1.41
sys/ufs/lfs/ulfs_quota2.c: 1.31
sys/ufs/lfs/ulfs_readwrite.c: 1.24
sys/ufs/lfs/ulfs_vnops.c: 1.49-1.50
Update inode member i_flag --> i_state to keep up with kernel changes
Move definition of IN_ALLMOD near the flag it's a mask for.
Now we can see that it doesn't match all the flags, but changing that will
require more careful thought.
Correct confusion between i_flag and i_flags
These will have to be renamed.
Spotted by Riastradh, thanks!
Add an XXX about the missing flags so it's not buried in a commit
message.
now the XXX count for LFS is 260
Rename i_flag to i_state.
The similarity to i_flags has previously caused errors.
Use continue to denote the no-op loop to match netbsd style
newline for extra clarity.
It isn't safe to drain dirops with seglock held, it'll deadlock if there
are any dirops. drain before grabbing seglock.
lfs_dirops == 0 is always true (as we already drained dirops), so omit
that part of the comparison.
Fixes a lot of LFS deadlocks. PR kern/52301
Many thanks to dholland for help analyzing coredumps
Ifdef out KDASSERT which fires on my machine.
Deduplicate sanity check that seglock is held on segunlock
Revert r1.272 fix to PR kern/52301, the performance hit is making things
unusable.
change lfs_nextsegsleep and lfs_allclean_wakeup to use condvar
XXX had to use lfs_lock in lfs_segwait, removed kernel_lock, is this
appropriate?
fix buffer overflow/KASSERT when cookies are supplied
lfs no longer uses the ffs-style struct direct, use the correct minimum
size
from dholland
XXX more wrong
Consistently use {,UN}MARK_VNODE macros rather than function calls.
Not much point doing anything after a panic call
Ask some question about the code in a XXX comment
XXX question our double-flushing of dirops
Fix typo in comment
 1.46.6.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.48.8.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.48.8.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.7 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.6 12-Aug-2015  dholland Provide 32-bit and 64-bit versions of FINFO.

This also entailed sorting out part of struct segment, as that
contains a pointer into the current FINFO data.
 1.5 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.4 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.3 16-Feb-2010  mlelstv branches: 1.3.6; 1.3.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 28-Mar-2003  perseant branches: 1.1.32; 1.1.34;
Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.1.34.1 18-May-2008  yamt sync with head.
 1.1.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.12.1 23-Jun-2013  tls resync from head
 1.3.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.62 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.61 17-Mar-2016  christos branches: 1.61.16;
PR/50974: David Binderman: Remove unused code.
 1.60 03-Oct-2015  dholland Fix hardwired 32-bit stuff in fsck:
- compute the maximum file size using LFS_BLKPTRSIZE()
- use the new IINFO in pass 6 instead of uint32_t pointers
- use accessors to read and write indirect blocks
 1.59 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.58 01-Sep-2015  dholland Tidy the MAXSYMLINKLEN macros.
 1.57 01-Sep-2015  dholland The ifile's inode number is constant. (it is always 1)

Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
 1.56 01-Sep-2015  dholland Use the lfs dinode accessors in place of the ufs-derived ones.
(Mostly.)

The ufs-derived ones are fake structure member macros, which are gross
and not very safe. Also, it seems that a lot of places in the lfs code
were using the ffsv1 branch of them unconditionally, and this way it's
guaranteed all those places have been updated.

Found while doing this: for non-devices, have getattr produce NODEV
in the rdev field instead of leaking the address of the first direct
block.
 1.55 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.54 12-Aug-2015  dholland Provide 32-bit and 64-bit versions of FINFO.

This also entailed sorting out part of struct segment, as that
contains a pointer into the current FINFO data.
 1.53 12-Aug-2015  dholland Make 32-bit and 64-bit versions of SEGSUM.
Also fix some of the FINFO handling as it's closely entangled.
 1.52 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.51 02-Aug-2015  dholland Second batch of 64 -> 32 truncations in lfs, along with more minor
tidyups and corrections in passing.
 1.50 02-Aug-2015  dholland Fix bug: for format version 1, the superblock "size" field is measured
in blocks instead of frags, so use lfs_blkstofrags to correct it.

This code was instead multiplying by the block size divided by
DEV_BSIZE to get the number of disk blocks rather than the number of
frags. (I gather that originally these were the same, but they're not
necessarily any more.)
 1.49 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.48 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.47 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.46 31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.45 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.44 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.43 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.42 08-Jun-2013  dholland Move the dinode (on-disk inode) structures to lfs.h, since they are
and will be obviously required by userland tools that need to read
the on-disk structures.

Also, DINODE{1,2}_SIZE -> LFS_DINODE{1,2}_SIZE.
 1.41 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.40 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.39 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.38 29-Aug-2011  bouyer branches: 1.38.2; 1.38.8;
PR bin/45299: print FBMASK not FFMASK when lfs_fbmask is incorrect.
 1.37 16-Feb-2010  mlelstv Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.36 16-May-2008  hannken Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.35 28-Apr-2008  martin branches: 1.35.2;
Remove clause 3 and 4 from TNF licenses
 1.34 16-Mar-2008  lukem branches: 1.34.2;
errexit() now provides the trailing \n (since fsck_ffs assumed that
from a conversion from err(3)), so "make it so".
 1.33 08-Oct-2007  ad branches: 1.33.6; 1.33.8;
Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.32 09-Nov-2006  christos branches: 1.32.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.31 16-Oct-2006  christos comment out/delete impossible code
 1.30 01-Sep-2006  perseant Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.29 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.28 28-Apr-2006  perseant Avoid a core dump if ginode() returns NULL. Correct an error message
while we're here.
 1.27 17-Apr-2006  perseant Remove the free list ordering/disordering code, since the kernel now keeps
the list in order (ordering it on mount).

Regularize error messages: these are now all in ALL CAPS, with all hex
numbers (not reported in caps) prefixed by 0x. (The non-fsck-specific
messages are an exception to this all-caps rule.)
 1.26 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.25 19-Aug-2005  christos 64 bit inode changes
 1.24 08-Jun-2005  perseant Use the correct method to create a new inode, when we allocate lost+found.

Correct uninitialized variable issues in pass6.c and dir.c (PR#30411 and
PR#30394, respectively).
 1.23 24-May-2005  agc Make this build on arm platforms by using the correct printf formats.
 1.22 23-May-2005  perseant Check some error conditions that would otherwise cause fsck_lfs to dump core.
Pointed out by Pavel Cahyna in a follow-on to PR #29151.
 1.21 14-Apr-2005  perseant Document "-f" (force check) flag. Implement and document "-q" (quiet).
 1.20 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.19 26-Feb-2005  perseant branches: 1.19.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.18 15-Sep-2004  minoura Changes from rev 1.34 and 1.35 of sbin/newfs_lfs/lfs.c.
 1.17 07-Aug-2003  agc branches: 1.17.4;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.15 31-Mar-2003  perseant Check inode free list tail pointer as well as head pointer, and write both
into the CLEANERINFO block of the Ifile as well as into the superblock.
Make preen update both superblocks.
 1.14 29-Mar-2003  perseant Fix some accounting problems when preening, since preening skips phases
1-4 entirely. Make preen run phase 0, since the Ifile is so important
and the test so quick.
 1.13 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.12 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.11 04-Feb-2002  perseant Walk the segment list correctly when rolling forward between the two
primary superblocks. This prevents spurious "block could not be read"
messages that might otherwise be seen if the filesystem had not been
properly unmounted.
 1.10 25-Sep-2001  wiz Fix a typo and two white space nits.
 1.9 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.8 05-Jan-2001  lukem branches: 1.8.2;
use %ll_ instead of the less standard %q_
 1.7 04-Oct-2000  jdolecek setup(): use calloc() for blockmap allocation, instead of malloc() followed
by bzero(); the net result is that the test for allocation failure
is actually sensible now
 1.6 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.5 23-May-2000  perseant branches: 1.5.2;
Convert to NetBSD source code style
 1.4 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.3 03-Jul-1999  kleink RCS Id police.
 1.2 24-Mar-1999  nathanw printf format fixes for Alpha.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.5.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.2.3 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.8.2.2 30-Jun-2001  perseant Fixes, from joff, for correct compatibility operation of fsck_lfs, dumplfs,
lfs_cleanerd; correct usage message from dumplfs.
 1.8.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.17.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.19.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.32.8.2 23-Mar-2008  matt sync with HEAD
 1.32.8.1 06-Nov-2007  matt sync with HEAD
 1.33.8.2 02-Jun-2008  mjf Sync with HEAD.
 1.33.8.1 03-Apr-2008  mjf Sync with HEAD.
 1.33.6.1 24-Mar-2008  keiichi sync with head.
 1.34.2.1 18-May-2008  yamt sync with head.
 1.35.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.38.8.2 23-Jun-2013  tls resync from head
 1.38.8.1 25-Feb-2013  tls resync with head
 1.38.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.38.2.1 23-Jan-2013  yamt sync with head
 1.61.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.43 14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.42 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.41 12-Aug-2015  dholland branches: 1.41.16;
Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.40 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.39 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.38 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.37 16-Jun-2015  christos a few more \n's in errors
 1.36 16-Jun-2015  christos fix error messages containing \n
 1.35 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.34 08-Jun-2013  dholland Stick LFS_ in front of IFMT, IFIFO, IFREG, etc. so as not to conflict
with the UFS copies of these symbols. (Which themselves ought to have
UFS_ stuck on.)
 1.33 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.32 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.31 09-Jun-2011  christos branches: 1.31.2; 1.31.8;
share more code.
 1.30 07-Jan-2010  christos branches: 1.30.4;
missing errno.h
 1.29 07-Jan-2010  christos make this compile again.
 1.28 06-Jan-2010  christos PR/42568: Pedro F. Giffuni: Better signal handling from OpenBSD, but simplified.
 1.27 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.26 09-Nov-2006  christos branches: 1.26.8; 1.26.16; 1.26.18;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.25 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.24 28-Apr-2006  perseant Avoid a core dump if ginode() returns NULL. Correct an error message
while we're here.
 1.23 13-Apr-2006  perseant Don't update the superblock if we were run with -n, regardless of whether
the "clean" bit is set.
 1.22 13-Sep-2005  christos rename lfs.h to lfs_user.h so that it does not conflict.
 1.21 23-Aug-2005  christos This should be LFS_MAXNAMLEN
 1.20 23-Aug-2005  tron Use FFS_MAXNAMLEN instead of MAXNAMLEN.
 1.19 27-Jun-2005  christos constify
 1.18 26-Feb-2005  perseant Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.17 06-Feb-2005  perry remove obsolete "register" declarations.
 1.16 20-Oct-2003  dsl branches: 1.16.4;
Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 13-Jul-2003  itojun use bounded string op
 1.13 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.12 31-Mar-2003  perseant Check inode free list tail pointer as well as head pointer, and write both
into the CLEANERINFO block of the Ifile as well as into the superblock.
Make preen update both superblocks.
 1.11 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.10 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.9 23-May-2002  perseant Re-checksum the superblock whenever it is marked dirty.

Tested on alpha.
 1.8 13-Jul-2001  perseant branches: 1.8.2;
Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.7 04-Feb-2001  christos branches: 1.7.2;
fix redundant decls
 1.6 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.5 14-Jun-2000  perseant branches: 1.5.2;
Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.4 23-May-2000  perseant branches: 1.4.2;
Convert to NetBSD source code style
 1.3 16-May-2000  perseant fsck_lfs can now write to the filesystem, allowing it to correct most
(though still not all) errors in a damaged lfs. Segment byte accounting
is corrected in pass 5. "fsck_lfs -p" will do a partial roll-forward,
verifying the checkpoint from the newer superblock. fscknames[] is
updated so that fsck knows about fsck_lfs.
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant branches: 1.1.2;
Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.1.2.1 10-Oct-2000  he Pull up revision 1.6 (requested by is):
Format string cleanup.
 1.4.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.5.2.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.7.2.2 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.7.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.8.2.1 02-Jun-2002  tv Pull up revision 1.9 (requested by perseant in ticket #131):
Re-checksum the superblock whenever it is marked dirty.
Tested on alpha.
 1.16.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.26.18.1 03-Apr-2008  mjf Sync with HEAD.
 1.26.16.1 24-Mar-2008  keiichi sync with head.
 1.26.8.1 23-Mar-2008  matt sync with HEAD
 1.30.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.31.8.2 23-Jun-2013  tls resync from head
 1.31.8.1 25-Feb-2013  tls resync with head
 1.31.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31.2.1 23-Jan-2013  yamt sync with head
 1.41.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.20 14-Sep-2025  perseant Add -a flag to suppress warnings about discrepancies in avail accounting,
which is common with the -i flag.

Expand the computation of avail if the -d flag is given. The computation
itself is not changed.

Do not offer to roll forward if the -n flag was given.

Exit with FSCK_EXIT_UNRESOLVED if the -n flag was given and any questions
were asked. This is helpful when using fsck_lfs as a diagnostic in scripts.
 1.19 03-Apr-2020  joerg Avoid common symbols for fsck_lfs.
 1.18 12-Aug-2015  dholland branches: 1.18.16;
Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.17 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.16 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.15 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.14 16-Feb-2010  mlelstv branches: 1.14.6; 1.14.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.13 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.12 01-Sep-2006  perseant branches: 1.12.18; 1.12.20;
Several fixes to improve the reliability of the roll-forward agent.
Also, note "properly orphaned" files as distinct from corrupted files.
 1.11 18-Jul-2006  perseant Various improvements to fsck_lfs, to wit:

* Add lfs_balloc capability to the lfs library.
* Extend the Ifile if we run out of free inodes when creating lost+found.
* Don't roll forward if we have allocated a lost+found, to avoid
conflicts when adding new files in roll-forward.
* Make some messages slightly more verbose (e.g. include inode number,
and use pwarn() instead of printf() so the messages include the device
name when preening).
* Change superblock detection/avoidance to use the offset table in the
primary superblock, rather than looking at the contents.
* Be more verbose about various operations when passed the -d flag,
especially roll-forward.
* Be more careful about dirops during roll forward, since the cleaner can
sometimes write blocks from dirop vnodes. Detect and avoid this problem.
* Always check the free list, even if given -i; if we're going to write
it we have to check it first.
* Mark inodes dirty when blocks are found during roll forward, so the
inodes are written with the new block locations.
* Update size of inodes if blocks beyond EOF are found during roll
forward.
* Fix segment accounting for blocks and inodes found during roll
forward.
* Report statistics on roll forward: how many new/deleted/moved files
and how many updated blocks (or "nothing new").
* Don't care if the device being checked is really a device, if we have
been passed the -f flag (to facilitate automated testing).
* When writing to the disk, use the current time in the segment headers
rathern than time 0.
* When passed the -i flag, locate the partial segment containing the
Ifile inode and use that to calculate lfs_offset, lfs_curseg,
lfs_nextseg. (Again for automated testing.)
 1.10 27-Jun-2005  christos constify
 1.9 14-Apr-2005  perseant Document "-f" (force check) flag. Implement and document "-q" (quiet).
 1.8 02-Apr-2003  fvdl branches: 1.8.6;
Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.7 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.6 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.5 04-Feb-2001  christos fix redundant decls
 1.4 14-Jun-2000  perseant Add "-i" flag to specify the location of the index file inode, to
examine alternate checkpoints. Regularize usage of maxino. Remove olf
debugging cruft.
 1.3 23-May-2000  perseant branches: 1.3.2;
Convert to NetBSD source code style
 1.2 03-Jul-1999  kleink RCS Id police.
 1.1 18-Mar-1999  perseant Initial checkin of fsck_lfs. This version cannot do any repair (-p flag
does nothing, and one of -p or -n is required) but can be useful as a
diagnostic tool.
 1.3.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.6.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.12.20.1 18-May-2008  yamt sync with head.
 1.12.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.12.1 23-Jun-2013  tls resync from head
 1.14.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.16 03-Apr-2020  joerg branches: 1.16.8;
Avoid common symbols for fsck_lfs.
 1.15 19-Aug-2015  dholland branches: 1.15.16;
Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.14 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.13 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.12 06-Jun-2013  dholland ufs -> ulfs for fsck_lfs.
 1.11 16-Feb-2010  mlelstv branches: 1.11.6; 1.11.12;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.10 06-Aug-2009  pooka Define syscalls of lfs userspace tools (cleaner, mainly) through
a struct called kernelops, which contains standard system calls
for the normal case and rump system calls for the rump case.

Make it possible to run the lfs cleaner in a library fashion (taking
the quick route with the implementation).
 1.9 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8 10-Oct-2007  ad branches: 1.8.8; 1.8.10;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.
 1.7 08-Oct-2007  ad Give brelse() a second argument so that it matches the kernel.
fsck_lfs now compiles again.
 1.6 09-Nov-2006  christos branches: 1.6.8;
Fix malloc/realloc/calloc issues: always check and exit, use EEXIT instead
of 8.
 1.5 20-Mar-2006  christos Coverity CID 2551: Don't use LIST_FOREACH() if you are going to free the
current element (bp) in the body of the loop; the foreach does bp = bp->next;
 1.4 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.3 11-Apr-2005  perseant Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.2 02-Apr-2003  fvdl branches: 1.2.6;
Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.1 28-Mar-2003  perseant Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.2.6.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.6.8.1 06-Nov-2007  matt sync with HEAD
 1.8.10.1 18-May-2008  yamt sync with head.
 1.8.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.12.1 23-Jun-2013  tls resync from head
 1.11.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.16.8.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.16.8.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.6 17-Sep-2021  christos branches: 1.6.4;
Fix the function pointer declaration to something lint likes.
 1.5 09-Jun-2017  chs this file uses the <sys/queue.h> macros so it should include
that header itself, rather than relying on getting it indirectly
by including some other header.
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 10-Oct-2007  ad branches: 1.3.8; 1.3.10;
Merge from vmlocking:

- Split vnode::v_flag into three fields, depending on field locking.
- simple_lock -> kmutex in a few places.
- Fix some simple locking problems.
 1.2 11-Apr-2005  perseant branches: 1.2.10;
Be more efficient with the hash tables for the buffer and vnode caches.

Note that roll-forward can add more inodes to the filesystem; don't overflow
the tables but reallocate them.
 1.1 28-Mar-2003  perseant branches: 1.1.6;
Add working writing ability to fsck_lfs, including roll-forward, based on
a partial-segment writer ported from the kernel.
 1.1.6.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.2.10.1 06-Nov-2007  matt sync with HEAD
 1.3.10.1 18-May-2008  yamt sync with head.
 1.3.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.4.2 06-Sep-2025  perseant Separate buffer cache code between fsck_lfs and fsck_exfatfs.
This may be reunited later, probably as a library.
 1.6.4.1 29-Jun-2024  perseant Implementation of exFAT filesystem, with compilation conditional on MKEXFATFS
make variable.
 1.12 11-Apr-2010  hannken Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.

While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.11 26-Aug-2006  christos Programs that use efun.
 1.10 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.9 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.8 06-Apr-2001  wiz Make WARNS=2 safe, and set WARNS to 2.
 1.7 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.6 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.5 06-May-1997  gwr Use .PATH.c: ...
 1.4 03-Jan-1997  ws Fix handling of clusters marked bad
Noted by Rafal Boni
 1.3 27-Sep-1996  christos util -> fsutil
 1.2 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.1 14-May-1996  ws Add fsck utility for msdosfs
 1.27 28-Aug-2022  mlelstv fix 32bit builds
 1.26 28-Aug-2022  mlelstv Fix writing of corrected fsinfo.
Continue when fsinfo has been rewritten.
 1.25 24-Apr-2022  hannken Cast read()/write() result to size_t to make this compile again.
 1.24 23-Apr-2022  mlelstv Support large disk sectors.
 1.23 22-Feb-2020  kamil Avoid unportable shift construct

boot.c:150:29, left shift of 255 by 24 places cannot be represented in type 'int'
boot.c:153:29, left shift of 255 by 24 places cannot be represented in type 'int'
 1.22 11-Jan-2020  christos Don't add the 2 reserved clusters before we determine if we using fat16/fat32.
From FreeBSD: https://reviews.freebsd.org/D23082:

Correct off-by-two issue when determining FAT type.

In the code we used NumClusters as the upper (non-inclusive) boundary
of valid cluster number, so the actual value was 2 (CLUST_FIRST) more
than the real number of clusters. This causes a FAT16 media with
65524 clusters be treated as FAT32 and might affect FAT12 media with
4084 clusters as well.

To fix this, we increment NumClusters by CLUST_FIRST after the type
determination.
 1.21 08-Feb-2018  dholland branches: 1.21.4;
Typos.
 1.20 02-May-2016  jakllsch The on-disk FAT array does not include anything before CLUST_FIRST,
compensate in size check.

This was tickled by my SanDisk Sansa Clip 4GB, which exactly filled the FAT array.
 1.19 02-Jan-2015  mlelstv Avoid mixing cluster numbers and sector numbers. Makes code more readable.
 1.18 04-Nov-2014  msaitoh Add #include <inttypes.h> for intmax_t to fix compile error.
 1.17 03-Nov-2014  jakllsch ClusterOffset actually needs to be able to be negative.
 1.16 07-Jul-2014  christos branches: 1.16.2;
From: http://marc.info/?l=openbsd-tech&m=140354518512871&w=2
more consistency checks
 1.15 11-Apr-2009  lukem branches: 1.15.12; 1.15.22;
fix sign-compare issues
 1.14 13-Jun-2008  martin branches: 1.14.4;
Move to 2 clause license, approved by Wolfgang Solfrank.
 1.13 19-Mar-2007  gdt branches: 1.13.12; 1.13.14; 1.13.16;
Change mismatch of bytes 11 to 90 to be a warning, not an error, and
print out the values of the bytes that do not match.
Add comment explaining that there is no documented rationale for the
check.

fsck_msdos checks that several bytes are equal in the primary and
backup bootblock. There is no documented rationale. The kernel does
not enforce this when mounting a filesystem. I have a FAT32
filesystem on my disk (mounted as /share) which fails this check, but
is accepted by both Windows XP and NetBSD. My volume differs in bytes
71-81. The primary contains "SHARE " and the backup NUL bytes.

Further, fsck_msdos does not have code to repair the mismatch. As a
result such filesystems can be used not checked.
 1.12 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.11 05-Jun-2006  christos - don't leak memory on allocation failure.
- s/perror/perr and print how much we were trying to allocate.
 1.10 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype.
 1.9 24-Jul-2003  ws Only compare the interesting part of the bootblock with its backup.
 1.8 22-Dec-2001  augustss Allow check to proceed with bad backup boot block if we're doing a readonly
check.
 1.7 26-Jul-2001  wiz Various typos in comments (neccessary, sceme, choise, ...).
 1.6 06-Oct-1998  ws Since M$ doesn't maintain the FSINFO block correctly,
don't treat errors there as modifications.
 1.5 17-Oct-1997  ws Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.4 14-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* cleanup manpage
 1.3 27-Sep-1996  christos util -> fsutil
 1.2 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.1 14-May-1996  ws Add fsck utility for msdosfs
 1.13.16.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.13.14.1 17-Jun-2008  yamt sync with head.
 1.13.12.1 29-Jun-2008  mjf Sync with HEAD.
 1.14.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.15.22.1 10-Aug-2014  tls Rebase.
 1.15.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.2.1 14-Nov-2014  martin Pull up following revision(s) (requested by jakllsch in ticket #234):
sbin/fsck_msdos/boot.c: revision 1.18
sbin/fsck_msdos/dosfs.h: revision 1.7
sbin/fsck_msdos/boot.c: revision 1.17
ClusterOffset actually needs to be able to be negative.
Add #include <inttypes.h> for intmax_t to fix compile error.
 1.21.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.20 28-Aug-2022  mlelstv Fix writing of corrected fsinfo.
Continue when fsinfo has been rewritten.
 1.19 10-Jul-2014  christos Well, if you set FSFIXFAT, better do it... Try running fsck on:

$ newfs_msdos -C 1M ./poc.fs
$ dd if=/dev/zero of=poc.fs conv=notrunc bs=1 count=1 seek=512

multiple times and see that it does not get fixed.
 1.18 11-Apr-2009  lukem branches: 1.18.12; 1.18.22;
fix sign-compare issues
 1.17 13-Jun-2008  martin branches: 1.17.4;
Move to 2 clause license, approved by Wolfgang Solfrank.
 1.16 23-Feb-2008  christos branches: 1.16.2; 1.16.4;
Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.15 10-Mar-2007  hubertf branches: 1.15.4; 1.15.10; 1.15.12;
- removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.14 05-Jun-2006  christos - don't leak memory on allocation failure.
- s/perror/perr and print how much we were trying to allocate.
 1.13 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype.
 1.12 06-Apr-2001  wiz Make WARNS=2 safe, and set WARNS to 2.
 1.11 15-Sep-2000  abs if readboot() calls pfatal(), we need to print a \n before exiting
 1.10 25-Apr-2000  jdolecek branches: 1.10.4;
Recognize "dirty" signature on FAT as set by Windows 95 OSR2+ and don't report
it just as "odd byte sequence". Handle the dirty flag similar way
it's treated on e.g. FFS - e.g. clear it separately from rest of FAT.
Changing of FAT is now postponed until after all checks are done,
check.c:checkfilesys() was cleaned considerably and several messages
has been adjusted to be more accurate.

If file system was modified and no error has occured, just return 0
instead of 4 - there is no need for forcing a reboot in this case.

This addresses bin/5638 by Christos Zoulas.
 1.9 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.8 17-Oct-1997  ws Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.7 14-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* cleanup manpage
 1.6 03-Jan-1997  ws Fix handling of clusters marked bad
Noted by Rafal Boni
 1.5 27-Sep-1996  christos util -> fsutil
 1.4 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.3 28-May-1996  ws Don't allocate data structures for non-directories
Free any data structures when finishing a check (at the latest)
 1.2 25-May-1996  ws Check return values of malloc
Generate full pathnames only on request
Minor cleanup, RCS Ids in .h files
 1.1 14-May-1996  ws branches: 1.1.4;
Add fsck utility for msdosfs
 1.1.4.1 31-May-1996  jtc pulled up from trunk by request of ws
 1.10.4.1 02-Oct-2000  abs Pullup sbin/fsck_msdos/check.c 1.11 (Approved by jhawk)
If readboot() calls pfatal() and returns an error, print \n before exiting
 1.15.12.2 29-Jun-2008  mjf Sync with HEAD.
 1.15.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.15.10.1 24-Mar-2008  keiichi sync with head.
 1.15.4.1 23-Mar-2008  matt sync with HEAD
 1.16.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.16.2.1 17-Jun-2008  yamt sync with head.
 1.17.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.18.22.1 10-Aug-2014  tls Rebase.
 1.18.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29 28-Apr-2017  christos Prevent SEGV on corrupted msdos directories (Veo Zhang)
 1.28 07-Mar-2016  christos branches: 1.28.6;
PR/50908: David Binderman: Optimize memset's
 1.27 02-Jan-2015  mlelstv Avoid mixing cluster numbers and sector numbers. Makes code more readable.
 1.26 07-Jul-2014  christos From: http://marc.info/?t=140304310700005&r=1&w=2
When truncating cluster chains fix the length of the cluster head.
 1.25 20-Feb-2011  christos branches: 1.25.10; 1.25.20;
undo part of the previous patch, which I suspect is bad.
 1.24 07-Feb-2011  christos PR/44529: Martin Danielsson: fsck_msdos crashes when verifying corrupt file
system. Avoid using the long name index when it is 0. Refactor the code to
avoid duplication.
 1.23 11-Apr-2009  lukem branches: 1.23.2;
fix sign-compare issues
 1.22 13-Jun-2008  martin branches: 1.22.4;
Move to 2 clause license, approved by Wolfgang Solfrank.
 1.21 17-Jan-2007  hubertf branches: 1.21.12; 1.21.14; 1.21.16;
Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.20 05-Jun-2006  christos - don't leak memory on allocation failure.
- s/perror/perr and print how much we were trying to allocate.
 1.19 10-Apr-2006  dbj the root directory of non fat32 filesystems is stored in a special area.
a couple of corner cases can cause it to fail to write out that area
after it performs repairs.
 1.18 20-Mar-2006  christos Coverity CID 1078: Add assertion check for NULL pointer.
 1.17 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype.
 1.16 13-Jul-2003  itojun use bounded string op
 1.15 25-Apr-2000  jdolecek Recognize "dirty" signature on FAT as set by Windows 95 OSR2+ and don't report
it just as "odd byte sequence". Handle the dirty flag similar way
it's treated on e.g. FFS - e.g. clear it separately from rest of FAT.
Changing of FAT is now postponed until after all checks are done,
check.c:checkfilesys() was cleaned considerably and several messages
has been adjusted to be more accurate.

If file system was modified and no error has occured, just return 0
instead of 4 - there is no need for forcing a reboot in this case.

This addresses bin/5638 by Christos Zoulas.
 1.14 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.13 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.12 22-Jan-1998  ws Fix some bugs & annoyances when reparing defect disks
 1.11 17-Oct-1997  ws Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.10 14-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* cleanup manpage
 1.9 08-Sep-1997  ws Fix a few bugs, especially when repairing disks:
Print correct pathname in error messages
Fix unterminating loop when trying to correct a bad fat
Require fat media byte to be the same as the one in the bpb
Fix unterminating loop when looking for free directory slot in LOST.DIR
(bad disk image provided by Christoph Badura)
 1.8 27-Sep-1996  christos util -> fsutil
 1.7 24-Sep-1996  ws Fix delete() call in dir.c differently than Christos' way.
Require at least one filesystem as program argument.
Update man page to reflect the latter.
 1.6 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.5 17-Sep-1996  ws Fix null pointer derefernce
Fixes PR#2765. Thanks David.
 1.4 11-Sep-1996  christos Fix gcc warnings.
 1.3 28-May-1996  ws Don't allocate data structures for non-directories
Free any data structures when finishing a check (at the latest)
 1.2 25-May-1996  ws Check return values of malloc
Generate full pathnames only on request
Minor cleanup, RCS Ids in .h files
 1.1 14-May-1996  ws branches: 1.1.4;
Add fsck utility for msdosfs
 1.1.4.1 31-May-1996  jtc pulled up from trunk by request of ws
 1.21.16.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.21.14.1 17-Jun-2008  yamt sync with head.
 1.21.12.1 29-Jun-2008  mjf Sync with HEAD.
 1.22.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.23.2.2 05-Mar-2011  bouyer Sync with HEAD
 1.23.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.25.20.1 10-Aug-2014  tls Rebase.
 1.25.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.6.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.8 02-Jan-2015  mlelstv Avoid mixing cluster numbers and sector numbers. Makes code more readable.
 1.7 03-Nov-2014  jakllsch ClusterOffset actually needs to be able to be negative.
 1.6 13-Jun-2008  martin branches: 1.6.38;
Move to 2 clause license, approved by Wolfgang Solfrank.
 1.5 17-Oct-1997  ws branches: 1.5.46; 1.5.48; 1.5.50;
Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.4 03-Jan-1997  ws Fix handling of clusters marked bad
Noted by Rafal Boni
 1.3 28-May-1996  ws Don't allocate data structures for non-directories
Free any data structures when finishing a check (at the latest)
 1.2 25-May-1996  ws Check return values of malloc
Generate full pathnames only on request
Minor cleanup, RCS Ids in .h files
 1.1 14-May-1996  ws branches: 1.1.4;
Add fsck utility for msdosfs
 1.1.4.1 31-May-1996  jtc pulled up from trunk by request of ws
 1.5.50.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.48.1 17-Jun-2008  yamt sync with head.
 1.5.46.1 29-Jun-2008  mjf Sync with HEAD.
 1.6.38.1 14-Nov-2014  martin Pull up following revision(s) (requested by jakllsch in ticket #234):
sbin/fsck_msdos/boot.c: revision 1.18
sbin/fsck_msdos/dosfs.h: revision 1.7
sbin/fsck_msdos/boot.c: revision 1.17
ClusterOffset actually needs to be able to be negative.
Add #include <inttypes.h> for intmax_t to fix compile error.
 1.14 24-Sep-2023  gutteridge ext.h: fix spelling and grammar in a comment
 1.13 11-Apr-2009  lukem fix sign-compare issues
 1.12 13-Jun-2008  martin branches: 1.12.4;
Move to 2 clause license, approved by Wolfgang Solfrank.
 1.11 19-Jan-2005  xtraeme branches: 1.11.26; 1.11.28; 1.11.30;
Kill __P(), ANSIfy, remove main() prototype.
 1.10 16-Sep-2001  wiz Spell 'occurred' with two 'r's.
 1.9 26-Jul-2001  wiz Various typos in comments (neccessary, sceme, choise, ...).
 1.8 06-Apr-2001  wiz Make WARNS=2 safe, and set WARNS to 2.
 1.7 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.6 25-Apr-2000  jdolecek branches: 1.6.4;
Recognize "dirty" signature on FAT as set by Windows 95 OSR2+ and don't report
it just as "odd byte sequence". Handle the dirty flag similar way
it's treated on e.g. FFS - e.g. clear it separately from rest of FAT.
Changing of FAT is now postponed until after all checks are done,
check.c:checkfilesys() was cleaned considerably and several messages
has been adjusted to be more accurate.

If file system was modified and no error has occured, just return 0
instead of 4 - there is no need for forcing a reboot in this case.

This addresses bin/5638 by Christos Zoulas.
 1.5 17-Oct-1997  ws branches: 1.5.4;
Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.4 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.3 28-May-1996  ws Don't allocate data structures for non-directories
Free any data structures when finishing a check (at the latest)
 1.2 25-May-1996  ws Check return values of malloc
Generate full pathnames only on request
Minor cleanup, RCS Ids in .h files
 1.1 14-May-1996  ws branches: 1.1.4;
Add fsck utility for msdosfs
 1.1.4.1 31-May-1996  jtc pulled up from trunk by request of ws
 1.5.4.1 10-Oct-2000  he Pull up revision 1.7 (requested by is):
Format string cleanup.
 1.6.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.11.30.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.11.28.1 17-Jun-2008  yamt sync with head.
 1.11.26.1 29-Jun-2008  mjf Sync with HEAD.
 1.12.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.30 04-Jun-2019  christos We already incremented cl; fix indexing. Noticed by Xin Li @FreeBSD.
 1.29 11-Jul-2014  christos branches: 1.29.24;
Another infinite loop fix from OpenBSD from Tobias Stoeckmann:

You can download a "proof of concept" from my website:
http://www.stoeckmann.org/openbsd/poc.iso.

Take FAT1 and it'll infinitely loop. This fix will complete
your previous commit.
 1.28 10-Jul-2014  christos Bring in a regression for the previous fix from OpenBSD
 1.27 07-Jul-2014  christos From: http://marc.info/?l=openbsd-tech&m=140234174104724&w=2
Avoid off-by-one on FAT12 filesystems.
 1.26 07-Jul-2014  christos From: http://marc.info/?l=openbsd-tech&m=140275150804337&w=2
Avoid infinite loops in cluster chain linked lists.
 1.25 07-Jul-2014  christos From: http://marc.info/?t=140304310700005&r=1&w=2
When truncating cluster chains fix the length of the cluster head.
 1.24 17-Jan-2013  jakllsch branches: 1.24.6;
An uninitialized next-free-cluster value in the file system information
block is valid; do not consider it for correction.
 1.23 07-Aug-2012  jakllsch branches: 1.23.2;
The free space value in the FSInfo block is merely unitialized when it is
0xffffffff. Fixes first part of bin/46743
 1.22 11-Apr-2009  lukem branches: 1.22.6;
fix sign-compare issues
 1.21 24-Jul-2008  matthias branches: 1.21.4;
Do not crash when boot->FSNext contains garbage (i.e. -1).
 1.20 13-Jun-2008  martin Move to 2 clause license, approved by Wolfgang Solfrank.
 1.19 06-Jun-2006  christos branches: 1.19.20; 1.19.22; 1.19.24;
don't use uint32_t when you mean size_t.
 1.18 05-Jun-2006  christos - don't leak memory on allocation failure.
- s/perror/perr and print how much we were trying to allocate.
 1.17 20-Mar-2006  christos Coverity CID 2302: Free fat if fatal error to avoid leak.
 1.16 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype.
 1.15 28-Feb-2003  matt Eliminate a -Wshadow warning
 1.14 06-Apr-2001  wiz Make WARNS=2 safe, and set WARNS to 2.
 1.13 05-Jan-2001  lukem minor knf
 1.12 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.11 26-Apr-2000  jdolecek branches: 1.11.4;
add a prototype for _readfat() added in last commit and make it static, so
that it's possible to compile this with -Wstrict-prototypes -Wmissing-prototypes

Breakage reported by Jeff Rizzo <riz@boogers.sf.ca.us> on current-users.
 1.10 25-Apr-2000  jdolecek Recognize "dirty" signature on FAT as set by Windows 95 OSR2+ and don't report
it just as "odd byte sequence". Handle the dirty flag similar way
it's treated on e.g. FFS - e.g. clear it separately from rest of FAT.
Changing of FAT is now postponed until after all checks are done,
check.c:checkfilesys() was cleaned considerably and several messages
has been adjusted to be more accurate.

If file system was modified and no error has occured, just return 0
instead of 4 - there is no need for forcing a reboot in this case.

This addresses bin/5638 by Christos Zoulas.
 1.9 22-Jan-1998  ws branches: 1.9.2;
Fix some bugs & annoyances when reparing defect disks
 1.8 17-Oct-1997  ws Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.7 14-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* cleanup manpage
 1.6 08-Sep-1997  ws Fix a few bugs, especially when repairing disks:
Print correct pathname in error messages
Fix unterminating loop when trying to correct a bad fat
Require fat media byte to be the same as the one in the bpb
Fix unterminating loop when looking for free directory slot in LOST.DIR
(bad disk image provided by Christoph Badura)
 1.5 03-Jan-1997  ws Fix handling of clusters marked bad
Noted by Rafal Boni
 1.4 27-Sep-1996  christos util -> fsutil
 1.3 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.2 28-May-1996  ws Don't allocate data structures for non-directories
Free any data structures when finishing a check (at the latest)
 1.1 14-May-1996  ws branches: 1.1.4;
Add fsck utility for msdosfs
 1.1.4.1 31-May-1996  jtc pulled up from trunk by request of ws
 1.9.2.2 11-Oct-2000  he Apply patch (requested by he):
Correct typo in previous.
 1.9.2.1 10-Oct-2000  he Pull up revision 1.12 (via patch, requested by is):
Format string cleanup.
 1.11.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.19.24.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.24.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.22.1 17-Jun-2008  yamt sync with head.
 1.19.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.19.20.1 29-Jun-2008  mjf Sync with HEAD.
 1.21.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.6.2 23-Jan-2013  yamt sync with head
 1.22.6.1 30-Oct-2012  yamt sync with head
 1.23.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.2.1 25-Feb-2013  tls resync with head
 1.24.6.1 10-Aug-2014  tls Rebase.
 1.29.24.1 10-Jun-2019  christos Sync with HEAD
 1.18 11-Sep-2016  sevan Document the version fsck_msdos first appeared.
Bump date.
 1.17 11-Apr-2010  wiz New sentence, new line. Sort SEE ALSO.
Improve formatting of option list.
 1.16 11-Apr-2010  hannken Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.

While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.15 13-Jun-2008  martin Move to 2 clause license, approved by Wolfgang Solfrank.
 1.14 25-Feb-2003  wiz branches: 1.14.32; 1.14.34; 1.14.36;
.Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.13 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.12 16-Nov-2001  wiz Drop an unnecessary .Pp.
 1.11 05-Jun-2001  wiz Drop arguments of .Os.
 1.10 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.9 17-Oct-1997  ws Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.8 11-Oct-1997  enami Use .Nm "" instead of .Nm fsck_msdos in SYNOPSIS.
 1.7 10-Oct-1997  lukem all but the first .Nm in SYNOPSIS need to be spelt out. [bin/4256]
 1.6 15-Sep-1997  lukem use .Nm correctly
 1.5 14-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* cleanup manpage
 1.4 17-Oct-1996  cgd clean up and add a fair bit of text. document -f (and the fact that it's
ignored).
 1.3 24-Sep-1996  ws Fix delete() call in dir.c differently than Christos' way.
Require at least one filesystem as program argument.
Update man page to reflect the latter.
 1.2 11-Sep-1996  christos Document -p (preen) option. If there are no filesystems specified on the
command line, get them from /etc/fstab when we are preening.
 1.1 14-May-1996  ws Add fsck utility for msdosfs
 1.14.36.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.34.1 17-Jun-2008  yamt sync with head.
 1.14.32.1 29-Jun-2008  mjf Sync with HEAD.
 1.24 16-Jun-2015  christos fix error messages containing \n
 1.23 09-Jun-2011  christos fix compilation.
 1.22 11-Apr-2010  hannken branches: 1.22.4;
Add -x option which allows to run `fsck_msdos -n' on a snapshot of
a live file system.

While here modify snap_open() to accept a character device as its
first arg and remove now unneeded get_snap_device().

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.21 13-Jun-2008  martin Move to 2 clause license, approved by Wolfgang Solfrank.
 1.20 24-Feb-2008  christos branches: 1.20.2; 1.20.4;
Catch signals and exit with the proper error code like all the other fsck
programs.
 1.19 23-Feb-2008  christos Make sure that the exit values are always sane, and use symbolic instead
of magic constants. Reviewed by go@
 1.18 10-Mar-2007  hubertf branches: 1.18.4; 1.18.10; 1.18.12;
- removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.17 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype.
 1.16 13-Jan-2005  christos Add a progress meter to fsck_ffs based on the work by thorpej presented
to the mailing lists last January. This is optional.
 1.15 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.14 20-Oct-2003  dsl Add a -q (quiet) option to print nothing for clean filesystems.
Support in fsck_ffs and stub in fsck_xxx.
Push a few more messages through pwarn() instead of printf() to ensure
disk name is shown.
 1.13 25-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.12 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.11 17-Oct-1997  ws Add support for FAT32
Support dropping lost cluster chains (on request by Christoph Badura)
While being here, fix some minor bugs, mostly with format strings
 1.10 01-Oct-1997  enami Don't declare optind.
 1.9 14-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* cleanup manpage
 1.8 17-Oct-1996  cgd include -f in usage, removed 'v' from getopt string since it's not handled
 1.7 03-Oct-1996  christos Accept -f flag, but do nothing with it.
 1.6 27-Sep-1996  christos util -> fsutil
 1.5 24-Sep-1996  ws Fix delete() call in dir.c differently than Christos' way.
Require at least one filesystem as program argument.
Update man page to reflect the latter.
 1.4 23-Sep-1996  christos - use error printing code from fsck(8)
- remove fstab walking code
- add missing prototypes
- add missing argument in dir.c near "Truncate", where delete() was being
called with fewer args. I think the missing argument should be a zero,
but Wolfgang should check...
 1.3 11-Sep-1996  christos Document -p (preen) option. If there are no filesystems specified on the
command line, get them from /etc/fstab when we are preening.
 1.2 25-May-1996  ws Check return values of malloc
Generate full pathnames only on request
Minor cleanup, RCS Ids in .h files
 1.1 14-May-1996  ws branches: 1.1.4;
Add fsck utility for msdosfs
 1.1.4.1 31-May-1996  jtc pulled up from trunk by request of ws
 1.18.12.2 29-Jun-2008  mjf Sync with HEAD.
 1.18.12.1 03-Apr-2008  mjf Sync with HEAD.
 1.18.10.1 24-Mar-2008  keiichi sync with head.
 1.18.4.1 23-Mar-2008  matt sync with HEAD
 1.20.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.20.2.1 17-Jun-2008  yamt sync with head.
 1.22.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.3 03-Jun-2023  lukem adapt to ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

Simplify CWARNFLAGS to use ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}
which works for both clang and gcc, and remove compiler-specific
equivalents.
 1.2 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.1 06-Apr-2022  reinoud Initial commit of the fsck_udf(8) utility that checks and repairs UDF
filesystems on optical media as well as on disc images, harddisc partitions
and wedges.
 1.2 06-Apr-2022  wiz New sentence, new line. Sort options.
 1.1 06-Apr-2022  reinoud Initial commit of the fsck_udf(8) utility that checks and repairs UDF
filesystems on optical media as well as on disc images, harddisc partitions
and wedges.
 1.15 05-Mar-2025  andvar fix couple typos in comments.
 1.14 03-Aug-2023  mrg branches: 1.14.2;
avoid double-free.

found by GCC 12.
 1.13 25-Apr-2022  reinoud Relax constraints on sequential media detection by checking for VAT format.
This allows fixing images of VAT formatted media too.
 1.12 25-Apr-2022  reinoud Fix endian bug in descriptor CRC length on updating a FE/EFE
 1.11 24-Apr-2022  reinoud Fix endian bug in allocation extents processing
 1.10 22-Apr-2022  reinoud Remove the error condition for these cases; the VAT LVExtension is
missing/corrupt but fsck_udf will reconstruct them anyway.
 1.9 22-Apr-2022  reinoud Prevent reading beyond the early_vat_location
 1.8 22-Apr-2022  reinoud Fix endian issues with fsck_udf/newfs_udf/makefs
 1.7 22-Apr-2022  reinoud Avoid assigned but unused compiler warnings when compiling with clang
 1.6 09-Apr-2022  riastradh fsck_udf(8): Nix trailing whitespace.

No functional change intended.
 1.5 08-Apr-2022  riastradh fsck_udf(8): Mark vat_length as ignored.
 1.4 08-Apr-2022  riastradh fsck_udf(8): Sprinkle __printflike and omit self-assignment.
 1.3 06-Apr-2022  martin Use PRI macros for uint64_t printf formats, %zu for size_t.
 1.2 06-Apr-2022  wiz fsck_udf: match usage to man page; fix typos
 1.1 06-Apr-2022  reinoud Initial commit of the fsck_udf(8) utility that checks and repairs UDF
filesystems on optical media as well as on disc images, harddisc partitions
and wedges.
 1.14.2.1 02-Aug-2025  perseant Sync with HEAD
 1.4 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.3 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.2 05-Sep-2012  riz Remove "-g" from CPPFLAGS.
 1.1 27-Jun-2011  uch branches: 1.1.2;
7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.2 17-Jul-2011  uch fix freeblock counting
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.3 11-Sep-2016  sevan Document author and the version fsck_v7fs appeared.
Replace contraction.
Bump date.
 1.2 27-Jun-2011  wiz Various improvements.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.2 10-Jan-2017  christos need <sys/stat.h>
 1.1 27-Jun-2011  uch branches: 1.1.24;
7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.1.24.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.2 08-Apr-2022  andvar fix various typos, mainly in comments, but also log messages, docs, game text.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.2 11-Feb-2022  hannken A component name is a counted string (cn_nameptr, cn_namelen),
not a zero terminated string cn_nameptr.

Change the following operations to work with counted strings:

v7fs_file_lookup_by_name()
v7fs_file_allocate()
v7fs_file_deallocate()
v7fs_directory_add_entry()
v7fs_directory_remove_entry()
v7fs_file_rename()
v7fs_file_link()
v7fs_dirent_filename()

Adapt all vnode operations with component names as argument.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.2 11-Feb-2022  hannken A component name is a counted string (cn_nameptr, cn_namelen),
not a zero terminated string cn_nameptr.

Change the following operations to work with counted strings:

v7fs_file_lookup_by_name()
v7fs_file_allocate()
v7fs_file_deallocate()
v7fs_directory_add_entry()
v7fs_directory_remove_entry()
v7fs_file_rename()
v7fs_file_link()
v7fs_dirent_filename()

Adapt all vnode operations with component names as argument.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.43 07-Oct-2023  rin Drop -O[01] hacks for vax; no longer necessary for patched GCC 10

PR port-vax/57646: Import major vax toolchain fix by Kalvis Duckmanton

XXXRO: GCC 12 may require hacks for a while, but it turned out that
GCC 12 should be treated differently from older versions; a lot of new
files need -O[01] flags, while some may no longer require it.

I will take a look later.

Note that these hacks are not required if Kalvis's patches for GCC 12
are applied.

Keep doc/HACKS entries for a while (will be sync with update for GCC 12).

diff --git a/crypto/external/bsd/openssh/lib/Makefile b/crypto/external/bsd/openssh/lib/Makefile
index 96a93f5e396..4e38be1b642 100644
--- a/crypto/external/bsd/openssh/lib/Makefile
+++ b/crypto/external/bsd/openssh/lib/Makefile
@@ -117,12 +117,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
# XXX
COPTS.channels.c+= -fno-strict-aliasing

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.poly1305.c+= -O0
-COPTS.umac.c+= -O0
-.endif
-
COPTS.hostfile.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.sshkey.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.cipher.c+= -Wno-error=deprecated-declarations
diff --git a/distrib/utils/x_ping/Makefile b/distrib/utils/x_ping/Makefile
index f1c452a0d60..8ee77580a3f 100644
--- a/distrib/utils/x_ping/Makefile
+++ b/distrib/utils/x_ping/Makefile
@@ -12,10 +12,6 @@ CPPFLAGS+= -I${SRCDIR} -DCRUNCHOPS
DPADD= ${LIBM}
LDADD= -lm

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>

.PATH: ${SRCDIR}
diff --git a/external/apache2/argon2/lib/libargon2/Makefile.inc b/external/apache2/argon2/lib/libargon2/Makefile.inc
index d3f4470c6c7..6a1dd146d7d 100644
--- a/external/apache2/argon2/lib/libargon2/Makefile.inc
+++ b/external/apache2/argon2/lib/libargon2/Makefile.inc
@@ -16,7 +16,3 @@ CFLAGS+= -pthread
LDADD+=-lpthread
DPADD+=${LIBPTHREAD}
.endif
-
-.if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-.endif
diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc
index 2f524358f46..d5da774f293 100644
--- a/external/bsd/jemalloc/lib/Makefile.inc
+++ b/external/bsd/jemalloc/lib/Makefile.inc
@@ -53,12 +53,6 @@ COPTS.ctl.c+=-Wno-error=stack-protector
COPTS.stats.c+=-Wno-error=stack-protector
COPTS.tcache.c+=-Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-# in merge_overlapping_regs, at regrename.c
-COPTS.arena.c+=-O0
-COPTS.extent.c+=-O0
-.endif
-
SRCS+=${JEMALLOC_SRCS}

jemalloc.d jemalloc.pico jemalloc.o jemalloc.ln jemalloc.po jemalloc.go: \
diff --git a/external/bsd/mdocml/lib/libmandoc/Makefile b/external/bsd/mdocml/lib/libmandoc/Makefile
index 40d7e29ae88..dfd3077a2c7 100644
--- a/external/bsd/mdocml/lib/libmandoc/Makefile
+++ b/external/bsd/mdocml/lib/libmandoc/Makefile
@@ -39,11 +39,6 @@ tbl_opts.c

MAN= mandoc.3

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.mdoc_macro.c+=-O0
-.endif
-
COPTS.man_validate.c+=-Wno-error=array-bounds

.include <bsd.lib.mk>
diff --git a/external/gpl3/binutils.old/lib/libbfd/Makefile b/external/gpl3/binutils.old/lib/libbfd/Makefile
index 03477232b55..74a354532fa 100644
--- a/external/gpl3/binutils.old/lib/libbfd/Makefile
+++ b/external/gpl3/binutils.old/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/binutils/lib/libbfd/Makefile b/external/gpl3/binutils/lib/libbfd/Makefile
index 00cb2b20081..a3f0c25fd35 100644
--- a/external/gpl3/binutils/lib/libbfd/Makefile
+++ b/external/gpl3/binutils/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/gcc.old/lib/Makefile.sanitizer b/external/gpl3/gcc.old/lib/Makefile.sanitizer
index efd36ae4bee..5173a5109a0 100644
--- a/external/gpl3/gcc.old/lib/Makefile.sanitizer
+++ b/external/gpl3/gcc.old/lib/Makefile.sanitizer
@@ -88,22 +88,3 @@ COPTS+=-fno-builtin -fno-exceptions -fno-rtti -funwind-tables

# Can't profile without it`
#-fomit-frame-pointer
-
-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_allocator.cc += -O1
-COPTS.sanitizer_common.cc += -O1
-COPTS.sanitizer_common_libcdep.cc += -O1
-COPTS.sanitizer_coverage_libcdep.cc += -O1
-COPTS.sanitizer_coverage_mapping_libcdep.cc += -O1
-COPTS.sanitizer_deadlock_detector1.cc += -O1
-COPTS.sanitizer_mac.cc += -O1
-COPTS.sanitizer_netbsd.cc += -O1
-COPTS.sanitizer_posix.cc += -O1
-COPTS.sanitizer_printf.cc += -O1
-COPTS.sanitizer_procmaps_common.cc += -O1
-COPTS.sanitizer_stackdepot.cc += -O1
-COPTS.sanitizer_symbolizer_libcdep.cc += -O1
-COPTS.sanitizer_symbolizer_report.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
diff --git a/external/gpl3/gcc.old/lib/libasan/Makefile b/external/gpl3/gcc.old/lib/libasan/Makefile
index 1e6f9608abe..3da7bbf2f58 100644
--- a/external/gpl3/gcc.old/lib/libasan/Makefile
+++ b/external/gpl3/gcc.old/lib/libasan/Makefile
@@ -49,14 +49,6 @@ LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
LIBDPLIBS+= pthread ${NETBSDSRCDIR}/lib/libpthread
CPPFLAGS+=-DCAN_SANITIZE_UB=0

-.if ${MACHINE_ARCH} == "vax"
-COPTS.asan_allocator.cc += -O1
-COPTS.asan_report.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
-
.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
COPTS.asan_interceptors.cc += -O1
.endif
diff --git a/external/gpl3/gcc.old/lib/liblsan/Makefile b/external/gpl3/gcc.old/lib/liblsan/Makefile
index 4578544a9a8..ddb7981077c 100644
--- a/external/gpl3/gcc.old/lib/liblsan/Makefile
+++ b/external/gpl3/gcc.old/lib/liblsan/Makefile
@@ -16,11 +16,6 @@ LSAN_SRCS+= \
lsan_linux.cc \
lsan_thread.cc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lsan_allocator.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= lsan
SRCS+= ${LSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/lib/libubsan/Makefile b/external/gpl3/gcc.old/lib/libubsan/Makefile
index 2e2faca7b1c..9de82550d14 100644
--- a/external/gpl3/gcc.old/lib/libubsan/Makefile
+++ b/external/gpl3/gcc.old/lib/libubsan/Makefile
@@ -26,10 +26,6 @@ UBSAN_SRCS= \
COPTS.${_s}.cc+=-frtti
.endfor

-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= ubsan
SRCS+= ${UBSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/usr.bin/cc1/Makefile b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
index c55e292ee8e..ff12a5be524 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
@@ -46,17 +46,6 @@ CPPFLAGS.default-c.c+= -I${BACKENDOBJ}
BUILDSYMLINKS+= ${GNUHOSTDIST}/gcc/config/sh/sh-c.cc sh-c.c
.endif

-.if ${MACHINE_CPU} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
index 3123ee0d60b..aab82ad3448 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
@@ -44,16 +44,8 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-.endif
+COPTS.c-cppbuiltin.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}
+COPTS.c-typeck.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}

.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
diff --git a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
index b9c108251c5..e04e8fc7f53 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
@@ -69,18 +69,6 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-COPTS.decl.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
index 7936efd3a5e..7c54559e21a 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
@@ -31,23 +31,6 @@ CHECKSUM_OBJS= ${LIBBACKTRACEOBJ}/libbacktrace.a \

CFLAGS+= -Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.call.c+=-O0
-COPTS.decl.c+=-O0
-COPTS.typeck2.c+=-O0
-COPTS.class.c+=-O0
-COPTS.typeck.c+=-O0
-COPTS.init.c+=-O0
-COPTS.semantics.c+=-O0
-COPTS.mangle.c+=-O0
-COPTS.constexpr.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1plus-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/gcc/Makefile b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
index 7a66d77ffc7..a5a4b1c3adf 100644
--- a/external/gpl3/gcc.old/usr.bin/gcc/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
@@ -25,9 +25,6 @@ ${SRCS}: ${GCCARCH}/defs.mk
.include <bsd.info.mk>

COPTS.gcc.c= -Wno-stack-protector
-.if ${MACHINE_ARCH} == "vax"
-COPTS.dse.c= -O1
-.endif

.PATH: ${DIST}/gcc ${DIST}/gcc/doc ${DIST}/gcc/c

diff --git a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
index 751d1513eec..33aeb1c9898 100644
--- a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
@@ -14,10 +14,6 @@ SRCS= decNumber.c decContext.c decimal32.c decimal64.c decimal128.c
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH} -I${DIST}/libdecnumber
CPPFLAGS+= -I${DIST}/libgcc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.include <bsd.lib.mk>

# Force using C++ for this
diff --git a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
index 90f44a9fcf6..fd251464fb7 100644
--- a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
@@ -24,11 +24,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.backtrace"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
DPADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} ${LIBINTL} ${LIBZ} ${LIBM}

diff --git a/external/gpl3/gcc.old/usr.bin/lto1/Makefile b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
index 4c49161a64c..340d3c6124f 100644
--- a/external/gpl3/gcc.old/usr.bin/lto1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
@@ -21,11 +21,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.libcpp"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTYOBJ}/libiberty.a
DPADD+= ${LIBIBERTYOBJ}/libiberty.a
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
diff --git a/external/gpl3/gdb.old/lib/libdecnumber/Makefile b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
index bcd4ae5b222..ce28811526b 100644
--- a/external/gpl3/gdb.old/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libdecnumber/Makefile b/external/gpl3/gdb/lib/libdecnumber/Makefile
index c95d36e3dfa..e3169865304 100644
--- a/external/gpl3/gdb/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd ${DIST}/libdecnumber/bid

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libgdb/Makefile b/external/gpl3/gdb/lib/libgdb/Makefile
index b87a515d13a..c118c363975 100644
--- a/external/gpl3/gdb/lib/libgdb/Makefile
+++ b/external/gpl3/gdb/lib/libgdb/Makefile
@@ -66,12 +66,6 @@ CFLAGS:= ${CXXFLAGS} -std=gnu++17 -Wno-error=stack-protector

ada-exp.c: ada-lex.c

-.if ${MACHINE} == "vax"
-. if ${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8
-COPTS.read.c+= -O0
-. endif
-.endif
-
# These are generated by implicit rules and are not easy to generate
CLEANDIRFILES+= \
ada-exp.c ada-lex.c \
diff --git a/external/mit/xorg/lib/gallium.old/Makefile b/external/mit/xorg/lib/gallium.old/Makefile
index 55b2fe3d1c1..bfa40c8974f 100644
--- a/external/mit/xorg/lib/gallium.old/Makefile
+++ b/external/mit/xorg/lib/gallium.old/Makefile
@@ -1211,10 +1211,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
# XXXGCC12
.if ${MACHINE_ARCH} == "m68k"
COPTS.st_glsl_to_tgsi.cpp += -O1
diff --git a/external/mit/xorg/lib/gallium/Makefile b/external/mit/xorg/lib/gallium/Makefile
index 6778a8c11c8..9f1422080fe 100644
--- a/external/mit/xorg/lib/gallium/Makefile
+++ b/external/mit/xorg/lib/gallium/Makefile
@@ -1428,10 +1428,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
COPTS.u_atomic.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-builtin-declaration-mismatch :}

.include <bsd.lib.mk>
diff --git a/external/mit/xorg/lib/libX11/Makefile.libx11 b/external/mit/xorg/lib/libX11/Makefile.libx11
index e103d9ace12..0e55c2a4732 100644
--- a/external/mit/xorg/lib/libX11/Makefile.libx11
+++ b/external/mit/xorg/lib/libX11/Makefile.libx11
@@ -471,11 +471,6 @@ COPTS.OpenDis.c+= -Wno-error # XXX xf86bigfstr.h
COPTS.XlibInt.c+= -Wno-error # XXX xcmiscstr.h
COPTS.XKBBind.c+= -Wno-deprecated-declarations # uses XKeycodeToKeysym

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.lcWrap.c+= -O0
-.endif
-
CWARNFLAGS.clang+= -Wno-string-plus-int

.include "${NETBSDSRCDIR}/external/mit/xorg/tools/makekeys/Makefile.makekeys"
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile
index e86a63aaea7..678537066ed 100644
--- a/games/gomoku/Makefile
+++ b/games/gomoku/Makefile
@@ -9,10 +9,6 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}

-.if ${MACHINE} == "vax"
-COPTS.pickmove.c += -O0
-.endif
-
#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index e9c53f23ae5..b919dac17c6 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -52,7 +52,3 @@ map: map.c
./map | plot > /dev/tty

.include <bsd.prog.mk>
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/i18n_module/UTF7/Makefile b/lib/i18n_module/UTF7/Makefile
index 712c1515d42..7136f7f0cc3 100644
--- a/lib/i18n_module/UTF7/Makefile
+++ b/lib/i18n_module/UTF7/Makefile
@@ -3,6 +3,3 @@
SRCPRE=citrus_
.include <bsd.lib.mk>

-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.citrus_utf7.c+= -O0
-.endif
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b2aea1e04b0..e60a2862d48 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -15,11 +15,6 @@ SRCS= blocksort.c huffman.c crctable.c randtable.c compress.c \
INCS= bzlib.h
INCSDIR= /usr/include

-# XXX huffman.c gets mis-compiled with 2.95.3
-.if ${MACHINE_ARCH} == "vax"
-COPTS+= -O0
-.endif
-
COPTS+= ${CC_WNO_IMPLICIT_FALLTHROUGH}

# XXX blocksort.c gets mis-compiled with 4.1
diff --git a/lib/libc/gdtoa/Makefile.inc b/lib/libc/gdtoa/Makefile.inc
index 132686fc33d..609da919803 100644
--- a/lib/libc/gdtoa/Makefile.inc
+++ b/lib/libc/gdtoa/Makefile.inc
@@ -44,10 +44,3 @@ SRCS+= dmisc.c \
.if ${MACHINE_ARCH} != "vax"
SRCS+= strtord.c
.endif
-
-# XXX revisit with newer GCC.
-# Ensure numbers like 0xffff319f5fa95963 print correctly
-# ("999999999999999.98", not garbage like "?A>C>@>C:BA;A><.:<")
-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index cb3f89d6d09..e9c8be820da 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -30,9 +30,6 @@ SRCS+= crypt-argon2.c
SRCS+= ${src}
COPTS.${src}+= -fvisibility=hidden
. endfor
-. if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-. endif
.endif

WARNS?= 5
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
index f5baae1e883..24f7e1121e5 100644
--- a/libexec/ld.elf_so/Makefile
+++ b/libexec/ld.elf_so/Makefile
@@ -141,10 +141,6 @@ CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector

-.if ${MACHINE_CPU} == "vax"
-COPTS.rtld.c+= -O0
-.endif
-
LDADD+= -Wl,--version-script=${.CURDIR}/symbols.map
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
diff --git a/sbin/fsck_ffs/Makefile.common b/sbin/fsck_ffs/Makefile.common
index 765638b2801..824e3bf2628 100644
--- a/sbin/fsck_ffs/Makefile.common
+++ b/sbin/fsck_ffs/Makefile.common
@@ -36,7 +36,3 @@ COPTS.ffs_appleufs.c+= -Wno-pointer-sign
.if ${MACHINE_ARCH} == "m68000"
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif
-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-.endif
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index c039f73a1eb..3b0331e5880 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -39,12 +39,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-COPTS.fsdb.c+= -O0
-.endif
-
CWARNFLAGS.gcc+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

.include <bsd.prog.mk>
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 40a44b9a038..ecfdbff4d3a 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -20,8 +20,4 @@ DPADD+=${LIBPROP}

.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mke2fs.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 4f33501ea7a..1f7f56e3ea5 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -12,8 +12,4 @@ CPPFLAGS+= -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax
index cf095d54a86..c483eaa644a 100644
--- a/sys/arch/vax/conf/Makefile.vax
+++ b/sys/arch/vax/conf/Makefile.vax
@@ -34,7 +34,6 @@ GENASSYM_CONF= ${VAX}/vax/genassym.cf
CPPFLAGS+= -D_VAX_INLINE_
AFLAGS+= -x assembler-with-cpp -fno-pic
CFLAGS+= -fno-pic
-COPTS.wsmux.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -O1 :}


##
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 718c97ce857..4ef3840c753 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -96,7 +96,3 @@ SRCS+= ufs.c
lib${LIB}.o:: ${OBJS:O} __buildstdlib

CPPFLAGS+= -Wno-pointer-sign
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.bootp.c+= -O0
-.endif
diff --git a/sys/lib/libz/Makefile b/sys/lib/libz/Makefile
index 6945c0da6c6..61fb7d4f652 100644
--- a/sys/lib/libz/Makefile
+++ b/sys/lib/libz/Makefile
@@ -25,7 +25,3 @@ CLEANFILES+= lib${LIB}.o
.include <bsd.lib.mk>

lib${LIB}.o:: ${OBJS:O} __buildstdlib
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.inftrees.c+= -O0
-.endif
diff --git a/sys/modules/lfs/Makefile b/sys/modules/lfs/Makefile
index 962538821a5..ea8f187e160 100644
--- a/sys/modules/lfs/Makefile
+++ b/sys/modules/lfs/Makefile
@@ -18,9 +18,4 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_inode.c ulfs_lookup.c \

WARNS= 3

-.if ${MACHINE} == "vax"
-# GCC 6.5 and 7.4 cannot compile this with -DDIAGNOSTIC and -O2/-O1
-COPTS.lfs_inode.c+= -O0
-.endif
-
.include <bsd.kmodule.mk>
diff --git a/sys/rump/fs/lib/liblfs/Makefile b/sys/rump/fs/lib/liblfs/Makefile
index abade3767d9..68b74c62502 100644
--- a/sys/rump/fs/lib/liblfs/Makefile
+++ b/sys/rump/fs/lib/liblfs/Makefile
@@ -17,9 +17,6 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_extattr.c \


CFLAGS+= -DLFS_KERNEL_RFW
-.if ${MACHINE_ARCH} == "vax"
-COPTS.lfs_inode.c+=-O0
-.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff --git a/usr.sbin/mtrace/Makefile b/usr.sbin/mtrace/Makefile
index aef09db6198..9c125c15265 100644
--- a/usr.sbin/mtrace/Makefile
+++ b/usr.sbin/mtrace/Makefile
@@ -12,10 +12,6 @@ PROG= mtrace
SRCS= igmp.c inet.c kern.c mtrace.c
MAN= mtrace.8

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mtrace.c=-O0
-.endif
-
BINMODE=4555
BINOWN= root

diff --git a/external/gpl3/gcc.old/usr.bin/backend/Makefile b/external/gpl3/gcc.old/usr.bin/backend/Makefile
index d69a26fe619..99e881c783d 100644
--- a/external/gpl3/gcc.old/usr.bin/backend/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/backend/Makefile
@@ -533,68 +533,9 @@ COPTS.insn-recog.c+=-Wno-error

.if ${GCC_MACHINE_ARCH} == "vax"
CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
-COPTS.builtins.c+=-O0
-COPTS.calls.c+=-O0
-COPTS.convert.c+=-O0
-COPTS.data-streamer-out.c+=-O0
-COPTS.dse.c+=-O0 # XXX port-vax/51967
-COPTS.dwarf2out.c+=-O0
-COPTS.expmed.c+=-O0
-COPTS.expr.c+=-O0 -Wno-error=tautological-compare
-COPTS.fixed-value.c+=-O0
-COPTS.fold-const.c+=-O0
-COPTS.generic-match.c+=-O0
-COPTS.gimple-fold.c+=-O0
-COPTS.gimple-match.c+=-O0
-COPTS.gimple-ssa-strength-reduction.c+=-O0
-COPTS.gimple-ssa-warn-restrict.c+=-O0
-COPTS.gimple.c+=-O0
-COPTS.internal-fn.c+=-O0
-COPTS.lto-streamer-out.c+=-O0
-COPTS.omp-low.c+=-O0
-COPTS.predict.c+=-O0
-COPTS.range-op.cc+=-O0
-COPTS.recog.c+=-O0
-COPTS.sanopt.c+=-O0
-COPTS.stmt.c+=-O0
-COPTS.stor-layout.c+=-O0
-COPTS.targhooks.c+=-O0
-COPTS.tree-affine.c+=-O0
-COPTS.tree-cfg.c+=-O0
-COPTS.tree-data-ref.c+=-O0
-COPTS.tree-eh.c+=-O0
-COPTS.tree-if-conv.c+=-O0
-COPTS.tree-object-size.c+=-O0
-COPTS.tree-parloops.c+=-O0
-COPTS.tree-predcom.c+=-O0
-COPTS.tree-pretty-print.c+=-O0
-COPTS.tree-ssa-alias.c+=-O0
-COPTS.tree-ssa-ccp.c+=-O0
-COPTS.tree-ssa-forwprop.c+=-O0
-COPTS.tree-ssa-loop-ivopts.c+=-O0
-COPTS.tree-ssa-loop-manip.c+=-O0
-COPTS.tree-ssa-loop-niter.c+=-O0
-COPTS.tree-ssa-math-opts.c+=-O0
-COPTS.tree-ssa-phiopt.c+= -O0
-COPTS.tree-ssa-pre.c+=-O0
-COPTS.tree-ssa-reassoc.c+=-O0
-COPTS.tree-ssa-strlen.c+=-O0
-COPTS.tree-ssa-uninit.c+=-O0
-COPTS.tree-ssa.c+=-O0
-COPTS.tree-switch-conversion.c+=-O0
-COPTS.tree-vect-data-refs.c+=-O0
-COPTS.tree-vect-loop-manip.c+=-O0
-COPTS.tree-vect-loop.c+=-O0
-COPTS.tree-vect-patterns.c+=-O0
-COPTS.tree-vect-stmts.c+=-O0
-COPTS.tree-vrp.c+=-O0
-COPTS.tree.c+=-O0
-COPTS.ubsan.c+=-O0
-COPTS.varasm.c+=-O0
-COPTS.vr-values.c+=-O0
-COPTS.web.c+=-O0
-COPTS.wide-int-range.cc+=-O0
-COPTS.wide-int.cc+=-O0
+
+COPTS.expmed.c+=-Wno-error=tautological-compare
+COPTS.expr.c+=-Wno-error=tautological-compare
.else
COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
.endif
 1.42 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.41 15-Apr-2021  mrg branches: 1.41.6;
vax vs gcc: fsdb.c loses. also build this with -O0.
 1.40 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.39 28-Oct-2019  christos inode.c needs -O0 for vax
 1.38 23-Mar-2016  christos branches: 1.38.16;
-O0 for pass1.c and vax
 1.37 15-Apr-2015  mrg remove various HAVE_GCC=45 fragments.
 1.36 09-Nov-2013  christos vax specific gcc 4.8.1 hacks
 1.35 09-Nov-2013  christos put instruction generation bug for the vax for 4.8 too
 1.34 10-Aug-2012  joerg Don't depend on HAVE_GCC being always defined.
 1.33 15-Aug-2011  dholland branches: 1.33.2;
Remove redundant WARNS=4
 1.32 14-Aug-2011  christos remove gcc-4.5 hacks.
 1.31 03-Jul-2011  mrg apply some -O0 with gcc 4.5 and vax.
 1.30 22-Jun-2011  mrg apply some -Wno-error and/or -fno-strict-aliasing.


all of this should be looked at closer, but some of them are not
very trivial.
 1.29 20-Jun-2011  mrg remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.28 06-Mar-2011  bouyer branches: 1.28.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.27 03-Feb-2010  roy branches: 1.27.2;
Userland now builds and uses terminfo instead of termcap.

OK: core@, jdc@
 1.26 06-Jun-2009  haad Add proplib to list of libraries, ifx fsdb build after my getdiskinfo change.
 1.25 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.24 29-Aug-2008  gmcgarry branches: 1.24.4;
Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.23 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.22 04-May-2008  tsutsui branches: 1.22.2; 1.22.4;
There is only one more file which requires HACKS for m68000,
so handle it in each Makefile rather than sys.mk.

These ICEs might be related with GCC Bugzilla Bug 32424
which is not resolved yet even in the upstream.
 1.21 09-Feb-2008  mrg branches: 1.21.4; 1.21.6;
make all sun2 use -O0 and move most of the hacks out into just 3 files.
 1.20 27-Aug-2006  christos branches: 1.20.8; 1.20.10;
need getdiskinfo.
 1.19 24-Jun-2006  mrg work around some GCC4 internal problems on m68000 platform.
document the hack, and update another GCC4 list.
 1.18 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.17 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.16 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.15 03-Jan-2004  dbj add -F option, similar to fsck/newfs/dumpfs
correctly handle negative results from fsck's setup routine
handle uid and gid in FS_42INODEFMT inodes
 1.14 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.13 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.12 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.11 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.10 13-Oct-1997  veego We don't need the -I. . Pointed out by enami tsugutomo.
 1.9 11-Oct-1997  veego Add the missing . for -I
 1.8 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.7 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.6 06-May-1997  gwr Use .PATH.c: ...
 1.5 11-Oct-1996  thorpej Fix a couple of glitches:
- s/fsutil.o/fsutil.c/ on a SRCS line.
- Don't need preen.c
 1.4 28-Sep-1996  christos Make this work after the fsck changes.
 1.3 08-Apr-1996  jtc Add to DPADD for each library in LDADD; Reported by Mike Long <mike.long@analog.com> in PR #2301.
 1.2 05-Apr-1996  cgd deal with the fact that fsck has moved
 1.1 08-Oct-1995  thorpej branches: 1.1.1;
Initial revision
 1.1.1.1 08-Oct-1995  thorpej FFS debugging/editing tool, from John Kohl.
 1.20.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.20.8.1 23-Mar-2008  matt sync with HEAD
 1.21.6.1 18-May-2008  yamt sync with head.
 1.21.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.21.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.4.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.22.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.27.2.2 08-Feb-2011  bouyer Add quota2_subr.c to make it link again.
 1.27.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.28.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.33.2.1 30-Oct-2012  yamt sync with head
 1.38.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.41.6.1 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #394):

external/gpl3/binutils/dist/gas/config/tc-vax.h: revision 1.10
tools/gcc/Makefile: revision 1.109
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.16
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.17
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/recog.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/function.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/dse.c: revision 1.14 - 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.13
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.15
external/gpl3/gcc.old/dist/gcc/doc/tm.texi.in: revision 1.10
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.19
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.13
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.20
external/gpl3/gcc.old/dist/gcc/targhooks.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.15
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.13
external/gpl3/gcc.old/dist/gcc/doc/tm.texi: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.13
external/gpl3/gcc.old/dist/gcc/targhooks.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/target.def: revision 1.10
external/gpl3/gcc.old/dist/gcc/rtlanal.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/reload.c: revision 1.12
external/gpl3/gcc.old/usr.bin/gcc/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/lto-dump/Makefile: revision 1.3
external/gpl3/gcc.old/lib/Makefile.sanitizer: revision 1.7
external/gpl3/binutils.old/lib/libbfd/Makefile: revision 1.10
distrib/utils/x_ping/Makefile: revision 1.9
games/phantasia/Makefile: revision 1.38
external/apache2/argon2/lib/libargon2/Makefile.inc: revision 1.2
external/gpl3/gcc.old/lib/libubsan/Makefile: revision 1.8
external/bsd/mdocml/lib/libmandoc/Makefile: revision 1.13
sbin/ping/Makefile: revision 1.18
sbin/newfs_ext2fs/Makefile: revision 1.7
sys/lib/libz/Makefile: revision 1.24
sys/lib/libsa/Makefile: revision 1.97
external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile: revision 1.3
external/gpl3/gdb/lib/libgdb/Makefile: revision 1.36
sys/modules/lfs/Makefile: revision 1.11
external/mit/xorg/lib/gallium/Makefile: revision 1.51
external/gpl3/gdb.old/lib/libdecnumber/Makefile: revision 1.10
external/mit/xorg/lib/libX11/Makefile.libx11: revision 1.26
libexec/ld.elf_so/Makefile: revision 1.148
external/bsd/jemalloc/lib/Makefile.inc: revision 1.16
external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile: revision 1.14
crypto/external/bsd/openssh/lib/Makefile: revision 1.38
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.21
external/gpl3/gcc.old/usr.bin/cc1/Makefile: revision 1.12
external/gpl3/gcc.old/lib/libasan/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/cc1plus/Makefile: revision 1.13
lib/libcrypt/Makefile: revision 1.36
external/gpl3/gdb/lib/libdecnumber/Makefile: revision 1.5
lib/libc/gdtoa/Makefile.inc: revision 1.13
games/gomoku/Makefile: revision 1.13
sbin/fsdb/Makefile: revision 1.43
external/gpl3/gcc.old/usr.bin/lto1/Makefile: revision 1.9
external/mit/xorg/lib/gallium.old/Makefile: revision 1.8
lib/libbz2/Makefile: revision 1.22
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.12
usr.sbin/mtrace/Makefile: revision 1.14
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.13
sys/arch/vax/conf/Makefile.vax: revision 1.86
sys/rump/fs/lib/liblfs/Makefile: revision 1.18
sbin/fsck_ffs/Makefile.common: revision 1.3
external/gpl3/binutils/lib/libbfd/Makefile: revision 1.27
lib/i18n_module/UTF7/Makefile: revision 1.5
external/gpl3/gcc.old/lib/liblsan/Makefile: revision 1.7
doc/CHANGES (apply patch)
(all external/gpl3/gcc.old/ changes applied to external/gpl3/gcc/)

PR 57646: Import major vax toolchain fix.
 1.28 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.27 29-May-2021  christos Add birthtime support and make time 64 bit.
 1.26 05-Aug-2017  wiz branches: 1.26.10;
Fix punctuation markup.
 1.25 04-Aug-2017  mrg add a "saveblks <file>" command that saves the data blocks of the current
inode into named file.
 1.24 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.23 03-Mar-2014  blymn Correct usage of clri.
 1.22 30-Apr-2008  martin branches: 1.22.22; 1.22.28;
Convert TNF licenses to new 2 clause variant
 1.21 25-May-2005  wiz branches: 1.21.20; 1.21.22;
Macro improvement.
 1.20 25-May-2005  snj Grammar fix, from Jeff Ito in PR bin/30320. While here, fix a typo
and use .Dq for quotes.
 1.19 04-Jan-2004  wiz Bump date for new -F. Standardise flags display in SYNOPSIS.
 1.18 03-Jan-2004  dbj add -F option, similar to fsck/newfs/dumpfs
correctly handle negative results from fsck's setup routine
handle uid and gid in FS_42INODEFMT inodes
 1.17 27-Jun-2003  wiz Add Ns.
 1.16 09-May-2003  jmc Fix typo
 1.15 26-Apr-2003  bouyer Add a findblk command, which list the inode(s) owning the disk sector(s)
passed as argument.
 1.14 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.13 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.12 16-Nov-2001  wiz Sort sections.
 1.11 16-Nov-2001  wiz Whitespace nits
 1.10 05-Jun-2001  wiz Drop arguments of .Os.
 1.9 09-Mar-1999  bouyer Add a [-n] option, which allows to examine a fs without altering it.
Add a 'blks' command, which lists the blocks address of a file.
 1.8 22-May-1998  msaitoh sort entries and delete extra periods in SEE also section.
 1.7 14-Sep-1997  lukem * KNF-ify
* prefix hex numbers with '0x'
 1.6 31-Jul-1997  jtc Fix files using old TNF copyright notice
 1.5 11-Jan-1997  lukem the editline(3) man page now exists (but not as libedit(3))
 1.4 27-Feb-1996  jtc Copyright assigned to the NetBSD Foundation
 1.3 06-Feb-1996  jtc Note that fsdb arrived with NetBSD 1.1
 1.2 08-Oct-1995  thorpej A teensy bit of really minor cleanup.
 1.1 08-Oct-1995  thorpej branches: 1.1.1;
Initial revision
 1.1.1.1 08-Oct-1995  thorpej FFS debugging/editing tool, from John Kohl.
 1.21.22.1 18-May-2008  yamt sync with head.
 1.21.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.28.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.22.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26.10.1 31-May-2021  cjep sync with head
 1.54 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.53 17-Nov-2022  chs branches: 1.53.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.52 29-May-2021  christos Add birthtime support and make time 64 bit.
 1.51 05-Apr-2020  joerg branches: 1.51.2;
Fix depenency on common symbols in sbin.
 1.50 04-Aug-2017  mrg branches: 1.50.4;
add a "saveblks <file>" command that saves the data blocks of the current
inode into named file.
 1.49 28-Jul-2016  martin From Michael Plass:

The superblock field that distinguishes between 4.2BSD and 4.4BSD
inodes is really only relevant on a UFS1 file system. Make sure that
it is a UFS1 fs before using fs_old_inodefmt.

Note that the NetBSD newfs and mkfs utilities initialize fs_old_inodefmt
even for UFS2, so problems were apparent only on file systems created
by other operating systems, for example, FreeBSD.
 1.48 23-Jun-2013  dholland branches: 1.48.6; 1.48.8; 1.48.10;
fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.47 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.46 09-Jun-2013  dholland Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.45 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.44 20-Mar-2012  matt branches: 1.44.2;
Convert to C89 function definitions
 1.43 29-Aug-2011  joerg branches: 1.43.2; 1.43.4; 1.43.8; 1.43.10;
Use __dead
 1.42 14-Aug-2011  christos remove gcc-4.5 hacks.
 1.41 09-Jun-2011  christos fix compilation.
 1.40 09-Jun-2011  christos share more code.
 1.39 11-Apr-2009  lukem branches: 1.39.4;
fix sign-compare issues
 1.38 30-Aug-2008  bouyer branches: 1.38.4;
Add fss(4) snapshot support to fsck_ffs(8) (via -x or -X options, like
dump(8)). This allows fsck_ffs -n to work on a snapshot of a R/W mounted
filesystem, and avoid errors related to filesystem activity.
 1.37 28-Apr-2008  martin branches: 1.37.2;
Remove clause 3 and 4 from TNF licenses
 1.36 16-Oct-2006  christos branches: 1.36.18; 1.36.20;
c99 initializer
 1.35 19-May-2006  christos Coverity CID 3656,3655: Plug memory leak.
 1.34 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.33 19-Aug-2005  christos 64 bit inode changes
 1.32 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.31 05-Feb-2005  xtraeme Kill __P();
 1.30 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.29 17-Sep-2004  yamt fix blks command.
- use 64-bit variables for lbns.
- correct file block offsets in the case of absent indirect blocks.
 1.28 04-Jan-2004  wiz branches: 1.28.2;
Standardize flags display in usage.
 1.27 03-Jan-2004  dbj add -F option, similar to fsck/newfs/dumpfs
correctly handle negative results from fsck's setup routine
handle uid and gid in FS_42INODEFMT inodes
 1.26 13-Jul-2003  itojun use bounded string op
 1.25 26-Apr-2003  bouyer Add a findblk command, which list the inode(s) owning the disk sector(s)
passed as argument.
 1.24 08-Apr-2003  fvdl Fix reverse test for UFS2 in the blks command.
 1.23 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.22 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.21 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.20 18-Mar-2002  thorpej Cast 3rd arg to el_parse() to deal with const'ification of
libedit.
 1.19 19-Feb-2001  cgd convert to use getprogname()
 1.18 04-Feb-2001  christos remove redundant declarations
 1.17 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.16 09-Mar-1999  bouyer branches: 1.16.2; 1.16.10;
Add a [-n] option, which allows to examine a fs without altering it.
Add a 'blks' command, which lists the blocks address of a file.
 1.15 20-May-1998  enami s/H_SETMAXSIZE/H_SETSIZE/
 1.14 20-May-1998  christos Adapt to the libedit changes.
 1.13 01-Apr-1998  kleink Need <time.h> for mktime() prototype.
 1.12 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.11 14-Oct-1997  christos PR/4257: Jaromir Dolecek: Update for libedit interface change.
 1.10 15-Sep-1997  lukem deprecate register
 1.9 14-Sep-1997  lukem * KNF-ify
* prefix hex numbers with '0x'
 1.8 31-Jul-1997  jtc Fix files using old TNF copyright notice
 1.7 11-Jan-1997  lukem don't call el_parse() if there's no commands (el_parse() now checks this,
but more safety is good)
 1.6 11-Oct-1996  thorpej Add a chlen command, to change the length/size of an inode. From FreeBSD.
 1.5 28-Sep-1996  christos Make this work after the fsck changes.
 1.4 21-Mar-1996  jtc Be pedantic, main() returns int in C.
 1.3 27-Feb-1996  jtc Copyright assigned to the NetBSD Foundation
 1.2 08-Oct-1995  thorpej A teensy bit of really minor cleanup.
 1.1 08-Oct-1995  thorpej branches: 1.1.1;
Initial revision
 1.1.1.1 08-Oct-1995  thorpej FFS debugging/editing tool, from John Kohl.
 1.16.10.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.16.2.1 10-Oct-2000  he Pull up revision 1.17 (requested by is):
Format string cleanup.
 1.28.2.1 18-Sep-2004  he Pull up revision 1.29 (requested by yamt in ticket #862):
Fix blks command:
- use 64-bit variables for lbns
- correct file block offsets in the case of absent indirect
blocks
 1.36.20.1 18-May-2008  yamt sync with head.
 1.36.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.36.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.37.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.38.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.39.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.43.10.1 27-Aug-2016  bouyer Pull up following revision(s) (requested by martin in ticket #1395):
sys/ufs/ffs/ffs_vfsops.c: revision 1.340
usr.sbin/quot/quot.c: revision 1.34
sbin/fsdb/fsdb.c: revision 1.49
From Michael Plass:
The superblock field that distinguishes between 4.2BSD and 4.4BSD
inodes is really only relevant on a UFS1 file system. Make sure that
it is a UFS1 fs before using fs_old_inodefmt.
Note that the NetBSD newfs and mkfs utilities initialize fs_old_inodefmt
even for UFS2, so problems were apparent only on file systems created
by other operating systems, for example, FreeBSD.
 1.43.8.1 27-Aug-2016  bouyer Pull up following revision(s) (requested by martin in ticket #1395):
sys/ufs/ffs/ffs_vfsops.c: revision 1.340
usr.sbin/quot/quot.c: revision 1.34
sbin/fsdb/fsdb.c: revision 1.49
From Michael Plass:
The superblock field that distinguishes between 4.2BSD and 4.4BSD
inodes is really only relevant on a UFS1 file system. Make sure that
it is a UFS1 fs before using fs_old_inodefmt.
Note that the NetBSD newfs and mkfs utilities initialize fs_old_inodefmt
even for UFS2, so problems were apparent only on file systems created
by other operating systems, for example, FreeBSD.
 1.43.4.1 27-Aug-2016  bouyer Pull up following revision(s) (requested by martin in ticket #1395):
sys/ufs/ffs/ffs_vfsops.c: revision 1.340
usr.sbin/quot/quot.c: revision 1.34
sbin/fsdb/fsdb.c: revision 1.49
From Michael Plass:
The superblock field that distinguishes between 4.2BSD and 4.4BSD
inodes is really only relevant on a UFS1 file system. Make sure that
it is a UFS1 fs before using fs_old_inodefmt.
Note that the NetBSD newfs and mkfs utilities initialize fs_old_inodefmt
even for UFS2, so problems were apparent only on file systems created
by other operating systems, for example, FreeBSD.
 1.43.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.43.2.2 23-Jan-2013  yamt sync with head
 1.43.2.1 17-Apr-2012  yamt sync with head
 1.44.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.44.2.2 23-Jun-2013  tls resync from head
 1.44.2.1 25-Feb-2013  tls resync with head
 1.48.10.1 06-Aug-2016  pgoyette Sync with HEAD
 1.48.8.1 27-Aug-2016  bouyer Pull up following revision(s) (requested by martin in ticket #1210):
sys/ufs/ffs/ffs_vfsops.c: revision 1.340
usr.sbin/quot/quot.c: revision 1.34
sbin/fsdb/fsdb.c: revision 1.49
From Michael Plass:
The superblock field that distinguishes between 4.2BSD and 4.4BSD
inodes is really only relevant on a UFS1 file system. Make sure that
it is a UFS1 fs before using fs_old_inodefmt.
Note that the NetBSD newfs and mkfs utilities initialize fs_old_inodefmt
even for UFS2, so problems were apparent only on file systems created
by other operating systems, for example, FreeBSD.
 1.48.6.1 27-Aug-2016  bouyer Pull up following revision(s) (requested by martin in ticket #1210):
sys/ufs/ffs/ffs_vfsops.c: revision 1.340
usr.sbin/quot/quot.c: revision 1.34
sbin/fsdb/fsdb.c: revision 1.49
From Michael Plass:
The superblock field that distinguishes between 4.2BSD and 4.4BSD
inodes is really only relevant on a UFS1 file system. Make sure that
it is a UFS1 fs before using fs_old_inodefmt.
Note that the NetBSD newfs and mkfs utilities initialize fs_old_inodefmt
even for UFS2, so problems were apparent only on file systems created
by other operating systems, for example, FreeBSD.
 1.50.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.51.2.1 31-May-2021  cjep sync with head
 1.53.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.11 11-Apr-2009  lukem fix sign-compare issues
 1.10 28-Apr-2008  martin branches: 1.10.8;
Remove clause 3 and 4 from TNF licenses
 1.9 19-Jan-2005  xtraeme branches: 1.9.26; 1.9.28;
Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.8 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.7 04-Feb-2001  christos remove redundant declarations
 1.6 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.5 31-Jul-1997  jtc Fix files using old TNF copyright notice
 1.4 28-Sep-1996  christos Make this work after the fsck changes.
 1.3 27-Feb-1996  jtc Copyright assigned to the NetBSD Foundation
 1.2 08-Oct-1995  thorpej A teensy bit of really minor cleanup.
 1.1 08-Oct-1995  thorpej branches: 1.1.1;
Initial revision
 1.1.1.1 08-Oct-1995  thorpej FFS debugging/editing tool, from John Kohl.
 1.9.28.1 18-May-2008  yamt sync with head.
 1.9.26.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.8.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.24 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.23 29-May-2021  christos Add birthtime support and make time 64 bit.
 1.22 11-Apr-2009  lukem branches: 1.22.52;
fix sign-compare issues
 1.21 29-Dec-2008  mlelstv branches: 1.21.2;
cast arguments for changed printf format
 1.20 28-Dec-2008  christos fix printf formats.
 1.19 08-Jul-2008  simonb No need to print "0x0x" before a hex number, one "0x" should be enough.
 1.18 28-Apr-2008  martin branches: 1.18.2; 1.18.4;
Remove clause 3 and 4 from TNF licenses
 1.17 10-Mar-2007  hubertf branches: 1.17.12; 1.17.14;
Remove unused ctype.h
From: Slava Semushin <php-coder@altlinux.ru>
 1.16 19-Aug-2005  christos 64 bit inode changes
 1.15 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.14 03-Jan-2004  dbj add -F option, similar to fsck/newfs/dumpfs
correctly handle negative results from fsck's setup routine
handle uid and gid in FS_42INODEFMT inodes
 1.13 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.12 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.11 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.10 01-Apr-1998  kleink Need <time.h> for ctime() prototype.
 1.9 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.8 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.7 14-Sep-1997  lukem * KNF-ify
* prefix hex numbers with '0x'
 1.6 31-Jul-1997  jtc Fix files using old TNF copyright notice
 1.5 28-Sep-1996  christos Make this work after the fsck changes.
 1.4 27-Feb-1996  jtc Copyright assigned to the NetBSD Foundation
 1.3 14-Dec-1995  thorpej Make this compile with -Werror.
 1.2 08-Oct-1995  thorpej A teensy bit of really minor cleanup.
 1.1 08-Oct-1995  thorpej branches: 1.1.1;
Initial revision
 1.1.1.1 08-Oct-1995  thorpej FFS debugging/editing tool, from John Kohl.
 1.17.14.1 18-May-2008  yamt sync with head.
 1.17.12.3 17-Jan-2009  mjf Sync with HEAD.
 1.17.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.17.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.18.4.1 18-Jul-2008  simonb Sync with head.
 1.18.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.52.1 31-May-2021  cjep sync with head
 1.9 23-Jan-2016  christos Define _KERNTYPES for things that need it.
 1.8 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.7 20-Jan-2005  xtraeme Remove main() prototype; WARNS=3
 1.6 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.5 16-Nov-2001  lukem change -F semantics to treat the argument as a file system image; open it
`as-is' without attempting to determine the device name with opendisk(3),
and don't attempt to read a disklabel.
 1.4 03-Aug-2001  lukem WARNS=2
 1.3 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.2 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.1 07-Mar-1997  christos First pass at fsirand. Needs /dev/random to do things right.
 1.11 28-Mar-2024  riastradh fsirand(8): Fix security claims.

PR misc/58063
 1.10 11-Sep-2016  sevan branches: 1.10.16; 1.10.24;
Document author and the version fsirand appeared.
Bump date.
 1.9 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.8 14-Jun-2005  peter branches: 1.8.20; 1.8.22;
Remove the SECURITY CONSIDERATIONS section which stated that the
implementation didn't used a good random generator, this is not true
anymore since arc4random(3) is used these days.

Pointed out by Jeff Ito in PR/30321
 1.7 16-Nov-2001  lukem change -F semantics to treat the argument as a file system image; open it
`as-is' without attempting to determine the device name with opendisk(3),
and don't attempt to read a disklabel.
 1.6 19-Aug-2001  lukem - add -F - manipulate a file system image in a regular file (instead of
a special device).
- implement statistics printing on SIGINFO
 1.5 05-Jun-2001  wiz Remove some trailing whitespace.
 1.4 04-Feb-2001  christos fix nested extern. While I am here assign copyright to TNF.
 1.3 08-Jun-1998  lukem Implement a new manual page category ``SECURITY CONSIDERATIONS''
(suggested by mycroft)
 1.2 14-Sep-1997  lukem * cleanup for WARNS=1
* prefix hex numbers with '0x'
 1.1 07-Mar-1997  christos First pass at fsirand. Needs /dev/random to do things right.
 1.8.22.1 18-May-2008  yamt sync with head.
 1.8.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.10.24.1 24-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #807):

usr.sbin/mountd/exports.5: revision 1.33
usr.sbin/mountd/exports.5: revision 1.34
sbin/fsirand/fsirand.8: revision 1.11
usr.sbin/mountd/exports.5: revision 1.35
usr.sbin/mountd/exports.5: revision 1.36
usr.sbin/mountd/mountd.8: revision 1.43
usr.sbin/mountd/exports.5: revision 1.37
usr.sbin/mountd/exports.5: revision 1.38

exports(5), mountd(8): First pass at clarifying export semantics.

The exports(5) man page is full of walls of turgid prose that should
be itemized lists with syntax templates, and I'm itching to rewrite
it, but let's get the security-relevant warnings out of the way
first.
PR misc/58063

exports(5): Revert warning about `-ro' on read/write file systems.

Looks like the nfs server does enforce that after all, in spite of
the rather oblique commentary in the BUGS section about export
options being tied to local mount point options with which they must
be noncontradictory.

And there's no reason in principle it shouldn't enforce this -- it
just need to block various file system _operations_, rather than the
subtree issue where the criteria for evaluating whether operations
are allowed on particular _file handles_ are too painful to
contemplate.

PR misc/58063

exports(5): Substantially rewrite for clarity.

Hope this is an improvement over the turgid paragraphs all about
first/second/third cases of everything.
PR misc/58063

exports(5): improve mark up

fsirand(8): Fix security claims.
PR misc/58063
pick some nits

exports(5): Tiny punctuation fix in man page.
 1.10.16.1 24-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1882):

usr.sbin/mountd/exports.5: revision 1.33
usr.sbin/mountd/exports.5: revision 1.34
sbin/fsirand/fsirand.8: revision 1.11
usr.sbin/mountd/exports.5: revision 1.35
usr.sbin/mountd/exports.5: revision 1.36
usr.sbin/mountd/mountd.8: revision 1.43
usr.sbin/mountd/exports.5: revision 1.37
usr.sbin/mountd/exports.5: revision 1.38

exports(5), mountd(8): First pass at clarifying export semantics.

The exports(5) man page is full of walls of turgid prose that should
be itemized lists with syntax templates, and I'm itching to rewrite
it, but let's get the security-relevant warnings out of the way
first.
PR misc/58063

exports(5): Revert warning about `-ro' on read/write file systems.

Looks like the nfs server does enforce that after all, in spite of
the rather oblique commentary in the BUGS section about export
options being tied to local mount point options with which they must
be noncontradictory.

And there's no reason in principle it shouldn't enforce this -- it
just need to block various file system _operations_, rather than the
subtree issue where the criteria for evaluating whether operations
are allowed on particular _file handles_ are too painful to
contemplate.

PR misc/58063

exports(5): Substantially rewrite for clarity.

Hope this is an improvement over the turgid paragraphs all about
first/second/third cases of everything.
PR misc/58063

exports(5): improve mark up

fsirand(8): Fix security claims.
PR misc/58063
pick some nits

exports(5): Tiny punctuation fix in man page.
 1.33 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.32 19-Oct-2013  christos fix unused variable warnings.
 1.31 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.30 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.29 27-Aug-2011  joerg branches: 1.29.2; 1.29.8;
static + __dead
 1.28 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.27 08-Feb-2007  drochner branches: 1.27.12; 1.27.14;
include <signal.h> where signal(3) is used
 1.26 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.25 20-Jan-2005  xtraeme Remove main() prototype; WARNS=3
 1.24 21-Mar-2004  dsl Don't use 1st alternate superblock at offset 64k for ffsv1.
Fixes part of PR kern/24809
 1.23 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.22 06-Sep-2003  itojun use arc4random
 1.21 17-Apr-2003  lukem clear errno before strto(u)l() if we're going to test it for ERANGE afterwards
 1.20 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.19 08-Jan-2002  lukem need ufs/ufs/dinode.h for ufs/ffs/fs.h
 1.18 16-Nov-2001  lukem this doesn't need <ufs/ufs/inode.h>
 1.17 16-Nov-2001  lukem change -F semantics to treat the argument as a file system image; open it
`as-is' without attempting to determine the device name with opendisk(3),
and don't attempt to read a disklabel.
 1.16 26-Oct-2001  lukem remove #include <ufs/ufs/quota.h> where it was just to appease
<ufs/ufs/inode.h>, since the latter now includes the former. leave the former
in source that obviously uses specific bits of it (for completeness.)
 1.15 19-Aug-2001  lukem - add -F - manipulate a file system image in a regular file (instead of
a special device).
- implement statistics printing on SIGINFO
 1.14 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.13 29-Jul-2001  lukem ansi knf, WARNS=2
 1.12 19-Feb-2001  cgd convert to use getprogname()
 1.11 04-Feb-2001  christos fix nested extern. While I am here assign copyright to TNF.
 1.10 23-Oct-1998  thorpej branches: 1.10.10;
Use DINODE_SIZE instead of sizeof(struct dinode) and/or pointer arithmetic.
 1.9 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.8 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.7 20-Sep-1997  christos Work around ggc-2.7.2 off_t initialization bug on m68k.
 1.6 14-Sep-1997  lukem * cleanup for WARNS=1
* prefix hex numbers with '0x'
 1.5 06-Jul-1997  mycroft Fix type error that caused offset to wrap at 4GB.
 1.4 24-Jun-1997  kleink * add `-x' option to usage().
* `=' vs. `==' in a comparison.
 1.3 14-Mar-1997  cgd string.h for protos
 1.2 08-Mar-1997  cgd Fix NetBSD RCS ID tag
 1.1 07-Mar-1997  christos First pass at fsirand. Needs /dev/random to do things right.
 1.10.10.1 25-Nov-2001  he Pull up revision 1.14 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.27.14.1 18-May-2008  yamt sync with head.
 1.27.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.29.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29.8.1 23-Jun-2013  tls resync from head
 1.29.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19 25-Jun-2019  jnemeth Add an "uuid" command to generate a new UUID for a portion. The
primary intention is for use for after cloning disks to prevent
collisions.
 1.18 03-Dec-2015  christos branches: 1.18.16;
WARNS=6
 1.17 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.16 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.15 29-Nov-2015  christos Remove getdisksize support; we either have the ioctls (current/-7) or we
don't (non-netbsd-current/7+tools).
 1.14 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.13 29-Dec-2014  christos Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.12 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.11 29-Sep-2014  christos more toolification
 1.10 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.9 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.8 10-Aug-2014  jnemeth branches: 1.8.2;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.7 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.6 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.5 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.4 06-Jan-2011  jakllsch branches: 1.4.6; 1.4.12;
Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.3 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.2 15-Oct-2006  christos branches: 1.2.28;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.4.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.8.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.18.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.46 23-Feb-2025  christos Pass some lint.
 1.45 02-Nov-2024  kre PR bin/58806 Never create a partition with a null guid

If a new partition entry being added doesn't already have a guid,
make one for it.
 1.44 03-Jul-2018  jnemeth branches: 1.44.2; 1.44.10; 1.44.12;
Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.43 29-Dec-2015  christos branches: 1.43.14; 1.43.16;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.42 03-Dec-2015  christos CID 1341561: Argument memory leak
 1.41 03-Dec-2015  christos CID 1341560: Free arg.
 1.40 03-Dec-2015  christos CID 1341548: Check error returns
 1.39 03-Dec-2015  christos WARNS=6
 1.38 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.37 02-Dec-2015  jnemeth hrmm...

i386devel: {245} ./gpt add -b 1000 -s 1000 disk
Segmentation fault (core dumped)

Where's my flyswatter? .......zzzzzzzap
 1.36 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.35 02-Dec-2015  christos - write a function to set the entity, so that we don't reset to guid.
- entry 0 means create entry.
 1.34 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.33 01-Dec-2015  christos refactor more duplicated code.
 1.32 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.31 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.30 01-Dec-2015  christos - use gpt_msg to print informational messages (perhaps these should be printed
only with -v)
- don't print any messages with gpt_msg if quiet
- print a message if we didn't reconfigure the wedges
 1.29 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.28 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.27 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.26 30-Sep-2014  christos remove compat defines.
 1.25 29-Sep-2014  christos minor toolification: need libprop...
 1.24 10-Dec-2013  jnemeth branches: 1.24.4;
Explicitly state which partition was added/modified.
 1.23 08-Dec-2013  jnemeth For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before)
otherwise size is in bytes.
 1.22 06-Dec-2013  jnemeth Don't attempt to create/resize an unaligned partition if the attempt
to create/resize an aligned one failed. This simplifies the code
and prevents surprises. If the user wants an unaligned partition
in the case where an aligned one fails, they can simply retry the
command without the "-a" option. This change was requested by
wiz@, and after some thought I agree with it.
 1.21 28-Nov-2013  jnemeth when calling dehumanize_number() make sure the resulting number is >= 1
 1.20 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.19 22-Nov-2013  jnemeth change the "-b blocknr" parameter to accept a "human number"
 1.18 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.17 19-Nov-2013  jnemeth delete an errant where it is obvious what the code is doing
 1.16 19-Nov-2013  jnemeth When setting a label on the new partition, be sure to set the label
in the secondary partition table as well.
 1.15 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.14 26-May-2013  wiz Instead of 'no space', say 'not enough space' in error message.
 1.13 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.12 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.11 27-Aug-2011  joerg branches: 1.11.2; 1.11.8;
Use __dead
 1.10 06-Jan-2011  riz Clarify the 'dkctl addwedge' usage message after creating a GPT
partition.
 1.9 06-Jan-2011  jakllsch UFS is called FFS in the NetBSD case. Display as such and accept as input.
 1.8 07-Feb-2009  uebayasi Let 'gpt add' suggest a collect device name so that opendisk(3) called by
dkctl(8) succeeds.
 1.7 07-Feb-2009  uebayasi Make manual and usage consistent. No functional changes.
 1.6 28-Dec-2007  riz As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.5 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.4 16-Feb-2007  riz branches: 1.4.4; 1.4.6;
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3 17-Oct-2006  he branches: 1.3.2;
Add initialization of a variable where gcc for some archs thinks
that it may be used un-initialized. From cursory inspection it is
not obvious that gcc is wrong.
 1.2 15-Oct-2006  christos Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.2.3 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.6
src/sbin/gpt/gpt.c 1.7
src/sbin/gpt/show.c 1.4
src/sys/dev/dkwedge/dkwedge_gpt.c 1.7
src/sys/sys/disk.h 1.47
src/sys/sys/disklabel_gpt.h 1.4
(requested by riz in ticket #1119).

As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.3.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.3.2.1 20-Feb-2007  tron branches: 1.3.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.4.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.1 09-Jan-2008  matt sync with HEAD
 1.11.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.8.1 23-Jun-2013  tls resync from head
 1.11.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.24.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.24.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.43.16.1 10-Jun-2019  christos Sync with HEAD
 1.43.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.44.12.1 02-Aug-2025  perseant Sync with HEAD
 1.44.10.1 17-Nov-2024  martin Pull up following revision(s) (requested by kre in ticket #1005):

sbin/gpt/add.c: revision 1.45

PR bin/58806 Never create a partition with a null guid

If a new partition entry being added doesn't already have a guid,
make one for it.
 1.44.2.1 17-Nov-2024  martin Pull up following revision(s) (requested by kre in ticket #1920):

sbin/gpt/add.c: revision 1.45

PR bin/58806 Never create a partition with a null guid

If a new partition entry being added doesn't already have a guid,
make one for it.
 1.21 23-Feb-2025  christos Pass some lint.
 1.20 08-Jun-2020  thorpej branches: 1.20.8;
When we add "entries", "index", and "sector_size" values to the dictionary,
add them as signed valaues, rather than unsigned (which is how we keep them
in memory). This causes them be serialized in base-10 (rather than base-16,
which is the default for unsigned). This behavior is documented in
prop_number(3). Fixes t_gpt::backup_2part unit test.
 1.19 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.18 07-Sep-2017  christos use __arraycount
 1.17 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.16 03-Dec-2015  christos branches: 1.16.8;
CID 1341558: Fix proplib memory leaks
 1.15 03-Dec-2015  christos compare to stdout, thanks kre
 1.14 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.13 02-Dec-2015  christos Allow backup and restore to operate on files.
 1.12 02-Dec-2015  christos split out into smaller functions.
 1.11 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.10 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.9 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.8 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.7 30-Sep-2014  christos remove compat defines.
 1.6 29-Sep-2014  christos more toolification changes
 1.5 29-Sep-2014  christos more toolification
 1.4 29-Sep-2014  christos minor toolification: need libprop...
 1.3 10-Sep-2014  jnemeth - dump all partitions, not just ones that are in use
- while here, squash a memory leak

It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
 1.2 09-Sep-2014  jnemeth - record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
 1.1 19-Dec-2013  jnemeth branches: 1.1.4; 1.1.6; 1.1.8;
Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 19-Dec-2013  tls file backup.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.1.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.1.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.1.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.1 19-Dec-2013  yamt file backup.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.16.8.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.20.8.1 02-Aug-2025  perseant Sync with HEAD
 1.34 23-Feb-2025  christos Pass some lint.
 1.33 13-Sep-2024  mlelstv Don't use kernel type daddr_t for disk offsets.
 1.32 20-Jun-2019  martin branches: 1.32.2; 1.32.10; 1.32.12;
When biosboot is used on an existing wedge and we are switching to
the gpt of the parent device, do not pass the size of the wedge to
gpt_open, it certainly is smaller than the whole device.
Fixes bin/54312.
 1.31 04-Apr-2019  martin Allow specifying the partition via -b startsec for the biosboot cmd.
 1.30 07-Sep-2017  christos branches: 1.30.4;
use __arraycount
 1.29 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.28 03-Jul-2017  mrg only do wedges if not the tools version. fixes build on netbsd-4,
and any other place that might have the same ioctl name while having
something not quite right (in this case, cpuid_t in headers not
working properly..)

XXX: pullup-8
 1.27 16-Feb-2017  christos branches: 1.27.4;
Add -T timestamp for reproducible builds.
 1.26 09-Jun-2016  christos branches: 1.26.2; 1.26.4;
Rename 'a' to set the active PMBR flag to 'A'
 1.25 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.24 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.23 03-Dec-2015  christos more leak
 1.22 03-Dec-2015  christos WARNS=6
 1.21 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.20 02-Dec-2015  christos don't advertise stuff we don't support.
 1.19 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.18 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.17 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.16 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.15 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.14 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.13 02-Oct-2014  joerg Fix tools build on !NetBSD.
 1.12 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.11 29-Sep-2014  christos more toolification
 1.10 29-Sep-2014  christos minor toolification: need libprop...
 1.9 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.8 26-Sep-2014  jnemeth no C99isms in tool code
 1.7 27-Nov-2013  jnemeth branches: 1.7.4;
Remove FreeBSD specific code as per message to tech-userlevel.
 1.6 13-Apr-2013  jakllsch drop trailing whitespace
 1.5 27-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 17-Aug-2011  martin Fix sign compare bugs
 1.3 17-Aug-2011  jakllsch Ajdust bootcode file name from mbr_gpt to gptmbr.bin.
 1.2 17-Aug-2011  jakllsch Switch 'gpt biosboot' to support T13 EDD-4 annex A GPT hybrid MBR instead
of a home-grown MBR/VBR hand off protocol.

'biosboot' now will set the legacy BIOS boot flag instead of patching a
GUID into the MBR.
 1.1 06-Jan-2011  jakllsch Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 23-Jun-2013  tls resync from head
 1.5.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.7.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.26.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.26.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.27.4.2 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.27.4.1 05-Jul-2017  snj Pull up following revision(s) (requested by mrg in ticket #93):
sbin/gpt/biosboot.c: revision 1.28
only do wedges if not the tools version. fixes build on netbsd-4,
and any other place that might have the same ioctl name while having
something not quite right (in this case, cpuid_t in headers not
working properly..)
 1.30.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.30.4.1 10-Jun-2019  christos Sync with HEAD
 1.32.12.1 02-Aug-2025  perseant Sync with HEAD
 1.32.10.1 02-Oct-2024  martin Pull up following revision(s) (requested by lloyd in ticket #911):

sbin/gpt/biosboot.c: revision 1.33

Don't use kernel type daddr_t for disk offsets.
 1.32.2.1 02-Oct-2024  martin Pull up following revision(s) (requested by lloyd in ticket #1889):

sbin/gpt/biosboot.c: revision 1.33

Don't use kernel type daddr_t for disk offsets.
 1.24 23-Feb-2025  christos Pass some lint.
 1.23 23-Sep-2016  christos branches: 1.23.26;
PR/51497: Clare: Allow gpt -p <n> create to work.
 1.22 09-Jun-2016  christos branches: 1.22.2;
Rename 'a' to set the active PMBR flag to 'A'
 1.21 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.20 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.19 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.18 03-Dec-2015  christos WARNS=6
 1.17 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.16 01-Dec-2015  christos refactor more duplicated code.
 1.15 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.14 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.13 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.12 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.11 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.10 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.9 30-Sep-2014  christos remove compat defines.
 1.8 29-Sep-2014  christos minor toolification: need libprop...
 1.7 04-Dec-2013  jakllsch branches: 1.7.4;
Use MBR_PTYPE_ defines from <sys/bootblock.h>.
 1.6 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.5 27-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 06-Jan-2011  jakllsch Use less bogus CHS addresses in PMBR.
With the ending head set at 0xff one machine I have will never leave
the initial startup screen if such a disk is present. Additionally,
Wikipedia suggests without citiation that 254 is the maximium allowable
value for the head, and this seems to be the case.
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 23-Jun-2013  tls resync from head
 1.5.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.7.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.22.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.23.26.1 02-Aug-2025  perseant Sync with HEAD
 1.15 23-Feb-2025  christos Pass some lint.
 1.14 20-Nov-2022  mlelstv branches: 1.14.4;
Fix destroying and moving GPT header also for truncated/extended
images.
 1.13 16-Oct-2019  jnemeth Do the 'dkctl makewedges' dance to drop any wedges assoicated the
destroyed GPT.
 1.12 04-Apr-2019  martin PR bin/54088: make "destroy" remove the protective MBR too.
We could make this optional if someone comes up with a good reason
to leave it intact.
 1.11 04-Apr-2019  martin Ignore -f with the "destroy" command completely (it was effectively
ignored already, so no functional change). Leave it as valid option
for compatibility.
 1.10 03-Dec-2015  christos branches: 1.10.16;
eliminate static globals so that commands can be re-used.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 29-Sep-2014  christos more toolification
 1.5 29-Sep-2014  christos minor toolification: need libprop...
 1.4 27-Aug-2011  joerg branches: 1.4.20;
Use __dead
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.4.20.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.4.20.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.10.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10.16.1 10-Jun-2019  christos Sync with HEAD
 1.14.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 29-Nov-2015  christos Remove getdisksize support; we either have the ioctls (current/-7) or we
don't (non-netbsd-current/7+tools).
 1.1 29-Dec-2014  christos branches: 1.1.2;
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.1.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.1.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.1.2.1 29-Dec-2014  snj file drvctl.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.86 09-Feb-2025  pgoyette Minor cleanups.
 1.85 12-Jan-2025  christos Add missing "to" (Anon Ymous)
 1.84 04-Nov-2024  christos Additions to guid printing and an option to print start/size in hex
(from Anon Ymous)
 1.83 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.82 10-Jun-2024  kre branches: 1.82.2;

Revert unintended commit.
 1.81 10-Jun-2024  kre Note need to deal with old libarchive.so files in cdrom images when doing
an update build.
 1.80 07-Nov-2023  gutteridge gpt.8: fix grammar in a sentence
 1.79 31-Oct-2023  martin Apply patch from Thierry Laronde: add missing suffixes for size values
and clarify that they are case independant.
 1.78 15-Jul-2023  gutteridge gpt.8: fix some grammar

(The BUGS section seems perhaps a little outdated in its warnings of
potential incompatible changes.)
 1.77 15-Jul-2023  gutteridge gpt.8: drop cross-reference to cvs(1)

It's no more useful to reference cvs(1) than, say, openssl(1), and
should be self-evident, anyway.
 1.76 07-Apr-2022  kre branches: 1.76.2;

Note that biosboot without -A clears the PMBR "active" flag.
While here, fix some grammar and make the selection options
for biosboot a little clearer.

Ride nia@'s Dd bump.
 1.75 07-Apr-2022  nia gpt.8: Clarify that "windows" partition types are also used for FAT32
("msdos" in NetBSD terms), and UDF partitions. Use the same name as
Wikipedia, "Microsoft basic data".
 1.74 27-Jul-2020  christos catch up with source rename of fbsd-zfs -> zfs
 1.73 24-May-2020  wiz Fix typo in macro. Sort option descriptions.
 1.72 24-May-2020  jmcneill Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.71 24-May-2020  jmcneill Exit gracefully when auto-expanding a partition and it is already the
correct size. Add a -q flag to "resize" and "resizedisk" commands to skip
printing warnings in the already resize paths.
 1.70 26-Jul-2019  martin Remove outdated note about sysinst restrictions
 1.69 25-Jun-2019  jnemeth Add an "uuid" command to generate a new UUID for a portion. The
primary intention is for use for after cloning disks to prevent
collisions.
 1.68 04-Apr-2019  martin Allow specifying the partition via -b startsec for the biosboot cmd.
 1.67 26-Mar-2019  martin Allow -b to specify a partition for "gpt unset" as well.
 1.66 25-Mar-2019  martin Allow -b startsec to specify the partition to change for the set subcommand
as well.
Add another option, -N, as a quick way to remove all attributes.
 1.65 24-Mar-2019  martin Make the "show" subcommand accept -b startsec to identify a partition
(very usefull for scripts and other robotic callers).
 1.64 24-Mar-2019  martin Add support for specifying the partition to resize via -b startsec
(similar to label and other subcommands). Do not fully add gpt_find
functionality here, as resizing multiple partitions in one go does not
make sense.
 1.63 01-May-2018  kre branches: 1.63.2;

Spello. (it is "existence").

ispell also says that we should s/parseable/parsable/ but I'm
not sure about that one, so I left it.

I also left a correct spelling that no-one has bothered to mangle!
 1.62 01-May-2018  wiz Bump date for new EXIT STATUS section.
 1.61 01-May-2018  wiz Sort sections.
 1.60 01-May-2018  martin Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
 1.59 11-Apr-2018  mrg add information about how to boot from gpt. mostly taken from the wiki.
 1.58 19-Mar-2018  mlelstv Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.57 15-Jan-2018  sborrill branches: 1.57.2;
Explain what suffixes are accepted when specifying a size.
 1.56 03-Oct-2017  mlelstv clarify that alignment is the number of bytes to align to.
 1.55 05-Aug-2017  wiz Use Fx/Nx.
 1.54 04-Aug-2017  kre Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...
 1.53 03-Aug-2017  msaitoh Add note about bootme flag:

The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.
 1.52 16-Feb-2017  christos branches: 1.52.4;
Add -T timestamp for reproducible builds.
 1.51 27-Jan-2017  abhinav Fix spelling of partition.
 1.50 01-Nov-2016  jdolecek branches: 1.50.2;
remove dup line
 1.49 11-Sep-2016  sevan Document the version gpt first appeared.
Replace contractions.
Bump date.
 1.48 09-Jun-2016  christos branches: 1.48.2;
Rename 'a' to set the active PMBR flag to 'A'
 1.47 09-Jun-2016  kre Fix rendering of biosboot command synopsis.
 1.46 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.45 25-Dec-2015  wiz Simplify usage for gpt show.
 1.44 25-Dec-2015  martin Add a -a flag to the show command, so we can display the full GPT with
all information in one go.
 1.43 06-Dec-2015  wiz Bump date for previous.
Remove trailing whitespace.
 1.42 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.41 02-Dec-2015  christos Allow backup and restore to operate on files.
 1.40 01-Dec-2015  christos Reflect reality better; we don't handle multiple devices anymore, and
the partitions option is only for the commands that support it.
 1.39 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.38 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.37 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.36 06-Dec-2014  wiz Bump date for previous.
 1.35 06-Dec-2014  mlelstv Add some more common partition types.
 1.34 04-Oct-2014  wiz Remove trailing whitespace.
 1.33 04-Oct-2014  christos Allow specifying sector and media size on the command line.
 1.32 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.31 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.30 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.29 20-Sep-2014  jnemeth document the new restore subcommand
 1.28 19-Dec-2013  wiz branches: 1.28.4;
Bump date for previous.
 1.27 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.26 09-Dec-2013  wiz Fix typo.
 1.25 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.24 09-Dec-2013  jnemeth For the "show -i <entry>" subcommand, print Start and Size both in
terms of number of sectors and bytes.
 1.23 08-Dec-2013  jnemeth For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before)
otherwise size is in bytes.
 1.22 06-Dec-2013  jnemeth Don't attempt to create/resize an unaligned partition if the attempt
to create/resize an aligned one failed. This simplifies the code
and prevents surprises. If the user wants an unaligned partition
in the case where an aligned one fails, they can simply retry the
command without the "-a" option. This change was requested by
wiz@, and after some thought I agree with it.
 1.21 30-Nov-2013  jnemeth Add two new options:

-g which shows the GUID for a partition
-i which shows all the gory details for a particular option

XXX the output format of -i is subject to change
 1.20 22-Nov-2013  jnemeth bump date
 1.19 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.18 20-Nov-2013  wiz shrunk.
 1.17 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.16 19-Nov-2013  jnemeth update synopsis for add subcommand
 1.15 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.14 24-Oct-2013  jnemeth - markup
- typo; the label command labels partitions, not remove them
- migrate -s isn't applicable to NetBSD
- add information about the space required for migration
- add a "gpt show -l" example
 1.13 20-Oct-2013  jnemeth revert typo fix; teach me to blindly take changes from upstream
 1.12 19-Oct-2013  jnemeth type fix: accommodate. -> accomodate.
 1.11 02-May-2012  jakllsch branches: 1.11.2;
Bump date to date of previous change.
 1.10 09-Mar-2012  drochner fix a path
 1.9 11-Nov-2011  wiz branches: 1.9.2;
Add an EXAMPLE section showing how to add a swap file system using gpt. Bump date.
 1.8 19-Sep-2011  wiz branches: 1.8.2;
Minimally document gpt recover. Bump date.
 1.7 27-Mar-2011  jym Document biosboot. Xref boot(8) and installboot(8).
 1.6 09-Feb-2011  schnoebe List all the aliases supported for GPT partition types.
 1.5 11-Mar-2009  joerg branches: 1.5.2;
Don't workaround ancient macro argument limit with .Xo/.Xc.
 1.4 09-Mar-2009  joerg Fix preamble to match order set out by mdoc(7). Discussed with wiz.
 1.3 24-Nov-2006  christos branches: 1.3.28;
fix spelling of accommodate; from Zapher.
 1.2 17-Oct-2006  wiz Serial comma. Add RCS Id. Remove superfluous quotes.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.5.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.8.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.2.2 23-May-2012  yamt sync with head.
 1.8.2.1 17-Apr-2012  yamt sync with head
 1.9.2.1 07-May-2012  riz Pull up following revision(s) (requested by jakllsch in ticket #210):
sbin/gpt/gpt.8: revision 1.10
sbin/gpt/gpt.8: revision 1.11
fix a path
Bump date to date of previous change.
 1.11.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.28.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.48.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.48.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.50.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.52.4.3 07-May-2018  snj Pull up following revision(s) (requested by martin in ticket #797):
sbin/gpt/gpt.8: 1.60-1.63
sbin/gpt/header.c: 1.9
Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
--
Sort sections.
--
Bump date for new EXIT STATUS section.
--
Spello. (it is "existence").
ispell also says that we should s/parseable/parsable/ but I'm
not sure about that one, so I left it.
I also left a correct spelling that no-one has bothered to mangle!
 1.52.4.2 04-May-2018  martin Pull up following revision(s) (requested by mrg in ticket #785):
sbin/gpt/gpt.c: revision 1.74
sbin/gpt/map.c: revision 1.14
sbin/gpt/gpt.8: revision 1.53
sbin/gpt/gpt.8: revision 1.54
sbin/gpt/gpt.8: revision 1.55
sbin/gpt/gpt.8: revision 1.56
sbin/gpt/gpt.8: revision 1.57
sbin/gpt/gpt.8: revision 1.59

Add note about bootme flag:
The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.

Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...

Use Fx/Nx.

clarify that alignment is the number of bytes to align to.

Explain what suffixes are accepted when specifying a size.
Spelling

add information about how to boot from gpt. mostly taken from the wiki.

if a new map entry doesn't fit, be more verbose about the sizes.
 1.52.4.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.57.2.3 02-May-2018  pgoyette Synch with HEAD
 1.57.2.2 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.57.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.63.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63.2.1 10-Jun-2019  christos Sync with HEAD
 1.76.2.1 02-Nov-2023  sborrill Pull up the following revisions(s) (requested by martin in ticket #441):
sbin/gpt/gpt.8: revision 1.79

Add missing suffixes for size values and clarify that they are
case-independent.
 1.82.2.1 02-Aug-2025  perseant Sync with HEAD
 1.91 23-Feb-2025  christos Pass some lint.
 1.90 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.89 10-Jun-2024  kre branches: 1.89.2;

Revert unintended commit.
 1.88 10-Jun-2024  kre Note need to deal with old libarchive.so files in cdrom images when doing
an update build.
 1.87 13-Dec-2023  mrg avoid use after free. skip the QUIET check already in gpt_warn().
 1.86 11-Dec-2023  mlelstv Be verbose about errors.
 1.85 26-Sep-2023  kre When extracting the attributes (to printable form), avoid simply ignoring
any attribute bits which are unknown, print them as a hex value. This
avoids "Attributes: " for most windows filesystem types, which all seem
to have but 63 set (which is supposed to mean "don't assign a drive letter"
which is akin to "noauto" in fstab - except it is set even on partitions
which do get mounted, so must mean something subtly different).

These upper 16 attribute bits are supposed to be file system type speficic
(in practice, they seem to be common to all filesystem types from one vendor)
but we don't have the info (yet anyway) to treat them like that.

ChromeOS seems to treat some of the bits as bit fields containing numeric
values - add #if 0'd (but compile tested) code to deal with those (maybe,
compile tested - but not execution tested) should someone ever get an
environment where these things occur, and could add the missing definitions
to actually test this.
 1.84 22-Nov-2022  mlelstv Big-Endian fixes.
 1.83 20-Nov-2022  mlelstv Fix destroying and moving GPT header also for truncated/extended
images.
 1.82 24-May-2020  jmcneill Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.81 11-Oct-2019  christos gpt_uuid_parse does not set errno ...
 1.80 25-Jun-2019  jnemeth Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.
 1.79 21-Jun-2019  jnemeth Add a third argument to the "cfn" function that is an argument to
gpt_change_ent(). The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry. It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.
 1.78 20-Jun-2019  martin Do not try to close a NULL gpt. Fixes the core dump part of PR bin/54312
 1.77 27-Jan-2019  martin Fix three MBR extended partition related bugs:
1) when walking an extended MBR chain, do not assign duplicate indices
2) the pointer to the next MBR may be any of the MBR_PTYPE_EXT* variants
3) the ext MBR chain links are relative to the primary extended partition,
unlike the contained partitions which are relative to the extended MBR
block address.
 1.76 14-Oct-2018  mlelstv When changing entries skip those that do not match the -L option.
Should fix PR 53668.
 1.75 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.74 13-Feb-2018  sevan branches: 1.74.2; 1.74.4;
Spelling
 1.73 07-Sep-2017  christos use __arraycount
 1.72 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.71 05-Sep-2017  christos PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
XXX: pullup-8
 1.70 16-Feb-2017  christos branches: 1.70.4;
Add -T timestamp for reproducible builds.
 1.69 24-Sep-2016  christos branches: 1.69.2;
say that you need to destroy it first.
 1.68 09-Jun-2016  christos branches: 1.68.2;
PR/51230: Add the ability to set the active flag in the PMBR.
 1.67 08-Jan-2016  joerg gpt_vwarnx is printf-like.
 1.66 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.65 26-Dec-2015  jnemeth pretty up attribute display a bit
 1.64 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.63 04-Dec-2015  christos Fix resizedisk.
 1.62 04-Dec-2015  christos don't print dkctl message for files
fix typo
 1.61 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.60 03-Dec-2015  christos Add a space.
 1.59 03-Dec-2015  christos WARNS=6
 1.58 02-Dec-2015  christos annotate map additions with non-allocated memory.
 1.57 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.56 02-Dec-2015  christos Always set NOSYNC if regular file, even if we got the size from the command
line.
 1.55 02-Dec-2015  jnemeth - dereferencing NULL is generally bad, found by visual inspection
- automatically set nosync when opening a file to avoid spurious errors
 1.54 02-Dec-2015  christos print the old and the new style usage.
 1.53 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.52 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.51 01-Dec-2015  christos refactor more duplicated code.
 1.50 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.49 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.48 01-Dec-2015  christos - use gpt_msg to print informational messages (perhaps these should be printed
only with -v)
- don't print any messages with gpt_msg if quiet
- print a message if we didn't reconfigure the wedges
 1.47 01-Dec-2015  christos only update the wedge information if it is supported.
 1.46 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.45 29-Nov-2015  christos Do division once
 1.44 29-Nov-2015  christos Only use the ioctl's if we have them.
 1.43 29-Nov-2015  jnemeth fix build breakage for systems that do not have DIOCG{SECTOR,MEDIA}SIZE
 1.42 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.41 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.40 29-Dec-2014  christos Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.39 17-Nov-2014  mlelstv handle constness better
 1.38 17-Nov-2014  mlelstv handle constness
 1.37 17-Nov-2014  mlelstv Report the argument instead of (null) when opendisk fails.
 1.36 04-Oct-2014  christos Allow specifying sector and media size on the command line.
 1.35 02-Oct-2014  joerg Fix tools build on !NetBSD.
 1.34 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.33 30-Sep-2014  christos remove compat defines.
 1.32 29-Sep-2014  christos more toolification
 1.31 29-Sep-2014  christos minor toolification: need libprop...
 1.30 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.29 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.28 10-Aug-2014  jnemeth branches: 1.28.2;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.27 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.26 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.25 04-Dec-2013  jakllsch Use MBR_PTYPE_ defines from <sys/bootblock.h>.
 1.24 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.23 23-Nov-2013  jnemeth Only skip past _PATH_DEV if it is actually present.
 1.22 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.21 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.20 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.19 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.18 18-Jan-2013  jakllsch Now that GPT_ENT_TYPE_LINUX_DATA is diffrent from the Windows one, use it.
 1.17 30-Jul-2012  matt branches: 1.17.2;
Fix a few straggling BE/LE problems.
 1.16 25-Jul-2012  matt Make sure utf-16 strings are written as little endian words.
 1.15 27-Aug-2011  joerg branches: 1.15.2; 1.15.4;
Use __dead
 1.14 06-Jan-2011  jakllsch UFS is called FFS in the NetBSD case. Display as such and accept as input.
 1.13 06-Jan-2011  jakllsch Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.12 02-Apr-2010  christos fix printf format.
 1.11 02-Apr-2010  christos PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
 1.10 20-Feb-2010  mlelstv Initialize device_name before opendisk to avoid
"unable to open device '(null)'" error messages
when the opendisk fails.
 1.9 07-Feb-2009  uebayasi Let 'gpt add' suggest a collect device name so that opendisk(3) called by
dkctl(8) succeeds.
 1.8 24-Feb-2008  christos branches: 1.8.6;
PR/38094: Robert Millan: support "BIOS Boot" partition type in gpt(8)
 1.7 28-Dec-2007  riz branches: 1.7.2; 1.7.4;
As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.6 19-Dec-2007  dogcow Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.4 11-Jun-2007  dyoung branches: 1.4.4; 1.4.6;
Produce more useful error messages.
 1.3 16-Feb-2007  riz Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2 15-Oct-2006  christos branches: 1.2.2;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.2.3 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.6
src/sbin/gpt/gpt.c 1.7
src/sbin/gpt/show.c 1.4
src/sys/dev/dkwedge/dkwedge_gpt.c 1.7
src/sys/sys/disk.h 1.47
src/sys/sys/disklabel_gpt.h 1.4
(requested by riz in ticket #1119).

As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.2.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.2.2.1 20-Feb-2007  tron branches: 1.2.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.4.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.2 23-Mar-2008  matt sync with HEAD
 1.4.4.1 09-Jan-2008  matt sync with HEAD
 1.7.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.7.2.1 24-Mar-2008  keiichi sync with head.
 1.8.6.2 24-Nov-2010  riz Pull up following revision(s) (requested by christos in ticket #1464):
sbin/gpt/gpt.c: revision 1.11
sbin/gpt/gpt.c: revision 1.12
PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
fix printf format.
 1.8.6.1 21-Nov-2010  riz Pull up following revision(s) (requested by christos in ticket #1464):
sbin/gpt/gpt.c: revision 1.11
PR/43105: Peter Kerwien: Destroying a GPT partition with dd will cause gpt
destroy / create to fail. When reading the GPT label from the end of the disk
ignore errors if the GPT label at the beginning of the disk was not found.
 1.15.4.1 26-Oct-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #619):
sbin/gpt/gpt.c: revision 1.16-1.17

Endianness fixes.
 1.15.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.2.2 23-Jan-2013  yamt sync with head
 1.15.2.1 30-Oct-2012  yamt sync with head
 1.17.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.2.2 23-Jun-2013  tls resync from head
 1.17.2.1 25-Feb-2013  tls resync with head
 1.28.2.3 15-Oct-2018  sborrill Pull up the following revisions(s) (requested by mlelstv in ticket #1643):
sbin/gpt/gpt.c: revision 1.76

When changing entries skip those that do not match the -L option.
Should fix PR 53668.
 1.28.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.28.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.68.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.68.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.69.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.70.4.3 15-Oct-2018  sborrill Pull up the following revisions(s) (requested by mlelstv in ticket #1063):
sbin/gpt/gpt.c: revision 1.76

When changing entries, skip those that do not match the -L option.
Should fix PR 53668.
 1.70.4.2 04-May-2018  martin Pull up following revision(s) (requested by mrg in ticket #785):
sbin/gpt/gpt.c: revision 1.74
sbin/gpt/map.c: revision 1.14
sbin/gpt/gpt.8: revision 1.53
sbin/gpt/gpt.8: revision 1.54
sbin/gpt/gpt.8: revision 1.55
sbin/gpt/gpt.8: revision 1.56
sbin/gpt/gpt.8: revision 1.57
sbin/gpt/gpt.8: revision 1.59

Add note about bootme flag:
The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.

Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...

Use Fx/Nx.

clarify that alignment is the number of bytes to align to.

Explain what suffixes are accepted when specifying a size.
Spelling

add information about how to boot from gpt. mostly taken from the wiki.

if a new map entry doesn't fit, be more verbose about the sizes.
 1.70.4.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.74.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.74.4.1 10-Jun-2019  christos Sync with HEAD
 1.74.2.2 20-Oct-2018  pgoyette Sync with head
 1.74.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.89.2.1 02-Aug-2025  perseant Sync with HEAD
 1.45 23-Feb-2025  christos Pass some lint.
 1.44 20-Nov-2022  mlelstv branches: 1.44.4;
Fix destroying and moving GPT header also for truncated/extended
images.
 1.43 16-Jul-2022  mlelstv Whitespace
 1.42 24-May-2020  jmcneill Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.41 30-Jun-2019  sevan Add rcsid
 1.40 25-Jun-2019  jnemeth Add gpt_change_hdr() similar to gpt_change_ent() for changing
arbitrary header fields.
 1.39 21-Jun-2019  jnemeth Add a third argument to the "cfn" function that is an argument to
gpt_change_ent(). The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry. It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.
 1.38 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.37 19-Mar-2018  mlelstv branches: 1.37.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.36 06-Sep-2017  christos branches: 1.36.2;
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.35 16-Feb-2017  christos branches: 1.35.4;
allow 0 timestamp
 1.34 16-Feb-2017  christos Add -T timestamp for reproducible builds.
 1.33 09-Jun-2016  christos branches: 1.33.2; 1.33.4;
PR/51230: Add the ability to set the active flag in the PMBR.
 1.32 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.31 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.30 04-Dec-2015  christos Fix resizedisk.
 1.29 04-Dec-2015  christos don't print dkctl message for files
fix typo
 1.28 03-Dec-2015  christos WARNS=6
 1.27 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.26 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.25 01-Dec-2015  christos refactor more duplicated code.
 1.24 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.23 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.22 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.21 29-Nov-2015  christos Remove getdisksize support; we either have the ioctls (current/-7) or we
don't (non-netbsd-current/7+tools).
 1.20 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.19 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.18 29-Dec-2014  christos Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.17 17-Nov-2014  mlelstv handle constness better
 1.16 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.15 30-Sep-2014  christos remove compat defines.
 1.14 29-Sep-2014  christos more toolification changes
 1.13 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.12 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.11 10-Aug-2014  jnemeth branches: 1.11.2;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.10 19-Dec-2013  jnemeth Add the backup subcommand. It dumps the contents of the partition
tables as a plist, which is readable by the restore subcommand.

XXX restore subcommand forthcoming
 1.9 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.8 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.7 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.6 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.5 06-Jan-2011  jakllsch branches: 1.5.6; 1.5.12;
Support booting from GPT-partioned disks on PC-BIOS-compatible systems.

Much of the work in this commit was done by Mike Volokhov during GSoC 2009.
 1.4 07-Feb-2009  uebayasi Let 'gpt add' suggest a collect device name so that opendisk(3) called by
dkctl(8) succeeds.
 1.3 12-Nov-2008  thorpej Don't use sizeof(struct gpt_hdr). It will pad the structure on x86-64,
which causes some systems to reject the GPT.

kern/38997
 1.2 15-Oct-2006  christos branches: 1.2.18; 1.2.26;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.26.1 26-Jan-2009  snj Pull up following revision(s) (requested by jakllsch in ticket #311):
sbin/gpt/gpt.h: revision 1.3
sys/sys/disklabel_gpt.h: revision 1.7
Don't use sizeof(struct gpt_hdr). It will pad the structure on x86-64,
which causes some systems to reject the GPT.
kern/38997
 1.2.18.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.12.1 23-Jun-2013  tls resync from head
 1.5.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.11.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.33.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.33.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.35.4.2 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.35.4.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.36.2.2 28-Jul-2018  pgoyette Sync with HEAD
 1.36.2.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.37.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.37.2.1 10-Jun-2019  christos Sync with HEAD
 1.44.4.1 02-Aug-2025  perseant Sync with HEAD
 1.4 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.3 30-Jun-2019  sevan branches: 1.3.12;
Add rcsid
 1.2 16-Feb-2017  christos branches: 1.2.12; 1.2.14;
Add -T timestamp for reproducible builds.
 1.1 01-Dec-2015  christos branches: 1.1.2; 1.1.4;
Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.1.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.14.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.2.14.1 16-Feb-2017  martin file gpt_private.h was added on branch netbsd-7 on 2018-08-13 16:12:12 +0000
 1.2.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.12.1 02-Aug-2025  perseant Sync with HEAD
 1.26 11-Oct-2025  thorpej Add a couple of GPT partition type GUIDs one might encounter when
fiddling around with RISC-V systems (Linux XBOOTLDR, SiFive BBL).
 1.25 23-Feb-2025  christos Pass some lint.
 1.24 18-Dec-2024  andvar s/reproducable/reproducible/ in comment.
 1.23 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.22 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.21 27-Sep-2023  riastradh branches: 1.21.2;
gpt(8): Make gpt type array and enum match again.

Add cross-referencing comment to reduce the probability of these
getting out of sync again.

Should fix a slew of failing tests since kre's recent change to add
windows-recovery to the array but not to the enum:

sbin/gpt/t_gpt:create_2part
sbin/gpt/t_gpt:migrate_disklabel
sbin/gpt/t_gpt:recover_backup
sbin/gpt/t_gpt:recover_primary
sbin/gpt/t_gpt:remove_2part
sbin/gpt/t_gpt:resize_2part
sbin/gpt/t_gpt:restore_2part

Fail: stdout does not match golden output
--- /usr/tests/sbin/gpt/gpt.2part.show.normal 2023-09-26 15:48:30.000000000 +0000
+++ /tmp/check.sc6ylB/stdout 2023-09-26 23:30:42.388157924 +0000
@@ -3,6 +3,6 @@
1 1 Pri GPT header
2 32 Pri GPT table
34 1024 1 GPT part - EFI System
- 1058 9150 2 GPT part - NetBSD FFSv1/FFSv2
+ 1058 9150 2 GPT part - NetBSD Cryptographic Disk
10208 32 Sec GPT table
10240 1 Sec GPT header

https://releng.netbsd.org/b5reports/i386/commits-2023.09.html#build-2023.09.26.15.47.11
 1.20 26-Sep-2023  kre Recognise Windows Recovery partitions.
 1.19 30-Mar-2020  martin Now that we use the same UUID for ZFS as FreeBSD, drop the FreeBSD marker
from the description.
 1.18 25-Jun-2019  jnemeth adjust gpt_uuid_generate() to accept gpt==NULL
 1.17 20-Dec-2018  martin Add a query function (for external code) to enumerate the know guids.
Add recently added VMware GUIDs to the internal enum type.
Fix some short names (bogus + duplicate).
 1.16 06-Nov-2018  mrg add support to detect the 3 vmware GPT partition types:

- VMKcore (dump partition)
- VMFS
- VMware reserved

this enables vmkcore partitions for netbsd swap or dump, as well
as naming all of them.
 1.15 16-Feb-2017  christos branches: 1.15.10; 1.15.12;
allow 0 timestamp
 1.14 16-Feb-2017  christos Add -T timestamp for reproducible builds.
 1.13 06-Dec-2015  christos branches: 1.13.2; 1.13.4;
Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.12 03-Dec-2015  christos WARNS=6
 1.11 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.10 06-Dec-2014  mlelstv branches: 1.10.2;
Add some more common partition types.
 1.9 04-Oct-2014  riastradh Paranoia: choke noisily on EOF from /dev/urandom.
 1.8 04-Oct-2014  riastradh Make gpt(8) generate v4 (random) uuids.

Don't needlessly leak your date/time and MAC address when you edit
the disk.

Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)

ok apb
 1.7 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.6 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.5 02-Oct-2014  apb include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.

Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
 1.4 01-Oct-2014  apb It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
 1.3 01-Oct-2014  jnemeth actually return the uuid when parsing one that is in numeric format
 1.2 30-Sep-2014  jnemeth correctly show partition type in the new world order
 1.1 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.10.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.10.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.10.2.1 06-Dec-2014  snj file gpt_uuid.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.13.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.15.12.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.15.12.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.15.12.1 10-Jun-2019  christos Sync with HEAD
 1.15.10.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.15.10.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.12 11-Oct-2025  thorpej Add a couple of GPT partition type GUIDs one might encounter when
fiddling around with RISC-V systems (Linux XBOOTLDR, SiFive BBL).
 1.11 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.10 27-Sep-2023  riastradh branches: 1.10.2;
gpt(8): Make gpt type array and enum match again.

Add cross-referencing comment to reduce the probability of these
getting out of sync again.

Should fix a slew of failing tests since kre's recent change to add
windows-recovery to the array but not to the enum:

sbin/gpt/t_gpt:create_2part
sbin/gpt/t_gpt:migrate_disklabel
sbin/gpt/t_gpt:recover_backup
sbin/gpt/t_gpt:recover_primary
sbin/gpt/t_gpt:remove_2part
sbin/gpt/t_gpt:resize_2part
sbin/gpt/t_gpt:restore_2part

Fail: stdout does not match golden output
--- /usr/tests/sbin/gpt/gpt.2part.show.normal 2023-09-26 15:48:30.000000000 +0000
+++ /tmp/check.sc6ylB/stdout 2023-09-26 23:30:42.388157924 +0000
@@ -3,6 +3,6 @@
1 1 Pri GPT header
2 32 Pri GPT table
34 1024 1 GPT part - EFI System
- 1058 9150 2 GPT part - NetBSD FFSv1/FFSv2
+ 1058 9150 2 GPT part - NetBSD Cryptographic Disk
10208 32 Sec GPT table
10240 1 Sec GPT header

https://releng.netbsd.org/b5reports/i386/commits-2023.09.html#build-2023.09.26.15.47.11
 1.9 30-Jun-2019  sevan Add rcsid
 1.8 20-Dec-2018  martin Add a query function (for external code) to enumerate the know guids.
Add recently added VMware GUIDs to the internal enum type.
Fix some short names (bogus + duplicate).
 1.7 06-Dec-2015  christos branches: 1.7.14; 1.7.16;
remove more duplicated code.
 1.6 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.5 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.4 04-Sep-2015  mlelstv A change to the GPT_TYPE list also requires a change to the GPT_TYPE
index constants.
 1.3 03-Oct-2014  christos branches: 1.3.2;
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.2 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.1 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.3.2.4 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.3.2.3 08-Sep-2015  martin Pull up following revision(s) (requested by mlelstv in ticket #969):
sbin/gpt/gpt_uuid.h: revision 1.4
A change to the GPT_TYPE list also requires a change to the GPT_TYPE
index constants.
 1.3.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.3.2.1 03-Oct-2014  snj file gpt_uuid.h was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.7.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.16.1 10-Jun-2019  christos Sync with HEAD
 1.7.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.11 23-Feb-2025  christos Pass some lint.
 1.10 14-Mar-2019  mlelstv branches: 1.10.12;
print little-endian header fields correctly.
 1.9 01-May-2018  martin branches: 1.9.2; 1.9.4;
Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
 1.8 24-Dec-2015  martin branches: 1.8.8; 1.8.14;
Fix output in an error case
 1.7 03-Dec-2015  christos WARNS=6
 1.6 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.5 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.4 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.3 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.2 16-Nov-2015  jnemeth correctly print the gpt header revision as a "float"
 1.1 03-Nov-2015  jnemeth Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists.
 1.8.14.1 02-May-2018  pgoyette Synch with HEAD
 1.8.8.1 07-May-2018  snj Pull up following revision(s) (requested by martin in ticket #797):
sbin/gpt/gpt.8: 1.60-1.63
sbin/gpt/header.c: 1.9
Make the "gpt header" command return EXIT_FAILURE when no GPT is present.
This helps sysinst to tell a GPT labeled disk from others.
Very lazy version of a change proposed by kre.
--
Sort sections.
--
Bump date for new EXIT STATUS section.
--
Spello. (it is "existence").
ispell also says that we should s/parseable/parsable/ but I'm
not sure about that one, so I left it.
I also left a correct spelling that no-one has bothered to mangle!
 1.9.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.9.4.1 01-May-2018  martin file header.c was added on branch netbsd-7 on 2018-08-13 16:12:12 +0000
 1.9.2.1 10-Jun-2019  christos Sync with HEAD
 1.10.12.1 02-Aug-2025  perseant Sync with HEAD
 1.31 23-Feb-2025  christos Pass some lint.
 1.30 21-Jun-2019  jnemeth branches: 1.30.12;
Add a third argument to the "cfn" function that is an argument to
gpt_change_ent(). The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry. It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.
 1.29 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.28 04-Dec-2015  christos branches: 1.28.14; 1.28.16;
put back usage from kre
 1.27 03-Dec-2015  christos CID 1341564: Arg memory leak
 1.26 03-Dec-2015  christos CID 1341563: fix leak
 1.25 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.24 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.23 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.22 01-Dec-2015  christos refactor more duplicated code.
 1.21 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.20 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.19 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.18 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.17 30-Sep-2014  christos remove compat defines.
 1.16 29-Sep-2014  christos minor toolification: need libprop...
 1.15 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.14 28-Nov-2013  jnemeth branches: 1.14.4;
when calling dehumanize_number() make sure the resulting number is >= 1
 1.13 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.12 22-Nov-2013  jnemeth change the "-b blocknr" parameter to accept a "human number"
 1.11 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.10 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.9 13-Apr-2013  jakllsch Use correct spelling of "secondary" in comments.
 1.8 27-Aug-2011  joerg branches: 1.8.2; 1.8.8;
Use __dead
 1.7 12-Mar-2009  dyoung Fix spelling: s/parition/partition/.
 1.6 19-Dec-2007  dogcow branches: 1.6.12;
Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.4 16-Feb-2007  riz branches: 1.4.4; 1.4.6;
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3 15-Oct-2006  christos branches: 1.3.2;
add casts
 1.2 15-Oct-2006  christos Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.3.2.1 20-Feb-2007  tron branches: 1.3.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.3.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.4.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.4.4.1 09-Jan-2008  matt sync with HEAD
 1.6.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.8.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.8.1 23-Jun-2013  tls resync from head
 1.8.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.14.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.28.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.28.16.1 10-Jun-2019  christos Sync with HEAD
 1.28.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.30.12.1 02-Aug-2025  perseant Sync with HEAD
 1.15 23-Feb-2025  christos Pass some lint.
 1.14 24-May-2020  jmcneill branches: 1.14.8;
Add -H flag to ignore existing MBR (Hybrid MBR/GPT mode).
 1.13 25-Jun-2019  jnemeth Add an "uuid" command to generate a new UUID for a portion. The
primary intention is for use for after cloning disks to prevent
collisions.
 1.12 27-Aug-2018  sevan Add the -T flag to usage()
 1.11 19-Mar-2018  mlelstv branches: 1.11.2; 1.11.4;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.10 16-Feb-2017  christos branches: 1.10.4; 1.10.10;
allow 0 timestamp
 1.9 16-Feb-2017  christos Add -T timestamp for reproducible builds.
 1.8 12-Feb-2017  aymeric Make gpt(8) work when compiled on a glibc-based OS.

This restores the ability to build amd64 install-image's under Linux.
 1.7 29-Dec-2015  christos branches: 1.7.2; 1.7.4;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.6 03-Dec-2015  christos WARNS=6
 1.5 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.4 01-Dec-2015  christos automatically enforce readonly for the commands that don't need to write.
 1.3 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.2 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.1 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.7.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.7.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10.10.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.10.10.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.10.4.2 28-Aug-2018  martin Pull up following revision(s) (requested by sevan in ticket #992):

external/bsd/top/dist/top.1.in: revision 1.11
sbin/gpt/main.c: revision 1.12
sbin/amrctl/amrctl.c: revision 1.11
bin/df/df.c: revision 1.93
sbin/fsck_ext2fs/fsck_ext2fs.8: revision 1.21
sbin/fsck_ext2fs/main.c: revision 1.38
bin/ksh/ksh.Man: revision 1.26
bin/ln/ln.c: revision 1.40
bin/df/df.1: revision 1.48
bin/df/df.1: revision 1.49

Document the WCPU field.

Match SYNOPSIS with usage()

-G cannot be specified alongside -i or -P.
Heads up by <leot>

Add -l to SYNOPSIS

Update usage to include -w

Match sequence as per SYNOPSIS in manual

Remove reference to -c flag which was never implemented.

Remove references to -c flag which was never included.

Add the -T flag to usage()
 1.10.4.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.11.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.11.4.1 19-Mar-2018  martin file main.c was added on branch netbsd-7 on 2018-08-13 16:12:12 +0000
 1.11.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.11.2.1 10-Jun-2019  christos Sync with HEAD
 1.14.8.1 02-Aug-2025  perseant Sync with HEAD
 1.16 05-Dec-2023  tsutsui Fix an incorrect comment.
 1.15 24-May-2020  jmcneill Exit gracefully when auto-expanding a partition and it is already the
correct size. Add a -q flag to "resize" and "resizedisk" commands to skip
printing warnings in the already resize paths.
 1.14 11-Apr-2018  mrg if a new map entry doesn't fit, be more verbose about the sizes.
 1.13 03-Dec-2015  christos branches: 1.13.8; 1.13.14;
CID 1341556: Don't leak map info
 1.12 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.11 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.10 29-Nov-2015  christos Add some debugging.
 1.9 29-Nov-2015  christos print the current map type.
 1.8 29-Nov-2015  christos - use snprintf
- fix bogus logic on map_type
 1.7 29-Sep-2014  christos minor toolification: need libprop...
 1.6 27-Nov-2013  christos branches: 1.6.4;
CID 1132762: Add error check for negative, to make zero-divide in module
impossible.
 1.5 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.4 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.3 26-Oct-2013  jnemeth cosmetic fix from drochner@
 1.2 15-Oct-2006  christos branches: 1.2.42; 1.2.48;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.48.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.42.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.13.14.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.13.8.1 04-May-2018  martin Pull up following revision(s) (requested by mrg in ticket #785):
sbin/gpt/gpt.c: revision 1.74
sbin/gpt/map.c: revision 1.14
sbin/gpt/gpt.8: revision 1.53
sbin/gpt/gpt.8: revision 1.54
sbin/gpt/gpt.8: revision 1.55
sbin/gpt/gpt.8: revision 1.56
sbin/gpt/gpt.8: revision 1.57
sbin/gpt/gpt.8: revision 1.59

Add note about bootme flag:
The bootme flag is used to indicate which partiotion should be booted
by UEFI boot code.

Fix a typo, and make a couple of minor wording improvements.
I resisted the (very weak) impulse to Americanise some spellings ...

Use Fx/Nx.

clarify that alignment is the number of bytes to align to.

Explain what suffixes are accepted when specifying a size.
Spelling

add information about how to boot from gpt. mostly taken from the wiki.

if a new map entry doesn't fit, be more verbose about the sizes.
 1.7 30-Jun-2019  sevan Add rcsid
 1.6 03-Dec-2015  christos branches: 1.6.16;
CID 1341556: Don't leak map info
 1.5 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.4 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.3 20-Nov-2013  jnemeth branches: 1.3.4;
Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.2 19-Nov-2013  jnemeth Add two new options to the "add" subcommand:

-a alignment -- attempt to align the start and size of the partition
-l label -- supply a label for the partition

These options were inspired by FreeBSD's gpart(8) command, but the
code was written by me.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos branches: 1.1.1.1.42; 1.1.1.1.48;
Import the gpt tool from FreeBSD
 1.1.1.1.48.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.1.1.42.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.4.1 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.36 23-Feb-2025  christos Pass some lint.
 1.35 03-Mar-2019  jnemeth branches: 1.35.12;
add some more FAT file system types
 1.34 10-Feb-2019  martin Make "gpt migrate" work for disks with FAT32 and NTFS partitions
 1.33 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.32 09-Jun-2016  christos branches: 1.32.14; 1.32.16;
Rename 'a' to set the active PMBR flag to 'A'
 1.31 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.30 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.29 06-Dec-2015  christos remove more duplicated code.
 1.28 05-Dec-2015  christos Add debugging and more to migration
 1.27 03-Dec-2015  christos WARNS=6
 1.26 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.25 01-Dec-2015  christos refactor more duplicated code.
 1.24 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.23 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.22 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.21 03-Oct-2014  christos provide a copy of the kernel uuid generator (with portable API calls) for
tools.
 1.20 03-Oct-2014  jnemeth "0" is not guaranteed to be unique
 1.19 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.18 30-Sep-2014  christos remove compat defines.
 1.17 29-Sep-2014  christos more toolification changes
 1.16 29-Sep-2014  christos more toolification
 1.15 29-Sep-2014  christos minor toolification: need libprop...
 1.14 04-Dec-2013  jakllsch branches: 1.14.4;
Use MBR_PTYPE_ defines from <sys/bootblock.h>.
 1.13 04-Dec-2013  jakllsch Mirror my changes of src/sbin/gpt/create.c 1.4 in migrate.c;

Use less bogus CHS addresses in PMBR.
With the ending head set at 0xff one machine I have will never leave
the initial startup screen if such a disk is present. Additionally,
Wikipedia suggests without citiation that 254 is the maximium allowable
value for the head, and this seems to be the case.
 1.12 13-Nov-2013  christos CID 1125874: Fix memory leak
 1.11 22-Oct-2013  jnemeth In a NetBSD disklabel, p_offset is from the beginning of the disk,
not the beginning of the NetBSD partition.
 1.10 19-Oct-2013  jnemeth Convert FreeBSD numeric FS_<type>s to labels by request.
 1.9 19-Oct-2013  jnemeth - convert FreeBSD FS_<type> to numbers where they don't match NetBSD
- add support for migrating NetBSD disklabel'ed disks (only 7 years late)
- use labels for partition types
 1.8 19-Oct-2013  jnemeth Add code for detecting FreeBSD ZFS partitions.

XXX Need to add code for migrating NetBSD disklabel'ed disks.
 1.7 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.6 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.5 27-Aug-2011  joerg branches: 1.5.2; 1.5.8;
Use __dead
 1.4 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.3 17-Oct-2006  he branches: 1.3.2; 1.3.4; 1.3.8; 1.3.10;
Some of our ports want <sys/param.h> in order to have DEV_BSIZE defined,
needed for LABELSECTOR expansion.
 1.2 15-Oct-2006  christos Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.3.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.8.1 09-Jan-2008  matt sync with HEAD
 1.3.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.3.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 23-Jun-2013  tls resync from head
 1.5.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.14.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.32.16.1 10-Jun-2019  christos Sync with HEAD
 1.32.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.35.12.1 02-Aug-2025  perseant Sync with HEAD
 1.21 24-Feb-2025  christos remove getopt call (noted by rillig@)
 1.20 23-Feb-2025  christos Pass some lint.
 1.19 13-Dec-2020  jnemeth branches: 1.19.8;
PR/55875 - Valentin -- "gpt recover -r" does nothing

Delete do nothing undocumented option, that was there from initial
import. No idea what it was intended to do and there is no longer
an "upstream".
 1.18 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.17 22-Mar-2017  martin branches: 1.17.10; 1.17.12;
Add missing endianes swap to make the "recover" command work on big endian
machines.
 1.16 12-Jun-2016  jnemeth branches: 1.16.2; 1.16.4;
- fix setting of hdr_lba_alt which was broken in revision 1.10 on 2015/12/2
- switch to using gpt_last
- PR/51230 -- recreate the PMBR if it was lost
 1.15 04-Dec-2015  christos Fix resizedisk.
 1.14 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.13 03-Dec-2015  christos WARNS=6
 1.12 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.11 02-Dec-2015  christos don't hard-code the program name
 1.10 02-Dec-2015  christos merge duplicated code and check allocations.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 18-Jun-2015  jnemeth Instruct user to use resizedisk if media size has changed, as
resizedisk will adjust the media size in the headers, whereas
recover simply copies the existing header over the missing one.

XXX recover and resizedisk should probably be merged (even if just
partially, so that recover can properly handle media size changes).
Also, reading in the GPT should probably be centralised so that
error handling can be centralised, and users aren't given misleading
messages (i.e. they aren't told to run recover when they should be
running resizedisk). However, something that can be quickly pulled
up to netbsd-7 was needed, and there isn't time for a major overhaul
or rewrite.
 1.5 29-Sep-2014  christos minor toolification: need libprop...
 1.4 27-Aug-2011  joerg branches: 1.4.20;
Use __dead
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.4.20.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.4.20.2 29-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #847):
sbin/gpt/recover.c: revision 1.6
Instruct user to use resizedisk if media size has changed, as
resizedisk will adjust the media size in the headers, whereas
recover simply copies the existing header over the missing one.
XXX recover and resizedisk should probably be merged (even if just
partially, so that recover can properly handle media size changes).
Also, reading in the GPT should probably be centralised so that
error handling can be centralised, and users aren't given misleading
messages (i.e. they aren't told to run recover when they should be
running resizedisk). However, something that can be quickly pulled
up to netbsd-7 was needed, and there isn't time for a major overhaul
or rewrite.
 1.4.20.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.16.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.16.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.17.12.1 10-Jun-2019  christos Sync with HEAD
 1.17.10.1 28-Jul-2018  pgoyette Sync with HEAD
 1.19.8.1 02-Aug-2025  perseant Sync with HEAD
 1.24 23-Feb-2025  christos Pass some lint.
 1.23 21-Jun-2019  jnemeth branches: 1.23.12;
Add a third argument to the "cfn" function that is an argument to
gpt_change_ent(). The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry. It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.
 1.22 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.21 03-Dec-2015  christos branches: 1.21.14; 1.21.16;
eliminate static globals so that commands can be re-used.
 1.20 01-Dec-2015  christos refactor more duplicated code.
 1.19 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.18 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.17 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.16 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.15 30-Sep-2014  christos remove compat defines.
 1.14 29-Sep-2014  christos minor toolification: need libprop...
 1.13 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.12 28-Nov-2013  jnemeth branches: 1.12.4;
when calling dehumanize_number() make sure the resulting number is >= 1
 1.11 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.10 22-Nov-2013  jnemeth change the "-b blocknr" parameter to accept a "human number"
 1.9 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.8 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.7 13-Apr-2013  jakllsch Use correct spelling of "secondary" in comments.
 1.6 27-Aug-2011  joerg branches: 1.6.2; 1.6.8;
Use __dead
 1.5 07-Feb-2009  uebayasi Make manual and usage consistent. No functional changes.
 1.4 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.3 16-Feb-2007  riz branches: 1.3.4; 1.3.6;
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2 15-Oct-2006  christos branches: 1.2.2;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.2.2.1 20-Feb-2007  tron branches: 1.2.2.1.2;
Pull up following revision(s) (requested by riz in ticket #445):
sbin/gpt/add.c: revision 1.4
sbin/gpt/remove.c: revision 1.3
sbin/gpt/label.c: revision 1.4
sbin/gpt/gpt.c: revision 1.3
Use strtoll() when converting a 64-bit quantity. This makes "gpt add"
work with an offset of more than 2147483647 sectors. While I'm here,
use strtoul() when converting an unsigned quantity.
 1.2.2.1.2.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.3.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.4.1 09-Jan-2008  matt sync with HEAD
 1.6.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.8.1 23-Jun-2013  tls resync from head
 1.6.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.12.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.21.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.21.16.1 10-Jun-2019  christos Sync with HEAD
 1.21.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.23.12.1 02-Aug-2025  perseant Sync with HEAD
 1.26 23-Feb-2025  christos Pass some lint.
 1.25 24-May-2020  jmcneill branches: 1.25.8;
Exit gracefully when auto-expanding a partition and it is already the
correct size. Add a -q flag to "resize" and "resizedisk" commands to skip
printing warnings in the already resize paths.
 1.24 24-Mar-2019  martin Add support for specifying the partition to resize via -b startsec
(similar to label and other subcommands). Do not fully add gpt_find
functionality here, as resizing multiple partitions in one go does not
make sense.
 1.23 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.22 04-Dec-2015  christos branches: 1.22.14; 1.22.16;
Kill newline
 1.21 03-Dec-2015  christos WARNS=6
 1.20 03-Dec-2015  christos remove extra assignment
 1.19 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.18 02-Dec-2015  christos - check errors from map allocation
- make map_resize return -1 instead of 0, and handle errors locally
explaining what's going wrong
 1.17 01-Dec-2015  christos refactor more duplicated code.
 1.16 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.15 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.14 01-Dec-2015  christos - use gpt_msg to print informational messages (perhaps these should be printed
only with -v)
- don't print any messages with gpt_msg if quiet
- print a message if we didn't reconfigure the wedges
 1.13 30-Nov-2015  christos - automatically sync the wedge information unless -n is specified.
- document the general options in the traditional way.
- split the main program into a separate file.
 1.12 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.11 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.10 30-Sep-2014  christos remove compat defines.
 1.9 29-Sep-2014  christos minor toolification: need libprop...
 1.8 10-Dec-2013  jnemeth branches: 1.8.4; 1.8.6; 1.8.8;
Explicitly state which partition was added/modified.
 1.7 08-Dec-2013  jnemeth For the add and resize subcommands, change the -s option. If there is
no suffix, or the suffix is 's' or 'S', size is in sectors (as before)
otherwise size is in bytes.
 1.6 06-Dec-2013  jnemeth Don't attempt to create/resize an unaligned partition if the attempt
to create/resize an aligned one failed. This simplifies the code
and prevents surprises. If the user wants an unaligned partition
in the case where an aligned one fails, they can simply retry the
command without the "-a" option. This change was requested by
wiz@, and after some thought I agree with it.
 1.5 28-Nov-2013  jnemeth when calling dehumanize_number() make sure the resulting number is >= 1
 1.4 27-Nov-2013  christos CID 1132764: Bogus test
 1.3 27-Nov-2013  jnemeth Remove FreeBSD specific code as per message to tech-userlevel.
 1.2 22-Nov-2013  jnemeth In the manpage:
- s/-b number/-b blocknr/
- s/-s count/-s sectors/
- s/-p count/-p partitions/

In the program:
- s/-b lba/-b blocknr/
- s/-s lba/-s sectors/

This makes the documentation in the manpage and the program consistent
and makes it more clear what the parameters are. Also, "-s lba" was
just plain wrong since LBA stands for Logical Block Address[ing], and
the -s option didn't represent any kind of address, but rather a size.
 1.1 20-Nov-2013  jnemeth Add a resize command. This command was inspired by FreeBSD's gpart(8),
but the code was written by myself.
 1.8.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.8.1 10-Dec-2013  tls file resize.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.8.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.8.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.8.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.4.1 10-Dec-2013  yamt file resize.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.22.16.1 10-Jun-2019  christos Sync with HEAD
 1.22.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.25.8.1 02-Aug-2025  perseant Sync with HEAD
 1.22 23-Feb-2025  christos Pass some lint.
 1.21 06-Feb-2024  christos branches: 1.21.2;
check the right variable
 1.20 22-Nov-2022  mlelstv Big-Endian fixes.
 1.19 20-Nov-2022  mlelstv Fix destroying and moving GPT header also for truncated/extended
images.
 1.18 24-May-2020  jmcneill Exit gracefully when auto-expanding a partition and it is already the
correct size. Add a -q flag to "resize" and "resizedisk" commands to skip
printing warnings in the already resize paths.
 1.17 04-Dec-2015  christos type confusion
 1.16 04-Dec-2015  christos Fix resizedisk.
 1.15 03-Dec-2015  christos CID 1341556: Don't leak map info
 1.14 03-Dec-2015  christos Fix stray paste, noted by kre.
 1.13 03-Dec-2015  christos WARNS=6
 1.12 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.11 02-Dec-2015  christos check allocations
 1.10 01-Dec-2015  christos refactor more duplicated code.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 01-Oct-2014  jnemeth branches: 1.6.2;
oops, forgot to update end of data area
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 23-Sep-2014  msaitoh Fix compile error observed on i386. Use PRIu64.
 1.1 23-Sep-2014  jnemeth - make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
 1.6.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.6.2.1 01-Oct-2014  snj file resizedisk.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.21.2.1 02-Aug-2025  perseant Sync with HEAD
 1.21 23-Feb-2025  christos Pass some lint.
 1.20 07-Jun-2020  thorpej branches: 1.20.8;
Update for proplib(3) API changes.
 1.19 14-May-2020  msaitoh Remove extra semicolon.
 1.18 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.17 07-Sep-2017  christos branches: 1.17.2; 1.17.4;
use __arraycount
 1.16 03-Dec-2015  christos branches: 1.16.8;
WARNS=6
 1.15 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.14 02-Dec-2015  christos - factor out into smaller separate functions
- fix signed/unsigned confusion
- do proper write checks
- fix some memory leaks
 1.13 02-Dec-2015  christos Allow backup and restore to operate on files.
 1.12 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.11 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.10 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.9 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.8 16-Jun-2015  christos fix error messages containing \n
 1.7 01-Oct-2014  jnemeth using random values for hdr->hdr_guid does not work very well
 1.6 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.5 30-Sep-2014  christos remove compat defines.
 1.4 29-Sep-2014  christos minor toolification: need libprop...
 1.3 26-Sep-2014  jnemeth - handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
 1.2 20-Sep-2014  jnemeth Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
 1.1 10-Aug-2014  jnemeth branches: 1.1.2; 1.1.4;
Add restore subcommand.

XXX It does not actually work yet. It is being committed now to make
later pullups easier.
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file restore.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.1.2.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.1.2.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.16.8.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.17.4.1 10-Jun-2019  christos Sync with HEAD
 1.17.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.20.8.1 02-Aug-2025  perseant Sync with HEAD
 1.16 23-Feb-2025  christos Pass some lint.
 1.15 25-Mar-2019  martin branches: 1.15.12;
Allow -b startsec to specify the partition to change for the set subcommand
as well.
Add another option, -N, as a quick way to remove all attributes.
 1.14 19-Mar-2018  mlelstv branches: 1.14.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.13 29-Dec-2015  christos branches: 1.13.8; 1.13.14;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.12 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.11 03-Dec-2015  christos WARNS=6
 1.10 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.9 01-Dec-2015  christos refactor more duplicated code.
 1.8 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.7 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.6 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 10-Dec-2013  jnemeth branches: 1.2.4; 1.2.6; 1.2.8;
Explicitly state which partition was added/modified.
 1.1 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 10-Dec-2013  tls file set.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.2.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.2.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.2.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.1 10-Dec-2013  yamt file set.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.14.2.1 10-Jun-2019  christos Sync with HEAD
 1.15.12.1 02-Aug-2025  perseant Sync with HEAD
 1.47 23-Feb-2025  christos Pass some lint.
 1.46 04-Nov-2024  christos Additions to guid printing and an option to print start/size in hex
(from Anon Ymous)
 1.45 13-Sep-2024  mlelstv Use destination variable also to determine size. No binary change, both
buffers are of the same size.
 1.44 26-Mar-2019  martin branches: 1.44.12;
When displaying a single partition (gpt show -i ...) display offset
and size in sectors (instead of the totally confusing bytes),
followed by the humanized byte offset/size.

This makes the numbers match the "gpt show" or "gpt show -a"
output.
 1.43 24-Mar-2019  martin Make the "show" subcommand accept -b startsec to identify a partition
(very usefull for scripts and other robotic callers).
 1.42 03-Mar-2019  jnemeth Make it clear when displaying data from the MBR.
 1.41 07-Sep-2017  christos branches: 1.41.4;
use __arraycount
 1.40 06-Sep-2017  christos - make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
 1.39 05-Oct-2016  kre branches: 1.39.6;

Avoiding having parameter name shadow its own function's name.
Strictly this shouldnt be (and hasn't been for almost a year) a problem,
but there are compilers that warn about locals shadowing globals (which
this is/was) and it is easy to avoid, so ... No functinal difference.
 1.38 09-Jun-2016  kre branches: 1.38.2;

Make "gpt show" add an "(active)" annotation to the PMBR output line
when it has been marked active for legacy (non UEFI) booting.
This was (kind of obviously) intended by the previous commit, but...
 1.37 09-Jun-2016  christos PR/51230: Add the ability to set the active flag in the PMBR.
 1.36 31-May-2016  dholland PR 50756 David Binderman: avoid running off the end of an array in case
thing we're looking for isn't there. Which is probably impossible, but
that's not obvious.
 1.35 29-Dec-2015  christos - add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.34 26-Dec-2015  martin Improve "show -a" display: split human readable Type: field from the Type-GUID
to avoid wrapping in the common case; add a human readable Size: display.
 1.33 25-Dec-2015  wiz Simplify usage for gpt show.
 1.32 25-Dec-2015  martin Add a -a flag to the show command, so we can display the full GPT with
all information in one go.
 1.31 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.30 04-Dec-2015  christos fix label printing.
 1.29 03-Dec-2015  christos WARNS=6
 1.28 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.27 02-Dec-2015  christos refactor the utf code so that it does not leak memory.
 1.26 01-Dec-2015  christos merge command line parsers and check all memory allocations.
 1.25 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.24 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.23 29-Nov-2015  christos Add the missing cases.
 1.22 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.21 30-Sep-2014  jnemeth correctly show partition type in the new world order
 1.20 30-Sep-2014  jnemeth Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
 1.19 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.18 30-Sep-2014  christos remove compat defines.
 1.17 29-Sep-2014  christos more toolification changes
 1.16 29-Sep-2014  christos minor toolification: need libprop...
 1.15 18-Dec-2013  jnemeth branches: 1.15.4;
If we want to GUIDs to display with correct endian, it helps to decode it first.
 1.14 09-Dec-2013  jnemeth For the "show -i <entry>" subcommand, print Start and Size both in
terms of number of sectors and bytes.
 1.13 08-Dec-2013  jnemeth fix off-by-one error
 1.12 30-Nov-2013  jnemeth Add two new options:

-g which shows the GUID for a partition
-i which shows all the gory details for a particular option

XXX the output format of -i is subject to change
 1.11 19-Oct-2013  jnemeth recognize FreeBSD ZFS partition
 1.10 13-Apr-2013  jakllsch Make pre-initialized partition type uuid_t symbols 'static const'.

This conserves a few hundred bytes of total program size by
allowing the linker to merge duplicates.
 1.9 13-Apr-2013  jakllsch Clean up gpt(8) a bit more

uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to
an array of bytes merely casted to compatible type.

Additonally, there no need for extra casts and address-of operations when
using le_uuid_*() functions.

Furthermore, le_uuid_*() are identical to uuid_*_le functions in
libc/libuuid, so use those instead on NetBSD.
 1.8 18-Jan-2013  jakllsch Now that GPT_ENT_TYPE_LINUX_DATA is diffrent from the Windows one, use it.
 1.7 27-Aug-2011  joerg branches: 1.7.2; 1.7.8;
Use __dead
 1.6 06-Jan-2011  jakllsch UFS is called FFS in the NetBSD case. Display as such and accept as input.
 1.5 24-Feb-2008  christos PR/38094: Robert Millan: support "BIOS Boot" partition type in gpt(8)
 1.4 28-Dec-2007  riz branches: 1.4.2; 1.4.4;
As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.3 18-Dec-2007  riz Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...
 1.2 15-Oct-2006  christos branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10;
Make this work under NetBSD.
 1.1 15-Oct-2006  christos branches: 1.1.1;
Initial revision
 1.1.1.1 15-Oct-2006  christos Import the gpt tool from FreeBSD
 1.2.10.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.10.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.8.2 23-Mar-2008  matt sync with HEAD
 1.2.8.1 09-Jan-2008  matt sync with HEAD
 1.2.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.2.2 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.6
src/sbin/gpt/gpt.c 1.7
src/sbin/gpt/show.c 1.4
src/sys/dev/dkwedge/dkwedge_gpt.c 1.7
src/sys/sys/disk.h 1.47
src/sys/sys/disklabel_gpt.h 1.4
(requested by riz in ticket #1119).

As discussed on tech-userlevel, add NetBSD GPT partition types for
swap, ffs, lfs, raidframe, ccd and cgd. gpt(8) now defaults to
NetBSD ffs if no type is given, but previous FreeBSD types are
still recognized in the DKWEDGE_AUTODISCOVER code.
 1.2.2.1 08-Apr-2008  jdc Pull up revisions:
src/sbin/gpt/add.c 1.5
src/sbin/gpt/create.c 1.3
src/sbin/gpt/destroy.c 1.3
src/sbin/gpt/gpt.c 1.4-1.6
src/sbin/gpt/label.c 1.5-1.6
src/sbin/gpt/migrate.c 1.4
src/sbin/gpt/recover.c 1.3
src/sbin/gpt/remove.c 1.4
src/sbin/gpt/show.c 1.3
(requested by riz in ticket #1117).

Produce more useful error messages.

Fix the usage strings for each command, and print them all for the
"global" usage. It's still a little ugly, but hopefully not as
fantastically confusing as before...

Your friendly neighborhood 64-bit architecture here to remind you that
strlen returns size_t, and printf's precision specifier uses int.
 1.4.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.4.2.1 24-Mar-2008  keiichi sync with head.
 1.7.8.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.8.2 23-Jun-2013  tls resync from head
 1.7.8.1 25-Feb-2013  tls resync with head
 1.7.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.2.1 23-Jan-2013  yamt sync with head
 1.15.4.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.15.4.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.38.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.39.6.1 12-Feb-2018  snj Pull up following revision(s) (requested by christos in ticket #545):
sbin/gpt/backup.c: 1.17-1.18
sbin/gpt/biosboot.c: 1.29-1.30
sbin/gpt/gpt.c: 1.71-1.73
sbin/gpt/gpt.h: 1.36
sbin/gpt/restore.c: 1.17
sbin/gpt/show.c: 1.40-1.41
sys/dev/dkwedge/dkwedge_gpt.c: 1.19-1.20
PR/52522: Piotr Meyer: Don't NUL terminate the gpt label name.
--
- make sure that the utf16 string is padded with 0's where needed.
- since the utf16 string is not 0 terminated, pass the size of the string.
--
use __arraycount
--
PR/52522: ent_name is not necessarily 0 terminated, so check bounds.
--
use arraycount.
 1.41.4.1 10-Jun-2019  christos Sync with HEAD
 1.44.12.1 02-Aug-2025  perseant Sync with HEAD
 1.17 23-Feb-2025  christos Pass some lint.
 1.16 21-Jun-2019  jnemeth branches: 1.16.12;
Add a third argument to the "cfn" function that is an argument to
gpt_change_ent(). The purpose of the third argument is to specify
whether the entry to be changed is a primary GPT entry or a secondary
GPT entry. It is assumed that a secondary GPT entry will always
follow a corresponding primary entry.

This is in preparation for an upcoming change that will require it.
 1.15 03-Jul-2018  jnemeth Not all things that write to the disk do something that dk(4) will
be interested in. Let individual commands decide if ioctl(DIOCMWEDGES)
should be done. I was conservative and set the flag on any command
that might create/modify/delete partitions in any way.
 1.14 19-Mar-2018  mlelstv branches: 1.14.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.13 06-Dec-2015  christos branches: 1.13.8; 1.13.14;
Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.12 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.11 02-Dec-2015  christos use the utility function.
 1.10 01-Dec-2015  christos refactor more duplicated code.
 1.9 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.8 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.7 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.6 07-Dec-2014  mlelstv branches: 1.6.2;
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 29-Sep-2014  jnemeth PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
 1.1 28-Sep-2014  jnemeth PR/44218 - David Young -- add "type" subcommand to change a partition type
 1.6.2.3 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.6.2.2 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.6.2.1 07-Dec-2014  snj file type.c was added on branch netbsd-7 on 2015-06-02 19:49:38 +0000
 1.13.14.2 28-Jul-2018  pgoyette Sync with HEAD
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.14.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.14.2.1 10-Jun-2019  christos Sync with HEAD
 1.16.12.1 02-Aug-2025  perseant Sync with HEAD
 1.16 23-Feb-2025  christos Pass some lint.
 1.15 26-Mar-2019  martin branches: 1.15.12;
Allow -b to specify a partition for "gpt unset" as well.
 1.14 19-Mar-2018  mlelstv branches: 1.14.2;
Check device parameter to avoid segfaults. Agument synopsis for -l option.
 1.13 29-Dec-2015  christos branches: 1.13.8; 1.13.14;
- add more informational messages
- handle case where last argument is an option not a device (set -l)
 1.12 06-Dec-2015  christos Add listing commands for type, set and unset.
Add help and formatting for set and unset.
Change show to print all the attribute info in one line.
 1.11 03-Dec-2015  christos WARNS=6
 1.10 03-Dec-2015  christos eliminate static globals so that commands can be re-used.
 1.9 01-Dec-2015  christos refactor more duplicated code.
 1.8 01-Dec-2015  christos Refactor the command dispatching and help printing logic.
 1.7 01-Dec-2015  christos Firs step of refactoring, remove all globals, factor out some common code,
handle alternate usage but not advertise it.
 1.6 29-Nov-2015  christos merge the create errors in one place and fix them.
 1.5 30-Sep-2014  christos Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
 1.4 30-Sep-2014  christos remove compat defines.
 1.3 29-Sep-2014  christos minor toolification: need libprop...
 1.2 10-Dec-2013  jnemeth branches: 1.2.4; 1.2.6; 1.2.8;
Explicitly state which partition was added/modified.
 1.1 09-Dec-2013  jnemeth Add two new subcommands, "set" and "unset". These were inspired by
FreeBSD's gpart(8), but the code is all mine. The purpose of these
is to set and unset partition attributes.
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 10-Dec-2013  tls file unset.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.2.6.2 13-Aug-2018  martin Catch up to current for the following, requested by sborrill in ticket #1629:

sbin/gpt/gpt_private.h up to 1.2
sbin/gpt/header.c up to 1.9
sbin/gpt/main.c up to 1.11
sbin/gpt/drvctl.c delete
sbin/gpt/Makefile up to 1.18
sbin/gpt/add.c up to 1.44
sbin/gpt/backup.c up to 1.18
sbin/gpt/biosboot.c up to 1.30
sbin/gpt/create.c up to 1.23
sbin/gpt/destroy.c up to 1.10
sbin/gpt/gpt.8 up to 1.63
sbin/gpt/gpt.c up to 1.75
sbin/gpt/gpt.h up to 1.38
sbin/gpt/gpt_uuid.c up to 1.15
sbin/gpt/gpt_uuid.h up to 1.7
sbin/gpt/label.c up to 1.29
sbin/gpt/map.c up to 1.14
sbin/gpt/map.h up to 1.6
sbin/gpt/migrate.c up to 1.33
sbin/gpt/recover.c up to 1.18
sbin/gpt/remove.c up to 1.22
sbin/gpt/resize.c up to 1.23
sbin/gpt/resizedisk.c up to 1.17
sbin/gpt/restore.c up to 1.18
sbin/gpt/set.c up to 1.14
sbin/gpt/show.c up to 1.41
sbin/gpt/type.c up to 1.15
sbin/gpt/unset.c up to 1.14

Many changes including:
- Significant refactoring
- PR/51230: Add the ability to set the active flag in the PMBR
- Let individual commands decide if ioctl(DIOCMWEDGES) should be done
- Add a "header" subcommand that displays information about the size of
the disk along with information from the GPT header if it exists
- Add listing commands for type, set and unset
- Add help and formatting for set and unset
- Change show to print all the attribute info in one line.
- Improve documentation, including booting and exit status
- Check device parameter to avoid segfaults
 1.2.6.1 02-Jun-2015  snj Pull up following revision(s) (requested by jnemeth in ticket #774):
sbin/gpt/Makefile: revisions 1.9-1.13
sbin/gpt/add.c: revisions 1.25-1.27
sbin/gpt/backup.c: revisions 1.2-1.8
sbin/gpt/biosboot.c: revisions 1.8-1.14
sbin/gpt/create.c: revisions 1.8-1.12
sbin/gpt/destroy.c: revisions 1.5-1.6
sbin/gpt/drvctl.c: revision 1.1
sbin/gpt/gpt.8: revisions 1.29-1.36
sbin/gpt/gpt.c: revisions 1.29-1.40
sbin/gpt/gpt.h: revisions 1.12-1.18
sbin/gpt/gpt_uuid.c: revisions 1.1-1.10
sbin/gpt/gpt_uuid.h: revisions 1.1-1.3
sbin/gpt/label.c: revisions 1.15-1.18
sbin/gpt/map.c: revision 1.7
sbin/gpt/migrate.c: revisions 1.15-1.21
sbin/gpt/recover.c: revision 1.5
sbin/gpt/remove.c: revisions 1.13-1.16
sbin/gpt/resize.c: revisions 1.9-1.11
sbin/gpt/resizedisk.c: revisions 1.1-1.6
sbin/gpt/restore.c: revisions 1.2-1.7
sbin/gpt/set.c: revisions 1.3-1.5
sbin/gpt/show.c: revision 1.16-1.21
sbin/gpt/type.c: revisions 1.1-1.6
sbin/gpt/unset.c: revisions 1.3-1.5
- record the sector size of the disk
- correct confusion with end_cylinder and end_sector in MBRs
--
- dump all partitions, not just ones that are in use
- while here, squash a memory leak
It shouldn't be necessary to backup unused partitions, however
the partition GUID is created at the time the GPT is created and
is never changed. It shouldn't matter if the GUID of an unused
partition changes, but there may be some special case where it
does. Since it isn't a big deal to record the unused partitions,
might as well do it.
--
Initial cut of gpt restore. This functions correctly in testing,
but isn't all that pretty. It has minimal error testing and may
leak memory. It also only works with empty disks. If passed "-F"
flag, it will blank the disk for you.
--
document the new restore subcommand
--
- make gpt_gpt() available for use directly by subcommands
- create new resizedisk disk subcommand for relocating backup GPT
--
Fix compile error observed on i386. Use PRIu64.
--
no C99isms in tool code
--
- handle a GPT that isn't an exact multiple of a sector
- adjust PMBR size, in case new disk is a different size
- don't leak as much memory
- clean up error handling somewhat
--
PR/44218 - David Young -- add "type" subcommand to change a partition type
--
PR/47990 - Dr. Wolfgang Stukenbrock -- add "-L <label>" as selector option
--
minor toolification: need libprop...
--
more toolification
--
more toolification changes
--
remove compat defines.
--
Add internal uuid support, since the linux+macos versions of the library
are different than than *bsd ones, and others might not have it at all.
--
Check size of correct buffer. Note, just being pedantic as the buffer
being checked is the same size as the one that should have been checked.
--
correctly show partition type in the new world order
--
actually return the uuid when parsing one that is in numeric format
--
using random values for hdr->hdr_guid does not work very well
--
oops, forgot to update end of data area
--
It's HAVE_NBTOOL_CONFIG_H, not HAVE_NBTOOLS_CONFIG_H
--
Fix tools build on !NetBSD.
--
include <sys/endian.h> for both the non-tools build,
and the tools build on a host where the file exists.
Fixes a build problem on FreeBSD, reported by Herbert J. Skuhra, where
tools/compat's configure detected that be32dec() and friends were
available in the host's <sys/endian.h>, so tools/compat did not provide
its own versions.
--
"0" is not guaranteed to be unique
--
provide a copy of the kernel uuid generator (with portable API calls) for
tools.
--
Allow specifying sector and media size on the command line.
--
Remove trailing whitespace.
--
Make gpt(8) generate v4 (random) uuids.
Don't needlessly leak your date/time and MAC address when you edit
the disk.
Read from /dev/urandom rather than calling arc4random or anything,
since this is a tool. (Cygwin seems to have /dev/urandom, but yell
if this breaks the build on your exotic platform because it lacks
/dev/urandom.)
ok apb
--
Paranoia: choke noisily on EOF from /dev/urandom.
--
Report the argument instead of (null) when opendisk fails.
--
handle constness
--
handle constness better
--
Add some more common partition types.
--
Bump date for previous.
--
Fix handling of -t option for the type command.
Match any type, when no option is given, just like for the label command.
--
Factor out the getdisksize() drvctl method, and provide an alternative that
directly uses the disk ioctl's instead of relying on the drvctl device driver
which is currently not mandatory.
 1.2.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.1 10-Dec-2013  yamt file unset.c was added on branch yamt-pagecache on 2014-05-22 11:37:28 +0000
 1.13.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.13.8.1 09-Apr-2018  bouyer Pull up following revision(s) (requested by mlelstv in ticket #710):
sbin/gpt/main.c: revision 1.11
sbin/gpt/gpt.h: revision 1.37
sbin/gpt/set.c: revision 1.14
sbin/gpt/type.c: revision 1.14
sbin/gpt/unset.c: revision 1.14
sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.
 1.14.2.1 10-Jun-2019  christos Sync with HEAD
 1.15.12.1 02-Aug-2025  perseant Sync with HEAD
 1.4 23-Feb-2025  christos Pass some lint.
 1.3 20-Oct-2024  mlelstv When generating timestamp based GUIDs for reproducable builds
- increment timestamp by 100ns for each partition.
- use the standard time-based UUID format (type 1) and don't
pretend it's a random number (type 4).
- make the -T option actually work for the uuid command.

Random GUIDs:
start size index contents
34 1000 1 GPT part - d93ba067-a788-4ce0-99b8-0ead51f00215
1034 2000 2 GPT part - bebba77a-7fdc-4ca0-a1bf-7450aa871d41

d93ba067-a788-4ce0-99b8-0ead51f00215:
Version 4 Random
Variant 2 RFC 4122
Data D9 3B A0 67 A7 88 4C E0 99 B8 0E AD 51 F0 02 15

bebba77a-7fdc-4ca0-a1bf-7450aa871d41:
Version 4 Random
Variant 2 RFC 4122
Data BE BB A7 7A 7F DC 4C A0 A1 BF 74 50 AA 87 1D 41

Timestamp based GUIDs:
start size index contents
34 1000 1 GPT part - 0a524600-8eba-11ef-8000-000000000000
1034 2000 2 GPT part - 0a524601-8eba-11ef-8000-000000000000

0a524600-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.0Z

0a524601-8eba-11ef-8000-000000000000:
Version 1 Time and MAC based
Variant 2 RFC 4122
Node 00:00:00:00:00:00
Clock 0
Time 2024-10-20T08:05:16.000000.1Z

Node (host MAC address) and clock (sequence number incremented whenever
the time went backwards) are left undefined (all zero) for our purpose.
 1.2 19-Aug-2024  christos Add -U option to specify new UUID
Add OpenBSD
from Anon Ymous
 1.1 25-Jun-2019  jnemeth branches: 1.1.6; 1.1.14;
Add an "uuid" command to generate a new UUID for a portion. The
primary intention is for use for after cloning disks to prevent
collisions.
 1.1.14.1 02-Aug-2025  perseant Sync with HEAD
 1.1.6.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.6.1 25-Jun-2019  martin file uuid.c was added on branch phil-wifi on 2020-04-13 08:03:20 +0000
 1.62 04-Apr-2025  rin ifconfig/Makefile: Makefile.inc -> Makefile.common in comment, NFC

I forgot to update this comment when I renamed Makefile.inc to .common.
 1.61 10-Oct-2017  christos branches: 1.61.16;
user librumpres
 1.60 08-Feb-2017  rin Cosmetic changes. No functional changes.
 1.59 08-Feb-2017  rin Factor out a common part in Makefile's of ifconfig and x_ifconfig.
 1.58 08-Feb-2017  rin Rename sbin/ifconfig/Makefile.inc to Makefile.common; the former can
potentially conflict with bsd.subdir.mk.
 1.57 08-Feb-2017  rin Remove ifconfig hack on m68000. I've confirmed that the problem has already
gone with TME.
 1.56 19-May-2015  ozaki-r branches: 1.56.2; 1.56.4;
Fix rump.ifconfig shows host's interface names in link local addresses
 1.55 28-Apr-2015  christos remove 80211 stats if small.
 1.54 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.53 08-Aug-2012  christos branches: 1.53.2;
don't define RUMP_ACTION if MKRUMP = no
 1.52 14-Aug-2011  christos branches: 1.52.2;
use memcpy to avoid strict aliasing warnings
 1.51 22-Jun-2011  mrg apply some -Wno-error and/or -fno-strict-aliasing.


all of this should be looked at closer, but some of them are not
very trivial.
 1.50 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.49 05-Nov-2010  pooka Need getifaddrs() for the rump client since it executes sysctl(2)
 1.48 04-Nov-2010  pooka Update RUMP_ACTION to use the newstyle rump client.
 1.47 01-Jul-2010  dyoung Apparently, -g belongs in the DBG variable, not in CFLAGS. Make it so
on a line that is commented-out in this makefile.
 1.46 16-Sep-2009  tsutsui - no space needed between -I and dir per gcc(1)
- it's still better to use ${NETBSDSRCDIR} per other existing Makefiles
 1.45 16-Sep-2009  tsutsui Add comments that Makefile.inc should have shared stuff with
src/distrib/utils/x_ifconfig for install media.
 1.44 15-Sep-2009  he Move the addition of pfsync.c from Makefile.inc to Makefile,
so that this part doesn't get included in install media versions
of ifconfig, as per comments on source-changes@ from Izumi Tsutsui.
Also re-instate the use of ${.CURDIR} when setting up the include path.
 1.43 02-Jun-2009  pooka If RUMP_ACTION, treat close() as a rump syscall.
 1.42 26-May-2009  pooka Add compile mode which executes rump system calls. This is useful
when figuring out Where In The Kernel Is Carmen Sandiego's ioctl
for an ifconfig command line, since we can simply single-step into
the kernel.

Activated by "make RUMP_ACTION=1". No changes to normal case.
 1.41 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.40 13-Feb-2009  uebayasi Comment out CFLAGS+=-g.
 1.39 29-Nov-2008  tsutsui branches: 1.39.2;
Specify -fno-loop-optimize on m68000 as workaround for gcc -O1 codegen bug
mentioned in PR bin/40036 and PR toolchain/40066.
 1.38 02-Jul-2008  dyoung branches: 1.38.2;
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.37 12-May-2008  dyoung Per discussion at
<http://mail-index.netbsd.org/tech-net/2008/04/08/msg000371.html>,
let us add, delete, and activate link-layer addresses with ifconfig:

# ifconfig sip0 link 02:00:00:00:00:01 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 active [activate address]
# ifconfig sip0 link 02:00:00:00:00:01 delete [remove address]
 1.36 08-May-2008  dyoung Don't use -pedantic, it stops af_atalk.c and af_iso.c from building
if INET_ONLY is #defined.
 1.35 07-May-2008  dyoung Remove CPPFLAGS that are redundant when WARNS=4.
 1.34 06-May-2008  dyoung branches: 1.34.2;
Add WARNS=4 and a dependency on ${LIBPROP}.
 1.33 06-May-2008  dyoung Take out my CFLAGS settings for debugging.
 1.32 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.31 26-Aug-2006  matt branches: 1.31.18; 1.31.20;
Remove XNS support.
 1.30 18-May-2006  liamjfoy Integrate Common Address Redundancy Procotol (CARP) from OpenBSD

'pseudo-device carp'

Thanks to: joerg@ christos@ riz@ and others who tested
Ok: core@
 1.29 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.28 20-Mar-2005  yamt add a reminder comment for x_ifconfig.
 1.27 20-Mar-2005  thorpej Don't build af_inet6.c if USE_INET6 is no.
 1.26 20-Mar-2005  thorpej Split the IPv4 support into its own file.
 1.25 20-Mar-2005  thorpej Split IPv6 support out into its own file.
 1.24 20-Mar-2005  thorpej Split OSI support off into its own file.
 1.23 19-Mar-2005  thorpej Split XNS support into its own file.
 1.22 19-Mar-2005  thorpej Split off AppleTalk support into its own file.
 1.21 19-Mar-2005  thorpej Split off 802.11 interface handling into its own file.
 1.20 19-Mar-2005  thorpej Split tunnel support into its own file.
 1.19 19-Mar-2005  thorpej Split VLAN configuration bits out into a separate file.
 1.18 18-Mar-2005  yamt add agr(4), a pseudo network device driver for link aggregation.
 1.17 20-Jan-2005  xtraeme Fix the cast for the getnameinfo() call in the status() function, which
should be "const struct" not "struct" for sockaddr.

WARNS=3
 1.16 10-Jan-2005  lukem Only compile in IPv6 support if ${USE_INET6} != "no"

MKINET6 is for providing IPv6 infrastructure.
USE_INET6 is for compiling IPv6 support into the programs (needs MKINET6).
 1.15 28-Oct-2004  dsl More isdigit() calls that need (unsigned char) cast
 1.14 20-Sep-2002  christos use snprintb()
 1.13 28-Apr-2001  itojun assume the presense of getifaddrs(3).
 1.12 13-Apr-2000  itojun use getifaddrs, not SIOCGIFCONF, to avoid alignment constraints.
TODO: maybe it's better to pass struct ifaddrs * to in{,6}_alias.
 1.11 13-Dec-1999  itojun bring in KAME scopeid hack. always show scopeid if it is scoped.
sync with latest KAME.
 1.10 12-Dec-1999  itojun prepare -DKAME_SCOPEID for extended scope id printing (commented out)
 1.9 03-Jul-1999  itojun branches: 1.9.4;
s/CFLAGS/CPPFLAGS/ for -D and -I.
 1.8 01-Jul-1999  itojun make ifconfig IPv6-ready.
TODO: update manpage for new options.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.31.20.1 18-May-2008  yamt sync with head.
 1.31.18.3 17-Jan-2009  mjf Sync with HEAD.
 1.31.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.31.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.34.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.34.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.38.2.2 08-Dec-2010  riz Pull up following revision(s) (requested by uwe in ticket #1490):
usr.bin/mkdep/Makefile: revision 1.16
sbin/dump_lfs/Makefile: revision 1.10
usr.sbin/services_mkdb/Makefile: revision 1.5
sbin/ifconfig/Makefile: revision 1.40
usr.sbin/racoonctl/Makefile: revision 1.3
sbin/sysctl/Makefile: revision 1.18
Comment out CFLAGS+=-g.
Disable debug.
 1.38.2.1 06-Dec-2008  snj Pull up following revision(s) (requested by tsutsui in ticket #164):
sbin/ifconfig/Makefile: revision 1.39
Specify -fno-loop-optimize on m68000 as workaround for gcc -O1 codegen bug
mentioned in PR bin/40036 and PR toolchain/40066.
 1.39.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.52.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.52.2.1 30-Oct-2012  yamt sync with head
 1.53.2.1 23-Jun-2013  tls resync from head
 1.56.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.56.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.61.16.1 02-Aug-2025  perseant Sync with HEAD
 1.8 18-Sep-2025  mrg introduce a couple of new turn-off-gcc-warning variables and use them.

GCC 14 has a new annoying calloc() checker that we turn off in a bunch
of places, and there are a few more dangling-pointer issuse that come up,
but seem bogus.
 1.7 17-May-2021  yamaguchi Add a new link-aggregation pseudo interface named lagg(4)

- FreeBSD's lagg(4) based implementation
- MP-safe and MP-scalable
 1.6 01-Mar-2021  martin branches: 1.6.2;
Make IEEE802.11 support optional
 1.5 02-May-2017  christos We don't need agr or l2tp when we are small.
 1.4 16-Feb-2017  knakahara branches: 1.4.2; 1.4.4; 1.4.6;
add l2tp(4) subcomands to ifconfig(8).

originally implemented by IIJ SEIL team.
 1.3 08-Feb-2017  rin Cosmetic changes. No functional changes.
 1.2 08-Feb-2017  rin Factor out a common part in Makefile's of ifconfig and x_ifconfig.
 1.1 08-Feb-2017  rin Rename sbin/ifconfig/Makefile.inc to Makefile.common; the former can
potentially conflict with bsd.subdir.mk.
 1.4.6.1 11-May-2017  pgoyette Sync with HEAD
 1.4.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.4.4.1 16-Feb-2017  bouyer file Makefile.common was added on branch bouyer-socketcan on 2017-04-21 16:53:13 +0000
 1.4.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.4.2.1 16-Feb-2017  pgoyette file Makefile.common was added on branch pgoyette-localcount on 2017-03-20 06:57:02 +0000
 1.6.2.1 31-May-2021  cjep sync with head
 1.10 08-Feb-2017  rin Rename sbin/ifconfig/Makefile.inc to Makefile.common; the former can
potentially conflict with bsd.subdir.mk.
 1.9 31-Oct-2012  msaitoh branches: 1.9.12; 1.9.16;
Add SIOCGETHERCAP ioctl.
There was no way to know the setting of ec_capabilities and ec_capenable
other than grepping the source.

See http://mail-index.netbsd.org/tech-kern/2010/07/28/msg008613.html
 1.8 13-Dec-2010  pooka branches: 1.8.6; 1.8.12;
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.7 16-Sep-2009  tsutsui Add comments that Makefile.inc should have shared stuff with
src/distrib/utils/x_ifconfig for install media.
 1.6 15-Sep-2009  he Move the addition of pfsync.c from Makefile.inc to Makefile,
so that this part doesn't get included in install media versions
of ifconfig, as per comments on source-changes@ from Izumi Tsutsui.
Also re-instate the use of ${.CURDIR} when setting up the include path.
 1.5 14-Sep-2009  he Change from using ${.CURDIR} to ${NETBSDSRCDIR} because this file
may be included by different parts of the source tree, in particular
deep down in the distrib/ tree, where ../.. isn't sufficient to "climb"
up to the top of the tree. Fixes the build at least for our arc port.
 1.4 14-Sep-2009  degroote Import pfsync support from OpenBSD 4.2

Pfsync interface exposes change in the pf(4) over a pseudo-interface, and can
be used to synchronise different pf.

This work was part of my 2009 GSoC

No objection on tech-net@
 1.3 26-May-2009  pooka Install agr ioctl header and stop putting our hand under the sys skirt
in ifconfig.
 1.2 29-Nov-2008  tsutsui Add RCS Id. XXX why separate Makefile.inc?
 1.1 02-Jul-2008  dyoung branches: 1.1.2; 1.1.4;
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.1.4.3 17-Jan-2009  mjf Sync with HEAD.
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 02-Jul-2008  mjf file Makefile.inc was added on branch mjf-devfs2 on 2008-09-28 11:17:11 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 02-Jul-2008  wrstuden file Makefile.inc was added on branch wrstuden-revivesa on 2008-09-18 04:28:24 +0000
 1.8.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.8.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.9.16.1 21-Apr-2017  bouyer Sync with HEAD
 1.9.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.21 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.20 16-Aug-2019  msaitoh Whitespace fix.
 1.19 19-Oct-2013  christos branches: 1.19.26;
use the new scopeid functions
 1.18 14-Aug-2011  christos branches: 1.18.2; 1.18.8;
use memcpy to avoid strict aliasing warnings
 1.17 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.16 30-Jan-2010  is Use getnameinfo() for printing AppleTalk addresses. While here, fix
printing of broadcast for this address family (AT broadcast is fixed
node 255 on the local net).
 1.15 01-Aug-2008  dyoung is@ pointed out that I set the phase and range of a sockaddr_at
without subsequently doing anything with it, so commit_address()
works with an address with phase == 0. phase == 0 is not allowed,
hence

random84# ifconfig nfe0 atalk 3.14
ifconfig: SIOCAIFADDR: Invalid argument

Solution: copy the new sockaddr_at to a temporary input environment,
and pass that environment to commit_address(). I may as well copy
the new sockaddr_at to the output environment, while I am at it.
 1.14 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.13 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.12 11-May-2008  dyoung Start to adapt the AppleTalk module to use commit_address().
 1.11 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.10 06-May-2008  dyoung branches: 1.10.2;
Use prop_dictionary_util(3).
 1.9 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.8 06-May-2008  dyoung If the address family is not set, assume AF_APPLETALK. Exit
at_status() quietly if the address family is set, and it is not
set to AF_APPLETALK.
 1.7 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.6 15-Apr-2008  dyoung branches: 1.6.2;
Cosmetic: write strcmp() == 0 instead of !strcmp().
 1.5 11-Apr-2008  dyoung Cosmeticc: there's no use casting a uint16_t to a u_short, so don't
do that. Change indentation for readability.
 1.4 26-Aug-2006  christos branches: 1.4.18;
Programs that use efun.
 1.3 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.2 14-Jun-2006  tron Adapt ifconfig(8) to new return value from socket(2). This stops
ifconfig(8) from printing errors like "ifconfig: socket: Address
family not supported by protocol family" when examining the status
of a network interface.
 1.1 19-Mar-2005  thorpej Split off AppleTalk support into its own file.
 1.4.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.4.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.10.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.18.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19.26.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.5 11-May-2008  dyoung Start to adapt the AppleTalk module to use commit_address().
 1.4 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.2 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1 19-Mar-2005  thorpej branches: 1.1.20; 1.1.22;
Split off AppleTalk support into its own file.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.28 14-May-2020  msaitoh Remove extra semicolon.
 1.27 10-Apr-2020  plunky trim extraneous return statement
 1.26 16-Aug-2019  msaitoh Whitespace fix.
 1.25 11-Jun-2018  kamil branches: 1.25.2;
Correct Undefined Behavior in ifconfig(8)

Unportable left shift reported with MKSANITIZER=yes USE_SANITIZER=undefined:

# ifconfig
alc0: flags=0x8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ec_capabilities=3<VLAN_MTU,VLAN_HWTAGGING>
ec_enabled=0
address: xx:xx:xx:xx:xx:xx
/public/src.git/sbin/ifconfig/af_inet.c:102:34: runtime error: left shift of 16777215 by 8 places cannot be represented in type 'int'
inet 192.168.0.38/24 broadcast 192.168.0.255 flags 0x0
inet6 xxxx::xxxx:xxxx:xxxx:xxx%alc0/64 flags 0x0 scopeid 0x1
lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33624
inet 127.0.0.1/8 flags 0x0
inet6 ::1/128 flags 0x20<NODAD>
inet6 fe80::1%lo0/64 flags 0x0 scopeid 0x2

Change shifting left 1 to shifting 1U. This corrects the issue.

if (cidr < 32) { /* more than 1 bit in mask */
/* check for non-contig netmask */
if ((mask ^ (((1 << cidr) - 1) << (32 - cidr))) != 0) // <- here
return -1; /* noncontig, no pfxlen */
}

Solution suggested by <uwe>

Sponsored by <The NetBSD Foundation>
 1.24 01-Oct-2016  kre branches: 1.24.12;

Return to printing explicit "netmask 0x...." in the case that the
mask set is non-contiguous. We don't prohibit setting such things
(even if they are basically useless) so they can be set by accident.
ifconfig ifN 10.0.0.1 netmask 225.0.0.0
produced
ifN .. inet 10.0.0.1/8
with the previous form (since 225 is 0xE1), now it produces
ifN ... inet 10.0.0.1 netmask 0xe1000000

If the "netmask" form ever appears in ifconfig output, it (now)
means that the netmask is non-contig, which should make that case
obvious (whther intended, or set by accident)
 1.23 01-Oct-2016  roy Modernise the output for the address to address/prefix instead
of differring outputs for INET and INET6.
The hex string of the INET netmask was particulary hard to read.
 1.22 30-Sep-2016  roy Remove the alias keyword from ifconfig output as it serves no purpose.
 1.21 30-Sep-2016  roy ifaddrs has more data than just the address.
Use it instead of making pointless ioctl calls.
 1.20 13-Sep-2016  christos print address flag bits using snprintb
 1.19 29-Feb-2016  riastradh branches: 1.19.2;
Consistently use estrlcpy for ifr.ifr_name here, not strncpy.
 1.18 07-Jan-2016  roy -W seconds will wait for the detached flag to clear on addresses on
interfaces marked up to allow time for the carrier to appear on the
interface.

This does not extend the -w option duration.
 1.17 12-May-2015  roy ioctl -> prog_ioctl as pointed out by pooka@
 1.16 02-May-2015  roy Report IN_IFF_TENTATIVE and friends.
Wait for IN_IFF_TENTATIVE to be removed with the -w flag.
 1.15 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.14 11-Sep-2009  dyoung Make ifconfig(8) set and display preference numbers for IPv6
addresses. Make the kernel support SIOC[SG]IFADDRPREF for IPv6
interface addresses.

In in6ifa_ifpforlinklocal(), consult preference numbers before
making an otherwise arbitrary choice of in6_ifaddr. Otherwise,
preference numbers are *not* consulted by the kernel, but that will
be rather easy for somebody with a little bit of free time to fix.

Please note that setting the preference number for a link-local
IPv6 address does not work right, yet, but that ought to be fixed
soon.

In support of the changes above,

1 Add a method to struct domain for "externalizing" a sockaddr, and
provide an implementation for IPv6. Expect more work in this area: it
may be more proper to say that the IPv6 implementation "internalizes"
a sockaddr. Add sockaddr_externalize().

2 Add a subroutine, sofamily(), that returns a struct socket's address
family or AF_UNSPEC.

3 Make a lot of IPv4-specific code generic, and move it from
sys/netinet/ to sys/net/ for re-use by IPv6 parts of the kernel and
ifconfig(8).
 1.13 07-Aug-2009  dyoung Use getnameinfo(3) instead of inet_ntoa(3) to convert IPv4 addresses
to names.
 1.12 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.11 12-May-2008  dyoung Make prototype and definition of in_alias() agree: it's static.
 1.10 11-May-2008  dyoung Don't export in_alias(). Pass in_alias() a more useful template.
Misc. cosmetic changes. Delete dead code. Treat the address
preference as int16_t, since that is its real type.
 1.9 11-May-2008  dyoung Let the address family modules zero initialize their own ifreqs,
instead of zeroing them in commit_address().

Switch to in6_commit_address() from in6_getprefix() and in6_getaddr().

Temporarily add some debugging code to setia6eui64_impl().
 1.8 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.7 06-May-2008  dyoung branches: 1.7.2;
Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.6 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.5 13-Nov-2006  dyoung branches: 1.5.18; 1.5.20;
Add a source-address selection policy mechanism to the kernel.

Also, add ioctls SIOCGIFADDRPREF/SIOCSIFADDRPREF to get/set preference
numbers for addresses. Make ifconfig(8) set/display preference
numbers.

To activate source-address selection policies in your kernel, add
'options IPSELSRC' to your kernel configuration.

Miscellaneous changes in support of source-address selection:

1 Factor out some common code, producing rt_replace_ifa().

2 Abbreviate a for-loop with TAILQ_FOREACH().

3 Add the predicates on IPv4 addresses IN_LINKLOCAL() and
IN_PRIVATE(), that are true for link-local unicast
(169.254/16) and RFC1918 private addresses, respectively.
Add the predicate IN_ANY_LOCAL() that is true for link-local
unicast and multicast.

4 Add IPv4-specific interface attach/detach routines,
in_domifattach and in_domifdetach, which build #ifdef
IPSELSRC.

See in_getifa(9) for a more thorough description of source-address
selection policy.
 1.4 26-Aug-2006  christos Programs that use efun.
 1.3 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.2 14-Jun-2006  tron Adapt ifconfig(8) to new return value from socket(2). This stops
ifconfig(8) from printing errors like "ifconfig: socket: Address
family not supported by protocol family" when examining the status
of a network interface.
 1.1 20-Mar-2005  thorpej Split the IPv4 support into its own file.
 1.5.20.1 18-May-2008  yamt sync with head.
 1.5.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.5.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.24.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.25.2.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.7 12-May-2008  dyoung setifipdst() is gone, so delete the prototype. #include nothing
(XXX).
 1.6 11-May-2008  dyoung Don't export in_alias(). Pass in_alias() a more useful template.
Misc. cosmetic changes. Delete dead code. Treat the address
preference as int16_t, since that is its real type.
 1.5 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.4 06-May-2008  dyoung branches: 1.4.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.3 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.2 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1 20-Mar-2005  thorpej branches: 1.1.20; 1.1.22;
Split the IPv4 support into its own file.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.4.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.39 16-Aug-2019  msaitoh Whitespace fix.
 1.38 01-Oct-2016  roy branches: 1.38.14;
Modernise the output for the address to address/prefix instead
of differring outputs for INET and INET6.
The hex string of the INET netmask was particulary hard to read.
 1.37 30-Sep-2016  roy ifaddrs has more data than just the address.
Use it instead of making pointless ioctl calls.
 1.36 13-Sep-2016  christos print address flag bits using snprintb
 1.35 29-Feb-2016  riastradh branches: 1.35.2;
Consistently use estrlcpy for ifr.ifr_name here, not strncpy.
 1.34 07-Jan-2016  roy -W seconds will wait for the detached flag to clear on addresses on
interfaces marked up to allow time for the carrier to appear on the
interface.

This does not extend the -w option duration.
 1.33 12-May-2015  roy ioctl -> prog_ioctl as pointed out by pooka@
 1.32 22-Apr-2015  roy Move the INET6 specific code for wait_dad_exec() into af_inet6
by using a new afswtch hook af_addr_tentative.
 1.31 20-Jan-2015  roy Display the IPv6 address flags autoconf and temporary
 1.30 20-Oct-2014  roy Remove the ability for userland to toggle IN6_IFF_TENTATIVE.
Preserve IN6_IFF_TENTATIVE when updating address flags.
 1.29 19-Oct-2013  christos branches: 1.29.4;
use symbolic flags
 1.28 19-Oct-2013  christos use the new scopeid functions
 1.27 13-Dec-2010  pooka branches: 1.27.6; 1.27.12;
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.26 22-Jan-2010  dyoung Compare a pointer with NULL instead of testing its "truth."
 1.25 11-Sep-2009  dyoung Make ifconfig(8) set and display preference numbers for IPv6
addresses. Make the kernel support SIOC[SG]IFADDRPREF for IPv6
interface addresses.

In in6ifa_ifpforlinklocal(), consult preference numbers before
making an otherwise arbitrary choice of in6_ifaddr. Otherwise,
preference numbers are *not* consulted by the kernel, but that will
be rather easy for somebody with a little bit of free time to fix.

Please note that setting the preference number for a link-local
IPv6 address does not work right, yet, but that ought to be fixed
soon.

In support of the changes above,

1 Add a method to struct domain for "externalizing" a sockaddr, and
provide an implementation for IPv6. Expect more work in this area: it
may be more proper to say that the IPv6 implementation "internalizes"
a sockaddr. Add sockaddr_externalize().

2 Add a subroutine, sofamily(), that returns a struct socket's address
family or AF_UNSPEC.

3 Make a lot of IPv4-specific code generic, and move it from
sys/netinet/ to sys/net/ for re-use by IPv6 parts of the kernel and
ifconfig(8).
 1.24 07-Aug-2009  dyoung Add option -N. -N is just the opposite of option -n in netstat(8)
or route(8): it tells ifconfig(8) to try to resolve numbers to
hosts and service names.

This default ifconfig behavior stays the same as it always was.
 1.23 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.22 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.21 12-May-2008  dyoung Retire in6_addreq and in6_ridreq, which we do not use in the
commit_address() regime.
 1.20 12-May-2008  dyoung Initialize IPv6 addresses and ifreqs with more rigor. Fixes this
bug reported by Matthias Scheler,

# ifconfig sip0 inet6 fdb4:542d:dc11:ec20::1
ifconfig: SIOCAIFADDR_IN6: Invalid argument
# ifconfig sip0 inet6 fdb4:542d:dc11:ec20::1 prefixlen 64
 1.19 11-May-2008  dyoung Get rid of sec2str() altogether.
 1.18 11-May-2008  dyoung In in6_alias(), instead of repeating the memset()/estrlcpy()/sockaddr_in6
assignment-dance, copy creq to ifr6 before each ioctl().
 1.17 11-May-2008  dyoung Delete unused array sin6tab[]. Delete unnecessary casts.
 1.16 11-May-2008  dyoung Delete dead code in sec2str().
 1.15 11-May-2008  dyoung Retire some code that in6_commit_address() replaces.
 1.14 11-May-2008  dyoung Let the address family modules zero initialize their own ifreqs,
instead of zeroing them in commit_address().

Switch to in6_commit_address() from in6_getprefix() and in6_getaddr().

Temporarily add some debugging code to setia6eui64_impl().
 1.13 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.12 07-May-2008  dyoung Move IPv6 syntax to af_inet6.c from ifconfig.c. Move IFKW() macro
from ifconfig.c to parse.h for reuse.
 1.11 07-May-2008  dyoung Fix a bug that I introduced in rev 1.88, where the default IPv6
prefix length changed from 64 to 128. While I am here, allow an
address to be given with prefix length /0, but interpret it as
/128.
 1.10 06-May-2008  dyoung branches: 1.10.2;
Use prop_dictionary_util(3).
 1.9 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.8 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.7 24-Apr-2008  dyoung Don't cast memset(3) to void. Remove a needless cast to struct
in6_addr *.
 1.6 15-Apr-2008  dyoung branches: 1.6.2;
Use static initializers to setup ISO and IPv6 addresses, instead
of calling protocol family-specific routines from main().
 1.5 26-Aug-2006  christos branches: 1.5.16; 1.5.18;
Programs that use efun.
 1.4 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.3 14-Jun-2006  tron Adapt ifconfig(8) to new return value from socket(2). This stops
ifconfig(8) from printing errors like "ifconfig: socket: Address
family not supported by protocol family" when examining the status
of a network interface.
 1.2 20-Mar-2005  thorpej Remove an #ifdef that is no longer necessary.
 1.1 20-Mar-2005  thorpej Split IPv6 support out into its own file.
 1.5.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.5.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.16.1 22-Feb-2008  keiichi imported Mobile IPv6 code developed by the SHISA project
(http://www.mobileip.jp/).
 1.6.2.1 18-May-2008  yamt sync with head.
 1.10.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.27.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.27.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.29.4.2 23-Jan-2015  martin Pull up following revision(s) (requested by pettai in ticket #442):
sbin/ifconfig/af_inet6.c: revision 1.31
Display the IPv6 address flags autoconf and temporary
 1.29.4.1 27-Oct-2014  martin Pull up following revision(s) (requested by roy in ticket #160):
sbin/ifconfig/af_inet6.c: revision 1.30
sbin/ifconfig/ifconfig.8: revision 1.109
sys/netinet6/in6.c: revision 1.177
Remove the ability for userland to toggle IN6_IFF_TENTATIVE.
Preserve IN6_IFF_TENTATIVE when updating address flags.
 1.35.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.38.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.8 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.7 03-Jun-2008  dyoung Remove remnants of struct afswtch.af_getprefix().
 1.6 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.5 07-May-2008  dyoung Move IPv6 syntax to af_inet6.c from ifconfig.c. Move IFKW() macro
from ifconfig.c to parse.h for reuse.
 1.4 06-May-2008  dyoung branches: 1.4.2;
Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.3 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.2 11-May-2006  mrg branches: 1.2.20; 1.2.22;
remove extern for unused ifr6.
 1.1 20-Mar-2005  thorpej Split IPv6 support out into its own file.
 1.2.22.2 17-Jun-2008  yamt sync with head.
 1.2.22.1 18-May-2008  yamt sync with head.
 1.2.20.3 28-Sep-2008  mjf Sync with HEAD.
 1.2.20.2 29-Jun-2008  mjf Sync with HEAD.
 1.2.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.4.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.23 17-Aug-2022  nat Revert to previous as the atf tests are still failing.
 1.22 17-Aug-2022  nat Use existing address when setting parameters.

No need to specify address every time when setting broadcast address or
netmask.

Hopefully successfully re addresses PR bin/10911.
 1.21 16-Aug-2022  nat Revert to previous as atf tests were failing.
 1.20 16-Aug-2022  nat No need address every time to specify broadcast and netmask.

Previously ifconfig would fail silently.

Addresses PR bin/10911.
 1.19 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.18 16-Aug-2019  msaitoh Whitespace fix.
 1.17 30-Dec-2012  christos branches: 1.17.30;
fix function name in error messages.
 1.16 30-Dec-2012  christos PR/46579: Takahiro HAYASHI: ifconfig clone destroy should not print useless
diagnostic and exit with an error code. Get the interface name and flags
opportunistically to allow the code to return normally if it does not need
to do anything.
 1.15 17-Mar-2012  christos branches: 1.15.2;
PR/43141: Tobias Nygren: Print an error on unknown interfaces.
 1.14 24-May-2011  joerg branches: 1.14.4; 1.14.6;
Don't use address strings as format string.
 1.13 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.12 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.11 03-Jun-2008  dyoung *Always* pass the prefix mask specified on the command line, even
on an IFF_POINTOPOINT interface. Patch tested by John Klos and
found to fix the bug he reported on tech-net@, "Subject: Can't use
gif in -current".
 1.10 02-Jun-2008  dyoung Cosmetic: add missing /*FALLTHROUGH*/.
 1.9 28-May-2008  dyoung branches: 1.9.2;
Fix kern/38775, "ifconfig inet delete fails".
 1.8 16-May-2008  dyoung branches: 1.8.2;
Apply netmasks to !(IFF_BROADCAST|IFF_POINTOPOINT) interfaces as
well as to IFF_BROADCAST interfaces. Fixes the bug reported by
Markus W Kilbinger,

ifconfig stf0 inet6 2002:xxxx:76ec:0001::1 prefixlen 16 alias

results in the wrong configuration,

stf0: flags=1<UP> mtu 1280
inet6 2002:xxxx:76ec:1::1 prefixlen 64
 1.7 12-May-2008  dyoung Apply the right copyright notice.
 1.6 11-May-2008  dyoung Let the address family modules zero initialize their own ifreqs,
instead of zeroing them in commit_address().

Switch to in6_commit_address() from in6_getprefix() and in6_getaddr().

Temporarily add some debugging code to setia6eui64_impl().
 1.5 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.4 06-May-2008  dyoung branches: 1.4.2;
Use prop_dictionary_util(3).
 1.3 06-May-2008  dyoung Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.2 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.1 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.4.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.4.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.2.3 04-Jun-2008  yamt sync with head
 1.8.2.2 18-May-2008  yamt sync with head.
 1.8.2.1 16-May-2008  yamt file af_inetany.c was added on branch yamt-pf42 on 2008-05-18 12:30:52 +0000
 1.9.2.4 28-Sep-2008  mjf Sync with HEAD.
 1.9.2.3 29-Jun-2008  mjf Sync with HEAD.
 1.9.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.9.2.1 28-May-2008  mjf file af_inetany.c was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.14.6.1 08-Feb-2013  riz Pull up following revision(s) (requested by christos in ticket #799):
sbin/ifconfig/af_inetany.c: revision 1.16
PR/46579: Takahiro HAYASHI: ifconfig clone destroy should not print useless
diagnostic and exit with an error code. Get the interface name and flags
opportunistically to allow the code to return normally if it does not need
to do anything.
 1.14.4.2 23-Jan-2013  yamt sync with head
 1.14.4.1 17-Apr-2012  yamt sync with head
 1.15.2.1 25-Feb-2013  tls resync with head
 1.17.30.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.3 12-May-2008  dyoung branches: 1.3.2; 1.3.4; 1.3.6;
Apply the right copyright notice.
 1.2 11-May-2008  dyoung Let the address family modules zero initialize their own ifreqs,
instead of zeroing them in commit_address().

Switch to in6_commit_address() from in6_getprefix() and in6_getaddr().

Temporarily add some debugging code to setia6eui64_impl().
 1.1 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.3.6.3 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.6.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.3.6.1 12-May-2008  wrstuden file af_inetany.h was added on branch wrstuden-revivesa on 2008-06-23 05:02:12 +0000
 1.3.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.3.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.3.4.1 12-May-2008  mjf file af_inetany.h was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.3.2.2 18-May-2008  yamt sync with head.
 1.3.2.1 12-May-2008  yamt file af_inetany.h was added on branch yamt-pf42 on 2008-05-18 12:30:52 +0000
 1.15 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.14 13-Dec-2010  pooka branches: 1.14.6; 1.14.12;
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.13 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.12 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.11 08-May-2008  dyoung Delete #if 0'd code.
 1.10 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.9 06-May-2008  dyoung branches: 1.9.2;
Extract subroutine do_setifcaps() and fix the bug that uwe@ reported
in capabilities-setting.

Use prop_dictionary_util(3).

Rename the parser snpaoffset to parse_snpaoffset.
 1.8 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.7 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.6 15-Apr-2008  dyoung branches: 1.6.2;
Use static initializers to setup ISO and IPv6 addresses, instead
of calling protocol family-specific routines from main().
 1.5 11-Apr-2008  dyoung Cosmetic: compare socket address family with AF_UNSPEC instead of
0.
 1.4 26-Aug-2006  christos branches: 1.4.18;
Programs that use efun.
 1.3 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.2 14-Jun-2006  tron Adapt ifconfig(8) to new return value from socket(2). This stops
ifconfig(8) from printing errors like "ifconfig: socket: Address
family not supported by protocol family" when examining the status
of a network interface.
 1.1 20-Mar-2005  thorpej Split OSI support off into its own file.
 1.4.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.4.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.9.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.9.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.12.1 23-Jun-2013  tls resync from head
 1.14.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.6 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.5 06-May-2008  dyoung branches: 1.5.2;
Extract subroutine do_setifcaps() and fix the bug that uwe@ reported
in capabilities-setting.

Use prop_dictionary_util(3).

Rename the parser snpaoffset to parse_snpaoffset.
 1.4 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.3 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.2 15-Apr-2008  dyoung branches: 1.2.2;
Use static initializers to setup ISO and IPv6 addresses, instead
of calling protocol family-specific routines from main().
 1.1 20-Mar-2005  thorpej branches: 1.1.20;
Split OSI support off into its own file.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.2.1 18-May-2008  yamt sync with head.
 1.5.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.5.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8 16-Aug-2019  msaitoh Whitespace fix.
 1.7 19-Jan-2014  matt branches: 1.7.26;
Rename link to link_pkw to avoid shadowing the link syscall.
 1.6 21-Apr-2009  dyoung branches: 1.6.6; 1.6.12;
To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
 1.5 21-Apr-2009  dyoung Use getnameinfo(3) to render a human-readable link-layer address in the
'address: ' line, just as we do in the 'link xx:xx:...:xx' line.
 1.4 21-Apr-2009  dyoung Fix indentation: change spaces to tabs.
 1.3 02-Jul-2008  dyoung branches: 1.3.2; 1.3.4; 1.3.8;
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.2 13-May-2008  dyoung branches: 1.2.2; 1.2.4; 1.2.6;
Use an AF_LINK socket to add/delete/get link-layer addresses.
 1.1 12-May-2008  dyoung Per discussion at
<http://mail-index.netbsd.org/tech-net/2008/04/08/msg000371.html>,
let us add, delete, and activate link-layer addresses with ifconfig:

# ifconfig sip0 link 02:00:00:00:00:01 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 active [activate address]
# ifconfig sip0 link 02:00:00:00:00:01 delete [remove address]
 1.2.6.3 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.6.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.2.6.1 13-May-2008  wrstuden file af_link.c was added on branch wrstuden-revivesa on 2008-06-23 05:02:12 +0000
 1.2.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.2.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.2.4.1 13-May-2008  mjf file af_link.c was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.2.2.2 18-May-2008  yamt sync with head.
 1.2.2.1 13-May-2008  yamt file af_link.c was added on branch yamt-pf42 on 2008-05-18 12:30:52 +0000
 1.3.8.1 21-Apr-2010  matt sync to netbsd-5
 1.3.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.3.2.1 03-May-2009  bouyer Pull up following revision(s) (requested by dyoung in ticket #730):
sbin/ifconfig/af_link.c: revisions 1.4 - 1.6
sbin/ifconfig/util.h: revision 1.7
sbin/ifconfig/util.c: revisions 1.10, 1.11
lib/libc/net/getifaddrs.c: revision 1.12
lib/libc/net/getifaddrs.3: revision 1.10
sbin/ifconfig/ifconfig.c: revisions 1.216 - 1.218
Fix indentation: change spaces to tabs.
Use getnameinfo(3) to render a human-readable link-layer address in the
'address: ' line, just as we do in the 'link xx:xx:...:xx' line.
There's no use casting a socket address to sockaddr_dl, only to cast it
back to sockaddr, so don't do it.
Cosmetic: add some whitespace for my ease of reading.
To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
For non-AF_LINK ifaddrs, ifa_data is NULL. AFAICT, this has always been
so. Say so in the documentation.
Bring getifaddrs(3) behavior in line with the documentation: the
ifa_data member of every AF_LINK struct ifaddrs points at the
corresponding struct if_data. In ifconfig(8), do not try to suppress
duplicate AF_LINK ifaddrs by checking for a NULL ifa_data.
Don't copy out two AF_LINK struct ifaddrs for each active link-layer
address. getifaddrs(3) used to copy out one ifaddrs for the kernel's
RTM_IFINFO message, and one more for the kernel's RTM_NEWADDR message.
I suppress the first duplicate with a highly conservative change that
wastes a little bit of ifaddrs storage. The storage is not leaked.
 1.6.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.26.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.1 12-May-2008  dyoung branches: 1.1.2; 1.1.4; 1.1.6;
Per discussion at
<http://mail-index.netbsd.org/tech-net/2008/04/08/msg000371.html>,
let us add, delete, and activate link-layer addresses with ifconfig:

# ifconfig sip0 link 02:00:00:00:00:01 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 active [activate address]
# ifconfig sip0 link 02:00:00:00:00:01 delete [remove address]
 1.1.6.3 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.1.6.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.1.6.1 12-May-2008  wrstuden file af_link.h was added on branch wrstuden-revivesa on 2008-06-23 05:02:12 +0000
 1.1.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.1 12-May-2008  mjf file af_link.h was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.1.2.2 18-May-2008  yamt sync with head.
 1.1.2.1 12-May-2008  yamt file af_link.h was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.5 26-Aug-2006  matt Remove XNS support.
 1.4 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.3 14-Jun-2006  tron Adapt ifconfig(8) to new return value from socket(2). This stops
ifconfig(8) from printing errors like "ifconfig: socket: Address
family not supported by protocol family" when examining the status
of a network interface.
 1.2 20-Mar-2005  thorpej Move a comment.
 1.1 19-Mar-2005  thorpej Split XNS support into its own file.
 1.2 26-Aug-2006  matt Remove XNS support.
 1.1 19-Mar-2005  thorpej Split XNS support into its own file.
 1.16 21-Jun-2021  christos fix proplib deprecation
 1.15 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.14 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.13 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.12 19-May-2008  dyoung Fix two bugs:

1 Let us associate a keyword with either a signed or an unsigned
number. Associate the '-chan' keyword with an unsigned number.
This fixes the defect that crashed 'ifconfig wi0 -chan', reported
by Michael van Elst.

2 Do not try to interpret names as ISO addresses unless the ISO
address family was specified. iso_addr(3) does not report errors,
so it appears to interpret *everything* as an ISO address. This
is a stopgap fix for the defect in 'ifconfig lo0 inet6' on a
!INET6 kernel that deletes the first IPv4 address on lo0.
(Reported by Scott Ellis.)
 1.11 09-May-2008  dyoung Repair agr(4) syntax. Should fix PR bin/38600.
 1.10 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.9 07-May-2008  dyoung Move net80211 and agr(4) syntax out of ifconfig.c and into ieee80211.c
and agr.c, respectively.
 1.8 07-May-2008  yamt branches: 1.8.2;
agrsetport: fix a use of uninitialized variable.
 1.7 06-May-2008  dyoung Use prop_dictionary_util(3).
 1.6 06-May-2008  dyoung Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.5 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.4 22-Apr-2008  dyoung Copy a const string to a temporary buffer instead of using __UNCONST().

Cosmetic: get rid of superflous curly braces and cast to (void *).
 1.3 19-Mar-2005  thorpej branches: 1.3.20; 1.3.22;
name -> ifname (avoid shadow decl with global name[]).
 1.2 19-Mar-2005  thorpej Move extern decls to extern.h
 1.1 18-Mar-2005  yamt add agr(4), a pseudo network device driver for link aggregation.
 1.3.22.2 04-Jun-2008  yamt sync with head
 1.3.22.1 18-May-2008  yamt sync with head.
 1.3.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.3.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.4 07-May-2008  dyoung Move net80211 and agr(4) syntax out of ifconfig.c and into ieee80211.c
and agr.c, respectively.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.2 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1 18-Mar-2005  yamt branches: 1.1.20; 1.1.22;
add agr(4), a pseudo network device driver for link aggregation.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.15 26-Mar-2023  mlelstv Fix parser for carp state.
The state values are uppercase words INIT, BACKUP and MASTER.
 1.14 07-Jun-2020  thorpej branches: 1.14.6;
Update for proplib(3) API changes.
 1.13 11-Sep-2009  dyoung This should fix 'carpdev <ifname>' or, at least, not break it more
badly than before.
 1.12 15-Jul-2008  dyoung branches: 1.12.2; 1.12.6; 1.12.10;
Cosmetic: s/xenv/oenv/
 1.11 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.10 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.9 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.8 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.7 06-May-2008  dyoung branches: 1.7.2;
Use prop_dictionary_util(3).
 1.6 06-May-2008  dyoung Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.5 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.4 22-Apr-2008  dyoung Delete some gratuitous casts, s/(char *)//.
 1.3 21-Apr-2008  dyoung s/(caddr_t)//
 1.2 21-Apr-2008  dyoung Change bzero calls to memset calls.
 1.1 18-May-2006  liamjfoy branches: 1.1.20; 1.1.22;
Integrate Common Address Redundancy Procotol (CARP) from OpenBSD

'pseudo-device carp'

Thanks to: joerg@ christos@ riz@ and others who tested
Ok: core@
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.12.10.1 16-Oct-2011  riz Pull up following revision(s) (requested by bouyer in ticket #1670):
sbin/ifconfig/carp.c: revision 1.13
This should fix 'carpdev &lt;ifname&gt;' or, at least, not break it more
badly than before.
 1.12.6.1 16-Oct-2011  riz Pull up following revision(s) (requested by bouyer in ticket #1670):
sbin/ifconfig/carp.c: revision 1.13
This should fix 'carpdev &lt;ifname&gt;' or, at least, not break it more
badly than before.
 1.12.2.1 16-Oct-2011  riz Pull up following revision(s) (requested by bouyer in ticket #1670):
sbin/ifconfig/carp.c: revision 1.13
This should fix 'carpdev &lt;ifname&gt;' or, at least, not break it more
badly than before.
 1.14.6.1 21-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #902):

sbin/ifconfig/carp.c: revision 1.15
sbin/ifconfig/ifconfig.8: revision 1.125
tests/net/carp/t_basic.sh: revision 1.9
sys/netinet/ip_carp.c: revision 1.118
sys/netinet/ip_carp.c: revision 1.119

Fix parser for carp state.

The state values are uppercase words INIT, BACKUP and MASTER.

Use backing device to send advertisements. Otherwise the packets originate
from the virtual MAC address, which confuses switches.

Select virtual address as sender if backing interface is anonymous.

Use correct scope for IPv6.

Don't expect the net/carp/t_basic/carp_handover_ipv6_halt_nocarpdevip
and carp_handover_ipv6_ifdown_nocarpdevip test cases to fail. At
least on the TNF i386 and amd64 testbeds, they pass more often than
not since the commit of src/sys/netinet/ip_carp.c 1.119 by mlelstv on
2023.04.07.06.44.08.
 1.5 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.4 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.2 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1 18-May-2006  liamjfoy branches: 1.1.20; 1.1.22;
Integrate Common Address Redundancy Procotol (CARP) from OpenBSD

'pseudo-device carp'

Thanks to: joerg@ christos@ riz@ and others who tested
Ok: core@
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14 21-Jun-2021  christos fix proplib deprecation
 1.13 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.12 16-Aug-2019  msaitoh Whitespace fix.
 1.11 07-Mar-2016  christos branches: 1.11.16;
PR/50909: David Binderman: Optimize memset
 1.10 07-Mar-2016  christos PR/50909: David Binderman: Optimize memset
 1.9 07-Feb-2013  apb Avoid dereferencing NULL. Coverity CID 275201.
Also fix a typo in previous: !== should be !=
 1.8 07-Feb-2013  apb Don't call prop_distionary_make_immutable on a NULL pointer.
Coverity CID 275179.
 1.7 13-Dec-2010  pooka branches: 1.7.6; 1.7.12;
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.6 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.5 12-May-2008  dyoung branches: 1.5.2; 1.5.4;
Cosmetic: fix copyright whitespace.
 1.4 09-May-2008  dyoung Use the correct key. Spotted by NONAKA Kimihiro.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3).
 1.2 06-May-2008  dyoung Add a license.
 1.1 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.3.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.5.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.5.4.1 12-May-2008  mjf file env.c was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.5.2.2 18-May-2008  yamt sync with head.
 1.5.2.1 12-May-2008  yamt file env.c was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.7.12.1 25-Feb-2013  tls resync with head
 1.7.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 30-Jun-2019  sevan Add rcsid
 1.3 04-Nov-2010  pooka branches: 1.3.46;
Update RUMP_ACTION to use the newstyle rump client.
 1.2 26-May-2009  pooka Add compile mode which executes rump system calls. This is useful
when figuring out Where In The Kernel Is Carmen Sandiego's ioctl
for an ifconfig command line, since we can simply single-step into
the kernel.

Activated by "make RUMP_ACTION=1". No changes to normal case.
 1.1 06-May-2008  dyoung branches: 1.1.4; 1.1.6;
Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.6.1 06-May-2008  mjf file env.h was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.1.4.2 18-May-2008  yamt sync with head.
 1.1.4.1 06-May-2008  yamt file env.h was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.3.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.8 02-Jan-2020  ryo fix printing capabilities and enabled flags.

no need to skip a prefix "0x" of output of snprintb.
ifconfig expect the result of snprintb has "0x" prefix, but snprintb(3) specification has changed
so that if 0 is passed, it prints "0" instead of "0x0". (common/lib/libutil/snprintb.c r1.22)
 1.7 16-Aug-2019  msaitoh Whitespace fix.
 1.6 17-Jul-2019  msaitoh Implement VLAN hardware filter function(ETHERCAP_VLAN_HWFILTER).
First proposed by jmcneill in 2017 and modified by me.

How to use:

- Set callback function:

ether_set_vlan_cb(struct ethercom *, ether_vlancb_t)

- Callback. This function is called when a vlan is attached/detached to the
parent interface:

int (*ether_vlancb_t)(struct ethercom *ec, uint16_t vlanid, bool set);

- ifconfig(8)

ifconfig ixg0 [-]vlan-hwfilter

Note that ETHERCAP_VLAN_HWFILTER is set by default on ixg(4) because
the PF driver usually enable "all block" filter by default.
 1.5 17-Jul-2019  msaitoh KNF. No functional change.
 1.4 08-Jul-2019  msaitoh Add "ifconfig [-]vlan-hwtagging" to enable/disable VLAN hardware tagging
offload function. It's useful to see Ethernet frame's VLAN tag by
disabling with "ifconfig fooX -vlan-hwtagging" and "tcpdump -e -i fooX".
 1.3 21-Dec-2018  msaitoh Add SIOCSETHERCAP. It's used to change ec_capenable.
 1.2 01-Nov-2012  pgoyette branches: 1.2.2; 1.2.4; 1.2.32; 1.2.34;
Use snprintb_m(3) to split flags/capabilities/enabled across multiple
output lines.

As discussed on current-users
 1.1 31-Oct-2012  msaitoh Add SIOCGETHERCAP ioctl.
There was no way to know the setting of ec_capabilities and ec_capenable
other than grepping the source.

See http://mail-index.netbsd.org/tech-kern/2010/07/28/msg008613.html
 1.2.34.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.34.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.34.1 10-Jun-2019  christos Sync with HEAD
 1.2.32.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.2.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.2.4.1 01-Nov-2012  yamt file ether.c was added on branch yamt-pagecache on 2013-01-16 05:32:33 +0000
 1.2.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.2.1 01-Nov-2012  tls file ether.c was added on branch tls-maxphys on 2012-11-20 03:00:48 +0000
 1.16 16-Aug-2019  msaitoh Whitespace fix.
 1.15 21-Dec-2018  msaitoh Add SIOCSETHERCAP. It's used to change ec_capenable.
 1.14 07-Aug-2009  dyoung branches: 1.14.44; 1.14.46;
Add option -N. -N is just the opposite of option -n in netstat(8)
or route(8): it tells ifconfig(8) to try to resolve numbers to
hosts and service names.

This default ifconfig behavior stays the same as it always was.
 1.13 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.12 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.11 06-May-2008  dyoung branches: 1.11.2;
Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.10 26-Aug-2006  christos branches: 1.10.18; 1.10.20;
Programs that use efun.
 1.9 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.8 20-Mar-2005  thorpej Split the IPv4 support into its own file.
 1.7 20-Mar-2005  thorpej Split IPv6 support out into its own file.
 1.6 19-Mar-2005  thorpej Split off AppleTalk support into its own file.
 1.5 19-Mar-2005  thorpej const'ify afswtch
 1.4 19-Mar-2005  thorpej Split off 802.11 interface handling into its own file.
 1.3 19-Mar-2005  thorpej Don't hare-code inet/inet6 in tunnel_status(), lookup the address family
name instead.
 1.2 19-Mar-2005  thorpej Split tunnel support into its own file.
 1.1 19-Mar-2005  thorpej Move extern decls to extern.h
 1.10.20.1 18-May-2008  yamt sync with head.
 1.10.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.10.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.14.46.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.14.46.1 10-Jun-2019  christos Sync with HEAD
 1.14.44.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.31 13-Aug-2021  andvar fix typos in words "pointer" and s/fram /frame/
 1.30 16-Aug-2019  msaitoh Whitespace fix.
 1.29 22-Sep-2016  christos branches: 1.29.14;
fix bugs in ssid printing
 1.28 28-Apr-2015  christos branches: 1.28.2;
remove 80211 stats if small.
 1.27 08-Jan-2014  christos perror is obsolete, use warn and add missing paren.
 1.26 07-Jan-2014  degroote Before scanning, check if the card is up. If it is not the case, exit
with some useful error message. Add some note about this fact in the man
page too.
 1.25 13-Dec-2010  pooka branches: 1.25.6; 1.25.12;
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.24 01-Jul-2010  dyoung Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it. (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.
 1.23 18-Jan-2009  lukem fix -Wsign-compare issues
 1.22 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.21 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.20 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.19 19-May-2008  dyoung Fix two bugs:

1 Let us associate a keyword with either a signed or an unsigned
number. Associate the '-chan' keyword with an unsigned number.
This fixes the defect that crashed 'ifconfig wi0 -chan', reported
by Michael van Elst.

2 Do not try to interpret names as ISO addresses unless the ISO
address family was specified. iso_addr(3) does not report errors,
so it appears to interpret *everything* as an ISO address. This
is a stopgap fix for the defect in 'ifconfig lo0 inet6' on a
!INET6 kernel that deletes the first IPv4 address on lo0.
(Reported by Scott Ellis.)
 1.18 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.17 07-May-2008  dyoung Move tunnel syntax into tunnel.c. Move net80211 'list' command
syntax into ieee80211.c.
 1.16 07-May-2008  dyoung Move net80211 and agr(4) syntax out of ifconfig.c and into ieee80211.c
and agr.c, respectively.
 1.15 06-May-2008  dyoung branches: 1.15.2;
Use prop_dictionary_util(3).

Re-use set80211() some more.
 1.14 06-May-2008  dyoung Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.13 06-May-2008  skrll Restore RCSId lost in 1.11
 1.12 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.11 16-Dec-2007  degroote branches: 1.11.4; 1.11.6;
Add support for the command list scan in ifconfig (this command permits to scan
access point in the neighbourhood).

Complete list of channel attributes and list of management information element
payload.

While here, use estrlcpy instead of strncpy.

From FreeBSD ifconfig and net80211
 1.10 09-Jan-2007  dyoung branches: 1.10.4; 1.10.6;
Print more 802.11 statistics when the operator runs 'ifconfig -v
ath0', for example. Fix the spelling of one statistic.
 1.9 09-Jan-2007  dyoung Per discussion "ifconfig error handling" on tech-net@ in August
2006, if we fail to set any 802.11 parameter, exit immediately with
EXIT_FAILURE.
 1.8 09-Jan-2007  dyoung Let us adjust the 802.11 fragmentation threshold with ifconfig ath0
frag 256, for example.
 1.7 26-Aug-2006  christos Programs that use efun.
 1.6 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.5 29-Apr-2006  rpaulo Add two new options from FreeBSD:
hidessid | -hidessid: SSID broadcast control
apbridge | -apbridge: how to pass packets between wifi clients
 1.4 25-Jan-2006  christos PR/32628: Yves-Emmanuel JUTARD: Missing cast in sbin/ifconfig/ifconfig.c,
strcasecmp needs char * not u_int8_t *.
 1.3 15-Sep-2005  dyoung Commit a straggler: use the new SIOCG80211STATS/SIOCG80211ZSTATS
ABI.
 1.2 22-Jun-2005  dyoung Resolve conflicts in importation of 18-May-2005 ath(4) / net80211(9)
from FreeBSD. Introduce compatibility shims (sys/dev/ic/ath_netbsd.[ch],
sys/net80211/ieee80211_netbsd.[ch]). Update drivers (an, atu, atw,
awi, ipw, iwi, rtw, wi) for the new net80211(9) API.
 1.1 19-Mar-2005  thorpej Split off 802.11 interface handling into its own file.
 1.10.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.10.4.1 09-Jan-2008  matt sync with HEAD
 1.11.6.2 04-Jun-2008  yamt sync with head
 1.11.6.1 18-May-2008  yamt sync with head.
 1.11.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.11.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.25.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.28.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.29.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.29.14.1 10-Jun-2019  christos Sync with HEAD
 1.8 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.7 07-May-2008  dyoung Move net80211 and agr(4) syntax out of ifconfig.c and into ieee80211.c
and agr.c, respectively.
 1.6 06-May-2008  dyoung branches: 1.6.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.5 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.4 16-Dec-2007  degroote branches: 1.4.4; 1.4.6;
Add support for the command list scan in ifconfig (this command permits to scan
access point in the neighbourhood).

Complete list of channel attributes and list of management information element
payload.

While here, use estrlcpy instead of strncpy.

From FreeBSD ifconfig and net80211
 1.3 09-Jan-2007  dyoung branches: 1.3.4; 1.3.6;
Let us adjust the 802.11 fragmentation threshold with ifconfig ath0
frag 256, for example.
 1.2 29-Apr-2006  rpaulo Add two new options from FreeBSD:
hidessid | -hidessid: SSID broadcast control
apbridge | -apbridge: how to pass packets between wifi clients
 1.1 19-Mar-2005  thorpej Split off 802.11 interface handling into its own file.
 1.3.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.4.1 09-Jan-2008  matt sync with HEAD
 1.4.6.1 18-May-2008  yamt sync with head.
 1.4.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.4.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.131 25-Sep-2024  roy ifconfig.8: -s only looks at interface link state
 1.130 20-Aug-2024  ozaki-r ifconfig: show link state on -v

We could guess it through "media" or "status" output, however, we
sometimes want to know it directly for debugging or testing.

It is shown only if the -v option is specified.
 1.129 08-Apr-2024  andvar branches: 1.129.2;
Update the date of the documentation to reflect recent changes.
 1.128 08-Apr-2024  uwe ifconfig(8): move laggportpri next to laggport
 1.127 08-Apr-2024  kre Correct a very minor typo (s/id/is/)
 1.126 08-Apr-2024  yamaguchi Added documents about parameters related to lagg(4)

PR misc/58125
 1.125 26-Mar-2023  mlelstv Fix parser for carp state.
The state values are uppercase words INIT, BACKUP and MASTER.
 1.124 25-Nov-2022  knakahara branches: 1.124.2;
ifconfig(8) support unnumbered flag.
 1.123 07-Jan-2022  bad mention ifmcstat(8) in SEE ALSO.
 1.122 09-Mar-2021  christos PR/50933: Uwe Toenjes: Document hardware limitations
 1.121 29-Sep-2020  msaitoh Add [-]eee and [-]vlan-hwfilter.
 1.120 23-Sep-2020  roy ifconfig: teach carrier test about ifi_link_state from SIOCGIFDATA

Because not all interfaces support media.
 1.119 08-Jul-2019  msaitoh Add "ifconfig [-]vlan-hwtagging" to enable/disable VLAN hardware tagging
offload function. It's useful to see Ethernet frame's VLAN tag by
disabling with "ifconfig fooX -vlan-hwtagging" and "tcpdump -e -i fooX".
 1.118 04-Jul-2019  wiz Formatting nit.
 1.117 04-Jul-2019  ozaki-r Add descr,description/-descr,-description commands to ifconfig(8) to handle a description.

From t-kusaba@IIJ
 1.116 15-Nov-2018  ozaki-r Fix the format of ifconfig linkstr; it takes an argument
 1.115 31-Jul-2018  sevan Remove ISO & XNS references which are now long gone.
 1.114 16-Feb-2017  wiz branches: 1.114.10; 1.114.12;
New sentence, new line.
Remove superfluous Oc and merge line to make it less likely to happen again.
Fix typo.
 1.113 16-Feb-2017  knakahara add man for l2tp(4).
 1.112 18-Jan-2017  abhinav Fix typo: s/forwared/forwarded
Also remove full stop from the date.
 1.111 11-Sep-2016  sevan branches: 1.111.2;
Replace contractions & abbreviation.
 1.110 07-Jan-2016  roy branches: 1.110.2;
-W seconds will wait for the detached flag to clear on addresses on
interfaces marked up to allow time for the carrier to appear on the
interface.

This does not extend the -w option duration.
 1.109 20-Oct-2014  roy Remove the ability for userland to toggle IN6_IFF_TENTATIVE.
Preserve IN6_IFF_TENTATIVE when updating address flags.
 1.108 15-Sep-2014  ozaki-r Write about -vlanif in ifconfig.8

PR 49114
 1.107 11-Sep-2014  roy Remove rtsol(8) and rtsold(8) as their functionality is in dhcpcd(8).
Remove rtsol(8) from rc.d/network.
Add -w seconds command to ifconfig to wait for N seconds for until DAD
has finished on all addresses.
Use ifconfig -w in rc.d/network instead of a forced sleep.

As discussed on tech-net@
 1.106 07-Jan-2014  degroote branches: 1.106.4;
Before scanning, check if the card is up. If it is not the case, exit
with some useful error message. Add some note about this fact in the man
page too.
 1.105 09-Nov-2013  kefren Bring tunnel src_addr and dst_addr on the same line
 1.104 28-Jan-2012  mbalmer branches: 1.104.2; 1.104.6;
When ifconfig is invoked without any arguments, display the list of
all network interfaces (equivalent to ifconfig -a), instead of displaying
the usage. (This is consistent with the behaviour on FreeBSD and OpenBSD.)
 1.103 31-May-2011  riastradh branches: 1.103.4;
Fix typo: `symbolically' takes three l's, not two.
 1.102 15-Nov-2010  pooka Implement ifconfig linkstr as proposed on tech-net.
 1.101 14-Sep-2009  degroote Import pfsync support from OpenBSD 4.2

Pfsync interface exposes change in the pf(4) over a pseudo-interface, and can
be used to synchronise different pf.

This work was part of my 2009 GSoC

No objection on tech-net@
 1.100 07-Aug-2009  dyoung Describe the -N flag.
 1.99 29-Jul-2009  hubertf Add "MAC" keyword to the corresponding example.
 1.98 02-Jul-2009  dyoung Use the keyword 'MAC' so that people looking for a way to change
their MAC address can find the example.
 1.97 02-Jul-2009  dyoung Deprecate wiconfig's -r, -g, -m options. Note that equivalent
options are available in ifconfig(8).
 1.96 08-Apr-2009  joerg Remove physical markup. Remove incorrect keep, .Bk is not callable, but
used as such. It doesn't seem to serve any purpose at the point either.
 1.95 27-Mar-2009  reed Point to ifmedia(4) more. And refer to -m flag to (for media).
 1.94 30-Sep-2008  wiz branches: 1.94.2; 1.94.4; 1.94.8;
Bump date for previous. Remove trailing whitespace.
New sentence, new line. Capitalize Ethernet.
 1.93 29-Sep-2008  dyoung Do not mention the 'ns' address family any longer, since that
support was removed quite a while ago.

Mention the 'link' address family. Describe the 'active' keyword.
Add examples for adding and activating a link-layer address.
 1.92 16-Dec-2007  degroote branches: 1.92.2; 1.92.4;
Add support for the command list scan in ifconfig (this command permits to scan
access point in the neighbourhood).

Complete list of channel attributes and list of management information element
payload.

While here, use estrlcpy instead of strncpy.

From FreeBSD ifconfig and net80211
 1.91 05-Jun-2007  mishka branches: 1.91.4; 1.91.6;
Our VLAN implementation (as it correctly expected) is not allowed
to modify the whole VLAN tags, but it is permitted to change 12-bit
VLAN identificators only. Reflect this fact on the appropriate man
pages.

Antti Kantee and Mihai Chelaru from #netbsd-code were helpful in
better understanding of VLAN stuff. Thank you!
 1.90 09-Jan-2007  dyoung Let us adjust the 802.11 fragmentation threshold with ifconfig ath0
frag 256, for example.
 1.89 23-Dec-2006  wiz Punctuation nit, sort SEE ALSO.
 1.88 03-Dec-2006  wiz Remove a troff command that added some empty lines to the man(1) output.
 1.87 23-Nov-2006  yamt implement ipv6 TSO.
partly from Matthias Scheler. tested by him.
 1.86 16-Sep-2006  hubertf Fix typo, noted by Nino Dehne <ndehne@gmail.com>
 1.85 31-Aug-2006  dyoung Add a mode to gre(4) that sends GRE tunnel packets in UDP datagrams.
Fix MOBILE encapsulation. Add many debugging printfs (mainly
concerning UDP mode). Clean up the gre(4) code a bit. Add the
capability to setup UDP tunnels to ifconfig. Update documentation.

In UDP mode, gre(4) puts a GRE header onto transmitted packets,
and hands them to a UDP socket for transmission. That is, the
encapsulation looks like this: IP+UDP+GRE+encapsulated packet.

There are two ways to set up a UDP tunnel. One way is to tell the
source and destination IP+port to gre(4), and let gre(4) create
the socket. The other way to create a UDP tunnel is for userland
to "delegate" a UDP socket to the kernel.
 1.84 30-Jun-2006  drochner fix an Xref
 1.83 18-May-2006  liamjfoy Integrate Common Address Redundancy Procotol (CARP) from OpenBSD

'pseudo-device carp'

Thanks to: joerg@ christos@ riz@ and others who tested
Ok: core@
 1.82 06-May-2006  wiz Remove trailing whitespace.
 1.81 29-Apr-2006  rpaulo Add two new options from FreeBSD:
hidessid | -hidessid: SSID broadcast control
apbridge | -apbridge: how to pass packets between wifi clients
 1.80 11-Sep-2005  wiz Argument is address_family, not "address family". From YOMURA Masanori in private mail.
 1.79 11-Aug-2005  rpaulo Explained the '-h' option.
 1.78 02-May-2005  yamt bump date for the previous.
 1.77 02-May-2005  yamt split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.76 18-Mar-2005  wiz Link to vlan(4) too, suggested by yamt.
 1.75 18-Mar-2005  wiz Bump date for agr; add agr(4) to SEE ALSO.
 1.74 18-Mar-2005  yamt add agr(4), a pseudo network device driver for link aggregation.
 1.73 06-Mar-2005  matt branches: 1.73.2;
Add ifconfig support for TCP Segment Offload
 1.72 01-Mar-2004  wiz Add an article.
 1.71 01-Mar-2004  perry Change "nwid" to "ssid", list "nwid" as a synonym for "ssid", and
clean up the ssid explanation a bit (including mentioning that if you
want to use a hex ssid, you precede it with a 0x, which really needed
documenting.)
 1.70 29-Feb-2004  wiz Drop trailing whitespace (hi perry! :) ).
 1.69 29-Feb-2004  perry update man page date. (hi wiz!)
 1.68 29-Feb-2004  perry document that if you are using a hex wep key, you need to put 0x in
front of it.
 1.67 29-Feb-2004  perry document "mode" -- taken from FreeBSD
 1.66 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.65 16-Apr-2003  wiz Combine no-argument options in SYNOPSIS.
 1.64 12-Apr-2003  perry Document the -v and -z flags.
 1.63 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.62 30-Sep-2002  grant New sentence, new line.
 1.61 30-Sep-2002  onoe Fix the option name 'channel' to 'chan' to be consistent with the source.
Add documents for '-chan' to unset the desired channel to associate.
 1.60 25-Sep-2002  wiz Grammar fixes. Bump Dd for recent additions.
 1.59 22-Sep-2002  thorpej New commands:
* bssid xx:xx:xx:xx:xx:xx -- set the desired BSSID of an 802.11
interface.
* -bssid -- unset the desired BSSID of an 802.11 interface, so
the interface will choose automatically (default).
* channel x -- set the channel (radio frequency) of an 802.11 interface.

Current BSSID and channel are now reported in the 802.11 status
display, if supported by the interface.

Above changes from David Young <dyoung@ojctech.com>, with some slight
changes by me (use ethers(3) functions rather than hand-parsing/printing
the 802.11 address).

Document bssid/-bssid/channel, and clean up markup of parentheticals
in the manual page.
 1.58 01-Sep-2002  ross xref ifconfig.if(5)
 1.57 06-Aug-2002  jwise Fix mandoc glitch in description of `eui64' command.
 1.56 14-Jun-2002  itojun support "eui64" option (grab interface ID from link-local addr).
from: ww@styx.org
 1.55 09-Jun-2002  itojun now "ifconfig tunnel" is usable for gre too, change wording slightly
 1.54 16-Nov-2001  wiz Whitespace nits
 1.53 17-Sep-2001  thorpej Add tcp4csum-rx and udp4csum-rx commands for interfaces that only
support TCP/UDP checksums on the in-bound direction.
 1.52 21-Jun-2001  onoe Add support of persistent key of IEEE 802.11 wireless LAN card.
Currently, only Aironet ("an") driver/card can be used.
nwkey persist (IEEE 802.11 devices only) Enable WEP encryption for IEEE
802.11-based wireless network interfaces with the persis-
tent key written in the network card.
nwkey persist:key
(IEEE 802.11 devices only) Write the key to the persis-
tent memory of the network card, and enable WEP encryp-
tion for IEEE 802.11-based wireless network interfaces
with the key.
 1.51 05-Jun-2001  wiz Drop arguments of .Os.
 1.50 02-Jun-2001  thorpej Implement support for IP/TCP/UDP checksum offloading provided by
network interfaces. This works by pre-computing the pseudo-header
checksum and caching it, delaying the actual checksum to ip_output()
if the hardware cannot perform the sum for us. In-bound checksums
can either be fully-checked by hardware, or summed up for final
verification by software. This method was modeled after how this
is done in FreeBSD, although the code is significantly different in
most places.

We don't delay checksums for IPv6/TCP, but we do take advantage of the
cached pseudo-header checksum.

Note: hardware-assisted checksumming defaults to "off". It is
enabled with ifconfig(8). See the manual page for details.

Implement hardware-assisted checksumming on the DP83820 Gigabit Ethernet,
3c90xB/3c90xC 10/100 Ethernet, and Alteon Tigon/Tigon2 Gigabit Ethernet.
 1.49 28-Apr-2001  itojun make -A a default. present MAC adderss on all ifconfig operations.
 1.48 27-Apr-2001  itojun allow ifconfig to take "deprecated" and "-deprecated" for IPv6. sync with kame

sync usage() with reality. take "up" and "down" outside of "[af ...],
as "up" and "down" are independent from interface address configuration.
 1.47 17-Jan-2001  itojun support "prefixlen n" for IPv4 too.
 1.46 12-Dec-2000  onoe powersavesleep requires argument
 1.45 12-Dec-2000  thorpej Add powersave, -powersave, and powersavesleep to manipulate 802.11
power management parameters.
 1.44 18-Oct-2000  kleink Don't make references to _10Mb/s_ Ethernet where not appropriate; from
Christian Weisgerber.
 1.43 27-Sep-2000  thorpej Add vlan(4) support. From Andy Doran <ad@netbsd.org>.
 1.42 13-Aug-2000  wiz add two letters in strategically important places, and replace one
ifconfig by .Nm
 1.41 21-Jul-2000  onoe also note that the WaveLAN/IEEE Gold cards accept the 104 bits key.
pointed out by jhawk.
XXX this doesn't match to wiconfig(8), which is probably wrong.
 1.40 21-Jul-2000  onoe Clarify the restrictions in length for argument of the nwid and nwkey.
 1.39 21-Jul-2000  onoe Add nwkey and -nwkey keywords, to enable/disable WEP,
and to set WEP encryption key for IEEE802.11 wireless network interfaces.
 1.38 20-Jul-2000  thorpej Add a -C flag, to list all available network interface cloners.
 1.37 06-Jul-2000  onoe hexadecimal digits for nwid.
 1.36 03-Jul-2000  enami - Remove description about trailers/-trailers since they are no longer
a meaningful option.
- Don't captialize the word address or interface when it refers an arugment.
- Use .Ar macro for dest_address since it is not a keyword.
 1.35 03-Jul-2000  enami Sort the SEE ALSO list first by section and kill the comma at the
end of the list.
 1.34 02-Jul-2000  thorpej Add `create' and `destroy' commands.
 1.33 30-Jun-2000  thorpej - Add `tunnel' and `deletetunnel' commands, which issue the ioctls
that gifconfig(8) would issue to configure tunnel endpoints. This
allows IP tunnel interfaces (`gif' right now, and `gre' later) to
be configured with ifconfig(8), and via /etc/ifconfig.<interface>.
Partially taken from similar changes in OpenBSD.
- Const poison the command functions a bit. We really need to clean
up the command function interface.
 1.32 01-Mar-2000  enami branches: 1.32.4;
Fix typo.
 1.31 31-Jan-2000  itojun note that ifconfig delete does not work for IPv6
this is intentional - IPv6 assumes multiple addresses on an interface,
and it is not very safe to "delete" arbitrary one. -alias with
explicit IPv6 address works fine.
 1.30 31-Jan-2000  itojun add "nwid" directive.
XXX there are too many flags that are not listed in usage().
what should we do?
 1.29 12-Jan-2000  joda implement netmask slash notation for IP and IPv6 addresses
 1.28 09-Dec-1999  itojun add reference to "inet6" family.
document -alias.
 1.27 03-Jul-1999  sommerfeld branches: 1.27.4;
Add a new -s option to make it easier to test the link-level status
(i.e., 10baseT carrier/no carrier) of an interface from scripts

ifconfig -s <interface> will exit with a false status if the interface
reports its unconnected.

-s also works in conjunction with -l and -a, filtering out interfaces
which are reporting down.

Also, add -b (which shows only broadcast interfaces with -l and -a).

I find these options useful in network autoconfig scripts for mobile
systems.
 1.26 02-Jul-1999  itojun write up IPv6 operations (prefixlen and others)
 1.25 01-Jul-1999  itojun make ifconfig IPv6-ready.
TODO: update manpage for new options.
 1.24 06-Sep-1998  christos Add support for displaying interface alias information. Based on PR/6109 by
Phil Nelson.
 1.23 09-Aug-1998  thorpej Cross-reference ifmedia(4).
 1.22 08-Aug-1998  thorpej Document "instance".
 1.21 11-Oct-1997  enami - Use .Nm "" instead of .Nm ifconfig in SYNOPSIS.
- Delete space at the end of line.
 1.20 10-Oct-1997  lukem all but the first .Nm in SYNOPSIS need to be spelt out. [bin/4256]
 1.19 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* use .Nm correctly
 1.18 30-May-1997  lukem Add "mask" argument to description of "broadcast".
From Thorsten Frueauf <frueauf@ira.uka.de> in [misc/3657]
 1.17 21-Apr-1997  lukem Implemented two modifier flags for -a and -l: -d (only show "down" interfaces)
and -u (only show "up" interfaces)
 1.16 10-Apr-1997  is Add mtu n parameter. Part of code by Matthias Pfaller (PR 1648).
 1.15 10-Apr-1997  jeremy Fix typo in media selector example. (from frueauf@ira.uka.de)
Fixes half of PR#3470.
 1.14 03-Apr-1997  christos - netatalk additions
- KNF
- prototype fixes
- ifconfig -a now prints all the address family parameters for all configured
interfaces.
 1.13 27-Mar-1997  thorpej Add a "-l" flag, which lists available network interfaces, with no
additional information.
 1.12 17-Mar-1997  thorpej Add support for BSD/OS-style media selection:
- new "media" keyword specified media to select:
ifconfig de0 media utp
- new "mediaopt/-mediaopt" keywords for setting/clearing
media options (such as full-duplex)
- new "-m" flag to display all supported media types for
a given interface.
Also, some generial cleanup of argument parsing while I was there.
Manual page updates from Jeremy Cooper <jeremy@netbsd.org>.
 1.11 04-Jan-1996  pk Merge with lite-2.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.8 22-Jan-1994  cgd fix a botch
 1.7 14-Jan-1994  jtc Fix spelling errors
 1.6 10-Dec-1993  cgd LLC -> LINK, documentation
 1.5 01-Aug-1993  mycroft Add RCS indentifiers.
 1.4 04-May-1993  deraadt Added another sunos-ism: ifconfig -a
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 04-Jan-1996  pk imported from 44lite2
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.27.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.32.4.10 01-May-2001  he Pull up revision 1.49 (requested by itojun):
Make ``-A'' the default, so that IPv4 aliases are printed.
Always print mac address.
 1.32.4.9 31-Dec-2000  jhawk Pull up revision 1.43 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.32.4.8 31-Dec-2000  jhawk Pull up revision 1.34, 1.38 (requested by bouyer):
Support cloning of network pseudo-interfaces.
 1.32.4.7 13-Aug-2000  wiz Pull up 1.41 -> 1.42 (approved by thorpej):
add two letters in strategically important places, and replace
one ifconfig by .Nm
 1.32.4.6 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- clarify the restriction for nwid/nwkey, add supported hardwares.
basesrc/sbin/ifconfig/ifconfig.8 1.40-1.41
saresrc/share/man/man4/awi.4 1.9
saresrc/share/man/man4/wi.4 1.11
 1.32.4.5 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- add support for nwkey to ifconfig
basesrc/sbin/ifconfig/ifconfig.c 1.88
basesrc/sbin/ifconfig/ifconfig.8 1.39
syssrc/sys/dev/ic/awi.c 1.26
syssrc/sys/dev/ic/awi_wep.c 1.3
syssrc/sys/dev/ic/awivar.h 1.12
syssrc/sys/dev/pcmcia/if_wi.c 1.26
syssrc/sys/net/if.c 1.69
syssrc/sys/net/if_ieee80211.h 1.5
 1.32.4.4 21-Jul-2000  onoe Pullups 802.11 stuff (approved by jhawk)
- allow non-string nwid settings
basesrc/sbin/ifconfig/ifconfig.c 1.82-1.86
basesrc/sbin/ifconfig/ifconfig.8 1.37
syssrc/sys/dev/ic/awi.c 1.21
syssrc/sys/dev/pcmcia/if_ray.c 1.21
syssrc/sys/dev/pcmcia/if_wi.c 1.23
syssrc/sys/dev/pcmcia/if_wivar.h 1.10
syssrc/sys/net/if_ieee80211.h 1.4
 1.32.4.3 03-Jul-2000  thorpej Pull up rev. 1.36:
- Remove description about trailers/-trailers since they are no longer
a meaningful option.
- Don't captialize the word address or interface when it refers an arugment.
- Use .Ar macro for dest_address since it is not a keyword.
 1.32.4.2 03-Jul-2000  thorpej Pull up rev. 1.35:
Sort the SEE ALSO list first by section and kill the comma at the
end of the list.
 1.32.4.1 30-Jun-2000  thorpej - Add `tunnel' and `deletetunnel' commands, which issue the ioctls
that gifconfig(8) would issue to configure tunnel endpoints. This
allows IP tunnel interfaces (`gif' right now, and `gre' later) to
be configured with ifconfig(8), and via /etc/ifconfig.<interface>.
Partially taken from similar changes in OpenBSD.
- Const poison the command functions a bit. We really need to clean
up the command function interface.

Rationale for pulling into netbsd-1-5 branch: While this looks like
a feature enhancement, it actually fixes a bug -- without this change
or a change in rc.d's network bring-up, it is not possible to configure
IP tunnels as a normal part of bringing up the network.
 1.73.2.1 24-Mar-2006  riz Pull up following revision(s) (requested by rpaulo in ticket #1219):
sbin/ifconfig/ifconfig.8: revision 1.79
Explained the '-h' option.
 1.91.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.91.4.1 09-Jan-2008  matt sync with HEAD
 1.92.4.1 05-Oct-2008  mjf Sync with HEAD.
 1.92.2.1 22-Feb-2008  keiichi imported Mobile IPv6 code developed by the SHISA project
(http://www.mobileip.jp/).
 1.94.8.1 21-Apr-2010  matt sync to netbsd-5
 1.94.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.94.2.2 29-Jul-2009  hubertf backout previous - wrong branch, thanks veego
 1.94.2.1 29-Jul-2009  hubertf Add "MAC" keyword to the corresponding example.
 1.103.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.103.4.1 17-Apr-2012  yamt sync with head
 1.104.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.104.2.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by ozaki-r in ticket #1156):
sbin/ifconfig/vlan.c: revision 1.14
sbin/ifconfig/ifconfig.8: revision 1.108
sys/net/if_vlan.c: revision 1.71
sys/net/if_vlan.c: revision 1.73
sys/net/if_vlan.c: revision 1.74
- PR#49114: Write about -vlanif in ifconfig.8.
Add -vlanif to the help message of ifconfig.
- PR#49196: Leave promiscuous mode when detaching a parent (ifconfig -vlanif)
We have to call ifpromisc(ifp, 0) for both a VLAN interface
and its parent when they are in promiscuous mode.
- PR#49197: Delete link local addresses of a vlan interface when detaching its
parent.
- PR#49112: Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig
 1.106.4.2 27-Oct-2014  martin Pull up following revision(s) (requested by roy in ticket #160):
sbin/ifconfig/af_inet6.c: revision 1.30
sbin/ifconfig/ifconfig.8: revision 1.109
sys/netinet6/in6.c: revision 1.177
Remove the ability for userland to toggle IN6_IFF_TENTATIVE.
Preserve IN6_IFF_TENTATIVE when updating address flags.
 1.106.4.1 22-Sep-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #108):
sbin/ifconfig/vlan.c: revision 1.14
sbin/ifconfig/ifconfig.8: revision 1.108
sys/net/if_vlan.c: revision 1.71-1.74

Document -vlanif in ifconfig.8 and in usage measseg (PR 49114).
Leave promiscuous mode when detaching a parent (PR 49196) and
delete link local addresses (49197).
Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig
(PR 49112).
Call if_input of vlan interface itself, not parent one.
This allows bridging vlan interfaces again.
 1.110.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.111.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.114.12.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.114.12.1 10-Jun-2019  christos Sync with HEAD
 1.114.10.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.114.10.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.124.2.3 21-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #902):

sbin/ifconfig/carp.c: revision 1.15
sbin/ifconfig/ifconfig.8: revision 1.125
tests/net/carp/t_basic.sh: revision 1.9
sys/netinet/ip_carp.c: revision 1.118
sys/netinet/ip_carp.c: revision 1.119

Fix parser for carp state.

The state values are uppercase words INIT, BACKUP and MASTER.

Use backing device to send advertisements. Otherwise the packets originate
from the virtual MAC address, which confuses switches.

Select virtual address as sender if backing interface is anonymous.

Use correct scope for IPv6.

Don't expect the net/carp/t_basic/carp_handover_ipv6_halt_nocarpdevip
and carp_handover_ipv6_ifdown_nocarpdevip test cases to fail. At
least on the TNF i386 and amd64 testbeds, they pass more often than
not since the commit of src/sys/netinet/ip_carp.c 1.119 by mlelstv on
2023.04.07.06.44.08.
 1.124.2.2 24-Aug-2024  martin Pull up following revision(s) (requested by ozaki-r in ticket #811):

tests/net/if_shmif/t_shmif.sh: revision 1.1
sbin/ifconfig/ifconfig.c: revision 1.251
sbin/ifconfig/ifconfig.8: revision 1.130
sys/rump/net/lib/libshmif/if_shmem.c: revision 1.85
sys/rump/net/lib/libshmif/if_shmem.c: revision 1.86
sys/rump/net/lib/libshmif/if_shmem.c: revision 1.87
etc/mtree/NetBSD.dist.tests: revision 1.206
distrib/sets/lists/tests/mi: revision 1.1333
tests/net/if_shmif/Makefile: revision 1.1
tests/net/Makefile: revision 1.42

shmif: change behaviors about link states

- Change the link state to UP on ifconfig linkstr
- This behavior emulates physical devices
- Change the link state to UNKNOWN on ifconfig -linkstr just in case
- Reject sending/receiving packets if the link state is DOWN
- Permit to send/receive packets on UNKNOWN, which is required
to unbreak some ATF tests written in C

shmif: support media

It enables to link-down shmif by ifconfig media none and link-up
again by media auto.

ifconfig: show link state on -v

We could guess it through "media" or "status" output, however, we
sometimes want to know it directly for debugging or testing.

It is shown only if the -v option is specified.
tests: add tests for shmif

The test file is placed under tests/net, not tests/rump/rumpnet,
to leverage utility functions provided for tests in there.
shmem(4): Fix typo in comment: AFT -> ATF.

Also fix grammar (if I understood correctly what this meant: rump
servers written in C, rather than set up via shell scripts around
rump_server invoking ifconfig).

No functional change intended.
 1.124.2.1 18-Apr-2024  martin Pull up following revision(s) (requested by andvar in ticket #660):

sbin/ifconfig/ifconfig.8: revision 1.126
sbin/ifconfig/ifconfig.8: revision 1.127
sbin/ifconfig/ifconfig.8: revision 1.128
sbin/ifconfig/ifconfig.8: revision 1.129

Added documents about parameters related to lagg(4)
PR misc/58125

Correct a very minor typo (s/id/is/)

ifconfig(8): move laggportpri next to laggport

Update the date of the documentation to reflect recent changes.
 1.129.2.1 02-Aug-2025  perseant Sync with HEAD
 1.251 20-Aug-2024  ozaki-r ifconfig: show link state on -v

We could guess it through "media" or "status" output, however, we
sometimes want to know it directly for debugging or testing.

It is shown only if the -v option is specified.
 1.250 03-Jan-2024  andvar branches: 1.250.2;
s/addreseses/addresses/ in comments (and one missing whitespace).
 1.249 25-Nov-2022  knakahara branches: 1.249.2;
ifconfig(8) support unnumbered flag.
 1.248 14-Oct-2020  roy ifconfig: go back to using direct ioctls rather than data from getifaddrs

AF_LINK may not be the first address returned for the interface.
Technically, it *might* not even exist on the interface even though
other families do.
This is likely a driver bug if this really is the case though.

As such it's just easier to use direct ioctls rather than thump around
getifaddrs results. As it stands, the code makes a lot of getifaddrs
calls anyway, so an extra ioctl or two won't break the bank.
 1.247 28-Sep-2020  roy ifconfig: Just look at if_data->ifi_link_state for carrier

It should be the sole source of truth.
if_data is also carried in ifa_data from getifaddrs(3) which saves
more ioctl calls.
 1.246 26-Sep-2020  roy ifconfig: We already have struct if_data in ifa_data.

So let's not bother with an ioctl we don't need.
 1.245 23-Sep-2020  roy ifconfig: test cases want LINK_STATE_UNKNOWN to be treated as up.
 1.244 23-Sep-2020  roy ifconfig: teach carrier test about ifi_link_state from SIOCGIFDATA

Because not all interfaces support media.
 1.243 22-Sep-2020  roy ifconfig: Report link state even if media is not supported

For AF_LINK addrs from getifaddrs(2), ifa_data is struct if_data.
This in turn holds ifi_link_state which we can use to report
link status if the interface does not support media where it's normally
reported.

Based on OpenBSD.
 1.242 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.241 02-Jan-2020  ryo fix printing capabilities and enabled flags.

no need to skip a prefix "0x" of output of snprintb.
ifconfig expect the result of snprintb has "0x" prefix, but snprintb(3) specification has changed
so that if 0 is passed, it prints "0" instead of "0x0". (common/lib/libutil/snprintb.c r1.22)
 1.240 16-Aug-2019  msaitoh Whitespace fix.
 1.239 04-Jul-2019  ozaki-r Add descr,description/-descr,-description commands to ifconfig(8) to handle a description.

From t-kusaba@IIJ
 1.238 21-Dec-2018  msaitoh Add SIOCSETHERCAP. It's used to change ec_capenable.
 1.237 15-Nov-2018  ozaki-r ifconfig: add linkstr/-linkstr to the help message
 1.236 07-Jan-2016  roy branches: 1.236.14; 1.236.16;
-W seconds will wait for the detached flag to clear on addresses on
interfaces marked up to allow time for the carrier to appear on the
interface.

This does not extend the -w option duration.
 1.235 29-Jul-2015  ozaki-r Don't divide flags output

If there are many enabled flags, ifconfig divides flags output into
multiple formatted strings due to snprintb_m, e.g.,
wm0: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX>wm0: flags=8b43<MULTICAST> mtu 1500

This behavior is probably unexpected. The change always outputs enabled
flags at once like this:
wm0: flags=8b43<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500
 1.234 22-Apr-2015  roy Move the INET6 specific code for wait_dad_exec() into af_inet6
by using a new afswtch hook af_addr_tentative.
 1.233 12-Sep-2014  martin Initialize timespec "end" for the benefit of some gcc versions getting
"may be used uninitialized" warnings wrong.
 1.232 11-Sep-2014  roy Remove rtsol(8) and rtsold(8) as their functionality is in dhcpcd(8).
Remove rtsol(8) from rc.d/network.
Add -w seconds command to ifconfig to wait for N seconds for until DAD
has finished on all addresses.
Use ifconfig -w in rc.d/network instead of a forced sleep.

As discussed on tech-net@
 1.231 19-Oct-2013  christos use the new scopeid functions
 1.230 17-Jul-2013  christos Allow -v to be used with other commands (list scan for example) as documented.
 1.229 07-Feb-2013  apb Abort on error from prop_dictionary_augment.
 1.228 01-Nov-2012  pgoyette Use snprintb_m(3) to split flags/capabilities/enabled across multiple
output lines.

As discussed on current-users
 1.227 28-Jan-2012  mbalmer branches: 1.227.6;
When ifconfig is invoked without any arguments, display the list of
all network interfaces (equivalent to ifconfig -a), instead of displaying
the usage. (This is consistent with the behaviour on FreeBSD and OpenBSD.)
 1.226 29-Aug-2011  joerg branches: 1.226.2;
Use __dead
 1.225 14-Dec-2010  pooka A few weeks ago when i added "linkstr" support I didn't know that
the string parser gives a proplib object which isn't a terminated
string. Fix that mistake now.
 1.224 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.223 15-Nov-2010  pooka Implement ifconfig linkstr as proposed on tech-net.
 1.222 05-Nov-2010  pooka adapt to new rumpclient_init() signature
 1.221 04-Nov-2010  pooka Update RUMP_ACTION to use the newstyle rump client.
 1.220 07-Aug-2009  dyoung Add option -N. -N is just the opposite of option -n in netstat(8)
or route(8): it tells ifconfig(8) to try to resolve numbers to
hosts and service names.

This default ifconfig behavior stays the same as it always was.
 1.219 26-May-2009  pooka Add compile mode which executes rump system calls. This is useful
when figuring out Where In The Kernel Is Carmen Sandiego's ioctl
for an ifconfig command line, since we can simply single-step into
the kernel.

Activated by "make RUMP_ACTION=1". No changes to normal case.
 1.218 21-Apr-2009  dyoung To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
 1.217 21-Apr-2009  dyoung Cosmetic: add some whitespace for my ease of reading.
 1.216 21-Apr-2009  dyoung There's no use casting a socket address to sockaddr_dl, only to cast it
back to sockaddr, so don't do it.
 1.215 04-Apr-2009  plunky Because the IFF_NOARP flag is a negative option it needs to be negated
when being applied from the "arp" option which itself is positive.

problem demonstrated by

# ifconfig tap3 create
# ifconfig tap3
tap3: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
address: f2:0b:a4:7f:44:03
media: Ethernet autoselect
# ifconfig tap3 arp
# ifconfig tap3
tap3: flags=8882<BROADCAST,NOARP,SIMPLEX,MULTICAST> mtu 1500
address: f2:0b:a4:7f:44:03
media: Ethernet autoselect
# ifconfig tap3 -arp
# ifconfig tap3
tap3: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
address: f2:0b:a4:7f:44:03
media: Ethernet autoselect
# ifconfig tap3 destroy
#
 1.214 18-Jan-2009  lukem branches: 1.214.2;
fix -Wsign-compare issues
 1.213 01-Aug-2008  dyoung branches: 1.213.2;
Extract common code. Create subroutine paddr_prefix_size().
 1.212 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.211 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.210 15-Jul-2008  dyoung Make usage() static.
 1.209 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.208 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.207 03-Jun-2008  dyoung Remove one more struct afswtch.af_getprefix() remnant.
 1.206 03-Jun-2008  dyoung Remove remnants of struct afswtch.af_getprefix().
 1.205 19-May-2008  dyoung Fix two bugs:

1 Let us associate a keyword with either a signed or an unsigned
number. Associate the '-chan' keyword with an unsigned number.
This fixes the defect that crashed 'ifconfig wi0 -chan', reported
by Michael van Elst.

2 Do not try to interpret names as ISO addresses unless the ISO
address family was specified. iso_addr(3) does not report errors,
so it appears to interpret *everything* as an ISO address. This
is a stopgap fix for the defect in 'ifconfig lo0 inet6' on a
!INET6 kernel that deletes the first IPv4 address on lo0.
(Reported by Scott Ellis.)
 1.204 12-May-2008  dyoung Per discussion at
<http://mail-index.netbsd.org/tech-net/2008/04/08/msg000371.html>,
let us add, delete, and activate link-layer addresses with ifconfig:

# ifconfig sip0 link 02:00:00:00:00:01 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 [add address]
# ifconfig sip0 link 02:00:00:00:00:02 active [activate address]
# ifconfig sip0 link 02:00:00:00:00:01 delete [remove address]
 1.203 11-May-2008  dyoung Let the address family modules zero initialize their own ifreqs,
instead of zeroing them in commit_address().

Switch to in6_commit_address() from in6_getprefix() and in6_getaddr().

Temporarily add some debugging code to setia6eui64_impl().
 1.202 08-May-2008  dyoung Move IPv4/IPv6-specific code from commit_address() to in_commit_address()
and in6_commit_address(). Fixes the USE_INET6=no build.
 1.201 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.200 07-May-2008  dyoung Move IPv6 syntax to af_inet6.c from ifconfig.c. Move IFKW() macro
from ifconfig.c to parse.h for reuse.
 1.199 07-May-2008  dyoung Move ISO, AppleTalk, carp(4) syntax from ifconfig.c to af_iso.c,
af_atalk.c, carp.c, respectively.
 1.198 07-May-2008  dyoung Sprinkle 'static const' on keyword objects.
 1.197 07-May-2008  dyoung Move vlan(4) syntax from ifconfig.c into vlan.c.
 1.196 07-May-2008  dyoung Move tunnel syntax into tunnel.c. Move net80211 'list' command
syntax into ieee80211.c.
 1.195 07-May-2008  dyoung Move net80211 and agr(4) syntax out of ifconfig.c and into ieee80211.c
and agr.c, respectively.
 1.194 07-May-2008  dyoung Fix a bug that I introduced in rev 1.88, where the default IPv6
prefix length changed from 64 to 128. While I am here, allow an
address to be given with prefix length /0, but interpret it as
/128.
 1.193 06-May-2008  dyoung branches: 1.193.2;
Use the right key, "ifcaps" not "ifcap", in do_setifcaps(). assert()
that the object associated with that key is the right size.
 1.192 06-May-2008  dyoung Extract subroutine do_setifcaps() and fix the bug that uwe@ reported
in capabilities-setting.

Use prop_dictionary_util(3).

Rename the parser snpaoffset to parse_snpaoffset.
 1.191 06-May-2008  dyoung Fix syntax error in last.
 1.190 06-May-2008  dyoung Cosmetic: use return rc ? 0 : -1;

Make sure to release a prop_object_t that I am no longer using.
 1.189 06-May-2008  dyoung Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.188 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.187 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.186 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.185 21-Apr-2008  dyoung Change int to bool in a couple of places.
 1.184 15-Apr-2008  dyoung branches: 1.184.2;
Straggler from last: call fewer protocol family-specific initialization
routines from main(), since the protocol-family modules are taking
care of it.
 1.183 14-Apr-2008  dyoung Cosmetic: delete dead code.
 1.182 11-Apr-2008  dyoung Cosmetic: use NULL instead of 0 for pointers. Shorten staircase.
 1.181 16-Dec-2007  degroote branches: 1.181.2; 1.181.4;
Add support for the command list scan in ifconfig (this command permits to scan
access point in the neighbourhood).

Complete list of channel attributes and list of management information element
payload.

While here, use estrlcpy instead of strncpy.

From FreeBSD ifconfig and net80211
 1.180 09-Jan-2007  dyoung branches: 1.180.4; 1.180.6;
Let us adjust the 802.11 fragmentation threshold with ifconfig ath0
frag 256, for example.
 1.179 23-Nov-2006  yamt implement ipv6 TSO.
partly from Matthias Scheler. tested by him.
 1.178 13-Nov-2006  dyoung Add a source-address selection policy mechanism to the kernel.

Also, add ioctls SIOCGIFADDRPREF/SIOCSIFADDRPREF to get/set preference
numbers for addresses. Make ifconfig(8) set/display preference
numbers.

To activate source-address selection policies in your kernel, add
'options IPSELSRC' to your kernel configuration.

Miscellaneous changes in support of source-address selection:

1 Factor out some common code, producing rt_replace_ifa().

2 Abbreviate a for-loop with TAILQ_FOREACH().

3 Add the predicates on IPv4 addresses IN_LINKLOCAL() and
IN_PRIVATE(), that are true for link-local unicast
(169.254/16) and RFC1918 private addresses, respectively.
Add the predicate IN_ANY_LOCAL() that is true for link-local
unicast and multicast.

4 Add IPv4-specific interface attach/detach routines,
in_domifattach and in_domifdetach, which build #ifdef
IPSELSRC.

See in_getifa(9) for a more thorough description of source-address
selection policy.
 1.177 16-Oct-2006  christos - get rid of p_cfunc2
- add missing initializers
 1.176 26-Aug-2006  christos Programs that use efun.
 1.175 26-Aug-2006  matt Nuke a leftover XNS fragment.
 1.174 26-Aug-2006  matt Remove XNS support.
 1.173 13-Jul-2006  martin Trying the old "ifconfig <name> x.x.x.x down" issue again:
if the kernel does not set the interface up after we set an address,
do it explicitly, unless we (previously) set it down on user request.

This will allow the network drivers to be "fixed" while keeping visible
behaviour the same. Part of fixing PR 30694.
 1.172 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.171 18-May-2006  liamjfoy Integrate Common Address Redundancy Procotol (CARP) from OpenBSD

'pseudo-device carp'

Thanks to: joerg@ christos@ riz@ and others who tested
Ok: core@
 1.170 29-Apr-2006  rpaulo Add two new options from FreeBSD:
hidessid | -hidessid: SSID broadcast control
apbridge | -apbridge: how to pass packets between wifi clients
 1.169 11-Aug-2005  rpaulo Added a new ifconfig flag, -h, allowing, in conjunction with -v, the display
of interface I/O bytes in human-format.

Reviewed by Christos Zoulas and Jason Thorpe.
 1.168 02-May-2005  yamt split IFCAP_CSUM_xxx to IFCAP_CSUM_xxx_Rx and IFCAP_CSUM_xxx_Tx.
 1.167 20-Mar-2005  thorpej IFFBITS and IFCAPBITS are now defined in <net/if.h>
 1.166 20-Mar-2005  thorpej Split the IPv4 support into its own file.
 1.165 20-Mar-2005  thorpej Move a comment.
 1.164 20-Mar-2005  thorpej Split IPv6 support out into its own file.
 1.163 20-Mar-2005  thorpej Split OSI support off into its own file.
 1.162 19-Mar-2005  thorpej Split XNS support into its own file.
 1.161 19-Mar-2005  thorpej Split off AppleTalk support into its own file.
 1.160 19-Mar-2005  thorpej const'ify afswtch
 1.159 19-Mar-2005  thorpej Split off 802.11 interface handling into its own file.
 1.158 19-Mar-2005  thorpej Don't hare-code inet/inet6 in tunnel_status(), lookup the address family
name instead.
 1.157 19-Mar-2005  thorpej Split tunnel support into its own file.
 1.156 19-Mar-2005  thorpej Move extern decls to extern.h
 1.155 19-Mar-2005  thorpej Split VLAN configuration bits out into a separate file.
 1.154 18-Mar-2005  yamt update usage() for agr(4). pointed by Thomas Klausner.
 1.153 18-Mar-2005  yamt add agr(4), a pseudo network device driver for link aggregation.
 1.152 06-Mar-2005  matt branches: 1.152.2;
Add ifconfig support for TCP Segment Offload
 1.151 06-Feb-2005  perry remove obsolete "register" declarations.
 1.150 20-Jan-2005  xtraeme Fix the cast for the getnameinfo() call in the status() function, which
should be "const struct" not "struct" for sockaddr.

WARNS=3
 1.149 20-Dec-2004  dyoung ifconfig -v prints 802.11 statistics. ifconfig -v prints and zeroes
802.11 statistics.
 1.148 16-Nov-2004  itojun NI_WITHSCOPEID was not picked up by IETF standardization process.
 1.147 11-Nov-2004  dsl Functions for converting media types to/from text are now in libutil.
 1.146 28-Oct-2004  dsl More isdigit() calls that need (unsigned char) cast
 1.145 11-Oct-2004  dsl De __P
 1.144 11-Oct-2004  dsl Remove all the caddr_t - mainly casts of the 3rd arg to ioctl()
 1.143 27-Jul-2004  yamt err -> errx where appropriate.
 1.142 06-Jul-2004  mycroft The change in revision 1.38 (in 1997!) was wrong. If we don't want the kernel
to automatically bring up interfaces, then we should move that code into
ifconfig(8) and out of the kernel, not cycle the interface up and down. Fixes
PR 9400 -- ifconfig(8) was not working as documented.
 1.141 01-Mar-2004  perry branches: 1.141.4;
Very minimal changes to make "ssid" and "nwid" aliases, and make the
ssid print out as "ssid", not "nwid".
XXX Really, someone should go through and change around all the
variable names etc. to ssid, but not today.
 1.140 27-Feb-2004  itojun check strlcpy error. idea from Ryan McBride
 1.139 13-Oct-2003  dyoung Add 'mode' option to change PHY media for 802.11 devices. Also,
display PHY mode. E.g., run an 802.11a (5GHz, 54Mbps max) access
point:

> ifconfig ath0 nwid my_access_point mode 11a mediaopt hostap
> ifconfig -m ath0
ath0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
nwid my_access_point
powersave off
bssid 00:05:5d:84:cc:6e chan 3
address: 00:05:5d:84:cc:6e
media: IEEE802.11 autoselect mode 11a hostap
status: active
supported IEEE802.11 media:
media autoselect
media autoselect mediaopt adhoc
media autoselect mediaopt hostap
media autoselect mediaopt monitor
media autoselect mode 11a
media autoselect mode 11a mediaopt adhoc
media autoselect mode 11a mediaopt hostap
media autoselect mode 11a mediaopt monitor
*snip snip*
 1.138 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.137 11-Jun-2003  christos PR/21860: Robert Elz: ifconfig doesn't allow addr/N notation for INET6
 1.136 17-May-2003  itojun use strlcpy
 1.135 17-May-2003  lukem Change -b from skipping POINTTOPOINT|LOOPBACK to skipping ! BROADCAST.
Fixes my [bin/21604]
 1.134 12-Apr-2003  perry Add an option (-z) like -v except that it clears the input/output
stats after printing them.
(Basically this just calls SIOCZIFDATA instead of SIOCGIFDATA).
Submitted by Jean-Edouard BABIN in PR bin/21078
However, he suggested using -c, and cgd (reasonably) noted that -z for
"zero" was probably more reasonable.
I've also changed the code very slightly.
 1.133 30-Sep-2002  onoe Hide bssid/chan for 802.11 if not specified nor not associated.
Allow "-chan" to allow any channel to associate, it doesn't affect
create channel for IBSS/AP mode.
 1.132 23-Sep-2002  thorpej Add missing newline.
 1.131 22-Sep-2002  thorpej New commands:
* bssid xx:xx:xx:xx:xx:xx -- set the desired BSSID of an 802.11
interface.
* -bssid -- unset the desired BSSID of an 802.11 interface, so
the interface will choose automatically (default).
* channel x -- set the channel (radio frequency) of an 802.11 interface.

Current BSSID and channel are now reported in the 802.11 status
display, if supported by the interface.

Above changes from David Young <dyoung@ojctech.com>, with some slight
changes by me (use ethers(3) functions rather than hand-parsing/printing
the 802.11 address).

Document bssid/-bssid/channel, and clean up markup of parentheticals
in the manual page.
 1.130 20-Sep-2002  christos use snprintb()
 1.129 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.128 14-Jun-2002  itojun grab eui64 only from the same interface.
 1.127 14-Jun-2002  itojun support "eui64" option (grab interface ID from link-local addr).
from: ww@styx.org
 1.126 14-Jun-2002  itojun init variable before strtoul
 1.125 14-Jun-2002  itojun metric and mtu are u_long, not int.
 1.124 23-May-2002  matt Add support to print interface counters (via SIOCGIFDATA) when the [new]
option -v is provided.
 1.123 06-May-2002  thorpej Don't bother testing if a u_short is > 0xffff -- that test is always false.
 1.122 25-Apr-2002  itojun use in_aliasreq for inet address manipulation, not ifaliasreq. they have
different alignment constraint. [tests on 64bit arch wanted]
 1.121 02-Nov-2001  lukem fix many -Wshadow warnings
 1.120 24-Oct-2001  atatat Clean up the code a bit so that the ioctl() return value is always
compared to -1 (instead of <0 or !=0) and always to call err() with
EXIT_FAILURE instead of sometimes using 1.
 1.119 06-Oct-2001  bjh21 Use getnameinfo() to format AF_LINK addresses again.
 1.118 05-Oct-2001  bjh21 Revert last change. getnameinfo() AF_LINK support is going away until I can
make it lint-clean.
 1.117 04-Oct-2001  bjh21 Use getnameinfo() to format AF_LINK addresses rather than doing it ourselves.
 1.116 26-Sep-2001  itojun remove duplicated line in cmds[].
 1.115 17-Sep-2001  thorpej Add tcp4csum-rx and udp4csum-rx commands for interfaces that only
support TCP/UDP checksums on the in-bound direction.
 1.114 19-Aug-2001  itojun snprintf return value audit. from deraadt
 1.113 09-Aug-2001  david Correct style of a comment, and bad else {} scoping from my previous
commit.

Thanks to enami tsugutomo for pointing both out.
 1.112 08-Aug-2001  david Cause multiple uses of alias, -alias, and delete to produce an error,
and exit.

Previously, combinations would produce unintended results, such as
deleting the primary IP on an interface, instead of deleting an specified
alias.
 1.111 31-Jul-2001  itojun embed scopeid on scoped ipv6 address. sync with kame
 1.110 25-Jul-2001  itojun do not go over the end of memory region we are supposed to touch,
overrun on "prefixlen" operation. there's no SEGV possibility.
 1.109 21-Jun-2001  onoe Add support of persistent key of IEEE 802.11 wireless LAN card.
Currently, only Aironet ("an") driver/card can be used.
nwkey persist (IEEE 802.11 devices only) Enable WEP encryption for IEEE
802.11-based wireless network interfaces with the persis-
tent key written in the network card.
nwkey persist:key
(IEEE 802.11 devices only) Write the key to the persis-
tent memory of the network card, and enable WEP encryp-
tion for IEEE 802.11-based wireless network interfaces
with the key.
 1.108 02-Jun-2001  thorpej Implement support for IP/TCP/UDP checksum offloading provided by
network interfaces. This works by pre-computing the pseudo-header
checksum and caching it, delaying the actual checksum to ip_output()
if the hardware cannot perform the sum for us. In-bound checksums
can either be fully-checked by hardware, or summed up for final
verification by software. This method was modeled after how this
is done in FreeBSD, although the code is significantly different in
most places.

We don't delay checksums for IPv6/TCP, but we do take advantage of the
cached pseudo-header checksum.

Note: hardware-assisted checksumming defaults to "off". It is
enabled with ifconfig(8). See the manual page for details.

Implement hardware-assisted checksumming on the DP83820 Gigabit Ethernet,
3c90xB/3c90xC 10/100 Ethernet, and Alteon Tigon/Tigon2 Gigabit Ethernet.
 1.107 28-Apr-2001  itojun make -A a default. present MAC adderss on all ifconfig operations.
 1.106 28-Apr-2001  itojun assume the presense of getifaddrs(3).
 1.105 27-Apr-2001  itojun sync usage() more to the reality. document alias/-alias.
 1.104 27-Apr-2001  itojun allow ifconfig to take "deprecated" and "-deprecated" for IPv6. sync with kame

sync usage() with reality. take "up" and "down" outside of "[af ...],
as "up" and "down" are independent from interface address configuration.
 1.103 01-Mar-2001  itojun whitespace at EOL
 1.102 01-Mar-2001  itojun on "tunnel" subcommand, use specified address family.
 1.101 23-Feb-2001  christos PR/12275:Kimmo Suominen: show -C in usage
 1.100 20-Feb-2001  itojun add SIOC[SG]LIFPHYADDR ioctl. greatly simplify tunnel address settings.
sync with kame. old ioctls are supplied but not recommended for new code.
 1.99 19-Feb-2001  cgd convert to use getprogname()
 1.98 04-Feb-2001  christos fix nested externs
 1.97 24-Jan-2001  garbled Fix the usage string so it displays the -b and s options to ifconfig -l
 1.96 17-Jan-2001  itojun unbroken slash notation (10.0.0.0/8) for IPv4.
 1.95 17-Jan-2001  itojun support "prefixlen n" for IPv4 too.
 1.94 08-Jan-2001  itojun uninitialized pointer. PR 11702
 1.93 12-Dec-2000  onoe Add powersave/powersavesleep into usage.
Fold usage output (still 14 lines...)
 1.92 12-Dec-2000  thorpej Add powersave, -powersave, and powersavesleep to manipulate 802.11
power management parameters.
 1.91 07-Nov-2000  itojun show IPv6 interface address status "deprecated" (preferred lifetime = 0).
RFC2462. sync with kame.
 1.90 02-Oct-2000  thorpej In tunnel_status(), if we have an IPv6 kernel, but a driver doesn't
support IPv6 tunnel endpoint addresses, fall back on the sockaddr
version of the ioctls.
 1.89 27-Sep-2000  thorpej Add vlan(4) support. From Andy Doran <ad@netbsd.org>.
 1.88 21-Jul-2000  onoe Add nwkey and -nwkey keywords, to enable/disable WEP,
and to set WEP encryption key for IEEE802.11 wireless network interfaces.
 1.87 20-Jul-2000  thorpej Add a -C flag, to list all available network interface cloners.
 1.86 19-Jul-2000  enami - Fix off-by-one error in previous.
- Fix a typo of ioctl name in warning message.
 1.85 19-Jul-2000  onoe check the length of nwid argument before copy to avoid SEGV.
pointed out by enami-san
 1.84 06-Jul-2000  onoe cast u_char for ctype (nwid stuff) to fix possible overrun problems.
 1.83 06-Jul-2000  onoe warn instead of print 802.11 nwid with bad length field.
 1.82 05-Jul-2000  onoe change the argument of SIOCS80211NWID and SIOCG80211NWID ioctls from
u_int8_t array to struct ieee80211_nwid to prepend length field.
The length field is necessary because IEEE 802.11 spec doesn't prohibit
even '\0' for SSID.
Though the name and the value of SIOC... macro is unchanged, this change
breaks binary compatibility. The only affected userland program on the
tree is ifconfig(8).
As Jason suggested on tech-net, it is better than live with problems
since there are no releases for this ioctls yet.
 1.81 02-Jul-2000  thorpej Add `create' and `destroy' commands.
 1.80 30-Jun-2000  thorpej - Add `tunnel' and `deletetunnel' commands, which issue the ioctls
that gifconfig(8) would issue to configure tunnel endpoints. This
allows IP tunnel interfaces (`gif' right now, and `gre' later) to
be configured with ifconfig(8), and via /etc/ifconfig.<interface>.
Partially taken from similar changes in OpenBSD.
- Const poison the command functions a bit. We really need to clean
up the command function interface.
 1.79 20-Apr-2000  enami branches: 1.79.4;
Allocate flagreq on stack.
 1.78 13-Apr-2000  itojun use getifaddrs, not SIOCGIFCONF, to avoid alignment constraints.
TODO: maybe it's better to pass struct ifaddrs * to in{,6}_alias.
 1.77 13-Apr-2000  itojun clarify in_alias() and in_status().
in_status() handles the whole inet address family. in_alias() handles
printout for single address (for both the primary address or an alias).
it is more consistent with, for example, the way at_status() is used.
 1.76 03-Apr-2000  enami Explicitly pick up ''the first address'' to delete.
 1.75 20-Mar-2000  onoe Set flagreq.ifr_name before issueing SIOCGIFFLAGS for setifflags.
Withoug this change, flagreq was never initialized and ifconfig w/o addr
always failed with ENXIO.
 1.74 18-Mar-2000  castor Fix PR bin/9629. The global variable ifr was used to save interface
flags even though the media routines tweak it.
 1.73 06-Mar-2000  enami Remove unnecessary continue statement.
 1.72 06-Mar-2000  enami Remove now unnecessary assignment. It looks like 4.4lite merge left over.
 1.71 06-Mar-2000  enami Don't copy from destination to destination.
 1.70 06-Mar-2000  thorpej Per a discussion on gcc-bugs, port-alpha/9494 is not a compiler bug, but
rather a bug in the code (which is violating the C standard by casting
an unaligned pointer to a pointer with more strict alignment constraints).

Fix the code to not do such things. Fixes port-alpha/9494.
 1.69 01-Mar-2000  enami Salvage the better comment appeared in rev 1.51 but gone in 1.53.
 1.68 18-Feb-2000  itojun more fix to SIOCGIFCONF alignment.
 1.67 25-Jan-2000  mycroft Fix a buglet that caused media-specific options to *always* be printed, even if
they were not set.
 1.66 25-Jan-2000  thorpej Fix a logic buglet in status printing code.
 1.65 25-Jan-2000  thorpej - Print 802.11 status (i.e. network ID) after mtu, etc. but before
protcol addresses.
- When searching for status bits, use the currently selected media type,
not the currently active media type.
 1.64 25-Jan-2000  thorpej Update copyright.
 1.63 25-Jan-2000  thorpej Make display of media status information (e.g. carrier, etc.) table-driven
and easily extensible (by merely adding to the tables in ifmedia.h).
 1.62 24-Jan-2000  chopps allow setting (and reporting) nwid for ieee 802.11 devices.
 1.61 24-Jan-2000  thorpej Fix a bug in get_media_options() which wasn't caught with global options;
make sure we only return option bits.
 1.60 12-Jan-2000  joda implement netmask slash notation for IP and IPv6 addresses
 1.59 13-Dec-1999  itojun bring in KAME scopeid hack. always show scopeid if it is scoped.
sync with latest KAME.
 1.58 29-Jul-1999  itojun branches: 1.58.4;
fix alignment problem of SIOCGIFCONF, on 64bit arch.
 1.57 26-Jul-1999  thorpej Make the previous actually compile.
 1.56 26-Jul-1999  darrenr cleanup error message
 1.55 26-Jul-1999  darrenr don't allow destination addresses to be set for non-Point-to-point interfaces
 1.54 03-Jul-1999  sommerfeld Add a new -s option to make it easier to test the link-level status
(i.e., 10baseT carrier/no carrier) of an interface from scripts

ifconfig -s <interface> will exit with a false status if the interface
reports its unconnected.

-s also works in conjunction with -l and -a, filtering out interfaces
which are reporting down.

Also, add -b (which shows only broadcast interfaces with -l and -a).

I find these options useful in network autoconfig scripts for mobile
systems.
 1.53 01-Jul-1999  itojun make ifconfig IPv6-ready.
TODO: update manpage for new options.
 1.52 18-May-1999  thorpej Fix a slight braino in last.
 1.51 17-May-1999  thorpej Don't force `inet' on status display; get all address families that have
configured addresses. From Jun-ichiro itojun Hagino, PR #7593.
 1.50 01-Apr-1999  chopps branches: 1.50.2;
revert the previous changes that removed special cased ioctls for ISO
stuff.
 1.49 06-Sep-1998  christos Add support for displaying interface alias information. Based on PR/6109 by
Phil Nelson.
 1.48 08-Aug-1998  thorpej Oops, add the "instance" command to the usage info.
 1.47 08-Aug-1998  thorpej Allow the user to explicitly set the media instance.
 1.46 08-Aug-1998  thorpej Hm, actions might not always be deferred; rename appropriately.
 1.45 08-Aug-1998  thorpej Completely rewrite the engine that sets media and media options. Previous
code would hit the interface multiple times. Now, all media and media
options are gathered and processed at once, hitting the interface only
once (except to grab the currently selected media exactly once; there is
no way to avoid that).
 1.44 06-Aug-1998  thorpej Implement a suggestion from Wolfgang Solfrank on the "supported media"
display. The display now looks like this:

bishop:thorpej 35$ obj.alpha/ifconfig -m fxp0
fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
media: Ethernet autoselect (100baseTX full-duplex)
status: active
supported Ethernet media:
media autoselect
media 100baseTX mediaopt full-duplex
media 100baseTX
media 10baseT mediaopt full-duplex
media 10baseT
media 100baseTX mediaopt loopback
inet 129.99.50.41 netmask 0xffffff00 broadcast 129.99.50.255
bishop:thorpej 36$

The intent here is to allow cut'n'pasting of the output to a command
line, or allow easier automatic extraction from scripts, etc.

XXX Still at issue is what to do about non-0 media instances.
 1.43 06-Aug-1998  thorpej Print the media instance if it's not zero, a reasonable compromise such
that no one will have to see those ugly instance numbers if they have
an interface with only one PHY (most of them out there).
 1.42 06-Aug-1998  thorpej Completely rewrite the way media descriptions are represented. The same
data structure is used, but a much saner matching mechanism is used, one
which allows greater ease in adding new types.

Also, rewrite the way media words are displayed. The status display now
looks like this:

bishop:thorpej 137$ ifconfig -m fxp0
fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
media: Ethernet autoselect (10baseT)
status: active
supported media:
Ethernet autoselect
Ethernet 100baseTX <full-duplex>
Ethernet 100baseTX
Ethernet 10baseT <full-duplex>
Ethernet 10baseT
Ethernet 100baseTX <loopback>
inet 129.99.50.41 netmask 0xffffff00 broadcast 129.99.50.255
bishop:thorpej 138$

This makes it more clear which media type (e.g. Ethernet) is currently
in-use, handy for devices such as the TI ThunderLAN which can also have
both Ethernet and Token Ring PHYs attached.
 1.41 05-Aug-1998  thorpej Copyright assigned to The NetBSD Foundation, Inc.
 1.40 01-Oct-1997  enami Don't declare optind.
 1.39 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* use .Nm correctly
 1.38 08-Sep-1997  mrg note that we have set ifflags so that we can reset them again after
setting the interface address. this is necessary as we may want to
configure an interface `down' by default, but, SIOCAIFADDR turns the
interface back on for us.
 1.37 14-Jul-1997  is ifr_metric vs. ifr_mtu: don't confuse people. Its a union anyway.
 1.36 30-May-1997  lukem Don't define the address of an interface to 0.0.0.0 if it's just being
brought "up" (without an address); don't give it an address at all.
From Koji Imada <koji@math.human.nagoya-u.ac.jp> in [bin/3477]
 1.35 05-May-1997  thorpej Force the ifaliasreq "addreq" to have 4-byte alignment, so that casting
one of its sockaddrs to a sockaddr_in doesn't cause an unaligned access
fault on the Alpha.
 1.34 21-Apr-1997  lukem Implemented two modifier flags for -a and -l: -d (only show "down" interfaces)
and -u (only show "up" interfaces)
 1.33 10-Apr-1997  is Add mtu n parameter. Part of code by Matthias Pfaller (PR 1648).
 1.32 03-Apr-1997  christos - netatalk additions
- KNF
- prototype fixes
- ifconfig -a now prints all the address family parameters for all configured
interfaces.
 1.31 27-Mar-1997  thorpej Add a "-l" flag, which lists available network interfaces, with no
additional information.
 1.30 26-Mar-1997  thorpej Print the station address of interfaces that have one. From
Matt Thomas <matt@3am-software.com>
 1.29 25-Mar-1997  thorpej Display the correct interface name in the event SIOCGIFMEDIA "succeeds"
but doesn't return any media types.
 1.28 24-Mar-1997  thorpej Fix a slight bogon in printing active/current media, from Matt Thomas.
 1.27 18-Mar-1997  thorpej Fix lookup_media_word() to properly distinguish between the "autoselect"
media type and error. (oops!)
 1.26 18-Mar-1997  thorpej Do that last change somewhat differently; We need to know the
currently selected media, and thus cannot allow E2BIG, since the
top-level kernel ioctl code won't perform the copyout of the
ifmediareq if it sees an "error".
 1.25 18-Mar-1997  thorpej Ignore E2BIG in domediaopt() like we do in setmedia(). Oversight pointed
out by Andrew Gallatin <gallatin@CS.Duke.EDU>.
 1.24 17-Mar-1997  thorpej Add support for BSD/OS-style media selection:
- new "media" keyword specified media to select:
ifconfig de0 media utp
- new "mediaopt/-mediaopt" keywords for setting/clearing
media options (such as full-duplex)
- new "-m" flag to display all supported media types for
a given interface.
Also, some generial cleanup of argument parsing while I was there.
Manual page updates from Jeremy Cooper <jeremy@netbsd.org>.
 1.23 08-Sep-1996  mycroft Update to match kernel changes.
 1.22 04-Jan-1996  pk branches: 1.22.4;
Agree with kernel on format of SIOCGIFCONF results.
 1.21 08-Oct-1995  gwr Add support for -DINET_ONLY to make this smaller in a ramdisk.
 1.20 19-May-1995  mycroft Use inet_aton(), not inet_addr(). Suggested by John Hawkinson.
 1.19 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.18 21-Jan-1995  glass fix usage message to include -a. fix command line handling for same
 1.17 18-Dec-1994  cgd spacing nit.
 1.16 05-Dec-1994  cgd more cleanups from Jim Jegers, passed over by me.
 1.15 31-Oct-1994  cgd ioctl types.
 1.14 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.13 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.12 22-Jan-1994  cgd (1) update usage info
(2) fix every instance of fprintf/exit except usage to use err()/errx()
(3) make netmask print out with a leading 0x, so that you can paste it back.
 1.11 10-Dec-1993  cgd add MULTICAST recognition
 1.10 10-Dec-1993  cgd LLC -> LINK, documentation
 1.9 01-Aug-1993  mycroft Add RCS identifiers.
 1.8 09-Jun-1993  deraadt removed aui/bnc hack from ifconfig. Use -llc0/llc0 instead.
 1.7 06-Jun-1993  deraadt fix ifconfig once again. multiple protocols really cooked hte code i wrote
before for -a.
 1.6 21-May-1993  cgd Remove ifdefs hiding ISO and XNS functionality
(from Havard Eidnes <Havard.Eidnes@runit.sintef.no>)
 1.5 04-May-1993  deraadt Added another sunos-ism: ifconfig -a
 1.4 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.3 22-Mar-1993  cgd added rcs ids to all files
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.22.4.1 11-Dec-1996  mycroft From trunk:
Eliminate SS_PRIV; instead, pass down a proc pointer to the usrreq methods
that need it.
Fix numerous memory leaks and bogus return values.
 1.50.2.2 18-Jun-1999  perry pullup 1.51->1.52 (thorpej)
 1.50.2.1 18-Jun-1999  perry pullup 1.50->1.51 (thorpej): Don't force "inet" on status display
 1.58.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.79.4.7 01-May-2001  he Pull up revision 1.107 (via patch, requested by itojun):
Make ``-A'' the default, so that IPv4 aliases are printed.
Always print mac address.
 1.79.4.6 26-Jan-2001  jhawk Pull up revision 1.94 (requested by itojun):
Initialize an uninitialized pointer. PR11702.
 1.79.4.5 31-Dec-2000  jhawk Pull up revision 1.89 (requested by bouyer):
Add support for 802.1Q virtual LANs.
 1.79.4.4 31-Dec-2000  jhawk Pull up revision 1.81, 1.87 (requested by bouyer):
Support cloning of network pseudo-interfaces.
 1.79.4.3 21-Jul-2000  onoe Pullup 802.11 stuff (approved by jhawk)
- add support for nwkey to ifconfig
basesrc/sbin/ifconfig/ifconfig.c 1.88
basesrc/sbin/ifconfig/ifconfig.8 1.39
syssrc/sys/dev/ic/awi.c 1.26
syssrc/sys/dev/ic/awi_wep.c 1.3
syssrc/sys/dev/ic/awivar.h 1.12
syssrc/sys/dev/pcmcia/if_wi.c 1.26
syssrc/sys/net/if.c 1.69
syssrc/sys/net/if_ieee80211.h 1.5
 1.79.4.2 21-Jul-2000  onoe Pullups 802.11 stuff (approved by jhawk)
- allow non-string nwid settings
basesrc/sbin/ifconfig/ifconfig.c 1.82-1.86
basesrc/sbin/ifconfig/ifconfig.8 1.37
syssrc/sys/dev/ic/awi.c 1.21
syssrc/sys/dev/pcmcia/if_ray.c 1.21
syssrc/sys/dev/pcmcia/if_wi.c 1.23
syssrc/sys/dev/pcmcia/if_wivar.h 1.10
syssrc/sys/net/if_ieee80211.h 1.4
 1.79.4.1 30-Jun-2000  thorpej - Add `tunnel' and `deletetunnel' commands, which issue the ioctls
that gifconfig(8) would issue to configure tunnel endpoints. This
allows IP tunnel interfaces (`gif' right now, and `gre' later) to
be configured with ifconfig(8), and via /etc/ifconfig.<interface>.
Partially taken from similar changes in OpenBSD.
- Const poison the command functions a bit. We really need to clean
up the command function interface.

Rationale for pulling into netbsd-1-5 branch: While this looks like
a feature enhancement, it actually fixes a bug -- without this change
or a change in rc.d's network bring-up, it is not possible to configure
IP tunnels as a normal part of bringing up the network.
 1.141.4.2 24-Jul-2005  snj Pull up revision 1.147 via patch (requested by riz in ticket #5518):
Functions for converting media types to/from text are now in libutil.
 1.141.4.1 24-Jul-2005  snj Pull up revision 1.142 (requested by riz in ticket #5517):
The change in revision 1.38 (in 1997!) was wrong. If we don't want the kernel
to automatically bring up interfaces, then we should move that code into
ifconfig(8) and out of the kernel, not cycle the interface up and down. Fixes
PR 9400 -- ifconfig(8) was not working as documented.
 1.152.2.2 14-Oct-2007  riz Pull up following revision(s) (requested by msaitoh in ticket #1801):
sbin/ifconfig/ifconfig.c: revision 1.173 via patch

If the kernel does not set the interface up after we set an address,
do it explicitly, unless we (previously) set it down on user request
(i.e. "ifconfig <name> x.x.x.x down").

This will allow the network drivers to be "fixed" while keeping visible
behaviour the same. Part of fixing PR 30694.
 1.152.2.1 24-Mar-2006  riz Pull up following revision(s) (requested by rpaulo in ticket #1219):
sbin/ifconfig/ifconfig.c: revision 1.169
Added a new ifconfig flag, -h, allowing, in conjunction with -v, the display
of interface I/O bytes in human-format.
Reviewed by Christos Zoulas and Jason Thorpe.
 1.180.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.180.4.1 09-Jan-2008  matt sync with HEAD
 1.181.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.181.4.2 29-Jun-2008  mjf Sync with HEAD.
 1.181.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.181.2.1 22-Feb-2008  keiichi imported Mobile IPv6 code developed by the SHISA project
(http://www.mobileip.jp/).
 1.184.2.3 17-Jun-2008  yamt sync with head.
 1.184.2.2 04-Jun-2008  yamt sync with head
 1.184.2.1 18-May-2008  yamt sync with head.
 1.193.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.193.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.213.2.2 03-May-2009  bouyer Pull up following revision(s) (requested by dyoung in ticket #730):
sbin/ifconfig/af_link.c: revisions 1.4 - 1.6
sbin/ifconfig/util.h: revision 1.7
sbin/ifconfig/util.c: revisions 1.10, 1.11
lib/libc/net/getifaddrs.c: revision 1.12
lib/libc/net/getifaddrs.3: revision 1.10
sbin/ifconfig/ifconfig.c: revisions 1.216 - 1.218
Fix indentation: change spaces to tabs.
Use getnameinfo(3) to render a human-readable link-layer address in the
'address: ' line, just as we do in the 'link xx:xx:...:xx' line.
There's no use casting a socket address to sockaddr_dl, only to cast it
back to sockaddr, so don't do it.
Cosmetic: add some whitespace for my ease of reading.
To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
For non-AF_LINK ifaddrs, ifa_data is NULL. AFAICT, this has always been
so. Say so in the documentation.
Bring getifaddrs(3) behavior in line with the documentation: the
ifa_data member of every AF_LINK struct ifaddrs points at the
corresponding struct if_data. In ifconfig(8), do not try to suppress
duplicate AF_LINK ifaddrs by checking for a NULL ifa_data.
Don't copy out two AF_LINK struct ifaddrs for each active link-layer
address. getifaddrs(3) used to copy out one ifaddrs for the kernel's
RTM_IFINFO message, and one more for the kernel's RTM_NEWADDR message.
I suppress the first duplicate with a highly conservative change that
wastes a little bit of ifaddrs storage. The storage is not leaked.
 1.213.2.1 04-Apr-2009  snj branches: 1.213.2.1.4;
Pull up following revision(s) (requested by plunky in ticket #665):
sbin/ifconfig/ifconfig.c: revision 1.215
Because the IFF_NOARP flag is a negative option it needs to be negated
when being applied from the "arp" option which itself is positive.
problem demonstrated by
# ifconfig tap3 create
# ifconfig tap3
tap3: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
address: f2:0b:a4:7f:44:03
media: Ethernet autoselect
# ifconfig tap3 arp
# ifconfig tap3
tap3: flags=8882<BROADCAST,NOARP,SIMPLEX,MULTICAST> mtu 1500
address: f2:0b:a4:7f:44:03
media: Ethernet autoselect
# ifconfig tap3 -arp
# ifconfig tap3
tap3: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
address: f2:0b:a4:7f:44:03
media: Ethernet autoselect
# ifconfig tap3 destroy
#
 1.213.2.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.214.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.226.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.226.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.226.2.1 17-Apr-2012  yamt sync with head
 1.227.6.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.227.6.2 25-Feb-2013  tls resync with head
 1.227.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.236.16.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.236.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.236.16.1 10-Jun-2019  christos Sync with HEAD
 1.236.14.2 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.236.14.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.249.2.1 24-Aug-2024  martin Pull up following revision(s) (requested by ozaki-r in ticket #811):

tests/net/if_shmif/t_shmif.sh: revision 1.1
sbin/ifconfig/ifconfig.c: revision 1.251
sbin/ifconfig/ifconfig.8: revision 1.130
sys/rump/net/lib/libshmif/if_shmem.c: revision 1.85
sys/rump/net/lib/libshmif/if_shmem.c: revision 1.86
sys/rump/net/lib/libshmif/if_shmem.c: revision 1.87
etc/mtree/NetBSD.dist.tests: revision 1.206
distrib/sets/lists/tests/mi: revision 1.1333
tests/net/if_shmif/Makefile: revision 1.1
tests/net/Makefile: revision 1.42

shmif: change behaviors about link states

- Change the link state to UP on ifconfig linkstr
- This behavior emulates physical devices
- Change the link state to UNKNOWN on ifconfig -linkstr just in case
- Reject sending/receiving packets if the link state is DOWN
- Permit to send/receive packets on UNKNOWN, which is required
to unbreak some ATF tests written in C

shmif: support media

It enables to link-down shmif by ifconfig media none and link-up
again by media auto.

ifconfig: show link state on -v

We could guess it through "media" or "status" output, however, we
sometimes want to know it directly for debugging or testing.

It is shown only if the -v option is specified.
tests: add tests for shmif

The test file is placed under tests/net, not tests/rump/rumpnet,
to leverage utility functions provided for tests in there.
shmem(4): Fix typo in comment: AFT -> ATF.

Also fix grammar (if I understood correctly what this meant: rump
servers written in C, rather than set up via shell scripts around
rump_server invoking ifconfig).

No functional change intended.
 1.250.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.1 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.2 19-Sep-2025  knakahara ifconfig(8): show missing l2tp-state of l2tp(4).
 1.1 16-Feb-2017  knakahara branches: 1.1.2; 1.1.4;
add l2tp(4) subcomands to ifconfig(8).

originally implemented by IIJ SEIL team.
 1.1.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.4.1 16-Feb-2017  bouyer file l2tp.c was added on branch bouyer-socketcan on 2017-04-21 16:53:13 +0000
 1.1.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.1 16-Feb-2017  pgoyette file l2tp.c was added on branch pgoyette-localcount on 2017-03-20 06:57:02 +0000
 1.8 09-Apr-2024  yamaguchi lagg(4): allocate memory for struct lagg_req by calloc(3)
to fix build error on clang
 1.7 08-Apr-2024  yamaguchi lagg(4): fix missing initialization of the number of array

pointed out by martin@, thanks.
 1.6 04-Apr-2024  yamaguchi ifconfig: remove optional space
 1.5 04-Apr-2024  yamaguchi lagg(4): use flexible array member
 1.4 06-Dec-2023  yamaguchi Fix "ifconfig lagg* lagglacp -maxports" command

This command clears the setting of the maximum number of
lacp active ports. The command was accepted but it did not
work until this change.
 1.3 31-Mar-2022  yamaguchi branches: 1.3.2;
Change error code to ENOBUFS on lack of buffer memory

pointed out by k-goda@IIJ
 1.2 21-Jun-2021  christos fix proplib deprecation
 1.1 17-May-2021  yamaguchi branches: 1.1.2;
Add a new link-aggregation pseudo interface named lagg(4)

- FreeBSD's lagg(4) based implementation
- MP-safe and MP-scalable
 1.1.2.2 31-May-2021  cjep sync with head
 1.1.2.1 17-May-2021  cjep file lagg.c was added on branch cjep_staticlib_x on 2021-05-31 22:15:08 +0000
 1.3.2.1 12-Dec-2023  martin Pull up following revision(s) (requested by yamaguchi in ticket #491):

sys/net/lagg/if_lagg.c: revision 1.56
sys/net/lagg/if_lagg.c: revision 1.57
sbin/ifconfig/lagg.c: revision 1.4

lagg(4): use sadl for lagg(4) configured by a user

lagg(4): eliminate unnecessary reset by the change of if_flags

Fix "ifconfig lagg* lagglacp -maxports" command

This command clears the setting of the maximum number of
lacp active ports. The command was accepted but it did not
work until this change.
 1.14 04-Apr-2022  andvar fix various typos, mainly in comments.
 1.13 14-Oct-2020  roy ifconfig: go back to using direct ioctls rather than data from getifaddrs

AF_LINK may not be the first address returned for the interface.
Technically, it *might* not even exist on the interface even though
other families do.
This is likely a driver bug if this really is the case though.

As such it's just easier to use direct ioctls rather than thump around
getifaddrs results. As it stands, the code makes a lot of getifaddrs
calls anyway, so an extra ioctl or two won't break the bank.
 1.12 05-Oct-2020  roy Minor correction to prior
 1.11 05-Oct-2020  roy ifconfig: Warn once more if media supported but no types

This reverts media.c -r1.7
 1.10 22-Sep-2020  roy ifconfig: Report link state even if media is not supported

For AF_LINK addrs from getifaddrs(2), ifa_data is struct if_data.
This in turn holds ifi_link_state which we can use to report
link status if the interface does not support media where it's normally
reported.

Based on OpenBSD.
 1.9 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.8 22-Apr-2019  msaitoh Suggested by Christos:
- Dont' cast malloc()'s return value.
- Use calloc() instead of malloc().
 1.7 14-Sep-2016  roy branches: 1.7.14;
Don't bail if SIOGIFMEDIA doesn't return any media lists because we
can still report link status.
 1.6 29-Aug-2011  joerg branches: 1.6.24;
Use __dead
 1.5 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.4 01-Jul-2010  dyoung Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it. (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.
 1.3 15-Jul-2008  dyoung branches: 1.3.2; 1.3.4;
Cosmetic: s/xenv/oenv/
 1.2 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.1 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.3.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.3.4.1 15-Jul-2008  mjf file media.c was added on branch mjf-devfs2 on 2008-09-28 11:17:11 +0000
 1.3.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.2.1 15-Jul-2008  wrstuden file media.c was added on branch wrstuden-revivesa on 2008-09-18 04:28:25 +0000
 1.6.24.1 04-Nov-2016  pgoyette Sync with HEAD
 1.7.14.1 10-Jun-2019  christos Sync with HEAD
 1.3 14-Oct-2020  roy ifconfig: go back to using direct ioctls rather than data from getifaddrs

AF_LINK may not be the first address returned for the interface.
Technically, it *might* not even exist on the interface even though
other families do.
This is likely a driver bug if this really is the case though.

As such it's just easier to use direct ioctls rather than thump around
getifaddrs results. As it stands, the code makes a lot of getifaddrs
calls anyway, so an extra ioctl or two won't break the bank.
 1.2 22-Sep-2020  roy ifconfig: Report link state even if media is not supported

For AF_LINK addrs from getifaddrs(2), ifa_data is struct if_data.
This in turn holds ifi_link_state which we can use to report
link status if the interface does not support media where it's normally
reported.

Based on OpenBSD.
 1.1 02-Jul-2008  dyoung branches: 1.1.2; 1.1.4;
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 02-Jul-2008  mjf file media.h was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 02-Jul-2008  wrstuden file media.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:25 +0000
 1.20 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.19 16-Aug-2019  msaitoh Whitespace fix.
 1.18 17-Jul-2013  christos branches: 1.18.28;
print the next parser name instead of just the pointer in debugging.
 1.17 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.16 01-Jul-2010  dyoung branches: 1.16.6; 1.16.12;
Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it. (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.
 1.15 20-Apr-2010  plunky C99 says that offsetof() expands to a constant expresssion, so we
can't use variable array index in there. Do the calculation manually
for C99 compilers (pcc)
 1.14 28-Jul-2009  dyoung Both carp.c and vlan.c expect for a keyword with a KW_T_STR-type
value to put a prop_string_t into the environment, but the keyword
parser put a prop_data_t into the environment, instead. That broke
the -vlanif and -carpdev keywords and defied developer expectations.
Let's put a prop_string_t into the environment.

Thanks to Arnaud Degroote for reporting the problem.
 1.13 18-Jan-2009  lukem fix -Wsign-compare issues
 1.12 01-Aug-2008  dyoung branches: 1.12.2; 1.12.4; 1.12.6;
Extract common code. Create subroutine paddr_prefix_size().
 1.11 01-Aug-2008  dyoung Always initialize the union of sockaddrs. I used to initialize it
only in the AF_UNSPEC/AF_INET/AF_INET6 cases. Maybe this will fix
the AF_APPLETALK problem that is@ reports:

random84# ifconfig nfe0 atalk 3.14
ifconfig: SIOCAIFADDR: Invalid argument
 1.10 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.9 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.8 19-May-2008  dyoung branches: 1.8.2;
Fix two bugs:

1 Let us associate a keyword with either a signed or an unsigned
number. Associate the '-chan' keyword with an unsigned number.
This fixes the defect that crashed 'ifconfig wi0 -chan', reported
by Michael van Elst.

2 Do not try to interpret names as ISO addresses unless the ISO
address family was specified. iso_addr(3) does not report errors,
so it appears to interpret *everything* as an ISO address. This
is a stopgap fix for the defect in 'ifconfig lo0 inet6' on a
!INET6 kernel that deletes the first IPv4 address on lo0.
(Reported by Scott Ellis.)
 1.7 12-May-2008  dyoung branches: 1.7.2;
Fix link-layer address parsing. Add debug statements.

Cosmetic: fix copyright whitespace.
 1.6 12-May-2008  dyoung Add code for parsing link-layer addresses of the form xx:xx:...:xx.
 1.5 09-May-2008  dyoung In address, integer, string parsers, gracefully handle a missing
token.
 1.4 07-May-2008  dyoung Fix a bug that I introduced in rev 1.88, where the default IPv6
prefix length changed from 64 to 128. While I am here, allow an
address to be given with prefix length /0, but interpret it as
/128.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3).
 1.2 06-May-2008  dyoung Add a license.
 1.1 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.3.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.2.3 04-Jun-2008  yamt sync with head
 1.7.2.2 18-May-2008  yamt sync with head.
 1.7.2.1 12-May-2008  yamt file parse.c was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.8.2.3 28-Sep-2008  mjf Sync with HEAD.
 1.8.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.1 19-May-2008  mjf file parse.c was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.12.6.1 21-Apr-2010  matt sync to netbsd-5
 1.12.4.1 14-Aug-2009  snj Pull up following revision(s) (requested by dyoung in ticket #878):
sbin/ifconfig/parse.c: revision 1.14
Both carp.c and vlan.c expect for a keyword with a KW_T_STR-type
value to put a prop_string_t into the environment, but the keyword
parser put a prop_data_t into the environment, instead. That broke
the -vlanif and -carpdev keywords and defied developer expectations.
Let's put a prop_string_t into the environment.
Thanks to Arnaud Degroote for reporting the problem.
 1.12.2.1 14-Aug-2009  snj Pull up following revision(s) (requested by dyoung in ticket #878):
sbin/ifconfig/parse.c: revision 1.14
Both carp.c and vlan.c expect for a keyword with a KW_T_STR-type
value to put a prop_string_t into the environment, but the keyword
parser put a prop_data_t into the environment, instead. That broke
the -vlanif and -carpdev keywords and defied developer expectations.
Let's put a prop_string_t into the environment.
Thanks to Arnaud Degroote for reporting the problem.
 1.16.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.12.1 23-Jun-2013  tls resync from head
 1.16.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.28.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9 16-Aug-2019  msaitoh Whitespace fix.
 1.8 30-Jun-2019  sevan Add rcsid
 1.7 01-Jul-2010  dyoung branches: 1.7.46;
Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it. (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.
 1.6 01-Aug-2008  dyoung Extract common code. Create subroutine paddr_prefix_size().
 1.5 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.4 19-May-2008  dyoung branches: 1.4.2;
Fix two bugs:

1 Let us associate a keyword with either a signed or an unsigned
number. Associate the '-chan' keyword with an unsigned number.
This fixes the defect that crashed 'ifconfig wi0 -chan', reported
by Michael van Elst.

2 Do not try to interpret names as ISO addresses unless the ISO
address family was specified. iso_addr(3) does not report errors,
so it appears to interpret *everything* as an ISO address. This
is a stopgap fix for the defect in 'ifconfig lo0 inet6' on a
!INET6 kernel that deletes the first IPv4 address on lo0.
(Reported by Scott Ellis.)
 1.3 07-May-2008  dyoung branches: 1.3.2;
Move IPv6 syntax to af_inet6.c from ifconfig.c. Move IFKW() macro
from ifconfig.c to parse.h for reuse.
 1.2 07-May-2008  dyoung Fix a bug that I introduced in rev 1.88, where the default IPv6
prefix length changed from 64 to 128. While I am here, allow an
address to be given with prefix length /0, but interpret it as
/128.
 1.1 06-May-2008  dyoung branches: 1.1.2;
Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.3.2.3 04-Jun-2008  yamt sync with head
 1.3.2.2 18-May-2008  yamt sync with head.
 1.3.2.1 07-May-2008  yamt file parse.h was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.4.2.3 28-Sep-2008  mjf Sync with HEAD.
 1.4.2.2 02-Jun-2008  mjf Sync with HEAD.
 1.4.2.1 19-May-2008  mjf file parse.h was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.7.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 21-Jun-2021  christos fix proplib deprecation
 1.3 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.2 16-Aug-2019  msaitoh Whitespace fix.
 1.1 14-Sep-2009  degroote branches: 1.1.46;
Import pfsync support from OpenBSD 4.2

Pfsync interface exposes change in the pf(4) over a pseudo-interface, and can
be used to synchronise different pf.

This work was part of my 2009 GSoC

No objection on tech-net@
 1.1.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 13-Dec-2010  pooka use crunchops for crunchables
 1.2 13-Dec-2010  njoly op_read return value is a ssize_t, not an int.
 1.1 13-Dec-2010  pooka Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.22 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.21 16-Aug-2019  msaitoh Whitespace fix.
 1.20 19-Oct-2013  christos branches: 1.20.26;
use correct function
 1.19 19-Oct-2013  christos use symbolic flags
 1.18 19-Oct-2013  christos use the new scopeid functions
 1.17 07-Aug-2009  dyoung branches: 1.17.6; 1.17.12;
Add option -N. -N is just the opposite of option -n in netstat(8)
or route(8): it tells ifconfig(8) to try to resolve numbers to
hosts and service names.

This default ifconfig behavior stays the same as it always was.
 1.16 15-Jul-2008  dyoung Cosmetic: s/xenv/oenv/
 1.15 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.14 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.13 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.12 07-May-2008  dyoung Move tunnel syntax into tunnel.c. Move net80211 'list' command
syntax into ieee80211.c.
 1.11 06-May-2008  dyoung branches: 1.11.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.10 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.9 26-Mar-2007  dyoung branches: 1.9.12; 1.9.14;
Don't try to convert numbers to names for either endpoint of a
tunnel. In this way, ifconfig will avoid emitting something
abominable like this:

tunnel 192.168.1.1,mdns --> 192.168.1.2,kazaa
 1.8 31-Aug-2006  dyoung Add a mode to gre(4) that sends GRE tunnel packets in UDP datagrams.
Fix MOBILE encapsulation. Add many debugging printfs (mainly
concerning UDP mode). Clean up the gre(4) code a bit. Add the
capability to setup UDP tunnels to ifconfig. Update documentation.

In UDP mode, gre(4) puts a GRE header onto transmitted packets,
and hands them to a UDP socket for transmission. That is, the
encapsulation looks like this: IP+UDP+GRE+encapsulated packet.

There are two ways to set up a UDP tunnel. One way is to tell the
source and destination IP+port to gre(4), and let gre(4) create
the socket. The other way to create a UDP tunnel is for userland
to "delegate" a UDP socket to the kernel.
 1.7 26-Aug-2006  christos Programs that use efun.
 1.6 16-Jun-2006  elad fix incorrect usage of strncpy() to (an internal implementation of)
estrlcpy().

okay christos
 1.5 20-Mar-2005  thorpej Split IPv6 support out into its own file.
 1.4 19-Mar-2005  thorpej const'ify afswtch
 1.3 19-Mar-2005  thorpej Don't hare-code inet/inet6 in tunnel_status(), lookup the address family
name instead.
 1.2 19-Mar-2005  yamt make this compilable with USE_INET6=no.
 1.1 19-Mar-2005  thorpej Split tunnel support into its own file.
 1.9.14.1 18-May-2008  yamt sync with head.
 1.9.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.9.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.17.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.20.26.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.4 07-May-2008  dyoung Move tunnel syntax into tunnel.c. Move net80211 'list' command
syntax into ieee80211.c.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.2 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1 19-Mar-2005  thorpej branches: 1.1.20; 1.1.22;
Split tunnel support into its own file.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.20 11-Oct-2020  roy ifconfig: if SIOCGLIFADDR fails, continue to the next address
 1.19 01-Oct-2019  kardel PR/54513 ifconfig exits on newly created carp interfaces
downgrade from err(EXIT_FAILURE, ... ) to warn() if ioctl(SIOCGLIFADDR) fails.
ifconfig now survives freshly created carp interfaces.
 1.18 16-Aug-2019  msaitoh Whitespace fix.
 1.17 19-Oct-2013  christos branches: 1.17.26;
use the new scopeid functions
 1.16 13-Dec-2010  pooka branches: 1.16.6; 1.16.12;
Convert from the .ifdef RUMP_ACTION stuff to RUMPPRG.
 1.15 01-Jul-2010  dyoung Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it. (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.
 1.14 01-Jul-2010  dyoung Change a > to a >= to avoid writing to the character after the end of
the buffer passed to get_string().
 1.13 11-Sep-2009  dyoung Make ifconfig(8) set and display preference numbers for IPv6
addresses. Make the kernel support SIOC[SG]IFADDRPREF for IPv6
interface addresses.

In in6ifa_ifpforlinklocal(), consult preference numbers before
making an otherwise arbitrary choice of in6_ifaddr. Otherwise,
preference numbers are *not* consulted by the kernel, but that will
be rather easy for somebody with a little bit of free time to fix.

Please note that setting the preference number for a link-local
IPv6 address does not work right, yet, but that ought to be fixed
soon.

In support of the changes above,

1 Add a method to struct domain for "externalizing" a sockaddr, and
provide an implementation for IPv6. Expect more work in this area: it
may be more proper to say that the IPv6 implementation "internalizes"
a sockaddr. Add sockaddr_externalize().

2 Add a subroutine, sofamily(), that returns a struct socket's address
family or AF_UNSPEC.

3 Make a lot of IPv4-specific code generic, and move it from
sys/netinet/ to sys/net/ for re-use by IPv6 parts of the kernel and
ifconfig(8).
 1.12 07-Aug-2009  dyoung Add option -N. -N is just the opposite of option -n in netstat(8)
or route(8): it tells ifconfig(8) to try to resolve numbers to
hosts and service names.

This default ifconfig behavior stays the same as it always was.
 1.11 27-Apr-2009  dyoung Bring getifaddrs(3) behavior in line with the documentation: the
ifa_data member of every AF_LINK struct ifaddrs points at the
corresponding struct if_data. In ifconfig(8), do not try to suppress
duplicate AF_LINK ifaddrs by checking for a NULL ifa_data.

Don't copy out two AF_LINK struct ifaddrs for each active link-layer
address. getifaddrs(3) used to copy out one ifaddrs for the kernel's
RTM_IFINFO message, and one more for the kernel's RTM_NEWADDR message.
I suppress the first duplicate with a highly conservative change that
wastes a little bit of ifaddrs storage. The storage is not leaked.
 1.10 21-Apr-2009  dyoung To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
 1.9 18-Jan-2009  lukem branches: 1.9.2;
fix -Wsign-compare issues
 1.8 02-Jul-2008  dyoung branches: 1.8.2; 1.8.6;
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.7 13-May-2008  dyoung branches: 1.7.2; 1.7.4;
Use an AF_LINK socket to add/delete/get link-layer addresses.
 1.6 12-May-2008  dyoung Cosmetic: fix copyright whitespace.
 1.5 12-May-2008  dyoung We cannot create an AF_LINK socket. If AF_LINK is requested, create
an AF_INET socket, instead.
 1.4 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.3 07-May-2008  dyoung Interpret 'prefixlen 0' as the maximum prefix length, as ifconfig
has always done.
 1.2 06-May-2008  dyoung branches: 1.2.2;
Add a license.
 1.1 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.2.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.7.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.7.4.1 13-May-2008  mjf file util.c was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.7.2.2 18-May-2008  yamt sync with head.
 1.7.2.1 13-May-2008  yamt file util.c was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.8.6.1 21-Apr-2010  matt sync to netbsd-5
 1.8.2.1 03-May-2009  bouyer Pull up following revision(s) (requested by dyoung in ticket #730):
sbin/ifconfig/af_link.c: revisions 1.4 - 1.6
sbin/ifconfig/util.h: revision 1.7
sbin/ifconfig/util.c: revisions 1.10, 1.11
lib/libc/net/getifaddrs.c: revision 1.12
lib/libc/net/getifaddrs.3: revision 1.10
sbin/ifconfig/ifconfig.c: revisions 1.216 - 1.218
Fix indentation: change spaces to tabs.
Use getnameinfo(3) to render a human-readable link-layer address in the
'address: ' line, just as we do in the 'link xx:xx:...:xx' line.
There's no use casting a socket address to sockaddr_dl, only to cast it
back to sockaddr, so don't do it.
Cosmetic: add some whitespace for my ease of reading.
To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
For non-AF_LINK ifaddrs, ifa_data is NULL. AFAICT, this has always been
so. Say so in the documentation.
Bring getifaddrs(3) behavior in line with the documentation: the
ifa_data member of every AF_LINK struct ifaddrs points at the
corresponding struct if_data. In ifconfig(8), do not try to suppress
duplicate AF_LINK ifaddrs by checking for a NULL ifa_data.
Don't copy out two AF_LINK struct ifaddrs for each active link-layer
address. getifaddrs(3) used to copy out one ifaddrs for the kernel's
RTM_IFINFO message, and one more for the kernel's RTM_NEWADDR message.
I suppress the first duplicate with a highly conservative change that
wastes a little bit of ifaddrs storage. The storage is not leaked.
 1.9.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.16.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.26.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13 30-Jun-2019  sevan Add rcsid
 1.12 07-Jan-2016  roy branches: 1.12.16;
-W seconds will wait for the detached flag to clear on addresses on
interfaces marked up to allow time for the carrier to appear on the
interface.

This does not extend the -w option duration.
 1.11 22-Apr-2015  roy Move the INET6 specific code for wait_dad_exec() into af_inet6
by using a new afswtch hook af_addr_tentative.
 1.10 19-Oct-2013  christos use the new scopeid functions
 1.9 01-Jul-2010  dyoung branches: 1.9.6; 1.9.12;
Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it. (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.
 1.8 11-Sep-2009  dyoung Make ifconfig(8) set and display preference numbers for IPv6
addresses. Make the kernel support SIOC[SG]IFADDRPREF for IPv6
interface addresses.

In in6ifa_ifpforlinklocal(), consult preference numbers before
making an otherwise arbitrary choice of in6_ifaddr. Otherwise,
preference numbers are *not* consulted by the kernel, but that will
be rather easy for somebody with a little bit of free time to fix.

Please note that setting the preference number for a link-local
IPv6 address does not work right, yet, but that ought to be fixed
soon.

In support of the changes above,

1 Add a method to struct domain for "externalizing" a sockaddr, and
provide an implementation for IPv6. Expect more work in this area: it
may be more proper to say that the IPv6 implementation "internalizes"
a sockaddr. Add sockaddr_externalize().

2 Add a subroutine, sofamily(), that returns a struct socket's address
family or AF_UNSPEC.

3 Make a lot of IPv4-specific code generic, and move it from
sys/netinet/ to sys/net/ for re-use by IPv6 parts of the kernel and
ifconfig(8).
 1.7 21-Apr-2009  dyoung To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
 1.6 02-Jul-2008  dyoung branches: 1.6.2; 1.6.4; 1.6.8;
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.5 03-Jun-2008  dyoung Remove remnants of struct afswtch.af_getprefix().
 1.4 07-May-2008  dyoung branches: 1.4.2; 1.4.4;
Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.2 06-May-2008  dyoung Rename in_addr_commit() to commit_address(), and refactor slightly
to support IPv6 as well as IPv4 (a work in progress).

Make the second argument of af_status() a bool instead of an int.

Exit early with an error if the operator specifies an unsupported
address family on the command line. The change should help rc
scripts to detect that IPv6 support is missing from the kernel,
with 'ifconfig lo0 inet6'.

Start using prop_dictionary_util(3).
 1.1 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.3.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.4.4.4 28-Sep-2008  mjf Sync with HEAD.
 1.4.4.3 29-Jun-2008  mjf Sync with HEAD.
 1.4.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.4.4.1 07-May-2008  mjf file util.h was added on branch mjf-devfs2 on 2008-06-02 13:21:22 +0000
 1.4.2.3 17-Jun-2008  yamt sync with head.
 1.4.2.2 18-May-2008  yamt sync with head.
 1.4.2.1 07-May-2008  yamt file util.h was added on branch yamt-pf42 on 2008-05-18 12:30:53 +0000
 1.6.8.1 21-Apr-2010  matt sync to netbsd-5
 1.6.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.6.2.1 03-May-2009  bouyer Pull up following revision(s) (requested by dyoung in ticket #730):
sbin/ifconfig/af_link.c: revisions 1.4 - 1.6
sbin/ifconfig/util.h: revision 1.7
sbin/ifconfig/util.c: revisions 1.10, 1.11
lib/libc/net/getifaddrs.c: revision 1.12
lib/libc/net/getifaddrs.3: revision 1.10
sbin/ifconfig/ifconfig.c: revisions 1.216 - 1.218
Fix indentation: change spaces to tabs.
Use getnameinfo(3) to render a human-readable link-layer address in the
'address: ' line, just as we do in the 'link xx:xx:...:xx' line.
There's no use casting a socket address to sockaddr_dl, only to cast it
back to sockaddr, so don't do it.
Cosmetic: add some whitespace for my ease of reading.
To make sure that we always print the active link-layer address in the
'address: ' field, don't treat the first address as the active address,
but search the link-layer addresses for the ones flagged IFLR_ACTIVE,
and print those. Extract a subroutine, print_link_addresses(), for
printing link-layer addresses.
For non-AF_LINK ifaddrs, ifa_data is NULL. AFAICT, this has always been
so. Say so in the documentation.
Bring getifaddrs(3) behavior in line with the documentation: the
ifa_data member of every AF_LINK struct ifaddrs points at the
corresponding struct if_data. In ifconfig(8), do not try to suppress
duplicate AF_LINK ifaddrs by checking for a NULL ifa_data.
Don't copy out two AF_LINK struct ifaddrs for each active link-layer
address. getifaddrs(3) used to copy out one ifaddrs for the kernel's
RTM_IFINFO message, and one more for the kernel's RTM_NEWADDR message.
I suppress the first duplicate with a highly conservative change that
wastes a little bit of ifaddrs storage. The storage is not leaked.
 1.9.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.16 21-Jun-2021  christos fix proplib deprecation
 1.15 16-Aug-2019  msaitoh Whitespace fix.
 1.14 15-Sep-2014  ozaki-r branches: 1.14.16;
Add -vlanif to the help message of ifconfig

PR 49114
 1.13 28-Jul-2009  dyoung branches: 1.13.8; 1.13.24;
Don't require a "vlan" argument with "-vlanif". "ifconfig vlan0
-vlanif" works as one would expect, now.
 1.12 15-Jul-2008  dyoung branches: 1.12.2; 1.12.6; 1.12.8;
Cosmetic: s/xenv/oenv/
 1.11 15-Jul-2008  dyoung Only describe flags -L and -m in the usage if they are available.
That helps me get rid of some conditional compilation (INET6) in
ifconfig.

Let each protocol/feature-module print its own usage, so that the
ifconfig usage reflects the modules that are actually compiled-in.

Write usage information for carp(4) options.
 1.10 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.9 16-May-2008  dyoung The key 'vlantag' activates the 'vlanif' keyword, not the key
'vlan'. Should fix this bug reported by Pierre Pronchery,

# ifconfig vlan0 vlan 1 vlanif hme0
ifconfig: SIOCAIFADDR: Address family not supported by protocol family
 1.8 07-May-2008  dyoung Factor out common code, creating direct_ioctl() and indirect_ioctl()
for the two most prevalent styles of ioctl(2) calls in ifconfig(8).
 1.7 07-May-2008  dyoung Move vlan(4) syntax from ifconfig.c into vlan.c.
 1.6 06-May-2008  dyoung branches: 1.6.2;
Use prop_dictionary_util(3).
 1.5 06-May-2008  dyoung Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.4 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.3 19-Mar-2005  thorpej branches: 1.3.20; 1.3.22;
name -> ifname (avoid shadow decl with global name[]).
 1.2 19-Mar-2005  thorpej Move extern decls to extern.h
 1.1 19-Mar-2005  thorpej Split VLAN configuration bits out into a separate file.
 1.3.22.1 18-May-2008  yamt sync with head.
 1.3.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.3.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.12.8.1 21-Apr-2010  matt sync to netbsd-5
 1.12.6.1 14-Aug-2009  snj Pull up following revision(s) (requested by dyoung in ticket #879):
sbin/ifconfig/vlan.c: revision 1.13
Don't require a "vlan" argument with "-vlanif". "ifconfig vlan0
-vlanif" works as one would expect, now.
 1.12.2.1 14-Aug-2009  snj Pull up following revision(s) (requested by dyoung in ticket #879):
sbin/ifconfig/vlan.c: revision 1.13
Don't require a "vlan" argument with "-vlanif". "ifconfig vlan0
-vlanif" works as one would expect, now.
 1.13.24.1 22-Sep-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #108):
sbin/ifconfig/vlan.c: revision 1.14
sbin/ifconfig/ifconfig.8: revision 1.108
sys/net/if_vlan.c: revision 1.71-1.74

Document -vlanif in ifconfig.8 and in usage measseg (PR 49114).
Leave promiscuous mode when detaching a parent (PR 49196) and
delete link local addresses (49197).
Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig
(PR 49112).
Call if_input of vlan interface itself, not parent one.
This allows bridging vlan interfaces again.
 1.13.8.1 03-Nov-2014  msaitoh Pull up following revision(s) (requested by ozaki-r in ticket #1156):
sbin/ifconfig/vlan.c: revision 1.14
sbin/ifconfig/ifconfig.8: revision 1.108
sys/net/if_vlan.c: revision 1.71
sys/net/if_vlan.c: revision 1.73
sys/net/if_vlan.c: revision 1.74
- PR#49114: Write about -vlanif in ifconfig.8.
Add -vlanif to the help message of ifconfig.
- PR#49196: Leave promiscuous mode when detaching a parent (ifconfig -vlanif)
We have to call ifpromisc(ifp, 0) for both a VLAN interface
and its parent when they are in promiscuous mode.
- PR#49197: Delete link local addresses of a vlan interface when detaching its
parent.
- PR#49112: Restore vlan_ioctl overwritten by ether_ifdetach in vlan_unconfig
 1.14.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5 02-Jul-2008  dyoung Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.

(In principle, ifconfig could load virtually all of its syntax from
shared objects.)

Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.

Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.

Sprinkle static. Change some int's to bool's. Constify.

Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.

Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.

Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
 1.4 07-May-2008  dyoung Move vlan(4) syntax from ifconfig.c into vlan.c.
 1.3 06-May-2008  dyoung branches: 1.3.2;
Use prop_dictionary_util(3) some more.

When we read interface flags and capabilities from the kernel, take
care not to record them in our current environment (env), but record
them in the output environment (oenv), instead. This helps us get
interface capabilities and flags right.
 1.2 06-May-2008  dyoung Overhaul ifconfig. Use fewer global variables. Take a leap toward
improved modularity and extensibility.

In the new architecture, a directed graph of argument-matching
objects (match objects) expresses the set of feasible ifconfig
statements. Match objects are labelled by subroutines that provide
the statement semantics.

Many IPv4, IPv6, 802.11, tunnel, and media configurations have been
tested.

AppleTalk, ISO, carp(4), agr(4), and vlan(4) configuration need
testing.
 1.1 19-Mar-2005  thorpej branches: 1.1.20; 1.1.22;
Split VLAN configuration bits out into a separate file.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3.2.2 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.41 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.40 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.39 15-Jul-2013  khorben branches: 1.39.28;
Let init be built easily with the CHROOT capability enabled.

This allows the ramdisk used in the incoming support for full-disk encryption to contain crunched binaries (much like sysinst) while booting a regular system (unlike sysinst).
 1.38 11-Apr-2009  lukem branches: 1.38.6; 1.38.12;
Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.37 04-Feb-2007  christos branches: 1.37.12; 1.37.22;
warns=4
 1.36 18-Apr-2006  salo Add support for running multi-user in a chroot() environment.

How it works:

- after successful execution of /etc/rc, check the value of "init.root"
sysctl node, if it's different than "/", chroot() into its value and run
/etc/rc inside the chroot(),

- in single-user, return back to the original / file system.

Allows running with / file system on e.g., cgd(4), vnd(4) or ccd(4) volumes.

Idea first discussed with Matt Thomas, implemented by Jachym Holecek <freza
(at) liberouter.org> with some nitpicks by me. Successfully used by me for
almost a year with / on a cgd(4) volume (for more information about the setup
check ftp://ftp.NetBSD.org/pub/NetBSD/misc/salo/init-chroot/ ).
 1.35 13-Jan-2005  lukem Revert previous revert; we don't need RESCUEDIR handling here now
<bsd.prog.mk> has it.
 1.34 10-Jan-2005  lukem Revert previous; init(8) still needs special case handling for RESCUEDIR
otherwise the path to mount_mfs(8) and the standard $PATH will be wrong...
 1.33 19-Aug-2004  christos Remove RESCUEDIR hack; it will be done centrally.
 1.32 26-May-2003  lukem If RESCUEDIR is defined, use that as an alternate path to sh and mount_mfs,
and prepend RESCUEDIR to the default PATH.
(This replaces my _PATH_ALTSHELL mods from rev 1.52 of init.c)
 1.31 24-Aug-2002  lukem if RESCUEDIR is defined, use ${RESCUEDIR}/sh as _PATH_ALTSHELL
 1.30 24-Aug-2002  lukem now that we have working rescue tools, there's no need to force
LDSTATIC=-static for init(8) on people who want LDSTATIC=""
 1.29 02-Aug-2002  christos fix typos that prevented us from cleaning utmpx. Noted by wiz
 1.28 27-Jul-2002  christos add utmpx/wtmpx processing support.
 1.27 03-Feb-2002  lukem .ifdef SMALLPROG, compile without ALTSHELL and SECURE support
 1.26 21-Jan-2002  abs Rename MSDOSFS_ROOT to MFS_DEV_IF_NO_CONSOLE, and rework:
- Always attempt mfs dev if missing /dev/console
- Save and run both MAKEDEV and MAKEDEV.local
- After creating the mfs dev, mknod() and freopen() /dev/console.
- If MAKEDEV is missing do not fail out early, but still create the mfs,
/dev/console.
- If we hit any errors fail out to single user.
This change _only_ affects systems booting without /dev/console.
 1.25 28-Dec-2001  lukem * Add user-controlled mk.conf variables
- SHLIBDIR Location to install shared libraries if ${USE_SHLIBDIR}
is "yes". Defaults to "/usr/lib".

- USE_SHLIBDIR If "yes", install shared libraries in ${SHLIBDIR}
instead of ${LIBDIR}. Defaults to "no".
Sets ${_LIBSODIR} to the appropriate value.
This may be set by individual Makefiles as well.

- SHLINKDIR Location of shared linker. Defaults to "/usr/libexec".
If != "/usr/libexec", change the dynamic-linker
encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

1.) If nothing is set or changed, there is no change from the
current behaviour:
- Static /bin, /sbin, and bits of /usr/*
- Dynamic rest
- Shared linker is /usr/libexec/ld*so

2.) If the following make variables are set:
LDSTATIC=
SHLINKDIR=/lib
SHLIBDIR=/lib
Then the behaviour becomes:
- Dynamic tools
- .so libraries used by /bin and /sbin are installed to /lib,
with symlinks from /usr/lib/lib*so to -> /lib/lib*so
where appropriate
- Shared linker is /lib/ld*so

3.) As per 2.), but add the following variable:
USE_SHLIBDIR=yes
This forces all .so's to be instaleld in /lib (with compat
symlinks), not just those tagged by their Makefiles to be.
Again, compat symlinks are installed
 1.24 18-Oct-2000  simonb Remove INSTALLFLAGS=-fschg, as per change to usr.bin/ssh/ssh/Makefile.
 1.23 19-Mar-2000  soren branches: 1.23.4;
The mode 0544 workaround has not been necessary since the first BSDi import.
 1.22 11-Oct-1997  mycroft Make these executables world-readable.
 1.21 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.20 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.19 30-Jul-1997  christos Support root on msdos filesystems by creating an mfs on /dev and running
MAKEDEV all to create the devices. Idea by Chris Demetriou.
 1.18 19-Jul-1997  perry add WARN=1
 1.17 19-Jul-1997  perry rename DEBUGSHELL to ALTSHELL
 1.16 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.15 22-Dec-1994  cgd specify man pages the new way.
 1.14 11-Jun-1994  mycroft Fix up RCS ids.
 1.13 10-Jun-1994  pk Update to 4.4-lite (basically some copyright changes) + local changes.
 1.12 07-Oct-1993  cgd always use libcrypt
 1.11 07-Aug-1993  cgd merge in changes from netbsd-0-9-ALPHA2
 1.10 01-Aug-1993  mycroft Add RCS identifiers.
 1.9 08-Jul-1993  cgd branches: 1.9.2;
get rid of the bogus changes i made to init. note that /etc/ttys
*must* have an entry for "console", though it should be "off",
prolly.
 1.8 18-Jun-1993  cgd a couple of local mods; always ask for shell in single user, use -lcrypt,
use root's shell rather that /bin/sh when going to single-user, etc.
 1.7 18-Jun-1993  cgd incorporate bsdi's version of init; this is their version, w/no local changes
other than adding Id strings as appropriate
 1.6 10-Jun-1993  cgd add preliminary support for devfs (e.g. MOUNT_DEVFS #define, etc.)
 1.5 26-Apr-1993  cgd changed to use new libcrypt scheme.
 1.4 23-Mar-1993  cgd added secure init patch
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.2.1 30-Jul-1993  cgd get rid of -DDEBUGSHELL
 1.23.4.2 13-Feb-2002  he Pull up revision 1.26 (requested by abs):
Add support to try to set up an MFS based /dev file system if
/dev/console is missing.
Here: enable recently pulled up code to init.c.
 1.23.4.1 18-Oct-2000  tv Pull up 1.24 [simonb]:
Remove INSTALLFLAGS=-fschg.
 1.37.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.37.12.1 29-Mar-2008  mjf - etc/devfsd.conf: Add some rules to give nodes like /dev/tty and
/dev/null better default modes, i.e. 0666.

- sbin/init: Run devfsd -s before going to multiuser.

- sys/arch: Provide arm32, i386, sparc with a mem_init() function to request
device nodes for /dev/null, /dev/zero, etc.

- sys/dev: Convert rnd, wd, agp, raid, cd, sd, wsdisplay, wskbd, wsmouse,
wsmux, tty, bpf, swap to devfs New World Order.

- sys/fs/devfs: Make the visibility attribute of device nodes configurable.
Also provide a function to mount a devfs on boot.

- sys/kern: Add a new boot flag, -n. This disables devfs support. Unless
the -n flag is specified the kernel will mount a devfs file
system on boot.
 1.38.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.39.28.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 18-Apr-2006  salo Add support for running multi-user in a chroot() environment.

How it works:

- after successful execution of /etc/rc, check the value of "init.root"
sysctl node, if it's different than "/", chroot() into its value and run
/etc/rc inside the chroot(),

- in single-user, return back to the original / file system.

Allows running with / file system on e.g., cgd(4), vnd(4) or ccd(4) volumes.

Idea first discussed with Matt Thomas, implemented by Jachym Holecek <freza
(at) liberouter.org> with some nitpicks by me. Successfully used by me for
almost a year with / on a cgd(4) volume (for more information about the setup
check ftp://ftp.NetBSD.org/pub/NetBSD/misc/salo/init-chroot/ ).
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 10-Jun-1994  pk branches: 1.1.1;
Update to 4.4-lite (basically some copyright changes) + local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.2 10-Jun-1994  mycroft Clean up deleted files.
 1.1 18-Jun-1993  cgd incorporate bsdi's version of init; this is their version, w/no local changes
other than adding Id strings as appropriate
 1.62 01-Sep-2019  wiz Remove superfluous Pp.
 1.61 01-Sep-2019  sevan grammar
 1.60 11-Sep-2016  sevan branches: 1.60.14; 1.60.16;
init first appeared in V1 UNIX
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/init.s
Replace contraction.
Bump date.
 1.59 02-Oct-2013  apb The "-s" flag is passed to init by the kernel, not by the boot loader.
 1.58 02-Oct-2013  apb Document that the kernel may try several paths for init.

XXX: This should be in the kernel documentation, not in the init(8) man page.
 1.57 18-May-2009  wiz branches: 1.57.6; 1.57.12;
Sort SEE ALSO.
 1.56 08-Apr-2009  joerg Remove physical markup.
 1.55 11-Nov-2008  wiz branches: 1.55.2;
Add backslash (minus is "\-").
 1.54 11-Nov-2008  reed Add some details about init's role with securelevel.
Add references to other manual pages for more details.
 1.53 21-Oct-2008  lukem branches: 1.53.2;
xref rescue(8)
 1.52 09-Feb-2008  dholland branches: 1.52.4;
Mention utmpx/wtmpx as well as utmp/wtmp. Suggested by the patches in
PR bin/36551 by Greg A. Woods. Also, while I'm here, fix a miscapitalized
word.
 1.51 15-Dec-2007  snj Sort xrefs.
 1.50 15-Dec-2007  apb Update for the fact that MAKEDEV uses either tmpfs or mfs.
 1.49 09-Dec-2007  apb * init calls "MAKEDEV -MM init", not "MAKEDEV -M init"
* s/filesystem/file system/
* one typo and one markup fix
* bump date
 1.48 24-Mar-2007  hubertf branches: 1.48.4; 1.48.6;
backout previous.
 1.47 23-Mar-2007  hubertf Call the pivot root by it's name.
 1.46 03-Mar-2007  dsl Update info about running MAKEDEV to note that MAKEDEV itself now creates
the mfs filesystem.
 1.45 03-Mar-2007  apb Remove all reference to MAKEDEV.subr. Add a reference to MAKEDEV.local.
 1.44 02-Mar-2007  wiz Bump date for previous.
 1.43 01-Mar-2007  apb When creating /dev in a memory file system, include all three of
MAKEDEV, MAKEDEV.subr and MAKEDEV.local in the set of files that are
copied if they exist.

Now booting an INSTALL kernel with an embedded ramdisk correctly creates
/dev again, fixing a problem introduced when MAKEDEV.subr was created a
few days ago.
 1.42 15-Sep-2006  elad Remove securelevel-related text from init(8) man-page as they're now in
secmodel_bsd44(9).

I'm not sure I agree with the BUGS section, but for now move it to
secmodel_bsd44(9) as well.
 1.41 15-Sep-2006  wiz Bump date for previous.
 1.40 15-Sep-2006  elad Remove sentence no longer true.
 1.39 23-Apr-2006  wiz New sentence, new line.
 1.38 18-Apr-2006  salo Add support for running multi-user in a chroot() environment.

How it works:

- after successful execution of /etc/rc, check the value of "init.root"
sysctl node, if it's different than "/", chroot() into its value and run
/etc/rc inside the chroot(),

- in single-user, return back to the original / file system.

Allows running with / file system on e.g., cgd(4), vnd(4) or ccd(4) volumes.

Idea first discussed with Matt Thomas, implemented by Jachym Holecek <freza
(at) liberouter.org> with some nitpicks by me. Successfully used by me for
almost a year with / on a cgd(4) volume (for more information about the setup
check ftp://ftp.NetBSD.org/pub/NetBSD/misc/salo/init-chroot/ ).
 1.37 13-Nov-2005  elad The securelevel does not affect whether Veriexec's tables can be modified;
this is now controlled by Veriexec's strict level.
 1.36 01-Jul-2005  wiz Mark up more paths with .Pa, and
break a line (<=80 chars per line).
 1.35 30-Jun-2005  snj Use more macros and sort xrefs.
 1.34 30-Jun-2005  christos Patch from Jeremy Reed to describe how MFS /dev works. Thanks!
 1.33 20-Jun-2005  peter Change all .Xr config 8 to .Xr config 1, following the recent move of
config from usr.sbin -> usr.bin.

Reviewed by wiz.
 1.32 01-Apr-2005  abs Fix typo 'and the go' -> 'and then go'
 1.31 19-Feb-2004  lukem veriexec can't be changed at securelevel 1
 1.30 12-Oct-2003  wiz Bump date for previous; new sentence, new line; use more macros; fix a typo.
 1.29 12-Oct-2003  tls Add an explanation of the fundamental purpose of the "security level"
mechanism and attempt to explain how to use it effectively.
 1.28 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.27 14-May-2003  wiz setup -> set up.
 1.26 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.25 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.24 16-Nov-2001  wiz Sort sections and SEE ALSO.
 1.23 05-Jun-2001  wiz Drop arguments of .Os.
 1.22 29-Apr-2000  lukem document the conditions for /etc/rc to be called with "autoboot"
 1.21 26-Apr-2000  lukem Using the `NOTES' file and source code as a reference, attempt to more
accurately explain the operation of init(8)'s state machine.
 1.20 19-Mar-2000  soren Remove reference to crash(8).
 1.19 28-Sep-1999  bouyer Note that proc.<pid>.corename susctl node is read-only at securelevel >= 2.
 1.18 14-Nov-1998  tls branches: 1.18.4;
document ipf change at securelevel >= 2
 1.17 14-Nov-1998  tls reflect new securelevel 2 changes
 1.16 17-Jul-1998  perry fix a typo, pointed out in pr-5785 from Mason Loring Bliss
 1.15 25-May-1998  msaitoh fix a bug.
 1.14 29-Apr-1998  fair fix a bad .Xr
 1.13 29-Apr-1998  fair fix bad .Xr references
 1.12 11-Oct-1997  enami Sort items of section 8 in SEE ALSO list alphabetical order.
 1.11 15-Sep-1997  lukem cleanup use of .Nm
 1.10 19-Jul-1997  perry in NetBSD, setting the clock back is inhibited in securelevel 2, not s-lev 1
 1.9 19-Jul-1997  perry (mostly) merge lite-2 changes (except for some silly ones.)
 1.8 30-Jun-1997  phil Better specify which flags can't be change at level 1. (PR 3299)
Make all "multiuser" be "multi-user" to conform with other "multi-user"
usage.
 1.7 17-Jan-1997  perry close pr-2717 from Manuel Bouyer <bouyer@lix.polytechnique.fr>
Replaces reference to hand patching securelevel kernel variable
with reference to options INSECURE.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 23-Sep-1994  mycroft Changes to match POSIXication of kill(1).
 1.4 11-Jun-1994  mycroft Fix up RCS ids.
 1.3 10-Jun-1994  pk Update to 4.4-lite (basically some copyright changes) + local changes.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 18-Jun-1993  cgd branches: 1.1.1;
incorporate bsdi's version of init; this is their version, w/no local changes
other than adding Id strings as appropriate
 1.1.1.2 19-Jul-1997  perry imported from 44lite2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.18.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.48.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.48.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.48.4.2 23-Mar-2008  matt sync with HEAD
 1.48.4.1 09-Jan-2008  matt sync with HEAD
 1.52.4.1 17-Jan-2009  mjf Sync with HEAD.
 1.53.2.2 12-Nov-2008  snj Pull up following revision(s) (requested by reed in ticket #46):
sbin/init/init.8: revision 1.55
Add backslash (minus is "\-").
 1.53.2.1 12-Nov-2008  snj Pull up following revision(s) (requested by reed in ticket #46):
sbin/init/init.8: revision 1.54
Add some details about init's role with securelevel.
Add references to other manual pages for more details.
 1.55.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.57.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.57.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.60.16.1 05-Sep-2019  martin Pull up following revision(s) (requested by sevan in ticket #174):
lib/libc/sys/chmod.2: revision 1.48
lib/libc/sys/stat.2: revision 1.59
lib/libc/sys/unlink.2: revision 1.30
lib/libc/sys/lseek.2: revision 1.25
lib/libc/sys/getuid.2: revision 1.18
lib/libc/sys/chown.2: revision 1.37
lib/libm/man/exp.3: revision 1.32
lib/libm/man/log.3: revision 1.7
lib/libc/sys/open.2: revision 1.60
lib/libc/stdio/fopen.3: revision 1.36
lib/libc/stdio/putc.3: revision 1.14
lib/libc/sys/mount.2: revision 1.51
share/man/man9/copy.9: revision 1.22
share/man/man9/uiomove.9: revision 1.20
lib/libc/sys/setuid.2: revision 1.23
lib/libc/sys/close.2: revision 1.18
sbin/init/init.8: revision 1.61
lib/libc/sys/write.2: revision 1.36
lib/libc/sys/read.2: revision 1.39
sbin/init/init.8: revision 1.62
lib/libc/sys/wait.2: revision 1.40
usr.bin/tty/tty.1: revision 1.10
lib/libc/sys/link.2: revision 1.33
usr.bin/du/du.1: revision 1.24
lib/libc/stdlib/exit.3: revision 1.17
usr.bin/su/su.1: revision 1.53
usr.bin/mail/mail.1: revision 1.66
lib/libc/sys/fork.2: revision 1.25
usr.bin/su/su.1: revision 1.54
usr.bin/mail/mail.1: revision 1.67
lib/libm/man/sin.3: revision 1.15
share/man/man9/intro.9: revision 1.26
share/man/man5/utmp.5: revision 1.17
lib/libc/compat-43/creat.3: revision 1.17
lib/libc/time/ctime.3: revision 1.61
lib/libcompat/4.1/stty.3: revision 1.10
usr.bin/dc/dc.1: revision 1.3
lib/libm/man/cos.3: revision 1.17
lib/libc/sys/chdir.2: revision 1.23
lib/libc/gen/exec.3: revision 1.30
lib/libc/gen/exec.3: revision 1.31
games/bcd/bcd.6: revision 1.18
games/bcd/bcd.6: revision 1.19
usr.bin/write/write.1: revision 1.7
usr.bin/wc/wc.1: revision 1.18
usr.bin/pr/pr.1: revision 1.24
usr.bin/who/who.1: revision 1.25
lib/libc/sys/mkdir.2: revision 1.30
lib/libc/stdio/getc.3: revision 1.13
usr.bin/sort/sort.1: revision 1.40
usr.bin/mesg/mesg.1: revision 1.11
share/man/man5/passwd.5: revision 1.34
sort was there since v1
https://www.bell-labs.com/usr/dmr/www/man61.pdf

dc was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

du was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mail was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

mesg was in v1
https://www.bell-labs.com/usr/dmr/www/man12.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

su was in v1
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man13.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man14.pdf
Update URL

write was in v1
https://www.bell-labs.com/usr/dmr/www/man14.pdf
grammar

passwd(5) was in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

utmp(5) was present in v1
https://www.bell-labs.com/usr/dmr/www/man51.pdf

Earliest version of wtmp I could find was in v3
https://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man5/wtmp.5

Document history of chdir(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chmod(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of chown(2)
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

create was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history of exec()
Move statement on execlpe() & execvpe() to HISTORY section.

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

fork was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
stat() was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

document history of fstat()
https://www.bell-labs.com/usr/dmr/www/man21.pdf

getuid was present in v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

Document history
https://www.bell-labs.com/usr/dmr/www/man21.pdf

stty & gtty were around since v1
https://www.bell-labs.com/usr/dmr/www/man21.pdf
https://www.bell-labs.com/usr/dmr/www/man22.pdf

mount & umount were present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

Open was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

read was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

seek was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

setuid was in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

unlink was presen in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

wait was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

write was present in v1
https://www.bell-labs.com/usr/dmr/www/man22.pdf

start documenting history
exp was present in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

log appeared in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putc & putw were in v1
https://www.bell-labs.com/usr/dmr/www/man31.pdf

putchar was in v4
https://minie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man3/putchr.3

Start documenting history
https://www.bell-labs.com/usr/dmr/www/man31.pdf

Document history.
https://www.bell-labs.com/usr/dmr/www/man11.pdf
Between v1 & v6 UNIX, bcd was rewritten in C, but I don't know if which
version,
hence I've skipped mentioning it.
End sentence with a dot.
Remove superfluous Pp.
Remove superfluous Pp.
Remove superfluous Ns.
Remove superfluous Pp.
fetch(9) -> ufetch(9)
fetch(9) -> ufetch(9). Remove superfluous Pp.
fetch(9) -> ufetch(9). Remove reference to unimplemented ppi(9).
 1.60.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.109 11-Oct-2021  jmcneill Allow getty to exit quickly a few times before deciding that it is exiting
too quickly. Based on a FreeBSD change from 1994.
 1.108 22-Jun-2020  msaitoh s/successfuly/successfully/ in comment. No functional change.
 1.107 14-Oct-2015  christos these are syslog-like
 1.106 16-Jun-2015  christos fix error messages containing \n
 1.105 09-Nov-2012  msaitoh Add missing free() in error path.
 1.104 04-Nov-2012  christos include the needed headers
 1.103 20-Mar-2012  matt branches: 1.103.2;
Convert to C89 function definitions
 1.102 28-Aug-2011  christos branches: 1.102.2; 1.102.4;
make it compile with SMALLPROG
 1.101 27-Aug-2011  joerg Be more static
 1.100 29-Dec-2009  elad Keep an internal variable indicating whether securelevel is present, and
don't blindly try to get/set it. Prevents error messages that don't make
sense if securelevel isn't supported by the kernel.
 1.99 22-Nov-2009  mbalmer s/the the/the/
 1.98 12-Apr-2009  apb If MAKEDEV exits non-zero, but was nevertheless able to create
/dev/console, then have init(8) just print a warning instead of
exiting.
 1.97 18-Jan-2009  lukem branches: 1.97.2;
fix -Wsign-compare issues
 1.96 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.95 18-Mar-2008  christos branches: 1.95.4;
un-bitrot #if 0 testing code.
 1.94 09-Dec-2007  apb branches: 1.94.4; 1.94.6;
No need to pass "-ppax" to MAKEDEV now that MAKEDEV internally defaults
to using pax.
 1.93 21-Mar-2007  dyoung branches: 1.93.4; 1.93.6;
KNF.
 1.92 11-Mar-2007  apb Adapt to the new MAKEDEV interpretation of -M by passing -MM.

Also pass "-ppax" in an attempt to get improved performance,
but this doesn't really work in the typical case, because the
install ramdisk image contains a version of pax(1) that doesn't
support the -M flag. (MAKEDEV detects the failure and falls back
to using mknod(8) as usual.)
 1.91 02-Mar-2007  dsl Instead of creating the mfs /dev here, get MAKEDEV to do it.
Removes a load of code that is easier done as a script.
Whenever init exits, use a different error number. Since it is difficult
for init to output messages when /dev/console is absent, having the exit
code reported by the kernel panic gives a chance of identifying the fault.
Also exit if MAKEDEV fails to create /dev/console.
 1.90 01-Mar-2007  apb When calculating the size of the MFS /dev file system, round file sizes
up to a multiple of 512. (Not doing this before was wrong but probably
asymptomatic, because there was enough slack space to cope with the
error).
 1.89 01-Mar-2007  apb When creating /dev in a memory file system, include all three of
MAKEDEV, MAKEDEV.subr and MAKEDEV.local in the set of files that are
copied if they exist.

Now booting an INSTALL kernel with an embedded ramdisk correctly creates
/dev again, fixing a problem introduced when MAKEDEV.subr was created a
few days ago.
 1.88 15-Feb-2007  tron Increase the numbers of inodes available on the "/dev" MFS to 1280.
This should fix the "sysinst" problems caused by adding more devices
node to resolve PR port-amd64/35532.
 1.87 06-Feb-2007  cbiere Revert previous commit.
 1.86 05-Feb-2007  cbiere * 0/1 -> EXIT_{SUCCESS,FAILURE}
* make_utmpx(): Added comment and slightly simpler construct.
* alrm_handler(): Suppress "unused parameter" warning.
* mapfile():
* Handle st.st_size correctly.
* Avoid unnecessary return statements.
* Removed unnecessary MAP_FILE flag.
* Use S_ISLNK() and check S_ISREG() too.
* Add the terminating NUL rather after readlink() than
before, just in case.
* writefile():
* Avoid unnecessary return statements.
* read_ttys():
* Check S_ISREG() as well.
* Check for st.st_size > 0 rather than != 0.
 1.85 05-Feb-2007  njoly Fix compilation on 64bit platforms.
ok by elad.
 1.84 04-Feb-2007  christos - close the utmpx file.
- sprinkle void
- use size_t consistently.
 1.83 20-Jan-2007  isaki Make it compile without SUPPORT_UTMP nor SUPPORT_UTMPX.
 1.82 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.81 28-Sep-2006  christos branches: 1.81.2;
Don't record runlvl transitions before we have a read-write /var. Noticed
by lrou at x dot ua.
 1.80 25-Sep-2006  christos Error message consistency:
1. don't print the program name in the message [syslog does it]
2. no extraneous \n [syslog takes care of it]
3. quote strings as `%s' [we are using syslog]
4. use %m instead of error = %d
 1.79 23-Sep-2006  he Um, correct previous, so that current_state def/use is consistent.
 1.78 23-Sep-2006  he Since current_state is conditionally defined, make sure its uses are as well.
 1.77 22-Sep-2006  christos Try entertain who(1) because it has been sad since it was swallowed by the
Death Star: add utmpx entries for boot time, down time, run level, login
process.
 1.76 30-Jul-2006  elad update comment, thanks freza@.
 1.75 30-Jul-2006  elad CTLFLAG_READONLY1 was deprecated in earlier commit, remove it here too
 1.74 30-Jul-2006  elad remove CTLFLAG_READONLY1 usage. pointed out by cube@, thanks..
 1.73 18-Apr-2006  salo Add support for running multi-user in a chroot() environment.

How it works:

- after successful execution of /etc/rc, check the value of "init.root"
sysctl node, if it's different than "/", chroot() into its value and run
/etc/rc inside the chroot(),

- in single-user, return back to the original / file system.

Allows running with / file system on e.g., cgd(4), vnd(4) or ccd(4) volumes.

Idea first discussed with Matt Thomas, implemented by Jachym Holecek <freza
(at) liberouter.org> with some nitpicks by me. Successfully used by me for
almost a year with / on a cgd(4) volume (for more information about the setup
check ftp://ftp.NetBSD.org/pub/NetBSD/misc/salo/init-chroot/ ).
 1.72 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.71 17-Mar-2006  chris Fix case where argv wasn't returned or freed.

This fixes Coverity CID 2023.

While here also return NULL if the malloc fails.
 1.70 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.69 15-Mar-2005  xtraeme Bump the number of inodes to 1024 in the MFS case, needed to
create more devices in the ramdisk images, ok'ed by thorpej@.
 1.68 12-Oct-2004  dan be explicit about the perms of mfs /dev
 1.67 13-Aug-2004  mycroft Put back one of the sleep()s -- it doesn't affect us in the usual case.
 1.66 13-Aug-2004  mycroft Replace the sleep(2) in setctty() with a nanosleep(), with a default value of
250ms.
 1.65 13-Aug-2004  mycroft Remove a completely gratuitous 30 delay if you enter the wrong shell path.
 1.64 06-Jun-2004  christos clear_session_logs is not needed when we are small.
 1.63 03-Oct-2003  dsl branches: 1.63.2;
If /dev/constty exists, use it instead of /dev/console for single user shell.
I'm not 100% certain it should call login_tty() for anything else.
 1.62 11-Sep-2003  dsl If /dev/MAKEDEV is a symlink then preserve the symlink in the mfs /dev.
If /dev/MAKEDEV doesn't exist then try to run /etc/MAKEDEV instead.
Use the (new) '-n inodes' option to mount_mfs and base the size on the number
of inodes and the size of the MAKEDEV script.
 1.61 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.60 05-Aug-2003  dsl Exit child process if we fail to 'cd /dev' or 'execl sh MAKEDEV'.
Don't really want two processes in the rest of init!
 1.59 12-Jul-2003  itojun use asprintf, which is easier
 1.58 01-Jul-2003  christos Avoid code duplication by factoring out the open/map open/write/unmap functions.
 1.57 01-Jul-2003  lukem Always compile in support for attempting to obtain the major device
number of the console from sysctl("machdep.console_device"), rather
than making in optional on the (unused) #ifdef DEBUG.
Certain platforms do not have the console at makedev(0,0) (including
many arm32 and some sh3 platforms), so the "mfs MAKEDEV" hack would
have failed on those.

Noted in private discussion with Quentin Barnes.
 1.56 26-May-2003  lukem If RESCUEDIR is defined, use that as an alternate path to sh and mount_mfs,
and prepend RESCUEDIR to the default PATH.
(This replaces my _PATH_ALTSHELL mods from rev 1.52 of init.c)
 1.55 20-Apr-2003  christos PR/5544: Anders Magnusson: Init segfaults when hupped in single user.
- fix so that session_db is not de-referenced when null, and other
possible null pointer dereferences.
- ignore hup and tstp in single user mode.
 1.54 17-Apr-2003  fvdl Call MAKEDEV with "init"
 1.53 04-Oct-2002  simonb White space nit.
 1.52 24-Aug-2002  lukem - use _PATH_ALTSHELL (which defaults to _PATH_BSHELL) as the default ALTSHELL
(as opposed to _PATH_BSHELL), to allow the ALTSHELL to be changed.
- print the full path to the default shell in the ALTSHELL prompt.
 1.51 02-Aug-2002  christos fix typos that prevented us from cleaning utmpx. Noted by wiz
 1.50 27-Jul-2002  christos add utmpx/wtmpx processing support.
 1.49 16-Apr-2002  mycroft In single-user, after taking a signal and having the `shell' die with
SIGKILL, go into an infinite loop (like in the runcom SIGTERM case), on the
assumption that reboot(8) is in the middle of taking the system down.
This fixes `panic: init died' from sysinst.
 1.48 03-Feb-2002  lukem crank size of mfs from 512 sectors to 768 sectors (large i386 MAKEDEV)
 1.47 26-Jan-2002  christos KNF: - use %m always instead of sometimes using strerror()
- space problems in casts
- don't cast 0, use NULL
- don't have long lines
- don't cast malloc
- use warn/warnx instead of fprintf
- fix bug where a failed mount_mfs would cause the program to continue.
- pass lint
 1.46 23-Jan-2002  lukem fix compilation problems on my alpha
 1.45 21-Jan-2002  abs Rename MSDOSFS_ROOT to MFS_DEV_IF_NO_CONSOLE, and rework:
- Always attempt mfs dev if missing /dev/console
- Save and run both MAKEDEV and MAKEDEV.local
- After creating the mfs dev, mknod() and freopen() /dev/console.
- If MAKEDEV is missing do not fail out early, but still create the mfs,
/dev/console.
- If we hit any errors fail out to single user.
This change _only_ affects systems booting without /dev/console.
 1.44 16-Jan-2002  abs Increase the size of the dev mfs to at least enough for 1.5.2 i386.
bin/15235 by Gavan Fantom.
 1.43 18-Jun-2001  lukem complete conversion to ANSI C
 1.42 10-Jan-2001  lukem deprecate LOG_ODELAY; it's the default
 1.41 30-Dec-2000  wiz Fix typo in v1.38.
 1.40 30-Dec-2000  wiz sprinkle some const's
 1.39 30-Dec-2000  wiz ANSIfy and de-__P()
 1.38 30-Dec-2000  wiz Handle NULL return value by fgets after shell prompt better. Also
improve '\n' slightly. Addresses bin/11847.
 1.37 19-Mar-2000  soren branches: 1.37.4;
Unbreak compilation with -DLETS_GET_SMALL as in PR bin/9639 by Patrick Welche.
 1.36 21-Jan-2000  mycroft Nuke `extern int errno;' in code we compile with -Wstrict-prototypes. We get
the correct definition from errno.h.
 1.35 09-Nov-1999  drochner Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
 1.34 14-Nov-1998  tls branches: 1.34.2; 1.34.6;
When downgrading from 'highly secure' mode (securelevel >= 2) to 'insecure' mode (securelevel 0) and the root password is set, always require it before giving a shell on the console. Reasoning: if an attacker has access to the machine console, he doesn't necessarily have access to the hardware itself; on a 'highly secure' machine, we may as well make his life hard.
 1.33 18-Sep-1998  thorpej Use sigset_t for signal masks.
 1.32 20-Feb-1998  mycroft Fill in missing (default) mmap(2) flags.
 1.31 06-Feb-1998  perry fix pr4766 from greywolf -- couldn't build without -DALTSHELL
 1.30 01-Nov-1997  drochner Remove the "wait for mfs to be mounted" hack; this is solved in mount_mfs
now.
 1.29 28-Oct-1997  christos PR/4372: Andread Wrede: increase number of inodes in mfs
 1.28 30-Jul-1997  christos branches: 1.28.2;
Support root on msdos filesystems by creating an mfs on /dev and running
MAKEDEV all to create the devices. Idea by Chris Demetriou.
 1.27 19-Jul-1997  perry get rid of "register" declarations.
turn 0 pointers into NULLs
Fix WARN=1 warnings
 1.26 19-Jul-1997  perry 1) change rcsid[] and copyright[] to use __RCSID and __COPYRIGHT
macros.
2) Clean up some gratuitous uses of write() instead of fprintf()
3) Clean up some of the alternative shell code in single_user(),
fixing a couple of bugs in the meanwhile. Also, fix pr-2620 from
Chris Demetriou -- when an alternative shell is exec'ed, it is now
not called "-sh" automatically.
4) rename the DEBUGSHELL option ALTSHELL since its almost always used
in NetBSD.

Notes:
1) It isn't clear that the ALTSHELL code is really ever very useful,
but we seem to have decided to always enable it anyway.
2) The code in init really needs an overall cleanup, but I just don't
have time or energy.
 1.25 19-Jul-1997  perry merge lite-2 changes
 1.24 14-Mar-1997  mycroft Insert some closelog()s, so we don't leave the syslog socket
on fd 0.
 1.23 22-Feb-1997  thorpej If root has no password, don't lock the operator out of single-user
mode if the console is "insecure".
 1.22 15-May-1996  jtc Updated to use <util.h>.
From Greg Hudson <ghudson@MIT.EDU>.
 1.21 05-Oct-1995  mycroft Kill sessions that were deleted when rereading /etc/ttys.
 1.20 28-May-1995  jtc sys_siglist[] -> strsignal()
 1.19 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.18 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.17 06-Aug-1994  deraadt ensure /sbin is in PATH in single user mode
 1.16 11-Jun-1994  mycroft branches: 1.16.2;
Fix up RCS ids.
 1.15 10-Jun-1994  pk Update to 4.4-lite (basically some copyright changes) + local changes.
 1.14 26-Apr-1994  pk Disabling *all* terminals in /etc/ttys meant disabling them for good:
stuck in `clean tty' => `multi user' => `clean tty' loop.
 1.13 18-Apr-1994  cgd if we want a LETS_GET_SMALL init, allow only single-user
 1.12 01-Mar-1994  cgd Establish an initial user so that programs running single user
do not freak out and die (like passwd).
 1.11 01-Aug-1993  mycroft Add RCS identifiers.
 1.10 08-Jul-1993  cgd get rid of the bogus changes i made to init. note that /etc/ttys
*must* have an entry for "console", though it should be "off",
prolly.
 1.9 18-Jun-1993  cgd a couple of local mods; always ask for shell in single user, use -lcrypt,
use root's shell rather that /bin/sh when going to single-user, etc.
 1.8 18-Jun-1993  cgd incorporate bsdi's version of init; this is their version, w/no local changes
other than adding Id strings as appropriate
 1.7 10-Jun-1993  cgd add preliminary support for devfs (e.g. MOUNT_DEVFS #define, etc.)
 1.6 26-Apr-1993  cgd changed to use new libcrypt scheme.
 1.5 06-Apr-1993  cgd added console security, if SECURE_CONSOLE defined in makefile,
and console not secure in ttys
 1.4 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.3 22-Mar-1993  cgd added rcs ids to all files
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 19-Jul-1997  perry imported from 44lite2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.2.1 06-Aug-1994  mycroft update from trunk
 1.28.2.1 02-Nov-1997  mellon Pull rev 1.29 and 1.30 up from trunk (drochner)
 1.34.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.34.2.1 23-Jan-2000  he Pull up revision 1.36 (requested by mycroft):
Always do the errno indirection hack, so that non-threaded
libraries get the right errno value when linked with -lpthread.
This means "always include <errno.h> and never declare errno
yourself".
 1.37.4.1 09-Feb-2002  he Pull up revisions 1.38-1.48 (requested by abs):
Add optional support to try to set up an MFS based /dev file
system if /dev/console is missing. Also fix PR#11847 -- handling
of EOF at altshell prompt, and convert to ANSI C code style.
 1.63.2.1 12-Nov-2004  jmc branches: 1.63.2.1.2;
Pullup rev 1.68 (requested by dan in ticket #914)

Be explicit about the perms of mfs /dev.
 1.63.2.1.2.1 10-May-2005  riz Pull up revision 1.69 (requested by martin in ticket #1331):
Bump the number of inodes to 1024 in the MFS case, needed to
create more devices in the ramdisk images, ok'ed by thorpej@.
 1.81.2.1 16-Feb-2007  riz Pull up following revision(s) (requested by tron in ticket #441):
sbin/init/init.c: revision 1.88
Increase the numbers of inodes available on the "/dev" MFS to 1280.
This should fix the "sysinst" problems caused by adding more devices
node to resolve PR port-amd64/35532.
 1.93.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.93.4.2 23-Mar-2008  matt sync with HEAD
 1.93.4.1 09-Jan-2008  matt sync with HEAD
 1.94.6.4 28-Sep-2008  mjf Sync with HEAD.
 1.94.6.3 04-Apr-2008  mjf * Catch up with selnotify() changes.

* Catch up with some softc changes in HEAD.

* More s/dctl/devfsctl/ changes.

* Remove debugging printfs from init(8) that slipped in by mistake.

* Cosmetic changes in devfsd, allow multiple attributes to be set in
one rule. Switch from err() to syslog() messages.

* Fix etc/devfsd.conf, I'd made some changes previously that had syntax
errors.
 1.94.6.2 03-Apr-2008  mjf Sync with HEAD.
 1.94.6.1 29-Mar-2008  mjf - etc/devfsd.conf: Add some rules to give nodes like /dev/tty and
/dev/null better default modes, i.e. 0666.

- sbin/init: Run devfsd -s before going to multiuser.

- sys/arch: Provide arm32, i386, sparc with a mem_init() function to request
device nodes for /dev/null, /dev/zero, etc.

- sys/dev: Convert rnd, wd, agp, raid, cd, sd, wsdisplay, wskbd, wsmouse,
wsmux, tty, bpf, swap to devfs New World Order.

- sys/fs/devfs: Make the visibility attribute of device nodes configurable.
Also provide a function to mount a devfs on boot.

- sys/kern: Add a new boot flag, -n. This disables devfs support. Unless
the -n flag is specified the kernel will mount a devfs file
system on boot.
 1.94.4.1 24-Mar-2008  keiichi sync with head.
 1.95.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.97.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.102.4.1 23-Nov-2012  riz Pull up following revision(s) (requested by msaitoh in ticket #698):
sbin/init/init.c: revision 1.105
Add missing free() in error path.
 1.102.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.102.2.1 17-Apr-2012  yamt sync with head
 1.103.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 11-Jun-1994  mycroft Fix up RCS ids.
 1.3 10-Jun-1994  pk Update to 4.4-lite (basically some copyright changes) + local changes.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 18-Jun-1993  cgd branches: 1.1.1;
incorporate bsdi's version of init; this is their version, w/no local changes
other than adding Id strings as appropriate
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.5 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.4 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.3 30-May-2015  joerg branches: 1.3.16;
Remove userland side of ISCSI_DEBUG and ISCSI_TEST_MODE.
 1.2 11-Aug-2013  dholland These pass WARNS=5, so don't set WARNS=4
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.8;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3 30-May-2015  joerg Remove userland side of ISCSI_DEBUG and ISCSI_TEST_MODE.
 1.2 30-Oct-2011  christos remove some lint
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.6 25-Jun-2012  mlelstv it's really 32bit
 1.5 25-Jun-2012  mlelstv report luns returns a 32bit list length.
 1.4 20-Jun-2012  martin Fix previous
 1.3 20-Jun-2012  martin Avoid printing values past the end of the buffer, and a size_t underflow.
 1.2 30-Oct-2011  christos branches: 1.2.2; 1.2.4;
remove some lint
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.4.2 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.2.4.1 02-Jul-2012  jdc Pull up revisions:
src/sbin/iscsictl/iscsic_driverif.c revisions 1.3,1.4
(requested by martin in ticket #363).

Avoid printing values past the end of the buffer, and a size_t underflow.

Fix previous
 1.2.2.1 30-Oct-2012  yamt sync with head
 1.6 03-Apr-2020  joerg Just declare driver and buf
 1.5 30-May-2015  joerg branches: 1.5.16;
Remove userland side of ISCSI_DEBUG and ISCSI_TEST_MODE.
 1.4 17-Nov-2011  joerg Use __dead
 1.3 30-Oct-2011  christos branches: 1.3.2;
remove some lint
 1.2 23-Oct-2011  christos add printflike and fix the format error.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.5.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6 30-May-2015  joerg Remove userland side of ISCSI_DEBUG and ISCSI_TEST_MODE.
 1.5 20-Nov-2011  agc give the correct count of arguments to the sub-functions
 1.4 17-Nov-2011  joerg Use __dead
 1.3 30-Oct-2011  christos branches: 1.3.2;
remove some lint
 1.2 23-Oct-2011  christos add printflike and fix the format error.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.3.2.1 17-Apr-2012  yamt sync with head
 1.5 25-Nov-2023  mlelstv Parse IPv6 targets and handle IPv6 addresses.
 1.4 03-Dec-2021  andvar branches: 1.4.2;
fix various typos in comments, log messages and documentation.
 1.3 30-May-2015  joerg Remove userland side of ISCSI_DEBUG and ISCSI_TEST_MODE.
 1.2 30-Oct-2011  christos remove some lint
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.4.2.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #504):

sbin/iscsictl/iscsic_parse.c: revision 1.5
sbin/iscsid/iscsid_driverif.c: revision 1.9

Parse IPv6 targets and handle IPv6 addresses.
 1.2 30-May-2015  joerg Remove userland side of ISCSI_DEBUG and ISCSI_TEST_MODE.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.9 30-Aug-2015  jnemeth update client OS version as well
 1.8 30-Aug-2015  jnemeth PR/49616 - Andreas Gustafsson -- bring modload example into era of MODULAR
 1.7 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.6 20-Jul-2013  wiz Use Mt for email addresses.
 1.5 02-Jun-2012  njoly branches: 1.5.2; 1.5.4;
Fix Bl -tag width arguments.
 1.4 29-May-2012  riz The 'list_sessions' command has a -c flag to display connections
associated with the sessions.
 1.3 27-May-2012  wiz NetBSD -> Nx; new sentence, new line; remove superfluous Pp.
 1.2 26-May-2012  riz Begin the tedious process of documenting iscsictl(8) commands,
options, and flags. I gathered this information by tediously
slogging through the source code, so it's likely to be incomplete
and occasionally flat wrong.

At a minimum, specify which options the various commands take, and
clarify the address specifications. There is still much to do,
but this increases the usefulness of this man page for me, at least.
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.4;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.1.4.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.1.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.5.4.1 23-Jul-2013  riastradh sync with HEAD
 1.5.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.5 11-Aug-2013  dholland These pass WARNS=5, so don't set WARNS=4
 1.4 28-May-2012  riz branches: 1.4.2;
Make the debugging printouts actually work when setting the debug level,
and allow the level to be set numerically from the command line.
 1.3 27-May-2012  christos use -n for nothreads.
 1.2 27-May-2012  christos make the debug level available on the command line.
 1.1 23-Oct-2011  agc branches: 1.1.2; 1.1.4;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.1.4.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.1.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.1 30-Oct-2012  yamt sync with head
 1.4.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14 14-Apr-2022  pgoyette iscsid(8) no longer requires scsibus(4) and sd(4) to be built-in to
the kernel. The scsi_subr module will be loaded if needed to resolve
any dependencies.
 1.13 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.12 10-Nov-2015  tnn fix iSCSI RFC number
 1.11 06-Jul-2014  zafer mention requirements for custom kernels.
 1.10 18-Mar-2014  riastradh branches: 1.10.2;
Merge riastradh-drm2 to HEAD.
 1.9 20-Jul-2013  wiz Use Mt for email addresses.
 1.8 28-May-2012  wiz branches: 1.8.2; 1.8.4;
Sort option descriptions (options without args, then options with args).
 1.7 28-May-2012  wiz Remove trailing whitespace.
 1.6 28-May-2012  riz Fix up the wording of the new flags, and show that the -d flag
now takes an argument.
 1.5 27-May-2012  riz Use Fl for the flags.
 1.4 27-May-2012  christos use -n for nothreads.
 1.3 27-May-2012  christos make the debug level available on the command line.
 1.2 21-Nov-2011  njoly branches: 1.2.2;
Fix title and xrefs.
 1.1 23-Oct-2011  agc branches: 1.1.2;
Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 17-Apr-2012  yamt sync with head
 1.2.2.2 25-Nov-2012  reed Fix simple typo. (3270 is MPLS)
 1.2.2.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.8.4.1 23-Jul-2013  riastradh sync with HEAD
 1.8.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.2.1 10-Aug-2014  tls Rebase.
 1.5 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.4 21-Feb-2015  joerg Move communication socket to /var/run, especially when starting iscsid
during boot, it might disappear otherwise.
 1.3 27-May-2012  christos use -n for nothreads.
 1.2 29-Oct-2011  christos branches: 1.2.2; 1.2.4;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.4.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.2.2.1 30-Oct-2012  yamt sync with head
 1.6 11-Jul-2025  andvar Fix various typos, mainly in comments and log/error messages.
 1.5 29-May-2016  mlelstv branches: 1.5.28;
Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.4 24-Jun-2012  mlelstv use first successful connection to a ISNS server
 1.3 20-Nov-2011  agc branches: 1.3.2;
simplify code by removing a useless "#define STATIC static" in both debug
and normal usage, and all of its uses.
 1.2 29-Oct-2011  christos branches: 1.2.2;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 03-Jul-2012  jdc Pull up revisions:
src/sys/dev/iscsi/iscsi_globals.h revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_main.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_text.c revisions 1.4,1.5
src/sys/dev/iscsi/iscsi_ioctl.c revisions 1.3,1.4
src/sys/dev/iscsi/iscsi_send.c revisions 1.3,1.4,1.5
src/sys/dev/iscsi/iscsi_utils.c revisions 1.2,1.3,1.4
src/sbin/iscsid/iscsid_discover.c revision 1.4
src/sys/dev/iscsi/iscsi_rcv.c revision 1.3
src/sbin/iscsictl/iscsic_driverif.c revisions 1.5,1.6
(requested by martin in ticket #357, with updates from mhitch and mlelstv).

avoid namespace pollution when debugging
don't panic when printing data for a dead (NULL) connection

Close file descriptor passed into the kernel on success.
Fix locking of file handle. More cleanup on error paths.
Keep track of CCBs, so they cannot be used after a session ends.
Handle CCB timeouts even when the connection is terminated.
Compute firstdata, firstimmed correctly.

assemble_login_parameters() has a strange error reporting convention:
errors are positive numbers, so <= 0 is good, not >= ...
This makes CHAP authenticated iscsi logins work.

use first successful connection to a ISNS server

Add more debugging, fix filehandle usage, login negotiation and session
shutdown.
Add #ifdef'd code to send negotiation parameters in hex instead of base64,
so it works against older Linux targets.

report luns returns a 32bit list length.

Make digests work also on big endian machines.

it's really 32bit
 1.5.28.1 02-Aug-2025  perseant Sync with HEAD
 1.11 13-Jul-2024  mlelstv Abort operation when a target address cannot be resolved.
 1.10 27-Dec-2023  mlelstv branches: 1.10.2;
Treat port 0 (unset) as ISCSI_DEFAULT_PORT like before.
 1.9 25-Nov-2023  mlelstv Parse IPv6 targets and handle IPv6 addresses.
 1.8 29-May-2016  mlelstv branches: 1.8.26;
Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.7 30-May-2015  joerg Remove ISCSI_DEBUG branches.
 1.6 29-Dec-2012  mlelstv Handle invalid messages more gracefully, handle sessions with no valid
connections, and be more verbose about errors.
 1.5 27-May-2012  christos branches: 1.5.2;
use -n for nothreads.
 1.4 27-May-2012  riz Don't try to print pointers as integers, use %p instead and don't cast.
 1.3 20-Nov-2011  agc branches: 1.3.2;
simplify code by removing a useless "#define STATIC static" in both debug
and normal usage, and all of its uses.
 1.2 29-Oct-2011  christos branches: 1.2.2;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.2.3 23-Jan-2013  yamt sync with head
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.5.2.1 25-Feb-2013  tls resync with head
 1.8.26.2 30-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #523):

sbin/iscsid/iscsid_driverif.c: revision 1.10

Treat port 0 (unset) as ISCSI_DEFAULT_PORT like before.
 1.8.26.1 18-Dec-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #504):

sbin/iscsictl/iscsic_parse.c: revision 1.5
sbin/iscsid/iscsid_driverif.c: revision 1.9

Parse IPv6 targets and handle IPv6 addresses.
 1.10.2.1 02-Aug-2025  perseant Sync with HEAD
 1.10 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.9 30-May-2016  joerg branches: 1.9.16;
Add printf-like annotation.
 1.8 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.7 28-May-2012  riz Make the debugging printouts actually work when setting the debug level,
and allow the level to be set numerically from the command line.
 1.6 27-May-2012  riz Implement the remaining bits of unthreaded operation.
 1.5 27-May-2012  riz When ISCSI_NOTHREAD is defined, make UNLOCK_SESSIONS a different kind
of noop, so that things build.
 1.4 20-Nov-2011  agc branches: 1.4.2;
simplify code by removing a useless "#define STATIC static" in both debug
and normal usage, and all of its uses.
 1.3 17-Nov-2011  joerg Use __dead
 1.2 29-Oct-2011  christos branches: 1.2.2;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.4.2.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.9.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10 31-May-2022  andvar fix various typos in comments, documentation and messages.
 1.9 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.8 29-Dec-2012  mlelstv Handle invalid messages more gracefully, handle sessions with no valid
connections, and be more verbose about errors.
 1.7 28-May-2012  riz branches: 1.7.2;
Fix 4 more instances of the same bug (not returning NULL when stuff
not found). While I'm here, add comments so it hopefully doesn't happen
again.
 1.6 27-May-2012  riz Fix a bug introduced in rev 1.2: return "curr", like the debugging
says we're doing, because it, unlike "t", will propely be NULL when
the target name isn't found in the list. Now we can have multiple
targets again!
 1.5 27-May-2012  christos use -n for nothreads.
 1.4 27-May-2012  riz Don't try to print pointers as integers, use %p instead and don't cast.
 1.3 20-Nov-2011  agc branches: 1.3.2;
simplify code by removing a useless "#define STATIC static" in both debug
and normal usage, and all of its uses.
 1.2 29-Oct-2011  christos branches: 1.2.2;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.2.3 23-Jan-2013  yamt sync with head
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.7.2.1 25-Feb-2013  tls resync with head
 1.12 04-Feb-2019  mrg check for snprintf() truncation and fail sanely if so, rather than
attempting to use a file that won't exist or isn't secure.
 1.11 30-May-2016  mlelstv branches: 1.11.16;
mark noreturn function exit_daemon() as __dead
 1.10 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.9 30-May-2015  joerg Remove ISCSI_DEBUG branches.
 1.8 29-Dec-2012  mlelstv Handle invalid messages more gracefully, handle sessions with no valid
connections, and be more verbose about errors.
 1.7 28-May-2012  riz branches: 1.7.2;
Make the debugging printouts actually work when setting the debug level,
and allow the level to be set numerically from the command line.
 1.6 27-May-2012  riz Implement the remaining bits of unthreaded operation.
 1.5 27-May-2012  christos use -n for nothreads.
 1.4 27-May-2012  christos make the debug level available on the command line.
 1.3 20-Nov-2011  agc branches: 1.3.2;
simplify code by removing a useless "#define STATIC static" in both debug
and normal usage, and all of its uses.
 1.2 29-Oct-2011  christos branches: 1.2.2;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.2.3 23-Jan-2013  yamt sync with head
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.7.2.1 25-Feb-2013  tls resync with head
 1.11.16.1 10-Jun-2019  christos Sync with HEAD
 1.7 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.6 29-May-2016  mlelstv Several improvents to iscsid

- debug log is now using syslog
- seperate options for log level and foreground mode
- writes a pidfile so that /etc/rc.d/iscsid works
Now links with libutil for pidfile(), the functions login() and logout()
needed to be renamed to avoid a conflict.
- drops the nothreads option
- handles signals to shut down gracefully
- the driver may also shut down the daemon when it terminates
Currently this cannot work as the driver can only terminate when
the daemon has closed the driver file handle.
 1.5 29-Dec-2012  mlelstv Handle invalid messages more gracefully, handle sessions with no valid
connections, and be more verbose about errors.
 1.4 27-May-2012  riz branches: 1.4.2;
Don't try to print pointers as integers, use %p instead and don't cast.
 1.3 20-Nov-2011  agc branches: 1.3.2;
simplify code by removing a useless "#define STATIC static" in both debug
and normal usage, and all of its uses.
 1.2 29-Oct-2011  christos branches: 1.2.2;
cleanup some messy casts and type violations.
XXX: There is one piece of code I marked that does not make sense.
Someone should take a look at it.
 1.1 23-Oct-2011  agc Start to move the in-kernel iSCSI initiator, kindly contributed to the
NetBSD Foundation by Wasabi Systems, from

othersrc/external/bsd/iscsi/{iscsictl,iscsid}

to

src/sbin/{iscsictl,iscsid}
 1.2.2.3 23-Jan-2013  yamt sync with head
 1.2.2.2 30-Oct-2012  yamt sync with head
 1.2.2.1 17-Apr-2012  yamt sync with head
 1.3.2.1 30-May-2012  sborrill Pull up the following revisions(s) (requested by riz in ticket #291):
etc/MAKEDEV.tmpl: revision 1.155
sbin/iscsictl/iscsictl.8: revision 1.2-1.4
sbin/iscsid/iscsid_driverif.c: revision 1.4-1.5
sbin/iscsid/iscsid_lists.c: revision 1.4-1.7
sbin/iscsid/iscsid_targets.c: revision 1.4
sbin/iscsid/iscsid_globals.h: revision 1.5-1.7
sbin/iscsid/iscsid_main.c: revision 1.4-1.7
sbin/iscsid/Makefile: revision 1.2-1.4
sbin/iscsid/iscsid.8: revision 1.3-1.8
sbin/iscsid/iscsid.h: revision 1.3
sys/dev/iscsi/iscsi_main.c: revision 1.2-1.3

Fix bugs in iscsid target list handling, and improve documentation
somewhat for the in-kernel iSCSI initiator.
 1.4.2.1 25-Feb-2013  tls resync with head
 1.28 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.27 18-Jul-2013  matt Use MACHINE_CPU with m68k (m68000 will not be matched due to MKPIC=no)
 1.26 05-Feb-2013  matt branches: 1.26.2;
There are other little endian arm machine_arches other than "arm"
 1.25 23-Aug-2012  joerg branches: 1.25.2;
Revert last, it breaks the tricks xsrc uses.
 1.24 23-Aug-2012  joerg Remove SHLIBINSTALLDIR and SHLINKINSTALLLIBDIR. Add rpath entries, if
SHLIBDIR differs from /usr/lib.
 1.23 06-Jul-2010  mrg branches: 1.23.6;
remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h
 1.22 31-Oct-2008  mrg make MKPIC=no builds work on i368, shark, vax, pmax, sgimips, sparc,
maybe all mips and all arm as well.
 1.21 12-Nov-2002  itohy branches: 1.21.32; 1.21.40;
MKDYNAMICROOT for a.out
 1.20 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.19 24-Feb-2002  matt Also build ldconfig is MACHINE_ARCH is arm or vax buf OBJECT_FMT=ELF
 1.18 21-Mar-2001  tsutsui Make and install ldconfig on ELF m68k ports.
 1.17 29-Sep-2000  fvdl Modification to previous: only build for ports that are a.out or used
to be a.out. No sense in building for ports that never were a.out.
 1.16 29-Sep-2000  fvdl Build this on ELF as well. When on an ELF system, only look in
_PATH_EMUL_AOUT/etc/ld.so.conf.
 1.15 17-Dec-1998  thorpej branches: 1.15.10;
Only build ldconfig on a.out platforms. Everyone else still builds the
manual page.
 1.14 15-Dec-1998  pk Adapt to new location in `src/sbin'.
 1.13 02-Mar-1998  cgd allow LDSTATIC definition to be overridden by bsd.own.mk/mk.conf
 1.12 23-Jun-1997  mrg install all man pages.
 1.11 16-Apr-1997  christos Ld directory reorganization:
- separate out the common files used by rtld ldd ld
- move machine dependent files into arch
- move ld in its own directory
- factor out .PATH and CFLAGS common to all Makefiles
 1.10 06-Mar-1995  cgd complete remove special search dirs, use NetBSD Id tag.
 1.9 22-Dec-1994  cgd specify man pages the new way.
 1.8 10-Jun-1994  pk Conversion to err()/warn() for error reports.
 1.7 10-Dec-1993  mycroft Minor cleanup.
 1.6 08-Dec-1993  mycroft Use MACHINE_ARCH.
 1.5 08-Dec-1993  pk *** empty log message ***
 1.4 05-Dec-1993  cgd MACHINE_ARCH support
 1.3 02-Dec-1993  mycroft Remove ${DESTDIR} from BINDIR.
 1.2 03-Nov-1993  cgd add -static to 'LDFLAGS', as it goes in /sbin
 1.1 23-Oct-1993  pk Utility to maintain shared library lookup "hints".
Does business in `/var/run/ld.so.hints'.
 1.15.10.1 18-Oct-2000  tv Pullup 1.16 and 1.17 [fvdl]:
Modification to previous: only build for ports that are a.out or used
to be a.out. No sense in building for ports that never were a.out.
 1.21.40.1 06-Nov-2008  snj branches: 1.21.40.1.4;
Pull up following revision(s) (requested by mrg in ticket #20):
compat/libexec/ld.elf_so/Makefile: revision 1.2
distrib/sets/lists/base/md.shark: revision 1.7
distrib/sets/lists/base/md.vax: revision 1.26
distrib/sets/lists/base/md.i386: revision 1.130
distrib/sets/lists/base/ad.arm: revision 1.10
distrib/sets/lists/comp/md.shark: revision 1.13
distrib/sets/lists/comp/md.sparc: revision 1.68
distrib/sets/lists/comp/ad.arm: revision 1.31
distrib/sets/lists/comp/md.vax: revision 1.35
distrib/sets/lists/comp/md.i386: revision 1.108
distrib/sets/lists/base/md.sparc: revision 1.75
distrib/sets/lists/comp/md.pmax: revision 1.59
libexec/ld.aout_so/Makefile: revision 1.46
sbin/ldconfig/Makefile: revision 1.22
make MKPIC=no builds work on i368, shark, vax, pmax, sgimips, sparc,
maybe all mips and all arm as well.
 1.21.40.1.4.1 24-Mar-2014  matt Make these work with a machine_arch of armv7
 1.21.32.1 17-Jan-2009  mjf Sync with HEAD.
 1.23.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.25.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.2.1 25-Feb-2013  tls resync with head
 1.26.2.1 23-Jul-2013  riastradh sync with HEAD
 1.15 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.14 01-Oct-2002  wiz branches: 1.14.32; 1.14.34;
New sentence, new line. By Robert Elz with minimal fixes.
 1.13 16-Nov-2001  wiz Sort sections, use standard headers, slight markup improvement.
 1.12 08-Oct-2000  bjh21 Miscellaneous -mdoc cleanups.
 1.11 08-Oct-2000  bjh21 Mention that ldconfig is a.out only.
Should fix PR bin/10299.
 1.10 22-Feb-1999  msaitoh branches: 1.10.10;
Add note about LD_PRELOAD
 1.9 05-Sep-1998  pk Assign my copyrights to TNF.
 1.8 05-Jan-1998  cgd RCS Id police
 1.7 27-Aug-1997  thorpej Document new flags and internal processing of ld.so.conf changes.
 1.6 05-Jan-1997  mrg xref ld.so.conf.5
 1.5 03-Jul-1996  thorpej RCS id police.
 1.4 20-Jun-1995  pk Add a `merge' option.
Use err() & warn().
 1.3 24-Jun-1994  pk copyright notice.
 1.2 16-Jun-1994  pk Update man page.
Use `__progname'.
 1.1 23-Oct-1993  pk Utility to maintain shared library lookup "hints".
Does business in `/var/run/ld.so.hints'.
 1.10.10.1 13-Nov-2000  tv Pullup 1.11 [releng]:
Mention that ldconfig is a.out only.
Should fix PR bin/10299.
 1.14.34.1 18-May-2008  yamt sync with head.
 1.14.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.48 04-Jan-2011  wiz Fix file descriptor leak. Found by cppcheck.
 1.47 13-May-2010  tnozaki cast isblank(3)'s argument to unsigned char.
 1.46 16-Aug-2009  martin Add <sys/exec_aout.h> includes
 1.45 17-Mar-2009  lukem fix sign-compare issues
 1.44 28-Apr-2008  martin branches: 1.44.6;
Remove clause 3 and 4 from TNF licenses
 1.43 26-Mar-2006  christos branches: 1.43.20; 1.43.22;
Coverity CID 2766: Don't leak memory.
 1.42 21-Mar-2006  christos Coverity CID 1601: Fix memory leak.
 1.41 21-Mar-2006  christos Coverity CID 1603: Fix memory leak.
 1.40 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.39 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.38 28-Oct-2004  dsl Add (unsigned char) cast to isdigit call
 1.37 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.36 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.35 05-Jan-2003  kristerw Correct length of a memcpy.
From Alan Barrett in PR 18620.
 1.34 01-Nov-2001  lukem fix a couple of -Wshadow warnings
 1.33 19-Feb-2001  cgd convert to use getprogname()
 1.32 10-Nov-2000  enami Cosmetic change; actually split a line which looks like as if two lines.
 1.31 29-Sep-2000  fvdl Build this on ELF as well. When on an ELF system, only look in
_PATH_EMUL_AOUT/etc/ld.so.conf.
 1.30 01-Jun-2000  matt branches: 1.30.2;
make ldconfig.c not always fail.
 1.29 27-May-2000  matt Add some code to test libraries to make sure they are a.out before adding
them to hints.
 1.28 27-May-2000  matt branches: 1.28.2;
Changes to put the COMPAT_AOUT code into ld.aout_so. Search <dir> for <lib>
then search /emul/aout/<dir> for <lib>. To make sure we don't get false
postives on ELF libraries we make the .so is a ZMAGIC dynamic library.
 1.27 16-Jul-1999  christos - don't core-dump if hints file is too short
- unmap the space and close fd's
- bcopy -> memcpy
- stat the file to get the size to map, instead of doing multiple mmaps.
 1.26 17-Jun-1999  thorpej MAP_COPY -> MAP_PRIVATE
 1.25 09-Apr-1999  agc Plug a file descriptor leak.
 1.24 08-Apr-1999  drochner !silent -> verbose, to make it compile again (there is no "silent")
 1.23 08-Apr-1999  agc If there is no /etc/ld.so.conf, it is not a fatal error. Correct the return
value from the function so that the exit value to the shell is correct.
 1.22 15-Dec-1998  pk branches: 1.22.2;
Adapt to new location in `src/sbin'.
 1.21 15-Dec-1998  pk Pull in proper headers; deal with compiler warnings; miscelleneous KNF.
 1.20 05-Sep-1998  pk Assign my copyrights to TNF.
 1.19 20-Feb-1998  mycroft Fill in missing (default) mmap(2) flags.
 1.18 26-Aug-1997  thorpej Enhancements from Jim Bernard <jbernard@tater.mines.edu>, to support
processing of /etc/ld.so.conf in ld.so itself (rather than in /etc/rc):
- added do_conf function and call to it in main to implement internal
processing of /etc/ld.so.conf
- moved maintenance of dir_list to dodir, with an added argument to
dodir to specify whether dir_list should be updated
- added option '-c' to suppress processing of /etc/ld.so.conf
- added option '-S' to suppress processing of std directories (but not
/etc/ld.so.conf)
- modified option -s to suppress processing of _both_ std directories
and /etc/ld.so.conf (i.e., it is equivalent to -cS)--this was done
so that users and scripts that interpret -s as meaning "process
only directories specified on the command line" would not be
startled

From PR #4031. One change was not committed, since it was unnecessary
(option variables are in the BSS, and do not need to be initialized to
0 explicitly).

Plus one change from me:
- getopt() returns -1 when completed, not EOF.
 1.17 16-Apr-1997  christos mktemp() -> mkstemp()
 1.16 03-Jan-1997  mikel eliminate valueless return from main(); PR bin/3073.
 1.15 03-Jul-1996  thorpej RCS id police.
 1.14 30-Jun-1996  jtc Add '-m' to usage string; Fixes PR #2580
 1.13 09-Jan-1996  pk Create v.2 hint files.
Note: don't bother to understand v.1 files..
 1.12 25-Aug-1995  pk branches: 1.12.2;
Just use umask(0);
Use mktemp() for temporary file creation.
 1.11 25-Aug-1995  pk Ensure the hints file is readable.
 1.10 05-Aug-1995  pk Parse library names better; takes care of PR#1291
 1.9 20-Jun-1995  pk Add a `merge' option.
Use err() & warn().
 1.8 16-Jun-1994  pk Update man page.
Use `__progname'.
 1.7 10-Jun-1994  pk Conversion to err()/warn() for error reports.
 1.6 28-Mar-1994  cgd no more MAP_FILE
 1.5 29-Jan-1994  jtc Fix spelling error in Copyright notice
 1.4 28-Jan-1994  pk Remove reference to `mywrite()'.
 1.3 13-Jan-1994  pk Don't barf if builtin directories happen to be non-existent.
 1.2 08-Dec-1993  pk *** empty log message ***
 1.1 23-Oct-1993  pk Utility to maintain shared library lookup "hints".
Does business in `/var/run/ld.so.hints'.
 1.12.2.1 16-Feb-1996  pk Pick up fixes from -current for patch2.
 1.22.2.3 27-Jun-2000  he Pull up revision 1.30 (requested by matt):
Do not treat non-existance of directories under /emul/aout as
errors.
 1.22.2.2 01-Jun-2000  he Pull up revisions 1.28-1.29 (requested by matt):
Enable searching for libraries under /emul/aout, and make sure
that ELF libraries are not erroneously accepted.
 1.22.2.1 20-Oct-1999  he Pull up revisions 1.23-1.25 (requested by agc):
Do not handle a missing /etc/ld.so.conf as a fatal error,
and plug a file descriptor leak.
 1.28.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.30.2.1 18-Oct-2000  tv Pullup 1.31 [fvdl]:
Build this on ELF as well. When on an ELF system, only look in
_PATH_EMUL_AOUT/etc/ld.so.conf.
 1.43.22.1 18-May-2008  yamt sync with head.
 1.43.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.44.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.2 21-Mar-2012  he Convert from K&R to c89 function definitions.
 1.1 06-Jul-2010  mrg branches: 1.1.6;
remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h
 1.1.6.1 17-Apr-2012  yamt sync with head
 1.1 06-Jul-2010  mrg remove almost all the ability to build netbsd with an a.out target.
we're ELF now, and there are many missing checks against OBJECT_FMT.
if we ever consider switching, the we can figure out what new ones
we need but for now it's just clutter.

this doesn't remove any of the support for exec_aout or any actually
required-for-boot a.out support, only the ability to build a netbsd
release in a.out format. ie, most of this code has been dead for
over a decade.

i've tested builds on vax, amd64, i386, mac68k, macppc, sparc, atari,
amiga, shark, cats, dreamcast, landisk, mmeye and x68k. this covers
the 5 MACHINE_ARCH's affected, and all the other arch code touched.
it also includes some actual run-time testing of sparc, i386 and
shark, and i performed binary comparison upon amiga and x68k as well.


some minor details relevant:
- move shlib.[ch] from ld.aout_so into ldconfig proper, and cut them
down to only the parts ldconfig needs
- remove various unused source files
- switch amiga bootblocks to using elf2bb.h instead of aout2bb.h
 1.1 16-Oct-2013  mbalmer branches: 1.1.4; 1.1.8;
luactl(8) is a command to control lua(4)
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 16-Oct-2013  tls file Makefile was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.1.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.1 16-Oct-2013  yamt file Makefile was added on branch yamt-pagecache on 2014-05-22 11:37:29 +0000
 1.7 10-Apr-2017  sevan Direct reader to intro(9lua), lua(9) does not exist.
 1.6 11-Sep-2016  sevan branches: 1.6.2;
Revert previous change, textproc/igor is not around from these parts here.
Heads up by maya@
 1.5 11-Sep-2016  sevan no comma after "i.e.", raised by textproc/igor
 1.4 17-Oct-2013  wiz branches: 1.4.4; 1.4.6; 1.4.8; 1.4.12;
Still more markup. Sort.
 1.3 17-Oct-2013  mbalmer there is no assign command
 1.2 17-Oct-2013  wiz More markup, typo fixes, update date and NetBSD version for import.
 1.1 16-Oct-2013  mbalmer luactl(8) is a command to control lua(4)
 1.4.12.1 26-Apr-2017  pgoyette Sync with HEAD
 1.4.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 17-Oct-2013  tls file luactl.8 was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.4.6.1 12-May-2017  snj Pull up following revision(s) (requested by sevan in ticket #1401):
sbin/luactl/luactl.8: revision 1.7
Direct reader to intro(9lua), lua(9) does not exist.
 1.4.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.4.1 17-Oct-2013  yamt file luactl.8 was added on branch yamt-pagecache on 2014-05-22 11:37:29 +0000
 1.6.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.2 29-Oct-2013  joerg branches: 1.2.4; 1.2.8;
Mark usage as dead.
 1.1 16-Oct-2013  mbalmer luactl(8) is a command to control lua(4)
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 29-Oct-2013  tls file luactl.c was added on branch tls-maxphys on 2014-08-20 00:02:25 +0000
 1.2.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.4.1 29-Oct-2013  yamt file luactl.c was added on branch yamt-pagecache on 2014-05-22 11:37:29 +0000
 1.5 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.4 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.3 24-Dec-2000  lukem i got sick of the brain damage that mbrlabel used to do, and had
gotten bitten by mbrlabel trashing my incore disklabel to a point where
the machine wasn't usable, so I reworked it:

* only update the incore (and on-disk) label if `-f' is given. by default,
the proposed disklabel will be printed but no changes will occur
* add -q, to make the default operation a bit more quiet.
* leave existing `used' in-core partition slots alone, and only add entries
to the incore label if:
- there's not an existing partition of the same size and offset
(even of a different type)
- there's a free partition slot (`unused', with size == 0)
* use DIOCWDINFO instead of DIOCSDINFO, to update the incore as well as
the on-disk label
* use showpartitions() from ../disklabel/printlabel.c

this should make mbrlabel a *lot* more useful.
 1.2 15-Mar-2000  fvdl branches: 1.2.4;
Moved from Makefile,v
 1.1 16-Nov-1998  ws Add a utility to allow access to the partitions of a
MBR labeled disk (i.e. a disk partitioned by fdisk)
on any platform (including extended partitions).
 1.2.4.1 26-Feb-2001  he Pull up revision 1.3 (requested by lukem):
Several fixes and enhancements:
o only update in-core (and on-disk) disklabels if requested
o be saner about adding MBR partitions to free disklabel slots
o NTFS recognition
o various cleanups
 1.20 27-Feb-2013  wiz Remove trailing whitespace.
 1.19 27-Feb-2013  is Fix terminology issue brought up by Bug Hunting in PR 47314.
The boot records in extended partitions are called "Extended Boot Record"
(EBR); use that in the documentation where appropriate.
 1.18 14-Jul-2012  wiz branches: 1.18.2;
From Bug Hunting:
- use more common option list header line;
- remove superfluous `.Pp' macro (fixes mandoc(1) warning);
- bump date.
 1.17 05-Apr-2010  wiz branches: 1.17.6;
Sort option descriptions, per PR 43119 by Bug Hunting.
Refer to -r from -w.
Bump date.
 1.16 12-Jan-2006  wiz Grammar fix.
 1.15 27-Dec-2005  jmmv Add an option (-s) to specify which sector to read to parse the partition
table. Useful if the disk has remapping drivers installed into it (such as
Ontrack Disk Manager).

Added as an option instead of automatic behavior to let the user scan any
of the two partition tables at will.
 1.14 13-Jul-2003  lukem xref dkctl(8)
 1.13 24-Jan-2002  fair make the description of -w and -r more clear, per PR 13503.
 1.12 13-Jan-2002  fair Cross-link fdisk(8), mbr(8), and mbrlabel(8) in the SEE ALSO sections,
as suggested in PR 14288. Also add a little white space to mbr(8) to
make it a little more readable.
 1.11 30-Dec-2001  mrg fix a typo
 1.10 16-Nov-2001  wiz Drop unnecessary .Pp.
 1.9 01-May-2001  lukem clarify that -w updates the in-core label if changed, and if -r is
given as well, the on-disk label will then be updated.
 1.8 27-Dec-2000  lukem change behaviour of flags slightly:
-w write in-core label if changed
-r update on-disk as well as in-core label (with -w)
-f force update (-w), even if there's been no change

-r behaviour suggested by matt green. what used to be `-f' is now `-wrf'
 1.7 24-Dec-2000  lukem more rewording
- mbrlabel updates the disklabel; it doesn't generate it
- it doesn't just affect the incore label, so remove the `incore' qualifier
 1.6 24-Dec-2000  lukem i got sick of the brain damage that mbrlabel used to do, and had
gotten bitten by mbrlabel trashing my incore disklabel to a point where
the machine wasn't usable, so I reworked it:

* only update the incore (and on-disk) label if `-f' is given. by default,
the proposed disklabel will be printed but no changes will occur
* add -q, to make the default operation a bit more quiet.
* leave existing `used' in-core partition slots alone, and only add entries
to the incore label if:
- there's not an existing partition of the same size and offset
(even of a different type)
- there's a free partition slot (`unused', with size == 0)
* use DIOCWDINFO instead of DIOCSDINFO, to update the incore as well as
the on-disk label
* use showpartitions() from ../disklabel/printlabel.c

this should make mbrlabel a *lot* more useful.
 1.5 14-Nov-2000  abs xref (disklabel.8, fdisk.8, mbrlabel.8) as appropriate
 1.4 15-Mar-2000  fvdl branches: 1.4.4;
Moved from mbrlabel.8,v
 1.3 22-Mar-1999  garbled More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages. Many more to
come.
 1.2 17-Nov-1998  ws Shorten name line to fit.
Thanks to Hubert Feyrer (feyrer@rfhs8012.fh-regensburg.de) for pointing this out
 1.1 16-Nov-1998  ws Add a utility to allow access to the partitions of a
MBR labeled disk (i.e. a disk partitioned by fdisk)
on any platform (including extended partitions).
 1.4.4.1 26-Feb-2001  he Pull up revisions 1.5-1.8 (requested by lukem):
Several fixes and enhancements:
o only update in-core (and on-disk) disklabels if requested
o be saner about adding MBR partitions to free disklabel slots
o NTFS recognition
o various cleanups
 1.17.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.6.1 30-Oct-2012  yamt sync with head
 1.18.2.1 23-Jun-2013  tls resync from head
 1.29 30-Mar-2018  mlelstv Handle sector sizes != 512, check partition overlaps, improve guessing
of filesystem parameters.
 1.28 14-Jul-2012  wiz branches: 1.28.30;
From Bug Hunting:
Sync usage with man page.
 1.27 27-Aug-2011  joerg branches: 1.27.2;
Be more static.
 1.26 28-Dec-2005  christos fix compilation on LP64 machines.
 1.25 27-Dec-2005  jmmv Add an option (-s) to specify which sector to read to parse the partition
table. Useful if the disk has remapping drivers installed into it (such as
Ontrack Disk Manager).

Added as an option instead of automatic behavior to let the user scan any
of the two partition tables at will.
 1.24 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.23 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.22 07-Jun-2003  dsl Make writes to the in-core label persist after mbrlabel closes the disk.
 1.21 28-Sep-2002  dbj add MBR_PTYPE_APPLEUFS of 0xa8
part of PR #17345
 1.20 21-May-2002  yamt open device as readonly unless -w is specified.
 1.19 07-Feb-2002  ross minor LP64 nits
 1.18 20-Aug-2001  ad Use getrawpartition().
 1.17 26-Jul-2001  wiz partiton -> partition
 1.16 20-Feb-2001  cgd use getprogname()
 1.15 18-Feb-2001  lukem - remove unused arg to getparts()
- clean up WARNS=2 problems
- implement getshort()
- use getshort() with MBR_MAGICOFF to test if the magic number is OK, rather
than using hard-coded magic numbers
 1.14 04-Feb-2001  christos ifix nested extern.
 1.13 04-Jan-2001  lukem change verbose probe message to display "size xxx (yyy MB), offset zzz".
use %u instead of %d.
 1.12 27-Dec-2000  lukem change behaviour of flags slightly:
-w write in-core label if changed
-r update on-disk as well as in-core label (with -w)
-f force update (-w), even if there's been no change

-r behaviour suggested by matt green. what used to be `-f' is now `-wrf'
 1.11 24-Dec-2000  lukem i got sick of the brain damage that mbrlabel used to do, and had
gotten bitten by mbrlabel trashing my incore disklabel to a point where
the machine wasn't usable, so I reworked it:

* only update the incore (and on-disk) label if `-f' is given. by default,
the proposed disklabel will be printed but no changes will occur
* add -q, to make the default operation a bit more quiet.
* leave existing `used' in-core partition slots alone, and only add entries
to the incore label if:
- there's not an existing partition of the same size and offset
(even of a different type)
- there's a free partition slot (`unused', with size == 0)
* use DIOCWDINFO instead of DIOCSDINFO, to update the incore as well as
the on-disk label
* use showpartitions() from ../disklabel/printlabel.c

this should make mbrlabel a *lot* more useful.
 1.10 24-Dec-2000  wiz Add NTFS recognition per patch supplied by Dave Huang in bin/11804.
 1.9 24-Dec-2000  wiz ANSIfy, de-__P()
 1.8 03-Jul-2000  matt More include fixups and GCC 2.96 nonsense
 1.7 15-Mar-2000  fvdl branches: 1.7.4;
Moved from mbrlabel.c,v
 1.6 23-Sep-1999  ws Correct handling of extended partitions within extended partitions.
Problem found and new program tested by Reinoud.Koornstra@ibbnet.nl.
While here, add support for Linux extended partitions.
 1.5 19-Aug-1999  cgd copy the MBR partition table being examined to a local array, to avoid
unaligned structure accesses on architectures that care.
 1.4 19-Aug-1999  cgd correct usage message
 1.3 27-Jan-1999  thorpej branches: 1.3.2;
Use <sys/disklabel_mbr.h> rather than our own home-grown.
 1.2 03-Dec-1998  fair This seemingly trivial (and computationally pointless) change shuts up
GCC 2.7.2.2 about "loff" being uninitialized on line 142 on m68k.
 1.1 16-Nov-1998  ws Add a utility to allow access to the partitions of a
MBR labeled disk (i.e. a disk partitioned by fdisk)
on any platform (including extended partitions).
 1.3.2.2 26-Sep-1999  cgd pull up rev 1.6 from trunk (requested by ws):
Correct handling of extended partitions within extended partitions, and
add support for Linux extended partitions.
 1.3.2.1 20-Aug-1999  cgd pull up revs 1.4-1.5 from trunk (cgd)
 1.7.4.1 26-Feb-2001  he Pull up revisions 1.8-15 (requested by lukem):
Several fixes and enhancements:
o only update in-core (and on-disk) disklabels if requested
o be saner about adding MBR partitions to free disklabel slots
o NTFS recognition
o various cleanups
 1.27.2.1 30-Oct-2012  yamt sync with head
 1.28.30.1 07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.13 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.12 13-Feb-2009  lukem WARNS=4
 1.11 27-Jun-2005  christos branches: 1.11.30;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.10 09-Feb-2005  xtraeme WARNS=3.
 1.9 08-Oct-2001  lukem cleanups suggested by simonb:
- rename "format.c" -> "pack_dev.c", "mknod.h" -> "pack_dev.h"
- make the private stuff in pack_dev.c static
 1.8 08-Oct-2001  lukem - move parsing of format type and format handlers into format.c, for easier
use in other programs
- do a bit of KNF whilst here
- enable WARNS=2
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.2 08-Oct-2001  lukem cleanups suggested by simonb:
- rename "format.c" -> "pack_dev.c", "mknod.h" -> "pack_dev.h"
- make the private stuff in pack_dev.c static
 1.1 08-Oct-2001  lukem - move parsing of format type and format handlers into format.c, for easier
use in other programs
- do a bit of KNF whilst here
- enable WARNS=2
 1.30 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.29 11-Sep-2016  sevan mknod appeared in V4
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V4/man/man8/mknod.8
Bump date.
 1.28 17-Jun-2004  dsl Document 'mknod -l' (list drivers in kernel), and use of driver name
instead of major number.
(all done using sysctl kern.drivers)
 1.27 29-Dec-2003  atatat Fix spelo
 1.26 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.25 09-May-2003  wiz Use .Nm instead of .Xr mknod, and sort options in HISTORY (incl. mdoc and grammar nit fixes).
 1.24 08-May-2003  lukem 2.0, not 1.7
 1.23 08-May-2003  dsl Add -g gid -m mode -u uid so that MAKEDEV can run when chown/chmod are
not available.
Add -r and -R to do two (different) sensible things if node exists.
From a discussion with Lukem.
 1.22 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.21 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.20 08-Oct-2001  mycroft Fix a formatting error.
 1.19 05-Jun-2001  wiz Drop arguments of .Os.
 1.18 17-May-2000  fair To resolve PR 9451, wording and formatting adjusted to be more clear about
the -F option for making device nodes for other versions of UNIX.
 1.17 22-Mar-2000  simonb Arch-specific directories now live under .../sys/arch, not directly
under .../sys.
 1.16 24-Nov-1998  christos branches: 1.16.2;
- document 'p' file type.
- fix stale documentation about the location of the major/minor device
tables in the kernel.
 1.15 11-Sep-1998  mycroft Add isc, sco, and bsdos 3-field format.
 1.14 17-Jan-1998  mycroft Add a `bsdos' format.
 1.13 17-Jan-1998  mycroft Add a -F option to specify the device number format.
Also accept a single opaque device number.
 1.12 11-Oct-1997  enami Sort SEE ALSO list; first by section number, then alphabetical order.
 1.11 15-Sep-1997  lukem * cleanup for WARNS+1
* use .Nm correctly
 1.10 30-Jun-1997  phil Added mkfifo(1) and mkfifo(2) to the SEE ALSO list. (PR 1307)
 1.9 10-Aug-1995  jtc makedev(8) -> MAKEDEV(8); PR #1306
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.6 14-Jan-1994  jtc Fix spelling errors
 1.5 30-Nov-1993  jtc Use ".At v6" macro instead of spelling out "Version 6 AT&T UNIX".
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.2.2 22-May-2000  he Pull up revision 1.18 (requested by fair):
Document -F flag. Fixes PR#9451.
 1.16.2.1 29-Mar-2000  he Pull up revision 1.17 (requested by simonb):
In the example conf.c path, arch-specific directories now
live under sys/arch, not directly under sys.
 1.42 22-Aug-2014  mlelstv Accept driver names only in the two args form together with a minor number.

That's what the documentation says and also avoids the case where the driver
name converted to a major number is interpreted as a packed dev_t number.
 1.41 14-Jun-2013  tsutsui Remove old workaround for Cygwin.
http://mail-index.netbsd.org/source-changes/2003/05/08/0042.html

16bit dev_t for !__CYGWIN_USE_BIG_TYPES__ was removed in Cygwin 1.7.2
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/include/cygwin/types.h?cvsroot=src#rev1.32
and __dev32_t has been removed since 1.7.19.
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/include/cygwin/types.h?cvsroot=src#rev1.36
 1.40 27-Aug-2011  joerg branches: 1.40.2; 1.40.8;
static + __dead
 1.39 13-Feb-2009  lukem fix -Wsign-compare issues
 1.38 20-Jul-2008  lukem branches: 1.38.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.37 28-Apr-2008  martin branches: 1.37.2;
Remove clause 3 and 4 from TNF licenses
 1.36 07-Jul-2007  dsl branches: 1.36.12; 1.36.14;
Use block minor (from device name) for block devices (not char minor).
Fixes PR bin/36614
 1.35 01-Oct-2005  christos fix setmode error handling.
 1.34 20-Jun-2004  jmc Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')

Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).

Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.

Fixes PR's: PR#17762 PR#25944
 1.33 17-Jun-2004  christos We only need sys/sysctl.h when we are building on NetBSD not as a host tool.
 1.32 17-Jun-2004  dsl Add support for specifying drivers by name and listing the drivers in the
current kernel.
Man page update in progress.
 1.31 11-May-2004  christos Constify.
 1.30 30-Jan-2004  ross Don't exit on error from pack_dev.c, but return an error string and
have the caller do cleanup and (potentially) report errors in context.
This is needed because mknod(8) is not the only user of pack_dev.[ch]
 1.29 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.28 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.27 08-May-2003  christos deal with cygwin's dev_t (John Gordon)
 1.26 08-May-2003  dsl Add -g gid -m mode -u uid so that MAKEDEV can run when chown/chmod are
not available.
Add -r and -R to do two (different) sensible things if node exists.
From a discussion with Lukem.
 1.25 17-Apr-2003  lukem clear errno before strto(u)l() if we're going to test it for ERANGE afterwards
 1.24 08-Oct-2001  lukem cleanups suggested by simonb:
- rename "format.c" -> "pack_dev.c", "mknod.h" -> "pack_dev.h"
- make the private stuff in pack_dev.c static
 1.23 08-Oct-2001  lukem improve arg clamping
 1.22 08-Oct-2001  lukem - move parsing of format type and format handlers into format.c, for easier
use in other programs
- do a bit of KNF whilst here
- enable WARNS=2
 1.21 19-Feb-2001  cgd convert to use getprogname()
 1.20 04-Feb-2001  christos fix nested extern
 1.19 03-Jul-2000  matt More include fixups and GCC 2.96 nonsense
 1.18 24-Nov-1998  christos Add mknod <name> p which creates a named pipe. There is no real reason for
a separate mkfifo program and there is prior art.
 1.17 13-Oct-1998  tron Print correct filename if mknod() fails.
 1.16 08-Oct-1998  wsanchez Init dev to quiet compiler.
 1.15 11-Sep-1998  mycroft Oops; update usage message.
 1.14 11-Sep-1998  mycroft Add isc, sco, and bsdos 3-field format.
 1.13 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.12 17-Jan-1998  mycroft Add a `bsdos' format.
 1.11 17-Jan-1998  mycroft Add a -F option to specify the device number format.
Also accept a single opaque device number.
 1.10 05-Nov-1997  cgd lint
 1.9 15-Sep-1997  lukem * cleanup for WARNS+1
* use .Nm correctly
 1.8 11-Aug-1995  jtc Convert to use err(3)
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 18-Dec-1994  cgd -Wall cleanups from Jim Jegers
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.36.14.1 18-May-2008  yamt sync with head.
 1.36.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.36.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.37.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.38.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.40.8.1 23-Jun-2013  tls resync from head
 1.40.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2 08-Oct-2001  lukem cleanups suggested by simonb:
- rename "format.c" -> "pack_dev.c", "mknod.h" -> "pack_dev.h"
- make the private stuff in pack_dev.c static
 1.1 08-Oct-2001  lukem - move parsing of format type and format handlers into format.c, for easier
use in other programs
- do a bit of KNF whilst here
- enable WARNS=2
 1.12 14-Jun-2013  tsutsui Remove old workaround for Cygwin.
http://mail-index.netbsd.org/source-changes/2003/05/08/0042.html

16bit dev_t for !__CYGWIN_USE_BIG_TYPES__ was removed in Cygwin 1.7.2
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/include/cygwin/types.h?cvsroot=src#rev1.32
and __dev32_t has been removed since 1.7.19.
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/include/cygwin/types.h?cvsroot=src#rev1.36
 1.11 27-Aug-2011  joerg branches: 1.11.2; 1.11.8;
static + __dead
 1.10 13-Feb-2009  lukem fix -Wsign-compare issues
 1.9 28-Apr-2008  martin branches: 1.9.6;
Remove clause 3 and 4 from TNF licenses
 1.8 11-May-2004  christos branches: 1.8.26; 1.8.28;
Constify.
 1.7 30-Jan-2004  ross Don't exit on error from pack_dev.c, but return an error string and
have the caller do cleanup and (potentially) report errors in context.
This is needed because mknod(8) is not the only user of pack_dev.[ch]
 1.6 27-Oct-2003  lukem Overhaul how `build.sh tools' are used:

* Rename "config.h" to "nbtool_config.h" and
HAVE_CONFIG_H to HAVE_NBTOOL_CONFIG_H.
This makes in more obvious in the source when we're using
tools/compat/config.h versus "standard autoconf" config.h

* Consistently move the inclusion of nbtool_config.h to before
<sys/cdefs.h> so that the former can provide __RCSID() (et al),
and there's no need to protect those macros any more.

These changes should make it easier to "tool-ify" a program by adding:
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
to the top of the source files (for the general case).
 1.5 08-May-2003  christos deal with cygwin's dev_t (John Gordon)
 1.4 08-May-2003  lukem Move major_netbsd(), minor_netbsd(), and makedev_netbsd() from
pack_dev.c to pack_dev.h, so that #include-rs of the latter can use them.
 1.3 31-Jan-2002  tv Roll in fixes to permit cross-compiling from non-NetBSD hosts. This
round has been tested on Solaris/x86 and Linux hosts.

* Add host tools cap_mkdb, ctags, m4, uudecode.
* Protect __RCSID() and __COPYRIGHT() better.
* Reduce the number of places that need to include "config.h", to keep
sources closer to their "vanilla" versions.
* Add more compat #defines and autoconf-checked functions.
 1.2 29-Jan-2002  tv Add hooks to make mtree compilable from src/tools.
 1.1 08-Oct-2001  lukem cleanups suggested by simonb:
- rename "format.c" -> "pack_dev.c", "mknod.h" -> "pack_dev.h"
- make the private stuff in pack_dev.c static
 1.8.28.1 18-May-2008  yamt sync with head.
 1.8.26.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.11.8.1 23-Jun-2013  tls resync from head
 1.11.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8 14-Jun-2013  tsutsui Remove old workaround for Cygwin.
http://mail-index.netbsd.org/source-changes/2003/05/08/0042.html

16bit dev_t for !__CYGWIN_USE_BIG_TYPES__ was removed in Cygwin 1.7.2
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/include/cygwin/types.h?cvsroot=src#rev1.32
and __dev32_t has been removed since 1.7.19.
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/include/cygwin/types.h?cvsroot=src#rev1.36
 1.7 28-Apr-2008  martin branches: 1.7.20; 1.7.26;
Remove clause 3 and 4 from TNF licenses
 1.6 11-May-2004  christos branches: 1.6.26; 1.6.28;
Constify.
 1.5 30-Jan-2004  ross Don't exit on error from pack_dev.c, but return an error string and
have the caller do cleanup and (potentially) report errors in context.
This is needed because mknod(8) is not the only user of pack_dev.[ch]
 1.4 08-May-2003  christos /sbin/wizd points out that it is CYGWIN not GYGWIN.
 1.3 08-May-2003  christos deal with cygwin's dev_t (John Gordon)
 1.2 08-May-2003  lukem Move major_netbsd(), minor_netbsd(), and makedev_netbsd() from
pack_dev.c to pack_dev.h, so that #include-rs of the latter can use them.
 1.1 08-Oct-2001  lukem cleanups suggested by simonb:
- rename "format.c" -> "pack_dev.c", "mknod.h" -> "pack_dev.h"
- make the private stuff in pack_dev.c static
 1.6.28.1 18-May-2008  yamt sync with head.
 1.6.26.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.26.1 23-Jun-2013  tls resync from head
 1.7.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17 11-Aug-2013  dholland WARNS=5 is the default in sbin, don't need to set it explicitly.
 1.16 22-Aug-2012  jnemeth branches: 1.16.2;
Set WARNS=5. No warnings/errors were found with a test compile.
 1.15 13-Dec-2010  pooka branches: 1.15.6;
Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.14 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.13 02-Mar-2008  jmmv Add the ability to specify load-time properties for modules. This adds
three new flags to the new modload utility: -b, -i and -s, which are used
to pass boolean, integer and string parameters respectively.
 1.12 10-Feb-2008  jmmv branches: 1.12.2; 1.12.4;
Always test MKMODULAR with != "no". Requested by mrg@.
 1.11 09-Feb-2008  jmmv Reverse MKMODULAR checks.
 1.10 09-Feb-2008  jmmv Recognize MKMODULAR and build the appropriate tool.
 1.9 16-Jan-2008  ad Pull in my modules code for review/test/hacking.
 1.8 27-Jun-2005  christos branches: 1.8.10; 1.8.12;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.7 13-Jun-1999  mrg add ELF support, mostly from joda@pdc.kth.se (Johan Danielsson) in PR#6149,
updated for the symtab support for a.out (non for ELF yet) and other cleanup
by myself. should work on the alpha as well as other ELF ports...
remove the ld(1) output by default, rather than leaving little binary turds
across the filesystem...
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Dec-1994  cgd specify man pages the new way.
 1.4 09-Feb-1994  deraadt do not -DKERNEL please
 1.3 09-Aug-1993  mycroft Don't reset CFLAGS.
 1.2 08-Jun-1993  cgd add LKM man pages
 1.1 07-Jun-1993  cgd add support for terry lambert's loadable kernel modules.
needs a bit of cleanup, but overall: SLICK!
 1.8.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.10.1 23-Mar-2008  matt sync with HEAD
 1.12.4.2 17-Jan-2009  mjf Sync with HEAD.
 1.12.4.1 03-Apr-2008  mjf Sync with HEAD.
 1.12.2.1 24-Mar-2008  keiichi sync with head.
 1.15.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.15.6.1 30-Oct-2012  yamt sync with head
 1.16.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.6 06-Feb-2005  perry branches: 1.6.26;
remove obsolete "register" declarations.
 1.5 11-Feb-2004  jdolecek it's not correct to use MAXPATHNAME-sized buffer for link command, as
pointed out by Klaus Klein (original idea was that it should hold at least
the pathname ...); instead, let the ELF and a.out backends allocate memory
for the link command, and get rid of the fixed size buffer altogether
 1.4 10-Oct-2002  simonb Add support for using an optional linker script (/usr/lkm/ldscript if
found, and overridable by the -T option).
 1.3 07-Oct-2002  simonb Use "type *" instead of "type*".
 1.2 06-Oct-2002  simonb ANSIfy, KNF, declare externs in headers only.
 1.1 13-Jun-1999  mrg add ELF support, mostly from joda@pdc.kth.se (Johan Danielsson) in PR#6149,
updated for the symtab support for a.out (non for ELF yet) and other cleanup
by myself. should work on the alpha as well as other ELF ports...
remove the ld(1) output by default, rather than leaving little binary turds
across the filesystem...
 1.6.26.1 17-Jan-2009  mjf Sync with HEAD.
 1.20 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.19 08-Jul-2006  ross branches: 1.19.20;
Replace complicated test for ELFSIZE 64 with #ifdef _LP64 which is
the netbsd convention. Rig the old test temporarily to a #error
sanity check.
 1.18 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.17 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.16 11-Feb-2004  jdolecek it's not correct to use MAXPATHNAME-sized buffer for link command, as
pointed out by Klaus Klein (original idea was that it should hold at least
the pathname ...); instead, let the ELF and a.out backends allocate memory
for the link command, and get rid of the fixed size buffer altogether
 1.15 21-Oct-2003  fvdl Don't compare an integer to NULL.
 1.14 07-Nov-2002  thorpej Skip empty sections. From Allen Briggs.
 1.13 10-Oct-2002  simonb Add support for using an optional linker script (/usr/lkm/ldscript if
found, and overridable by the -T option).
 1.12 07-Oct-2002  simonb Use "type *" instead of "type*".
 1.11 06-Oct-2002  simonb ANSIfy, KNF, declare externs in headers only.
 1.10 24-Jul-2002  joda various spelling
 1.9 03-Apr-2002  jdolecek Only provide sym_size and sym_symsize if symbols are actually going
to be loaded.
This also avoids the annoying 'Unable to find symbol table slot
for xxx' kernel message when module is unloaded.
 1.8 03-Jan-2002  jdolecek make sure string_table is initialized to NULL in read_shstring_table(),
so that NULL is returned if .strtab is not found
 1.7 08-Nov-2001  christos PR/14498: Wesley Chen: Support symbol loading on elf lkms.
 1.6 19-Jun-2001  fvdl Use ELFSIZE 64 for x86-64.
 1.5 26-Mar-2001  drochner Do the last fix correctly: round the beginning of the .data segment,
otherwise an unaligned address gets passed to the linker. (which is
rounded there, so this is harmless)
XXX how about passing "-N" and killing all these hacks?
 1.4 27-Dec-2000  jdolecek make sure that elf_mod_sizes() uses data_hole size aligned to section alignment
this fixes a problem where elf_mod_sizes() would report size which would
be different (smaller) that the actual size of LKM code to be loaded in some
cases

Reviewed by: Johan Danielsson
 1.3 25-Oct-1999  kleink branches: 1.3.6;
Update to match new SVR4-style definition names in <sys/exec_elf.h>.
 1.2 21-Jul-1999  mycroft branches: 1.2.2;
Don't try to play games with the BSS; just make it work.
 1.1 13-Jun-1999  mrg add ELF support, mostly from joda@pdc.kth.se (Johan Danielsson) in PR#6149,
updated for the symtab support for a.out (non for ELF yet) and other cleanup
by myself. should work on the alpha as well as other ELF ports...
remove the ld(1) output by default, rather than leaving little binary turds
across the filesystem...
 1.2.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.6.1 25-Jan-2001  jhawk Pull up revision 1.4 (requested by jdolecek):
Ensure that data_hole is aligned to a section, otherwise
elf_mod_sizes() may report a size too small, affecting LKM loading.
 1.19.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.18 07-Jun-2020  thorpej Update for proplib(3) API changes.
 1.17 05-Sep-2016  sevan Drop main() prototype.
 1.16 06-May-2016  khorben More friendly error messages for modload(8) and modunload(8)

Tested on NetBSD/amd64.

From Christian Koch (cfkoch@) of EdgeBSD; thanks!
 1.15 07-Feb-2013  apb Don't pass NULL to prop_dictionary_set.
Coverity CID 275196.
 1.14 13-Dec-2010  pooka branches: 1.14.6; 1.14.12;
Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.13 11-Jun-2009  wiz Sync usage with man page.
 1.12 10-Jun-2009  jnemeth -p -P doesn't make much sense since no module will be loaded.
 1.11 09-Jun-2009  jnemeth Add the MODCTL_NO_PROP flag to tell the kernel to ignore <module>.prop.

Add the '-P' option to modload(8) to set this flag.
 1.10 05-Jun-2009  jnemeth Add a new [-d var] option which when combined with -p and -m will allow
you to delete vars from the existing <module>.prop file.
 1.9 05-Jun-2009  wiz Sort options.
 1.8 04-Jun-2009  jnemeth Add a "-m plist" option. This option will read in an existing
<module>.prop file and merge any options supplied on the "command
line".

This code will serve as the basis for in-kernel merging.
 1.7 19-May-2009  jnemeth fputs() instead of puts() so we don't get the silly extra blank line
 1.6 19-May-2009  wiz Sync usage and man page.
 1.5 19-May-2009  jnemeth Add -p option which outputs a property list suitable for loading with a
module. This is in preparation for having the kernel load an optional
<module>.prop alongside a module, which is useful for passing options
to autoloaded modules and modules loaded at boot time.
 1.4 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 02-Mar-2008  jmmv branches: 1.2.2; 1.2.4;
Add the ability to specify load-time properties for modules. This adds
three new flags to the new modload utility: -b, -i and -s, which are used
to pass boolean, integer and string parameters respectively.
 1.1 16-Jan-2008  ad branches: 1.1.2; 1.1.4; 1.1.6;
Pull in my modules code for review/test/hacking.
 1.1.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.1.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.1.4.1 24-Mar-2008  keiichi sync with head.
 1.1.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.2.1 16-Jan-2008  mjf file main.c was added on branch mjf-devfs on 2008-02-18 21:04:17 +0000
 1.2.4.1 18-May-2008  yamt sync with head.
 1.2.2.2 23-Mar-2008  matt sync with HEAD
 1.2.2.1 02-Mar-2008  matt file main.c was added on branch matt-armv6 on 2008-03-23 00:44:24 +0000
 1.14.12.1 25-Feb-2013  tls resync with head
 1.14.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.49 17-Jan-2021  mrg call it "kernel object linker module framework" not just
"module framework". the latter is generic enough to
also mean the old ld(1) linked loadable kernel modules.
 1.48 01-Jun-2020  uwe Make -f description actually use the word "force" so that it can be
found when searched for.
 1.47 18-Jul-2017  wiz Fix Dt argument.
 1.46 18-Jul-2017  christos PR/52417: Edgar Pettijohn: modules.conf(5) not mentioned in related manuals
 1.45 12-Sep-2016  wiz Add .An -nosplit.
 1.44 12-Sep-2016  sevan Document the version modload appeared and authors.
Correct spelling mistakes.
Bump date.
 1.43 28-Nov-2015  pgoyette Add cross-refs from modload(8) amd modunload(8) to modctl(2)
 1.42 06-Aug-2011  wiz Quote path separator character.
 1.41 06-Aug-2011  mbalmer Do not not look for modules in the current working directory first. This is
to prevent from accidentally loading ./module.kmod when we actually wanted to
load module from the system module area.

To load a module from a filesystem path, the module name must contain at
least on path separator character (/), to load a module from the system
module areas, the name must not contain a path separator character:

modload ./mymod.kmod # loads mymod.kmod from the curren directory
modload mymod # loads mymod.kmod from the system module area
 1.40 14-Dec-2010  jruoho Fix xref; module(4) -> module(7).
 1.39 13-Dec-2010  jruoho Xref module(4).
 1.38 05-Mar-2010  pooka note module changes
 1.37 11-Jun-2009  wiz Remove -P from -p section, not from -f one.
 1.36 10-Jun-2009  jnemeth -p -P doesn't make much sense since no module will be loaded.
 1.35 09-Jun-2009  jnemeth Add the MODCTL_NO_PROP flag to tell the kernel to ignore <module>.prop.

Add the '-P' option to modload(8) to set this flag.
 1.34 05-Jun-2009  jnemeth Add a new [-d var] option which when combined with -p and -m will allow
you to delete vars from the existing <module>.prop file.
 1.33 05-Jun-2009  wiz Sort options.
 1.32 04-Jun-2009  jnemeth Add a "-m plist" option. This option will read in an existing
<module>.prop file and merge any options supplied on the "command
line".

This code will serve as the basis for in-kernel merging.
 1.31 19-May-2009  wiz Sync usage and man page.
 1.30 19-May-2009  wiz Sort option descriptions. Split usage in SYNOPSIS in two, since there
are two different methods of calling it.
Add arguments to option descriptions.
 1.29 19-May-2009  jnemeth Add -p option which outputs a property list suitable for loading with a
module. This is in preparation for having the kernel load an optional
<module>.prop alongside a module, which is useful for passing options
to autoloaded modules and modules loaded at boot time.
 1.28 17-Nov-2008  uwe Punctuation formatting nit.
 1.27 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.26 24-Mar-2006  reed branches: 1.26.20;
In the DIAGNOSTICS section, document that mismatched LKM and kernel
versions will be reported to the console and to the system message
buffer.

And update documentation date.
 1.25 06-Sep-2003  wiz New sentence, new line; improve grammar.
 1.24 06-Sep-2003  jdolecek implement support for forced LKM load, which makes the kernel skip
the version checks, using new -f flag and LMFORCE ioctl

Hopefully the description in the manpage is discouraging enough so that
nobody would dare even _think_ of using forced loads. A warning
message is written to stderr when this is used, just in case.
 1.23 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.22 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.21 10-Oct-2002  simonb Add support for using an optional linker script (/usr/lkm/ldscript if
found, and overridable by the -T option).
 1.20 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.19 13-Sep-2002  gehenna For loadable drivers, the 3rd argument is character device major and
the 4th argument is block device major.

Remove one item from BUGS section.
 1.18 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.17 16-Nov-2001  wiz Improve author markup, use standard header.
 1.16 16-Nov-2001  wiz Whitespace nits
 1.15 05-Jun-2001  wiz Drop arguments of .Os.
 1.14 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.13 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.12 13-Jun-1999  mrg branches: 1.12.6;
add ELF support, mostly from joda@pdc.kth.se (Johan Danielsson) in PR#6149,
updated for the symtab support for a.out (non for ELF yet) and other cleanup
by myself. should work on the alpha as well as other ELF ports...
remove the ld(1) output by default, rather than leaving little binary turds
across the filesystem...
 1.11 30-Apr-1999  ross Invert the meaning of -s, from "don't load symbols" to "load symbols".
Document that this is expensive (and why) in the BUGS section.
 1.10 10-Mar-1999  erh branches: 1.10.2;
Add missing .El line.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 13-Jan-1999  sommerfe Allow modload to load symbols for use by DDB.
 1.7 15-Sep-1997  darrenr if xxxinit is not found in the module, look for <modname>_lkmentry as an
alternate entry point (used in provided modules). Mention this on man page
too.
 1.6 15-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* use .Nm correctly
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 18-Sep-1994  mycroft Bug fixes from John Kohl:
modload didn't honor its -p argument.
It also would destroy the input file when you didn't specify an output
symbol file with -o.
 1.3 29-Jan-1994  jtc branches: 1.3.2;
Fix spelling error in Copyright notice
 1.2 14-Jan-1994  jtc Fix spelling errors
 1.1 08-Jun-1993  cgd add LKM man pages
 1.3.2.1 29-Sep-1994  cgd from trunk.
 1.10.2.1 30-Apr-1999  perry pullup 1.10->1.11 (ross)
 1.12.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.52 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.51 27-Jun-2005  christos branches: 1.51.20; 1.51.28;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.50 25-Apr-2005  matt Terminate variable argument list with NULL, not 0.
 1.49 27-Oct-2004  peter Fix a typo in a comment.
 1.48 07-Sep-2004  jrf Replaced strncpy with strlcpy. Thanks to Peter Postma who
pointed them our in PR #25762. Approved by christos@NetBSD.org.
 1.47 28-Jun-2004  nathanw Remove an extraneous comment before main() that seems to have been
accidentally cut-and-pasted in with rev 1.30.
 1.46 08-Jun-2004  cjep Put -T in usage output. PR#25875 from Kouichirou Hiratsuka.
 1.45 19-Mar-2004  wiz Remove superfluous TRUE and FALSE definitions.
Noted by Jeff Ito in PR 24845.
 1.44 12-Feb-2004  kleink Update the change from rev. 1.42 to reflect that MAXPATH includes room
for the terminating NUL character.
 1.43 11-Feb-2004  jdolecek it's not correct to use MAXPATHNAME-sized buffer for link command, as
pointed out by Klaus Klein (original idea was that it should hold at least
the pathname ...); instead, let the ELF and a.out backends allocate memory
for the link command, and get rid of the fixed size buffer altogether
 1.42 10-Feb-2004  jdolecek use MAXPATHLEN-sized buffer for module paths
reported and fix provided in bin/24379 by Nicolas Joly
 1.41 06-Sep-2003  jdolecek implement support for forced LKM load, which makes the kernel skip
the version checks, using new -f flag and LMFORCE ioctl

Hopefully the description in the manpage is discouraging enough so that
nobody would dare even _think_ of using forced loads. A warning
message is written to stderr when this is used, just in case.
 1.40 13-Jul-2003  itojun remove obsolete comment
 1.39 12-Jul-2003  itojun asprintf() is easier than malloc + sprintf
 1.38 24-Apr-2003  ragge Try first to use /dev/ksyms to get kernel symbols, if that fails mutter a
bit and fallback to the old way.
 1.37 11-Apr-2003  jdolecek desupport LMRESERV_O, anything relying on it doesn't have chance of working
anyway due to numerous kernel structure changes
 1.36 09-Feb-2003  atatat If no other name is specified, and machdep.booted_kernel is present
and names a file, use that as a the default kernel, otherwise fall
back to /netbsd.

Makes lkms work *much* better when you're testing kernels that are not
named /netbsd.
 1.35 10-Oct-2002  simonb Add support for using an optional linker script (/usr/lkm/ldscript if
found, and overridable by the -T option).
 1.34 07-Oct-2002  simonb Use "type *" instead of "type*".
 1.33 06-Oct-2002  simonb ANSIfy, KNF, declare externs in headers only.
 1.32 18-Sep-2002  lha uppercase the lkm kernel-userspace dev macros and prefix them with LKM_
make modload print the bdev and cdev major when its a dev lkm
 1.31 13-Sep-2002  gehenna Split the overload block/character device major.
The 3rd argument is character device major and
the 4th argument is block device major.
 1.30 08-Nov-2001  christos PR/14498: Wesley Chen: Support symbol loading on elf lkms.
 1.29 29-Sep-2001  jdolecek couple cosmetic stylistic changes
 1.28 17-Sep-2001  assar (usage): add -s and -S
 1.27 16-Mar-2000  jdolecek correct getopt() optstring: -A gets a parameter!
 1.26 27-Feb-2000  deberg -S isn't supposed to take an argument
 1.25 13-Jun-1999  mrg add ELF support, mostly from joda@pdc.kth.se (Johan Danielsson) in PR#6149,
updated for the symtab support for a.out (non for ELF yet) and other cleanup
by myself. should work on the alpha as well as other ELF ports...
remove the ld(1) output by default, rather than leaving little binary turds
across the filesystem...
 1.24 30-Apr-1999  ross Invert the meaning of -s, from "don't load symbols" to "load symbols".
Document that this is expensive (and why) in the BUGS section.
 1.23 23-Apr-1999  abs Fix entry point parsing if output file specified to modload (PR7352)
 1.22 13-Jan-1999  sommerfe branches: 1.22.2;
Allow modload to load symbols for use by DDB.
 1.21 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.20 26-Jul-1998  mycroft const poisoning.
 1.19 01-Dec-1997  mjacob Mods for alpha: doesn't work yet, but this is as good a placeholder as
any to note the ld flags to actually use. Still to do: elf loading.
 1.18 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.17 15-Sep-1997  lukem use memset() not bcopy()
 1.16 15-Sep-1997  darrenr if xxxinit is not found in the module, look for <modname>_lkmentry as an
alternate entry point (used in provided modules). Mention this on man page
too.
 1.15 15-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* use .Nm correctly
 1.14 17-Jan-1996  jtc Check for .o extension after the *last* . in a file name.
Reported by Micheal Graff in PR #1868.
 1.13 28-May-1995  jtc <sys/errno.h> -> <errno.h>
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 18-Dec-1994  cgd -Wall cleanups from Jim Jegers
 1.10 18-Sep-1994  mycroft Bug fixes from John Kohl:
modload didn't honor its -p argument.
It also would destroy the input file when you didn't specify an output
symbol file with -o.
 1.9 23-May-1994  cgd branches: 1.9.2;
kill (bogus) multiple inclusions
 1.8 05-May-1994  cgd kill stupidity
 1.7 31-Mar-1994  mycroft Stylistic cleanup; use err*() and atexit().
 1.6 31-Mar-1994  ws Support BSS in LKMs
 1.5 10-Feb-1994  cgd while documentation is nice, including SunOS man pages in your source isn't!
 1.4 03-Dec-1993  deraadt i love ansi
 1.3 23-Nov-1993  cgd update for present reality
 1.2 07-Jun-1993  cgd open device for read/write, so we can actually load
devices w/new checks in kern_lkm.c
 1.1 07-Jun-1993  cgd add support for terry lambert's loadable kernel modules.
needs a bit of cleanup, but overall: SLICK!
 1.9.2.1 29-Sep-1994  cgd from trunk.
 1.22.2.2 30-Apr-1999  perry pullup 1.23->1.24 (ross)
 1.22.2.1 23-Apr-1999  perry pullup 1.22->1.23 (abs)
 1.51.28.1 20-Apr-2009  snj Apply patch (requested by ad in ticket #708):
Disable ksyms support, falling back to using sysctl to obtain the name
of the booted kernel.
 1.51.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.7 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.6 11-Feb-2004  jdolecek branches: 1.6.32;
it's not correct to use MAXPATHNAME-sized buffer for link command, as
pointed out by Klaus Klein (original idea was that it should hold at least
the pathname ...); instead, let the ELF and a.out backends allocate memory
for the link command, and get rid of the fixed size buffer altogether
 1.5 10-Oct-2002  simonb Add support for using an optional linker script (/usr/lkm/ldscript if
found, and overridable by the -T option).
 1.4 07-Oct-2002  simonb Use "type *" instead of "type*".
 1.3 06-Oct-2002  simonb ANSIfy, KNF, declare externs in headers only.
 1.2 08-Nov-2001  christos PR/14498: Wesley Chen: Support symbol loading on elf lkms.
 1.1 13-Jun-1999  mrg add ELF support, mostly from joda@pdc.kth.se (Johan Danielsson) in PR#6149,
updated for the symtab support for a.out (non for ELF yet) and other cleanup
by myself. should work on the alpha as well as other ELF ports...
remove the ld(1) output by default, rather than leaving little binary turds
across the filesystem...
 1.6.32.1 17-Jan-2009  mjf Sync with HEAD.
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.4 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.3 10-Oct-2002  simonb branches: 1.3.32;
Add support for using an optional linker script (/usr/lkm/ldscript if
found, and overridable by the -T option).
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 01-Apr-1994  mycroft Forgot to check this in.
 1.3.32.1 17-Jan-2009  mjf Sync with HEAD.
 1.2 13-Dec-2010  pooka use crunchops for crunchables
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.4 11-Aug-2013  dholland WARNS=5 is the default in sbin, don't need to set it explicitly.
 1.3 16-Aug-2012  jnemeth branches: 1.3.2;
Bump up to WARNS=5. No new warnings/errors were found.
 1.2 13-Dec-2010  pooka branches: 1.2.6;
Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.1 16-Jan-2008  ad branches: 1.1.2; 1.1.8;
Pull in my modules code for review/test/hacking.
 1.1.8.2 23-Mar-2008  matt sync with HEAD
 1.1.8.1 16-Jan-2008  matt file Makefile was added on branch matt-armv6 on 2008-03-23 00:44:24 +0000
 1.1.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.2.1 16-Jan-2008  mjf file Makefile was added on branch mjf-devfs on 2008-02-18 21:04:17 +0000
 1.2.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.6.1 30-Oct-2012  yamt sync with head
 1.3.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.26 07-Apr-2021  simonb Update usage message to reflect reality.
 1.25 27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.24 16-Nov-2016  pgoyette branches: 1.24.12; 1.24.14;
Add a description for the new MODULE_CLASS_BUFQ class.
 1.23 05-Sep-2016  sevan Drop main() prototype.
 1.22 03-Aug-2016  pgoyette Right-align numeric columns REFS and SIZE for easier viewing
 1.21 02-Dec-2015  pgoyette branches: 1.21.2;
By default, don't display the module load address. Add a -k option
to restore display of this field.
 1.20 04-Nov-2015  christos print flags symbolically.
 1.19 04-Nov-2015  pgoyette Add FLAGS to the module data displayed. Reduce some of the extra
inter-column white-space to (partly) compensate for the additional
column.
 1.18 23-Oct-2013  mbalmer use MODULE_CLASS_MISC for Lua modules
 1.17 21-Oct-2013  mbalmer properly display Lua modules
 1.16 26-Jun-2013  riz Display the load address of modules. PR bin/47951.
 1.15 07-Aug-2012  jnemeth branches: 1.15.2;
Add -A, -a, and -e options to modstat(8) along with kernel
changes required to support these options. The -e option was
requested by martin@ in private chat in order to make writing tests
easier (i.e. don't bother testing MODULAR functionaility if it
doesn't exist). While there, I added -A and -a since those were
quite similar.

-A Tells you whether or not modules can be autoloaded at the moment.
This option does take into consideration the sysctl
kern.module.autoload.

-a Tells you whether or not modules can be autoloaded at the moment.
This option does not take into consideration the sysctl
kern.module.autoload.

-e Tells you whether or not you may load a module at the moment.
 1.14 02-Aug-2011  mbalmer branches: 1.14.2;
Accept both 'modstat -n name' as well as 'modstat name' to display information
about a single module.
 1.13 03-Jun-2011  pgoyette Keep printf() happy - cast the max name length to type int
 1.12 03-Jun-2011  nonaka fix output format for long module name.
 1.11 13-Dec-2010  pooka branches: 1.11.4;
Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.10 19-Mar-2010  pooka Avoid known unknown if the kernel presents us with an unknown
unknown for module class and/or source.

related to PR kern/43014
 1.9 05-Mar-2010  pooka Use 8k buffer, since 4k is too short for the default list (might
save one round of modctl()).
 1.8 03-Oct-2009  elad Make modstat output look pretty again.
 1.7 02-Oct-2009  elad First part of secmodel cleanup and other misc. changes:

- Separate the suser part of the bsd44 secmodel into its own secmodel
and directory, pending even more cleanups. For revision history
purposes, the original location of the files was

src/sys/secmodel/bsd44/secmodel_bsd44_suser.c
src/sys/secmodel/bsd44/suser.h

- Add a man-page for secmodel_suser(9) and update the one for
secmodel_bsd44(9).

- Add a "secmodel" module class and use it. Userland program and
documentation updated.

- Manage secmodel count (nsecmodels) through the module framework.
This eliminates the need for secmodel_{,de}register() calls in
secmodel code.

- Prepare for secmodel modularization by adding relevant module bits.
The secmodels don't allow auto unload. The bsd44 secmodel depends
on the suser and securelevel secmodels. The overlay secmodel depends
on the bsd44 secmodel. As the module class is only cosmetic, and to
prevent ambiguity, the bsd44 and overlay secmodels are prefixed with
"secmodel_".

- Adapt the overlay secmodel to recent changes (mainly vnode scope).

- Stop using link-sets for the sysctl node(s) creation.

- Keep sysctl variables under nodes of their relevant secmodels. In
other words, don't create duplicates for the suser/securelevel
secmodels under the bsd44 secmodel, as the latter is merely used
for "grouping".

- For the suser and securelevel secmodels, "advertise presence" in
relevant sysctl nodes (sysctl.security.models.{suser,securelevel}).

- Get rid of the LKM preprocessor stuff.

- As secmodels are now modules, there's no need for an explicit call
to secmodel_start(); it's handled by the module framework. That
said, the module framework was adjusted to properly load secmodels
early during system startup.

- Adapt rump to changes: Instead of using empty stubs for securelevel,
simply use the suser secmodel. Also replace secmodel_start() with a
call to secmodel_suser_start().

- 5.99.20.

Testing was done on i386 ("release" build). Spearated module_init()
changes were tested on sparc and sparc64 as well by martin@ (thanks!).

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/09/25/msg006135.html
 1.6 16-Nov-2008  ad Sort output by name.
 1.5 15-Nov-2008  ad kernel -> builtin in output.
 1.4 14-Nov-2008  hira Add missing newline to usage.
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 19-Jan-2008  ad branches: 1.2.2; 1.2.6; 1.2.8; 1.2.10;
Fix a dumb bug.
 1.1 16-Jan-2008  ad Pull in my modules code for review/test/hacking.
 1.2.10.1 18-May-2008  yamt sync with head.
 1.2.8.2 23-Mar-2008  matt sync with HEAD
 1.2.8.1 19-Jan-2008  matt file main.c was added on branch matt-armv6 on 2008-03-23 00:44:24 +0000
 1.2.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.2.1 19-Jan-2008  mjf file main.c was added on branch mjf-devfs on 2008-02-18 21:04:17 +0000
 1.11.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.14.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.2.1 30-Oct-2012  yamt sync with head
 1.15.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.21.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.24.14.1 10-Jun-2019  christos Sync with HEAD
 1.24.12.3 07-Sep-2018  pgoyette At the request of reviewers, remove the module alias functionality.

We will rely only on module names and duplicate-symbol detection to
detect module conflicts.
 1.24.12.2 03-Apr-2018  pgoyette Remove fixed allocation of modules' "required" lists (previously
limited to MAXMODDEPS entries). Update the modctl(MODCTL_STAT)
syscall to return the required data in a new format, and retain
the previous data format in MODCTL_OSTAT. Update the compat_80
and compat_netbsd32 modules as needed.
 1.24.12.1 10-Mar-2018  pgoyette Update for new A-is-for-Alias flag value(s)
 1.28 23-Feb-2020  wiz Fix date.
 1.27 22-Feb-2020  pgoyette Clarify that the -k option only provides the address of the module's
text segment. The addresses of any other segments are not available.
 1.26 07-Dec-2019  wiz Remove superfluous Pp.
 1.25 06-Dec-2019  pgoyette Note also that the load address (if provided) is also for the module's
text segment.
 1.24 04-Dec-2019  pgoyette Note that the size returned by modctl(2) and displayed by modstat(8) is
only for the module's text section, not for the entire size of the module.

Addresses PR kern-54737
 1.23 27-Jan-2019  pgoyette branches: 1.23.2;
Merge the [pgoyette-compat] branch
 1.22 12-Sep-2016  wiz branches: 1.22.12; 1.22.14;
Add .An -nosplit.
 1.21 12-Sep-2016  sevan modstat initially lived in src/usr.bin/modstat before being moved to src/modstat.
Note the history of the initial implementation and amend AUTHORS section to
credit Terrence R. Lambert.
Heads up by Matthew Green.
 1.20 12-Sep-2016  sevan Document author and the version modstat appeared.
Bump date.
 1.19 02-Dec-2015  pgoyette By default, don't display the module load address. Add a -k option
to restore display of this field.
 1.18 29-Nov-2015  wiz Fix xref.
 1.17 04-Nov-2015  christos print flags symbolically.
 1.16 04-Nov-2015  pgoyette Add FLAGS to the module data displayed. Reduce some of the extra
inter-column white-space to (partly) compensate for the additional
column.
 1.15 24-Oct-2013  mbalmer bump date for previous
 1.14 24-Oct-2013  mbalmer remove lua class
 1.13 21-Oct-2013  mbalmer properly display Lua modules
 1.12 26-Jun-2013  riz Display the load address of modules. PR bin/47951.
 1.11 12-Aug-2012  wiz branches: 1.11.2;
Make the difference between -A and -a clearer by using more markup.
 1.10 07-Aug-2012  jnemeth Add -A, -a, and -e options to modstat(8) along with kernel
changes required to support these options. The -e option was
requested by martin@ in private chat in order to make writing tests
easier (i.e. don't bother testing MODULAR functionaility if it
doesn't exist). While there, I added -A and -a since those were
quite similar.

-A Tells you whether or not modules can be autoloaded at the moment.
This option does take into consideration the sysctl
kern.module.autoload.

-a Tells you whether or not modules can be autoloaded at the moment.
This option does not take into consideration the sysctl
kern.module.autoload.

-e Tells you whether or not you may load a module at the moment.
 1.9 02-Aug-2011  mbalmer branches: 1.9.2;
Accept both 'modstat -n name' as well as 'modstat name' to display information
about a single module.
 1.8 14-Dec-2010  jruoho Fix xref; module(4) -> module(7).
 1.7 13-Dec-2010  jruoho Xref module(4).
 1.6 05-Mar-2010  pooka note module changes
 1.5 02-Oct-2009  elad Bump date to today's date (rather than when the changes were made).
 1.4 02-Oct-2009  elad First part of secmodel cleanup and other misc. changes:

- Separate the suser part of the bsd44 secmodel into its own secmodel
and directory, pending even more cleanups. For revision history
purposes, the original location of the files was

src/sys/secmodel/bsd44/secmodel_bsd44_suser.c
src/sys/secmodel/bsd44/suser.h

- Add a man-page for secmodel_suser(9) and update the one for
secmodel_bsd44(9).

- Add a "secmodel" module class and use it. Userland program and
documentation updated.

- Manage secmodel count (nsecmodels) through the module framework.
This eliminates the need for secmodel_{,de}register() calls in
secmodel code.

- Prepare for secmodel modularization by adding relevant module bits.
The secmodels don't allow auto unload. The bsd44 secmodel depends
on the suser and securelevel secmodels. The overlay secmodel depends
on the bsd44 secmodel. As the module class is only cosmetic, and to
prevent ambiguity, the bsd44 and overlay secmodels are prefixed with
"secmodel_".

- Adapt the overlay secmodel to recent changes (mainly vnode scope).

- Stop using link-sets for the sysctl node(s) creation.

- Keep sysctl variables under nodes of their relevant secmodels. In
other words, don't create duplicates for the suser/securelevel
secmodels under the bsd44 secmodel, as the latter is merely used
for "grouping".

- For the suser and securelevel secmodels, "advertise presence" in
relevant sysctl nodes (sysctl.security.models.{suser,securelevel}).

- Get rid of the LKM preprocessor stuff.

- As secmodels are now modules, there's no need for an explicit call
to secmodel_start(); it's handled by the module framework. That
said, the module framework was adjusted to properly load secmodels
early during system startup.

- Adapt rump to changes: Instead of using empty stubs for securelevel,
simply use the suser secmodel. Also replace secmodel_start() with a
call to secmodel_suser_start().

- 5.99.20.

Testing was done on i386 ("release" build). Spearated module_init()
changes were tested on sparc and sparc64 as well by martin@ (thanks!).

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/09/25/msg006135.html
 1.3 17-Nov-2008  uwe ".Dv Qo foo Qc" should be ".Qq Dv foo"
 1.2 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.1 16-Jan-2008  ad branches: 1.1.2; 1.1.6; 1.1.8;
Pull in my modules code for review/test/hacking.
 1.1.8.2 23-Mar-2008  matt sync with HEAD
 1.1.8.1 16-Jan-2008  matt file modstat.8 was added on branch matt-armv6 on 2008-03-23 00:44:24 +0000
 1.1.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.1.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.2.1 16-Jan-2008  mjf file modstat.8 was added on branch mjf-devfs on 2008-02-18 21:04:17 +0000
 1.9.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.2.1 30-Oct-2012  yamt sync with head
 1.11.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.14.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.22.14.1 10-Jun-2019  christos Sync with HEAD
 1.22.12.3 07-Sep-2018  pgoyette At the request of reviewers, remove the module alias functionality.

We will rely only on module names and duplicate-symbol detection to
detect module conflicts.
 1.22.12.2 15-Mar-2018  pgoyette Typo - for aliases, the REQUIRES column contains the real _module_ name,
not the real alias name.
 1.22.12.1 10-Mar-2018  pgoyette Document the new A-is-for-Alias flag value
 1.23.2.1 09-Dec-2019  martin Pull up following revision(s) (requested by pgoyette in ticket #527):

sbin/modstat/modstat.8: revision 1.24
sbin/modstat/modstat.8: revision 1.26
lib/libc/sys/modctl.2: revision 1.16

Note that the size returned by modctl(2) and displayed by modstat(8) is
only for the module's text section, not for the entire size of the
module.

Addresses PR kern-54737

Remove superfluous Pp.
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.2 13-Dec-2010  pooka use crunchops for crunchables
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.16 11-Aug-2013  dholland WARNS=5 is the default in sbin, don't need to set it explicitly.
 1.15 22-Aug-2012  jnemeth branches: 1.15.2;
Set WARNS=5. No warnings/errors were found with a test compile.
 1.14 13-Dec-2010  pooka branches: 1.14.6;
Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.13 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.12 10-Feb-2008  jmmv branches: 1.12.4;
Always test MKMODULAR with != "no". Requested by mrg@.
 1.11 09-Feb-2008  jmmv Reverse MKMODULAR checks.
 1.10 09-Feb-2008  jmmv Recognize MKMODULAR and build the appropriate tool.
 1.9 16-Jan-2008  ad Pull in my modules code for review/test/hacking.
 1.8 27-Jun-2005  christos branches: 1.8.10; 1.8.12;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.7 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Dec-1994  cgd specify man pages the new way.
 1.4 09-Feb-1994  deraadt do not -DKERNEL please
 1.3 09-Aug-1993  mycroft Don't reset CFLAGS.
 1.2 08-Jun-1993  cgd add LKM man pages
 1.1 07-Jun-1993  cgd add support for terry lambert's loadable kernel modules.
needs a bit of cleanup, but overall: SLICK!
 1.8.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.10.1 23-Mar-2008  matt sync with HEAD
 1.12.4.1 17-Jan-2009  mjf Sync with HEAD.
 1.14.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.6.1 30-Oct-2012  yamt sync with head
 1.15.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6 05-Sep-2016  sevan Drop main() prototype.
 1.5 06-May-2016  khorben More friendly error messages for modload(8) and modunload(8)

Tested on NetBSD/amd64.

From Christian Koch (cfkoch@) of EdgeBSD; thanks!
 1.4 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.3 06-Dec-2010  jmcneill Allow for passing more than one module at a time:

$ sudo modunload auvitek xc5000 wintv_eeprom
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 16-Jan-2008  ad branches: 1.1.2; 1.1.6; 1.1.8; 1.1.10;
Pull in my modules code for review/test/hacking.
 1.1.10.1 18-May-2008  yamt sync with head.
 1.1.8.2 23-Mar-2008  matt sync with HEAD
 1.1.8.1 16-Jan-2008  matt file main.c was added on branch matt-armv6 on 2008-03-23 00:44:24 +0000
 1.1.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.2.1 16-Jan-2008  mjf file main.c was added on branch mjf-devfs on 2008-02-18 21:04:17 +0000
 1.23 12-Sep-2016  wiz Use standard section header.
 1.22 12-Sep-2016  sevan Document author and the version modunload appeared.
Bump date.
 1.21 28-Nov-2015  pgoyette Add cross-refs from modload(8) amd modunload(8) to modctl(2)
 1.20 14-Dec-2010  jruoho Fix xref; module(4) -> module(7).
 1.19 13-Dec-2010  jruoho Xref module(4).
 1.18 06-Dec-2010  jmcneill Allow for passing more than one module at a time:

$ sudo modunload auvitek xc5000 wintv_eeprom
 1.17 05-Mar-2010  pooka note module changes
 1.16 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.15 06-Sep-2003  wiz branches: 1.15.32;
New sentence, new line; drop trailing whitespace.
 1.14 06-Sep-2003  jdolecek if neither -i nor -n option is specified, use the passed argument
as module ID if it's numeric, and as module name if it's not numeric

this saves some typing which bothered me for some years (one too many today)
 1.13 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.12 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.11 16-Nov-2001  wiz Improve author markup, use standard header.
 1.10 16-Nov-2001  wiz Whitespace nits
 1.9 05-Jun-2001  wiz Drop arguments of .Os.
 1.8 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.7 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.6 07-Mar-1999  mycroft branches: 1.6.8;
Clean up SYNOPSIS formatting.
 1.5 15-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* use .Nm correctly
 1.4 28-Nov-1995  jtc merge in changes from 1.1 release branch
 1.3 18-Mar-1995  cgd branches: 1.3.2;
convert to new RCS Id conventions; reduce my headache
 1.2 29-Jan-1994  jtc Fix spelling error in Copyright notice
 1.1 08-Jun-1993  cgd add LKM man pages
 1.3.2.1 26-Oct-1995  jtc Fix bad xref: modunload(8) -> modload(8); PR #1691
 1.6.8.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.15.32.1 17-Jan-2009  mjf Sync with HEAD.
 1.14 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.13 05-Feb-2005  xtraeme branches: 1.13.26;
Kill __P(), use ANSI function declarations; WARNS=3.
 1.12 06-Sep-2003  jdolecek if neither -i nor -n option is specified, use the passed argument
as module ID if it's numeric, and as module name if it's not numeric

this saves some typing which bothered me for some years (one too many today)
 1.11 22-Jul-1999  hubertf s/atoi/strtol/ and check if argument given to -i was really a valid
number.

Patch submitted in PR 6456 by lha@stacken.kth.se
 1.10 15-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* use .Nm correctly
 1.9 28-May-1995  jtc <sys/errno.h> -> <errno.h>
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 18-Dec-1994  cgd -Wall cleanups from Jim Jegers
 1.6 23-May-1994  cgd kill (bogus) multiple inclusions
 1.5 05-May-1994  cgd kill stupidity
 1.4 01-Apr-1994  mycroft Style cleanup; use err*() and atexit().
 1.3 03-Dec-1993  deraadt i love ansi
 1.2 07-Jun-1993  cgd open device for read/write, so we can actually load
devices w/new checks in kern_lkm.c
 1.1 07-Jun-1993  cgd add support for terry lambert's loadable kernel modules.
needs a bit of cleanup, but overall: SLICK!
 1.13.26.1 17-Jan-2009  mjf Sync with HEAD.
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.3 12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.2 18-Mar-1995  cgd branches: 1.2.50;
convert to new RCS Id conventions; reduce my headache
 1.1 01-Apr-1994  mycroft Style cleanup; use err*() and atexit().
 1.2.50.1 17-Jan-2009  mjf Sync with HEAD.
 1.2 13-Dec-2010  pooka use crunchops for crunchables
 1.1 13-Dec-2010  pooka Add rump client support for module utilities. It should be noted
that while modstat and modunload and builtin modules work exactly
the same as in the host case, modload loads file system kernel
modules from the rump kernel namespace. By default, archs which
have rump support for the kernel kernel ABI have the host module
directory mapped into the rump kernel namespace at the same location
(/stand/...). Therefore, if the *host* module directory is populated,
"rump.modload foo" will work as expected. Otherwise, RUMP_MODULEBASE
can be used to point to the module directory.
 1.32 23-Jan-2016  christos Define _KERNTYPES for things that need it.
 1.31 07-Apr-2012  christos add missing DPADD
 1.30 07-Apr-2012  christos Accept NAME=label for special so that we can wire down our wedges.
 1.29 19-Aug-2004  christos branches: 1.29.52;
Remove special case
 1.28 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.27 19-Jan-2003  tsutsui libutil (which was added for MNT_GETARGS) is no longer needed.
 1.26 19-Jan-2003  jdolecek do not link all mount programs into single image; the total size difference
isn't really that huge now that these are compiled as dynamic
 1.25 01-Oct-2002  jdolecek update incorrect comment - getmntopts.c _is_ used by mount(8)
 1.24 21-Sep-2002  christos MNT_GETARGS support
 1.23 01-Sep-2002  taca Remove extra tab in really an empty line.
 1.22 23-Aug-2002  lukem if RESCUEDIR is defined, set _PATH_RESCUE to that
 1.21 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.20 20-Feb-2001  cgd use getprogname()
 1.19 04-Feb-2001  christos fix nested extern
 1.18 16-Jan-2001  cgd generated source should include stdlib.h and string.h for prototypes.
 1.17 02-Nov-2000  jdolecek also install mount_ufs manpage links
Fixes bin/11412 by Andrew Brown.
 1.16 01-Nov-2000  veego Add a 'CLEANFILES+= checkname.c' to remove that file during a make clean.
 1.15 30-Oct-2000  jdolecek mount(8) now includes code for all mount_*(8) but mount_portal(8) and
mount_mfs(8); the mount_*(8) are hardlinked to mount (appropriate mount routine
is called depending on program name) - this saves approx. 1.7MB of /sbin
space
mount.c: make all local symbols static
 1.14 16-Sep-1997  lukem branches: 1.14.6;
resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.13 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.12 01-Aug-1997  jtk don't need getmntopts.c as part of mount(8)
 1.11 04-Jul-1997  christos Fix warnings.
 1.10 12-Jul-1995  cgd remove FFS mounting code from mount(8); there are now _no_ 'internal' mount
types. when using mount(8) with '-a', do _NOT_ remount file systems
that have been mounted once already. (This cannot be 100% precisely
determined (thanks to mfs, union fs, and similar file systems which
don't use a 'real' mounted-from node), and changed options cannot be updated
with mount -a. however, options wouldn't be updated with the old mount -a
anyway, and this solves several annoyances.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 22-Dec-1994  cgd specify man pages the new way.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 08-Oct-1993  cgd there is no librpc any more
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 12-Apr-1993  cgd fixed NFSCLIENT problem.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.6.1 19-Oct-1999  fvdl Add CPPFLAGS+=-I${.CURDIR}/../../sys for convenience.
 1.29.52.1 17-Apr-2012  yamt sync with head
 1.10 19-Jun-2009  stacktic Fixed a_mask to actually use its argument
 1.9 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.8 28-Apr-2008  martin branches: 1.8.2;
Remove clause 3 and 4 from TNF licenses
 1.7 10-Mar-2007  hubertf branches: 1.7.12; 1.7.14;
- removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.6 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.5 02-Feb-2006  christos expose a_num.
 1.4 03-Mar-2005  dsl Simplify a_uid and a_gid, and fix a_mask to actually use its argument
(fortunately it is always called with 'optarg')
Saves a few bytes from mount_msdos in rescue_tiny.
 1.3 29-Oct-2004  dsl Add (unsigned char) cast to ctype function
 1.2 30-Oct-2000  jdolecek fix copyright (damned copy&paste)
 1.1 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.7.14.1 18-May-2008  yamt sync with head.
 1.7.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.7.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.5 28-Apr-2008  martin branches: 1.5.2;
Remove clause 3 and 4 from TNF licenses
 1.4 02-Feb-2006  christos branches: 1.4.20; 1.4.22;
expose a_num.
 1.3 03-Mar-2005  dsl Simplify a_uid and a_gid, and fix a_mask to actually use its argument
(fortunately it is always called with 'optarg')
Saves a few bytes from mount_msdos in rescue_tiny.
 1.2 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.1 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.4.22.1 18-May-2008  yamt sync with head.
 1.4.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.4.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.2.1 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.7 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.6 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.5 16-Nov-2001  wiz Whitespace nits
 1.4 05-Jun-2001  wiz Drop arguments of .Os.
 1.3 16-Sep-1997  lukem resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.7 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.6 09-Nov-1999  drochner Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
 1.5 16-Sep-1997  lukem branches: 1.5.10;
resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.4 04-Jul-1997  christos Fix warnings.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 24-Jun-1994  deraadt fix quotas
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.5.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.11 07-Nov-2002  christos PR/16688: Robert Elz: No way exists to use MNT_IGNORE (custom C code excepted)
 1.10 21-Sep-2002  christos MNT_GETARGS support
 1.9 15-Jun-2000  fvdl Enable and document the -o softdep option.
 1.8 01-Dec-1998  kenh branches: 1.8.10;
Add support for a new flag: "nodevmtime". This sets the MNT_NODEVMTIME mount
flag.
 1.7 30-Oct-1997  enami Conditionalize the recognition of symbolic link permission by
per fs mount option `symperm'.
 1.6 16-Sep-1997  lukem branches: 1.6.2;
resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.5 30-Jan-1997  tls add support for noatime mount flag
 1.4 23-Oct-1996  cgd recognize the 'nocoredump' mount option as a standard option (supported by
all file system types).
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 24-Jun-1994  deraadt fix quotas
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.6.2.1 31-Oct-1997  mellon Pull rev 1.7 up from trunk (enami)
 1.8.10.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.94 25-Sep-2025  christos PR/59669: rl / Hetzer: document posix1eacls
 1.93 01-Jul-2025  kre PR bin/59494

Cause "mount -v [spec] filesystem" to indicate only what was
mounted (and where), to obtain all the rest of the data that
used to be printed, -v must be given twice.

Implemented differently from the patch given in the PR from
greywolf, but the same idea.

While here, avoid the -d option, after indicating what mount
command would have been run, but wasn't, going on to attempt
to report statistics on the never mounted filesystem, and
instead getting those from the intended mount point.

Update the man page to match.
 1.92 03-Apr-2024  wiz branches: 1.92.2;
new sentence, new line
 1.91 03-Apr-2024  charlotte mount(8): Mention the ability to refer to dk(4) wedges in the manpage
 1.90 10-Jul-2022  snj drop reference to smbfs, which was removed in 2020.

while here, s/file-system/file system/
 1.89 04-Jun-2021  simonb Remove the warning about autoselecting nfs based on : or @.

Ok jmcneill@, mrg@.
 1.88 24-Oct-2020  nia branches: 1.88.4;
file systems that are used as what spools?
 1.87 09-Jan-2018  wiz Sort SEE ALSO.
 1.86 09-Jan-2018  christos Merge autofs support from: Tomohiro Kusumi
XXX: Does not work yet
 1.85 20-Nov-2017  wiz Remove Tn. Remove undefined .Sp. Use tagged list instead of hanging one
with .brs.
 1.84 20-Nov-2017  christos Clarify the program naming convention, and use consistently <fstype> instead
of XXX.
 1.83 22-Mar-2017  jdolecek expand a little the explanation about discard

describe behaviour of combination of log+async (i.e. same as just log)
 1.82 10-Nov-2016  jdolecek branches: 1.82.2;
stress more that discard is experimental, and explain why; also note that
it's not compatible with log
 1.81 12-Sep-2016  sevan mount appeared in V1
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/man/man1/mount.1
Replace contraction.
Bump date.
 1.80 06-Dec-2014  mbalmer branches: 1.80.2;
Add reference to mount_chfs, bump date.
 1.79 31-Oct-2013  apb Add a reference to secmodel_extensions(9), to make it a little easier to
figure out how to enable mounts for unprivileged users. (Why don't we
just explain vfs.generic.usermount in the mount(8) man page?)

Also add another example of different ways in which the "special"
argument is interpreted by different file systems: mount_tmpfs(8)
ignores it.
 1.78 19-Oct-2012  drochner Implement experimental support to pass notifications that a file
was deleted from the filesystem to the disk driver, commonly
known as "discard" or "trim".
fs/driver support is in ffs and ata wd for now.
This is what was posted here:
http://mail-index.netbsd.org/tech-kern/2012/02/28/msg012813.html
with minor cleanup, and the global switch replaced by a mount option.
 1.77 03-Oct-2012  wiz - Improve wording;
- remove superfluous `.Pp' macro (fixes mandoc(1) warning).

From Bug Hunting.
 1.76 23-Jun-2012  wiz branches: 1.76.2;
Bump date for previous.
 1.75 23-Jun-2012  jdf Clarify use of the union option for mount, as proposed in PR 45919.
Text proposed by apb.
 1.74 22-Jul-2011  dholland branches: 1.74.2;
Improve previous; thanks to tsutsui-san for reminding me of the proper
reference. PR 45166
 1.73 22-Jul-2011  dholland Clarify UFS2 superblock format stuff. Bump date.
 1.72 17-Jun-2011  wiz New sentence, new line; fix wording; bump date.
 1.71 17-Jun-2011  manu Add mount -o extattr option to enable extended attributs (corrently only
for UFS1).
Remove kernel option for EA backing store autocreation and do it by
default. Add a sysctl so that autocreated attriutr size can be modified.
 1.70 21-Nov-2010  pooka branches: 1.70.4;
xref rump_smbfs
 1.69 03-Oct-2009  wiz branches: 1.69.2;
Drop trailing whitespace.
 1.68 02-Oct-2009  elad Centralize documentation about exported sysctl variables in the relevant
secmodel's man-page.
 1.67 23-Feb-2009  wiz Fix typo, and restore line that was lost in previous.
 1.66 22-Feb-2009  ad PR kern/26878 FFSv2 + softdep = livelock (no free ram)
PR kern/16942 panic with softdep and quotas
PR kern/19565 panic: softdep_write_inodeblock: indirect pointer #1 mismatch
PR kern/26274 softdep panic: allocdirect_merge: ...
PR kern/26374 Long delay before non-root users can write to softdep partitions
PR kern/28621 1.6.x "vp != NULL" panic in ffs_softdep.c:4653 while unmounting a softdep (+quota) filesystem
PR kern/29513 FFS+Softdep panic with unfsck-able file-corruption
PR kern/31544 The ffs softdep code appears to fail to write dirty bits to disk
PR kern/31981 stopping scsi disk can cause panic (softdep)
PR kern/32116 kernel panic in softdep (assertion failure)
PR kern/32532 softdep_trackbufs deadlock
PR kern/37191 softdep: locking against myself
PR kern/40474 Kernel panic after remounting raid root with softdep

Retire softdep, pass 2. As discussed and later formally announced on the
mailing lists.
 1.65 20-Jan-2009  apb branches: 1.65.2;
* Say that type "nfs" is inferred if the path contains a
":" or "@". (Amazingly, this was not documented before).
* Say that the "nfs" inference is deprecated. (It was deprecated in
revision 1.87 of mount.c, dated 2009-01-11.)
* Add "-t nfs" in an example, so as not to rely on the automatic
inference of nfs when the path contains a colon.
* Try to improve the description of how the arguments are interpreted.
 1.64 11-Jan-2009  wiz New sentence, new line.
 1.63 11-Jan-2009  pooka Support mount -o rump, which uses the rump server instead of using
the kernel service. E.g. "mount -t efs -o rump /dev/sgidev /mnt"
runs effectively "rump_efs /dev/sgidev /mnt".
 1.62 13-Aug-2008  martti branches: 1.62.2;
s/If/It/
 1.61 04-Aug-2008  wiz Add missing word and bump date for previous.
 1.60 04-Aug-2008  simonb Mention "-o log".
 1.59 06-May-2008  xtraeme branches: 1.59.2;
Xref mount_tmpfs(8).
 1.58 01-Aug-2007  pooka branches: 1.58.10; 1.58.12; 1.58.14;
Explain that nosuid,nodev is also needed for non-privileged mounts.
 1.57 06-Jan-2007  elad Mention potential reasons for EPERM.
Requested by Anon Ymous.
 1.56 31-Oct-2006  mjf branches: 1.56.2; 1.56.4;
Revert the changes I introduced trying to solve tmpfs' NFS export problem.
Requested by yamt@
 1.55 24-Oct-2006  mjf Add support to allow a file system to not permit being exported over NFS.

Approved by elad@ and wrstuden@
 1.54 27-Sep-2006  wiz End sentence with a dot.
 1.53 25-Sep-2006  elad Add a DIAGNOSTICS section, specifically to address the "Operation not
supported by device" error. Reference options(4). Bump date.
 1.52 12-Feb-2006  chs convert "magiclinks" from a per-fs mount option to a system-wide sysctl.
as discussed on tech-kern quite some time ago.
 1.51 03-Feb-2006  riz Bump date, use "file system" consistently, no hyphen in "soft
dependencies", and sort options under -o.
 1.50 03-Feb-2006  riz Note that softdep and async options can't be used together. From
Dheeraj S in PR#32211, wording and formatting changes by me.
 1.49 02-Feb-2006  reinoud Crosslink mount(8) with mount_udf(8)
 1.48 13-Jan-2006  elad document port option; prompted by wiz@ :)
 1.47 23-Jun-2005  thorpej Implement expansion of special "magic" strings in symlinks into
system-specific values. Submitted by Chris Demetriou in Nov 1995 (!)
in PR kern/1781, modified only slighly by me.

This is enabled on a per-mount basis with the MNT_MAGICLINKS mount
flag. It can be enabled at mountroot() time by building the kernel
with the ROOTFS_MAGICLINKS option.

The following magic strings are supported by the implementation:

@machine value of MACHINE for the system
@machine_arch value of MACHINE_ARCH for the system
@hostname the system host name, as set with sethostname()
@domainname the system domain name, as set with setdomainname()
@kernel_ident the kernel config file name
@osrelease the releaes number of the OS
@ostype the name of the OS (always "NetBSD" for NetBSD)

Example usage:

mkdir /arch/i386/bin
mkdir /arch/sparc/bin
ln -s /arch/@machine_arch/bin /bin
 1.46 08-Dec-2004  snj branches: 1.46.2;
New sentence, new line, Xref fsck(8), use Dq.
 1.45 07-Dec-2004  jdolecek document reload option, description shamelessly stolen off ffs_reload()
comment
 1.44 27-Mar-2004  snj Bump date for last.
 1.43 27-Mar-2004  cgd Recognize 'from_mount' as the device, which is especially useful when
putting root on NFS. (From my PR, 20305.)
 1.42 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.41 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.40 21-Dec-2002  wiz removable with only two es, from Adrian Mrva.
 1.39 07-Nov-2002  wiz Sort SEE ALSO.
 1.38 07-Nov-2002  christos PR/16688: Robert Elz: No way exists to use MNT_IGNORE (custom C code excepted)
 1.37 01-Oct-2002  wiz Use .Fl t instead of \fI-t\fP.
 1.36 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.35 21-Sep-2002  christos MNT_GETARGS support
 1.34 21-May-2002  lukem Improve mount_mfs examples. Inspired by [misc/16193] from
Brian A. Seklecki <lavalamp@hurt.spiritual-machines.org>
 1.33 16-Nov-2001  wiz Drop empty lines and an unnecessary .Pp, sort sections.
 1.32 12-Sep-2001  gmcgarry Prominently provide explanation of who is allowed to mount file
systems.
 1.31 05-Jun-2001  wiz Drop arguments of .Os.
 1.30 18-Sep-2000  abs If device and mountpoint are given without -t, and without a : in the
device, check the disklabel for filesystem type. Fall back to ffs as ever.
 1.29 30-Jul-2000  jhawk Xr for mount_overlay(8)
 1.28 07-Jul-2000  he Make sure .Dl has the line to be shown as argument (on same line).
 1.27 07-Jul-2000  fair Add example text to answer PR 10232.
 1.26 15-Jun-2000  fvdl branches: 1.26.2;
Enable and document the -o softdep option.
 1.25 08-Aug-1999  jdolecek branches: 1.25.8;
xref mount_ntfs(8) in SEE ALSO
 1.24 01-Dec-1998  kenh branches: 1.24.2;
Add support for a new flag: "nodevmtime". This sets the MNT_NODEVMTIME mount
flag.
 1.23 03-Oct-1998  hubertf add mount_filecore to "see also"-list
 1.22 16-Sep-1998  mycroft Word the comments about `async' a bit more strongly.
 1.21 14-Sep-1998  ross Document noasync and nosync.
Clarify the meaning of sync.
Run all the -o keywords through the Cm (keyword emphasis) macro.
 1.20 29-Apr-1998  fair fix bad .Xr references
 1.19 19-Nov-1997  drochner Add a clarification how the missing data are looked up if either
mount source or target are omitted. Adresses PR 3240.
XXX This is not the complete truth. Things change with the -u
option. Should be fixed in "mount.c".
 1.18 30-Oct-1997  enami Conditionalize the recognition of symbolic link permission by
per fs mount option `symperm'.
 1.17 20-Oct-1997  enami branches: 1.17.2;
Fix .Nm usage.
 1.16 16-Sep-1997  lukem resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.15 15-Sep-1997  lukem * getopt returns -1 not EOF
* use .Nm correctly
 1.14 10-Mar-1997  mikel add support for MNT_NOATIME; from Lennart Augustsson in PR bin/3304.
 1.13 23-Oct-1996  cgd document the 'nocoredump' mount option, which sets the MNT_NOCOREDUMP
mount flag, disabling core dumps on the file system.
 1.12 22-May-1996  mrg fdesc file system does not allow files created in it. pr#941
 1.11 12-Jul-1995  cgd update docs to match the code.
 1.10 12-Jul-1995  cgd remove FFS mounting code from mount(8); there are now _no_ 'internal' mount
types. when using mount(8) with '-a', do _NOT_ remount file systems
that have been mounted once already. (This cannot be 100% precisely
determined (thanks to mfs, union fs, and similar file systems which
don't use a 'real' mounted-from node), and changed options cannot be updated
with mount -a. however, options wouldn't be updated with the old mount -a
anyway, and this solves several annoyances.
 1.9 30-Apr-1995  briggs Remove xref to mount_lofs and add xref to mount_ados and mount_msdos.
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 05-Jan-1994  cgd update for new (actually old... *sigh*) mount flags
 1.5 01-Aug-1993  mycroft Add RCS indentifiers.
 1.4 28-Jul-1993  cgd incorporate changes from 0-9-base to 0-9-ALPHA
 1.3 23-Mar-1993  cgd branches: 1.3.2;
changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.2.1 20-Jul-1993  cgd tell people to also see mount_XXX(8). if they read the previous
section of the man page, they'll understand that XXX expands into the
external FS name.
 1.17.2.2 19-Nov-1997  mellon Pull rev 1.19 up from trunk (drochner)
 1.17.2.1 31-Oct-1997  mellon Pull rev 1.18 up from trunk (enami)
 1.24.2.1 07-Jul-2000  he Pull up revisions 1.27-1.28 (requested by fair):
Add an EXAMPLES section to the mount(8) manual page.
Fixes PR#10232.
 1.25.8.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.2.2 26-Feb-2001  he Pull up revision 1.30 (requested by abs):
If both special and node are given (but no type), the disklabel
is checked for the file system type before falling back to ffs.
 1.26.2.1 04-Sep-2000  jhawk Pullup revs 1.27-1.29, requested by fair, he, and jhawk:
>----------------------------
>revision 1.29
>date: 2000/07/30 15:17:14; author: jhawk; state: Exp; lines: +2 -1
>Xr for mount_overlay(8)
>----------------------------
>revision 1.28
>date: 2000/07/07 17:58:37; author: he; state: Exp; lines: +2 -3
>Make sure .Dl has the line to be shown as argument (on same line).
>----------------------------
>revision 1.27
>date: 2000/07/07 09:25:36; author: fair; state: Exp; lines: +40 -1
>Add example text to answer PR 10232.
>----------------------------
 1.46.2.3 07-Oct-2006  ghen Pull up following revision(s) (requested by tron in ticket #1540):
sbin/mount/mount.8: revision 1.53 via patch
sbin/mount/mount.8: revision 1.54
Add a DIAGNOSTICS section, specifically to address the "Operation not
supported by device" error. Reference options(4). Bump date.
End sentence with a dot.
 1.46.2.2 20-Jan-2006  riz Back out tickets 490, 559, and 560, which added "magic symlinks", at
the request of chs@ (thorpej@ concurs), as there is consensus that
this should be changed to a system-wide tunable, rather than a mount
option.
 1.46.2.1 29-Dec-2005  riz Pull up following revision(s) (requested by thorpej in ticket #490):
lib/libc/sys/mount.2: revision 1.33
sys/sys/systm.h: revision 1.179
sys/sys/fstypes.h: revision 1.4
include/mntopts.h: revision 1.6
sys/conf/newvers.sh: revision 1.41
sys/kern/vfs_syscalls.c: revision 1.223
sys/conf/files: revision 1.720
sys/kern/vfs_lookup.c: revision 1.61
share/man/man7/symlink.7: revision 1.7
sbin/mount/mount.8: revision 1.47
sys/kern/init_main.c: revision 1.248 via patch
share/man/man4/options.4: revision 1.280 via patch
Implement expansion of special "magic" strings in symlinks into
system-specific values. Submitted by Chris Demetriou in Nov 1995 (!)
in PR kern/1781, modified only slighly by me.
This is enabled on a per-mount basis with the MNT_MAGICLINKS mount
flag. It can be enabled at mountroot() time by building the kernel
with the ROOTFS_MAGICLINKS option.
The following magic strings are supported by the implementation:
@machine value of MACHINE for the system
@machine_arch value of MACHINE_ARCH for the system
@hostname the system host name, as set with sethostname()
@domainname the system domain name, as set with setdomainname()
@kernel_ident the kernel config file name
@osrelease the releaes number of the OS
@ostype the name of the OS (always "NetBSD" for NetBSD)
Example usage:
mkdir /arch/i386/bin
mkdir /arch/sparc/bin
ln -s /arch/@machine_arch/bin /bin
 1.56.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.56.2.1 01-Aug-2007  liamjfoy Pull up following revision(s) (requested by pooka in ticket #806):
sbin/mount/mount.8: revision 1.58
Explain that nosuid,nodev is also needed for non-privileged mounts.
 1.58.14.2 01-Aug-2007  pooka Explain that nosuid,nodev is also needed for non-privileged mounts.
 1.58.14.1 01-Aug-2007  pooka file mount.8 was added on branch matt-mips64 on 2007-08-01 08:51:25 +0000
 1.58.12.1 18-May-2008  yamt sync with head.
 1.58.10.3 17-Jan-2009  mjf Sync with HEAD.
 1.58.10.2 28-Sep-2008  mjf Sync with HEAD.
 1.58.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.59.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.62.2.4 17-Mar-2012  bouyer Pull up following revision(s) (requested by dholland in ticket #1743):
sbin/mount/mount.8: revision 1.73
sbin/mount/mount.8: revision 1.74
Clarify UFS2 superblock format stuff. Bump date.
Improve previous; thanks to tsutsui-san for reminding me of the proper
reference. PR 45166
 1.62.2.3 22-Jan-2009  snj branches: 1.62.2.3.2; 1.62.2.3.6;
Pull up following revision(s) (requested by apb in ticket #303):
sbin/mount/mount.8: revision 1.65
* Say that type "nfs" is inferred if the path contains a
":" or "@". (Amazingly, this was not documented before).
* Say that the "nfs" inference is deprecated. (It was deprecated in
revision 1.87 of mount.c, dated 2009-01-11.)
* Add "-t nfs" in an example, so as not to rely on the automatic
inference of nfs when the path contains a colon.
* Try to improve the description of how the arguments are interpreted.
 1.62.2.2 22-Jan-2009  snj Pull up following revision(s) (requested by pooka in ticket #288):
sbin/mount/mount.8: revision 1.64
New sentence, new line.
 1.62.2.1 22-Jan-2009  snj Pull up following revision(s) (requested by pooka in ticket #288):
include/mntopts.h: revision 1.12
sbin/mount/mount.8: revision 1.63
sbin/mount/mount.c: revision 1.88
Support mount -o rump, which uses the rump server instead of using
the kernel service. E.g. "mount -t efs -o rump /dev/sgidev /mnt"
runs effectively "rump_efs /dev/sgidev /mnt".
 1.62.2.3.6.1 17-Mar-2012  bouyer Pull up following revision(s) (requested by dholland in ticket #1743):
sbin/mount/mount.8: revision 1.73
sbin/mount/mount.8: revision 1.74
Clarify UFS2 superblock format stuff. Bump date.
Improve previous; thanks to tsutsui-san for reminding me of the proper
reference. PR 45166
 1.62.2.3.2.1 17-Mar-2012  bouyer Pull up following revision(s) (requested by dholland in ticket #1743):
sbin/mount/mount.8: revision 1.73
sbin/mount/mount.8: revision 1.74
Clarify UFS2 superblock format stuff. Bump date.
Improve previous; thanks to tsutsui-san for reminding me of the proper
reference. PR 45166
 1.65.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.69.2.3 21-Oct-2010  uebayasi After consideration, put back "xip" mount option.

The internal behavior is totally different between with and without
the option; automatic detection and/or fall-through are not user
friendly. mount(8) returning the "xip" flag is also informative.
 1.69.2.2 28-May-2010  uebayasi Remove the "xip" option from mount_ffs(8) for simplicity.
 1.69.2.1 11-Feb-2010  uebayasi Add the new "xip" mount option.
 1.70.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.74.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.74.2.1 30-Oct-2012  yamt sync with head
 1.76.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.76.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.80.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.80.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.82.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.88.4.1 06-Jun-2021  cjep sync with head
 1.92.2.1 02-Aug-2025  perseant Sync with HEAD
 1.108 01-Jul-2025  kre PR bin/59494

Cause "mount -v [spec] filesystem" to indicate only what was
mounted (and where), to obtain all the rest of the data that
used to be printed, -v must be given twice.

Implemented differently from the patch given in the PR from
greywolf, but the same idea.

While here, avoid the -d option, after indicating what mount
command would have been run, but wasn't, going on to attempt
to report statistics on the never mounted filesystem, and
instead getting those from the intended mount point.

Update the man page to match.
 1.107 07-Dec-2021  christos branches: 1.107.4;
remove impossible test.
 1.106 02-Dec-2021  christos PR/56529: RVP: mount should try ffs when DIOCGWEDGEINFO returns an empty
dkw_ptype.
 1.105 21-Nov-2021  simonb Add some { } around an if body that is followed by an "else {".
 1.104 04-Jun-2021  simonb Remove the warning about autoselecting nfs based on : or @.

Ok jmcneill@, mrg@.
 1.103 18-Oct-2020  mlelstv branches: 1.103.4;
Make command line arguments -r and -w actually override defaults from fstab,
previously -w would only cancel a preceeding -r.

No longer strip -o rw.
 1.102 09-Oct-2016  christos try to be more clear about what is not found.
 1.101 08-Oct-2016  maya change warning message

previously attempting to use mount -t ext2 like myself would result in
the warning "mount: mount_ext2 not found for /mnt", which (if you're me)
can be misunderstood as "/mnt is not an ext2 filesystem"...

change it to "mount: mount_ext2 not found"
 1.100 04-Jan-2015  pooka branches: 1.100.2;
gcc 4.9 produces vfork clobberation warnings for "name" and "buflen".
Since there's no performance reason to use vfork here, just replace it
with fork and be done with warnings once and for all.
 1.99 05-Oct-2013  ast No code change: corrected spelling in comment, removed trailing white spaces.
 1.98 24-Jan-2013  christos use return instead of exit.
 1.97 14-Jun-2012  christos branches: 1.97.2;
don't print the NULL, but the error
 1.96 09-Apr-2012  mlelstv return exit code from mount_XXXX again
 1.95 07-Apr-2012  christos use getfsspecname
 1.94 07-Apr-2012  christos Accept NAME=label for special so that we can wire down our wedges.
 1.93 29-Aug-2011  joerg branches: 1.93.2;
Use __dead
 1.92 13-Jan-2011  pooka In case we are union-mounting /, don't force MNT_UPDATE. This makes
the following work:

mount -t tmpfs -o union tmpfs /

(some caveats are implied, such as if you "mkdir /usr" you're
screwed, but then again you'll get there with "rm -rf /usr" even
without union -- we supply rope)

per discussion with zafer, use case for jibbed
 1.91 14-Jan-2010  pooka Remove puffs| from vfstype before making comparison to determine if
fs is mounted.

Fixes slightly-miscategorized kern/37626.
 1.90 14-Jan-2010  pooka If getargs and vfs has PUFFS_TYPEPREFIX, use mount_puffs to query args.
 1.89 04-May-2009  yamt disable automatic mountd reloading for now because it makes the service
temporary unavailable. PR/41331 from FUKAUMI Naoki.
 1.88 11-Jan-2009  pooka branches: 1.88.2;
Support mount -o rump, which uses the rump server instead of using
the kernel service. E.g. "mount -t efs -o rump /dev/sgidev /mnt"
runs effectively "rump_efs /dev/sgidev /mnt".
 1.87 11-Jan-2009  pooka Warn that autoselecting nfs based on : or @ in the device path will
be removed in a future release.
 1.86 05-Aug-2008  pooka branches: 1.86.2;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.85 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.84 17-Jul-2007  christos branches: 1.84.12; 1.84.16;
cast sizeof() to int for printf widths.
 1.83 17-Jul-2007  christos kill MFSTYPENAME
 1.82 16-Oct-2006  christos sprinkle volatile.
 1.81 04-May-2006  christos since yamt prohibits any flag with MNT_GETARGS, don't set MNT_UPDATE for
/ when we do getargs.
 1.80 21-Mar-2006  christos Coverity CID 1688: Fix memory leak.
 1.79 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.78 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.77 18-Mar-2005  lukem Fix core dump when doing
mount fileserver:/somepath
by not passing a NULL pointer to getfsfile(3).
(Bug was introduced in rev 1.74 as part of fix for PR 28644.)
 1.76 05-Feb-2005  xtraeme branches: 1.76.2;
Kill __P(), use ANSI function declarations.
 1.75 31-Jan-2005  he Move local variable declaration to variable declaration section at
top of function, and at least away from after active code within
a block. Fixes build problem with gcc 2 (for vax).
 1.74 31-Jan-2005  erh PR #28644: Use realpath to make mount more forgiving of non-canonical
mount paths entered on the command line.
 1.73 25-Sep-2004  thorpej Try the DIOCGWEDGEINFO ioctl first. If that succeeds (i.e. the block
device is a wedge), use the partition type string from the dkwedge_info
structure to get the file system type.
 1.72 19-Aug-2004  christos Handle RESCUEDIR
 1.71 30-Apr-2004  enami Print fsid on verbose printing. It is useful when debugging nfs.
 1.70 22-Apr-2004  hannken Use PRIu64 to printf uint64_t. Compiles again on sparc64.
 1.69 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.68 27-Mar-2004  cgd Recognize 'from_mount' as the device, which is especially useful when
putting root on NFS. (From my PR, 20305.)
 1.67 19-Sep-2003  itojun realloc pedant
 1.66 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.65 19-Jan-2003  jdolecek do not link all mount programs into single image; the total size difference
isn't really that huge now that these are compiled as dynamic
 1.64 23-Sep-2002  enami Cosmetic changes.
 1.63 23-Sep-2002  enami Properly terminate the output from mount -v.
 1.62 21-Sep-2002  christos make sure options is not NULL before we look in it. Thanks Charles.
 1.61 21-Sep-2002  christos MNT_GETARGS support
 1.60 23-Aug-2002  lukem if _PATH_RESCUE is defined, try that before _PATH_SBIN & _PATH_USRSBIN
 1.59 21-May-2002  nathanw When attempting to guess the filesystem type from the disklabel, don't
consider a out-of-range partition letter at the end of the special
device node to be a fatal error; just return NULL and let the caller
fall back to FFS.

This fixes the "mount -u /kern/rootdev /" done by the script installer.

XXX this is still gross, and breaks things like
"mount /my/strange/dev/path/b /mnt". Perhaps it should stat the node
and use the minor number as an index instead?
 1.58 30-Jan-2002  christos Use __MNT_FLAGS from <sys/mount.h> instead of rolling our own list. Also
when -v is used, print even the silent flags.
 1.57 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.56 18-Feb-2001  tsutsui Add x_mount, which does not include any MOUNT_PROGS.
Installer does not require all vfs progs and all binaries
are crunched after all.
 1.55 01-Nov-2000  enami Factor out some function declarations into a header file.
 1.54 01-Nov-2000  enami When failed to read disklabel to deduce filesystem type,
- don't warn. It's just too verbose when we know there is
no disklabel and want to use the default filesystem type.
- close the file descriptor so that further mount success.
 1.53 01-Nov-2000  enami Cosmetic changes.
 1.52 30-Oct-2000  jdolecek mount(8) now includes code for all mount_*(8) but mount_portal(8) and
mount_mfs(8); the mount_*(8) are hardlinked to mount (appropriate mount routine
is called depending on program name) - this saves approx. 1.7MB of /sbin
space
mount.c: make all local symbols static
 1.51 11-Oct-2000  abs When determining the filesystem type automatically, only try the raw device
for the disklabel if the given device fails with EBUSY. Also make disklabel
errors non fatal (just fall back to ffs as per pre-autofilesystem behaviour)
Based on further discussion with Launey Thomas <ljt@alum.mit.edu>
 1.50 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.49 02-Oct-2000  abs When opening a partition to automatically determine the filesystem type,
always use the raw partition in case it is already mounted and this is
an 'update' mount. Patch from Launey Thomas <ljt@alum.mit.edu>
 1.48 18-Sep-2000  abs If device and mountpoint are given without -t, and without a : in the
device, check the disklabel for filesystem type. Fall back to ffs as ever.
 1.47 16-Nov-1999  enami branches: 1.47.4;
If we didn't print an open paren, no need to print a closing paren
(by backing out part of previous commit).
 1.46 15-Nov-1999  fvdl Print softdep information. Also print sync+async writes in verbose mode.
 1.45 01-Dec-1998  kenh branches: 1.45.2; 1.45.4; 1.45.8;
Add support for a new flag: "nodevmtime". This sets the MNT_NODEVMTIME mount
flag.
 1.44 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.43 26-Jul-1998  mycroft const poisoning.
 1.42 06-May-1998  ross Rewrite options and fstype handling for upgrade mounts.
 1.41 23-Nov-1997  enami Add MNT_SYMPERM to optnames[].
 1.40 05-Nov-1997  cgd lint
 1.39 01-Nov-1997  drochner Take out last change (wait for mount_mfs completion).
I changed it in mount_mfs instead.
 1.38 01-Nov-1997  drochner Fix a problem with asynchronous processing of mfs mounts: Calls to
statfs() or getmountinfo() did not tell about the freshly mounted
ramdisk.
XXX Imo, "mount_mfs" should not return before the mount is done.
This is the only place where this can be done cleanly. But this would
require a substancial restructuring of "newfs". For now, wait in "mount"
until the filesystem appears.
 1.37 01-Nov-1997  drochner Fix a misbehaviour introduced in rev. 1.34 - mountfs() returned in
"verbose" mode after printing the exec args.
This invalidates most of my comment in the previous commit. (Not all,
there are still bogosities with mount_mfs.)
 1.36 01-Nov-1997  drochner When checking whether a filesystem is already mounted (for -a), get and
check all mounts (getmntinfo), not only the top one (statfs).
Otherwise we might miss lower level mounts on the same mountpoint.
XXX "mount" behaves differently with the "verbose" flag (-v) in some
cases, probably due to asynchronous calls to fs dependant mount programs.
 1.35 31-Oct-1997  mycroft Import modified mangle() from mount(8).
Also rewrite catopt() with a more sane interface.
 1.34 29-Oct-1997  christos PR/2974: VaX#n8: fix the rest of the problems that were not addressed by 4384.
- vfork exit -> _exit
- debug and verbose consistency with fsck.
 1.33 29-Oct-1997  christos PR/4384: Brian Grayson: Pass the real argv[0] to the exec'ed child.
Also while I am here, remove bogus XXX comment about mount_mfs.
 1.32 16-Sep-1997  lukem branches: 1.32.2;
resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.31 15-Sep-1997  lukem * getopt returns -1 not EOF
* use .Nm correctly
 1.30 30-Jul-1997  christos When we mount -u and there is no vfstype specified, deduce the vfstype from
statfs.
 1.29 04-Jul-1997  christos Fix warnings.
 1.28 31-May-1997  pk More accurate failure message for unknown filesystem types, as
suggested in PR#1274.
 1.27 17-May-1997  pk NULL => 0 (Arne Juul; PR#3629)
 1.26 10-Mar-1997  mikel add support for MNT_NOATIME; from Lennart Augustsson in PR bin/3304.
 1.25 23-Oct-1996  cgd recognize MNT_NOCOREDUMP and print the 'nocoredump' flag for file
systems which have MNT_NOCOREDUMP set.
 1.24 18-Nov-1995  cgd Recognize all mount flags exported from the kernel (but only print the
ones that we used to print). Note unrecognized flags(s) when printing
mount list.
 1.23 22-Aug-1995  jtc Call mount_ffs instead of mount_ufs; PR #1379
 1.22 12-Jul-1995  cgd fix a goof in my previous code, that i thought of while reading pr 749.
add a -A flag, which does the same thing as '-a', but doesn't check for
remounts.
 1.21 12-Jul-1995  cgd remove FFS mounting code from mount(8); there are now _no_ 'internal' mount
types. when using mount(8) with '-a', do _NOT_ remount file systems
that have been mounted once already. (This cannot be 100% precisely
determined (thanks to mfs, union fs, and similar file systems which
don't use a 'real' mounted-from node), and changed options cannot be updated
with mount -a. however, options wouldn't be updated with the old mount -a
anyway, and this solves several annoyances.
 1.20 04-Jul-1995  ghudson Give an argument to the warning message for when realpath() fails.
 1.19 22-Jun-1995  cgd specify precision, not minimum field width. pointed out by John Kohl
 1.18 18-Jun-1995  cgd don't assume f_fstypename is larger than MFSNAMELEN or is nul-terminated
 1.17 28-May-1995  jtc sys_siglist[] -> strsignal()
 1.16 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.15 30-Jan-1995  mycroft Change type list code to match umount(8).
 1.14 18-Dec-1994  cgd compile against new headers
 1.13 29-Aug-1994  mycroft branches: 1.13.2;
Display type of mount; suggested by Thomas Eberhardt.
 1.12 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.11 18-Apr-1994  cgd allow external mount types, even if LETS_GET_SMALL
 1.10 15-Apr-1994  cgd oops, forgot one
 1.9 14-Apr-1994  cgd fs type names, and much clean
 1.8 05-Jan-1994  cgd update for new (actually old... *sigh*) mount flags
 1.7 05-Dec-1993  deraadt should bzero automatic sockaddr's before use
 1.6 07-Sep-1993  ws Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers
 1.5 03-Aug-1993  mycroft Recognize `noauto' (and `auto', just for symmetry) in fstab.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.13.2.2 29-Aug-1994  mycroft Display type of mount; suggested by Thomas Eberhardt.
 1.13.2.1 29-Aug-1994  mycroft file mount.c was added on branch netbsd-1-0 on 1994-08-29 02:38:01 +0000
 1.32.2.3 08-May-1998  mycroft Pull up 1.42, per request of ross.
 1.32.2.2 02-Nov-1997  mellon Pull rev 1.36, 1.37, 1.38 and 1.39 up from trunk (drochner)
 1.32.2.1 31-Oct-1997  mellon Pull rev 1.33, 1.34 and 1.35 up from trunk (mycroft)
 1.45.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.45.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.45.2.1 10-Oct-2000  he Pull up revision 1.50 (via patch, requested by is):
Format string cleanup.
 1.47.4.2 26-Feb-2001  he Pull up revisions 1.48-1.49,1.51,1.54 (via patch, requested by abs):
If both special and node are given (but no type), the disklabel
is checked for the file system type before falling back to ffs.
 1.47.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.76.2.1 19-Mar-2005  tron Pull up revision 1.77 (requested by lukem in ticket #10):
Fix core dump when doing
mount fileserver:/somepath
by not passing a NULL pointer to getfsfile(3).
(Bug was introduced in rev 1.74 as part of fix for PR 28644.)
 1.84.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.84.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.84.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.86.2.2 22-Jan-2009  snj Pull up following revision(s) (requested by pooka in ticket #288):
include/mntopts.h: revision 1.12
sbin/mount/mount.8: revision 1.63
sbin/mount/mount.c: revision 1.88
Support mount -o rump, which uses the rump server instead of using
the kernel service. E.g. "mount -t efs -o rump /dev/sgidev /mnt"
runs effectively "rump_efs /dev/sgidev /mnt".
 1.86.2.1 16-Jan-2009  bouyer Pull up following revision(s) (requested by pooka in ticket #266):
sbin/mount/mount.c: revision 1.87
Warn that autoselecting nfs based on : or @ in the device path will
be removed in a future release.
 1.88.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.93.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.93.2.2 30-Oct-2012  yamt sync with head
 1.93.2.1 17-Apr-2012  yamt sync with head
 1.97.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.97.2.1 25-Feb-2013  tls resync with head
 1.100.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.103.4.1 06-Jun-2021  cjep sync with head
 1.107.4.1 02-Aug-2025  perseant Sync with HEAD
 1.3 12-Jul-1995  cgd remove FFS mounting code from mount(8); there are now _no_ 'internal' mount
types. when using mount(8) with '-a', do _NOT_ remount file systems
that have been mounted once already. (This cannot be 100% precisely
determined (thanks to mfs, union fs, and similar file systems which
don't use a 'real' mounted-from node), and changed options cannot be updated
with mount -a. however, options wouldn't be updated with the old mount -a
anyway, and this solves several annoyances.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mountprog.h was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mountprog.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:25 +0000
 1.4 25-May-2023  kre pathadj() is required to succeed. If it cannot, simply issuing a
warning and continuing is not good enough. Change the warning to
an error (and hence immediate exit) instead, that's all we can do.

Problem pointed out by tlaronde@polynum.com

XXX - pullup -10 (others?)
 1.3 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.2 17-Feb-2011  pooka "when in doubt, let the kernel decide"
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4; 1.1.20;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.20.1 05-Mar-2011  bouyer Sync with HEAD
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file pathadj.c was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file pathadj.c was added on branch wrstuden-revivesa on 2008-09-18 04:28:26 +0000
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.6 26-Jun-2005  christos branches: 1.6.20; 1.6.24;
Don't abuse writing to const strings. We can pass const strings to this,
and we write to them. Allocate memory instead.
 1.5 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.3 01-Nov-2000  enami Factor out some function declarations into a header file.
 1.2 16-Sep-1997  lukem resolve conflicts from lite-2 import, with two major modifications
that require all of /sbin/mount_* and /sbin/umount to be modified:
* incorporate vfslist.c, adding checkvfsname() and makevfslist()
* getmntopts() now takes 4 args (adding int *altflagp)
 1.1 16-Sep-1997  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 16-Sep-1997  lukem imported from lite-2
 1.6.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.5 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.4 26-Jun-2005  christos branches: 1.4.20; 1.4.24;
Don't abuse writing to const strings. We can pass const strings to this,
and we write to them. Allocate memory instead.
 1.3 21-Apr-2004  christos un-__P
 1.2 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.1 01-Nov-2000  enami Factor out some function declarations into a header file.
 1.4.24.1 07-Sep-2008  wrstuden Delete a bunch of things that are now gone in head.
 1.4.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.14 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.13 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.12 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.11 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.10 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.9 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.8 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.7 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.6 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.5 06-May-1997  gwr Use .PATH.c: ...
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 18-Jan-1995  mycroft Clone from mount_msdos.
 1.2 22-Dec-1994  cgd specify man pages the new way.
 1.1 03-Jun-1994  chopps basically mount_msdos for now.
 1.19 30-Jul-2007  rumble branches: 1.19.18;
Rescue the subjunctive.
 1.18 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.17 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.16 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.15 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.14 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.13 16-Nov-2001  wiz Whitespace nits
 1.12 05-Jun-2001  wiz Drop arguments of .Os.
 1.11 25-Feb-2001  is error code formatting
 1.10 25-Feb-2001  is Note that the ados fs is read-only, and that mount_ados falls back to
read-only mounts now.
 1.9 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.8 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.7 06-Apr-1999  pk branches: 1.7.6;
1, 2, 3 and.. 4!
 1.6 07-Mar-1999  mycroft branches: 1.6.2;
Clean up SYNOPSIS formatting.
 1.5 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.4 15-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* correct use of .Nm
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 18-Jan-1995  mycroft Clone from mount_msdos.
 1.1 03-Jun-1994  chopps basically mount_msdos for now.
 1.6.2.1 07-Apr-1999  pk Pull up from trunk: copyright text warts.
 1.7.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.18.2 30-Jul-2007  rumble Rescue the subjunctive.
 1.19.18.1 30-Jul-2007  rumble file mount_ados.8 was added on branch matt-mips64 on 2007-07-30 05:00:56 +0000
 1.30 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.29 29-Aug-2011  joerg Use __dead
 1.28 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.27 16-Jul-2007  pooka branches: 1.27.12; 1.27.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.26 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.25 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.24 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.23 16-Oct-2006  christos use MOPT_NULL
 1.22 16-Oct-2006  christos c99 initializer
 1.21 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.20 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.19 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.18 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.17 03-May-2003  christos print masks and modes in octal.
 1.16 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.15 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.14 21-Sep-2002  christos MNT_GETARGS support
 1.13 22-Feb-2001  is Silently fall back to read-only mounting, when we get EROFS.
We do not want to enforce read-only mounting (like mount_iso does)
because we want to write adosfs writing code eventually.
 1.12 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.11 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.10 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.9 25-Jun-1999  perseant branches: 1.9.6;
Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.8 01-Mar-1998  fvdl branches: 1.8.2;
Merge with Lite2 + local changes
 1.7 16-Sep-1997  lukem update for new getmntopts() brought in from lite-2 merge
 1.6 15-Sep-1997  lukem * cleanup for WARNS=1
* getopt returns -1 not EOF
* correct use of .Nm
 1.5 13-Apr-1996  jtc Add const qualifier to mopts table
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 18-Jan-1995  mycroft Clone from mount_msdos.
 1.2 30-Jul-1994  chopps conditional floppy version remove uid/gid/mode options shrinks by ~70k
 1.1 03-Jun-1994  chopps branches: 1.1.2;
basically mount_msdos for now.
 1.1.2.1 03-Aug-1994  cgd from trunk.
 1.8.2.1 05-Sep-1999  he Pull up revision 1.9:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.9.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.27.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.27.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.3 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.2 22-Jan-2018  kamil Add mount_autofs(8) from DragonFly BSD
 1.1 14-Jan-2018  christos Add mount_autofs
 1.8 20-Nov-2019  wiz Sort options and SEE ALSO. Improve a sentence.
 1.7 20-Nov-2019  tkusumi mount_autofs: Sync man page with DragonFlyBSD

Taken-from: DragonFlyBSD
 1.6 24-Jan-2018  uwe branches: 1.6.4;
It's not literal "-options" so use .Ar
 1.5 23-Jan-2018  wiz Improve description of options. Based on comments by Tomohiro Kusumi.
 1.4 22-Jan-2018  wiz Sync usage with man page.
 1.3 22-Jan-2018  wiz Add RCS Id, simplify wording, sort.

The option arguments need to be properly described.
 1.2 22-Jan-2018  kamil Improve the mount_autofs(8) stub documentation

Improve DESCRIPTION and NAME.
 1.1 22-Jan-2018  kamil Add mount_autofs(8) from DragonFly BSD
 1.6.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.4 20-Nov-2019  tkusumi mount_autofs: Remove blank line with trailing whitespace
 1.3 23-Jan-2018  wiz branches: 1.3.4;
Fix typos.

XXX: does not compile for me because of constness issues
 1.2 22-Jan-2018  wiz Sync usage with man page.
 1.1 14-Jan-2018  christos Add mount_autofs
 1.3.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2 23-Jan-2018  wiz Fix typos.

XXX: does not compile for me because of constness issues
 1.1 14-Jan-2018  christos Add mount_autofs
 1.13 02-Feb-2024  christos PR/57897: Ricardo Branco: Add support for mount options mask,dirmask,uid,gid
 1.12 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.11 27-Jun-2005  christos branches: 1.11.20; 1.11.24;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.10 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.9 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.8 21-Sep-2002  christos MNT_GETARGS support
 1.7 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.6 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.5 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.4 06-May-1997  gwr Use .PATH.c: ...
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 22-Dec-1994  cgd specify man pages the new way.
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.11.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.33 03-Feb-2024  wiz Sort options in man page.
 1.32 02-Feb-2024  christos PR/57897: Ricardo Branco: Add support for mount options mask,dirmask,uid,gid
 1.31 30-Jun-2018  sevan vnconfig name is retained for backwards compatibility. Use vndconfig.

Heads up by <tsutsui>
 1.30 29-Jun-2018  sevan Note vnconfig(8) may be of interest, especially when looking to mount an iso via
loopback.
 1.29 07-Jun-2017  abhinav branches: 1.29.4; 1.29.6;
s/filesystem/file system/
 1.28 03-Jan-2009  christos document nocasetrans.
 1.27 02-May-2008  martin Move TNF licenses to 2 clause form
 1.26 27-Dec-2005  reinoud branches: 1.26.20; 1.26.22;
Fix obvious typo in the man page of mount_cd9660:

-The behaviour is cotrollable by the
+The behaviour is controllable by the
 1.25 24-Jun-2005  hubertf it is iso8859, not 8869
 1.24 29-Mar-2005  hubertf Xref mscdlabel(8) - it may be useful. Bump date.
 1.23 31-Jan-2005  erh branches: 1.23.2;
Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.22 22-Nov-2004  wiz New sentence, new line.
 1.21 21-Nov-2004  jdolecek update for UTF-8 encoding of Unicode file names on Joliet filesystems
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.19 18-Apr-2003  wiz This command is not normally executed at boot time.
Closes PR 21225 by Aidan Kehoe.
 1.18 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.17 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.16 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.15 05-Jun-2001  wiz Drop arguments of .Os.
 1.14 09-Jan-2001  augustss Document what can happen with bad Rock Ridge info on the CD.
(Perhaps this can save someone the two hours I spent in the kernel
debugger tracking this down. :)
 1.13 16-Jul-2000  jdolecek note addition of rrcaseins in history
 1.12 15-Jul-2000  jdolecek Add an option to do case-insensitive lookups even on Rock-Ridge CD-ROMS.
Add 'rrcaseins' option to mount_cd9660(8).

This addresses kern/2419 by Jason Downs.
 1.11 15-Jul-2000  jdolecek add extatt, gens, nojoliet, norrip options - names taken from FreeBSD
add nrr as an alias for norrip, for compatibility with Solaris
retire -e, -g, -j, -r: they are still recognized and handled, but are
not listed in mount_cd9660's SYNOPSIS and are documented as
obsolete in mount_cd9660(8)
update history for joliet support and nomaplcase option
 1.10 14-Jun-2000  cgd branches: 1.10.2;
fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.9 27-May-2000  jdolecek Add new mount option nomaplcase (name taken from Solaris) - if set, file
names read from non-Rock Ridge cdroms won't be translated to lower case.
This is functionally similar to -g flag, but the version numbers on files
are still stripped.
 1.8 13-Jul-1999  scw branches: 1.8.6;
From PR-7951 by Joachim Kuebart:

Add support for Microsoft Joliet long filename extensions to the
cd9660 filesystem.
 1.7 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.6 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.5 05-Dec-1997  ws Clarify handling of option -g and names of files without a Rockridge name
on CDs that otherwise do have Rockridge extensions.
The latter should really be handled differently in the code.
 1.4 15-Sep-1997  lukem branches: 1.4.2;
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.3 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.4.2.1 09-Dec-1997  thorpej Sync w/ trunk: better documentation of "-g" option. (ws)
 1.8.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.10.2.3 16-Jul-2000  jdolecek note addition of rrcaseins in history too
 1.10.2.2 16-Jul-2000  jdolecek pullup from trunk (approved by thorpej):
Add an option to do case-insensitive lookups even on Rock-Ridge CD-ROMS.
Add 'rrcaseins' option to mount_cd9660(8).

This addresses kern/2419 by Jason Downs.
 1.10.2.1 15-Jul-2000  jdolecek update from trunk (approved by thorpej):
add extatt, gens, nojoliet, norrip options - names taken from FreeBSD
add nrr as an alias for norrip, for compatibility with Solaris
retire -e, -g, -j, -r: they are still recognized and handled, but are
not listed in mount_cd9660's SYNOPSIS and are documented as
obsolete in mount_cd9660(8)
update history for joliet support and nomaplcase option
 1.23.2.1 30-Jul-2005  tron Pull up revision 1.25 (requested by hubertf in ticket #620):
it is iso8859, not 8869
 1.26.22.1 18-May-2008  yamt sync with head.
 1.26.20.2 17-Jan-2009  mjf Sync with HEAD.
 1.26.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.29.6.1 10-Jun-2019  christos Sync with HEAD
 1.29.4.1 28-Jul-2018  pgoyette Sync with HEAD
 1.35 03-Feb-2024  wiz sync usage with man page
 1.34 02-Feb-2024  christos PR/57897: Ricardo Branco: Add support for mount options mask,dirmask,uid,gid
 1.33 16-Oct-2022  rillig mount_cd9660: remove unhandled option -i from getopt

Found by lint. While here, fix the other lint warning as well, as lint
still doesn't know that exit(3) doesn't return normally.
 1.32 29-Aug-2011  joerg Use __dead
 1.31 07-Oct-2009  pooka fspec: dev -> canon_dev
 1.30 03-Jan-2009  christos when using getargs, don't set read-only otherwise it fails with EINVAL.
 1.29 03-Jan-2009  christos reset args. Add casetrans
 1.28 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.27 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.26 16-Jul-2007  pooka branches: 1.26.12; 1.26.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.25 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.24 16-Oct-2006  christos use MOPT_NULL
 1.23 16-Oct-2006  christos c99 initializer
 1.22 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.21 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.20 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.19 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.18 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.17 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.16 06-Jan-2003  wiz writable, not writeable.
 1.15 21-Sep-2002  christos MNT_GETARGS support
 1.14 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.13 15-Jul-2000  jdolecek Add an option to do case-insensitive lookups even on Rock-Ridge CD-ROMS.
Add 'rrcaseins' option to mount_cd9660(8).

This addresses kern/2419 by Jason Downs.
 1.12 15-Jul-2000  jdolecek add extatt, gens, nojoliet, norrip options - names taken from FreeBSD
add nrr as an alias for norrip, for compatibility with Solaris
retire -e, -g, -j, -r: they are still recognized and handled, but are
not listed in mount_cd9660's SYNOPSIS and are documented as
obsolete in mount_cd9660(8)
update history for joliet support and nomaplcase option
 1.11 27-May-2000  jdolecek branches: 1.11.2;
Add new mount option nomaplcase (name taken from Solaris) - if set, file
names read from non-Rock Ridge cdroms won't be translated to lower case.
This is functionally similar to -g flag, but the version numbers on files
are still stripped.
 1.10 21-Nov-1999  mjl branches: 1.10.2;
Make usage message match actual options.
 1.9 13-Jul-1999  scw branches: 1.9.4;
From PR-7951 by Joachim Kuebart:

Add support for Microsoft Joliet long filename extensions to the
cd9660 filesystem.
 1.8 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.7 28-May-1999  mjl Remove non-existant option -t from usage.
 1.6 01-Mar-1998  fvdl branches: 1.6.2;
Merge with Lite2 + local changes
 1.5 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.4 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.3 13-Apr-1996  jtc Add const qualifier to mopts table
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.6.2.1 05-Sep-1999  he Pull up revision 1.8:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.9.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.10.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.11.2.2 16-Jul-2000  jdolecek pullup from trunk (approved by thorpej):
Add an option to do case-insensitive lookups even on Rock-Ridge CD-ROMS.
Add 'rrcaseins' option to mount_cd9660(8).

This addresses kern/2419 by Jason Downs.
 1.11.2.1 15-Jul-2000  jdolecek update from trunk (approved by thorpej):
add extatt, gens, nojoliet, norrip options - names taken from FreeBSD
add nrr as an alias for norrip, for compatibility with Solaris
retire -e, -g, -j, -r: they are still recognized and handled, but are
not listed in mount_cd9660's SYNOPSIS and are documented as
obsolete in mount_cd9660(8)
update history for joliet support and nomaplcase option
 1.26.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.26.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.26.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_cd9660.h was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_cd9660.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:26 +0000
 1.2 11-Aug-2013  dholland These pass WARNS=5, so don't set WARNS=4
 1.1 24-Nov-2011  ahoka branches: 1.1.4; 1.1.8;
Import mount_chfs for CHFS.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 24-Nov-2011  yamt file Makefile was added on branch yamt-pagecache on 2012-04-17 00:05:41 +0000
 1.5 07-Jun-2021  dholland Teach mount_chfs to understand -o. From Andrius V.
 1.4 12-Sep-2016  sevan Document the version mount_chfs appeared.
Add An macro to AUTHORS section.
Bump date.
 1.3 29-Nov-2011  ahoka branches: 1.3.4;
add known bugs
fix license (copypaste)
 1.2 24-Nov-2011  wiz Add RCS Id, sort sections, sort SEE ALSO, use more markup.

XXX: is the license correct? it is for jmmv.
 1.1 24-Nov-2011  ahoka Import mount_chfs for CHFS.
 1.3.4.2 17-Apr-2012  yamt sync with head
 1.3.4.1 29-Nov-2011  yamt file mount_chfs.8 was added on branch yamt-pagecache on 2012-04-17 00:05:41 +0000
 1.5 16-Jul-2021  andvar Remove commented code, including empty if block. Replace tab with whitespace in usage declaration.
 1.4 07-Jun-2021  dholland Teach mount_chfs to understand -o. From Andrius V.
 1.3 04-Jun-2021  riastradh mount_chfs(8): Remove some vestiges of chewiefs name.

Add RCS id while here and nix some needless whitespace.

No functional change intended.

Patch from Andrius V.
 1.2 13-Sep-2013  joerg branches: 1.2.34;
GC mopts.
 1.1 24-Nov-2011  ahoka branches: 1.1.4; 1.1.8;
Import mount_chfs for CHFS.
 1.1.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 24-Nov-2011  yamt file mount_chfs.c was added on branch yamt-pagecache on 2012-04-17 00:05:41 +0000
 1.2.34.1 06-Jun-2021  cjep sync with head
 1.2 04-Jun-2021  riastradh mount_chfs(8): Remove some vestiges of chewiefs name.

Add RCS id while here and nix some needless whitespace.

No functional change intended.

Patch from Andrius V.
 1.1 24-Nov-2011  ahoka branches: 1.1.4; 1.1.50;
Import mount_chfs for CHFS.
 1.1.50.1 06-Jun-2021  cjep sync with head
 1.1.4.2 17-Apr-2012  yamt sync with head
 1.1.4.1 24-Nov-2011  yamt file mount_chfs.h was added on branch yamt-pagecache on 2012-04-17 00:05:41 +0000
 1.2 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1 29-Jun-2007  rumble branches: 1.1.12; 1.1.16;
Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.1.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.4 29-May-2013  wiz De-capitalize `.Nd' macro argument.

From Bug Hunting.
 1.3 05-Jan-2009  pooka branches: 1.3.8; 1.3.14;
EFS -> SGI EFS in NAME
 1.2 30-Jun-2007  rumble branches: 1.2.12;
Make mount_efs.8 and svhlabel.8 reference one another.
 1.1 29-Jun-2007  rumble Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.2.12.1 17-Jan-2009  mjf Sync with HEAD.
 1.3.14.1 23-Jun-2013  tls resync from head
 1.3.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 03-Nov-2024  rillig sbin, usr.bin, usr.sbin: remove redundant getopt declarations

No binary change, except for assertion line numbers in tprof.
 1.5 29-Aug-2011  joerg branches: 1.5.54;
Use __dead
 1.4 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.3 16-Jul-2007  pooka branches: 1.3.12; 1.3.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.2 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.1 29-Jun-2007  rumble Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.3.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.5.54.1 02-Aug-2025  perseant Sync with HEAD
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_efs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_efs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:26 +0000
 1.8 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.7 27-Jun-2005  christos branches: 1.7.20; 1.7.24;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.6 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.5 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.4 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.3 09-Jan-1998  perry RCS Id Police.
 1.2 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.7.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.7.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.16 29-May-2013  wiz De-capitalize `.Nd' macro argument.

From Bug Hunting.
 1.15 22-Feb-2010  tsutsui branches: 1.15.6; 1.15.12;
32 bit UID and GID support on ext2fs has been added since 5.0
so remove description about the limitations from BUGS section.
 1.14 21-Feb-2010  wiz Call the file system "ext2" consistently. Suggested by tsutsui.
 1.13 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.10 16-Nov-2001  wiz Sort sections.
 1.9 16-Nov-2001  wiz Whitespace nits
 1.8 05-Jun-2001  wiz Drop arguments of .Os.
 1.7 28-Jan-2000  bouyer Updates for ext2fs revision 1.
 1.6 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.5 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.4 15-Sep-1997  lukem * cleanup WARNS=1
* getopt returns -1 not EOF
* use .Nm correctly
 1.3 09-Jul-1997  mikel fix typos and other nits
 1.2 12-Jun-1997  bouyer Add a BUGS section, and xref options(4).
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.15.12.1 23-Jun-2013  tls resync from head
 1.15.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.23 21-Feb-2016  christos Add MOPT_{REL,NO}ATIME as supported by the underlying filesystems.
 1.22 29-Aug-2011  joerg Use __dead
 1.21 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.20 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.19 16-Jul-2007  pooka branches: 1.19.12; 1.19.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.18 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.17 16-Oct-2006  christos use MOPT_NULL
 1.16 16-Oct-2006  christos c99 initializer
 1.15 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.14 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.13 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.12 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.9 21-Sep-2002  christos MNT_GETARGS support
 1.8 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.7 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.6 02-Dec-1998  kenh Do this for ext2fs as well, because Manuel said so.
 1.5 26-Jul-1998  mycroft const poisoning.
 1.4 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.3 16-Sep-1997  lukem apply mods from lite-2 vers. of mount/mount_ufs.c (which this is derived from)
 1.2 15-Sep-1997  lukem * cleanup WARNS=1
* getopt returns -1 not EOF
* use .Nm correctly
 1.1 11-Jun-1997  bouyer Add support programs for ext2fs. fsck_ext2fs is derived from fsck_ffs.
 1.19.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_ext2fs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_ext2fs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:26 +0000
 1.14 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.13 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.12 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.11 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.10 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.9 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.8 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.7 06-May-1997  gwr Use .PATH.c: ...
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Dec-1994  cgd specify man pages the new way.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 12-Jan-1994  cgd update from jsp
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 28-Mar-1993  cgd branches: 1.1.1; 1.1.2;
merged version of mount_fdesc and mount_kernfs
 1.1.2.2 20-Jul-1993  cgd break mount_miscfs into mount_kernfs and mount_fdesc
 1.1.2.1 19-Jul-1993  cgd add man pages for mount_fdesc and mount_kernfs.
after things settle down, i've decided that these should be broken
out into their component programs again; combining them was a mistake...
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.16 30-Dec-2013  dholland Add crossreference to fd(4) as noted a while back in PR 45694. Bump date.
 1.15 31-Jan-2005  erh branches: 1.15.50; 1.15.56;
Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.13 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.12 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.11 16-Nov-2001  wiz Whitespace nits
 1.10 05-Jun-2001  wiz Drop arguments of .Os.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.7 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.6 17-Dec-1995  ghudson fdescfs now provides . and .. entries, so remove the comment about
them not being there.
 1.5 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.2 12-Jan-1994  cgd update from jsp
 1.1 19-Jul-1993  cgd branches: 1.1.1; 1.1.2;
add man pages for mount_fdesc and mount_kernfs.
after things settle down, i've decided that these should be broken
out into their component programs again; combining them was a mistake...
 1.1.2.2 19-Jul-1993  cgd add man pages for mount_fdesc and mount_kernfs.
after things settle down, i've decided that these should be broken
out into their component programs again; combining them was a mistake...
 1.1.2.1 19-Jul-1993  cgd file mount_fdesc.8 was added on branch netbsd-0-9 on 1993-07-19 23:49:28 +0000
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.15.56.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.50.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.27 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.26 29-Aug-2011  joerg Use __dead
 1.25 31-Mar-2010  pooka initialize canon_dev
 1.24 31-Jul-2009  pooka convert to parseargs form
 1.23 31-Jul-2009  pooka Shortcircuit -o getargs in userspace. We know the kernel driver
will not return any data and mount(2) fails with EINVAL if data_len
is 0. This caused lame-o output in mount -vv:
mount_fdesc: fdesc on /failsystem: Invalid argument
 1.22 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.21 16-Jul-2007  pooka branches: 1.21.12; 1.21.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.20 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.19 16-Oct-2006  christos use MOPT_NULL
 1.18 16-Oct-2006  christos c99 initializer
 1.17 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.16 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.15 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.13 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.12 21-Sep-2002  christos MNT_GETARGS support
 1.11 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.10 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.9 16-Sep-1997  lukem branches: 1.9.4;
resolve conflicts from lite-2 merge
 1.8 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.7 13-Apr-1996  jtc Add const qualifier to mopts table
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 12-Jan-1994  cgd update from jsp
 1.3 24-Aug-1993  pk Initialized `mntflags'.
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 28-Mar-1993  cgd branches: 1.1.1; 1.1.2;
merged version of mount_fdesc and mount_kernfs
 1.1.2.1 20-Jul-1993  cgd break mount_miscfs into mount_kernfs and mount_fdesc
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.9.4.1 05-Sep-1999  he Pull up revision 1.10:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.21.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 31-Jul-2009  pooka convert to parseargs form
 1.10 10-Apr-2011  joerg Extend CPPFLAGS, don't replace it
 1.9 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.8 27-Jun-2005  christos branches: 1.8.20; 1.8.24;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.7 05-Feb-2005  xtraeme ll __P(), use ANSI function declarations; WARNS=3.
 1.6 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.5 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.4 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.3 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.2 06-May-1997  gwr Use .PATH.c: ...
 1.1 12-Jul-1995  cgd split FFS mount code out of mount(8). the correct way to name fast file
systems is now 'ffs', though 'ufs' is tolerated in fstab for backward
compatibility.
 1.8.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.13 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.10 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.9 16-Nov-2001  wiz Sort sections.
 1.8 05-Jun-2001  wiz Drop arguments of .Os.
 1.7 05-Mar-2001  aymeric Move reference to article on soft-updates from tunefs.8 to mount_ffs.8
OK'd by Ignatios.
 1.6 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.5 24-Nov-1997  lukem fix .Nx usage (use 1.0 instead of 0.9a, etc), and other minor cleanups
 1.4 15-Oct-1997  fvdl .Nm " " -> .Nm mount_ufs, the old name should be specifically mentioned
here.
 1.3 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.2 05-Feb-1996  jtc Removed extraneous text; From Mike Long <mike.long@analog.com>
 1.1 12-Jul-1995  cgd split FFS mount code out of mount(8). the correct way to name fast file
systems is now 'ffs', though 'ufs' is tolerated in fstab for backward
compatibility.
 1.30 18-Sep-2021  christos Change the default for ACLs to be posix1e instead of nfsv4 to match FreeBSD.
Requested by chuq.
 1.29 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.28 19-Oct-2012  drochner Implement experimental support to pass notifications that a file
was deleted from the filesystem to the disk driver, commonly
known as "discard" or "trim".
fs/driver support is in ffs and ata wd for now.
This is what was posted here:
http://mail-index.netbsd.org/tech-kern/2012/02/28/msg012813.html
with minor cleanup, and the global switch replaced by a mount option.
 1.27 29-Aug-2011  joerg branches: 1.27.2; 1.27.8;
Use __dead
 1.26 17-Jun-2011  manu Add mount -o extattr option to enable extended attributs (corrently only
for UFS1).
Remove kernel option for EA backing store autocreation and do it by
default. Add a sysctl so that autocreated attriutr size can be modified.
 1.25 05-Aug-2008  pooka branches: 1.25.10; 1.25.18;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.24 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.23 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.22 16-Jul-2007  pooka branches: 1.22.12; 1.22.16; 1.22.18;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.21 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.20 16-Oct-2006  christos use MOPT_NULL
 1.19 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.18 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.17 05-Feb-2005  xtraeme ll __P(), use ANSI function declarations; WARNS=3.
 1.16 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.13 21-Sep-2002  christos MNT_GETARGS support
 1.12 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.11 15-Jun-2000  fvdl Enable -o softdep.
 1.10 14-Apr-2000  simonb branches: 1.10.2;
Don't declare 'extern opt*' getopt variables.
 1.9 01-Dec-1998  kenh Add support for a new flag: "nodevmtime". This sets the MNT_NODEVMTIME mount
flag.
 1.8 26-Jul-1998  mycroft const poisoning.
 1.7 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.6 16-Sep-1997  lukem apply mods from lite-2 vers. of mount/mount_ufs.c (which this is derived from)
 1.5 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.4 30-Jan-1997  tls add support for noatime mount flag
 1.3 13-Apr-1996  jtc Add const qualifier to mopts table
 1.2 11-Nov-1995  mycroft MOUNT_UFS -> MOUNT_FFS, and remove bogus comment.
 1.1 12-Jul-1995  cgd branches: 1.1.2;
split FFS mount code out of mount(8). the correct way to name fast file
systems is now 'ffs', though 'ufs' is tolerated in fstab for backward
compatibility.
 1.1.2.1 01-Nov-1995  jtc complete ufs -> ffs change (From John Kohl; PR #1403)
 1.10.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.22.18.2 28-Jul-2008  simonb Sync with head.
 1.22.18.1 10-Jun-2008  simonb Initial commit of Wasabi System's WAPBL (Write Ahead Physical Block
Logging) journaling code. Originally written by Darrin B. Jewell
while at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

Still a number of issues - look in doc/BRANCHES for "simonb-wapbl"
for more info.
 1.22.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.22.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.25.18.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.25.10.3 21-Oct-2010  uebayasi After consideration, put back "xip" mount option.

The internal behavior is totally different between with and without
the option; automatic detection and/or fall-through are not user
friendly. mount(8) returning the "xip" flag is also informative.
 1.25.10.2 28-May-2010  uebayasi Remove the "xip" option from mount_ffs(8) for simplicity.
 1.25.10.1 11-Feb-2010  uebayasi Support the "xip" option.
 1.27.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.27.2.1 30-Oct-2012  yamt sync with head
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_ffs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:12 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_ffs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:26 +0000
 1.9 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.8 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.7 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.6 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.5 21-Sep-2002  christos MNT_GETARGS support
 1.4 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.3 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.2 14-Aug-1998  mark Add man page for mount_filecore.
 1.1 14-Aug-1998  mark Initial commit of mount_filecore used for mounting filecorefs partitions.
 1.13 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.12 25-Jun-2004  wiz Sort options; bump date.
 1.11 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.10 02-Jan-2003  wiz Sort sections.
 1.9 01-Jan-2003  jschauma Fix tyops pointed out by Igor Sobrado in PR misc/19623:

mount_filecore(8) - frquently (frequently), upto (up to)
mount_nfs(8) - NFSV3 (NFSv3), automaticly (automatically)
mount_ntfs(8) - particularily (particularly), fisk (disk)
 1.8 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.7 16-Nov-2001  wiz Punctuation nit.
 1.6 05-Jun-2001  wiz Drop arguments of .Os.
 1.5 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.4 06-Apr-1999  pk branches: 1.4.6;
1, 2, 3 and.. 4!
 1.3 07-Mar-1999  mycroft branches: 1.3.2;
Clean up SYNOPSIS formatting.
 1.2 14-Aug-1998  mark Add a description of the origin of filecore and what it is.
 1.1 14-Aug-1998  mark Add man page for mount_filecore.
 1.3.2.1 07-Apr-1999  pk Pull up from trunk: copyright text warts.
 1.4.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.21 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.20 29-Aug-2011  joerg Use __dead
 1.19 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.18 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.17 16-Jul-2007  pooka branches: 1.17.12; 1.17.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.16 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.15 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.14 16-Oct-2006  christos use MOPT_NULL
 1.13 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.12 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.11 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.10 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.9 25-Jun-2004  wiz Sync usage with reality. Closes PR 25915 by Kouichirou Hiratsuka.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.6 06-Jan-2003  wiz writable, not writeable.
 1.5 21-Sep-2002  christos MNT_GETARGS support
 1.4 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.3 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.2 25-Jun-1999  perseant branches: 1.2.6;
Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.1 14-Aug-1998  mark branches: 1.1.2;
Initial commit of mount_filecore used for mounting filecorefs partitions.
 1.1.2.1 05-Sep-1999  he Pull up revision 1.2:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.2.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.17.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.17.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.4 10-Apr-2011  joerg Extend CPPFLAGS, don't replace it
 1.3 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.2 06-Mar-2007  dillo branches: 1.2.12; 1.2.16;
Complete rename of hfsp to hfs, requested by thorpej.
 1.1 06-Mar-2007  dillo branches: 1.1.1;
Initial revision
 1.1.1.1 06-Mar-2007  dillo Initial import of (experimental read-only) implementation of Apple
HFS+ file system.

Originally developed for Google Summer of Code 2005 by Yevgeny Binder,
updated and enhanced by me.
 1.2.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.8 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.7 20-Jul-2013  wiz Use Mt for email addresses.
 1.6 02-May-2008  martin branches: 1.6.20; 1.6.26; 1.6.32;
Move TNF licenses to 2 clause form
 1.5 19-May-2007  wiz branches: 1.5.12; 1.5.14;
Fill in AUTHORS section. Bump date.
 1.4 22-Mar-2007  dillo Bump date for previous.
 1.3 22-Mar-2007  dillo Remove offset argument, no longer needed.
 1.2 06-Mar-2007  dillo Complete rename of hfsp to hfs, requested by thorpej.
 1.1 06-Mar-2007  dillo branches: 1.1.1;
Initial revision
 1.1.1.1 06-Mar-2007  dillo Initial import of (experimental read-only) implementation of Apple
HFS+ file system.

Originally developed for Google Summer of Code 2005 by Yevgeny Binder,
updated and enhanced by me.
 1.5.14.1 18-May-2008  yamt sync with head.
 1.5.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.32.1 23-Jul-2013  riastradh sync with HEAD
 1.6.26.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10 05-Sep-2016  sevan Drop main() prototype.
 1.9 29-Aug-2011  joerg Use __dead
 1.8 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.7 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.6 15-Dec-2007  perry branches: 1.6.4; 1.6.8;
de-__P, ansify prototypes
 1.5 16-Jul-2007  pooka branches: 1.5.4; 1.5.6;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.4 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.3 22-Mar-2007  dillo Remove offset argument, no longer needed.
 1.2 06-Mar-2007  dillo Complete rename of hfsp to hfs, requested by thorpej.
 1.1 06-Mar-2007  dillo branches: 1.1.1;
Initial revision
 1.1.1.1 06-Mar-2007  dillo Initial import of (experimental read-only) implementation of Apple
HFS+ file system.

Originally developed for Google Summer of Code 2005 by Yevgeny Binder,
updated and enhanced by me.
 1.5.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.5.4.1 09-Jan-2008  matt sync with HEAD
 1.6.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_hfs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:13 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_hfs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:27 +0000
 1.14 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.13 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.12 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.11 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.10 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.9 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.8 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.7 06-May-1997  gwr Use .PATH.c: ...
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Dec-1994  cgd specify man pages the new way.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 12-Jan-1994  cgd update from jsp; some bits of man page don't apply and were commented out
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 28-Mar-1993  cgd branches: 1.1.1; 1.1.2;
merged version of mount_fdesc and mount_kernfs
 1.1.2.2 20-Jul-1993  cgd break mount_miscfs into mount_kernfs and mount_fdesc
 1.1.2.1 19-Jul-1993  cgd add man pages for mount_fdesc and mount_kernfs.
after things settle down, i've decided that these should be broken
out into their component programs again; combining them was a mistake...
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.18 22-Mar-2012  wiz Bump date for previous.
 1.17 22-Mar-2012  drochner remove KAME IPSEC, replaced by FAST_IPSEC
 1.16 31-Jan-2005  erh branches: 1.16.50;
Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.15 21-Nov-2004  jmmv Minor grammar improvements.
 1.14 08-Sep-2003  itojun add /kern/ipsecsa and /kern/ipsecsp, which can be inspected by setkey(8).
it allows easier access to ipsecsa/sp. it works around problem where
setkey -D does not work with large number of ipsec SAs due to socket buffer
size.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.12 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.11 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.10 05-Jun-2001  wiz Drop arguments of .Os.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.7 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 25-Jul-1994  mycroft Add `msgbuf'.
 1.4 08-Jun-1994  mycroft branches: 1.4.2;
Update from 4.4-Lite, with local changes.
 1.3 12-Jan-1994  cgd update from jsp; some bits of man page don't apply and were commented out
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 19-Jul-1993  cgd branches: 1.1.1; 1.1.2;
add man pages for mount_fdesc and mount_kernfs.
after things settle down, i've decided that these should be broken
out into their component programs again; combining them was a mistake...
 1.1.2.2 20-Jul-1993  cgd break mount_miscfs into mount_kernfs and mount_fdesc
 1.1.2.1 19-Jul-1993  cgd file mount_kernfs.8 was added on branch netbsd-0-9 on 1993-07-20 02:34:54 +0000
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.4.2.1 26-Jul-1994  cgd from trunk
 1.16.50.1 17-Apr-2012  yamt sync with head
 1.26 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.25 29-Aug-2011  joerg Use __dead
 1.24 31-Mar-2010  pooka convert to parseargs
 1.23 21-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
 1.22 16-Jul-2007  pooka branches: 1.22.12; 1.22.16;
kernfs doesn't support getargs, so fail silently instead of making
a fuss about it.
 1.21 16-Jul-2007  pooka Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.20 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.19 16-Oct-2006  christos use MOPT_NULL
 1.18 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.17 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.16 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.13 21-Sep-2002  christos MNT_GETARGS support
 1.12 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.11 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.10 16-Sep-1997  lukem branches: 1.10.4;
resolve conflicts from lite-2 merge
 1.9 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.8 13-Apr-1996  cgd 'const struct' not 'struct const'
 1.7 13-Apr-1996  jtc Add const qualifier to mopts table
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 12-Jan-1994  cgd update from jsp; some bits of man page don't apply and were commented out
 1.3 24-Aug-1993  pk Initialized `mntflags'.
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 28-Mar-1993  cgd branches: 1.1.1; 1.1.2;
merged version of mount_fdesc and mount_kernfs
 1.1.2.1 20-Jul-1993  cgd break mount_miscfs into mount_kernfs and mount_fdesc
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.10.4.1 05-Sep-1999  he Pull up revision 1.11:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.22.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.22.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 31-Mar-2010  pooka convert to parseargs
 1.9 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.8 22-Mar-2003  jdolecek branches: 1.8.32; 1.8.36;
move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.7 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.6 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.5 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.4 06-May-1997  gwr Use .PATH.c: ...
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 22-Dec-1994  cgd specify man pages the new way.
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.8.36.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.32.1 28-Sep-2008  mjf Sync with HEAD.
 1.15 31-Mar-2005  wiz Add -i to SYNOPSIS.
 1.14 31-Mar-2005  xtraeme Add -i option, it's just the same than -f in lfs_cleanerd(8), ok'ed
thorpej@.
 1.13 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.12 10-Jun-2004  uebayasi Fix SEE ALSO; remove .sp; put .Pp before sentences.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.9 05-Jun-2001  wiz Drop arguments of .Os.
 1.8 08-Nov-2000  hubertf xref dump_lfs(8), newfs_lfs(8) in SEE ALSO
 1.7 09-Sep-2000  perseant Various bug-fixes to LFS, to wit:


Kernel:

* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.

If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.

* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.

* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.

* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().

lfs_cleanerd:

* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.

* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.

* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.

* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).

fsck_lfs:

* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.

newfs_lfs:

* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.

* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).

* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.

mount_lfs:

* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.

* Default to calling lfs_cleanerd with "-b -n 4".


[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
 1.6 07-Mar-1999  mycroft branches: 1.6.10;
Clean up SYNOPSIS formatting.
 1.5 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.4 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.3 29-May-1997  cgd Fix broken uses of Dd. Both the mdoc and mdoc.samples pages agree:
.Dd is supposed to be invoked like:
.Dd month day, year
e.g. ".Dd January 25, 1989", rather than:
.Dd "month day, year"
which is what these pages did.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.6.10.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.39 21-Feb-2016  christos Add MOPT_{REL,NO}ATIME as supported by the underlying filesystems.
 1.38 02-Aug-2015  dholland Use the lfs header file and lfs's mount args struct, not ufsmount.h
and the ffs mount args struct, for mounting lfs.

(they are the same, so this doesn't matter yet, but still...)
 1.37 19-Oct-2013  christos put back oldflags and __USE it.
 1.36 19-Oct-2013  christos remove unused
 1.35 19-Oct-2013  christos fix unused variable warnings.
 1.34 29-Aug-2011  joerg branches: 1.34.2; 1.34.8;
Use __dead
 1.33 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.32 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.31 17-Jul-2007  pooka branches: 1.31.12; 1.31.16;
Don't attempt to start megamaid if run with MNT_GETARGS.
 1.30 16-Jul-2007  pooka Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.29 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.28 16-Oct-2006  christos use MOPT_NULL
 1.27 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.26 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.25 27-Jun-2005  christos constify.
 1.24 31-Mar-2005  xtraeme tabify
 1.23 31-Mar-2005  xtraeme Add -i option, it's just the same than -f in lfs_cleanerd(8), ok'ed
thorpej@.
 1.22 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.21 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.20 06-Jul-2004  wiz Add -b and -N to usage. Use getprogname.
From Kouichirou Hiratsuka in PR 26064.
 1.19 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.18 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.17 13-Jul-2003  itojun asprintf is easier. plug memory leak
 1.16 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.15 18-Feb-2003  jdolecek add 'noatime' to list of supported mount options
fixes PR bin/20411 by KOIE Hidetaka
 1.14 21-Sep-2002  christos MNT_GETARGS support
 1.13 26-Feb-2002  wiz Add -b to getopt argument. Patch from DHOYASHIKI Shinichi in bin/15742.
 1.12 13-Nov-2000  perseant Try to prevent running more than one active cleaner on a filesystem at a time.

Let lfs_cleanerd record its pid in /var/run like other daemons. Make
mount_lfs not start another cleaner when updating the mount, unless it is
being upgraded from read-only to read-write; when downgrading to read-only,
kill the cleaner using the recorded pids.
 1.11 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.10 09-Sep-2000  perseant Various bug-fixes to LFS, to wit:


Kernel:

* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.

If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.

* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.

* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.

* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().

lfs_cleanerd:

* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.

* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.

* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.

* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).

fsck_lfs:

* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.

newfs_lfs:

* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.

* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).

* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.

mount_lfs:

* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.

* Default to calling lfs_cleanerd with "-b -n 4".


[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
 1.9 08-Dec-1999  perseant branches: 1.9.4;
Read-only mounts should not start cleaning processes. Make it so.
 1.8 25-Jun-1999  perseant branches: 1.8.4;
Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.7 01-Mar-1998  fvdl branches: 1.7.2;
Merge with Lite2 + local changes
 1.6 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.5 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.4 13-Apr-1996  cgd 'const struct' not 'struct const'
 1.3 13-Apr-1996  jtc Add const qualifier to mopts table
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.7.2.2 16-Dec-1999  he Pull up revision 1.9 (requested by perseant):
Read-only mounts no longer start useless cleanerd processes.
 1.7.2.1 05-Sep-1999  he Pull up revision 1.8:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.8.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9.4.2 03-Feb-2001  he Pull up revision 1.12 (via patch, requested by perseant):
Don't spawn more cleaners when using "mount -u", unless
upgrading from r/o to r/w; when downgrading, kill the cleaner.
 1.9.4.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.31.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.31.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.34.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.34.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3 02-Aug-2015  dholland Use the lfs header file and lfs's mount args struct, not ufsmount.h
and the ffs mount args struct, for mounting lfs.

(they are the same, so this doesn't matter yet, but still...)
 1.2 06-Aug-2009  pooka remember to add cleaner_main() prototype
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_lfs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:13 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_lfs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:27 +0000
 1.4 11-Nov-2006  jmmv Move lfs_cleanerd from /usr/libexec to /libexec. This is to allow putting
the root file system on a LFS volume.

Addresses PR bin/30407. No objections in tech-userlevel@.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.22 22-Dec-2009  pooka Don't -I from $S/sys.
 1.21 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.20 27-Jun-2005  christos branches: 1.20.20; 1.20.24;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.19 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.18 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.17 21-Sep-2002  christos MNT_GETARGS support
 1.16 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.15 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.14 14-Aug-2000  deberg use CURDIR where appropriate
 1.13 01-Mar-1998  fvdl branches: 1.13.10;
Merge with Lite2 + local changes
 1.12 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.11 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.10 06-May-1997  gwr Use .PATH.c: ...
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 22-Dec-1994  cgd specify man pages the new way.
 1.7 20-Dec-1994  mycroft No longer install setuid root.
 1.6 16-Jul-1994  cgd branches: 1.6.2;
update from ws. make it work again
 1.5 08-Apr-1994  cgd new functionality -- uid/gid/perms settable, users can invoke
 1.4 07-Apr-1994  cgd clean up, zero args struct so we're ok for changes coming soon...
 1.3 09-Aug-1993  mycroft PCFS --> MSDOSFS
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 09-Apr-1993  cgd branches: 1.1.2;
written by Paul Popelka. mounts pcfs MS-DOS filesystem. (patch 111)
 1.1.2.3 15-Aug-1993  cgd define MSDOSFS not PCFS
 1.1.2.2 20-Jul-1993  cgd source file is mount_msdos.c now...
 1.1.2.1 20-Jul-1993  cgd change name to mount_msdos, and add man page. need some more hacking
later to change everything to mount_msdos, i.e. files need to be
moved in the tree, but that can wait.
 1.6.2.2 16-Jul-1994  cgd update from ws. make it work again
 1.6.2.1 16-Jul-1994  cgd file Makefile was added on branch netbsd-1-0 on 1994-07-16 21:32:07 +0000
 1.13.10.1 14-Aug-2000  deberg pullup 1.14, approved by thorpej

use CURDIR where appropriate
 1.20.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.20.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.41 12-Feb-2020  leot Fix a thinko

Reported by qjsgkem via #netbsd-code, thanks!
 1.40 11-Oct-2016  sevan branches: 1.40.14;
Whilst mount_pcfs originated as a patch in 386BSD, NetBSD 0.8 actually was the first release of an OS to ship with it.
Heads up by Ingo Schwarze.
 1.39 12-Sep-2016  sevan - mount_pcfs appeared in 386BSD
https://groups.google.com/forum/#!search/mount_pcfs.c/comp.unix.bsd/9qhH0v1tZm0/inlPnXZj_2sJ
- Edit history to note name change version & rewrite.
- Add authors section.
- s/filesystem/file systems
- Bump date.
 1.38 30-Jan-2016  wiz branches: 1.38.2;
New sentence, new line. Bump date.
 1.37 30-Jan-2016  mlelstv Add support to msdosfs and makefs to generate correct Unicode (UCS-2) directory
entries from UTF8 encoded file names.
 1.36 16-Nov-2012  tsutsui Note mount_msdos -G option also allows mounting X680x0's Human68k floppies.
 1.35 27-Sep-2012  riz Remove the bit about empty DOS file systems assumed to have short names
by default; jmcneill changed this back in Jan 2009, but missed this
text.
 1.34 15-Sep-2011  wiz branches: 1.34.2; 1.34.4; 1.34.8; 1.34.10;
Consistently spell MS-DOS with a hyphen. From Snader_LB.
 1.33 24-Jan-2009  wiz New sentence, new line.
 1.32 23-Jan-2009  jmcneill Note that empty filesystems are now treated as if they support long
filenames by default.
 1.31 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.30 08-Sep-2003  wiz Sort options.
 1.29 08-Sep-2003  wiz Bump date for previous.
 1.28 07-Sep-2003  itojun add -t option for gmt time offset (normally MS-DOS filesystem has timestamp
in localtime, not GMT). PR kern/22717
 1.27 02-Aug-2003  jdolecek bump date for last
 1.26 02-Aug-2003  jdolecek Allow separate masks for files and directories. Useful e.g. to turn
the execute bit off for files, but keep search permission for directories.
Change contributed in PR kern/21538 by Pavel Arnost, based on some FreeBSD
patches.
Further manpage changes, and backward-compatibility adjustments done by me.

Also fixes PR kern/16778 by Johan Danielsson, and PR kern/3400 by Rick Byers
 1.25 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.24 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.23 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.22 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.21 16-Nov-2001  wiz Whitespace nits
 1.20 05-Jun-2001  wiz Drop arguments of .Os.
 1.19 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.18 28-Aug-2000  hubertf Document the FAT types we support, and add a bugs section (suggested
by ws@netbsd.org).
 1.17 14-Jun-2000  cgd branches: 1.17.2;
sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.16 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.15 06-Apr-1999  pk branches: 1.15.6;
1, 2, 3 and.. 4!
 1.14 07-Mar-1999  mycroft branches: 1.14.2;
Clean up SYNOPSIS formatting.
 1.13 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.12 17-Oct-1997  ws Drop indication of support for access times (they are no longer maintained)
 1.11 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.10 19-Jan-1996  leo Add '-G' flag for mounting Atari-Gemdos filesystems.
 1.9 29-Nov-1995  ws - Add support for Win'95 separate creation/modification/access timestamps
- Re-introduce lowercase filenames for non-Win'95-filesystems
 1.8 15-Oct-1995  ws Add support for Win'95 long filenames
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 18-Jan-1995  mycroft Document the `-o' option. Remove the last vestige of the `-F' option.
 1.5 16-Jul-1994  cgd branches: 1.5.2;
update from ws. make it work again
 1.4 08-Apr-1994  cgd new functionality -- uid/gid/perms settable, users can invoke
 1.3 29-Jan-1994  jtc Fix spelling error in Copyright notice
 1.2 30-Jul-1993  mycroft Merge changes from netbsd-0-9 branch.
 1.1 20-Jul-1993  cgd branches: 1.1.2;
change name to mount_msdos, and add man page. need some more hacking
later to change everything to mount_msdos, i.e. files need to be
moved in the tree, but that can wait.
 1.1.2.2 20-Jul-1993  cgd change phrasing of compatibility CAVEAT thang.
 1.1.2.1 20-Jul-1993  cgd file mount_msdos.8 was added on branch netbsd-0-9 on 1993-07-20 01:41:12 +0000
 1.5.2.2 16-Jul-1994  cgd update from ws. make it work again
 1.5.2.1 16-Jul-1994  cgd file mount_msdos.8 was added on branch netbsd-1-0 on 1994-07-16 21:32:08 +0000
 1.14.2.1 07-Apr-1999  pk Pull up from trunk: copyright text warts.
 1.15.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.17.2.1 29-Aug-2000  hubertf Pull up rev. 1.18 to netbsd-1-5 branch, OK'd by thorpej:
> Document the FAT types we support, and add a bugs section (suggested
> by ws@netbsd.org).
 1.34.10.1 24-Nov-2012  jdc Pull up revisions:
src/sbin/mount_msdos/mount_msdos.8 revisions 1.35,1.36
(requested by tsutsui in ticket #711).

Remove the bit about empty DOS file systems assumed to have short names
by default; jmcneill changed this back in Jan 2009, but missed this
text.

Note mount_msdos -G option also allows mounting X680x0's Human68k floppies.
 1.34.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.34.4.1 24-Nov-2012  jdc Pull up revisions:
src/sbin/mount_msdos/mount_msdos.8 revisions 1.35,1.36
(requested by tsutsui in ticket #711).

Remove the bit about empty DOS file systems assumed to have short names
by default; jmcneill changed this back in Jan 2009, but missed this
text.

Note mount_msdos -G option also allows mounting X680x0's Human68k floppies.
 1.34.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.34.2.1 30-Oct-2012  yamt sync with head
 1.38.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.40.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.50 21-Aug-2016  jdolecek report also gmtoff in the output of mount options
 1.49 06-Feb-2016  mlelstv fix usage message
 1.48 30-Jan-2016  mlelstv Add support to msdosfs and makefs to generate correct Unicode (UCS-2) directory
entries from UTF8 encoded file names.
 1.47 07-Oct-2009  pooka Mount from canon_dev instead of dev.
 1.46 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.45 29-Jul-2008  pooka Split option parsing into its own routine so that it can be used
by other consumers as well.
 1.44 15-Dec-2007  perry branches: 1.44.4; 1.44.8;
convert __attribute__s to applicable cdefs.h macros
 1.43 16-Jul-2007  pooka branches: 1.43.4; 1.43.6;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.42 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.41 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.40 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.39 16-Oct-2006  christos use MOPT_NULL
 1.38 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.37 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.36 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.35 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.34 05-Jan-2004  jmmv Remove extra newline from usage message.
 1.33 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.32 08-Sep-2003  wiz Sync usage with man page.
 1.31 07-Sep-2003  itojun add -t option for gmt time offset (normally MS-DOS filesystem has timestamp
in localtime, not GMT). PR kern/22717
 1.30 02-Aug-2003  jdolecek actually enable MNT_GETARGS support
 1.29 02-Aug-2003  jdolecek Allow separate masks for files and directories. Useful e.g. to turn
the execute bit off for files, but keep search permission for directories.
Change contributed in PR kern/21538 by Pavel Arnost, based on some FreeBSD
patches.
Further manpage changes, and backward-compatibility adjustments done by me.

Also fixes PR kern/16778 by Johan Danielsson, and PR kern/3400 by Rick Byers
 1.28 03-May-2003  christos print masks and modes in octal.
 1.27 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.26 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.25 21-Sep-2002  christos MNT_GETARGS support
 1.24 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.23 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.22 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.21 27-Mar-2000  jdolecek branches: 1.21.2;
allow options 'sync' and 'async'
 1.20 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.19 01-Mar-1998  fvdl branches: 1.19.2;
Merge with Lite2 + local changes
 1.18 16-Sep-1997  lukem update for new getmntopts() brought in from lite-2 merge
 1.17 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.16 24-Oct-1996  cgd Fix typo in last commit
 1.15 23-Oct-1996  cgd this file system (according to its source) supports MNT_UPDATE. Therefore
the mount program must recognize the 'update' option.
 1.14 13-Apr-1996  cgd 'const struct' not 'struct const'
 1.13 13-Apr-1996  jtc Add const qualifier to mopts table
 1.12 19-Jan-1996  leo Add '-G' flag for mounting Atari-Gemdos filesystems.
 1.11 15-Oct-1995  ws Add support for Win'95 long filenames
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 18-Jan-1995  mycroft Document the `-o' option. Remove the last vestige of the `-F' option.
 1.8 16-Jul-1994  cgd branches: 1.8.2;
update from ws. make it work again
 1.7 08-Apr-1994  cgd kill relative paths
 1.6 08-Apr-1994  cgd new functionality -- uid/gid/perms settable, users can invoke
 1.5 07-Apr-1994  cgd clean up, zero args struct so we're ok for changes coming soon...
 1.4 07-Sep-1993  ws Changes to VFS readdir semantics
NFS changes for better cookie support
ISOFS changes for better Rockridge support and support for generation numbers
 1.3 14-Aug-1993  mycroft pcfs_args --> msdosfs_args
 1.2 02-Aug-1993  mycroft Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1 09-Apr-1993  cgd written by Paul Popelka. mounts pcfs MS-DOS filesystem. (patch 111)
 1.8.2.2 16-Jul-1994  cgd update from ws. make it work again
 1.8.2.1 16-Jul-1994  cgd file mount_msdos.c was added on branch netbsd-1-0 on 1994-07-16 21:32:09 +0000
 1.19.2.1 05-Sep-1999  he Pull up revision 1.20:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.21.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.43.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.43.4.1 09-Jan-2008  matt sync with HEAD
 1.44.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.44.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 29-Jul-2008  pooka branches: 1.1.2; 1.1.4;
Split option parsing into its own routine so that it can be used
by other consumers as well.
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 29-Jul-2008  mjf file mount_msdos.h was added on branch mjf-devfs2 on 2008-09-28 11:17:13 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 29-Jul-2008  wrstuden file mount_msdos.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:27 +0000
 1.24 10-Apr-2011  joerg Extend CPPFLAGS, don't replace it
 1.23 05-Mar-2010  pooka Remove no longer used -DNFS.
 1.22 16-Oct-2008  pooka Convert mount_nfs to the mount_foo_parseargs() format. No functional
change.
 1.21 28-May-2007  tls branches: 1.21.12;
Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.20 23-Mar-2006  wiz Remove Kerberos4/NFSKERB settings.
 1.19 21-Jan-2006  yamt whitespace.
 1.18 21-Jan-2006  dsl Use the rpc code from sys/lib/libsa to determine the root file handle.
Saves the code from depending on the xdr functions.
Tested on i386 and IPv4, may need tweaking for IPv6 and using TCP for the
portmap/mount functions.
 1.17 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.16 15-May-2005  dsl Split getnfsargs() out into its own file, it drags in 70kB of rpc code.
I might manage to write a version that doesn't pull in all the crud.
(Which will give a load of space in the install floppy images)
 1.15 10-Jan-2005  lukem Only compile in IPv6 support if ${USE_INET6} != "no"

MKINET6 is for providing IPv6 infrastructure.
USE_INET6 is for compiling IPv6 support into the programs (needs MKINET6).
 1.14 11-Apr-2003  christos PR/1472: David Carrel: Add option to specify the nfs port.
This was not done, I added the functionality to be able to parse
port=num in the options. While I was there, I added this for all
the other numeric options: rsize, wsize etc.
 1.13 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.12 21-Sep-2002  christos MNT_GETARGS support
 1.11 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.10 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.9 16-Sep-1997  lukem back to using mount/getmntopts.c since mount is now post lite-2
 1.8 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.7 06-May-1997  gwr Use .PATH.c: ...
 1.6 09-Jan-1997  tls it's a shame, but since we have no kernel support for kerb NFS (which may or may not be worth having, in the form available to us) this is how I'm closing PR #2469.
 1.5 18-Feb-1996  fvdl Bring in NFSv3 code by Rick Macklem (from Lite2).
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 22-Dec-1994  cgd specify man pages the new way.
 1.2 27-Jul-1994  brezak If in a kerberos environment; build -DKERBEROS
 1.1 08-Jun-1994  mycroft branches: 1.1.1; 1.1.2;
Update from 4.4-Lite, with local changes.
 1.1.2.1 06-Sep-1994  cgd from trunk.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.21.12.1 17-Jan-2009  mjf Sync with HEAD.
 1.3 16-Sep-1997  lukem back to using mount/getmntopts.c since mount is now post lite-2
 1.2 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
* deprecate register
* bzero() -> memset()
 1.1 18-Feb-1996  fvdl Temporarily use own getmntopts.c for mount_nfs (the Lite2 version). The other
mount_* commands need to be upgraded to use this version too soon.
 1.18 05-Feb-2017  christos remove debugging printf.
 1.17 03-Feb-2017  christos use the netid value because it could be udp6...
 1.16 29-Jun-2013  christos branches: 1.16.10; 1.16.14;
declare the variables that getnfsargs need in getnfsargs so that they can
easily be used from other programs.
 1.15 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.14 23-Jul-2010  pooka branches: 1.14.6; 1.14.12;
Make it possible to set the retry timeout as a compile-time define.
This is useful for automated environments where everything (rpcbind,
mountd, nfsd and the client) is started in parallel in a split
second and there is a small chance we will race in there before
everything has been communicated to rpcbind.
 1.13 30-Nov-2009  pooka Use getprogname() instead of hardcoding "mount_nfs" to get the
right info in rump_nfs.
 1.12 15-Oct-2008  pooka Reword quite out-of-place (even historically) "nqnfs 2" error message.
 1.11 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.10 05-Aug-2007  yamt branches: 1.10.10; 1.10.14; 1.10.16;
lengthen timeout. i saw a server for which 10s was not enough.
 1.9 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.8 27-Dec-2006  yamt remove the rest of Kerberos 4 code.
 1.7 27-Dec-2006  yamt sync with header changes. (nqnfs removal)
 1.6 07-Jul-2006  hubertf Replace strcpy() call with strlcpy() call.
OK'd by christos@
 1.5 20-May-2006  yamt do not keep to use nfsv3 filehandle when falling back to nfsv2.
 1.4 23-Mar-2006  wiz unifdef NFSKERB (Kerberos 4 support). Update man page and usage() for
-K and -m removal (Kerberos 4 specific options).
 1.3 12-Nov-2005  dsl Add a missing break!
Maybe 'mount_nfs -oport=<port>' has been broken since the IPv6 changes.
 1.2 02-Jun-2005  lukem Use ai_nfs instead of the uninitialized ai when determining the NFSMNT_KERB
reverse IP address, and ensure ecode is set as well.
Detected with gcc -Wuninitialized.
(The bug was introduced in mount_nfs.c rev 1.25. Hi fvdl! :)
 1.1 15-May-2005  dsl Split getnfsargs() out into its own file, it drags in 70kB of rpc code.
I might manage to write a version that doesn't pull in all the crud.
(Which will give a load of space in the install floppy images)
 1.10.16.2 05-Aug-2007  yamt lengthen timeout. i saw a server for which 10s was not enough.
 1.10.16.1 05-Aug-2007  yamt file getnfsargs.c was added on branch matt-mips64 on 2007-08-05 22:09:13 +0000
 1.10.14.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.10.2 17-Jan-2009  mjf Sync with HEAD.
 1.10.10.1 28-Sep-2008  mjf Sync with HEAD.
 1.14.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.12.1 23-Jun-2013  tls resync from head
 1.14.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.14.1 21-Apr-2017  bouyer Sync with HEAD
 1.16.10.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10 29-Jun-2013  christos declare the variables that getnfsargs need in getnfsargs so that they can
easily be used from other programs.
 1.9 06-Jul-2011  mrg branches: 1.9.2; 1.9.8;
switch from an ugly cast and ntohl() usage to be32dec(). use sizeof.
idea from dh, and fixes a GCC 4.5 warning.
 1.8 29-Apr-2008  martin Convert to new 2 clause license
 1.7 10-Mar-2007  hubertf branches: 1.7.12; 1.7.14;
- removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.6 27-Dec-2006  yamt sync with header changes. (nqnfs removal)
 1.5 07-Jul-2006  hubertf Replace strcpy() call with strlcpy() call.
OK'd by christos@
 1.4 20-May-2006  yamt do not keep to use nfsv3 filehandle when falling back to nfsv2.
 1.3 20-May-2006  yamt replace a magic constant with a macro.
 1.2 20-May-2006  yamt copy missing copyright notices from
getnfsargs.c and sys/arch/i386/stand/libsa/nfs.c.
 1.1 21-Jan-2006  dsl Use the rpc code from sys/lib/libsa to determine the root file handle.
Saves the code from depending on the xdr functions.
Tested on i386 and IPv4, may need tweaking for IPv6 and using TCP for the
portmap/mount functions.
 1.7.14.1 18-May-2008  yamt sync with head.
 1.7.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3 13-Jan-2009  tsutsui Add workaround typedefs for awful hack.

XXX: It's completely unacceptable for me to refer libsa files from userland.
XXX: Nowadays we no longer have serious size restriction in install media,
XXX: so I think it's much better to simply remove this ugly SMALLPROG hacks.
XXX: If you really want to share files, please move them into src/common
XXX: with defined APIs.
 1.2 29-Apr-2008  martin Convert to new 2 clause license
 1.1 21-Jan-2006  dsl branches: 1.1.20; 1.1.22;
Use the rpc code from sys/lib/libsa to determine the root file handle.
Saves the code from depending on the xdr functions.
Tested on i386 and IPv4, may need tweaking for IPv6 and using TCP for the
portmap/mount functions.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.2 17-Jan-2009  mjf Sync with HEAD.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.3 16-Sep-1997  lukem back to using mount/getmntopts.c since mount is now post lite-2
 1.2 23-Oct-1996  cgd recognize the 'nocoredump' mount option as a standard option (supported by
all file system types).
 1.1 18-Feb-1996  mycroft This accompanies getmntopts.c.
 1.52 14-Mar-2021  rin Fix typo: s/--r/-r/
 1.51 24-Jan-2021  jmcneill Use 32K as the default NFSv3 read and write data sizes on aarch64, matching
i386 and amd64.
 1.50 03-Oct-2020  wiz New sentence, new line.
 1.49 03-Oct-2020  christos Add -A (noac) option to turn off the attribute cache. (Maciej W. Rozycki)
 1.48 17-May-2018  wiz Remove Tn for standard abbreviations.
 1.47 17-May-2018  thorpej Default NFS mounts to using TCP transport instead of UDP.
PR kern/53166
 1.46 03-Jul-2017  wiz branches: 1.46.4;
Remove workaround for ancient HTML generation code.
 1.45 12-Sep-2016  sevan Add HISTORY section.
Bump date.
Not sure where mount_nfs first showed up but the version in the moder BSDs originates
from 4.4BSD according to CSRG archive
http://minnie.tuhs.org/cgi-bin/utree.pl?file=4.4BSD/usr/src/sbin/mount_nfs
Commercial offerings from Sun and others covers older systems, eg
https://groups.google.com/forum/#!topic/net.unix-wizards/lMe7aQikqJI
 1.44 28-Apr-2015  prlw1 Fix typos
 1.43 11-Jul-2012  dholland minor wording improvement.
 1.42 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.41 02-Apr-2012  njoly Note that amd64 defaults to 32k read/write data size, just like i386.
 1.40 29-Aug-2011  jruoho branches: 1.40.2;
Remove a comma. From "Snader_LB" on freenode.
 1.39 18-Apr-2009  wiz Remove outdated example. From Todd Kover in PR 41238.
 1.38 08-Apr-2009  joerg Fix string literals.
 1.37 11-Jan-2009  pooka branches: 1.37.2;
-o resport, not -o resvport
 1.36 09-Nov-2007  yamt branches: 1.36.8; 1.36.14;
- fix timeout for -s.
- mention default values of some options.
 1.35 01-Jun-2007  ginsbach branches: 1.35.4;
Add arguments to option descriptions for options that require arguments.
Document all of the NFS specific -o options.
 1.34 27-Dec-2006  wiz Sort options.
 1.33 27-Dec-2006  yamt oops, remove duplicated -D.
 1.32 27-Dec-2006  yamt revive -D option because it actually has some meanings for non-nqnfs mounts.
 1.31 09-Nov-2006  yamt remove nqnfs support.
namely,
- make -q a synonym of -3.
- ignore -L and -D.
 1.30 23-Mar-2006  wiz unifdef NFSKERB (Kerberos 4 support). Update man page and usage() for
-K and -m removal (Kerberos 4 specific options).
 1.29 23-Mar-2006  wiz Fix typo in Xref.
 1.28 20-Jun-2005  peter Change all .Xr config 8 to .Xr config 1, following the recent move of
config from usr.sbin -> usr.bin.

Reviewed by wiz.
 1.27 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.26 21-Jan-2005  yamt note that loopback mount is a bad idea.
 1.25 05-May-2004  fair Came in here to add nfsstat(1) reference in SEE ALSO,
but since I was here...

Correct spelling of "Kerberos." Add RFC references.
Reword some awkward english. Sprinkle mandoc macros throughout.
Add white space to aid readability. Change date.
 1.24 15-Jan-2004  grant branches: 1.24.2;
uppercase NFS acronym
 1.23 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.22 06-Apr-2003  wiz Some casing changes, and use Er for EINTR.
 1.21 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.20 01-Jan-2003  jschauma Fix tyops pointed out by Igor Sobrado in PR misc/19623:

mount_filecore(8) - frquently (frequently), upto (up to)
mount_nfs(8) - NFSV3 (NFSv3), automaticly (automatically)
mount_ntfs(8) - particularily (particularly), fisk (disk)
 1.19 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.18 15-May-2002  simonb In the description of the -r and -w options, match the wording of the
stats to look for from netstat(1) with what netstat actually shows.
 1.17 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.16 21-Jan-2002  wiz Use mdoc macros instead of man ones.
 1.15 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.14 16-Nov-2001  wiz Punctuation nit, and drop two .Pps.
 1.13 02-May-2001  fvdl Remove BUGS section, which only referred to performance tuning.
Instead, add a PERFORMANCE section which explains the most common
optimizations.
 1.12 07-Oct-1999  soren branches: 1.12.6;
NFS over TCP is more common these days.
 1.11 07-Mar-1999  mycroft branches: 1.11.4;
Clean up SYNOPSIS formatting.
 1.10 01-Feb-1999  msaitoh Eliminate unused period.
 1.9 12-Jan-1999  garbled Add an EXAMPLES and ERRORS section to the manpage to partially fix
PR# 6121 by Charles M. Hannum. Someone else will have to do the
fixing to mountd's diagnostics.
 1.8 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.7 19-Oct-1997  fvdl Implement -X option for 32 <-> 64 bit translation of directory cookies
for v3 mounts. Should rarely be needed (i.e. servers actually
returning information in the upper 32 bits, and programs not
being able to deal with that (emulated binaries; native NetBSD
binaries will never need this)).
 1.6 23-Mar-1997  fvdl Use a reserved port by default. The -P option is now obsolete, but
kept for backward compatibility. The -p option was added to explicitly
NOT use reserved ports.
 1.5 26-Nov-1996  mikel Fix typo; PR misc/2956. Also cleaned up .Nm usage.
 1.4 27-Oct-1996  christos Fix PR/2884: Change default for nfs mounts to not do a connect on the
socket. Add option -C to force a connected mount. Now option -c is still
there, but it is the default. Maybe amd should be changed similarly.
 1.3 18-Feb-1996  fvdl Bring in NFSv3 code by Rick Macklem (from Lite2).
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 09-Jan-1997  tls Import from 4.4BSD-Lite2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.11.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.12.6.1 02-May-2001  he Pull up revision 1.13 (requested by fvdl):
Add some text explaining NFS performance tuning.
 1.24.2.1 08-May-2004  grant Pull up revision 1.25 (requested by fair in ticket #264):

Came in here to add nfsstat(1) reference in SEE ALSO,
but since I was here...

Correct spelling of "Kerberos." Add RFC references.
Reword some awkward english. Sprinkle mandoc macros throughout.
Add white space to aid readability. Change date.
 1.35.4.1 09-Jan-2008  matt sync with HEAD
 1.36.14.3 19-Apr-2009  snj Pull up following revision(s) (requested by wiz in ticket #707):
sbin/mount_nfs/mount_nfs.8: revision 1.39
Remove outdated example. From Todd Kover in PR 41238.
 1.36.14.2 19-Apr-2009  snj Pull up following revision(s) (requested by wiz in ticket #707):
sbin/mount_nfs/mount_nfs.8: revision 1.38
Fix string literals.
 1.36.14.1 19-Apr-2009  snj Pull up following revision(s) (requested by wiz in ticket #707):
sbin/mount_nfs/mount_nfs.8: revision 1.37
-o resport, not -o resvport
 1.36.8.1 17-Jan-2009  mjf Sync with HEAD.
 1.37.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.40.2.2 30-Oct-2012  yamt sync with head
 1.40.2.1 17-Apr-2012  yamt sync with head
 1.46.4.1 21-May-2018  pgoyette Sync with HEAD
 1.76 03-Jan-2025  rillig mount_nfs: fix a few lint warnings

The options 'K' and 'm:' are neither documented nor handled.
 1.75 21-Dec-2022  chs branches: 1.75.2;
mount_nfs: add missing "A" to getopt string
 1.74 03-Oct-2020  christos branches: 1.74.6;
- centralize number parsing code
- enable -g
- KNF
 1.73 03-Oct-2020  christos Add -A (noac) option to turn off the attribute cache. (Maciej W. Rozycki)
 1.72 17-May-2018  thorpej Default NFS mounts to using TCP transport instead of UDP.
PR kern/53166
 1.71 29-Jun-2013  christos branches: 1.71.26;
declare the variables that getnfsargs need in getnfsargs so that they can
easily be used from other programs.
 1.70 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.69 29-Aug-2011  joerg branches: 1.69.2; 1.69.8;
Use __dead
 1.68 30-Nov-2009  pooka Use getprogname() instead of hardcoding "mount_nfs" to get the
right info in rump_nfs.
 1.67 03-Apr-2009  pooka Fix bug I introduced in rev 1.64: don't use stack space after
return. pointed out by yamt.
 1.66 20-Feb-2009  yamt nfsdefargs: use designated initializers
 1.65 11-Jan-2009  pooka branches: 1.65.2;
Fix noresport mount option parsing.
 1.64 16-Oct-2008  pooka Convert mount_nfs to the mount_foo_parseargs() format. No functional
change.
 1.63 27-Sep-2008  pooka Assign default value for retrycnt already in data.
XXX: the use of globals would benefit from a loving touch
 1.62 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.61 30-Nov-2007  yamt branches: 1.61.2; 1.61.8; 1.61.12;
remove an unused variable, nfsproto.
 1.60 16-Jul-2007  pooka branches: 1.60.4;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.59 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.58 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.57 27-Dec-2006  yamt remove the rest of Kerberos 4 code.
 1.56 27-Dec-2006  yamt sync with header changes. (nqnfs removal)
 1.55 27-Dec-2006  wiz Sort options in usage.
 1.54 27-Dec-2006  yamt revive -D option because it actually has some meanings for non-nqnfs mounts.
 1.53 09-Nov-2006  yamt remove nqnfs support.
namely,
- make -q a synonym of -3.
- ignore -L and -D.
 1.52 16-Oct-2006  christos use MOPT_NULL
 1.51 20-May-2006  yamt do not keep to use nfsv3 filehandle when falling back to nfsv2.
 1.50 23-Mar-2006  wiz unifdef NFSKERB (Kerberos 4 support). Update man page and usage() for
-K and -m removal (Kerberos 4 specific options).
 1.49 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.48 15-May-2005  dsl Split getnfsargs() out into its own file, it drags in 70kB of rpc code.
I might manage to write a version that doesn't pull in all the crud.
(Which will give a load of space in the install floppy images)
 1.47 05-Feb-2005  xtraeme branches: 1.47.2;
Kill __P(), use ANSI function declarations; WARNS=3.
 1.46 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.45 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.44 23-Jul-2003  itojun include des.h, not kerberosIV/des.h
 1.43 13-Jul-2003  itojun use bounded string op
 1.42 16-May-2003  yamt fix a typo that prevents -o wsize=nnn to work.
 1.41 05-May-2003  yamt remove _KERNEL hack.
 1.40 11-Apr-2003  christos PR/1472: David Carrel: Add option to specify the nfs port.
This was not done, I added the functionality to be able to parse
port=num in the options. While I was there, I added this for all
the other numeric options: rsize, wsize etc.
 1.39 10-Apr-2003  lukem fix typo introduced in previous (print "addr=" instead of "ddr=")
 1.38 07-Apr-2003  fvdl Don't print the version of the argument structure, it's easily confused
with the NFS version.
 1.37 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.36 21-Oct-2002  enami When printing filesystem specific parameters, also print the address and
port of server numerically.
 1.35 01-Oct-2002  itojun KNF
 1.34 21-Sep-2002  christos MNT_GETARGS support
 1.33 16-Jun-2002  wrstuden Catch error code from mount command, and if it's the
error given when we ask for a v3 mount on a v2-only kernel,
*and* we weren't forcing v3, try the mount again as a v2 mount
before erroring out.
 1.32 29-May-2002  cjs When RPC fails, state explicitly which service we were trying to connect to.
 1.31 02-Mar-2002  mrg branches: 1.31.2;
when complaining that we can't lookup a hostname, actually say which
hostname this is...
 1.30 11-Jan-2001  lukem remove unnecessary ":" in openlog ident
 1.29 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.28 16-Jul-2000  itojun correct hard-to-understand indentation.
 1.27 26-Jun-2000  bjh21 Remove spurious colon from error message; clnt_pcreateerror provides one.
 1.26 19-Jun-2000  fvdl branches: 1.26.2;
Handle unsupported protocols (i.e. no v6 support on the other side)
a tad better.
 1.25 09-Jun-2000  fvdl Update to be more address-family independent, and adapt to TI-RPC
interface.

XXX this code needs a cleanup, especially the retry-loop.
 1.24 21-Nov-1999  mjl branches: 1.24.2;
Make usage message match actual options.
 1.23 25-Jun-1999  perseant branches: 1.23.4;
Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.22 14-May-1998  tron branches: 1.22.2;
Get protocol type for "pmap_getport()" from variable "nfsproto" instead of
checking the socket type.
 1.21 01-Apr-1998  kleink No need to include <sys/socketvar.h>.
 1.20 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.19 03-Feb-1998  perry change <strings.h> to <string.h> to fix compiler warning
 1.18 19-Oct-1997  fvdl Implement -X option for 32 <-> 64 bit translation of directory cookies
for v3 mounts. Should rarely be needed (i.e. servers actually
returning information in the upper 32 bits, and programs not
being able to deal with that (emulated binaries; native NetBSD
binaries will never need this)).
 1.17 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
* deprecate register
* bzero() -> memset()
 1.16 12-May-1997  jtk fix typo: PRC should have been RPC
 1.15 23-Mar-1997  fvdl Use a reserved port by default. The -P option is now obsolete, but
kept for backward compatibility. The -p option was added to explicitly
NOT use reserved ports.
 1.14 27-Oct-1996  christos Fix PR/2884: Change default for nfs mounts to not do a connect on the
socket. Add option -C to force a connected mount. Now option -c is still
there, but it is the default. Maybe amd should be changed similarly.
 1.13 23-May-1996  fvdl Be stricter when checking NQNFS and version combinations. Incorrect combinations
of these flags were previously possible when falling back from a v3 -> v2
mount, and could confuse the system.
 1.12 13-Apr-1996  jtc branches: 1.12.4;
Add const qualifier to mopts table
 1.11 18-Feb-1996  fvdl Bring in NFSv3 code by Rick Macklem (from Lite2).
 1.10 21-May-1995  mycroft Use inet_aton(), not inet_addr().
 1.9 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 29-Dec-1994  cgd fix bug 547. it looks like somebody mis-pasted. kirk has been informed.
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 17-Sep-1994  mycroft Get the root filehandle using the same transport as the mount itself. From
Ken Hornstein.
 1.4 05-Sep-1994  mycroft Fix incorrect error messages.
 1.3 27-Jul-1994  brezak Use default realm instead of constant
 1.2 24-Jun-1994  pk branches: 1.2.2;
Make numerical IP addresses work (fix from Christos Zoulas).
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 09-Jan-1997  tls Import from 4.4BSD-Lite2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.2.2.1 06-Sep-1994  cgd from trunk.
 1.12.4.1 25-May-1996  fvdl Pull in options-combinations bugfix from main branch.
 1.22.2.1 05-Sep-1999  he Pull up revision 1.23:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.23.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.24.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.2.1 03-Jul-2000  thorpej Pull up rev. 1.27:
Remove spurious colon from error message; clnt_pcreateerror provides one.
 1.31.2.1 18-Jun-2002  lukem Pull up revision 1.33 (requested by wrstuden in ticket #290):
Catch error code from mount command, and if it's the
error given when we ask for a v3 mount on a v2-only kernel,
*and* we weren't forcing v3, try the mount again as a v2 mount
before erroring out.
 1.47.2.1 11-Jun-2005  tron Apply patch (requested by lukem in ticket #391):
Use ai_nfs instead of the uninitialized ai when determining the
NFSMNT_KERB reverse IP address, and ensure ecode is set as well.
(Fix derived from getnfsargs.c 1.2)
 1.60.4.1 09-Jan-2008  matt sync with HEAD
 1.61.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.61.8.2 17-Jan-2009  mjf Sync with HEAD.
 1.61.8.1 28-Sep-2008  mjf Sync with HEAD.
 1.61.2.2 30-Nov-2007  yamt remove an unused variable, nfsproto.
 1.61.2.1 30-Nov-2007  yamt file mount_nfs.c was added on branch mjf-devfs on 2007-11-30 16:13:16 +0000
 1.65.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.69.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.69.8.1 23-Jun-2013  tls resync from head
 1.69.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.71.26.1 21-May-2018  pgoyette Sync with HEAD
 1.74.6.1 21-Dec-2022  martin Pull up following revision(s) (requested by chs in ticket #18):

sbin/mount_nfs/mount_nfs.c: revision 1.75

mount_nfs: add missing "A" to getopt string
 1.75.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 29-Jun-2013  christos declare the variables that getnfsargs need in getnfsargs so that they can
easily be used from other programs.
 1.2 16-Oct-2008  pooka branches: 1.2.18; 1.2.24;
Convert mount_nfs to the mount_foo_parseargs() format. No functional
change.
 1.1 15-May-2005  dsl branches: 1.1.20;
Split getnfsargs() out into its own file, it drags in 70kB of rpc code.
I might manage to write a version that doesn't pull in all the crud.
(Which will give a load of space in the install floppy images)
 1.1.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.2.24.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.18.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2 29-Apr-2008  martin Convert to new 2 clause license
 1.1 21-Jan-2006  dsl branches: 1.1.20; 1.1.22;
Use the rpc code from sys/lib/libsa to determine the root file handle.
Saves the code from depending on the xdr functions.
Tested on i386 and IPv4, may need tweaking for IPv6 and using TCP for the
portmap/mount functions.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.2 11-Aug-2013  dholland These pass WARNS=5, so don't set WARNS=4
 1.1 18-Jul-2009  reinoud branches: 1.1.6; 1.1.12;
Import read-only part of the NiLFS (v2) implementation for NetBSD. It has been
tested with a DEBUG+DIAGNOSTIC+LOCKDEBUG kernel. To summerise NiLFS, i'll
repeat my posting to tech-kern here:

NiLFS stands for New implementation of Logging File System; LFS done
right they claim :) It is at version 2 now and is being developed by NTT, the
Japanese telecom company and recently put into the linux source tree. See
http://www.nilfs.org. The on-disc format is not completely frozen and i expect
at least one minor revision to come in time.

The benefits of NiLFS are build-in fine-grained checkpointing, persistent
snapshots, multiple mounts and very large file and media support. Every
checkpoint can be transformed into a snapshot and v.v. It is said to perform
very well on flash media since it is not overwriting pieces apart from a
incidental update of the superblock, but that might change. It is accompanied
by a cleaner to clean up the segments and recover lost space.

My work is not a port of the linux code; its a new implementation. Porting the
code would be more work since its very linux oriented and never written to be
ported outside linux. The goal is to be fully interchangable. The code is non
intrusive to other parts of the kernel. It is also very light-weight.

The current state of the code is read-only access to both clean and dirty
NiLFS partitions. On mounting a dirty partition it rolls forward the log to
the last checkpoint. Full read-write support is however planned!

Just as the linux code, mount_nilfs allows for the `head' to be mounted
read/write and allows multiple read-only snapshots/checkpoint mounts next to
it.

By allowing the RW mount at a different snapshot for read-write it should be
possible eventually to revert back to a previous state; i.e. try to upgrade a
system and being able to revert to the exact state prior to the upgrade.

Compared to other FS's its pretty light-weight, suitable for embedded use and
on flash media. The read-only code is currently 17kb object code on
NetBSD/i386. I doubt the read-write code will surpass the 50 or 60. Compared
this to FFS being 156kb, UDF being 84 kb and NFS being 130kb. Run-time memory
usage is most likely not very different from other uses though maybe a bit
higher than FFS.
 1.1.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 24-May-2022  andvar fix various typos in comment, documentation and log messages.
 1.5 16-Oct-2019  maya Switch files copyright Reinoud Zandijk from BSD 4 clause to BSD 2 clause.

OK'd by reinoud in email (from 4 Feb 2019).
 1.4 01-Jun-2016  wiz branches: 1.4.16;
Sort SEE ALSO. New sentence, new line. Punctuation nits. Use Nx.
 1.3 01-Jun-2016  pgoyette Improved documentation of mount_nilfs, from PR bin/46730
 1.2 18-Jul-2009  wiz Fix Dd argument, sort options and option descriptions.
 1.1 18-Jul-2009  reinoud Import read-only part of the NiLFS (v2) implementation for NetBSD. It has been
tested with a DEBUG+DIAGNOSTIC+LOCKDEBUG kernel. To summerise NiLFS, i'll
repeat my posting to tech-kern here:

NiLFS stands for New implementation of Logging File System; LFS done
right they claim :) It is at version 2 now and is being developed by NTT, the
Japanese telecom company and recently put into the linux source tree. See
http://www.nilfs.org. The on-disc format is not completely frozen and i expect
at least one minor revision to come in time.

The benefits of NiLFS are build-in fine-grained checkpointing, persistent
snapshots, multiple mounts and very large file and media support. Every
checkpoint can be transformed into a snapshot and v.v. It is said to perform
very well on flash media since it is not overwriting pieces apart from a
incidental update of the superblock, but that might change. It is accompanied
by a cleaner to clean up the segments and recover lost space.

My work is not a port of the linux code; its a new implementation. Porting the
code would be more work since its very linux oriented and never written to be
ported outside linux. The goal is to be fully interchangable. The code is non
intrusive to other parts of the kernel. It is also very light-weight.

The current state of the code is read-only access to both clean and dirty
NiLFS partitions. On mounting a dirty partition it rolls forward the log to
the last checkpoint. Full read-write support is however planned!

Just as the linux code, mount_nilfs allows for the `head' to be mounted
read/write and allows multiple read-only snapshots/checkpoint mounts next to
it.

By allowing the RW mount at a different snapshot for read-write it should be
possible eventually to revert back to a previous state; i.e. try to upgrade a
system and being able to revert to the exact state prior to the upgrade.

Compared to other FS's its pretty light-weight, suitable for embedded use and
on flash media. The read-only code is currently 17kb object code on
NetBSD/i386. I doubt the read-write code will surpass the 50 or 60. Compared
this to FFS being 156kb, UDF being 84 kb and NFS being 130kb. Run-time memory
usage is most likely not very different from other uses though maybe a bit
higher than FFS.
 1.4.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 16-Oct-2019  maya Switch files copyright Reinoud Zandijk from BSD 4 clause to BSD 2 clause.

OK'd by reinoud in email (from 4 Feb 2019).
 1.3 21-Feb-2016  christos branches: 1.3.16;
Add MOPT_{REL,NO}ATIME as supported by the underlying filesystems.
 1.2 19-Oct-2013  christos fix unused variable warnings.
 1.1 18-Jul-2009  reinoud branches: 1.1.6; 1.1.12;
Import read-only part of the NiLFS (v2) implementation for NetBSD. It has been
tested with a DEBUG+DIAGNOSTIC+LOCKDEBUG kernel. To summerise NiLFS, i'll
repeat my posting to tech-kern here:

NiLFS stands for New implementation of Logging File System; LFS done
right they claim :) It is at version 2 now and is being developed by NTT, the
Japanese telecom company and recently put into the linux source tree. See
http://www.nilfs.org. The on-disc format is not completely frozen and i expect
at least one minor revision to come in time.

The benefits of NiLFS are build-in fine-grained checkpointing, persistent
snapshots, multiple mounts and very large file and media support. Every
checkpoint can be transformed into a snapshot and v.v. It is said to perform
very well on flash media since it is not overwriting pieces apart from a
incidental update of the superblock, but that might change. It is accompanied
by a cleaner to clean up the segments and recover lost space.

My work is not a port of the linux code; its a new implementation. Porting the
code would be more work since its very linux oriented and never written to be
ported outside linux. The goal is to be fully interchangable. The code is non
intrusive to other parts of the kernel. It is also very light-weight.

The current state of the code is read-only access to both clean and dirty
NiLFS partitions. On mounting a dirty partition it rolls forward the log to
the last checkpoint. Full read-write support is however planned!

Just as the linux code, mount_nilfs allows for the `head' to be mounted
read/write and allows multiple read-only snapshots/checkpoint mounts next to
it.

By allowing the RW mount at a different snapshot for read-write it should be
possible eventually to revert back to a previous state; i.e. try to upgrade a
system and being able to revert to the exact state prior to the upgrade.

Compared to other FS's its pretty light-weight, suitable for embedded use and
on flash media. The read-only code is currently 17kb object code on
NetBSD/i386. I doubt the read-write code will surpass the 50 or 60. Compared
this to FFS being 156kb, UDF being 84 kb and NFS being 130kb. Run-time memory
usage is most likely not very different from other uses though maybe a bit
higher than FFS.
 1.1.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 18-Jul-2009  reinoud Import read-only part of the NiLFS (v2) implementation for NetBSD. It has been
tested with a DEBUG+DIAGNOSTIC+LOCKDEBUG kernel. To summerise NiLFS, i'll
repeat my posting to tech-kern here:

NiLFS stands for New implementation of Logging File System; LFS done
right they claim :) It is at version 2 now and is being developed by NTT, the
Japanese telecom company and recently put into the linux source tree. See
http://www.nilfs.org. The on-disc format is not completely frozen and i expect
at least one minor revision to come in time.

The benefits of NiLFS are build-in fine-grained checkpointing, persistent
snapshots, multiple mounts and very large file and media support. Every
checkpoint can be transformed into a snapshot and v.v. It is said to perform
very well on flash media since it is not overwriting pieces apart from a
incidental update of the superblock, but that might change. It is accompanied
by a cleaner to clean up the segments and recover lost space.

My work is not a port of the linux code; its a new implementation. Porting the
code would be more work since its very linux oriented and never written to be
ported outside linux. The goal is to be fully interchangable. The code is non
intrusive to other parts of the kernel. It is also very light-weight.

The current state of the code is read-only access to both clean and dirty
NiLFS partitions. On mounting a dirty partition it rolls forward the log to
the last checkpoint. Full read-write support is however planned!

Just as the linux code, mount_nilfs allows for the `head' to be mounted
read/write and allows multiple read-only snapshots/checkpoint mounts next to
it.

By allowing the RW mount at a different snapshot for read-write it should be
possible eventually to revert back to a previous state; i.e. try to upgrade a
system and being able to revert to the exact state prior to the upgrade.

Compared to other FS's its pretty light-weight, suitable for embedded use and
on flash media. The read-only code is currently 17kb object code on
NetBSD/i386. I doubt the read-write code will surpass the 50 or 60. Compared
this to FFS being 156kb, UDF being 84 kb and NFS being 130kb. Run-time memory
usage is most likely not very different from other uses though maybe a bit
higher than FFS.
 1.10 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.9 27-Jun-2005  christos branches: 1.9.20; 1.9.24;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.8 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.7 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.6 21-Sep-2002  christos MNT_GETARGS support
 1.5 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.4 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.3 17-May-1999  kleink Use the system search path for ntfs headers.
 1.2 06-May-1999  christos Make this compile...
 1.1 06-May-1999  christos branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1999  christos Import yesterday's FreeBSD mount_ntfs source
 1.9.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.9.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.22 15-Apr-2017  abhinav Use Xr instead of Fn to refer readdir(3)
 1.21 09-Sep-2015  christos branches: 1.21.2; 1.21.4;
more recent information about unsupported drives.
 1.20 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.19 20-Jul-2013  wiz Use Mt for email addresses.
 1.18 30-Mar-2010  joerg branches: 1.18.6; 1.18.12; 1.18.16;
\\ -> \e
 1.17 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.16 23-Apr-2004  simonb s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.15 20-May-2003  wiz Add some missing words (like articles), remove duplicate word; fix some nits. From jmc@openbsd.
 1.14 14-May-2003  wiz setup -> set up.
 1.13 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.12 01-Jan-2003  jschauma Fix tyops pointed out by Igor Sobrado in PR misc/19623:

mount_filecore(8) - frquently (frequently), upto (up to)
mount_nfs(8) - NFSV3 (NFSv3), automaticly (automatically)
mount_ntfs(8) - particularily (particularly), fisk (disk)
 1.11 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.10 16-Nov-2001  wiz Punctuation nits, drop a .Pp, use .Nx, use standard headers.
 1.9 16-Nov-2001  wiz Whitespace nits
 1.8 31-Oct-2001  jdolecek Xref disklabel and mention that mbrlabel can help setup the disk label
Note that NTFS partition is no longer accessible in NetBSD once
it's marked 'dynamic' in MS Windows XP.

Pointed out by Christos.
 1.7 31-Oct-2001  jdolecek Couple changes, mainly to address stuff raised recently on port-i386
('Does i386 support NTFS5 now?'):

add a note both NTFS4 and NTFS5 are supported
reformat the Limitations a bit
assert the write support is not really useful, and should not be used
add a BUGS section, note missing stuff for the write support to be useful,
and the disk label thing spotted by Christos Zoulas
 1.6 17-Dec-1999  jdolecek Rework the manpage to be a bit more pleasing to read

BUGS section is gone, the facts are stated in the paragraph about
support for writing.
also note that NetBSD 1.5 is the first release supporting NTFS
 1.5 12-Sep-1999  kleink branches: 1.5.4;
Use full month names with .Dd, as per mdoc.samples(7).
 1.4 07-Sep-1999  jdolecek Use unixish term "hole" instead od "sparce" (which looks like it
should be "sparse" anyway).

Noted by Soren Jorvang <soren@NetBSD.org>.
 1.3 05-Aug-1999  jdolecek * put new BUGS section instead of CAVEATS, which explicitely warns NTFS
is experimental and should be used with extreme caution
* give credit to christos & me for the NetBSD port
 1.2 06-May-1999  christos Make this compile...
 1.1 06-May-1999  christos branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1999  christos Import yesterday's FreeBSD mount_ntfs source
 1.5.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.16.1 23-Jul-2013  riastradh sync with HEAD
 1.18.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.21.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.21.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.22 14-Sep-2009  pooka Set fspec to canon_dev instead of dev.
 1.21 05-Aug-2008  pooka Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.20 15-Dec-2007  perry branches: 1.20.4; 1.20.8;
convert __attribute__s to applicable cdefs.h macros
 1.19 16-Jul-2007  pooka branches: 1.19.4; 1.19.6;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.18 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.17 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.16 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.15 16-Oct-2006  christos use MOPT_NULL
 1.14 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.13 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.12 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.11 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.10 02-Aug-2003  jdolecek g/c all traces of FreeBSD-specific code - it only obfuscated the code without
any real benefit
 1.9 03-May-2003  christos print masks and modes in octal.
 1.8 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.7 01-Oct-2002  itojun minor KNF
 1.6 21-Sep-2002  christos MNT_GETARGS support
 1.5 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.4 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.3 25-Jun-1999  perseant branches: 1.3.6;
Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.2 06-May-1999  christos Make this compile...
 1.1 06-May-1999  christos branches: 1.1.1;
Initial revision
 1.1.1.1 06-May-1999  christos Import yesterday's FreeBSD mount_ntfs source
 1.3.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.19.4.1 09-Jan-2008  matt sync with HEAD
 1.20.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.20.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_ntfs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:13 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_ntfs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:27 +0000
 1.13 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.12 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.11 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.10 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.9 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.8 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.7 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.6 06-May-1997  gwr Use .PATH.c: ...
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 22-Dec-1994  cgd specify man pages the new way.
 1.3 03-Aug-1994  deraadt do not need -I/sys
 1.2 10-Jun-1994  pk X compilation
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.24 23-Jul-2024  uwe mount_null(8): tweak previous

Make the wording in the example less ambiguous.
While here, g/c accidental blank like in input.
 1.23 23-Jul-2024  uwe mount_null(8): brush up markup, add read-only /usr/src example

TODO: the source code references probably need to be updated!
 1.22 01-Dec-2020  pgoyette branches: 1.22.8;
Be consistent with mark-up of vop_reclaim
 1.21 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.20 10-Jun-2004  uebayasi Fix SEE ALSO; remove .sp; put .Pp before sentences.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.18 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.17 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.16 30-Mar-2002  groo s/bypassing/passing/
 1.15 16-Nov-2001  wiz Lose unnecessary .Nm argument.
 1.14 16-Nov-2001  wiz Whitespace nits
 1.13 07-Jun-2001  wiz Typos and grammar fixes (last part of misc/13133 by Michael K. Sanders)
 1.12 05-Jun-2001  wiz Drop arguments of .Os.
 1.11 11-Apr-2001  agc "It's" is short for "it is". The possessive pronoun is "its".
 1.10 19-Nov-1999  kristerw Typos (from OpenBSD)
 1.9 07-Mar-1999  mycroft branches: 1.9.6;
Clean up SYNOPSIS formatting.
 1.8 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.7 20-Oct-1997  enami Fix .Nm usage.
 1.6 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.5 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.4 10-Apr-1996  thorpej Remove extra "the", from Masanobu Saitoh <msaitoh@spa.is.uec.ac.jp>,
PR #2318.
 1.3 12-Jul-1995  cgd clean up (GRAMMAR POLICE!), removed references to now-nonexistent
loopback file system (fixes pr 955, but more thoroughly).
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.9.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.22.8.1 02-Aug-2025  perseant Sync with HEAD
 1.21 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.20 25-Jul-2016  erh Eliminate the distinct path check, since the paths don't actually need to be
distinct and allowing this makes certain useful tasks possible, such as
fixing an unpopulated /dev while a tmpfs is mounted over it.
However, require the paths to be different, as mounting a path directly over
itself has the side effect of causing any other mount points within that path
to no longer be accessible, and is difficult to unmount when done on /.
 1.19 29-Aug-2011  joerg branches: 1.19.24;
Use __dead
 1.18 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.17 16-Jul-2007  pooka branches: 1.17.12; 1.17.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.16 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.15 16-Oct-2006  christos use MOPT_NULL
 1.14 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.13 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.12 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.9 21-Sep-2002  christos MNT_GETARGS support
 1.8 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.7 08-Jul-1999  wrstuden Update to new mount arguments.
 1.6 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.5 16-Sep-1997  lukem branches: 1.5.4;
resolve conflicts from lite-2 merge
 1.4 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.3 13-Apr-1996  jtc Add const qualifier to mopts table
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.5.4.1 05-Sep-1999  he Pull up revision 1.6:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.17.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.17.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.19.24.1 26-Jul-2016  pgoyette Sync with HEAD
 1.6 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.5 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.4 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.3 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.2 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.1 20-Jan-2000  wrstuden Add mount_overlay.
 1.9 10-Jun-2004  uebayasi Fix SEE ALSO; remove .sp; put .Pp before sentences.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.6 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.5 07-Jun-2001  wiz Typos and grammar fixes (last part of misc/13133 by Michael K. Sanders)
 1.4 05-Jun-2001  wiz Drop arguments of .Os.
 1.3 30-Jul-2000  jdolecek in SEE ALSO, add missing comma between moun(8) and mount_null(8)
 1.2 20-Jan-2000  wrstuden branches: 1.2.4;
Fix tyop pointed out by Simon Burge. Also expand description
a little, and change words to suggest overlay is a starting point for
layers which need to overlay the over-mounted fs.
 1.1 20-Jan-2000  wrstuden Add mount_overlay.
 1.2.4.1 30-Jul-2000  jdolecek pullup rev. 1.3 from trunk (approved by jhawk):
add missing comma between entries in SEE ALSO
 1.14 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.13 29-Aug-2011  joerg Use __dead
 1.12 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.11 16-Jul-2007  pooka branches: 1.11.12; 1.11.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.10 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.9 16-Oct-2006  christos use MOPT_NULL
 1.8 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.7 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.6 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.5 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.4 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.3 21-Sep-2002  christos MNT_GETARGS support
 1.2 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.1 20-Jan-2000  wrstuden Add mount_overlay.
 1.11.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.27 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.26 23-Jan-2016  christos branches: 1.26.6;
Define _KERNTYPES for things that need it.
 1.25 14-Aug-2011  christos document non-literal strings
 1.24 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
 1.23 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.22 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.21 01-Mar-2004  itojun unifdef -DINET6. getaddrinfo will always be there, so there's no point in
keeping old code. moreover old code does not traverse list of DNS-returned
addresses.
 1.20 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.19 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.18 31-Dec-2000  itojun support IPv6. PR 11858 from ura@hiru.aoba.yokohama.jp
 1.17 06-Nov-2000  jdolecek convert to use regex (it used compat regexp previously), g/c now unneded stuff
 1.16 16-Aug-1999  bgrayson Initial support for rfilter and wfilter namespaces, in pt_filter.c.
Also, recur into ./examples, to grab the tutorial and example configurations.
 1.15 18-Sep-1998  thorpej We use regexp(3), better link w/ libcompat!
 1.14 04-Feb-1998  christos Remove -lcompat; not needed.
 1.13 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.12 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.11 06-May-1997  gwr Use .PATH.c: ...
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 22-Dec-1994  cgd specify man pages the new way.
 1.8 03-Aug-1994  deraadt do not need -I/sys
 1.7 10-Jun-1994  pk X compilation
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 28-Jan-1994  cgd don't need -lutil
 1.4 13-Jan-1994  mycroft Remove some notdefage and link with libutil so we properly daemonize.
 1.3 12-Jan-1994  cgd it uses the old regex stuff, so include -lcompat
 1.2 12-Jan-1994  mycroft Get CFLAGS right so the blasted thing is optimized.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.26.6.1 11-May-2017  pgoyette Sync with HEAD
 1.15 11-Apr-2009  lukem fix sign-compare issues
 1.14 02-Jul-2007  pooka branches: 1.14.22;
The kernel socket isn't used by any of the providers, and it's a bit
hard to imagine how it could be used, so get rid of it.
 1.13 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 11-Feb-2002  atatat Minor tweak to make portalfs work on 64 bit ports.
 1.10 10-Jan-2001  lukem be consistent (both internally and with other programs):
log_err fatal errors
log_warning non-fatal errors & warnings
log_debug debug messages (#ifdef DEBUG)
 1.9 05-Jun-2000  thorpej Use CMSG_*() correctly when sending file descriptors.
 1.8 21-Sep-1997  enami branches: 1.8.10;
Cosmetic changes:

- Use syslog(..., "...%m") instead of syslog(..., "...%s",
strerror(errno)).
- Don't put a simple and single statement into a block.
- Indent continuation line by four space.
- Add an empty line at the beginning of a function if it doesn't have
local variable.
- Use err() or errx() instead of fprintf(stderr, "progname: ....\n")
and exit() (there was two place left).
- Use MOUNT_PORTAL, which is defined as "portal" in sys/mount.h,
instead of using "portal" directly.
- Fold long line to fit column < 80.
 1.7 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.6 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.5 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.8.10.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.14.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.14 23-May-2019  kre Better handling of comments in portal.conf ... # now only introduces
a comment at beginning of line, or after whitespace. This allows #
to be used as data otherwhere in the line (there is no escape mechanism).
 1.13 23-May-2019  kre KNF: blank lines after declarations, return (x) -> return x, and
eliminate spaces between cast and value being cast (most were OK already)
NFCI.
 1.12 02-Jul-2007  pooka branches: 1.12.78;
* narrow-angle const spray
* make config read return an error if it can't read the config file
 1.11 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.10 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.9 10-Jan-2001  lukem be consistent (both internally and with other programs):
log_err fatal errors
log_warning non-fatal errors & warnings
log_debug debug messages (#ifdef DEBUG)
 1.8 06-Nov-2000  jdolecek convert to use regex (it used compat regexp previously), g/c now unneded stuff
 1.7 21-Sep-1997  enami Cosmetic changes:

- Use syslog(..., "...%m") instead of syslog(..., "...%s",
strerror(errno)).
- Don't put a simple and single statement into a block.
- Indent continuation line by four space.
- Add an empty line at the beginning of a function if it doesn't have
local variable.
- Use err() or errx() instead of fprintf(stderr, "progname: ....\n")
and exit() (there was two place left).
- Use MOUNT_PORTAL, which is defined as "portal" in sys/mount.h,
instead of using "portal" directly.
- Fold long line to fit column < 80.
 1.6 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.5 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.4 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.12.78.1 10-Jun-2019  christos Sync with HEAD
 1.24 23-May-2019  wiz Remove superfluous Pp.
 1.23 23-May-2019  kre Better handling of comments in portal.conf ... # now only introduces
a comment at beginning of line, or after whitespace. This allows #
to be used as data otherwhere in the line (there is no escape mechanism).
 1.22 03-Jul-2017  wiz branches: 1.22.6;
Remove workaround for ancient HTML generation code.
 1.21 05-Dec-2009  pooka Note conversion to puffs for the kernel driver.
 1.20 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.18 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.17 01-Oct-2002  wiz Use more markup.
 1.16 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.15 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.14 16-Nov-2001  wiz Use .Pp for paragraphs, sort sections, use standard headers, and a markup fix.
 1.13 16-Nov-2001  wiz Whitespace nits
 1.12 05-Jun-2001  wiz Drop arguments of .Os.
 1.11 06-Nov-2000  jdolecek put in some commas, remove newlines
 1.10 16-Aug-1999  bgrayson branches: 1.10.8;
Initial support for rfilter and wfilter namespaces, in pt_filter.c.
Also, recur into ./examples, to grab the tutorial and example configurations.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.7 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.6 18-Aug-1995  pk Remove junk (from Masanobu Saitoh; PR#1378).
 1.5 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.2 24-Jan-1994  jtc fix formatting
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.10.8.1 09-Nov-2000  tv Pullup 1.11 [jdolecek]:
put in some commas, remove newlines
 1.22.6.1 10-Jun-2019  christos Sync with HEAD
 1.34 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
 1.33 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.32 16-Jul-2007  pooka branches: 1.32.12; 1.32.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.31 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.30 16-Oct-2006  christos use MOPT_NULL
 1.29 09-May-2006  mrg change (mostly) int to socklen_t. GCC 4 doesn't like that int and
socklen_t are different signness.
 1.28 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.27 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.26 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.25 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.24 13-Jul-2003  itojun use bounded string ops
 1.23 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.22 21-Sep-2002  christos MNT_GETARGS support
 1.21 21-Sep-2002  mycroft select() -> poll()
 1.20 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.19 01-Nov-2001  lukem fix a -Wshadow warning
 1.18 10-Jan-2001  lukem be consistent (both internally and with other programs):
log_err fatal errors
log_warning non-fatal errors & warnings
log_debug debug messages (#ifdef DEBUG)
 1.17 06-Nov-2000  jdolecek use mkdtemp(3) instead of mktemp(3)
call daemon(3) before the mount(2) call, so that we can fill correct pid
to mount tag argument (previous code used getpid() + 1!)
 1.16 17-Jan-2000  bgrayson Remove unneeded syslog() at unmount
 1.15 16-Aug-1999  bgrayson Make life a little easier: warn if the configuration file is not an absolute
path, and under DEBUG, keep stderr around.
 1.14 04-Mar-1999  bgrayson Slightly more useful error messages
 1.13 18-Jul-1998  lukem use AF_LOCAL instead of AF_UNIX
 1.12 17-Feb-1998  kleink Include <sys/time.h>, which is the canonical location of the select()
prototype and assorted data type definitions.
 1.11 21-Sep-1997  enami Cosmetic changes:

- Use syslog(..., "...%m") instead of syslog(..., "...%s",
strerror(errno)).
- Don't put a simple and single statement into a block.
- Indent continuation line by four space.
- Add an empty line at the beginning of a function if it doesn't have
local variable.
- Use err() or errx() instead of fprintf(stderr, "progname: ....\n")
and exit() (there was two place left).
- Use MOUNT_PORTAL, which is defined as "portal" in sys/mount.h,
instead of using "portal" directly.
- Fold long line to fit column < 80.
 1.10 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.9 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.8 13-Apr-1996  jtc Add const qualifier to mopts table
 1.7 23-Mar-1996  mrg add a SIGTERM handler to unmount the portal fs when killed. also put the
right PID in the mount table. from pr#893 <kstailey@leidecker.gsfc.nasa.gov>
 1.6 08-Jun-1995  cgd fd_set *'s really aren't compatible with timeval *'s
 1.5 06-Jun-1995  mycroft Make sure the SIGHUP handler is actually set. Zero the fd_set before using
it.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.2 13-Jan-1994  mycroft Remove some notdefage and link with libutil so we properly daemonize.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.32.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.32.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.5 06-Nov-2000  jdolecek use mkdtemp(3) instead of mktemp(3)
call daemon(3) before the mount(2) call, so that we can fill correct pid
to mount tag argument (previous code used getpid() + 1!)
 1.4 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.4 09-May-2017  kamil Sync example portal.conf with reality

Since day0 nobody implemented pipe, tcplisten, exec modes - eliminate them.
 1.3 18-Mar-1995  cgd branches: 1.3.106;
convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.3.106.1 11-May-2017  pgoyette Sync with HEAD
 1.10 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
 1.9 02-Jul-2007  pooka The kernel socket isn't used by any of the providers, and it's a bit
hard to imagine how it could be used, so get rid of it.
 1.8 02-Jul-2007  pooka * narrow-angle const spray
* make config read return an error if it can't read the config file
 1.7 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.5 16-Aug-1999  bgrayson Initial support for rfilter and wfilter namespaces, in pt_filter.c.
Also, recur into ./examples, to grab the tutorial and example configurations.
 1.4 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.8 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.7 07-Aug-2003  agc branches: 1.7.88;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 16-Aug-1999  bgrayson Initial support for rfilter and wfilter namespaces, in pt_filter.c.
Also, recur into ./examples, to grab the tutorial and example configurations.
 1.5 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.4 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.7.88.1 11-May-2017  pgoyette Sync with HEAD
 1.10 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.9 02-Jul-2007  pooka branches: 1.9.68;
The kernel socket isn't used by any of the providers, and it's a bit
hard to imagine how it could be used, so get rid of it.
 1.8 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 21-Sep-1997  enami Cosmetic changes:

- Use syslog(..., "...%m") instead of syslog(..., "...%s",
strerror(errno)).
- Don't put a simple and single statement into a block.
- Indent continuation line by four space.
- Add an empty line at the beginning of a function if it doesn't have
local variable.
- Use err() or errx() instead of fprintf(stderr, "progname: ....\n")
and exit() (there was two place left).
- Use MOUNT_PORTAL, which is defined as "portal" in sys/mount.h,
instead of using "portal" directly.
- Fold long line to fit column < 80.
 1.5 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.4 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.9.68.1 11-May-2017  pgoyette Sync with HEAD
 1.20 23-May-2019  kre PR bin/54222

Don't use portal_node_reclaim() inappropriately. It frees data we
did not allocate, but which might have been allocated by someone else.

While here, various other cleanups (avoid losing fd's if fork fails,
don't compose mangled st_mode S_IFMT values - puffs or's in what it
thinks is correct to the value we set, one case I saw was producing
0110600 for the mode, the 011 isn't any defined type at all - I'd
never seen ls print a '?' as the first char of ls -l output before!

This is still not really correct, but is I believe, better than before.
 1.19 10-May-2017  christos branches: 1.19.10;
set only the effective user id to the user id of the requesting user so that
we can go back to the original uid later.
 1.18 19-Oct-2013  christos branches: 1.18.16;
fix unused variable warnings.
 1.17 02-Jul-2007  pooka branches: 1.17.36; 1.17.42;
The kernel socket isn't used by any of the providers, and it's a bit
hard to imagine how it could be used, so get rid of it.
 1.16 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 13-Jul-2003  itojun use bounded string ops
 1.13 10-Jan-2001  lukem be consistent (both internally and with other programs):
log_err fatal errors
log_warning non-fatal errors & warnings
log_debug debug messages (#ifdef DEBUG)
 1.12 15-Jan-2000  bgrayson Fix security problem noticed by Alaric Williams:
when giving up root credentials, I was setting the egid and euid,
and forgot to also do gid and uid.
 1.11 16-Aug-1999  bgrayson Changes include:
- user mounts of fs namespace are now possible.
- if read/write access is not possible, fall back to read-only.
- use lose_credentials() as a common method to change UID etc.
(it is also used by the rfilter and wfilter code)
- some KNF changes, while I was here.
 1.10 21-Sep-1997  enami Cosmetic changes:

- Use syslog(..., "...%m") instead of syslog(..., "...%s",
strerror(errno)).
- Don't put a simple and single statement into a block.
- Indent continuation line by four space.
- Add an empty line at the beginning of a function if it doesn't have
local variable.
- Use err() or errx() instead of fprintf(stderr, "progname: ....\n")
and exit() (there was two place left).
- Use MOUNT_PORTAL, which is defined as "portal" in sys/mount.h,
instead of using "portal" directly.
- Fold long line to fit column < 80.
 1.9 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.8 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.7 06-Jun-1995  mycroft Fix debugging printf.
 1.6 06-Jun-1995  mycroft Use setegid() explicitly, just to be safe.
 1.5 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.2 13-Apr-1994  cgd kill warning
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.17.42.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.36.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18.16.1 11-May-2017  pgoyette Sync with HEAD
 1.19.10.1 10-Jun-2019  christos Sync with HEAD
 1.13 12-Apr-2021  mrg properly terminate a buffer after strncpy().
 1.12 14-May-2020  msaitoh Remove extra semicolon.
 1.11 04-Jan-2011  wiz Use pclose for popened handles. Found by cppcheck.
 1.10 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9 02-Jul-2007  pooka branches: 1.9.12; 1.9.14;
The kernel socket isn't used by any of the providers, and it's a bit
hard to imagine how it could be used, so get rid of it.
 1.8 09-Nov-2006  christos replace varstack alloc with malloc.
 1.7 21-Apr-2006  skrll Don't use cast expressions as lvalues as newer versions of gcc warn.
 1.6 21-Mar-2006  christos Coverity CID 782: Don't dereference NULL was not going to happen, but:
1. return error instead of the trashed errno.
2. don't return -1, but return ENAMETOOLONG.
3. eliminate unused code.
 1.5 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.4 10-Jan-2001  lukem be consistent (both internally and with other programs):
log_err fatal errors
log_warning non-fatal errors & warnings
log_debug debug messages (#ifdef DEBUG)
 1.3 17-Jan-2000  bgrayson Fix bug where NULL pointer wasn't checked before dereferencing
 1.2 17-Aug-1999  kleink printf() format warnings for size_t != int; from Peter Seebach in PR bin/8214.
 1.1 16-Aug-1999  bgrayson Initial support for rfilter and wfilter namespaces, in pt_filter.c.
Also, recur into ./examples, to grab the tutorial and example configurations.
 1.9.14.1 18-May-2008  yamt sync with head.
 1.9.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.21 11-Apr-2009  lukem fix sign-compare issues
 1.20 02-Jul-2007  pooka branches: 1.20.22;
The kernel socket isn't used by any of the providers, and it's a bit
hard to imagine how it could be used, so get rid of it.
 1.19 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.
 1.18 01-Mar-2004  itojun unifdef -DINET6. getaddrinfo will always be there, so there's no point in
keeping old code. moreover old code does not traverse list of DNS-returned
addresses.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 13-Jul-2003  itojun use bounded string ops
 1.15 10-Jan-2001  lukem be consistent (both internally and with other programs):
log_err fatal errors
log_warning non-fatal errors & warnings
log_debug debug messages (#ifdef DEBUG)
 1.14 31-Dec-2000  itojun support IPv6. PR 11858 from ura@hiru.aoba.yokohama.jp
 1.13 03-Feb-1998  perry change <strings.h> to <string.h> to fix compiler warning
 1.12 21-Sep-1997  enami Cosmetic changes:

- Use syslog(..., "...%m") instead of syslog(..., "...%s",
strerror(errno)).
- Don't put a simple and single statement into a block.
- Indent continuation line by four space.
- Add an empty line at the beginning of a function if it doesn't have
local variable.
- Use err() or errx() instead of fprintf(stderr, "progname: ....\n")
and exit() (there was two place left).
- Use MOUNT_PORTAL, which is defined as "portal" in sys/mount.h,
instead of using "portal" directly.
- Fold long line to fit column < 80.
 1.11 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.10 15-Sep-1997  lukem * KNF-ify
* update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.9 21-May-1995  mycroft Use inet_aton(), not inet_addr().
 1.8 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 30-May-1994  mycroft Add missing htons(), reported by Thorsten Lockert.
 1.3 14-Jan-1994  cgd update from jsp; add 'priv' keyword to get privileged ports
 1.2 13-Jan-1994  mycroft Fix path name parsing.
 1.1 12-Jan-1994  cgd branches: 1.1.1;
mount_portal command, from jsp
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.20.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.11 04-Apr-2023  rillig mount_portal: fix lint warnings about extern and empty declarations
 1.10 23-May-2019  kre PR bin/54222

Don't use portal_node_reclaim() inappropriately. It frees data we
did not allocate, but which might have been allocated by someone else.

While here, various other cleanups (avoid losing fd's if fork fails,
don't compose mangled st_mode S_IFMT values - puffs or's in what it
thinks is correct to the value we set, one case I saw was producing
0110600 for the mode, the 011 isn't any defined type at all - I'd
never seen ls print a '?' as the first char of ls -l output before!

This is still not really correct, but is I believe, better than before.
 1.9 10-May-2017  christos branches: 1.9.10;
We need to provide a size for getattr for the cp example to work, so cheat
and use fstat() to do it instead of libpuffs.
 1.8 09-May-2017  christos prevent hang on vnode EOF.
 1.7 04-Nov-2012  christos branches: 1.7.20;
include the headers that you need.
 1.6 20-Mar-2012  matt branches: 1.6.2;
Convert to C89 function definitions
 1.5 19-Dec-2011  riastradh Fix error reporting in puffs_framev_enqueue_waitevent and callers.

ok christos
 1.4 29-Aug-2011  joerg branches: 1.4.2;
Use __dead
 1.3 19-Dec-2009  pooka Use CMSG_SPACE() for buffer when receiving file descriptors.
Doesn't break i386 and might be better for sparc64.
 1.2 05-Dec-2009  pooka use puffs_cookie_t. no functional change.
 1.1 05-Dec-2009  pooka Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
(missed new file in change batch)
 1.4.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.4.2.1 17-Apr-2012  yamt sync with head
 1.6.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.7.20.1 11-May-2017  pgoyette Sync with HEAD
 1.9.10.1 10-Jun-2019  christos Sync with HEAD
 1.5 24-Apr-2002  lukem - in <bsd.files.mk>, don't clear FILES after using it, as that prevents
make -V FILES
from being useful (and given that every other variable can be
extracted using make -V, the behaviour was unusually inconsistent
given that the original reason for clearing it doesn't seem to be
relevant anymore)
- use <bsd.prog.mk> instead of directly including <bsd.files.mk>
(and possibly <bsd.man.mk> or <bsd.own.mk>)
- remove obsolete NOPROG
 1.4 11-Dec-2001  bgrayson Changed Makefile to install scripts as executable (SCRIPTS, not as FILES), and
also did name change on them to preserve .sh suffix
 1.3 12-Oct-2001  atatat Install the shell script instead of the perl script
 1.2 11-Oct-2001  atatat Add another example that shows how to map a cvs server into your local
file system so that you can pull random files out of it easily.
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.6 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.5 26-Jul-2003  salo branches: 1.5.88;
netbsd.org->NetBSD.org
 1.4 11-Dec-2001  bgrayson Fixed minor typo in example for cksum /tmp/rc
 1.3 06-Nov-2000  jdolecek fix typo
 1.2 17-Jan-2000  bgrayson Added sysctl examples (read-only sysctls for now)
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.5.88.1 11-May-2017  pgoyette Sync with HEAD
 1.3 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.2 17-Jan-2000  bgrayson branches: 1.2.94;
Added sysctl examples (read-only sysctls for now)
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.2.94.1 11-May-2017  pgoyette Sync with HEAD
 1.7 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.6 02-Jul-2007  pooka branches: 1.6.68;
basesrc is no more
 1.5 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.4 11-Dec-2001  bgrayson Removed 'chmod +x cvs.sh' from instructions -- the script is now installed executable by the Makefile
 1.3 16-Nov-2001  wiz Whitespace nits
 1.2 12-Oct-2001  atatat Remove the perl script from the mount_portal example for cvs and
replace it with a regular sh script.
 1.1 11-Oct-2001  atatat Add another example that shows how to map a cvs server into your local
file system so that you can pull random files out of it easily.
 1.6.68.1 11-May-2017  pgoyette Sync with HEAD
 1.3 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.2 15-Oct-2001  atatat branches: 1.2.90;
Use the new sh script instead of the (now defunct) pl one
 1.1 11-Oct-2001  atatat Add another example that shows how to map a cvs server into your local
file system so that you can pull random files out of it easily.
 1.2.90.1 11-May-2017  pgoyette Sync with HEAD
 1.2 12-Oct-2001  atatat Bye bye, perl script.
 1.1 11-Oct-2001  atatat Add another example that shows how to map a cvs server into your local
file system so that you can pull random files out of it easily.
 1.2 11-Dec-2001  bgrayson Renamed so that .sh suffix is not stripped on install
 1.1 12-Oct-2001  atatat Remove the perl script from the mount_portal example for cvs and
replace it with a regular sh script.
 1.4 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.3 26-Jul-2003  salo branches: 1.3.88;
netbsd.org->NetBSD.org
 1.2 12-Jul-2003  atatat Allow _ in tags
 1.1 11-Dec-2001  bgrayson Renamed so that .sh suffix is not stripped on install
 1.3.88.1 11-May-2017  pgoyette Sync with HEAD
 1.3 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.2 20-Jul-2002  grant branches: 1.2.88;
sweep of errx/warnx, remove unnecessary trailing \n
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.2.88.1 11-May-2017  pgoyette Sync with HEAD
 1.2 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.1 16-Aug-1999  bgrayson branches: 1.1.98;
Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.1.98.1 11-May-2017  pgoyette Sync with HEAD
 1.2 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.1 16-Aug-1999  bgrayson branches: 1.1.98;
Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.1.98.1 11-May-2017  pgoyette Sync with HEAD
 1.3 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.2 11-Oct-2001  atatat Add another example that shows how to map a cvs server into your local
file system so that you can pull random files out of it easily.
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.2 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.1 16-Aug-1999  bgrayson branches: 1.1.98;
Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.1.98.1 11-May-2017  pgoyette Sync with HEAD
 1.4 22-Mar-2020  gutteridge rfilter.2: fix a typo

Reported by Andrius V in PR kern/54889.
 1.3 09-May-2017  kamil branches: 1.3.10;
Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.2 26-Jul-2003  salo branches: 1.2.88;
netbsd.org->NetBSD.org
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.2.88.1 11-May-2017  pgoyette Sync with HEAD
 1.3.10.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.1 16-Aug-1999  bgrayson branches: 1.1.98;
Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.1.98.1 11-May-2017  pgoyette Sync with HEAD
 1.2 11-Dec-2001  bgrayson Renamed so that .sh suffix is not stripped on install
 1.1 17-Jan-2000  bgrayson Added sysctl examples (read-only sysctls for now)
 1.2 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.1 11-Dec-2001  bgrayson Renamed so that .sh suffix is not stripped on install
 1.3 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.2 16-Nov-2001  wiz branches: 1.2.90;
Whitespace nits
 1.1 16-Aug-1999  bgrayson Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.2.90.1 11-May-2017  pgoyette Sync with HEAD
 1.2 09-May-2017  kamil Minor and non-functional enhancements in mount_portal(8)

Since day0 pt_exec.c shipped with a dummy stub for "exec" operation, stop
waiting longer and eliminate it now. This functionality can be achieved
with filters.

Drop FreeBSD CVS repos references. There are certainly still some mirrors
or old mirrors available, but since the project moved to SVN+GIT entirely
drop it.

Add CVS Id - where missing - to the documentation files. This helps users
to determine how recent are the files.
 1.1 16-Aug-1999  bgrayson branches: 1.1.98;
Initial checkin. Contains some tutorial-like examples, plus configurations.
 1.1.98.1 11-May-2017  pgoyette Sync with HEAD
 1.15 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.14 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.13 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.12 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.11 21-Sep-2002  christos MNT_GETARGS support
 1.10 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.9 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.8 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.7 06-May-1997  gwr Use .PATH.c: ...
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Dec-1994  cgd specify man pages the new way.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 12-Jan-1994  cgd update from jsp; no man page yet, so torch the old one (for now)
 1.2 24-Aug-1993  pk Man page added.
 1.1 24-Aug-1993  pk branches: 1.1.1;
mount program for proc filesystem.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.39 18-Apr-2023  jkoshy mount_procfs(8): Document the format of the region descriptor
lines contained in the 'map' and 'maps' special files.
 1.38 08-Jan-2020  ad branches: 1.38.8;
- options NAMECACHE_ENTER_REVERSE is no more.

- Partially sort the list of per-vnode namecache entries by using a TAILQ.
Put the real name to the head, and put dot and dotdot to the tail so that
cache_lookup_reverse() doesn't have to consider them.
 1.37 28-Aug-2017  wiz branches: 1.37.4;
Bump date for previous.
 1.36 28-Aug-2017  kamil Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed
PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).

Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>
 1.35 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.34 24-Feb-2009  pooka branches: 1.34.38;
Note change with linux compat.
 1.33 05-Apr-2007  pooka branches: 1.33.20; 1.33.22;
whooops, bump date also
 1.32 05-Apr-2007  pooka /proc/devices, not /proc/device
 1.31 24-Feb-2007  pooka proc/#/exe is now exposed for all mounts, move it away from linux-only
 1.30 02-Feb-2007  wiz Bump date for previous.
 1.29 02-Feb-2007  alc - sync file list with reality
- add a description for fd/# (with reference to fd(4))
 1.28 03-Oct-2005  wiz branches: 1.28.4;
Bump date for previous.
 1.27 01-Oct-2005  atatat Add "cwd" and "root" symlinks to each process's directory. The cwd
link points to the process's current working directory, and the root
link points to the process's root directory. What else would you
expect?

For directories that are out of reach (caller is in a chroot, target
process is in a different chroot, etc), the links point to "/"
instead.
 1.26 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.25 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.24 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.23 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.22 31-May-2002  atatat Add descriptions of the "self" symbolic link and the "maps" pseudo file.
Also note the kernel option that is required in order to get pathnames
with file backed entries in the "maps" pseudo file.
 1.21 08-Feb-2002  ross branches: 1.21.2;
Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.20 16-Nov-2001  wiz Punctuation fixes, sort SEE ALSO, sort sections, use standard headers.
 1.19 05-Jun-2001  wiz Drop arguments of .Os.
 1.18 17-Jan-2001  fvdl Fix spelling.
 1.17 17-Jan-2001  fvdl Document -o linux option.
 1.16 08-Jun-2000  mason Fixed typo - zonbie -> zombie
 1.15 19-Jul-1999  jlam branches: 1.15.6;
Add description of /proc/#/cmdline to mount_procfs.8.
Closes PR misc/8021.
 1.14 24-Mar-1999  mycroft Remove spurious .ne's.
 1.13 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.12 25-Jan-1999  msaitoh Add /proc/#/map.
 1.11 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.10 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.9 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.8 13-May-1997  mikel fix typos noted by Masanobu Saitoh <msaitoh@spa.is.uec.ac.jp>.
 1.7 28-Apr-1997  mycroft Fix several errors and remove out of date comments.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 25-Aug-1993  cgd df lists filesystem as "proc" -- note this, rather than "procfs"
 1.3 25-Aug-1993  cgd this stuff didn't go in for 0.8a...
 1.2 24-Aug-1993  pk removed trash left over from FTP PUT operation :-(
 1.1 24-Aug-1993  pk branches: 1.1.1;
Man page added.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.15.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.21.2.1 02-Jun-2002  tv Pull up revision 1.22 (requested by atatat in ticket #113):
Add descriptions of the "self" symbolic link and the "maps" pseudo file.
Also note the kernel option that is required in order to get pathnames
with file backed entries in the "maps" pseudo file.
 1.28.4.1 06-Apr-2007  bouyer Pull up following revision(s) (requested by pooka in ticket #535):
sbin/mount_procfs/mount_procfs.8 1.28-1.33
sync file list with reality
add a description for fd/# (with reference to fd(4))
proc/#/exe is now exposed for all mounts, move it away from linux-only
 1.33.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.33.20.1 02-Mar-2009  snj Pull up following revision(s) (requested by pooka in ticket #519):
sbin/mount_procfs/mount_procfs.8: revision 1.34
Note change with linux compat.
 1.34.38.1 12-Apr-2018  martin Pull up following revision(s) (requested by kamil in ticket #713):

sys/modules/procfs/Makefile: revision 1.4
sys/miscfs/procfs/procfs_vfsops.c: revision 1.98
bin/ps/ps.1: revision 1.108
sys/compat/linux/arch/i386/linux_ptrace.c: revision 1.32
sys/miscfs/procfs/procfs_vnops.c: revision 1.198
sys/kern/sys_ptrace_common.c: revision 1.23
sys/kern/sys_ptrace_common.c: revision 1.24
sbin/mount_procfs/mount_procfs.8: revision 1.36
sys/kern/sys_ptrace_common.c: revision 1.25
sys/kern/sys_ptrace.c: revision 1.5
sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.30
sys/sys/proc.h: revision 1.342
sys/kern/sys_ptrace_common.c: revision 1.26
sys/miscfs/procfs/procfs_ctl.c: file removal
sys/kern/sys_ptrace_common.c: revision 1.27
sys/miscfs/procfs/procfs_subr.c: revision 1.109
sys/kern/sys_ptrace_common.c: revision 1.28
sys/secmodel/extensions/secmodel_extensions.c: revision 1.8
sys/kern/sys_ptrace_common.c: revision 1.29
sys/sys/ptrace.h: revision 1.62
sys/compat/netbsd32/netbsd32_signal.c: revision 1.45
share/man/man9/kauth.9: revision 1.109
sys/miscfs/procfs/files.procfs: revision 1.12
sys/compat/netbsd32/netbsd32.h: revision 1.115
sys/miscfs/procfs/procfs.h: revision 1.72
sys/compat/netbsd32/netbsd32_ptrace.c: revision 1.5
sys/kern/kern_sig.c: revision 1.337
sys/sys/kauth.h: revision 1.75
sys/sys/sysctl.h: revision 1.224
sys/kern/sys_ptrace_common.c: revision 1.30
sys/kern/sys_ptrace_common.c: revision 1.31
sys/kern/sys_ptrace_common.c: revision 1.32
sys/kern/sys_ptrace_common.c: revision 1.33
sys/compat/linux/arch/arm/linux_ptrace.c: revision 1.20
sys/kern/sys_ptrace_common.c: revision 1.34
sys/kern/sys_ptrace_common.c: revision 1.36
sys/kern/kern_proc.c: revision 1.207
sys/kern/kern_exit.c: revision 1.269
doc/TODO.ptrace: revision 1.29

Make {s,g}et{db,fp,}regs work again for PK_32 processes
XXX: pullup-8

add disgusting magic to handle compat_netbsd32 as a module.

use process_*reg32 instead of struct *reg32.

Remove the filesystem tracing feature

This is a legacy interface from 4.4BSD, and it was
introduced to overcome shortcomings of ptrace(2) at that time, which are
no longer relevant (performance). Today /proc/#/ctl offers a narrow
subset of ptrace(2) commands and is not applicable for modern
applications use beyond simplistic tracing scenarios.

This removal will simplify kernel internals. Users will still be able to
use all the other /proc files.

This change won't affect other procfs files neither Linux compat
features within mount_procfs(8). /proc/#/ctl isn't available on Linux.

Remove:
- /proc/#/ctl from mount_procfs(8)
- P_FSTRACE note from the documentation of ps(1)
- /proc/#/ctl and filesystem tracing documentation from mount_procfs(8)
- KAUTH_REQ_PROCESS_PROCFS_CTL documentation from kauth(9)
- source code file miscfs/procfs/procfs_ctl.c
- PFSctl and procfs_doctl() from sys/miscfs/procfs/procfs.h
- KAUTH_REQ_PROCESS_PROCFS_CTL from sys/sys/kauth.h
- PSL_FSTRACE (0x00010000) from sys/sys/proc.h
- P_FSTRACE (0x00010000) from sys/sys/sysctl.h

Reduce code complexity after removal of this functionality.

Update TODO.ptrace accordingly: remove two entries about /proc tracing.

Do not keep legacy notes as comments in the headers about removed

PSL_FSTRACE / P_FSTRACE, as this interface had little number of users
(close or equal to zero).
Proposed on tech-kern@.

All filesystem tracing utility users are encouraged to switch to ptrace(2).

Sponsored by <The NetBSD Foundation>

untangle the mess:
- factor out common code
- break each ptrace subcall to its own sub-function
.. more to come ...
- reduce ifdef ugliness by moving it up top.
- factor out PT_IO and make PT_{READ,WRITE}_{I,D} use it
- factor out PT_DUMPCORE
- factor out sendsig code
.. more to come ...

handle siginfo requests for ptrace32

ptrace: Partially undo PT_{READ,WRITE}_{I,D} and unbreak these commands

The refactored code did not work and was generating EFAULT.

Sponsored by <The NetBSD Foundation>

Merge the code back; the problem was that since we are reading/writing
to a kernel address for PT_{READ,WRITE}_{I,D} we need the kernel vmspace.
provide separate read and write functions to accomodate register functions
that need a size argument.

don't ignore error from copyout_piod

Use the proper process (the tracee) to get information about lwps and
registers and the tracer for vmspace.

Add new sysctl(3) entry: security.models.extensions.user_set_dbregs

Model this new sysctl(3) entry after "user_set_cpu_affinity" in the same
level of sysctl(3) switches.

Allow to read unconditionally Debug Registers (no change here). This is
convenient as even if a user of a debugger does not use hardware assisted
watchpoints/breakpoints, a debugger can still prompt these values to store
in an internal cache with context of registers. Reading them should have
no security concerns.

Add a paranoid MI switch that prohibits by default setting these registers
by a regular user (non-superuser). Make this switch disabled by default.
There are enough reserved bits out there to allow using them
unconditionally on hardened hosts.

Features shipped with Debug Registers are optional features in debuggers.
There is no reduction in elementary functionality.

Reviewed by <christos>

Sponsored by <The NetBSD Foundation>
 1.37.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.38.8.1 20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #760):

sbin/mount_procfs/mount_procfs.8: revision 1.39

mount_procfs(8): Document the format of the region descriptor
lines contained in the 'map' and 'maps' special files.
 1.25 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.24 29-Aug-2011  joerg Use __dead
 1.23 23-Feb-2009  pooka Default to -o linux. This prevents programs from not working just
because the -o linux flag was not supplied, i.e. it is the sensible
default. People who absolutely do not want the extra files in
their /proc for whatever aesthetic reason (it's not like they
consume any resources) can do -o nolinux.
 1.22 20-Jul-2008  lukem branches: 1.22.2; 1.22.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.21 16-Jul-2007  pooka branches: 1.21.12; 1.21.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.20 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.19 16-Oct-2006  christos use MOPT_NULL
 1.18 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.17 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.16 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.13 21-Sep-2002  christos MNT_GETARGS support
 1.12 17-Jan-2001  fvdl Add handling of -o linux.
 1.11 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.10 25-Jun-1999  perseant branches: 1.10.8;
Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.9 16-Sep-1997  lukem branches: 1.9.4;
resolve conflicts from lite-2 merge
 1.8 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.7 13-Apr-1996  jtc Add const qualifier to mopts table
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 12-Jan-1994  cgd update from jsp; no man page yet, so torch the old one (for now)
 1.3 25-Aug-1993  pk should not default to read-only mount.
 1.2 24-Aug-1993  pk Man page added.
 1.1 24-Aug-1993  pk branches: 1.1.1;
mount program for proc filesystem.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.9.4.1 05-Sep-1999  he Pull up revision 1.10:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.10.8.1 30-Mar-2001  he Pull up revision 1.12 (via patch, requested by fvdl):
Add some required Linux emulation bits to support the Linux
version of VMware.
 1.21.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.22.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.2.1 26-Feb-2009  snj Pull up following revision(s) (requested by pooka in ticket #495):
sbin/mount_procfs/mount_procfs.c: revision 1.23
Default to -o linux. This prevents programs from not working just
because the -o linux flag was not supplied, i.e. it is the sensible
default. People who absolutely do not want the extra files in
their /proc for whatever aesthetic reason (it's not like they
consume any resources) can do -o nolinux.
 1.6 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.5 14-Jun-2010  pooka naughty naughty, don't peek into src/sys
 1.4 25-Nov-2004  wiz Remove "CFLAGS+=-g".
 1.3 24-Nov-2004  christos Add arguments for ptyfs: slave tty group and mode, so we don't have to
hard-code them in the kernel.
 1.2 11-Nov-2004  jdolecek add -I${NETBSDSRCDIR}/sys into CPPFLAGS, so that this picks up necessary
kernel includes without need to have them installed
 1.1 11-Nov-2004  christos Add userland glue for ptyfs.
 1.14 13-Aug-2014  hannken Adapt to reality -- already open BSD style nodes do not appear on
ptyfs mounts (this changed some months ago).
 1.13 04-Apr-2014  christos branches: 1.13.4;
the bug has been fixed.
 1.12 19-Sep-2012  christos Does not make sense to mount this as NFS, so it is not a bug.
We can now mount multiple instances, but all of them show all the ptys.
 1.11 18-Sep-2012  christos remove -c and chroot option; they are always on now
 1.10 09-Sep-2012  wiz branches: 1.10.2;
Bump date for previous.
 1.9 09-Sep-2012  dholland ptyfs hasn't been experimental in a long time. (noticed by blymn)
 1.8 18-Mar-2009  wiz branches: 1.8.6; 1.8.8; 1.8.10;
Drop trailing whitespace.
 1.7 15-Mar-2009  christos Allow ptyfs to be mounted inside a chrooted environment.
 1.6 30-Apr-2008  martin branches: 1.6.6;
Convert TNF licenses to new 2 clause variant
 1.5 31-Jan-2005  erh branches: 1.5.26; 1.5.28;
Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.4 24-Nov-2004  christos Add arguments for ptyfs: slave tty group and mode, so we don't have to
hard-code them in the kernel.
 1.3 11-Nov-2004  christos Add a license; thanks manu.
 1.2 11-Nov-2004  wiz Nit fixes.
 1.1 11-Nov-2004  christos Add userland glue for ptyfs.
 1.5.28.1 18-May-2008  yamt sync with head.
 1.5.26.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.8.10.1 01-Nov-2012  matt sync with netbsd-6-0-RELEASE.
 1.8.8.2 01-Oct-2012  riz Pull up following revision(s) (requested by christos in ticket #566):
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.11
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.12
sys/fs/ptyfs/ptyfs.h: revision 1.9
sbin/mount_ptyfs/mount_ptyfs.c: revision 1.14
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.43
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.44
Does not make sense to mount this as NFS, so it is not a bug.
We can now mount multiple instances, but all of them show all the ptys.
let us get mounted multiple times.
remove -c and chroot option; they are always on now
Always do the chroot filename mapping; it is pointless not to do it.
 1.8.8.1 13-Sep-2012  riz Pull up following revision(s) (requested by dholland in ticket #552):
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.9
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.10
ptyfs hasn't been experimental in a long time. (noticed by blymn)
Bump date for previous.
 1.8.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.6.1 30-Oct-2012  yamt sync with head
 1.10.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.13.4.1 17-Aug-2014  riz Pull up following revision(s) (requested by hannken in ticket #29):
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.14
sys/fs/ptyfs/ptyfs_vnops.c: revision 1.48
sys/fs/ptyfs/ptyfs_vnops.c: revision 1.49
sys/fs/ptyfs/ptyfs_subr.c: revision 1.30
sys/fs/ptyfs/ptyfs_subr.c: revision 1.31
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.51
sys/fs/ptyfs/ptyfs_subr.c: revision 1.32
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.52
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.53
sys/fs/ptyfs/ptyfs.h: revision 1.13
sys/fs/ptyfs/ptyfs.h: revision 1.14
Needs HASH_SLIST, not HASH_LIST.
Change ptyfs to vcache.
- Use (type, minor) as key.
- Change ptyfs_allocvp to return a referenced vnode and lock where needed.
- Remove unneeded vnode backpointer ptyfs_vnode.
- Keep a single hashlist for pty nodes to make their attributes persistent.
OK: Christos Zoulas
Overflow if *data_len == OSIZE and args->version >= PTYFS_ARGSVERSION.
Sent on tech-kern@, ok christos@
Adapt to reality -- already open BSD style nodes do not appear on
ptyfs mounts (this changed some months ago).
- Add a map of active controlling ptys per mount and no longer abuse
the vnode lifecycle.
- No longer set "recycle" on VOP_INACTIVE().
- Make ptyfs_used_get() private to ptyfs_subr.c
- Stop copying device attributes from traditional ptys on first allocation.
- Remove unneeded argument "lwp" from ptyfs_allocvp() and ptyfs_free_get().
OK: Christos Zoulas
 1.18 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.17 05-Sep-2016  sevan Drop main() prototype.
 1.16 21-Feb-2016  christos Add MOPT_{REL,NO}ATIME as supported by the underlying filesystems.
 1.15 20-Sep-2012  christos add back old options for compatibility, but complain if specified.
 1.14 18-Sep-2012  christos remove -c and chroot option; they are always on now
 1.13 02-Apr-2012  christos branches: 1.13.2;
don't print 2 lines of info, remove the bogus one.
 1.12 29-Aug-2011  joerg branches: 1.12.2; 1.12.4; 1.12.6;
Use __dead
 1.11 21-May-2011  riastradh Make `mount_ptyfs -c' actually work.

The ALTF_* are bit masks, not indices, so use 4, not 3, for the one
after 2. Use 0x on all the values to emphasize this.

ok rmind
 1.10 15-Mar-2009  christos Allow ptyfs to be mounted inside a chrooted environment.
 1.9 20-Jul-2008  lukem branches: 1.9.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.8 16-Jul-2007  pooka branches: 1.8.12; 1.8.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.7 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.6 16-Oct-2006  christos use MOPT_NULL
 1.5 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.4 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.3 27-Nov-2004  christos Add a missing =
 1.2 24-Nov-2004  christos Add arguments for ptyfs: slave tty group and mode, so we don't have to
hard-code them in the kernel.
 1.1 11-Nov-2004  christos Add userland glue for ptyfs.
 1.8.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.9.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.12.6.1 01-Nov-2012  matt sync with netbsd-6-0-RELEASE.
 1.12.4.1 01-Oct-2012  riz Pull up following revision(s) (requested by christos in ticket #566):
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.11
sbin/mount_ptyfs/mount_ptyfs.8: revision 1.12
sys/fs/ptyfs/ptyfs.h: revision 1.9
sbin/mount_ptyfs/mount_ptyfs.c: revision 1.14
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.43
sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.44
Does not make sense to mount this as NFS, so it is not a bug.
We can now mount multiple instances, but all of them show all the ptys.
let us get mounted multiple times.
remove -c and chroot option; they are always on now
Always do the chroot filename mapping; it is pointless not to do it.
 1.12.2.2 30-Oct-2012  yamt sync with head
 1.12.2.1 17-Apr-2012  yamt sync with head
 1.13.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2 23-Jan-2016  christos Define _KERNTYPES for things that need it.
 1.1 14-Jan-2010  pooka Add a generic puffs kernel utility for querying mount arguments.
E.g.:
golem> dtfs -r 'chr 15 25' dtfs /puffs
golem> mount_puffs -o getargs dtfs /puffs
version=26, flags=0x10, root cookie=0xbb90c0c0, root type=VCHR, root size=0, root rdev=0xf19
 1.3 24-Nov-2016  wiz New sentence, new line. Sort SEE ALSO. Fix typo.
 1.2 23-Nov-2016  pho Major rework on mount_puffs(8) so that it can actually start file servers

Now you can do
# mount_puffs -o rdonly rot13fs#/home/foo /mnt/rot13

or in fstab
rot13fs#/home/foo /mnt/rot13 puffs rdonly

to start rot13fs with arguments identical to
# rot13fs -o rdonly /home/foo /mnt/rot13
 1.1 14-Jan-2010  pooka branches: 1.1.28;
Add a generic puffs kernel utility for querying mount arguments.
E.g.:
golem> dtfs -r 'chr 15 25' dtfs /puffs
golem> mount_puffs -o getargs dtfs /puffs
version=26, flags=0x10, root cookie=0xbb90c0c0, root type=VCHR, root size=0, root rdev=0xf19
 1.1.28.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.5 23-Nov-2016  pho Major rework on mount_puffs(8) so that it can actually start file servers

Now you can do
# mount_puffs -o rdonly rot13fs#/home/foo /mnt/rot13

or in fstab
rot13fs#/home/foo /mnt/rot13 puffs rdonly

to start rot13fs with arguments identical to
# rot13fs -o rdonly /home/foo /mnt/rot13
 1.4 29-Aug-2011  joerg branches: 1.4.24;
Use __dead
 1.3 21-May-2010  pooka PUFFSDEVELVERS is a goner
 1.2 14-Jan-2010  pooka from main with return 0;
(Why did I manage to succesfully build n times, including a full
distribution build, without tripping this before ?!?)
 1.1 14-Jan-2010  pooka Add a generic puffs kernel utility for querying mount arguments.
E.g.:
golem> dtfs -r 'chr 15 25' dtfs /puffs
golem> mount_puffs -o getargs dtfs /puffs
version=26, flags=0x10, root cookie=0xbb90c0c0, root type=VCHR, root size=0, root rdev=0xf19
 1.4.24.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.5 04-Dec-2021  pho librefuse: Preparation of a proper API versioning; no more #ifdef woes in user code

The goal is to fully support FUSE API version 3.0 while maintaining
API/ABI compatibility with code written for 2.6 (or even older).

* <fuse.h> now emits a compiler warning if it's included without
defining FUSE_USE_VERSION. It had been silently defaulted to the
latest supported version prior to this change. This is permissive
compared to the original FUSE, as it emits an error instead.

* <fuse.h> now emits a warning if FUSE_USE_VERSION is higher than what
can be provided.

* Added a macro FUSE_MAKE_VERSION(maj, min). It was missing from
librefuse <fuse.h>.

No actual API updates have been made (yet).
 1.4 03-Oct-2018  jmcneill Add libpuffs (fixes sun2 build)
 1.3 28-Nov-2017  wiz branches: 1.3.2; 1.3.4;
Install qemufwcfg(4) and mount_qemufwcfg(8).
 1.2 26-Nov-2017  christos cleanup, knf, remove debugging printf, homebrew alloc macros, types.
 1.1 25-Nov-2017  jmcneill Add virtual filesystem for QEMU Firmware Configuration interface.
 1.3.4.1 10-Jun-2019  christos Sync with HEAD
 1.3.2.1 20-Oct-2018  pgoyette Sync with head
 1.2 26-Nov-2017  christos cleanup, knf, remove debugging printf, homebrew alloc macros, types.
 1.1 25-Nov-2017  jmcneill Add virtual filesystem for QEMU Firmware Configuration interface.
 1.7 22-Jan-2022  pho lib/librefuse: Implement FUSE session API and its signal handling functionality
 1.6 04-Dec-2021  pho librefuse: Preparation of a proper API versioning; no more #ifdef woes in user code

The goal is to fully support FUSE API version 3.0 while maintaining
API/ABI compatibility with code written for 2.6 (or even older).

* <fuse.h> now emits a compiler warning if it's included without
defining FUSE_USE_VERSION. It had been silently defaulted to the
latest supported version prior to this change. This is permissive
compared to the original FUSE, as it emits an error instead.

* <fuse.h> now emits a warning if FUSE_USE_VERSION is higher than what
can be provided.

* Added a macro FUSE_MAKE_VERSION(maj, min). It was missing from
librefuse <fuse.h>.

No actual API updates have been made (yet).
 1.5 30-Nov-2017  wiz Sync (dead) usage with man page.
 1.4 30-Nov-2017  christos clang does not like dead unused functions.
 1.3 26-Nov-2017  christos don't error on unknown options.
 1.2 26-Nov-2017  christos cleanup, knf, remove debugging printf, homebrew alloc macros, types.
 1.1 25-Nov-2017  jmcneill Add virtual filesystem for QEMU Firmware Configuration interface.
 1.3 29-Apr-2020  gson Remove references to "special", as mount_qemufwcfg(8) does not
actually take such an argument. Discussed with jmcneill.
 1.2 28-Nov-2017  wiz Fix typo found by jmcneill.
 1.1 28-Nov-2017  wiz Add mount_qemufwcfg man page for review.
 1.3 26-Nov-2017  christos more cleanups, const
 1.2 26-Nov-2017  christos cleanup, knf, remove debugging printf, homebrew alloc macros, types.
 1.1 25-Nov-2017  jmcneill Add virtual filesystem for QEMU Firmware Configuration interface.
 1.3 26-Nov-2017  christos more cleanups, const
 1.2 26-Nov-2017  christos cleanup, knf, remove debugging printf, homebrew alloc macros, types.
 1.1 25-Nov-2017  jmcneill Add virtual filesystem for QEMU Firmware Configuration interface.
 1.2 04-Sep-2008  pooka Convert to the new mount world order with parseargs.
 1.1 29-Dec-2005  tsutsui branches: 1.1.20; 1.1.24;
Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.1.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.2 12-Sep-2016  sevan Add AUTHORS section.
Bump date.
 1.1 29-Dec-2005  tsutsui Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.8 29-Aug-2011  joerg Use __dead
 1.7 04-Sep-2008  pooka Convert to the new mount world order with parseargs.
 1.6 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.5 16-Jul-2007  pooka branches: 1.5.12; 1.5.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.4 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.3 16-Oct-2006  christos use MOPT_NULL
 1.2 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.1 29-Dec-2005  tsutsui Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.5.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.5.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 04-Sep-2008  pooka branches: 1.1.2; 1.1.4;
Convert to the new mount world order with parseargs.
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 04-Sep-2008  mjf file mount_sysvbfs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:13 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 04-Sep-2008  wrstuden file mount_sysvbfs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:28 +0000
 1.5 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.4 05-Aug-2008  pooka branches: 1.4.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.3 28-Jul-2008  pooka Install mount argument structure header just like every other file system.
 1.2 14-Dec-2007  christos branches: 1.2.4; 1.2.8;
- Use fattr.c functions instead of home brewed ones.
- Use new dehumanize number.
 1.1 10-Sep-2005  jmmv branches: 1.1.10; 1.1.12;
Initial addition of tmpfs, an efficient memory file-system. This project
was developed as part of Google's Summer of Code 2005 program. This
change adds the kernel code, the mount_tmpfs utility, a regression test
suite and does all other related changes to integrate these.

The file-system is still *experimental*. Therefore, it is disabled by
default in all kernels. However, as typically done, a commented-out
entry is added in them to ease its setup.

Note that I haven't commited the required mountd(8) changes to be able
to export tmpfs file-systems because NFS support is still very unstable
and because, before enabling it, I'd like to do some other changes.

OK'ed by my project mentor, William Studenmund (wrstuden@).
 1.1.12.1 27-Dec-2007  mjf Sync with HEAD.
 1.1.10.1 09-Jan-2008  matt sync with HEAD
 1.2.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.4.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.19 12-Apr-2022  andvar s/similarily/similarly/
 1.18 07-Jun-2014  martin Remove reference to (no longer) fixed 4 mbyte kernel memory being reserved,
it is now dynamic.
 1.17 04-Dec-2013  wiz branches: 1.17.2;
Bump date for previous.
 1.16 04-Dec-2013  martin Provide variants of the -s option to allow limiting the tmpfs dynamically
at mount time to 1/Nth or to N percent of the available ram.
 1.15 02-Jun-2013  wiz Improvements from jmc@openbsd.
 1.14 30-Apr-2008  martin branches: 1.14.20; 1.14.26;
Convert TNF licenses to new 2 clause variant
 1.13 13-Feb-2008  rillig branches: 1.13.4; 1.13.6;
The first non-optional parameter is ignored by this program.

ok'ed by jmmv@.
 1.12 03-Jan-2007  jmmv branches: 1.12.4; 1.12.6;
s/tons/lots/, per simonb@'s suggestion. This looks more formal.
 1.11 19-Dec-2006  wiz Nicer macro usage.
 1.10 19-Dec-2006  jmmv Note that meta data is stored in non-pageable memory and the problems this
may carry. Suggested by Greg Troxel in private mail.
 1.9 11-Nov-2006  jmmv tmpfs is not considered experimental any more. OK'ed by core@.
 1.8 24-Dec-2005  jmmv Point to the share/examples/fstab/fstab.ramdisk file for some more information.
 1.7 29-Sep-2005  jmmv Add an EXAMPLES section. Requested by martti@ to clarify the purpose of
the field before the mount point.
 1.6 25-Sep-2005  jmmv Kill reference to tmpfs(9). Noticed by "pancake".
 1.5 25-Sep-2005  jmmv Ignore case of trailing unit specifiers in size measures to remove confusion.
 1.4 25-Sep-2005  jmmv Inherit owner, group and mode of the mount directory so that mounting a
tmpfs over, e.g., /tmp, is trivial.
 1.3 23-Sep-2005  jmmv Kill the tmpfs(9) manual page; it was just documenting internal details of
tmpfs' "API" and was already rotting.

Instead, merge all the relevant comments into the code. This includes
acknowledgements to Google's Summer of Code 2005 program (they were in the
AUTHORS section of tmpfs(9) before), so all the files need to be changed
to include this sentence alongside the title. (Note that this was not a
requirement of the program.)
 1.2 10-Sep-2005  jmmv wiz@ remembers that the preferred way to spell file-system in NetBSD is
file system.
 1.1 10-Sep-2005  jmmv Initial addition of tmpfs, an efficient memory file-system. This project
was developed as part of Google's Summer of Code 2005 program. This
change adds the kernel code, the mount_tmpfs utility, a regression test
suite and does all other related changes to integrate these.

The file-system is still *experimental*. Therefore, it is disabled by
default in all kernels. However, as typically done, a commented-out
entry is added in them to ease its setup.

Note that I haven't commited the required mountd(8) changes to be able
to export tmpfs file-systems because NFS support is still very unstable
and because, before enabling it, I'd like to do some other changes.

OK'ed by my project mentor, William Studenmund (wrstuden@).
 1.12.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.12.4.1 23-Mar-2008  matt sync with HEAD
 1.13.6.1 18-May-2008  yamt sync with head.
 1.13.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.14.26.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.26.1 23-Jun-2013  tls resync from head
 1.14.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.2.1 10-Aug-2014  tls Rebase.
 1.29 21-Feb-2016  christos Add MOPT_{REL,NO}ATIME as supported by the underlying filesystems.
 1.28 30-Apr-2014  christos allow update
 1.27 04-Dec-2013  martin branches: 1.27.2;
Fix err/errx confusion, pointed out by rmind.
 1.26 04-Dec-2013  martin Provide variants of the -s option to allow limiting the tmpfs dynamically
at mount time to 1/Nth or to N percent of the available ram.
 1.25 02-Jun-2013  wiz Sync with man page. From jmc@openbsd.
 1.24 05-Aug-2008  pooka branches: 1.24.18; 1.24.24;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.23 28-Jul-2008  pooka Install mount argument structure header just like every other file system.
 1.22 28-Apr-2008  martin branches: 1.22.2;
Remove clause 3 and 4 from TNF licenses
 1.21 13-Feb-2008  rillig branches: 1.21.4; 1.21.6;
Print the second parameter in the error messages, since the first is
ignored anyway.

ok'ed by jmmv@.

NB: I didn't add a regression test for this because of lack of knowledge,
as the existing tests don't seem to follow the regress/README file.
 1.20 15-Dec-2007  perry convert __attribute__s to applicable cdefs.h macros
 1.19 14-Dec-2007  christos - Use fattr.c functions instead of home brewed ones.
- Use new dehumanize number.
 1.18 16-Jul-2007  pooka branches: 1.18.4; 1.18.6;
Print MNT_GETARGS results in one line to make them display
properly with mount -vvvvvvvvvv
 1.17 16-Jul-2007  pooka Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.16 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.15 16-Oct-2006  christos use MOPT_NULL
 1.14 27-May-2006  yamt remove __POOL_EXPOSE.
 1.13 26-Mar-2006  jmmv There is no need to check for the resulting value of a strto*l call after
ERANGE has been raised. Just remove the extra checks, which were incorrect
anyway in almost all calls because they did not match their corresponding
strto*l function.

This caused mount_tmpfs to not catch some error cases in, e.g., i386, as
strtoll was returning LLONG_MAX instead of LONG_MAX, which are different
in this platform (but not on 64-bit ones).

Problem found by martin@; thanks!
 1.12 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.11 11-Feb-2006  christos define __POOL_EXPOSE.
 1.10 30-Sep-2005  jmmv Do not use stdbool.h; it breaks the build on ports using gcc 2.x (such as
vax). Ew. Pointed out by he@.
 1.9 26-Sep-2005  jmmv Handle overflow errors in dehumanize_number. Noticed by chs@.
 1.8 25-Sep-2005  jmmv Implement the getargs option. I knew the code in the kernel had to be of
some use...
 1.7 25-Sep-2005  jmmv Fix some type mismatch issues (gid_t and uid_t are unsigned); pointed out
by chs@.
 1.6 25-Sep-2005  jmmv Change two variables from size_t to long as they are used with long
values (strtol). Silences a warning from lint.
 1.5 25-Sep-2005  jmmv Ignore case of trailing unit specifiers in size measures to remove confusion.
 1.4 25-Sep-2005  jmmv Inherit owner, group and mode of the mount directory so that mounting a
tmpfs over, e.g., /tmp, is trivial.
 1.3 23-Sep-2005  jmmv Kill the tmpfs(9) manual page; it was just documenting internal details of
tmpfs' "API" and was already rotting.

Instead, merge all the relevant comments into the code. This includes
acknowledgements to Google's Summer of Code 2005 program (they were in the
AUTHORS section of tmpfs(9) before), so all the files need to be changed
to include this sentence alongside the title. (Note that this was not a
requirement of the program.)
 1.2 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.1 10-Sep-2005  jmmv Initial addition of tmpfs, an efficient memory file-system. This project
was developed as part of Google's Summer of Code 2005 program. This
change adds the kernel code, the mount_tmpfs utility, a regression test
suite and does all other related changes to integrate these.

The file-system is still *experimental*. Therefore, it is disabled by
default in all kernels. However, as typically done, a commented-out
entry is added in them to ease its setup.

Note that I haven't commited the required mountd(8) changes to be able
to export tmpfs file-systems because NFS support is still very unstable
and because, before enabling it, I'd like to do some other changes.

OK'ed by my project mentor, William Studenmund (wrstuden@).
 1.18.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.18.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.18.4.2 23-Mar-2008  matt sync with HEAD
 1.18.4.1 09-Jan-2008  matt sync with HEAD
 1.21.6.1 18-May-2008  yamt sync with head.
 1.21.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.21.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.22.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.24.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.24.1 23-Jun-2013  tls resync from head
 1.24.18.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.27.2.1 10-Aug-2014  tls Rebase.
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_tmpfs.h was added on branch mjf-devfs2 on 2008-09-28 11:17:13 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_tmpfs.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:28 +0000
 1.3 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.2 05-Aug-2008  pooka branches: 1.2.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1 02-Feb-2006  reinoud branches: 1.1.20; 1.1.24;
Initial import of a UDF file system implementation for NetBSD.

Add UDF file system mounter.
 1.1.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.2.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.14 16-Oct-2019  maya Switch files copyright Reinoud Zandijk from BSD 4 clause to BSD 2 clause.

OK'd by reinoud in email (from 4 Feb 2019).
 1.13 12-Sep-2016  sevan branches: 1.13.14;
Add HISTORY & AUTHORS section.
Bump date.
 1.12 13-Jul-2009  reinoud Remove the comment on disc space accounting from the bugs section; it has been
fixed.
 1.11 08-Feb-2009  wiz Bump date for previous. New sentence, new line.
 1.10 08-Feb-2009  reinoud branches: 1.10.2;
Add mount_udf(8) option '-c' requesting session closure on unmount and
document it in the manpage.
 1.9 08-Aug-2008  wiz branches: 1.9.2;
Fix Dd argument and remove superfluous empty line.
 1.8 08-Aug-2008  reinoud Update the mount_udf(8) manpage to include the write support.
 1.7 15-May-2008  reinoud Fix missing -s argument.
 1.6 06-Feb-2006  reinoud branches: 1.6.20; 1.6.22; 1.6.24;
Fix 3 more spelling errors and make it pass `spell -b'
 1.5 04-Feb-2006  wiz New sentence, new line; sort SEE ALSO; other minor improvements
 1.4 03-Feb-2006  snj Fix two spelling errors and a typo. From Chris Tribo in PR misc/32715.
 1.3 02-Feb-2006  reinoud Note the support for harddisc partitions and vnd devices and notify users
of the problems that could arise with mapping images of UDF file systems
when using vnd with respect to the sector size.
 1.2 02-Feb-2006  reinoud Remove false notion about harddisc partition and vnd support since it has
been added since.
 1.1 02-Feb-2006  reinoud Initial import of a UDF file system implementation for NetBSD.

Add UDF file system mounter.
 1.6.24.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.6.24.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.6.22.1 18-May-2008  yamt sync with head.
 1.6.20.2 28-Sep-2008  mjf Sync with HEAD.
 1.6.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.2.2 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #447):
sbin/mount_udf/mount_udf.8: revision 1.11
Bump date for previous. New sentence, new line.
 1.9.2.1 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #447):
sbin/mount_udf/mount_udf.8: revision 1.10
sbin/mount_udf/mount_udf.c: revision 1.13
Add mount_udf(8) option '-c' requesting session closure on unmount and
document it in the manpage.
 1.10.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.13.14.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.15 16-Oct-2019  maya Switch files copyright Reinoud Zandijk from BSD 4 clause to BSD 2 clause.

OK'd by reinoud in email (from 4 Feb 2019).
 1.14 21-Feb-2016  christos branches: 1.14.16;
Add MOPT_{REL,NO}ATIME as supported by the underlying filesystems.
 1.13 08-Feb-2009  reinoud Add mount_udf(8) option '-c' requesting session closure on unmount and
document it in the manpage.
 1.12 05-Aug-2008  pooka branches: 1.12.2;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.11 15-Dec-2007  perry branches: 1.11.4; 1.11.8;
convert __attribute__s to applicable cdefs.h macros
 1.10 14-Jul-2007  dsl branches: 1.10.4; 1.10.6;
Add additional 'sizeof args' parameter to mount(2).
 1.9 10-Mar-2007  hubertf - removes unused ctype.h header
- correct comment in mount_nfs/getnfsargs.c: s/Nead/Need/

From: Slava Semushin <php-coder@altlinux.ru>
 1.8 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.7 17-Jan-2007  reinoud Add `-o noatime' support to the mount program. Not relevant for the
read-only implementation currently committed though.
 1.6 16-Oct-2006  christos use MOPT_NULL
 1.5 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.4 02-Feb-2006  christos - pass lint
- check errors
- use EXIT_FOO consistently
- use the fattr.h functions, don't duplicate the code
 1.3 02-Feb-2006  xtraeme KNF
 1.2 02-Feb-2006  xtraeme Fix NetBSD tag.
 1.1 02-Feb-2006  reinoud Initial import of a UDF file system implementation for NetBSD.

Add UDF file system mounter.
 1.10.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.10.4.1 09-Jan-2008  matt sync with HEAD
 1.11.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.12.2.1 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #447):
sbin/mount_udf/mount_udf.8: revision 1.10
sbin/mount_udf/mount_udf.c: revision 1.13
Add mount_udf(8) option '-c' requesting session closure on unmount and
document it in the manpage.
 1.14.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 05-Aug-2008  pooka branches: 1.1.2; 1.1.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.1.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.1 05-Aug-2008  mjf file mount_udf.h was added on branch mjf-devfs2 on 2008-09-28 11:17:14 +0000
 1.1.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.1.2.1 05-Aug-2008  wrstuden file mount_udf.h was added on branch wrstuden-revivesa on 2008-09-18 04:28:28 +0000
 1.12 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.11 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.10 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.9 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.8 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.7 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.6 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.5 06-May-1997  gwr Use .PATH.c: ...
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 22-Dec-1994  cgd specify man pages the new way.
 1.2 03-Aug-1994  deraadt do not need -I/sys
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.21 20-Aug-2019  wiz Sort options in usage.

filesystem -> file system
 1.20 20-Aug-2019  perseant Allow the user to specify the filesystem ID for umapfs at mount time,
allowing a consistent filesystem ID across reboots. Closes PR #54471.
 1.19 11-Sep-2005  wiz branches: 1.19.86;
Use .Fl. From YOMURA Masanori in private mail.
While here, sort options.
 1.18 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.15 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.14 16-Nov-2001  wiz Sort sections.
 1.13 16-Nov-2001  wiz Whitespace nits
 1.12 05-Jun-2001  wiz Drop arguments of .Os.
 1.11 06-Mar-2001  thorpej Make this manual page a lot more helpful.
 1.10 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.9 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.8 15-Nov-1997  msaitoh fix typo
 1.7 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.6 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.5 29-May-1997  cgd Fix broken uses of Dd. Both the mdoc and mdoc.samples pages agree:
.Dd is supposed to be invoked like:
.Dd month day, year
e.g. ".Dd January 25, 1989", rather than:
.Dd "month day, year"
which is what these pages did.
 1.4 05-Mar-1996  thorpej Make the manual page reflect reality, from Dave Carrel <carrel@cisco.com>,
PR #1699.
 1.3 15-Jan-1996  thorpej Remove reference to mount_lofs(8), per Todd Williamson
<toddw@delorean.rb.isl.secom.co.jp> in PR #1783.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.19.86.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.27 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.26 20-Aug-2019  perseant Clean up debugging cruft that somehow made it into my previous commit.
 1.25 20-Aug-2019  wiz Sort options in usage.

filesystem -> file system
 1.24 20-Aug-2019  perseant Allow the user to specify the filesystem ID for umapfs at mount time,
allowing a consistent filesystem ID across reboots. Closes PR #54471.
 1.23 29-Aug-2011  joerg branches: 1.23.42;
Use __dead
 1.22 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.21 16-Jul-2007  pooka branches: 1.21.12; 1.21.16;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.20 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.19 16-Oct-2006  christos use MOPT_NULL
 1.18 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.17 11-Sep-2005  wiz Sync usage with manpage.
 1.16 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.15 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.13 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.12 21-Sep-2002  christos MNT_GETARGS support
 1.11 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.10 08-Jul-1999  wrstuden Update to new mount arguments.
 1.9 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.8 01-Jun-1999  perseant Patch for PRs 5124, 5535: correctly interpret the gid mapping file, rather
than using the last uid map entry for every gid map entry.
 1.7 16-Sep-1997  lukem branches: 1.7.4;
resolve conflicts from lite-2 merge
 1.6 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.5 13-Apr-1996  jtc Add const qualifier to mopts table
 1.4 24-Apr-1995  cgd fix array types to match what the file system wants.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 31-Oct-1994  cgd be more careful with types.
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.7.4.2 05-Sep-1999  he Pull up revision 1.9:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.7.4.1 21-Jun-1999  perry pullup 1.7->1.8 (perseant): fixes a trivial bug in gid handling
 1.21.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.23.42.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.15 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.14 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.13 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.12 22-Mar-2003  jdolecek move getmntopts(3) to libutil, build and install also it's manpage
bump libutil minor
adjust individual mount_*/Makefile to use libutil getmntopts(3)
 1.11 21-Sep-2002  christos MNT_GETARGS support
 1.10 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.9 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.8 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.7 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.6 06-May-1997  gwr Use .PATH.c: ...
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 09-Jan-1995  mycroft This shouldn't be setuid any more.
 1.3 22-Dec-1994  cgd specify man pages the new way.
 1.2 03-Aug-1994  deraadt do not need -I/sys
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.20 07-Jun-2017  abhinav s/filesystem/file system/
 1.19 04-May-2009  wiz Fix typo in Dd argument.
 1.18 05-Feb-2008  ad branches: 1.18.12;
Kill -r. Union makes for a poor nullfs.
 1.17 01-Aug-2007  pooka branches: 1.17.2; 1.17.4; 1.17.8;
Don't re-explain vfs.generic.usermount & friends here.
 1.16 31-Jan-2005  erh branches: 1.16.10; 1.16.12;
Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.15 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.14 07-May-2003  fair Add some mdoc macros. Add text from PR 13878, modified.
 1.13 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.12 16-Nov-2001  wiz branches: 1.12.2;
Sort SEE ALSO, sort sections.
 1.11 16-Nov-2001  wiz Whitespace nits
 1.10 05-Jun-2001  wiz Drop arguments of .Os.
 1.9 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.8 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.7 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.6 30-Jun-1997  phil Note error when FFS does not support whiteouts and how to fix. (PR 3233)
 1.5 15-Jan-1996  thorpej Remove reference to mount_lofs(8), per Todd Williamson
<toddw@delorean.rb.isl.secom.co.jp> in PR #1783.
 1.4 29-Sep-1995  jtc Fixed example. The "-o -b" flags aren't needed unless the arguments
(directory and uniondir) are swapped. (PR #1469).
 1.3 30-May-1995  mycroft Add missing option in example.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.12.2.1 19-Jun-2003  grant Pull up revision 1.14 (requested by fair in ticket #1283):

Add some mdoc macros. Add text from PR 13878, modified.
 1.16.12.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.16.10.1 01-Aug-2007  liamjfoy Pull up following revision(s) (requested by pooka in ticket #807):
sbin/mount_union/mount_union.8: revision 1.17
Don't re-explain vfs.generic.usermount & friends here.
 1.17.8.2 01-Aug-2007  pooka Don't re-explain vfs.generic.usermount & friends here.
 1.17.8.1 01-Aug-2007  pooka file mount_union.8 was added on branch matt-mips64 on 2007-08-01 08:52:08 +0000
 1.17.4.1 18-Feb-2008  mjf Sync with HEAD.
 1.17.2.1 23-Mar-2008  matt sync with HEAD
 1.18.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.23 26-Jul-2020  mlelstv Refactor remaining mount_* commands to use the common pathadj()
function for resolving paths.

Make pathadj() no longer warn about symlinks. Symlinks in /dev are
regularly used in several places like LVM . The warning was also
only visible when calling a mount_* command directly as mount(8)
itself would resolve the path witout warning before passing it to
a mount_* command.
 1.22 29-Aug-2011  joerg Use __dead
 1.21 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.20 05-Feb-2008  ad branches: 1.20.4; 1.20.8;
Kill -r. Union makes for a poor nullfs.
 1.19 16-Jul-2007  pooka branches: 1.19.4; 1.19.6;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.18 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.17 16-Oct-2006  christos use MOPT_NULL
 1.16 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.15 17-Mar-2006  erh Fix Coverity issue 1579. Check retval from getmntopts(). Use freemntopts().
 1.14 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.13 31-Jan-2005  erh Fix PR#3617 and PR#3205: call realpath to convert mount points and paths to
device nodes into absolute paths before using them.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 22-Mar-2003  jdolecek use <> rather than "" for #include mntopts.h
 1.10 19-Mar-2003  christos put this back.
 1.9 19-Mar-2003  christos union moved.
 1.8 21-Sep-2002  christos MNT_GETARGS support
 1.7 30-Oct-2000  jdolecek make the code includable into other programs:
* make static all symbols which do not need to be exported
* rename main() to mount_FOO()
* new main() now just calls mount_FOO(), main() is only compiled in if
MOUNT_NOMAIN is not defined
* a_gid(), a_uid() and a_mask() were put into ../mount/fattr.[ch], local
versions removed
 1.6 25-Jun-1999  perseant Regularize error reporting of mount_* commands for failure of mount(2)
to the form:

mount_xxx: dev on dir: reason for failure
 1.5 16-Sep-1997  lukem branches: 1.5.4;
resolve conflicts from lite-2 merge
 1.4 15-Sep-1997  lukem * update for WARNS=1
* getopt returns -1 not EOF
* fix .Nm usage
 1.3 13-Apr-1996  jtc Add const qualifier to mopts table
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.5.4.1 05-Sep-1999  he Pull up revision 1.6:
Regularize error reporting of mount_* commands for failure of
mount(2) to the form "mount_xxx: dev on dir: reason for failure"
(as opposed to the old "mount_xxx: : reason for failure").
(perseant)
 1.19.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.19.4.1 23-Mar-2008  matt sync with HEAD
 1.20.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.20.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.3 12-Sep-2016  sevan Add HISTORY & AUTHORS section.
Bump date.
 1.2 27-Jun-2011  wiz Various improvements.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.1 05-Oct-1999  darrenr branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1999  darrenr branches: 1.1.1.1.4;
import script to setup directories for maintaining separate boot configs.
 1.1.1.1.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.20 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.19 30-Sep-2005  rpaulo .An -nosplit
 1.18 31-Aug-2004  uwe Drop bogus .Bl/.El uncovered by new mdoc.
 1.17 27-Jun-2003  wiz Quote macro candidate.
 1.16 14-May-2003  wiz setup -> set up.
 1.15 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.14 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.13 06-Jan-2003  wiz Bump date for revert. Use proper mdoc in some places. Avoid \fI and \fP.
Begin new sentences on new lines.
 1.12 06-Jan-2003  seb Introduce a new feature for reverting multiple boot configurations i.e.
effectively making the currently selected configuration the only one
active and removing boot configuration selection menu.
This is accomplished by running 'newbtconf revert'.

From PR bin/17808 by myself. Thanks to gendalia and lukem for the help finding
the right keyword.

Approved by lukem.
 1.11 16-Dec-2002  wiz Remove mention of update, per Kevin P. Neal in PR 19386.
 1.10 21-Nov-2002  wiz Add missing word.
 1.9 01-Oct-2002  wiz Use more mdoc.
 1.8 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.7 16-Nov-2001  wiz Remove unnecessary .Pps, use .Nx for NetBSD, sort sections.
 1.6 20-Aug-2001  wiz precede, not preceed.
 1.5 18-Jun-2001  lukem remove references to /etc/rbootd.conf, since it's the config file for
a little used server daemon which can be controlled with rc.conf in any case.
(xxx: list of files probably should be totally configurable, but that's
another story). from [bin/13061] by matthew green.
 1.4 03-Apr-2001  wiz Xref rc.conf 5, not 8. Whitespace fixes while I'm here.
 1.3 26-Aug-2000  enami Pull down the changes I've just accidently commited into 1.5 branch.
Mainly, .Pa fixes.
 1.2 22-Aug-2000  lukem - add rc.conf.d to list of items to link
- update man page to reflect reality
- use mdoc macros correctly...
 1.1 05-Oct-1999  darrenr branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1999  darrenr branches: 1.1.1.1.4; 1.1.1.1.6;
import script to setup directories for maintaining separate boot configs.
 1.1.1.1.6.4 04-Apr-2001  he Pull up revision 1.4 (requested by wiz):
Xref rc.conf 5, not 8 + whitespace fixes.
 1.1.1.1.6.3 26-Aug-2000  enami Backout previous.
SORRY, I'VE FORGOT THAT I'VE TAGGED THIS MOBIO'S TREE AS netbsd-1.5.
 1.1.1.1.6.2 26-Aug-2000  enami Cosmetic changes resolving conflicts with my local tree. Mainly, use .Pa
for pathnames.
 1.1.1.1.6.1 23-Aug-2000  lukem pull up rev 1.3:
- add rc.conf.d to list of items to link
- update man page to reflect reality
- use mdoc macros correctly...

approved: thorpej
 1.1.1.1.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.9 16-Sep-2018  kre Remove uses of test -o
 1.8 05-Jan-2004  jmmv branches: 1.8.96; 1.8.98;
Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.7 06-Jan-2003  seb Introduce a new feature for reverting multiple boot configurations i.e.
effectively making the currently selected configuration the only one
active and removing boot configuration selection menu.
This is accomplished by running 'newbtconf revert'.

From PR bin/17808 by myself. Thanks to gendalia and lukem for the help finding
the right keyword.

Approved by lukem.
 1.6 05-Jan-2003  seb Newbtconf is supposed to handle directories as well, like /etc/rc.conf.d,
hence fix directory handling.
From PR bin/17807 by myself. Approved by lukem.
 1.5 18-Nov-2001  hubertf Fix typo (etc/config -> etc.config)

Pointed out by Robby Griffin <sysadmin@terc.edu> in PR 14603.
 1.4 18-Jun-2001  lukem remove references to /etc/rbootd.conf, since it's the config file for
a little used server daemon which can be controlled with rc.conf in any case.
(xxx: list of files probably should be totally configurable, but that's
another story). from [bin/13061] by matthew green.
 1.3 22-Aug-2000  lukem - add rc.conf.d to list of items to link
- update man page to reflect reality
- use mdoc macros correctly...
 1.2 11-Oct-1999  darrenr branches: 1.2.4; 1.2.8;
bail if the source config doesn't exist as a directory
 1.1 05-Oct-1999  darrenr branches: 1.1.1;
Initial revision
 1.1.1.1 05-Oct-1999  darrenr import script to setup directories for maintaining separate boot configs.
 1.2.8.1 23-Aug-2000  lukem pull up rev 1.3:
- add rc.conf.d to list of items to link

approved: thorpej
 1.2.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.98.1 10-Jun-2019  christos Sync with HEAD
 1.8.96.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.42 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.41 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.40 08-Feb-2017  rin Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.39 10-Aug-2012  joerg branches: 1.39.14; 1.39.18;
Don't depend on HAVE_GCC being always defined.
 1.38 20-Jun-2011  mrg branches: 1.38.2;
remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.37 06-Mar-2011  bouyer branches: 1.37.2;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.36 09-Aug-2010  pooka branches: 1.36.2;
Add -G, which turns consistency check errors in warnings. The
current testing purpose is to create a file system with
block size > MAXPHYS.

(the check doesn't make that much sense anyway in these days of
mobile file systems, since we're interested in MAXPHYS where we
attempt to mount the file system, not where we happen to create it)
 1.35 20-Dec-2009  dsl Push the mount path for mount_mfs through realpath().
This matches what other fs do.
Fixes PR/20362
 1.34 06-Jun-2009  haad Remove debuging CFLAGS.
 1.33 05-Jun-2009  haad Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.32 29-Aug-2008  gmcgarry Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.31 26-Aug-2006  christos branches: 1.31.18; 1.31.22;
- Deal with wedges and the new disk geometry structures, instead of using
struct disklabel.

Functionality lost:
1. struct disklabel used to be updated to contain bsize, fsize, cpg.
This information was used to locate the alternative superblock in
the filesystem if the primary superblock was corrupted. We need
to find a new place to store this information if we need this
functionality.
2. On vax SMD drives that contained bad sector lists, the newfs program
knew how to get the offset and skip to the correct location in order
to place the label.
 1.30 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.29 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.28 01-Nov-2003  dsl Use fstat(2) to get the partition size (falling back to the label on old
kernels) so that newfs works on vinum (and similar).
Kill the -V hack for vinum.
Don't bother faking up a label for -F and mfs, nothing is needed from it.
Ignore label if special doesn't match DISKPART(sb.st_rdev);
Simplifly logic for default block/frag sizes.
Update man page to match.
WARNS=3.
 1.27 26-Oct-2003  mycroft Remove alpha optimization hack.
 1.26 22-Mar-2003  jdolecek no need for -I${MOUNT} & .PATH: ${MOUNT} now neither
 1.25 22-Mar-2003  tron Remove "getmntopts.c" from list of source files. getmntopts(3) is in
"libutil" now.
 1.24 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.23 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.22 08-Jan-2002  thorpej Use MACHINE_ARCH, not MACHINE.
 1.21 06-Jan-2002  lukem add ugly hack for alpha to crank the optimisation level down to -O1,
because the default -O2 with gcc 2.95.3 builds a non functional newfs
 1.20 04-Jan-2002  lukem remove duplicate MAN= entry
 1.19 04-Jan-2002  lukem move mount_mfs(8) into separate man page
 1.18 29-Jul-2001  lukem enable WARNS=2
 1.17 15-Jan-1999  bouyer #include machine/bswap.h and remove -lutil.
 1.16 18-Mar-1998  bouyer Allow creation of non-native byteorder FFS (via the '-B' option).
 1.15 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.14 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.13 30-Jun-1997  christos Fix compiler warnings.
 1.12 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.11 06-May-1997  gwr Use .PATH.c: ...
 1.10 16-May-1996  thorpej Use getmaxpartitions() from libutil, not a homegrown version.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 22-Dec-1994  cgd specify man pages the new way.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 12-Feb-1994  chopps added -D${MACHINE} for amiga's becuase of differing sizeof (struct disklabel)
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 28-Jul-1993  cgd incorporate changes from 0-9-base to 0-9-ALPHA
 1.3 23-Mar-1993  cgd branches: 1.3.2;
changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.2.1 20-Jul-1993  cgd change all refs to "mfs" to be to "mount_mfs" as is appropriate
 1.31.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.31.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.36.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.37.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.38.2.1 30-Oct-2012  yamt sync with head
 1.39.18.1 21-Apr-2017  bouyer Sync with HEAD
 1.39.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 08-Feb-2017  rin branches: 1.1.2; 1.1.4;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.1.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.4.1 08-Feb-2017  bouyer file Makefile.common was added on branch bouyer-socketcan on 2017-04-21 16:53:14 +0000
 1.1.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.1 08-Feb-2017  pgoyette file Makefile.common was added on branch pgoyette-localcount on 2017-03-20 06:57:02 +0000
 1.20 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.19 18-Apr-2020  jdolecek add NO_IOBUF_ALIGNED to not pull aligned_alloc() for really constrained
boot media
 1.18 08-Feb-2017  rin branches: 1.18.12;
__empty -> __nothing
 1.17 08-Feb-2017  rin switch to __empty
 1.16 08-Feb-2017  rin Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.15 06-Mar-2011  bouyer branches: 1.15.26; 1.15.30;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.14 21-Oct-2009  snj branches: 1.14.2;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.13 26-Aug-2006  christos - Deal with wedges and the new disk geometry structures, instead of using
struct disklabel.

Functionality lost:
1. struct disklabel used to be updated to contain bsize, fsize, cpg.
This information was used to locate the alternative superblock in
the filesystem if the primary superblock was corrupted. We need
to find a new place to store this information if we need this
functionality.
2. On vax SMD drives that contained bad sector lists, the newfs program
knew how to get the offset and skip to the correct location in order
to place the label.
 1.12 15-Jan-2006  dsl Add a '-V verbose' option that controls the amount of info writen to stdout.
0: No output. Default for mount_mfs unless -N specified
1: Output size of partition and cylinder groups.
2: Follow with a progress-bar line of dots (scaled to finish at RH margin)
3: Include a single line of alternate suberblock addresses before progress
bar. Default for newfs.
4: Output lots of lines of alternate superblock numbers that scroll madly
up the screen.
If -N given, newfs/mount_mfs exits before displaying any progress bar.
Output constrained (almost always) to 1 column less than the terminal width.
 1.11 11-Sep-2003  dsl Make mkfs -N work again (was trying to read filesystem).
Correct calculation of number of inodes from density for small filesystems.
Add a '-n inodes' option so that the desired number of inodes can be
explicitly given - init needs this for mfs /dev, -i density is too crude.
 1.10 03-Sep-2003  dsl Ensure the area between the end of the main superblock and the start of the
first alternate superblock is zerod.
Removes any possibility of any programs using a trully out of date
alternate superblock if a filesystem is remade with a larger block size.
 1.9 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.8 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.7 07-Jan-2002  simonb Add the ability for the user, group and permissions of an MFS to be set
on the command line with the -u, -g and -p options respectively.
The old malloc() replacement (and related functions) didn't work with
the libc get{pw,gr}nam() functions so it was removed and a separate
memory allocation function added that is only called to allocate the
space for the MFS file system.
Also use a table for the usage flags instead of multiple fprintf()'s
with "if (mfs)" checks sprinkled through.
 1.6 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.5 30-Aug-2001  lukem some improvements from freebsd/openbsd
- replace the unused fs_headswitch and fs_trkseek with fs_id[2], bringing
our struct fs closer to that in freebsd & openbsd (& solaris FWIW)
- dumpfs: improve warning message when cpc == 0
 1.4 30-Jul-2001  lukem - constify mkfs()'s first arg
- slightly reorder steps in -F image creation
 1.3 01-Dec-2000  simonb Put extern variable declarations in "extern.h".
 1.2 01-Dec-2000  simonb ANSIfy.
 1.1 30-Jun-1997  christos branches: 1.1.12;
Fix compiler warnings.
 1.1.12.3 25-Nov-2001  he Pull up revision 1.6 (requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.1.12.2 25-Nov-2001  he Pull up revision 1.5 (requested by lukem):
Replace unused fs_headswitch/trkseek with fs_id.
 1.1.12.1 24-Nov-2001  he Pull up revisions 1.2-1.3 (requested by lukem):
Jumbo pullup for newfs:
o convert to ANSI function prototypes
o move external variables to extern.h
 1.14.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.15.30.1 21-Apr-2017  bouyer Sync with HEAD
 1.15.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.18.12.1 21-Apr-2020  martin Sync with HEAD
 1.137 10-May-2024  andvar s/superbock/superblock/ in comment.
 1.136 22-Feb-2024  mrg if the window size works but is 0, assume it didn't work and use 80.
 1.135 05-Jul-2023  riastradh Revert "newfs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.134 04-Jul-2023  riastradh newfs(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.133 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.132 17-Nov-2022  chs branches: 1.132.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.131 01-Jan-2022  msaitoh s/sytem/system/
 1.130 20-Aug-2020  riastradh mmap MAP_FAILED audit.
 1.129 17-Apr-2020  jdolecek align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) device
 1.128 08-Feb-2017  rin branches: 1.128.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.127 07-Mar-2016  christos branches: 1.127.2; 1.127.4;
PR/50910: David Binderman: Optimize memset.
 1.126 07-Mar-2016  dholland Terminate expression with a semicolon, instead of accidentally
splicing to the next line with a comma. Noticed by Christos. Has no
actual effect, fortunately. (Compiler output is unchanged.)
 1.125 16-Jun-2015  christos fix error messages containing \n
 1.124 29-Apr-2015  christos - use calloc to zero memory
- pass the proper buffer to mkdir
- fix for apple ufs
 1.123 28-Apr-2015  christos reduce bss usage
 1.122 26-Apr-2014  martin Increase alignement of the global "buf" variable to cover all pointers it
is casted too. Fixes a crash on arm v5.
 1.121 05-Apr-2014  justin branches: 1.121.2;
Iterate over fields of struct seperately to avoid warnings from pedantic compilers
 1.120 23-Jun-2013  dholland Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.119 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.118 23-Jun-2013  dholland Revert accidental commit of the change for PR 47911; got rolled into
other stuff by mistake.
 1.117 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.116 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.115 09-Jun-2013  dholland Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.

(two stragglers in this commit; oops)
 1.114 17-Mar-2013  mlelstv For MFS, no longer use heuristic based on rlimit to determine mmap size.
This is no longer functional with current memory allocation routines.
 1.113 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.112 13-Feb-2012  wiz branches: 1.112.6;
Remove unused variables.
From cppcheck via Henning Petersen in PR 46004.
 1.111 07-Feb-2012  tsutsui Explicitly zap possible Ext2fs magic leftover to prevent
kernel vfs_mountroot() and bootloaders from mis-recognizing
the newfs(8)'ed file system as still Ext2fs.

The problem is reported and the fix is tested by Frank Wille
on current-users@. Also approved by releng.
 1.110 25-Aug-2011  joerg branches: 1.110.2;
Avoid magic manipulation of the format string.
 1.109 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.108 09-Aug-2010  pooka branches: 1.108.2;
Add -G, which turns consistency check errors in warnings. The
current testing purpose is to create a file system with
block size > MAXPHYS.

(the check doesn't make that much sense anyway in these days of
mobile file systems, since we're interested in MAXPHYS where we
attempt to mount the file system, not where we happen to create it)
 1.107 31-Jan-2010  mlelstv Skip handling of APPLEUFS_LABEL if it is smaller than a device block.
In particular:

- newfs will not try to erase the label
- fsck_ffs will not try to validate the label

This lets newfs and fsck work on 2048-byte-per-sector media.

Does Apple UFS support such media and how?
 1.106 07-May-2009  lukem Consistently use FFSv1 or FFSv2
 1.105 11-Apr-2009  lukem fix sign-compare issues
 1.104 08-Dec-2007  jnemeth branches: 1.104.14;
PR/37155 - Marcelo Schmidt -- specifying too large of a size causes segvs
 1.103 27-Nov-2007  tsutsui branches: 1.103.2;
Use powerof2() macro in <sys/param.h> rather than a homegrown version.
 1.102 16-Oct-2006  christos branches: 1.102.2; 1.102.4; 1.102.8;
c99 initializers.
 1.101 26-Aug-2006  christos - Deal with wedges and the new disk geometry structures, instead of using
struct disklabel.

Functionality lost:
1. struct disklabel used to be updated to contain bsize, fsize, cpg.
This information was used to locate the alternative superblock in
the filesystem if the primary superblock was corrupted. We need
to find a new place to store this information if we need this
functionality.
2. On vax SMD drives that contained bad sector lists, the newfs program
knew how to get the offset and skip to the correct location in order
to place the label.
 1.100 21-Jan-2006  simonb Use 64-bit arithmetic to calculate fragsperinodeblk, avoiding 32-bit
overflows for large values of "-i bytes-per-inode".
 1.99 16-Jan-2006  dsl Add '-V' to usage output.
Correct a couple of comments.
 1.98 15-Jan-2006  dsl Add a '-V verbose' option that controls the amount of info writen to stdout.
0: No output. Default for mount_mfs unless -N specified
1: Output size of partition and cylinder groups.
2: Follow with a progress-bar line of dots (scaled to finish at RH margin)
3: Include a single line of alternate suberblock addresses before progress
bar. Default for newfs.
4: Output lots of lines of alternate superblock numbers that scroll madly
up the screen.
If -N given, newfs/mount_mfs exits before displaying any progress bar.
Output constrained (almost always) to 1 column less than the terminal width.
 1.97 11-Jan-2006  dsl Don't look for old superblocks if newfs -N
 1.96 11-Jan-2006  dsl The 'cylinder group' size calculation was incorrect. If the cylinder groups
were full then not enough bits were left for the inode allocation map.
Always put a multiple of 8 fragments (and non-zero) inodes into the eqns
so that answer is correct.
Fix the sum that may discard the last cylinder group if it isn't large enough
to contain all its inodes.
Spotted during some other tests, eg:
$ newfs -s 109610 -n1 -f512 -b4096 -N -O2 -F ./z
CGSIZE miscalculated 4097 > 4096
$
 1.95 11-Jan-2006  dsl Modify previous so that at most 79 (more likely 78) dots are printed, with
at most 1 dot per cylinder group.
This is much more useful for filesystems with very large numbers of cgs.
 1.94 09-Jan-2006  dsl There really isn't any point reporting all the alternate superblocks,
big filesystems can have thousands of them - no one ever writes them down.
After the first line of numbers just output a '.' for each cylinder group.
Also limit the lines to 79 columns so broken terminal emulaters don't
double-space the output lines.
 1.93 05-Jan-2006  hubertf The -b option is really on fsck_ffs, not fsck
Pointed out by Sebastian Schuetz on IRCnet #NetBSD
 1.92 05-Nov-2005  chs don't set fs_maxsymlinklen and fs_old_inodefmt twice,
we set them correctly the first time. fixes PR 26995.
 1.91 23-Aug-2005  tron Use FFS_MAXNAMLEN instead of MAXNAMLEN.
 1.90 19-Aug-2005  christos 64 bit inode changes
 1.89 03-Jun-2005  dbj ufs2 disk addresses in dp2->di_db[] must be swapped with bswap64, not bswap32
 1.88 14-Apr-2004  dbj branches: 1.88.2;
fix support for creating APPLE_UFS filesystems with -v
this addresses pr/23924

this includes most of support for creating fslevel 3 compatible filesystems,
although there is currently no command line option to invoke it when
not using apple_ufs
 1.87 18-Mar-2004  dsl branches: 1.87.2;
Speed up mkfs of ffsv1 by writing inodes more than 8k at a time.
Use mmap() instead of malloc() for temporary buffers so that they
can be unmapped for mfs.
 1.86 07-Mar-2004  dsl Re-instate the old behaviour where 'mount_mfs device mount_pt' would
use the size of 'device' for teh file syste size - fixes pr 18353.
(It might be better to be able to say 50% of the size...)
Fix 'mount_mfs -N ...', as well as supressing the creation of the fs, the -N
inhibits the supression of the prints of the mfs parameters.
 1.85 02-Jan-2004  dbj add uuid field to apple ufs volume label
 1.84 29-Oct-2003  lukem Under no circumstances try to zap an existing superblock at sector 0.
There's no reasonable situation where there will be one there, except if the
disk had data on it previously for some reason. It's significantly more
likely (read "the world until UFS2 was merged") that sector 0(..15)
contains really important stuff like boot blocks and disk labels.

Once again, I ask, why wasn't UFS2 implemented as a separate file
system a la lfs & ext2fs ?
It could have shared a chunk of the kernel code (just like those),
and had different userland tools and a different fs_type.
 1.83 15-Oct-2003  dsl The 'struct partition *pp' is only used to save the block and fragment
sizes (so they can be written back into the disklabel).
Allow pp to be NULL
 1.82 17-Sep-2003  enami Need to write entire sector.
 1.81 11-Sep-2003  dsl Make mkfs -N work again (was trying to read filesystem).
Correct calculation of number of inodes from density for small filesystems.
Add a '-n inodes' option so that the desired number of inodes can be
explicitly given - init needs this for mfs /dev, -i density is too crude.
 1.80 10-Sep-2003  dsl Try very hard to ensure that the correct superblock will be found by
invalidating a host of other possible superblocks.
 1.79 06-Sep-2003  itojun use arc4random
 1.78 04-Sep-2003  itojun s/0x7fffffff/INT32_MAX/
 1.77 04-Sep-2003  itojun use arc4random(3). it is at least better than random(3)
XXX masked topmost bit so that values don't go negative, is it the right thing
to do?
 1.76 03-Sep-2003  dsl Ensure the area between the end of the main superblock and the start of the
first alternate superblock is zerod.
Removes any possibility of any programs using a trully out of date
alternate superblock if a filesystem is remade with a larger block size.
 1.75 03-Sep-2003  dsl Randomise di_igen for the first 2 blocks of inodes for non-UFS2 filesystems.
Randomise di_igen for "/" (and lost+found) for UFS2 filesystems.
Ensure nothing from the lost+found inode leaks into the / inode.
 1.74 21-Aug-2003  dsl Rework of code that sorts out number of cylinder groups and inodes:
- allows less than 'one fragment per inode' (useful for mfs /dev)
- limits number of inodes to 2^31 (they are stored in an int32_t)
- errors if the number of cylinder groups is such that the cylinder group
summary won't fit in the first cylinder group.
- ensures that the last cylinder block contains a valid number of fragments
and inodes, and is not larger than any earlier ones.
- cylinder groups are now created with almost the same size as each other.
Change posted to tech-kern, and no one objected.
 1.73 15-Aug-2003  dsl Avoid allocating a data buffer the size of the cylinder group summary.
Write the summary every time it fills a fragment - except for the first
sector which is written last.
 1.72 15-Aug-2003  dsl Fix layout of printout of alternate superblock list when > 2^32 sectors, use
80 columns (sysinst uses full width these days).
Use {;} instead of , in a couple of places.
Abort if user tries to make a UFS1 filesytem with > 2^31 fragments.
Abort if the cylinder group summary won't fit into the first cylinder group.
Use pread/pwrite and remove a few redundant casts.
 1.71 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.70 02-May-2003  atatat Convert to using gettimeofday(2) instead of time(3) to get the current
time, and stuff as much precision as possible into as many places as
possible. This includes setting the atime, mtime, and ctime on inode
#2 of a freshly created file system, and the birthtime on a new ffs2
filesystem.

Previously these would all be left at zero, and since the birthtime
only gets set when the inode is allocated (and since inode #2 never
gets recycled), inode #2 would always have a birthtime of the epoch.
 1.69 20-Apr-2003  christos PR/5680: Markus Illenseer: Mounting and using broken mfs results into kernel
panic
Fixed by checking two return cases from alloc() that were not checked before.
 1.68 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.67 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.66 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.65 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.64 10-Apr-2002  mycroft Some manual strength reduction.
 1.63 10-Apr-2002  mycroft Remove debugging output.
 1.62 10-Apr-2002  mycroft Use fs_fragshift more. Simplify a bunch of arithmetic involving NSPF().
 1.61 18-Jan-2002  lukem wrap some mfs specific code in #ifdef MFS
 1.60 07-Jan-2002  simonb Add the ability for the user, group and permissions of an MFS to be set
on the command line with the -u, -g and -p options respectively.
The old malloc() replacement (and related functions) didn't work with
the libc get{pw,gr}nam() functions so it was removed and a separate
memory allocation function added that is only called to allocate the
space for the MFS file system.
Also use a table for the usage flags instead of multiple fprintf()'s
with "if (mfs)" checks sprinkled through.
 1.59 31-Dec-2001  lukem don't bother printing a warning about the cylinder group size being
restricted if -c isn't given; it just confuses a user of newfs (and
the cpg info is printed as part of the display anyway), and prints an
unnecessary warning for mount_mfs.
 1.58 13-Dec-2001  lukem clamp bsize to MAXBSIZE
 1.57 14-Oct-2001  lukem fix error reporting in rdfs() and wtfs()
 1.56 24-Sep-2001  lukem the change of calculation of inodes per group in rev 1.52 was far too
aggressive; rework to be a bit less susceptable to round-off error.
now it's likely that the density might not be obtained with a small
filesystem with a large number of inodes (e.g -s 4M -i 1k), but that's
an extremely unlikely corner case that can easily be rectified with
command-line arguments.
fixed provided in private email by Takao Shinohara <shin@sm.sony.co.jp>
should resolve PRs [bin/14049] and [bin/14046]
 1.55 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.54 02-Sep-2001  lukem Incorporate fix by iedowse @ FreeBSD to allow disks with large numbers of
cylinder groups to work correctly, with minor modifications by me to work
with our FFS_EI code. From the FreeBSD commit message:

The ffs superblock includes a 128-byte region for use by temporary
in-core pointers to summary information. An array in this region
(fs_csp) could overflow on filesystems with a very large number of
cylinder groups (~16000 on i386 with 8k blocks). When this happens,
other fields in the superblock get corrupted, and fsck refuses to
check the filesystem.

Solve this problem by replacing the fs_csp array in 'struct fs'
with a single pointer, and add padding to keep the length of the
128-byte region fixed. Update the kernel and userland utilities
to use just this single pointer.

With this change, the kernel no longer makes use of the superblock
fields 'fs_csshift' and 'fs_csmask'. Add a comment to newfs/mkfs.c
to indicate that these fields must be calculated for compatibility
with older kernels.

Reviewed by: mckusick
 1.53 30-Aug-2001  lukem some improvements from freebsd/openbsd
- replace the unused fs_headswitch and fs_trkseek with fs_id[2], bringing
our struct fs closer to that in freebsd & openbsd (& solaris FWIW)
- dumpfs: improve warning message when cpc == 0
 1.52 25-Aug-2001  lukem various calcipg() fixes:
- fix round-off errors when determining the number of inodes per group,
which often resulted in the total number of inodes in the file system
being less than what the density asked for.
now you might get more inodes than requested for a given density,
rather than less.
- if the new inodes/group is <= 0, ensure that it's at least 1, preventing
a possible division by zero or other wacky problems
- use long long instead of quad_t
 1.51 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.50 31-Jul-2001  lukem revert rev 1.48 for now, until i'm sure the malloc (et al) rename is
safe (since there's two separate mallocs using sbrk(2) in that case)

XXX: local malloc provided for mfs memory store allocation; need to
investigate if system (phk) malloc can be used instead.
 1.49 30-Jul-2001  lukem - constify mkfs()'s first arg
- slightly reorder steps in -F image creation
 1.48 30-Jul-2001  lukem rename and hide: malloc->Malloc, calloc->Calloc, free->Free. (remove realloc)
 1.47 27-Jul-2001  lukem improve message describing MAXCSBUFS overflow
 1.46 27-Jul-2001  lukem s/filesystem/file system/
 1.45 26-Jul-2001  lukem clean up for WARNS=2 by renaming some local variables that shadow globals
 1.44 26-Jul-2001  lukem - check return value of calloc() in mkfs()
- in replacement malloc(), if sbrk(2) returns (void *)-1, convert to NULL
before returning
- in replacement calloc(), check return value of malloc() before zeroing result
 1.43 26-Jul-2001  lukem remove unnecessary duplicate initialisation of sblock.fs_clean
 1.42 23-Dec-2000  enami Don't swap clustersum[0]. It's not a cluster summery but block free bitmap.
 1.41 04-Dec-2000  scw Fix a bug introduced by 4.4-Lite:
Don't try to subtract the address of "acg.cg_firstfield" from
"acg.cg_nextfreeoff", as it's already relative to the start of "&acg".
This always worked because the result of the subtraction was
always negative, thus could never be > "sblock.fs_cgsize" ...
 1.40 01-Dec-2000  simonb Put extern variable declarations in "extern.h".
 1.39 01-Dec-2000  simonb ANSIfy.
 1.38 22-May-2000  bouyer branches: 1.38.4;
Check the number of cylinder group summary area against MAXCSBUFS. fsck and
the kernel will happilly trash data after fs_csp[] in the superblock with
a large number of cylinder group.
 1.37 30-Jul-1999  wrstuden Adjust column-sizing code to keep output in 76 character lines, so output
doesn't wrap in sysinst.
 1.36 14-May-1999  wrstuden Make newfs's spare superblock output nicer. Figure out how wide the
largest block number will be, and make the columns wide enough for it. Then
make enough columns to fit in an 80 character window.

Samples: small end & faked up values:

super-block backups (for fsck -b #) at:
32, 176, 272, 416, 512, 656, 752, 896, 992, 1136, 1232, 1376, 1472,
1616, 1712, 1856, 1952, 2096, 2192, 2336, 2432, 2576, 2672, 2816, 2912, 3056,
3152, 3296, 3392, 3536, 3632, 3776, 3872, 4016, 4112, 4256, 4352, 4496, 4592,

For a 155 GB fs we have:

super-block backups (for fsck -b #) at:
128, 65792, 131456, 197120, 262784, 328448, 394112,
459776, 525440, 591104, 656768, 722432, 788096, 853760,
919424, 985088, 1050752, 1116416, 1182080, 1247744, 1313408,
1379072, 1444736, 1510400, 1576064, 1641728, 1707392, 1773056,
...
317462144, 317527808, 317593472, 317659136, 317724800, 317790464, 317856128,
317921792, 317987456, 318053120, 318118784, 318184448, 318250112, 318315776,
318381440, 318447104, 318512768, 318578432,

Now it actually looks like someone's thought about making large fs's. :-)
 1.35 16-Mar-1999  wrstuden branches: 1.35.2;
Modify newfs so that the root node (and lost+found dir, if created)
of the new fs has uid.gid equal to the euid.egid of the process
which made it. This change permits users who have write access to
a device (say a floppy) to create a filesystem that, when mounted,
they have write access to.

This change closes PR bin/5990 from jbernard@ox.mines.edu, and is also the
change requested in PR bin/6276 from "Charles M. Hannum" <mycroft@netbsd.org>
 1.34 11-Mar-1999  wrstuden Modify how the byteswapping of the cylinder summaries is handled. If we
need to swap, allocate a buffer for the swapped summaries rather than using
writebuf. The latter is fixed at 64k, which is only enough room to hold
4096 summaries. Creating an fs with more results in a buffer overrun.

First noted by Matt Jacob mjacob@netbsd.org, and fixed by Albeaus
Bayucan, bayucan@nas.nasa.gov. Minor mods by me.
 1.33 03-Nov-1998  simonb Explicitly zero "node" before we start using it.
 1.32 23-Oct-1998  thorpej Use DINODE_SIZE instead of sizeof(struct dinode). Also, eliminate some
unnecessary pointer casts.
 1.31 01-Apr-1998  kleink Need <time.h> for time() prototype.
 1.30 18-Mar-1998  bouyer Allow creation of non-native byteorder FFS (via the '-B' option).
 1.29 01-Nov-1997  drochner Make "mount_mfs" behave synchronously - don't exit before the mount is
done. This has 2 advantages:
-The calling process can rely on the mounted filesystem.
-We get error messages if the mount system call fails.
 1.28 21-Sep-1997  jeremy branches: 1.28.2;
Quell gcc 2.7.2 initialization warning.
 1.27 16-Sep-1997  lukem * resolve conflicts from lite-2 import
* use int32_t instead of long
 1.26 30-Jun-1997  christos Fix compiler warnings.
 1.25 18-Jun-1995  cgd update for posixified stat structure
 1.24 11-Jun-1995  mycroft Back out previous change.
 1.23 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.22 06-May-1995  jtc flush stdout instead of stderr, so that each block number is displayed
as it is printed. From PR 989.
 1.21 12-Apr-1995  mycroft Set the `clean' flag.
 1.20 21-Mar-1995  cgd short -> int16_t in a couple of places
 1.19 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.18 18-Mar-1995  cgd calculate the 'offset' argument to lseek() in a prettier way, more
consistent with the way fsck(8) does it. no functional change.
 1.17 04-Mar-1995  cgd flush stdout after printing each alternate superblock location.
 1.16 04-Mar-1995  cgd fix up inconsisten uses of lseek(). (three uses. one hard-coded 'whence'
as a number, one used an L_ constant and the other used a SEEK_ constant!)
 1.15 18-Dec-1994  cgd compile against new headers.
 1.14 18-Dec-1994  cgd type size paranoia, and allow one to mount an mfs on the device 'swap',
so that diskless machines can use MFS /tmp directories.
 1.13 31-Oct-1994  cgd types/field names.
 1.12 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.11 20-Jul-1994  cgd fix from Peter Galbavy <peter@alice.wonderland.org>: don't overflow 80cols.
 1.10 20-Jul-1994  cgd fix that annoying 'cgd0: bad magic number' bug
 1.9 08-Jun-1994  mycroft branches: 1.9.2;
Update from 4.4-Lite, with local changes.
 1.8 25-Apr-1994  cgd various grunge
 1.7 01-Apr-1994  cgd off_t death...
 1.6 01-Oct-1993  mycroft Set clean flags.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 28-Jul-1993  cgd incorporate changes from 0-9-base to 0-9-ALPHA
 1.3 23-Mar-1993  cgd branches: 1.3.2;
changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.2.1 20-Jul-1993  cgd change all refs to "mfs" to be to "mount_mfs" as is appropriate
 1.9.2.2 20-Jul-1994  cgd from trunk.
 1.9.2.1 20-Jul-1994  cgd update from trunk.
 1.28.2.1 02-Nov-1997  mellon Pull rev 1.29 up from trunk (drochner)
 1.35.2.1 01-Jun-2000  he Pull up revision 1.38 (requested by bouyer):
Abort if the number of cylinder group summary area is larger than
MAXCSBUFS.
 1.38.4.6 25-Nov-2001  he Pull up revisions 1.52,1.56-1.57 (requested by lukem):
Improve calcipg() calculations, and fix error reporting.
 1.38.4.5 25-Nov-2001  he Pull up revision 1.55 (requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.38.4.4 25-Nov-2001  he Pull up revision 1.54 (requested by lukem):
Change fs_csp[] from being a fixed size to being an array sized
as required. This allows file systems with more than about 15500
cylinder groups (on 32-bit systems) to be used.
 1.38.4.3 25-Nov-2001  he Pull up revision 1.53 (requested by lukem):
Replace unused fs_headswitch/trkseek with fs_id.
 1.38.4.2 25-Nov-2001  he Pull up revision 1.51 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.38.4.1 24-Nov-2001  he Pull up revisions 1.39-1.47 (requested by lukem):
Jumbo pullup for newfs:
o convert to ANSI function prototypes
o move external variables to extern.h
o allow ``m'' suffix in MFS size
o fix cg_firstfield bug introduced in 4.4-Lite
o don't swap clustersum[0], it's a bitmap
o don't unnecessarily set fs_clean twice
o check return vailues of memory allocation functions
o cleanup to reduce compile warnings
o replace ``filesystem'' with ``file system''
o improve warning messages describing the MAXCSBUFS overflow
o manual page typos and other corrections
 1.87.2.2 06-Nov-2005  riz Pull up following revision(s) (requested by chs in ticket #5971):
sbin/newfs/mkfs.c: revision 1.92
don't set fs_maxsymlinklen and fs_old_inodefmt twice,
we set them correctly the first time. fixes PR 26995.
 1.87.2.1 27-Apr-2004  jdc branches: 1.87.2.1.2; 1.87.2.1.4;
Pull up revision 1.88 (requested by dbj in ticket #184)

fix support for creating APPLE_UFS filesystems with -v
this addresses pr/23924

this includes most of support for creating fslevel 3 compatible filesystems,
although there is currently no command line option to invoke it when
not using apple_ufs
 1.87.2.1.4.1 06-Nov-2005  riz Pull up following revision(s) (requested by chs in ticket #5971):
sbin/newfs/mkfs.c: revision 1.92
don't set fs_maxsymlinklen and fs_old_inodefmt twice,
we set them correctly the first time. fixes PR 26995.
 1.87.2.1.2.1 06-Nov-2005  riz Pull up following revision(s) (requested by chs in ticket #5971):
sbin/newfs/mkfs.c: revision 1.92
don't set fs_maxsymlinklen and fs_old_inodefmt twice,
we set them correctly the first time. fixes PR 26995.
 1.88.2.3 30-May-2009  snj Pull up following revision(s) (requested by jnemeth in ticket #2020):
sbin/newfs/mkfs.c: revision 1.104
PR/37155 - Marcelo Schmidt -- specifying too large of a size causes segvs
 1.88.2.2 05-Jan-2006  riz Pull up following revision(s) (requested by hubertf in ticket #1088):
sbin/newfs/mkfs.c: revision 1.93
The -b option is really on fsck_ffs, not fsck
Pointed out by Sebastian Schuetz on IRCnet #NetBSD
 1.88.2.1 06-Nov-2005  tron Pull up following revision(s) (requested by chs in ticket #935):
sbin/newfs/mkfs.c: revision 1.92
don't set fs_maxsymlinklen and fs_old_inodefmt twice,
we set them correctly the first time. fixes PR 26995.
 1.102.8.1 09-Jan-2008  matt sync with HEAD
 1.102.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.102.2.1 02-Feb-2008  riz Pull up following revision(s) (requested by jnemeth in ticket #1024):
sbin/newfs/mount_mfs.8: revision 1.15
sbin/newfs/mkfs.c: revision 1.104
PR/37503 - De Zeurkous -- inaccurate description of -s option
PR/37155 - Marcelo Schmidt -- specifying too large of a size causes segvs
 1.103.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.103.2.1 27-Nov-2007  mjf file mkfs.c was added on branch mjf-devfs on 2007-12-27 00:47:02 +0000
 1.104.14.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.108.2.2 08-Feb-2011  bouyer Q2V -> QL
 1.108.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.110.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.110.2.2 23-Jan-2013  yamt sync with head
 1.110.2.1 17-Apr-2012  yamt sync with head
 1.112.6.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.112.6.2 23-Jun-2013  tls resync from head
 1.112.6.1 25-Feb-2013  tls resync with head
 1.121.2.1 10-Aug-2014  tls Rebase.
 1.127.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.127.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.128.12.1 21-Apr-2020  martin Sync with HEAD
 1.132.2.2 11-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #835):

sbin/newfs/mkfs.c: revision 1.136

if the window size works but is 0, assume it didn't work and use 80.
 1.132.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.18 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.17 12-Sep-2016  sevan Memory File System support appeared in 4.4BSD, implemented as an extension to
newfs(8). So while newfs may have appeared in 4.2BSD, MFS support was later.
https://svnweb.freebsd.org/csrg/sbin/newfs/Makefile?r1=39047&r2=39051
Adjust HISTORY.
Bump date.
 1.16 18-Feb-2010  wiz Fix typo (specifed -> specified).
 1.15 08-Dec-2007  jnemeth PR/37503 - De Zeurkous -- inaccurate description of -s option
 1.14 15-Jan-2006  dsl branches: 1.14.4; 1.14.6; 1.14.10; 1.14.12;
Add a '-V verbose' option that controls the amount of info writen to stdout.
0: No output. Default for mount_mfs unless -N specified
1: Output size of partition and cylinder groups.
2: Follow with a progress-bar line of dots (scaled to finish at RH margin)
3: Include a single line of alternate suberblock addresses before progress
bar. Default for newfs.
4: Output lots of lines of alternate superblock numbers that scroll madly
up the screen.
If -N given, newfs/mount_mfs exits before displaying any progress bar.
Output constrained (almost always) to 1 column less than the terminal width.
 1.13 05-Aug-2005  jmmv Replace a dot with a colon, as a list of items follows it.
 1.12 11-Sep-2003  dsl Change date on man pages
 1.11 11-Sep-2003  dsl Make mkfs -N work again (was trying to read filesystem).
Correct calculation of number of inodes from density for small filesystems.
Add a '-n inodes' option so that the desired number of inodes can be
explicitly given - init needs this for mfs /dev, -i density is too crude.
 1.10 21-Aug-2003  dsl Update date for last.
 1.9 21-Aug-2003  dsl Remove unimplemented -n rotational positions
Remove depracated -c cpg (had been fragments per group in newfs.c, but...)
I might add something to let MINCYL (= 4) be configurable.
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 21-Dec-2002  wiz Add a BUGS section describing that async mounts are currently disabled,
and explaining the reason. From Julio Merino.
 1.6 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.5 20-Aug-2002  wiz Drop superfluous Ns.
 1.4 21-May-2002  lukem Add examples. Inspired by [misc/16193] from
Brian A. Seklecki <lavalamp@hurt.spiritual-machines.org>
 1.3 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.2 07-Jan-2002  simonb Add the ability for the user, group and permissions of an MFS to be set
on the command line with the -u, -g and -p options respectively.
The old malloc() replacement (and related functions) didn't work with
the libc get{pw,gr}nam() functions so it was removed and a separate
memory allocation function added that is only called to allocate the
space for the MFS file system.
Also use a table for the usage flags instead of multiple fprintf()'s
with "if (mfs)" checks sprinkled through.
 1.1 04-Jan-2002  lukem move mount_mfs(8) into separate man page
 1.14.12.1 27-Dec-2007  mjf Sync with HEAD.
 1.14.10.1 09-Jan-2008  matt sync with HEAD
 1.14.6.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.14.4.1 02-Feb-2008  riz Pull up following revision(s) (requested by jnemeth in ticket #1024):
sbin/newfs/mount_mfs.8: revision 1.15
sbin/newfs/mkfs.c: revision 1.104
PR/37503 - De Zeurkous -- inaccurate description of -s option
PR/37155 - Marcelo Schmidt -- specifying too large of a size causes segvs
 1.86 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.85 13-Apr-2019  maya Omit mention of old vnd(4) bug, now resolved.

Via elge, thanks.
 1.84 03-Jul-2017  wiz branches: 1.84.6;
Remove workaround for ancient HTML generation code.
 1.83 30-Jun-2012  tsutsui Use 32KB/4KB for default block/fragment size on >= 128 GB partitions
for modern AFT disks. No particular comments against PR install/46629.
 1.82 14-May-2011  dholland branches: 1.82.4; 1.82.6;
Improve documentation of FFS formats and format levels from PR 32100.
Prompted also by recent discussion on tech-kern. Bump date.
 1.81 06-Mar-2011  wiz New sentence, new line.
 1.80 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.79 09-Aug-2010  wiz branches: 1.79.2;
Sort option descriptions.
 1.78 09-Aug-2010  pooka Add -G, which turns consistency check errors in warnings. The
current testing purpose is to create a file system with
block size > MAXPHYS.

(the check doesn't make that much sense anyway in these days of
mobile file systems, since we're interested in MAXPHYS where we
attempt to mount the file system, not where we happen to create it)
 1.77 21-Feb-2010  wiz Call the file system "ext2" consistently. Suggested by tsutsui.
 1.76 18-Feb-2010  wiz Pull over some of Jason McIntyre's fixes for newfs_ext2fs.
Suggested by tsutsui.
 1.75 01-Dec-2009  pooka Add note saying that special must be a raw device.
PR bin/42391
 1.74 01-Jul-2009  uwe G/c sentence fragment left over from vinum reference (forgotten in 1.69).
Noticed by bad@ in PR bin/41652
 1.73 10-May-2009  lukem Note that FFSv1 is also known as FFS, UFS, or UFS1.
Note that FFSv2 is also known as UFS2.
Add a reference to Kirk's BSDcon03 paper on UFS2.
 1.72 01-Aug-2008  simonb branches: 1.72.4;
Handle 't' suffix for terabytes for number arguments.
 1.71 08-Mar-2008  reinoud branches: 1.71.4;
Fix small documentation bug as reported in PR#38192 :

FFS -> FFSv1
UFS2 -> FFSv2
 1.70 10-Dec-2007  tsutsui branches: 1.70.4; 1.70.6;
Add Xref newfs_ext2fs(8).
 1.69 25-Feb-2006  christos branches: 1.69.4; 1.69.6; 1.69.10; 1.69.12; 1.69.14;
remove vinum reference.
 1.68 15-Jan-2006  dsl Add a '-V verbose' option that controls the amount of info writen to stdout.
0: No output. Default for mount_mfs unless -N specified
1: Output size of partition and cylinder groups.
2: Follow with a progress-bar line of dots (scaled to finish at RH margin)
3: Include a single line of alternate suberblock addresses before progress
bar. Default for newfs.
4: Output lots of lines of alternate superblock numbers that scroll madly
up the screen.
If -N given, newfs/mount_mfs exits before displaying any progress bar.
Output constrained (almost always) to 1 column less than the terminal width.
 1.67 27-Dec-2005  hubertf Xref newfs_msdos, noted by rabioli on Freenode #NetBSD
 1.66 24-Jun-2005  wiz Bump date for previous.
 1.65 24-Jun-2005  peter Note that flag -a is obsolete. Thanks to Darrin B. Jewell.
Should fix PR/26883 from Hauke Fath.
 1.64 25-Jun-2004  wiz branches: 1.64.2;
Minimally document -d; addresses second part of
PR 25914 by Kouichirou Hiratsuka.
 1.63 01-Nov-2003  wiz eg -> e.g., vinum -> Xr vinum 4.
 1.62 01-Nov-2003  dsl Use fstat(2) to get the partition size (falling back to the label on old
kernels) so that newfs works on vinum (and similar).
Kill the -V hack for vinum.
Don't bother faking up a label for -F and mfs, nothing is needed from it.
Ignore label if special doesn't match DISKPART(sb.st_rdev);
Simplifly logic for default block/frag sizes.
Update man page to match.
WARNS=3.
 1.61 10-Oct-2003  wiz All single letter options are usually combined; add -V to the others.
 1.60 10-Oct-2003  grant bump date for last
 1.59 10-Oct-2003  grog Decribe the V flag.
 1.58 09-Oct-2003  dbj calculate "-s size" values after sectorsize has been fully determined
extend "-s size" argument to allow negative sizes to represent value to
subtract from diskalbel partition size
 1.57 11-Sep-2003  dsl Change date on man pages
 1.56 11-Sep-2003  dsl Make mkfs -N work again (was trying to read filesystem).
Correct calculation of number of inodes from density for small filesystems.
Add a '-n inodes' option so that the desired number of inodes can be
explicitly given - init needs this for mfs /dev, -i density is too crude.
 1.55 03-Sep-2003  dsl fsirand is no longer needed.
 1.54 12-Aug-2003  wiz Bump date for last.
 1.53 12-Aug-2003  dsl Mention and cross reference newfs_lfs and makefs.
 1.52 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.51 03-Apr-2003  wiz Sort options; mention -O default; grammar improvements; use more macros.
 1.50 03-Apr-2003  fvdl The -r option is no more, so delete it from the synopsis line too.
 1.49 03-Apr-2003  tron Document extended "-O" option after UFS2 import.
 1.48 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.47 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.46 12-Oct-2002  wiz Remove some unnecessary ``\&''. Add an 'n' between an 'a' and an 'A'.
 1.45 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.44 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.43 20-Aug-2002  wiz Drop superfluous Ns.
 1.42 06-Apr-2002  dsainty Reverted a small part of 1.30, removing full stops that accidentally got added
in the middle of sentences.
 1.41 20-Feb-2002  lukem change the default back to checking the file system type is '4.2BSD',
and add -I to ignore this check. per discussion with thorpej.
 1.40 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.39 04-Jan-2002  lukem move mount_mfs(8) into separate man page
 1.38 31-Dec-2001  lukem document that default block-size, frag-size, and bytes-per-inode are
now dependent upon file system size
 1.37 30-Dec-2001  lukem Fixes from and/or inspired by FreeBSD:
- Change the default cpg from 16 to 65536, which effectively means
that the largest allowable value for cpg will be computed if it's
not specified with -c or in the disklabel for that partition.
This is much more convenient for users.
- Improve the description of the defaults for various options
 1.36 21-Nov-2001  lukem - For mount_mfs, always ignore the `special' field and just fake up
the label instead. The previous change to use opendisk() prevented
this from working with special fields such as `/dev/wd0b', and this
new method is arguably cleaner anyway. Fixes [misc/14654]
- Don't bother supporting -T for mount_mfs anymore, since it's
superfluous. The option still works (for compatibility reasons), but
it's just ignored and not documented anymore.
- Use an RPM of 10000 instead of 3600 for the fake label (why not :-)
 1.35 16-Nov-2001  wiz Sort SEE ALSO, whitespace nits.
 1.34 16-Nov-2001  lukem - Without -F, use opendisk(3) to find the raw device
- With -F, relax the restriction that the filesystem must be a regular file
 1.33 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.32 31-Aug-2001  lukem fix a couple of typos in option descriptions
 1.31 30-Aug-2001  lukem replace mkfs reference with sentence describing what newfs does (from freebsd)
 1.30 29-Jul-2001  lukem * add -F option: enable creation of file system in a regular file. a "fake"
disklabel is created as per mfs on "swap".
* add -Z option: pre-zero the -F image file before use. this is necessary if
the image is to be used with vnd(4) because by default the files created
with -F have "holes" and vnd doesn't cope with that.
* support 'k', 'm', 'g' suffixes for all options which take numeric arguments.
provide strsuftoi() which performs the parsing mechanism.
* improve man page description of various options
* replace "filesystem" with "file system"
* when displaying usage for mfs, only list mfs options
* minor KNF and WARNS=2 cleanups
 1.29 07-Jun-2001  mrg s/primary swap area/first swap area/
 1.28 05-Jun-2001  wiz Drop arguments of .Os.
 1.27 03-Apr-2001  wiz Don't xref format(8) -- the man pages we have for it (hp300/vax) don't
seem very interesting at all, if not even obsolete.
Whitespace fixes while I'm here.
 1.26 02-Mar-2001  ad Fix typo.
 1.25 01-Dec-2000  simonb For mount_mfs, allow an 'm' suffix to the file system size option to
specify the size of the mfs in megabytes.

Inspired by the Solaris tmpfs "-o size=sz" option.
 1.24 16-May-1999  ad branches: 1.24.8;
Add NOTES section. Indicate that fstype in disklabel should be set to 4.2BSD.
 1.23 16-Mar-1999  wrstuden Modify newfs so that the root node (and lost+found dir, if created)
of the new fs has uid.gid equal to the euid.egid of the process
which made it. This change permits users who have write access to
a device (say a floppy) to create a filesystem that, when mounted,
they have write access to.

This change closes PR bin/5990 from jbernard@ox.mines.edu, and is also the
change requested in PR bin/6276 from "Charles M. Hannum" <mycroft@netbsd.org>
 1.22 07-Mar-1999  mycroft Clean up SYNOPSIS formatting.
 1.21 07-May-1998  mycroft Add a reference to fsirand(8).
 1.20 29-Apr-1998  fair fix bad .Xr references
 1.19 18-Mar-1998  bouyer Allow creation of non-native byteorder FFS (via the '-B' option).
 1.18 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.17 16-Sep-1997  lukem * resolve conflicts from lite-2 import
* use int32_t instead of long
 1.16 15-Sep-1997  lukem * getopt returns -1 not EOF
* fix .Nm usage
 1.15 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.14 26-Dec-1996  mikel eliminate obsolete reference to mkfs(8);
from Klaus Klein <kleink@layla.inka.de>.
also fixed buggy -a flag lines, reference fsck_ffs(8) instead of fsck(8).
 1.13 06-Jun-1996  mrg update to reality. from mike long (pr#2517)
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 18-Dec-1994  cgd adjust the documentation to note that 'swap' can be used instead of a dev.
 1.10 01-Dec-1994  mycroft Use defaults that are more reasonable for modern disks, and document the `-n'
option.
 1.9 16-Jul-1994  jtc Change mfs in Synopsis to mount_mfs.
 1.8 08-Jun-1994  mycroft branches: 1.8.2;
Update from 4.4-Lite, with local changes.
 1.7 20-Apr-1994  cgd back to 10%, per mkm
 1.6 12-Apr-1994  cgd 10 -> 5
 1.5 01-Aug-1993  mycroft Add RCS indentifiers.
 1.4 28-Jul-1993  cgd incorporate changes from 0-9-base to 0-9-ALPHA
 1.3 23-Mar-1993  cgd branches: 1.3.2;
changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.2.1 20-Jul-1993  cgd change all refs to "mfs" to be to "mount_mfs" as is appropriate
 1.8.2.1 20-Jul-1994  cgd update from trunk.
 1.24.8.3 25-Nov-2001  he Pull up revision 1.33 (via patch, requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.24.8.2 24-Nov-2001  he Pull up revisions 1.25-1.26,1.28-1.29,1.31 (requested by lukem):
Jumbo pullup for newfs:
o allow ``m'' suffix in MFS size
o replace ``filesystem'' with ``file system''
o manual page typos and other corrections
 1.24.8.1 04-Apr-2001  he Pull up revision 1.27 (requested by wiz):
Don't xref format(8) -- the man pages we have for it (hp300/vax) don't
seem very interesting at all, if not even obsolete.
Also some whitespace fixes.
 1.64.2.1 29-Dec-2005  riz Pull up following revision(s) (requested by hubertf in ticket #1073):
sbin/newfs/newfs.8: revision 1.67 via patch
Xref newfs_msdos, noted by rabioli on Freenode #NetBSD
 1.69.14.1 09-Mar-2008  bouyer Pull up following revision(s) (requested by reinoud in ticket #1099):
sbin/newfs/newfs.8: revision 1.71
Fix small documentation bug as reported in PR#38192 :
FFS -> FFSv1
UFS2 -> FFSv2
 1.69.12.1 27-Dec-2007  mjf Sync with HEAD.
 1.69.10.2 23-Mar-2008  matt sync with HEAD
 1.69.10.1 09-Jan-2008  matt sync with HEAD
 1.69.6.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.69.4.1 09-Mar-2008  bouyer Pull up following revision(s) (requested by reinoud in ticket #1099):
sbin/newfs/newfs.8: revision 1.71
Fix small documentation bug as reported in PR#38192 :
FFS -> FFSv1
UFS2 -> FFSv2
 1.70.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.70.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.70.4.1 24-Mar-2008  keiichi sync with head.
 1.71.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.72.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.79.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.82.6.1 05-Jul-2012  riz Pull up following revision(s) (requested by tsutsui in ticket #396):
sbin/newfs/newfs.8: revision 1.83
sbin/newfs/newfs.c: revision 1.111
distrib/utils/sysinst/label.c: revision 1.62
Use 32KB/4KB for default block/fragment size on >= 128 GB partitions
for modern AFT disks. No particular comments against PR install/46629.
 1.82.4.1 30-Oct-2012  yamt sync with head
 1.84.6.1 10-Jun-2019  christos Sync with HEAD
 1.120 05-Jul-2023  riastradh Revert "newfs(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.119 04-Jul-2023  riastradh newfs(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.118 17-Nov-2022  chs Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.117 16-Apr-2022  andvar fix various typos in comments and log messages.
 1.116 17-Apr-2020  jdolecek align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) device
 1.115 08-Feb-2017  rin branches: 1.115.12;
Add smaller versions of fsck_ffs(8) and newfs(8) for install media, where
support for Endian-Independent FFS and Apple UFS is disabled unless FFS_EI=1
and APPLE_UFS=1 are added to CRUNCHENV, respectively.

This reduces the size of ramdisk image for atari by over 15KB.

Thanks tsutsui and christos for their useful comments.
 1.114 01-Apr-2016  ryo branches: 1.114.2; 1.114.4;
no need to escape
 1.113 25-Jul-2015  mlelstv Handle getfsspecname errors.
 1.112 25-Oct-2014  mlelstv Support wedge names.

before:
newfs dk1 - formats /dev/rdk1
newfs rdk1 - cannot open /dev/rrdk1
newfs /dev/dk1 - /dev/dk1 is a block-device, use raw device
newfs /dev/rdk1 - formats /dev/rdk1

now:
newfs dk1 - formats /dev/rdk1
newfs rdk1 - cannot open /dev/rrdk1
newfs /dev/dk1 - formats /dev/rdk1 (*)
newfs /dev/rdk1 - formats /dev/rdk1
newfs NAME=wedge - formats /dev/rdk1

(*) getfsspecname() returns the block device which must be translated.
Passing a block device manually cannot be distinguished from this case.
 1.111 30-Jun-2012  tsutsui branches: 1.111.10;
Use 32KB/4KB for default block/fragment size on >= 128 GB partitions
for modern AFT disks. No particular comments against PR install/46629.
 1.110 13-Feb-2012  wiz branches: 1.110.2;
Remove unused variables.
From cppcheck via Henning Petersen in PR 46004.
 1.109 06-Mar-2011  bouyer branches: 1.109.4;
merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.108 09-Aug-2010  pooka branches: 1.108.2;
Add -G to usage, omission pointed out by wiz. Also, make usage format
nicer on a 80col terminal.
 1.107 09-Aug-2010  pooka Add -G, which turns consistency check errors in warnings. The
current testing purpose is to create a file system with
block size > MAXPHYS.

(the check doesn't make that much sense anyway in these days of
mobile file systems, since we're interested in MAXPHYS where we
attempt to mount the file system, not where we happen to create it)
 1.106 20-Dec-2009  dsl Push the mount path for mount_mfs through realpath().
This matches what other fs do.
Fixes PR/20362
 1.105 07-May-2009  lukem Consistently use FFSv1 or FFSv2
 1.104 11-Apr-2009  lukem fix sign-compare issues
 1.103 03-Apr-2009  pooka Issue a better error message if attempting to create a file system
on a block device. Inspired by PR kern/41127.
 1.102 01-Aug-2008  simonb branches: 1.102.2; 1.102.4; 1.102.8;
Handle 't' suffix for terabytes for number arguments.
 1.101 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.100 15-Dec-2007  perry branches: 1.100.4; 1.100.8;
convert __attribute__s to applicable cdefs.h macros
 1.99 16-Jul-2007  pooka branches: 1.99.4; 1.99.6;
Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.98 14-Jul-2007  dsl Add additional 'sizeof args' parameter to mount(2).
 1.97 28-Apr-2007  christos PR/36229: Geoff Wing: uninitialized dkwedge_info structure in mount_mfs
causes random failures
 1.96 25-Nov-2006  christos PR/28884: Izumi Tsutsui: mount_mfs(8) doesn't set default fssize if "swap" is
specified
 1.95 16-Oct-2006  christos c99 initializers.
 1.94 27-Aug-2006  christos Make the "traditional" comment match reality.
 1.93 27-Aug-2006  christos Don't hard-code 3. From our secret user.
 1.92 26-Aug-2006  christos - Deal with wedges and the new disk geometry structures, instead of using
struct disklabel.

Functionality lost:
1. struct disklabel used to be updated to contain bsize, fsize, cpg.
This information was used to locate the alternative superblock in
the filesystem if the primary superblock was corrupted. We need
to find a new place to store this information if we need this
functionality.
2. On vax SMD drives that contained bad sector lists, the newfs program
knew how to get the offset and skip to the correct location in order
to place the label.
 1.91 04-May-2006  christos Since MNT_GETARGS is not allowed when any other flags are set, don't set
ASYNC in the getargs case.
 1.90 21-Mar-2006  christos Always check the results of getmntopts() and free them.
 1.89 16-Jan-2006  dsl Add '-V' to usage output.
Correct a couple of comments.
 1.88 15-Jan-2006  dsl Add a '-V verbose' option that controls the amount of info writen to stdout.
0: No output. Default for mount_mfs unless -N specified
1: Output size of partition and cylinder groups.
2: Follow with a progress-bar line of dots (scaled to finish at RH margin)
3: Include a single line of alternate suberblock addresses before progress
bar. Default for newfs.
4: Output lots of lines of alternate superblock numbers that scroll madly
up the screen.
If -N given, newfs/mount_mfs exits before displaying any progress bar.
Output constrained (almost always) to 1 column less than the terminal width.
 1.87 28-Nov-2005  dsl Include the size we are trying to create in the 'partition to small'
error message.
 1.86 23-Sep-2005  jmmv Apply the NFS exports list rototill patch:

- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.

Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
 1.85 15-Nov-2004  he branches: 1.85.2;
Add a cast to unsigned char when using a ctype function/macro.
 1.84 07-Sep-2004  lukem fix typo
 1.83 25-Jun-2004  wiz Remove last traces of -c, for which the code was removed
last summer; addresses part of PR 25914 by Kouichirou Hiratsuka.
 1.82 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.81 18-Mar-2004  dsl Simplify logic for MNT_GETARGS and MNT_UPDATE of mfs filesystems.
Stop core dump caused by broken 'newfs -mfs' (= mount_mfs) hack when
newfs run with no arguments.
 1.80 07-Mar-2004  dsl Re-instate the old behaviour where 'mount_mfs device mount_pt' would
use the size of 'device' for teh file syste size - fixes pr 18353.
(It might be better to be able to say 50% of the size...)
Fix 'mount_mfs -N ...', as well as supressing the creation of the fs, the -N
inhibits the supression of the prints of the mfs parameters.
 1.79 07-Mar-2004  dsl Make update mounts (to change miniroot ramdisks to rw) take the same short
circuit as MNT_GETARGS.
Fixes PR#24533
 1.78 22-Dec-2003  jmmv Fix typo: numder -> number. From Christian Biere in PR bin/23838.
 1.77 11-Dec-2003  drochner If a disktype was specified, use the disktab information
and don't try the disklabel.
Allows to create a filesystem on a floppy again.
(It is arguably another bug that DIOCGDINFO returns nonsense
for floppies.)
 1.76 01-Nov-2003  wiz KNF: sort includes.
 1.75 01-Nov-2003  dsl Use fstat(2) to get the partition size (falling back to the label on old
kernels) so that newfs works on vinum (and similar).
Kill the -V hack for vinum.
Don't bother faking up a label for -F and mfs, nothing is needed from it.
Ignore label if special doesn't match DISKPART(sb.st_rdev);
Simplifly logic for default block/frag sizes.
Update man page to match.
WARNS=3.
 1.74 15-Oct-2003  dbj initialize llsize and llsizemult to 0
fixes bug noticed by Christopher SEKIYA on tech-kern@
 1.73 10-Oct-2003  wiz Sync look of -V description in usage with other option descriptions.
 1.72 10-Oct-2003  grog Add -V flag for use with Vinum to indicate that the last character of
the device name should not be interpreted as a partition identifier.
 1.71 09-Oct-2003  dbj calculate "-s size" values after sectorsize has been fully determined
extend "-s size" argument to allow negative sizes to represent value to
subtract from diskalbel partition size
 1.70 11-Sep-2003  dsl Make mkfs -N work again (was trying to read filesystem).
Correct calculation of number of inodes from density for small filesystems.
Add a '-n inodes' option so that the desired number of inodes can be
explicitly given - init needs this for mfs /dev, -i density is too crude.
 1.69 03-Sep-2003  dsl Ensure the area between the end of the main superblock and the start of the
first alternate superblock is zerod.
Removes any possibility of any programs using a trully out of date
alternate superblock if a filesystem is remade with a larger block size.
 1.68 21-Aug-2003  dsl Remove -c maxblkspercg (leaving -c xxx ignored).
-c used to specify the number of cylinders per group
- but newfs has ignored cylinders for a while.
Changing what -c meant is just asking for trouble!
I might add something to let MINCYL be changed.
 1.67 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.66 13-Jul-2003  itojun use bounded string op
 1.65 02-Apr-2003  dbj On Apple UFS filesystems, change the default fragment size to 1024
and the default block size to 4096. Issue a warning if values
are used that will not work on Darwin.
 1.64 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.63 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.62 12-Dec-2002  scw Use getlabeloffset() instead of LABELOFFSET.
 1.61 28-Sep-2002  dbj Add support for the Apple UFS variation on ffs
This is the bulk of PR #17345

The general approach is to use a run time deteriminable value
for DIRBLKSIZ. Additional allowances are included for using
MAXSYMLINKLEN with FS_42INODEFMT and a shift in the cylinder group
cluster summary count array. Support is added for managing
the Apple UFS volume label.
 1.60 21-Sep-2002  christos MNT_GETARGS support
 1.59 08-Aug-2002  soren Remove extraneous \n's in {err,warn}{,x} that used to be printfs.
 1.58 20-Feb-2002  lukem change the default back to checking the file system type is '4.2BSD',
and add -I to ignore this check. per discussion with thorpej.
 1.57 16-Feb-2002  thorpej * Undo rev 1.55. While one might think this test is useful, newfs
has historically allowed file systems to be created on non-4.2BSD
partitions, and the ability to do so is quite useful to some people.
* When rewriting the disklabel, don't consider it an error if there's
not a label already on the disk (and thus the rewrite operation fails).
 1.56 18-Jan-2002  lukem fix this if MFS is not #defined
 1.55 15-Jan-2002  lukem If -F isn't given, only newfs(8) partitions of type `4.2BSD'.
 1.54 07-Jan-2002  simonb Add the ability for the user, group and permissions of an MFS to be set
on the command line with the -u, -g and -p options respectively.
The old malloc() replacement (and related functions) didn't work with
the libc get{pw,gr}nam() functions so it was removed and a separate
memory allocation function added that is only called to allocate the
space for the MFS file system.
Also use a table for the usage flags instead of multiple fprintf()'s
with "if (mfs)" checks sprinkled through.
 1.53 30-Dec-2001  augustss Change how default block size is picked. The default block size is used
if there is no command line option and the disklabel gives 0 as the size.
The default used to be 8k, not the default is picked depending on the
file system size. FS < 20M gets 4k, <1G get 8k, and >1G get 16k.
The 16k default was suggested by lukem which FreeBSD is using.
 1.52 30-Dec-2001  lukem Revert rev 1.37 (use disklabel value for cpg if -c isn't given), because
we would rather let the "optimal cpg" calculation kick in at this point.
 1.51 30-Dec-2001  lukem Fixes from and/or inspired by FreeBSD:
- Change the default cpg from 16 to 65536, which effectively means
that the largest allowable value for cpg will be computed if it's
not specified with -c or in the disklabel for that partition.
This is much more convenient for users.
- Improve the description of the defaults for various options
 1.50 13-Dec-2001  lukem constrain bsize and fsize to MAXBSIZE
 1.49 21-Nov-2001  lukem - For mount_mfs, always ignore the `special' field and just fake up
the label instead. The previous change to use opendisk() prevented
this from working with special fields such as `/dev/wd0b', and this
new method is arguably cleaner anyway. Fixes [misc/14654]
- Don't bother supporting -T for mount_mfs anymore, since it's
superfluous. The option still works (for compatibility reasons), but
it's just ignored and not documented anymore.
- Use an RPM of 10000 instead of 3600 for the fake label (why not :-)
 1.48 16-Nov-2001  lukem - Without -F, use opendisk(3) to find the raw device
- With -F, relax the restriction that the filesystem must be a regular file
 1.47 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.46 30-Aug-2001  lukem some improvements from freebsd/openbsd
- replace the unused fs_headswitch and fs_trkseek with fs_id[2], bringing
our struct fs closer to that in freebsd & openbsd (& solaris FWIW)
- dumpfs: improve warning message when cpc == 0
 1.45 08-Aug-2001  lukem when zeroing the image, use fstatfs() to find the optimal block size
(falling back to 8KB) instead of 512. should speed things up.
 1.44 30-Jul-2001  lukem - constify mkfs()'s first arg
- slightly reorder steps in -F image creation
 1.43 29-Jul-2001  lukem * add -F option: enable creation of file system in a regular file. a "fake"
disklabel is created as per mfs on "swap".
* add -Z option: pre-zero the -F image file before use. this is necessary if
the image is to be used with vnd(4) because by default the files created
with -F have "holes" and vnd doesn't cope with that.
* support 'k', 'm', 'g' suffixes for all options which take numeric arguments.
provide strsuftoi() which performs the parsing mechanism.
* improve man page description of various options
* replace "filesystem" with "file system"
* when displaying usage for mfs, only list mfs options
* minor KNF and WARNS=2 cleanups
 1.42 19-Feb-2001  cgd convert to use getprogname()
 1.41 01-Dec-2000  simonb For mount_mfs, allow an 'm' suffix to the file system size option to
specify the size of the mfs in megabytes.

Inspired by the Solaris tmpfs "-o size=sz" option.
 1.40 01-Dec-2000  simonb ANSIfy.
 1.39 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.38 19-May-1999  wrstuden branches: 1.38.8;
If -c not set on command line and the partition has a non-zero cpg
value, use it for the number of cylinders per group. So now the value
in the disklabel does something. :-)
 1.37 19-Jan-1999  tron branches: 1.37.2;
Include "disktab.h" to get prototype for getdiskbyname().
 1.36 22-Oct-1998  mycroft Use the default calculation of maxcontig, based on fs_bsize and MAXPHYS, so
that the cluster summary information is correct for bsize=4k and MAXPHYS=64k.
 1.35 20-Oct-1998  matt vax -> __vax__
 1.34 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.33 18-Mar-1998  bouyer Allow creation of non-native byteorder FFS (via the '-B' option).
 1.32 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.31 19-Nov-1997  drochner mount_mfs: avoid spurious error message if the mount system call returns
for "valid reasons" (ie, "mount -u")
 1.30 01-Nov-1997  drochner Make "mount_mfs" behave synchronously - don't exit before the mount is
done. This has 2 advantages:
-The calling process can rely on the mounted filesystem.
-We get error messages if the mount system call fails.
 1.29 01-Oct-1997  enami branches: 1.29.2;
Don't declare optind and optarg.
 1.28 29-Sep-1997  enami When calling err(3),
- Don't output unnecessary colon and space, and
- Include the name of system call just called.
 1.27 16-Sep-1997  lukem * resolve conflicts from lite-2 import
* use int32_t instead of long
 1.26 15-Sep-1997  lukem * getopt returns -1 not EOF
* fix .Nm usage
 1.25 30-Jun-1997  christos Fix compiler warnings.
 1.24 30-Jun-1997  tls I don't understand just what exactly changed in the past week that the GDINFO ioctl call here would smash the value of 'fd' and fail, but making fd volatile seems to fix it, for this program at least.
 1.23 30-Jan-1997  tls add support for noatime mount flag
 1.22 23-Oct-1996  cgd this file system (according to its source) supports MNT_UPDATE. Therefore
the mount program must recognize the 'update' option.
 1.21 18-Oct-1996  perry Remove #ifdef tahoe conditionals. We have no tahoe port. There is
still a big #if vax in this file which should be removed if possible --
#ifdef MACHINE stuff in mi code is bad.
 1.20 16-May-1996  thorpej Use getmaxpartitions() from libutil, not a homegrown version.
 1.19 28-Jun-1995  thorpej Use sysctl() to determine maxpartitions. Fixes pr #970.
 1.18 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.17 18-Mar-1995  cgd calculate the 'offset' argument to lseek() in a prettier way, more
consistent with the way fsck(8) does it. no functional change.
 1.16 04-Mar-1995  cgd fix up inconsisten uses of lseek(). (three uses. one hard-coded 'whence'
as a number, one used an L_ constant and the other used a SEEK_ constant!)
 1.15 30-Jan-1995  mycroft Use S_IS*().
 1.14 18-Dec-1994  cgd type size paranoia, and allow one to mount an mfs on the device 'swap',
so that diskless machines can use MFS /tmp directories.
 1.13 01-Dec-1994  mycroft Use defaults that are more reasonable for modern disks, and document the `-n'
option.
 1.12 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.11 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.10 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.9 20-Apr-1994  cgd back to 10%, per mkm
 1.8 06-Feb-1994  cgd numeric -> symbolic constant
 1.7 28-Jan-1994  cgd MINFREE defaults to 5% per mckusick
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 28-Jul-1993  cgd incorporate changes from 0-9-base to 0-9-ALPHA
 1.4 18-Apr-1993  mycroft branches: 1.4.2;
Don't mix ANSI and pre-ANSI varargs.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.2 21-Jul-1993  cgd in the last round: one of my changes was wrong, one was ugly.
 1.4.2.1 20-Jul-1993  cgd change all refs to "mfs" to be to "mount_mfs" as is appropriate
 1.29.2.3 23-Oct-1998  cgd pull up rev 1.36 from trunk (mycroft)
 1.29.2.2 19-Nov-1997  mellon Pull rev 1.31 up from trunk (drochner)
 1.29.2.1 02-Nov-1997  mellon Pull rev 1.30 up from trunk (drochner)
 1.37.2.1 10-Oct-2000  he Pull up revision 1.39 (requested by is):
Format string cleanup.
 1.38.8.4 25-Nov-2001  he Pull up revision 1.47 (via patch, requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.38.8.3 25-Nov-2001  he Pull up revision 1.46 (requested by lukem):
Replace unused fs_headswitch/trkseek with fs_id.
 1.38.8.2 24-Nov-2001  he Pull up revisions 1.40-1.41 (requested by lukem):
Jumbo pullup for newfs:
o convert to ANSI function prototypes
o allow ``m'' suffix in MFS size
 1.38.8.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.85.2.1 03-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1672):
sbin/newfs/newfs.c: revision 1.96
PR/28884: Izumi Tsutsui: mount_mfs(8) doesn't set default fssize if "swap" is
specified
 1.99.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.99.4.1 09-Jan-2008  matt sync with HEAD
 1.100.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.100.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.102.8.1 21-Apr-2010  matt sync to netbsd-5
 1.102.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.102.2.1 10-Jun-2009  bouyer Pull up following revision(s) (requested by snj in ticket #803):
sbin/newfs/newfs.c: revision 1.103
Issue a better error message if attempting to create a file system
on a block device. Inspired by PR kern/41127.
 1.108.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.109.4.2 30-Oct-2012  yamt sync with head
 1.109.4.1 17-Apr-2012  yamt sync with head
 1.110.2.1 05-Jul-2012  riz Pull up following revision(s) (requested by tsutsui in ticket #396):
sbin/newfs/newfs.8: revision 1.83
sbin/newfs/newfs.c: revision 1.111
distrib/utils/sysinst/label.c: revision 1.62
Use 32KB/4KB for default block/fragment size on >= 128 GB partitions
for modern AFT disks. No particular comments against PR install/46629.
 1.111.10.2 30-Jul-2015  snj Pull up following revision(s) (requested by mlelstv in ticket #900):
sbin/newfs/newfs.c: revision 1.113
usr.sbin/installboot/installboot.c: revision 1.39
Handle getfsspecname errors.
 1.111.10.1 11-Nov-2014  martin Pull up following revision(s) (requested by mlelstv in ticket #199):
sbin/newfs/newfs.c: revision 1.112
sbin/fsck/fsck.c: revision 1.52
fix logic that handles command line arguments. Now you can:
fsck /mnt/point
fsck dkX
fsck rdkX
fsck /dev/dkX
fsck /dev/rdkX
fsck NAME=wedge
Support wedge names.
before:
newfs dk1 - formats /dev/rdk1
newfs rdk1 - cannot open /dev/rrdk1
newfs /dev/dk1 - /dev/dk1 is a block-device, use raw device
newfs /dev/rdk1 - formats /dev/rdk1
now:
newfs dk1 - formats /dev/rdk1
newfs rdk1 - cannot open /dev/rrdk1
newfs /dev/dk1 - formats /dev/rdk1 (*)
newfs /dev/rdk1 - formats /dev/rdk1
newfs NAME=wedge - formats /dev/rdk1
(*) getfsspecname() returns the block device which must be translated.
Passing a block device manually cannot be distinguished from this case.
 1.114.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.114.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.115.12.1 21-Apr-2020  martin Sync with HEAD
 1.7 07-Oct-2023  rin Drop -O[01] hacks for vax; no longer necessary for patched GCC 10

PR port-vax/57646: Import major vax toolchain fix by Kalvis Duckmanton

XXXRO: GCC 12 may require hacks for a while, but it turned out that
GCC 12 should be treated differently from older versions; a lot of new
files need -O[01] flags, while some may no longer require it.

I will take a look later.

Note that these hacks are not required if Kalvis's patches for GCC 12
are applied.

Keep doc/HACKS entries for a while (will be sync with update for GCC 12).

diff --git a/crypto/external/bsd/openssh/lib/Makefile b/crypto/external/bsd/openssh/lib/Makefile
index 96a93f5e396..4e38be1b642 100644
--- a/crypto/external/bsd/openssh/lib/Makefile
+++ b/crypto/external/bsd/openssh/lib/Makefile
@@ -117,12 +117,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
# XXX
COPTS.channels.c+= -fno-strict-aliasing

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.poly1305.c+= -O0
-COPTS.umac.c+= -O0
-.endif
-
COPTS.hostfile.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.sshkey.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.cipher.c+= -Wno-error=deprecated-declarations
diff --git a/distrib/utils/x_ping/Makefile b/distrib/utils/x_ping/Makefile
index f1c452a0d60..8ee77580a3f 100644
--- a/distrib/utils/x_ping/Makefile
+++ b/distrib/utils/x_ping/Makefile
@@ -12,10 +12,6 @@ CPPFLAGS+= -I${SRCDIR} -DCRUNCHOPS
DPADD= ${LIBM}
LDADD= -lm

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>

.PATH: ${SRCDIR}
diff --git a/external/apache2/argon2/lib/libargon2/Makefile.inc b/external/apache2/argon2/lib/libargon2/Makefile.inc
index d3f4470c6c7..6a1dd146d7d 100644
--- a/external/apache2/argon2/lib/libargon2/Makefile.inc
+++ b/external/apache2/argon2/lib/libargon2/Makefile.inc
@@ -16,7 +16,3 @@ CFLAGS+= -pthread
LDADD+=-lpthread
DPADD+=${LIBPTHREAD}
.endif
-
-.if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-.endif
diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc
index 2f524358f46..d5da774f293 100644
--- a/external/bsd/jemalloc/lib/Makefile.inc
+++ b/external/bsd/jemalloc/lib/Makefile.inc
@@ -53,12 +53,6 @@ COPTS.ctl.c+=-Wno-error=stack-protector
COPTS.stats.c+=-Wno-error=stack-protector
COPTS.tcache.c+=-Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-# in merge_overlapping_regs, at regrename.c
-COPTS.arena.c+=-O0
-COPTS.extent.c+=-O0
-.endif
-
SRCS+=${JEMALLOC_SRCS}

jemalloc.d jemalloc.pico jemalloc.o jemalloc.ln jemalloc.po jemalloc.go: \
diff --git a/external/bsd/mdocml/lib/libmandoc/Makefile b/external/bsd/mdocml/lib/libmandoc/Makefile
index 40d7e29ae88..dfd3077a2c7 100644
--- a/external/bsd/mdocml/lib/libmandoc/Makefile
+++ b/external/bsd/mdocml/lib/libmandoc/Makefile
@@ -39,11 +39,6 @@ tbl_opts.c

MAN= mandoc.3

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.mdoc_macro.c+=-O0
-.endif
-
COPTS.man_validate.c+=-Wno-error=array-bounds

.include <bsd.lib.mk>
diff --git a/external/gpl3/binutils.old/lib/libbfd/Makefile b/external/gpl3/binutils.old/lib/libbfd/Makefile
index 03477232b55..74a354532fa 100644
--- a/external/gpl3/binutils.old/lib/libbfd/Makefile
+++ b/external/gpl3/binutils.old/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/binutils/lib/libbfd/Makefile b/external/gpl3/binutils/lib/libbfd/Makefile
index 00cb2b20081..a3f0c25fd35 100644
--- a/external/gpl3/binutils/lib/libbfd/Makefile
+++ b/external/gpl3/binutils/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/gcc.old/lib/Makefile.sanitizer b/external/gpl3/gcc.old/lib/Makefile.sanitizer
index efd36ae4bee..5173a5109a0 100644
--- a/external/gpl3/gcc.old/lib/Makefile.sanitizer
+++ b/external/gpl3/gcc.old/lib/Makefile.sanitizer
@@ -88,22 +88,3 @@ COPTS+=-fno-builtin -fno-exceptions -fno-rtti -funwind-tables

# Can't profile without it`
#-fomit-frame-pointer
-
-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_allocator.cc += -O1
-COPTS.sanitizer_common.cc += -O1
-COPTS.sanitizer_common_libcdep.cc += -O1
-COPTS.sanitizer_coverage_libcdep.cc += -O1
-COPTS.sanitizer_coverage_mapping_libcdep.cc += -O1
-COPTS.sanitizer_deadlock_detector1.cc += -O1
-COPTS.sanitizer_mac.cc += -O1
-COPTS.sanitizer_netbsd.cc += -O1
-COPTS.sanitizer_posix.cc += -O1
-COPTS.sanitizer_printf.cc += -O1
-COPTS.sanitizer_procmaps_common.cc += -O1
-COPTS.sanitizer_stackdepot.cc += -O1
-COPTS.sanitizer_symbolizer_libcdep.cc += -O1
-COPTS.sanitizer_symbolizer_report.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
diff --git a/external/gpl3/gcc.old/lib/libasan/Makefile b/external/gpl3/gcc.old/lib/libasan/Makefile
index 1e6f9608abe..3da7bbf2f58 100644
--- a/external/gpl3/gcc.old/lib/libasan/Makefile
+++ b/external/gpl3/gcc.old/lib/libasan/Makefile
@@ -49,14 +49,6 @@ LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
LIBDPLIBS+= pthread ${NETBSDSRCDIR}/lib/libpthread
CPPFLAGS+=-DCAN_SANITIZE_UB=0

-.if ${MACHINE_ARCH} == "vax"
-COPTS.asan_allocator.cc += -O1
-COPTS.asan_report.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
-
.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
COPTS.asan_interceptors.cc += -O1
.endif
diff --git a/external/gpl3/gcc.old/lib/liblsan/Makefile b/external/gpl3/gcc.old/lib/liblsan/Makefile
index 4578544a9a8..ddb7981077c 100644
--- a/external/gpl3/gcc.old/lib/liblsan/Makefile
+++ b/external/gpl3/gcc.old/lib/liblsan/Makefile
@@ -16,11 +16,6 @@ LSAN_SRCS+= \
lsan_linux.cc \
lsan_thread.cc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lsan_allocator.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= lsan
SRCS+= ${LSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/lib/libubsan/Makefile b/external/gpl3/gcc.old/lib/libubsan/Makefile
index 2e2faca7b1c..9de82550d14 100644
--- a/external/gpl3/gcc.old/lib/libubsan/Makefile
+++ b/external/gpl3/gcc.old/lib/libubsan/Makefile
@@ -26,10 +26,6 @@ UBSAN_SRCS= \
COPTS.${_s}.cc+=-frtti
.endfor

-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= ubsan
SRCS+= ${UBSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/usr.bin/cc1/Makefile b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
index c55e292ee8e..ff12a5be524 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
@@ -46,17 +46,6 @@ CPPFLAGS.default-c.c+= -I${BACKENDOBJ}
BUILDSYMLINKS+= ${GNUHOSTDIST}/gcc/config/sh/sh-c.cc sh-c.c
.endif

-.if ${MACHINE_CPU} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
index 3123ee0d60b..aab82ad3448 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
@@ -44,16 +44,8 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-.endif
+COPTS.c-cppbuiltin.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}
+COPTS.c-typeck.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}

.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
diff --git a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
index b9c108251c5..e04e8fc7f53 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
@@ -69,18 +69,6 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-COPTS.decl.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
index 7936efd3a5e..7c54559e21a 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
@@ -31,23 +31,6 @@ CHECKSUM_OBJS= ${LIBBACKTRACEOBJ}/libbacktrace.a \

CFLAGS+= -Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.call.c+=-O0
-COPTS.decl.c+=-O0
-COPTS.typeck2.c+=-O0
-COPTS.class.c+=-O0
-COPTS.typeck.c+=-O0
-COPTS.init.c+=-O0
-COPTS.semantics.c+=-O0
-COPTS.mangle.c+=-O0
-COPTS.constexpr.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1plus-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/gcc/Makefile b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
index 7a66d77ffc7..a5a4b1c3adf 100644
--- a/external/gpl3/gcc.old/usr.bin/gcc/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
@@ -25,9 +25,6 @@ ${SRCS}: ${GCCARCH}/defs.mk
.include <bsd.info.mk>

COPTS.gcc.c= -Wno-stack-protector
-.if ${MACHINE_ARCH} == "vax"
-COPTS.dse.c= -O1
-.endif

.PATH: ${DIST}/gcc ${DIST}/gcc/doc ${DIST}/gcc/c

diff --git a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
index 751d1513eec..33aeb1c9898 100644
--- a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
@@ -14,10 +14,6 @@ SRCS= decNumber.c decContext.c decimal32.c decimal64.c decimal128.c
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH} -I${DIST}/libdecnumber
CPPFLAGS+= -I${DIST}/libgcc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.include <bsd.lib.mk>

# Force using C++ for this
diff --git a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
index 90f44a9fcf6..fd251464fb7 100644
--- a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
@@ -24,11 +24,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.backtrace"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
DPADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} ${LIBINTL} ${LIBZ} ${LIBM}

diff --git a/external/gpl3/gcc.old/usr.bin/lto1/Makefile b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
index 4c49161a64c..340d3c6124f 100644
--- a/external/gpl3/gcc.old/usr.bin/lto1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
@@ -21,11 +21,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.libcpp"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTYOBJ}/libiberty.a
DPADD+= ${LIBIBERTYOBJ}/libiberty.a
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
diff --git a/external/gpl3/gdb.old/lib/libdecnumber/Makefile b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
index bcd4ae5b222..ce28811526b 100644
--- a/external/gpl3/gdb.old/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libdecnumber/Makefile b/external/gpl3/gdb/lib/libdecnumber/Makefile
index c95d36e3dfa..e3169865304 100644
--- a/external/gpl3/gdb/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd ${DIST}/libdecnumber/bid

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libgdb/Makefile b/external/gpl3/gdb/lib/libgdb/Makefile
index b87a515d13a..c118c363975 100644
--- a/external/gpl3/gdb/lib/libgdb/Makefile
+++ b/external/gpl3/gdb/lib/libgdb/Makefile
@@ -66,12 +66,6 @@ CFLAGS:= ${CXXFLAGS} -std=gnu++17 -Wno-error=stack-protector

ada-exp.c: ada-lex.c

-.if ${MACHINE} == "vax"
-. if ${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8
-COPTS.read.c+= -O0
-. endif
-.endif
-
# These are generated by implicit rules and are not easy to generate
CLEANDIRFILES+= \
ada-exp.c ada-lex.c \
diff --git a/external/mit/xorg/lib/gallium.old/Makefile b/external/mit/xorg/lib/gallium.old/Makefile
index 55b2fe3d1c1..bfa40c8974f 100644
--- a/external/mit/xorg/lib/gallium.old/Makefile
+++ b/external/mit/xorg/lib/gallium.old/Makefile
@@ -1211,10 +1211,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
# XXXGCC12
.if ${MACHINE_ARCH} == "m68k"
COPTS.st_glsl_to_tgsi.cpp += -O1
diff --git a/external/mit/xorg/lib/gallium/Makefile b/external/mit/xorg/lib/gallium/Makefile
index 6778a8c11c8..9f1422080fe 100644
--- a/external/mit/xorg/lib/gallium/Makefile
+++ b/external/mit/xorg/lib/gallium/Makefile
@@ -1428,10 +1428,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
COPTS.u_atomic.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-builtin-declaration-mismatch :}

.include <bsd.lib.mk>
diff --git a/external/mit/xorg/lib/libX11/Makefile.libx11 b/external/mit/xorg/lib/libX11/Makefile.libx11
index e103d9ace12..0e55c2a4732 100644
--- a/external/mit/xorg/lib/libX11/Makefile.libx11
+++ b/external/mit/xorg/lib/libX11/Makefile.libx11
@@ -471,11 +471,6 @@ COPTS.OpenDis.c+= -Wno-error # XXX xf86bigfstr.h
COPTS.XlibInt.c+= -Wno-error # XXX xcmiscstr.h
COPTS.XKBBind.c+= -Wno-deprecated-declarations # uses XKeycodeToKeysym

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.lcWrap.c+= -O0
-.endif
-
CWARNFLAGS.clang+= -Wno-string-plus-int

.include "${NETBSDSRCDIR}/external/mit/xorg/tools/makekeys/Makefile.makekeys"
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile
index e86a63aaea7..678537066ed 100644
--- a/games/gomoku/Makefile
+++ b/games/gomoku/Makefile
@@ -9,10 +9,6 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}

-.if ${MACHINE} == "vax"
-COPTS.pickmove.c += -O0
-.endif
-
#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index e9c53f23ae5..b919dac17c6 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -52,7 +52,3 @@ map: map.c
./map | plot > /dev/tty

.include <bsd.prog.mk>
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/i18n_module/UTF7/Makefile b/lib/i18n_module/UTF7/Makefile
index 712c1515d42..7136f7f0cc3 100644
--- a/lib/i18n_module/UTF7/Makefile
+++ b/lib/i18n_module/UTF7/Makefile
@@ -3,6 +3,3 @@
SRCPRE=citrus_
.include <bsd.lib.mk>

-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.citrus_utf7.c+= -O0
-.endif
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b2aea1e04b0..e60a2862d48 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -15,11 +15,6 @@ SRCS= blocksort.c huffman.c crctable.c randtable.c compress.c \
INCS= bzlib.h
INCSDIR= /usr/include

-# XXX huffman.c gets mis-compiled with 2.95.3
-.if ${MACHINE_ARCH} == "vax"
-COPTS+= -O0
-.endif
-
COPTS+= ${CC_WNO_IMPLICIT_FALLTHROUGH}

# XXX blocksort.c gets mis-compiled with 4.1
diff --git a/lib/libc/gdtoa/Makefile.inc b/lib/libc/gdtoa/Makefile.inc
index 132686fc33d..609da919803 100644
--- a/lib/libc/gdtoa/Makefile.inc
+++ b/lib/libc/gdtoa/Makefile.inc
@@ -44,10 +44,3 @@ SRCS+= dmisc.c \
.if ${MACHINE_ARCH} != "vax"
SRCS+= strtord.c
.endif
-
-# XXX revisit with newer GCC.
-# Ensure numbers like 0xffff319f5fa95963 print correctly
-# ("999999999999999.98", not garbage like "?A>C>@>C:BA;A><.:<")
-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index cb3f89d6d09..e9c8be820da 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -30,9 +30,6 @@ SRCS+= crypt-argon2.c
SRCS+= ${src}
COPTS.${src}+= -fvisibility=hidden
. endfor
-. if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-. endif
.endif

WARNS?= 5
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
index f5baae1e883..24f7e1121e5 100644
--- a/libexec/ld.elf_so/Makefile
+++ b/libexec/ld.elf_so/Makefile
@@ -141,10 +141,6 @@ CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector

-.if ${MACHINE_CPU} == "vax"
-COPTS.rtld.c+= -O0
-.endif
-
LDADD+= -Wl,--version-script=${.CURDIR}/symbols.map
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
diff --git a/sbin/fsck_ffs/Makefile.common b/sbin/fsck_ffs/Makefile.common
index 765638b2801..824e3bf2628 100644
--- a/sbin/fsck_ffs/Makefile.common
+++ b/sbin/fsck_ffs/Makefile.common
@@ -36,7 +36,3 @@ COPTS.ffs_appleufs.c+= -Wno-pointer-sign
.if ${MACHINE_ARCH} == "m68000"
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif
-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-.endif
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index c039f73a1eb..3b0331e5880 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -39,12 +39,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-COPTS.fsdb.c+= -O0
-.endif
-
CWARNFLAGS.gcc+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

.include <bsd.prog.mk>
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 40a44b9a038..ecfdbff4d3a 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -20,8 +20,4 @@ DPADD+=${LIBPROP}

.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mke2fs.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 4f33501ea7a..1f7f56e3ea5 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -12,8 +12,4 @@ CPPFLAGS+= -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax
index cf095d54a86..c483eaa644a 100644
--- a/sys/arch/vax/conf/Makefile.vax
+++ b/sys/arch/vax/conf/Makefile.vax
@@ -34,7 +34,6 @@ GENASSYM_CONF= ${VAX}/vax/genassym.cf
CPPFLAGS+= -D_VAX_INLINE_
AFLAGS+= -x assembler-with-cpp -fno-pic
CFLAGS+= -fno-pic
-COPTS.wsmux.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -O1 :}


##
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 718c97ce857..4ef3840c753 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -96,7 +96,3 @@ SRCS+= ufs.c
lib${LIB}.o:: ${OBJS:O} __buildstdlib

CPPFLAGS+= -Wno-pointer-sign
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.bootp.c+= -O0
-.endif
diff --git a/sys/lib/libz/Makefile b/sys/lib/libz/Makefile
index 6945c0da6c6..61fb7d4f652 100644
--- a/sys/lib/libz/Makefile
+++ b/sys/lib/libz/Makefile
@@ -25,7 +25,3 @@ CLEANFILES+= lib${LIB}.o
.include <bsd.lib.mk>

lib${LIB}.o:: ${OBJS:O} __buildstdlib
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.inftrees.c+= -O0
-.endif
diff --git a/sys/modules/lfs/Makefile b/sys/modules/lfs/Makefile
index 962538821a5..ea8f187e160 100644
--- a/sys/modules/lfs/Makefile
+++ b/sys/modules/lfs/Makefile
@@ -18,9 +18,4 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_inode.c ulfs_lookup.c \

WARNS= 3

-.if ${MACHINE} == "vax"
-# GCC 6.5 and 7.4 cannot compile this with -DDIAGNOSTIC and -O2/-O1
-COPTS.lfs_inode.c+= -O0
-.endif
-
.include <bsd.kmodule.mk>
diff --git a/sys/rump/fs/lib/liblfs/Makefile b/sys/rump/fs/lib/liblfs/Makefile
index abade3767d9..68b74c62502 100644
--- a/sys/rump/fs/lib/liblfs/Makefile
+++ b/sys/rump/fs/lib/liblfs/Makefile
@@ -17,9 +17,6 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_extattr.c \


CFLAGS+= -DLFS_KERNEL_RFW
-.if ${MACHINE_ARCH} == "vax"
-COPTS.lfs_inode.c+=-O0
-.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff --git a/usr.sbin/mtrace/Makefile b/usr.sbin/mtrace/Makefile
index aef09db6198..9c125c15265 100644
--- a/usr.sbin/mtrace/Makefile
+++ b/usr.sbin/mtrace/Makefile
@@ -12,10 +12,6 @@ PROG= mtrace
SRCS= igmp.c inet.c kern.c mtrace.c
MAN= mtrace.8

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mtrace.c=-O0
-.endif
-
BINMODE=4555
BINOWN= root

diff --git a/external/gpl3/gcc.old/usr.bin/backend/Makefile b/external/gpl3/gcc.old/usr.bin/backend/Makefile
index d69a26fe619..99e881c783d 100644
--- a/external/gpl3/gcc.old/usr.bin/backend/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/backend/Makefile
@@ -533,68 +533,9 @@ COPTS.insn-recog.c+=-Wno-error

.if ${GCC_MACHINE_ARCH} == "vax"
CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
-COPTS.builtins.c+=-O0
-COPTS.calls.c+=-O0
-COPTS.convert.c+=-O0
-COPTS.data-streamer-out.c+=-O0
-COPTS.dse.c+=-O0 # XXX port-vax/51967
-COPTS.dwarf2out.c+=-O0
-COPTS.expmed.c+=-O0
-COPTS.expr.c+=-O0 -Wno-error=tautological-compare
-COPTS.fixed-value.c+=-O0
-COPTS.fold-const.c+=-O0
-COPTS.generic-match.c+=-O0
-COPTS.gimple-fold.c+=-O0
-COPTS.gimple-match.c+=-O0
-COPTS.gimple-ssa-strength-reduction.c+=-O0
-COPTS.gimple-ssa-warn-restrict.c+=-O0
-COPTS.gimple.c+=-O0
-COPTS.internal-fn.c+=-O0
-COPTS.lto-streamer-out.c+=-O0
-COPTS.omp-low.c+=-O0
-COPTS.predict.c+=-O0
-COPTS.range-op.cc+=-O0
-COPTS.recog.c+=-O0
-COPTS.sanopt.c+=-O0
-COPTS.stmt.c+=-O0
-COPTS.stor-layout.c+=-O0
-COPTS.targhooks.c+=-O0
-COPTS.tree-affine.c+=-O0
-COPTS.tree-cfg.c+=-O0
-COPTS.tree-data-ref.c+=-O0
-COPTS.tree-eh.c+=-O0
-COPTS.tree-if-conv.c+=-O0
-COPTS.tree-object-size.c+=-O0
-COPTS.tree-parloops.c+=-O0
-COPTS.tree-predcom.c+=-O0
-COPTS.tree-pretty-print.c+=-O0
-COPTS.tree-ssa-alias.c+=-O0
-COPTS.tree-ssa-ccp.c+=-O0
-COPTS.tree-ssa-forwprop.c+=-O0
-COPTS.tree-ssa-loop-ivopts.c+=-O0
-COPTS.tree-ssa-loop-manip.c+=-O0
-COPTS.tree-ssa-loop-niter.c+=-O0
-COPTS.tree-ssa-math-opts.c+=-O0
-COPTS.tree-ssa-phiopt.c+= -O0
-COPTS.tree-ssa-pre.c+=-O0
-COPTS.tree-ssa-reassoc.c+=-O0
-COPTS.tree-ssa-strlen.c+=-O0
-COPTS.tree-ssa-uninit.c+=-O0
-COPTS.tree-ssa.c+=-O0
-COPTS.tree-switch-conversion.c+=-O0
-COPTS.tree-vect-data-refs.c+=-O0
-COPTS.tree-vect-loop-manip.c+=-O0
-COPTS.tree-vect-loop.c+=-O0
-COPTS.tree-vect-patterns.c+=-O0
-COPTS.tree-vect-stmts.c+=-O0
-COPTS.tree-vrp.c+=-O0
-COPTS.tree.c+=-O0
-COPTS.ubsan.c+=-O0
-COPTS.varasm.c+=-O0
-COPTS.vr-values.c+=-O0
-COPTS.web.c+=-O0
-COPTS.wide-int-range.cc+=-O0
-COPTS.wide-int.cc+=-O0
+
+COPTS.expmed.c+=-Wno-error=tautological-compare
+COPTS.expr.c+=-Wno-error=tautological-compare
.else
COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
.endif
 1.6 09-Nov-2013  christos branches: 1.6.36;
vax specific gcc 4.8.1 hacks
 1.5 11-Aug-2013  dholland This passes WARNS=5.
 1.4 24-Mar-2012  joerg branches: 1.4.2;
Avoid non-literal format string. Raise WARNS to 4 and disable
sign warnings instead.
 1.3 05-Jun-2009  haad branches: 1.3.6;
Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.2 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.1 17-Nov-2007  tsutsui branches: 1.1.6; 1.1.18;
Add a dumb but BSD-licensed newfs_ext2fs(8) command.
This is based on the newfs(8) command for ffs, but
most ext2fs specific part is written from scratch.

Tested on alpha, cobalt, i386 and sgimips with some disks and vnd(4),
and at least cobalt's firmware can load boot files from an ext2fs
E2FS_REV0 partition created by this native newfs_ext2fs(8) command.

Closes PR bin/16175.
 1.1.18.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.1.6.2 09-Jan-2008  matt sync with HEAD
 1.1.6.1 17-Nov-2007  matt file Makefile was added on branch matt-armv6 on 2008-01-09 01:38:13 +0000
 1.3.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3.6.1 17-Apr-2012  yamt sync with head
 1.4.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.36.1 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #394):

external/gpl3/binutils/dist/gas/config/tc-vax.h: revision 1.10
tools/gcc/Makefile: revision 1.109
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.16
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.17
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/recog.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/function.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/dse.c: revision 1.14 - 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.13
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.15
external/gpl3/gcc.old/dist/gcc/doc/tm.texi.in: revision 1.10
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.19
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.13
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.20
external/gpl3/gcc.old/dist/gcc/targhooks.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.15
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.13
external/gpl3/gcc.old/dist/gcc/doc/tm.texi: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.13
external/gpl3/gcc.old/dist/gcc/targhooks.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/target.def: revision 1.10
external/gpl3/gcc.old/dist/gcc/rtlanal.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/reload.c: revision 1.12
external/gpl3/gcc.old/usr.bin/gcc/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/lto-dump/Makefile: revision 1.3
external/gpl3/gcc.old/lib/Makefile.sanitizer: revision 1.7
external/gpl3/binutils.old/lib/libbfd/Makefile: revision 1.10
distrib/utils/x_ping/Makefile: revision 1.9
games/phantasia/Makefile: revision 1.38
external/apache2/argon2/lib/libargon2/Makefile.inc: revision 1.2
external/gpl3/gcc.old/lib/libubsan/Makefile: revision 1.8
external/bsd/mdocml/lib/libmandoc/Makefile: revision 1.13
sbin/ping/Makefile: revision 1.18
sbin/newfs_ext2fs/Makefile: revision 1.7
sys/lib/libz/Makefile: revision 1.24
sys/lib/libsa/Makefile: revision 1.97
external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile: revision 1.3
external/gpl3/gdb/lib/libgdb/Makefile: revision 1.36
sys/modules/lfs/Makefile: revision 1.11
external/mit/xorg/lib/gallium/Makefile: revision 1.51
external/gpl3/gdb.old/lib/libdecnumber/Makefile: revision 1.10
external/mit/xorg/lib/libX11/Makefile.libx11: revision 1.26
libexec/ld.elf_so/Makefile: revision 1.148
external/bsd/jemalloc/lib/Makefile.inc: revision 1.16
external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile: revision 1.14
crypto/external/bsd/openssh/lib/Makefile: revision 1.38
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.21
external/gpl3/gcc.old/usr.bin/cc1/Makefile: revision 1.12
external/gpl3/gcc.old/lib/libasan/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/cc1plus/Makefile: revision 1.13
lib/libcrypt/Makefile: revision 1.36
external/gpl3/gdb/lib/libdecnumber/Makefile: revision 1.5
lib/libc/gdtoa/Makefile.inc: revision 1.13
games/gomoku/Makefile: revision 1.13
sbin/fsdb/Makefile: revision 1.43
external/gpl3/gcc.old/usr.bin/lto1/Makefile: revision 1.9
external/mit/xorg/lib/gallium.old/Makefile: revision 1.8
lib/libbz2/Makefile: revision 1.22
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.12
usr.sbin/mtrace/Makefile: revision 1.14
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.13
sys/arch/vax/conf/Makefile.vax: revision 1.86
sys/rump/fs/lib/liblfs/Makefile: revision 1.18
sbin/fsck_ffs/Makefile.common: revision 1.3
external/gpl3/binutils/lib/libbfd/Makefile: revision 1.27
lib/i18n_module/UTF7/Makefile: revision 1.5
external/gpl3/gcc.old/lib/liblsan/Makefile: revision 1.7
doc/CHANGES (apply patch)
(all external/gpl3/gcc.old/ changes applied to external/gpl3/gcc/)

PR 57646: Import major vax toolchain fix.
 1.4 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.3 01-Mar-2009  christos Support variable inode sizes.
 1.2 14-Dec-2007  tsutsui branches: 1.2.2; 1.2.12; 1.2.14;
Don't allow blocksize larger than 4096 bytes as our kernel, fsck_ext2fs(8),
and Linux e2fsprogs.
 1.1 17-Nov-2007  tsutsui branches: 1.1.2;
Add a dumb but BSD-licensed newfs_ext2fs(8) command.
This is based on the newfs(8) command for ffs, but
most ext2fs specific part is written from scratch.

Tested on alpha, cobalt, i386 and sgimips with some disks and vnd(4),
and at least cobalt's firmware can load boot files from an ext2fs
E2FS_REV0 partition created by this native newfs_ext2fs(8) command.

Closes PR bin/16175.
 1.1.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.2.14.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.2.12.1 17-Jan-2011  jdc Add change :
sbin/newfs_ext2fs/extern.h: revision 1.3
required for ticket #1486. Original commit message was:

Pull up following revision(s) (requested by tsutsui in ticket #1486):
sbin/fsck_ext2fs/setup.c: revision 1.26
sbin/newfs_ext2fs/mke2fs.c: revision 1.10
sbin/newfs_ext2fs/mke2fs.c: revision 1.11
sbin/newfs_ext2fs/mke2fs.c: revision 1.12
sbin/fsck_ext2fs/inode.c: revision 1.24
sys/lib/libsa/ext2fs.c: revision 1.6
sbin/newfs_ext2fs/extern.h: revision 1.3
sbin/fsck_ext2fs/inode.c: revision 1.25
sys/lib/libsa/ext2fs.c: revision 1.7
sbin/fsck_ext2fs/inode.c: revision 1.26
sys/ufs/ext2fs/ext2fs_inode.c: revision 1.68
sbin/fsck_ext2fs/inode.c: revision 1.27
sbin/fsck_ext2fs/inode.c: revision 1.28
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.18
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.19
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.5
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.2
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.6
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.3
sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.142
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.7
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.4
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.8
PR/40936: Frederik Sausmikat: ext2fs: add support for inodes > 128 bytes
Support variable inode sizes.
catch up with variable inode size.
Don't use e2fs_inode_size in superblock on E2FS_REV0 file system.
- accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
Use EXT2_DINODE_SIZE() to get offset of inode, not struct ext2fs_dinode array.
Fix botched logic in inodesize check.
Use inodesize to get offset of inode in one more place.
- add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
Sort options.
New sentence, new line.
Sort options in usage.
- unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
Add missed byteswap ops against ext2fs_dinode members.
Handle 32 bit uid field on E2FS_REV1.
 1.2.2.2 09-Jan-2008  matt sync with HEAD
 1.2.2.1 14-Dec-2007  matt file extern.h was added on branch matt-armv6 on 2008-01-09 01:38:14 +0000
 1.28 05-Jan-2025  andvar fix various typos in comments.
 1.27 22-Feb-2024  tsutsui branches: 1.27.2;
Pull a change of newfs/mkfs.c rev 1.136:

> if the window size works but is 0, assume it didn't work and use 80.
 1.26 17-May-2023  tsutsui Use https for Ext2 documentation URLs.
 1.25 05-Sep-2016  martin Add a bit of swapping for values in CG descriptors (used to be done
wholesale in e2fs_cgsave, but now common code keeps them in FS byte
order). Seems to fix newfs_ext2fs on big endian hosts.
 1.24 04-Aug-2016  jdolecek rename struct ext2fs_dinode attribute e2di_dacl to correct
e2di_size_high; even Linux ext2 filesystem code actually uses it
unconditionally this way and ext4 code finally also calls it that way
in their struct definition too; if there was any trace of this for other
purpose it's long gone
 1.23 04-Aug-2016  nonaka pass EXT2_DINODE_SIZE(&sblock) as isize to e2fs_isave().
 1.22 16-Jun-2015  christos branches: 1.22.2;
fix error messages containing \n
 1.21 19-Oct-2013  tsutsui Wrap long lines overflowed after EXT2_ prefix addtion to fs macro.
 1.20 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.19 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.18 07-Feb-2013  apb free(bbp) in error paths. Coverity CID 274748.
 1.17 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.16 24-Mar-2012  joerg branches: 1.16.2;
Avoid non-literal format string. Raise WARNS to 4 and disable
sign warnings instead.
 1.15 06-Mar-2012  tsutsui Stop zero'ing all possible superblock backup leftovers conservatively.
Instead, explicitly zap only possible first backups and FFS superblocks.

Fixes "Extreamly slow newfs_ext2fs on 60Gb USB stick" problem
reported by Aleksey Cheusov on tech-kern@.
 1.14 10-Sep-2010  tsutsui branches: 1.14.6; 1.14.8;
Add a URL of Linux Documentation "The Second Extended Filesystem."
 1.13 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.12 02-Mar-2009  tsutsui Use inodesize to get offset of inode in one more place.
 1.11 02-Mar-2009  tsutsui - accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
 1.10 01-Mar-2009  christos Support variable inode sizes.
 1.9 28-Aug-2008  tsutsui branches: 1.9.2; 1.9.4;
Fix some spelling.
 1.8 14-May-2008  tsutsui Normalize my licenses.
 1.7 14-Dec-2007  tsutsui branches: 1.7.2; 1.7.6; 1.7.8; 1.7.10;
Don't allow blocksize larger than 4096 bytes as our kernel, fsck_ext2fs(8),
and Linux e2fsprogs.
 1.6 09-Dec-2007  tsutsui Fix typo.
 1.5 21-Nov-2007  tsutsui branches: 1.5.2;
Roundup e2fs_ipg to make it use whole inode table blocks since
it's still reasonable and some kernel code seems to assume it
(otherwise some inode numbers of directories could be corrupted).

XXX: not sure if odd e2fs_ipg is valid or not in ext2fs spec.
 1.4 20-Nov-2007  tsutsui Fix e2fs_itpg calculation.
 1.3 19-Nov-2007  tsutsui - fix a possible integer overflow
- initialize inode generation numbers with random numbers for NFS
like newfs(8) as man page said
XXX: sys/ufs/ext2fs/ext2fs_alloc.c:ext2fs_valloc() seems to override
these generated numbers.
 1.2 18-Nov-2007  tsutsui Several minor fixes:
- replace a magic number with a macro
- fix several printf format
- fix possble block sizes for zap_old_sblock()
- use err(3) rather than errx(3) + strerror(errno)
- fix a typo
- misc cosmetics
 1.1 17-Nov-2007  tsutsui Add a dumb but BSD-licensed newfs_ext2fs(8) command.
This is based on the newfs(8) command for ffs, but
most ext2fs specific part is written from scratch.

Tested on alpha, cobalt, i386 and sgimips with some disks and vnd(4),
and at least cobalt's firmware can load boot files from an ext2fs
E2FS_REV0 partition created by this native newfs_ext2fs(8) command.

Closes PR bin/16175.
 1.5.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.5.2.1 21-Nov-2007  mjf file mke2fs.c was added on branch mjf-devfs on 2007-12-27 00:47:03 +0000
 1.7.10.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.7.10.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.8.1 18-May-2008  yamt sync with head.
 1.7.6.2 28-Sep-2008  mjf Sync with HEAD.
 1.7.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.2.2 09-Jan-2008  matt sync with HEAD
 1.7.2.1 14-Dec-2007  matt file mke2fs.c was added on branch matt-armv6 on 2008-01-09 01:38:14 +0000
 1.9.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.9.2.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1486):
sbin/fsck_ext2fs/setup.c: revision 1.26
sbin/newfs_ext2fs/mke2fs.c: revision 1.10
sbin/newfs_ext2fs/mke2fs.c: revision 1.11
sbin/newfs_ext2fs/mke2fs.c: revision 1.12
sbin/fsck_ext2fs/inode.c: revision 1.24
sys/lib/libsa/ext2fs.c: revision 1.6
sbin/newfs_ext2fs/extern.h: revision 1.3
sbin/fsck_ext2fs/inode.c: revision 1.25
sys/lib/libsa/ext2fs.c: revision 1.7
sbin/fsck_ext2fs/inode.c: revision 1.26
sys/ufs/ext2fs/ext2fs_inode.c: revision 1.68
sbin/fsck_ext2fs/inode.c: revision 1.27
sbin/fsck_ext2fs/inode.c: revision 1.28
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.18
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.19
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.5
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.2
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.6
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.3
sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.142
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.7
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.4
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.8
PR/40936: Frederik Sausmikat: ext2fs: add support for inodes > 128 bytes
Support variable inode sizes.
catch up with variable inode size.
Don't use e2fs_inode_size in superblock on E2FS_REV0 file system.
- accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
Use EXT2_DINODE_SIZE() to get offset of inode, not struct ext2fs_dinode array.
Fix botched logic in inodesize check.
Use inodesize to get offset of inode in one more place.
- add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
Sort options.
New sentence, new line.
Sort options in usage.
- unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
Add missed byteswap ops against ext2fs_dinode members.
Handle 32 bit uid field on E2FS_REV1.
 1.14.8.1 09-Mar-2012  sborrill Pull up the following revisions(s) (requested by tsutsui in ticket #105):
sbin/newfs_ext2fs/mke2fs.c: revision 1.15

Fix extremely slow newfs_ext2fs(8) operation on large USB stick.
 1.14.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.6.2 23-Jan-2013  yamt sync with head
 1.14.6.1 17-Apr-2012  yamt sync with head
 1.16.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.2.2 23-Jun-2013  tls resync from head
 1.16.2.1 25-Feb-2013  tls resync with head
 1.22.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.27.2.1 02-Aug-2025  perseant Sync with HEAD
 1.15 17-May-2023  tsutsui Use https for Ext2 documentation URLs.
 1.14 13-Apr-2019  maya Omit mention of old vnd(4) bug, now resolved.

Via elge, thanks.
 1.13 06-Mar-2019  mrg make ext2fs rev1 the default. this enables LARGEFILES support.
 1.12 03-Jul-2017  wiz branches: 1.12.6;
Remove workaround for ancient HTML generation code.
 1.11 25-Feb-2010  tsutsui Avoid line break in `Linux Ext2' strings.
 1.10 21-Feb-2010  wiz Fix string, noted by tsutsui.
 1.9 18-Feb-2010  wiz Fix pasto noted by tsutsui.
 1.8 17-Feb-2010  wiz Various fixes from Jason McIntyre <jmc@kerhand.co.uk>.
 1.7 01-Dec-2009  pooka Remove vinum-removal sentence fragment, similarly to newfs(8).
 1.6 25-Oct-2009  joerg Use .%U.
 1.5 18-May-2009  wiz Sort option descriptions.
 1.4 01-Mar-2009  wiz New sentence, new line.
 1.3 01-Mar-2009  wiz Sort options.
 1.2 01-Mar-2009  christos Support variable inode sizes.
 1.1 17-Nov-2007  tsutsui branches: 1.1.6; 1.1.16; 1.1.18;
Add a dumb but BSD-licensed newfs_ext2fs(8) command.
This is based on the newfs(8) command for ffs, but
most ext2fs specific part is written from scratch.

Tested on alpha, cobalt, i386 and sgimips with some disks and vnd(4),
and at least cobalt's firmware can load boot files from an ext2fs
E2FS_REV0 partition created by this native newfs_ext2fs(8) command.

Closes PR bin/16175.
 1.1.18.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.1.16.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1486):
sbin/fsck_ext2fs/setup.c: revision 1.26
sbin/newfs_ext2fs/mke2fs.c: revision 1.10
sbin/newfs_ext2fs/mke2fs.c: revision 1.11
sbin/newfs_ext2fs/mke2fs.c: revision 1.12
sbin/fsck_ext2fs/inode.c: revision 1.24
sys/lib/libsa/ext2fs.c: revision 1.6
sbin/newfs_ext2fs/extern.h: revision 1.3
sbin/fsck_ext2fs/inode.c: revision 1.25
sys/lib/libsa/ext2fs.c: revision 1.7
sbin/fsck_ext2fs/inode.c: revision 1.26
sys/ufs/ext2fs/ext2fs_inode.c: revision 1.68
sbin/fsck_ext2fs/inode.c: revision 1.27
sbin/fsck_ext2fs/inode.c: revision 1.28
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.18
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.19
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.5
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.2
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.6
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.3
sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.142
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.7
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.4
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.8
PR/40936: Frederik Sausmikat: ext2fs: add support for inodes > 128 bytes
Support variable inode sizes.
catch up with variable inode size.
Don't use e2fs_inode_size in superblock on E2FS_REV0 file system.
- accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
Use EXT2_DINODE_SIZE() to get offset of inode, not struct ext2fs_dinode array.
Fix botched logic in inodesize check.
Use inodesize to get offset of inode in one more place.
- add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
Sort options.
New sentence, new line.
Sort options in usage.
- unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
Add missed byteswap ops against ext2fs_dinode members.
Handle 32 bit uid field on E2FS_REV1.
 1.1.6.2 09-Jan-2008  matt sync with HEAD
 1.1.6.1 17-Nov-2007  matt file newfs_ext2fs.8 was added on branch matt-armv6 on 2008-01-09 01:38:15 +0000
 1.12.6.1 10-Jun-2019  christos Sync with HEAD
 1.11 16-Apr-2022  andvar fix various typos in comments and log messages.
 1.10 06-Mar-2019  mrg make ext2fs rev1 the default. this enables LARGEFILES support.
 1.9 19-Oct-2013  christos branches: 1.9.26;
fix unused variable warnings.
 1.8 02-Mar-2009  tsutsui branches: 1.8.6; 1.8.12;
Fix botched logic in inodesize check.
 1.7 02-Mar-2009  tsutsui Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
 1.6 01-Mar-2009  wiz Sort options in usage.
 1.5 01-Mar-2009  christos Support variable inode sizes.
 1.4 20-Jul-2008  lukem branches: 1.4.2; 1.4.4;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.3 15-Dec-2007  perry branches: 1.3.2; 1.3.6; 1.3.10;
convert __attribute__s to applicable cdefs.h macros
 1.2 14-Dec-2007  tsutsui Don't allow blocksize larger than 4096 bytes as our kernel, fsck_ext2fs(8),
and Linux e2fsprogs.
 1.1 17-Nov-2007  tsutsui branches: 1.1.2;
Add a dumb but BSD-licensed newfs_ext2fs(8) command.
This is based on the newfs(8) command for ffs, but
most ext2fs specific part is written from scratch.

Tested on alpha, cobalt, i386 and sgimips with some disks and vnd(4),
and at least cobalt's firmware can load boot files from an ext2fs
E2FS_REV0 partition created by this native newfs_ext2fs(8) command.

Closes PR bin/16175.
 1.1.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.3.10.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.6.1 28-Sep-2008  mjf Sync with HEAD.
 1.3.2.2 09-Jan-2008  matt sync with HEAD
 1.3.2.1 15-Dec-2007  matt file newfs_ext2fs.c was added on branch matt-armv6 on 2008-01-09 01:38:15 +0000
 1.4.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.4.2.1 16-Jan-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1486):
sbin/fsck_ext2fs/setup.c: revision 1.26
sbin/newfs_ext2fs/mke2fs.c: revision 1.10
sbin/newfs_ext2fs/mke2fs.c: revision 1.11
sbin/newfs_ext2fs/mke2fs.c: revision 1.12
sbin/fsck_ext2fs/inode.c: revision 1.24
sys/lib/libsa/ext2fs.c: revision 1.6
sbin/newfs_ext2fs/extern.h: revision 1.3
sbin/fsck_ext2fs/inode.c: revision 1.25
sys/lib/libsa/ext2fs.c: revision 1.7
sbin/fsck_ext2fs/inode.c: revision 1.26
sys/ufs/ext2fs/ext2fs_inode.c: revision 1.68
sbin/fsck_ext2fs/inode.c: revision 1.27
sbin/fsck_ext2fs/inode.c: revision 1.28
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.18
sys/ufs/ext2fs/ext2fs_dinode.h: revision 1.19
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.5
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.2
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.6
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.3
sys/ufs/ext2fs/ext2fs_vfsops.c: revision 1.142
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.7
sbin/newfs_ext2fs/newfs_ext2fs.8: revision 1.4
sbin/newfs_ext2fs/newfs_ext2fs.c: revision 1.8
PR/40936: Frederik Sausmikat: ext2fs: add support for inodes > 128 bytes
Support variable inode sizes.
catch up with variable inode size.
Don't use e2fs_inode_size in superblock on E2FS_REV0 file system.
- accept only EXT2_REV0_DINODE_SIZE inodesize on -O 0
- use inodesize to get offset of inode, not struct ext2fs_dinode array
Replace a magic number with a new EXT2_REV0_DINODE_SIZE macro.
Use EXT2_DINODE_SIZE() to get offset of inode, not struct ext2fs_dinode array.
Fix botched logic in inodesize check.
Use inodesize to get offset of inode in one more place.
- add a sanity check for e2fs_inode_size in readsb()
- use EXT2_DINODE_SIZE() rather than sizeof(struct ext2fs_dinode) or
struct ext2fs_dinode array/pointer to see e2fs_ipb and inode offsets
Sort options.
New sentence, new line.
Sort options in usage.
- unsigned -> unsigned int
- remove unnecessary casts from malloc(3) and free(3)
- fix a bogus indent
Use "size > INT32_MAX" rather than "size >= 0x80000000U" to check 2GB limit.
Add missed byteswap ops against ext2fs_dinode members.
Handle 32 bit uid field on E2FS_REV1.
 1.8.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.26.1 10-Jun-2019  christos Sync with HEAD
 1.16 20-Apr-2024  rillig {usr.,}{s,}bin: replace LINT_SUPPORTED with the standard NOLINT

While here, re-enable lint in those cases where lint was skipped due to
a bug in interpreting abstract types, which was fixed in cgram.y 1.469
from 2023-08-02.
 1.15 14-Sep-2021  rillig sbin: enable lint for almost all programs

The programs fsck_lfs and newfs_lfs both trigger a longstanding bug in
lint that is difficult to fix, so ignore them for now.

For resize_ffs, lint thinks that 'struct fs' is incomplete, but GCC and
Clang accept it. Needs further investigation.
 1.14 07-Sep-2020  mrg remove GCC_NO_ADDR_OF_PACKED_MEMBER for several subdir builds
that are now handled by lfs_accessors.h internally.
 1.13 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.12 08-Jun-2013  dholland Redo these changes properly:
-r1.12 libexec/lfs_cleanerd/Makefile
-r1.15 sbin/fsck_lfs/Makefile
-r1.6 sbin/newfs_lfs/Makefile

hi ad@
 1.11 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.10 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.9 06-Aug-2009  pooka branches: 1.9.6; 1.9.12;
Define syscalls of lfs userspace tools (cleaner, mainly) through
a struct called kernelops, which contains standard system calls
for the normal case and rump system calls for the rump case.

Make it possible to run the lfs cleaner in a library fashion (taking
the quick route with the implementation).
 1.8 05-Jun-2009  haad Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.7 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.6 28-Dec-2007  ad branches: 1.6.12;
Make it build with src/sys from the vmlocking2 branch.
 1.5 05-Sep-2006  riz branches: 1.5.8; 1.5.10;
Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. From Christos Zoulas.
 1.4 13-Sep-2005  christos make this compile again.
 1.3 26-Feb-2005  perseant Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.2 19-Aug-2002  lukem branches: 1.2.4;
Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.1 18-Mar-1999  perseant Change name of newlfs to newfs_lfs.
 1.2.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.5.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.8.1 09-Jan-2008  matt sync with HEAD
 1.6.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.9.12.1 23-Jun-2013  tls resync from head
 1.9.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.10 18-Oct-2025  perseant Reduce the minimum allowed segment size to match up with the size produced
by the auto-sizer for ATF tests. Will need to revisit the auto-sizer logic
later as well.
 1.9 02-Feb-2012  perseant When creating a very small filesystem, use well-known small segment,
block and fragment sizes by default instead of the ordinary 1M/8k/1k
default for larger filesystems.
 1.8 17-Dec-2003  yamt branches: 1.8.56;
remove definitions for ffs, which don't belong here.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.5 09-Sep-2000  perseant branches: 1.5.2;
Various bug-fixes to LFS, to wit:


Kernel:

* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.

If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.

* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.

* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.

* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().

lfs_cleanerd:

* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.

* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.

* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.

* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).

fsck_lfs:

* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.

newfs_lfs:

* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.

* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).

* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.

mount_lfs:

* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.

* Default to calling lfs_cleanerd with "-b -n 4".


[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
 1.4 04-Jul-2000  perseant Tweak how lfs_avail is initialized, corresponding to changes in the
kernel.

Don't make more superblock segments than we have a record of in
the superblock; and print these out as we go, like newfs.

Add am "-M" flag to specify the number of reserved segments, with a note
in the man page not to use it.
 1.3 03-Jul-2000  perseant User-level changes corrseponding to my latest kernel changes.
newfs_lfs gives lfs_minfreeseg a value of 1/8 of the total segments on
the disk, based on rough empirical data, but this should be refined in
the future.
 1.2 27-Jun-2000  perseant User-level changes for filling the disk.

Set MINFREE to 80, since that's a more reasonable value according to the
literature than FFS' 90. Remove a bunch of other unused FFS cruft from
config.h.

Initialize lfs_bfree correctly vis-a-vis MIN_FREE_SEGS, so the
filesystem doesn't over-represent the amount of free space it has.
Initialize lfs_dmeta so the kernel can estimate starting from a
reasonable value.
 1.1 18-Mar-1999  perseant branches: 1.1.10;
Change name of newlfs to newfs_lfs.
 1.1.10.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.5.2.2 13-Jul-2001  perseant Default to creating a v2 lfs, and print out the roll-forward id that
was used. Update newfs_lfs.8 to reflect new options.
 1.5.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.8.56.1 17-Apr-2012  yamt sync with head
 1.14 15-Oct-2015  dholland Enable the creation of lfs64 volumes.

To create an lfs64 volume, use -w 64. You can also force a 32-bit
volume with -w 32, but this will fail on devices thta are too large.

lfs64 is the default for devices > 1TB. (1TB rather than 2TB because
daddr_t is signed and negative block numbers can cause interesting
complications.)

For now print a warning that the lfs64 format isn't finalized, because
it isn't. For now any lfs64 use should be limited to test data,
benchmarking, and so forth.
 1.13 02-Aug-2015  dholland Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.12 16-Feb-2008  matt lfs_sb_cksum returns a uint32_t, not a u_long
 1.11 05-Sep-2006  riz branches: 1.11.8; 1.11.10;
Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. From Christos Zoulas.
 1.10 11-May-2006  mrg - log2() -> lfs_log2().
- fix a couple of entries in struct lfs lfs_default:
- in a comment, it's called dlfs_freehd now
- dlfs_inodefmt comes after dlfs_tstamp. fortunately for this
one, LFS_44INODEFMT is also 0 so the right thing was happening.
 1.9 04-May-2006  perseant newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.8 12-Aug-2003  dsl branches: 1.8.6;
Stop superblock being written to sector 0 for small filesystems.
Honour the '-s size' command option.
Allow an LFS filesystem to be created in a file.
 1.7 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.6 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.5 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.4 05-Dec-2000  perseant branches: 1.4.2;
Add "-A" option to autoconfigure the segment size based on measured
bandwidth and seek time of the disk, using the "4 * bandwidth * seek
time" formula from Neefe-Matthews' 1997 paper. An RZ25 disk with this
option gets 200K segments. Reference the paper in the manual page.
 1.3 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.2 04-Jul-2000  perseant Tweak how lfs_avail is initialized, corresponding to changes in the
kernel.

Don't make more superblock segments than we have a record of in
the superblock; and print these out as we go, like newfs.

Add am "-M" flag to specify the number of reserved segments, with a note
in the man page not to use it.
 1.1 18-Mar-1999  perseant branches: 1.1.2; 1.1.10;
Change name of newlfs to newfs_lfs.
 1.1.10.2 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.1.10.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.1.2.1 10-Oct-2000  he Pull up revision 1.3 (requested by is):
Format string cleanup.
 1.4.2.2 29-Jun-2001  perseant Get rid of __P(), protoizing where it had not already been done
 1.4.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.8.6.1 20-May-2006  riz Pull up following revision(s) (requested by perseant in ticket #1327):
sbin/newfs_lfs/extern.h: revision 1.9
sbin/newfs_lfs/make_lfs.c: revision 1.7
sbin/newfs_lfs/newfs_lfs.8: revision 1.21
sbin/newfs_lfs/newfs.c: revision 1.20
newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.11.10.1 18-Feb-2008  mjf Sync with HEAD.
 1.11.8.1 23-Mar-2008  matt sync with HEAD
 1.36 26-Feb-2005  perseant Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.35 11-Sep-2004  yamt - calculate maxfilesize dynamically rather than having a static table.
- no longer limit filesize to INT32_MAX. file lbns are 64-bit these days.
anyway, on-disk format shouldn't be limited by the kernel internals.
 1.34 09-Sep-2004  yamt fix a sign expansion bug for >=8k blocksizes.
 1.33 10-Nov-2003  wiz branches: 1.33.4;
Spell address with two d's. Inspired by similar changes in OpenBSD,
originating from Jonathon Gray and forwarded by jmc@openbsd.
 1.32 09-Oct-2003  yamt - don't try to write alt super blocks beyond the end of the partition.
- flush stdout when printing each super block addresses.
 1.31 06-Sep-2003  itojun use arc4random
 1.30 12-Aug-2003  dsl Stop superblock being written to sector 0 for small filesystems.
Honour the '-s size' command option.
Allow an LFS filesystem to be created in a file.
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.28 13-Jul-2003  itojun use bounded string ops
 1.27 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.26 23-Feb-2003  simonb Use the PRId64 format to print a daddr_t.
 1.25 23-Feb-2003  perseant Make the "-O" (start filesystem offset) flag to newfs_lfs work correctly,
and update fsck_lfs and dumplfs to deal with it. Note that while the argument
to -O is given in disk sectors, it must be a multiple of the fragment size,
and although it can be lower than the label or superblock, it can't intersect
either.
 1.24 24-Jan-2003  fvdl Bump daddr_t to 64 bits. Replace it with int32_t in all places where
it was used on-disk, so that on-disk formats remain the same.
Remove ufs_daddr_t and ufs_lbn_t for the time being.
 1.23 13-Jul-2001  thorpej Fix printf format on LP64.
 1.22 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.21 23-Nov-2000  perseant branches: 1.21.2;
Initialize inodes' generation number to 1, consistent with their version
number.
 1.20 11-Oct-2000  he Format fixup. size_t can be long, so cast to u_long and print with %ld.
 1.19 02-Oct-2000  perseant Handle "-m 0" properly (PR #11112).
 1.18 11-Sep-2000  perseant Do not report write errors if the user specified the -N flag.
Also, change the segment size report to include the total size of the disk,
similar to newfs, e.g.

newfs_lfs -N -F -B 65536 /dev/rsd0b
272.7MB in 4363 segments of size 65536
super-block backups (for fsck -b #) at:
16, 55824, 111632, 167440, 223248, 279056, 334864, 390672, 446480, 502288
 1.17 09-Sep-2000  perseant Various bug-fixes to LFS, to wit:


Kernel:

* Add runtime quantity lfs_ravail, the number of disk-blocks reserved
for writing. Writes to the filesystem first reserve a maximum amount
of blocks before their write is allowed to proceed; after the blocks
are allocated the reserved total is reduced by a corresponding amount.

If the lfs_reserve function cannot immediately reserve the requested
number of blocks, the inode is unlocked, and the thread sleeps until
the cleaner has made enough space available for the blocks to be
reserved. In this way large files can be written to the filesystem
(or, smaller files can be written to a nearly-full but thoroughly
clean filesystem) and the cleaner can still function properly.

* Remove explicit switching on dlfs_minfreeseg from the kernel code; it
is now merely a fs-creation parameter used to compute dlfs_avail and
dlfs_bfree (and used by fsck_lfs(8) to check their accuracy). Its
former role is better assumed by a properly computed dlfs_avail.

* Bounds-check inode numbers submitted through lfs_bmapv and lfs_markv.
This prevents a panic, but, if the cleaner is feeding the filesystem
the wrong data, you are still in a world of hurt.

* Cleanup: remove explicit references of DEV_BSIZE in favor of
btodb()/dbtob().

lfs_cleanerd:

* Make -n mean "send N segments' blocks through a single call to
lfs_markv". Previously it had meant "clean N segments though N calls
to lfs_markv, before looking again to see if more need to be cleaned".
The new behavior gives better packing of direct data on disk with as
little metadata as possible, largely alleviating the problem that the
cleaner can consume more disk through inefficient use of metadata than
it frees by moving dirty data away from clean "holes" to produce
entirely clean segments.

* Make -b mean "read as many segments as necessary to write N segments
of dirty data back to disk", rather than its former meaning of "read
as many segments as necessary to free N segments worth of space". The
new meaning, combined with the new -n behavior described above,
further aids in cleaning storage efficiency as entire segments can be
written at once, using as few blocks as possible for segment summaries
and inode blocks.

* Make the cleaner take note of segments which could not be cleaned due
to error, and not attempt to clean them until they are entirely free
of dirty blocks. This prevents the case in which a cleanerd running
with -n 1 and without -b (formerly the default) would spin trying
repeatedly to clean a corrupt segment, while the remaining space
filled and deadlocked the filesystem.

* Update the lfs_cleanerd manual page to describe all the options,
including the changes mentioned here (in particular, the -b and -n
flags were previously undocumented).

fsck_lfs:

* Check, and optionally fix, lfs_avail (to an exact figure) and
lfs_bfree (within a margin of error) in pass 5.

newfs_lfs:

* Reduce the default dlfs_minfreeseg to 1/20 of the total segments.

* Add a warning if the sgs disklabel field is 16 (the default for FFS'
cpg, but not usually desirable for LFS' sgs: 5--8 is a better range).

* Change the calculation of lfs_avail and lfs_bfree, corresponding to
the kernel changes mentioned above.

mount_lfs:

* Add -N and -b options to pass corresponding -n and -b options to
lfs_cleanerd.

* Default to calling lfs_cleanerd with "-b -n 4".


[All of these changes were largely tested in the 1.5 branch, with the
idea that they (along with previous un-pulled-up work) could be applied
to the branch while it was still in ALPHA2; however my test system has
experienced corruption on another filesystem (/dev/console has gone
missing :^), and, while I believe this unrelated to the LFS changes, I
cannot with good conscience request that the changes be pulled up.]
 1.16 04-Jul-2000  perseant Tweak how lfs_avail is initialized, corresponding to changes in the
kernel.

Don't make more superblock segments than we have a record of in
the superblock; and print these out as we go, like newfs.

Add am "-M" flag to specify the number of reserved segments, with a note
in the man page not to use it.
 1.15 03-Jul-2000  thorpej Default the root directory and lost+found directory to mode 0755,
as in FFS.
 1.14 03-Jul-2000  perseant User-level changes corrseponding to my latest kernel changes.
newfs_lfs gives lfs_minfreeseg a value of 1/8 of the total segments on
the disk, based on rough empirical data, but this should be refined in
the future.
 1.13 27-Jun-2000  perseant User-level changes for filling the disk.

Set MINFREE to 80, since that's a more reasonable value according to the
literature than FFS' 90. Remove a bunch of other unused FFS cruft from
config.h.

Initialize lfs_bfree correctly vis-a-vis MIN_FREE_SEGS, so the
filesystem doesn't over-represent the amount of free space it has.
Initialize lfs_dmeta so the kernel can estimate starting from a
reasonable value.
 1.12 23-May-2000  perseant branches: 1.12.4;
Count the Ifile indirect block too (part of PR#9357)
 1.11 18-May-2000  perseant More corrections to newfs_lfs' handling of segment 0.
 1.10 17-May-2000  perseant Make newfs_lfs use fragments when creating the root and lost+found
directories, rather than full blocks; corrects some minor misaccounting
for segment zero.
 1.9 19-Jan-2000  perseant Fix frag -> fsize typo
 1.8 18-Jan-2000  perseant newfs_lfs now recognizes a zero p_sgs field to mean "use the default segment
size" (for consistency with bsize/fsize, and since segment size == block
size is never a valid combination).

Updated the man page to include explicit reasonable values for fsize, bsize,
and sgs, at suggestion from Hubert Feyrer.
 1.7 18-Jan-2000  perseant disklabel now understands the p_sgs partition field (shift to compute
segment size from block size).

newfs_lfs now reads the disklabel to find segment, block, and fragment
sizes. Because reading this info from the wrong fs type could result in
very poor fs layout (e.g. ffs has "16" where the segshift would go,
resulting in 512-*megabyte* segments for 8K blocks), newfs_lfs refuses
to create a filesystem on a partition not labeled "4.4LFS".

Man pages for newfs_lfs updated to reflect this change.
 1.6 05-Nov-1999  perseant branches: 1.6.2;
Make newfs_lfs try increasingly smaller segment sizes down to 2*block size,
if the partition is so small that not enough segments can be created to
place the second superblock. Addresses PR#7623.
 1.5 22-Jul-1999  perseant branches: 1.5.2;
Address PR bin/7623: if the filesystem is so small (or segment size so large)
that not enough segments are available for the second superblock, or to have
MIN_FREE_SEGS free for work room for the cleaner, newfs_lfs will now exit
with an error.
 1.4 24-Jun-1999  perseant Use ufs_daddr_t instead of u_long, so non-32-bit architectures can clean seg 0
 1.3 30-Mar-1999  perseant branches: 1.3.2;
Correct data checksum to take ifile indirect block into account, if it exists
 1.2 19-Mar-1999  perseant Fixes for newfs_lfs on partitions that would require writing an indirect
block on the Ifile (>~4Gb with standard block/segment size).
 1.1 18-Mar-1999  perseant Change name of newlfs to newfs_lfs.
 1.3.2.3 11-Oct-2000  he Pull up revision 1.20 (requested by he):
Format string cleanup.
 1.3.2.2 05-Sep-1999  he Pull up revision 1.5:
Refuse to create a file system with too few segments, which
would prevent the cleaner from working, fixing PR#7623. (perseant)
 1.3.2.1 25-Jun-1999  perry pullup 1.3->1.4 (perseant)
 1.5.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.2.2 05-Nov-1999  perseant Make newfs_lfs try increasingly smaller segment sizes down to 2*block size,
if the partition is so small that not enough segments can be created to
place the second superblock. Addresses PR#7623.
 1.6.2.1 05-Nov-1999  perseant file lfs.c was added on branch comdex-fall-1999 on 1999-11-05 18:59:13 +0000
 1.12.4.4 03-Feb-2001  he Pull up revisions 1.19,1.21 (requested by perseant):
o Allow the user to specify a 0% free space threshold at fs
creation time with "newfs_lfs -m 0" (PR #11112).
o Initialize inodes' gen to match version.
 1.12.4.3 16-Oct-2000  tv Pullup 1.20 [he]:
Format fixup. size_t can be long, so cast to u_long and print with %ld.
 1.12.4.2 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.12.4.1 03-Jul-2000  thorpej Pull up rev. 1.15:
Default the root directory and lost+found directory to mode 0755,
as in FFS.
 1.21.2.5 13-Jul-2001  perseant Default to creating a v2 lfs, and print out the roll-forward id that
was used. Update newfs_lfs.8 to reflect new options.
 1.21.2.4 10-Jul-2001  perseant Properly initialize and report the inode free list tail.
 1.21.2.3 02-Jul-2001  perseant Change disk addressing unit to be the fragment, instead of the disk sector.
All quantities in the superblock, inodes, indirect blocks, etc. refer now
to this abstract unit (called "fsb" as it is in FFS) instead of disk sectors;
as a consequence segment summary blocks have to be multiples of a fragment in
size. In v1 filesystems, compatibility code ensures that 1 fsb == 1 sector,
regardless of fragment size.

Fragments can now range in size between 512 and 32k; in the event that
LFS_LABELPAD (8k) is smaller than the disk address unit size, an extra
proto-superblock is kept at 8k from the beginning of the disk, to be used
*only* to locate the real superblocks. (Not all of the userland knows about
this yet.)

Almost all of this was done not by me, but by joff.
 1.21.2.2 29-Jun-2001  perseant Get rid of __P(), protoizing where it had not already been done
 1.21.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.33.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.59 15-Oct-2015  dholland Enable the creation of lfs64 volumes.

To create an lfs64 volume, use -w 64. You can also force a 32-bit
volume with -w 32, but this will fail on devices thta are too large.

lfs64 is the default for devices > 1TB. (1TB rather than 2TB because
daddr_t is signed and negative block numbers can cause interesting
complications.)

For now print a warning that the lfs64 format isn't finalized, because
it isn't. For now any lfs64 use should be limited to test data,
benchmarking, and so forth.
 1.58 10-Oct-2015  dholland Use a specific SEGSUM size instead of the size of the union.
 1.57 21-Sep-2015  dholland Fix some assorted 32-bit assumptions not yet otherwise handled.

Also apply patch to fix the overt problem in PR 50246: newfs was
calculating ifpb wrong for volumes with non-default block sizes.
 1.56 21-Sep-2015  dholland Add 64-bit directory entry structures, and adjust accessors accordingly.

The LFS64 directory entry has a 64-bit inode number. This is stored as
two 32-bit values to avoid inducing 64-bit alignment requirements.

The exposed type for manipulating directory entries is now
LFS_DIRHEADER, following the same convention as e.g. IFILE and SEGUSE.
(But with LFS_ on it, because.)
 1.55 21-Sep-2015  dholland Oops; LFS_DIRECTSIZ() is going to need the fs as an argument.

Also, it turns out that dirhash needs a compile-time-constant version
of LFS_DIRECTSIZ(LFS_MAXNAMLEN+1), independent of 64-vs-32, so create
LFS_MAXDIRENTRYSIZE for this. Sigh.
 1.54 15-Sep-2015  dholland Pass around struct lfs_dirheader instead of struct lfs_direct.
 1.53 15-Sep-2015  dholland Add an accessor function for directory names.
 1.52 15-Sep-2015  dholland Add a function lfs_copydirname() to copy directory names in place; use
it in place of (variously) memcpy and strlcpy. (The latter isn't even
correct; was probably changed blindly from strncpy at some point.)

The new function zeroes the padding in the directory entry instead of
leaving trash behind.
 1.51 15-Sep-2015  dholland Move the header part of struct lfs_direct to its own structure.
(lfs_dirheader)

Take the opportunity to improve the directory generation code in
make_lfs.c. (Everything else was unaffected by virtue of using
accessor functions.)
 1.50 15-Sep-2015  dholland Add and use accessor functions for more of the directory entry fields.
 1.49 01-Sep-2015  dholland Add new accessors for the d_type and d_namlen fields of struct lfs_direct.
Napalm the old byteswap access logic for these.
 1.48 01-Sep-2015  dholland Use daddr_t, not ulfs_daddr_t, as the latter's 32 bits wide.
Don't use either for on-disk items.
Declare external data in header files.
Part 3 of 3.
 1.47 01-Sep-2015  dholland Tidy the MAXSYMLINKLEN macros.
 1.46 01-Sep-2015  dholland The ifile's inode number is constant. (it is always 1)

Therefore, storing the value in the superblock and reading it out
again is silly and offers the opportunity for it to become corrupted.
So, don't do that (most of the code already didn't) and use the
existing constant instead. Initialize new 32-bit superblocks with
the value for the sake of old userland programs, but don't keep the
value in the 64-bit superblock at all.

(approved by Margo Seltzer)
 1.45 01-Sep-2015  dholland Add byteswapping to the dinode accessors.

This prevents regressions in the ulfs code when switching to the new
accessors. Note that while adding byteswapping to the other accessors
is straightforward, I haven't done it yet; and that also is not enough
to make LFS_EI work, because there are places lying around that bypass
the accessors for one reason and another and all of them need to be
updated. That is going to have to wait for a later day as LFS_EI is
not on the critical path right now.
 1.44 19-Aug-2015  dholland Part two of dinodes; use the same union everywhere.
(previously the ufs-derived code had things set up slightly different)

Remove a bunch of associated mess.
 1.43 12-Aug-2015  dholland Hack up dinode usage to be 64 vs. 32 as needed. Part 1.

(This part changes the native lfs code; the ufs-derived code already
has 64 vs. 32 logic, but as aspects of it are unsafe, and don't
entirely interoperate cleanly with the lfs 64/32 stuff, pass 2 will be
rehashing that.)
 1.42 12-Aug-2015  dholland Add IFILE32 and IFILE64 structures for the on-disk ifile entries.
Add and use accessors. There are also a bunch of places that cast and
I hope I've found them all...
 1.41 12-Aug-2015  dholland Make 32-bit and 64-bit versions of CLEANERINFO.

XXX: while this is written to disk, it seems like much of it would
XXX: be better set up as a commpage shared with the cleaner.
 1.40 02-Aug-2015  dholland Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.39 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.38 02-Aug-2015  dholland Typo in comment.
 1.37 02-Aug-2015  dholland Use c99 initializers.
 1.36 02-Aug-2015  dholland Second batch of 64 -> 32 truncations in lfs, along with more minor
tidyups and corrections in passing.
 1.35 02-Aug-2015  dholland Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.
 1.34 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.33 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.32 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.31 31-May-2015  hannken Use VFS_PROTOS() for lfs.
Rename conflicting struct lfs field "lfs_start" to "lfs_s0addr".

No functional change.
 1.30 29-Mar-2015  chopps - Fix fallout for recent bread() change (removing cred arg).
 1.29 19-Oct-2013  christos fix unused variable warnings.
 1.28 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.27 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.26 08-Jun-2013  dholland DIRBLKSIZ -> LFS_DIRBLKSIZ
DIRECTSIZ -> LFS_DIRECTSIZ
DIRSIZ -> LFS_DIRSIZ
OLDDIRFMT -> LFS_OLDDIRFMT
NEWDIRFMT -> LFS_NEWDIRFMT
IFTODT -> LFS_IFTODT
DTTOIF -> LFS_DTTOIF
 1.25 08-Jun-2013  dholland struct direct -> struct lfs_direct
struct dirtemplate -> struct lfs_dirtemplate
struct odirtemplate -> struct lfs_odirtemplate
DT_* -> LFS_DT_*
 1.24 08-Jun-2013  dholland Stick LFS_ in front of IFMT, IFIFO, IFREG, etc. so as not to conflict
with the UFS copies of these symbols. (Which themselves ought to have
UFS_ stuck on.)
 1.23 08-Jun-2013  dholland Move the dinode (on-disk inode) structures to lfs.h, since they are
and will be obviously required by userland tools that need to read
the on-disk structures.

Also, DINODE{1,2}_SIZE -> LFS_DINODE{1,2}_SIZE.
 1.22 06-Jun-2013  dholland Cleanups and hacks to make lfs userland stuff build:
- lfs_cksum.c doesn't actually need ulfs_inode.h any more.
- neither does lfs_itimes.c.
- add hacks to fsck_lfs to make it compile.
- add hacks to newfs_lfs to make it compile.
- fix warning in ulfs_quota.c when quotas are fully disabled
(as I guess is happening with the rumpity version)

XXX: This commit adds -I${NETBSDSRCDIR}/sys to the Makefiles for
XXX: fsck_lfs, newfs_lfs, and lfs_cleanerd. This needs to be cleaned
XXX: up ASAP; but I consider this less problematic in the short term
XXX: than spewing ulfs_*.h into /usr/include.
 1.21 06-Jun-2013  dholland ufs -> ulfs for newfs_lfs
 1.20 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.19 16-Feb-2012  perseant branches: 1.19.2;
Pass t_renamerace and t_rmdirrace tests.

Adapt dholland@'s fix to ufs_rename to fix PR kern/43582. Address several
other MP locking issues discovered during the course of investigating the
same problem.

Removed extraneous vn_lock() calls on the Ifile, since the Ifile writes
are controlled by the segment lock.

Fix PR kern/45982 by deemphasizing the estimate of how much metadata
will fill the empty space on disk when the disk is nearly empty
(t_renamerace crates a lot of inode blocks on a tiny empty disk).
 1.18 02-Feb-2012  perseant branches: 1.18.2;
When creating a very small filesystem, use well-known small segment,
block and fragment sizes by default instead of the ordinary 1M/8k/1k
default for larger filesystems.
 1.17 17-Jan-2012  perseant Use an even smaller segment size when creating a very small filesystem.
This allows the lfs_renamerace_dirs case of the t_renamerace test to
fail correctly, rather than with a bogus "file system full" error as it
has since rev 1.135 of sys/ufs/lfs/lfs.h.
 1.16 16-Feb-2010  mlelstv branches: 1.16.6;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.15 22-Feb-2009  dholland Restore newfs_lfs after softdep removal (hi ad)
 1.14 22-Feb-2009  ad PR kern/26878 FFSv2 + softdep = livelock (no free ram)
PR kern/16942 panic with softdep and quotas
PR kern/19565 panic: softdep_write_inodeblock: indirect pointer #1 mismatch
PR kern/26274 softdep panic: allocdirect_merge: ...
PR kern/26374 Long delay before non-root users can write to softdep partitions
PR kern/28621 1.6.x "vp != NULL" panic in ffs_softdep.c:4653 while unmounting a softdep (+quota) filesystem
PR kern/29513 FFS+Softdep panic with unfsck-able file-corruption
PR kern/31544 The ffs softdep code appears to fail to write dirty bits to disk
PR kern/31981 stopping scsi disk can cause panic (softdep)
PR kern/32116 kernel panic in softdep (assertion failure)
PR kern/32532 softdep_trackbufs deadlock
PR kern/37191 softdep: locking against myself
PR kern/40474 Kernel panic after remounting raid root with softdep

Retire softdep, pass 2. As discussed and later formally announced on the
mailing lists.
 1.13 16-May-2008  hannken branches: 1.13.4;
Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.12 28-Apr-2008  martin branches: 1.12.2;
Remove clause 3 and 4 from TNF licenses
 1.11 08-Oct-2007  ad branches: 1.11.8; 1.11.10;
brelse() now takes two args.
 1.10 16-Oct-2006  christos branches: 1.10.8;
c99 initializer
 1.9 05-Sep-2006  riz Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. From Christos Zoulas.
 1.8 11-May-2006  mrg - log2() -> lfs_log2().
- fix a couple of entries in struct lfs lfs_default:
- in a comment, it's called dlfs_freehd now
- dlfs_inodefmt comes after dlfs_tstamp. fortunately for this
one, LFS_44INODEFMT is also 0 so the right thing was happening.
 1.7 04-May-2006  perseant newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.6 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.5 13-Sep-2005  christos make this compile again.
 1.4 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.3 12-Apr-2005  perseant branches: 1.3.2;
Use the buffer cache improvements from fsck_lfs. Make it build again.
 1.2 25-Mar-2005  perseant "#define lfs_devvp lfs_unlockvp" for readability, since that's what we
use it for in fsck_lfs/newfs_lfs.
 1.1 26-Feb-2005  perseant branches: 1.1.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.1.2.2 20-May-2006  riz Pull up following revision(s) (requested by perseant in ticket #1327):
sbin/newfs_lfs/extern.h: revision 1.9
sbin/newfs_lfs/make_lfs.c: revision 1.7
sbin/newfs_lfs/newfs_lfs.8: revision 1.21
sbin/newfs_lfs/newfs.c: revision 1.20
newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.1.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.3.2.2 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.3.2.1 12-Apr-2005  riz file make_lfs.c was added on branch netbsd-2 on 2005-05-10 05:08:57 +0000
 1.10.8.1 06-Nov-2007  matt sync with HEAD
 1.11.10.1 18-May-2008  yamt sync with head.
 1.11.8.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.13.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.16.6.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.16.6.2 23-Jan-2013  yamt sync with head
 1.16.6.1 17-Apr-2012  yamt sync with head
 1.18.2.1 17-Mar-2012  bouyer Pull up following revision(s) (requested by perseant in ticket #116):
sys/ufs/lfs/lfs_alloc.c: revision 1.112
tests/fs/vfs/t_rmdirrace.c: revision 1.9
tests/fs/vfs/t_renamerace.c: revision 1.25
sys/ufs/lfs/lfs_vnops.c: revision 1.240
sys/ufs/lfs/lfs_segment.c: revision 1.224
sys/ufs/lfs/lfs_bio.c: revision 1.122
sys/ufs/lfs/lfs_vfsops.c: revision 1.294
sbin/newfs_lfs/make_lfs.c: revision 1.19
sys/ufs/lfs/lfs.h: revision 1.136
Pass t_renamerace and t_rmdirrace tests.
Adapt dholland@'s fix to ufs_rename to fix PR kern/43582. Address several
other MP locking issues discovered during the course of investigating the
same problem.
Removed extraneous vn_lock() calls on the Ifile, since the Ifile writes
are controlled by the segment lock.
Fix PR kern/45982 by deemphasizing the estimate of how much metadata
will fill the empty space on disk when the disk is nearly empty
(t_renamerace crates a lot of inode blocks on a tiny empty disk).
 1.19.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.2.2 23-Jun-2013  tls resync from head
 1.19.2.1 25-Feb-2013  tls resync with head
 1.7 17-Jan-2007  hubertf Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.6 05-Sep-2006  riz Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. From Christos Zoulas.
 1.5 11-May-2006  mrg - log2() -> lfs_log2().
- fix a couple of entries in struct lfs lfs_default:
- in a comment, it's called dlfs_freehd now
- dlfs_inodefmt comes after dlfs_tstamp. fortunately for this
one, LFS_44INODEFMT is also 0 so the right thing was happening.
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.3 25-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.2 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.1 18-Mar-1999  perseant branches: 1.1.12;
Change name of newlfs to newfs_lfs.
 1.1.12.1 29-Jun-2001  perseant Get rid of __P(), protoizing where it had not already been done
 1.30 15-Oct-2015  dholland Enable the creation of lfs64 volumes.

To create an lfs64 volume, use -w 64. You can also force a 32-bit
volume with -w 32, but this will fail on devices thta are too large.

lfs64 is the default for devices > 1TB. (1TB rather than 2TB because
daddr_t is signed and negative block numbers can cause interesting
complications.)

For now print a warning that the lfs64 format isn't finalized, because
it isn't. For now any lfs64 use should be limited to test data,
benchmarking, and so forth.
 1.29 18-Jun-2013  christos Prefix most of the cpp macros with lfs_ and LFS_ to avoid conflicts with ffs.
This was done so that boot blocks that want to compile both FFS and LFS in
the same file work.
 1.28 08-Jun-2013  dholland Tidy up the LFS userland build hacks.
Don't use -I${NETBSDSRCDIR}/sys; don't include files other than the
exported LFS headers, which are lfs.h, lfs_inode.h, and (for now)
lfs_extern.h.
 1.27 06-Jun-2013  dholland ufs -> ulfs for newfs_lfs
 1.26 02-Feb-2012  perseant branches: 1.26.6;
If invoked with -D and creating an image file, ensure that the image
file is filled to the given size. This prevents false failures
with "lfs: ifile read: 22" in ATF tests.
 1.25 16-Feb-2010  mlelstv branches: 1.25.6;
Three changes in a single commit.

- drop the notion of frags (LFS fragments) vs fsb (FFS fragments)
The code uses a complicated unity function that just makes the
code difficult to understand.

- support larger sector sizes. Fix disk address computations
to use DEV_BSIZE in the kernel as required by device drivers
and to use sector sizes in userland.

- Fix several locking bugs in lfs_bio.c and lfs_subr.c.
 1.24 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.23 05-Sep-2006  riz branches: 1.23.18; 1.23.22;
Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. From Christos Zoulas.
 1.22 06-Aug-2006  perseant Ensure sector size is zero in the debug case, to avoid a division by zero
error pointed out by Zafer Aydogan.
 1.21 06-Aug-2006  perseant Don't try to even fake building a filesystem on a file descriptor that is
neither a file nor a character special device.
 1.20 04-May-2006  perseant newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.19 23-Apr-2006  jld When testing seek speed (for the -A option), use sector-aligned offsets
so the reads don't always fail, and also be more careful not to read off
the end of the disk. If a read does fail, error out instead of silently
leaving the loop early (and possibly dividing by zero seconds), because
it means our idea of the disk size is wrong, or worse.

This fixes PR bin/33199.
 1.18 22-Aug-2005  yamt even with -F, don't overwrite p_size unless filesystem size is
specified by -s.
 1.17 27-Jun-2005  christos add const.
 1.16 12-Apr-2005  perseant Use the buffer cache improvements from fsck_lfs. Make it build again.
 1.15 26-Feb-2005  perseant branches: 1.15.2;
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
 1.14 29-Oct-2004  dsl Add (unsigned char) cast to ctype function
 1.13 12-Aug-2003  dsl branches: 1.13.4;
Stop superblock being written to sector 0 for small filesystems.
Honour the '-s size' command option.
Allow an LFS filesystem to be created in a file.
 1.12 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.11 13-Jul-2003  itojun use bounded string ops
 1.10 12-Dec-2002  scw Use getlabeloffset() instead of LABELOFFSET.
 1.9 29-Aug-2002  perseant Don't use adaptive measuring techniques to discover a good segment size,
if the device is not a character device (they will give bogus results
if they interact with the buffer cache).
 1.8 01-Nov-2001  lukem fix -Wshadow warning by moving "int version" from global to main() scope
 1.7 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.6 05-Dec-2000  perseant branches: 1.6.2;
Add "-A" option to autoconfigure the segment size based on measured
bandwidth and seek time of the disk, using the "4 * bandwidth * seek
time" formula from Neefe-Matthews' 1997 paper. An RZ25 disk with this
option gets 200K segments. Reference the paper in the manual page.
 1.5 11-Oct-2000  he The type of sizeof() can be u_long, so cast to that and print with %ld.
 1.4 04-Jul-2000  perseant Tweak how lfs_avail is initialized, corresponding to changes in the
kernel.

Don't make more superblock segments than we have a record of in
the superblock; and print these out as we go, like newfs.

Add am "-M" flag to specify the number of reserved segments, with a note
in the man page not to use it.
 1.3 12-Feb-2000  perseant branches: 1.3.4;
Add -F flag to override newfs_lfs' preference for 4.4LFS-labelled partitions.
 1.2 15-Jul-1999  perseant Address PR 7412: fix newfs_lfs.8 to list all real options for newfs_lfs;
also fix newfs_lfs to get rid of all sorts of useless options that applied
only to newfs_ffs. Corrected reference to the FFS paper to the reference
to the BSD-LFS paper.
 1.1 18-Mar-1999  perseant branches: 1.1.2;
Change name of newlfs to newfs_lfs.
 1.1.2.1 11-Oct-2000  he Pull up revision 1.5 (requested by he):
Format string cleanup.
 1.3.4.2 16-Oct-2000  tv Pullup 1.5 [he]:
The type of sizeof() can be u_long, so cast to that and print with %ld.
 1.3.4.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.6.2.3 13-Jul-2001  perseant Default to creating a v2 lfs, and print out the roll-forward id that
was used. Update newfs_lfs.8 to reflect new options.
 1.6.2.2 29-Jun-2001  perseant Get rid of __P(), protoizing where it had not already been done
 1.6.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.13.4.1 10-May-2005  riz Pull up the following revisions (requested by perseant in ticket #1281):

1.8 sys/ufs/lfs/TODO
1.75 sys/ufs/lfs/lfs.h (via patch)
1.74 sys/ufs/lfs/lfs_alloc.c (via patch)
1.49, 1.51 sys/ufs/lfs/lfs_balloc.c (1.51 via patch)
1.78 sys/ufs/lfs/lfs_bio.c
1.62 sys/ufs/lfs/lfs_extern.h (via patch)
1.156 sys/ufs/lfs/lfs_segment.c (via patch)
1.48 sys/ufs/lfs/lfs_subr.c
1.101 sys/ufs/lfs/lfs_syscalls.c
1.163 sys/ufs/lfs/lfs_vfsops.c (via patch)
1.134 sys/ufs/lfs/lfs_vnops.c (via patch)
1.61 sys/ufs/ufs/ufs_readwrite.c (via patch)

1.20 libexec/lfs_cleanerd/clean.h (via patch)
1.52 libexec/lfs_cleanerd/cleanerd.c (via patch)
1.41 libexec/lfs_cleanerd/library.c (via patch)

1.4 regress/sys/fs/lfs/newfs_fsck/Makefile
1.2 regress/sys/fs/lfs/newfs_fsck/mkfs_mount
1.2 regress/sys/fs/lfs/newfs_fsck/smallfiles
1.3 sbin/fsck_lfs/bufcache.c
1.3 sbin/fsck_lfs/bufcache.h
1.3 sbin/fsck_lfs/lfs.h
1.8 sbin/fsck_lfs/lfs.c (via patch)
1.8 sbin/fsck_lfs/pass3.c (via patch)
1.18 sbin/fsck_lfs/pass0.c (via patch)
1.18 sbin/fsck_lfs/utilities.c (via patch)
1.7 sbin/fsck_lfs/segwrite.c
1.19 sbin/fsck_lfs/setup.c (via patch)
1.3 sbin/newfs_lfs/Makefile
0 sbin/newfs_lfs/lfs.c (yes, remove it)
1.1 sbin/newfs_lfs/make_lfs.c
1.15 sbin/newfs_lfs/newfs.c (via patch)

Various minor LFS improvements.

Kernel:

* Note when lfs_putpages(9) thinks it is not going to be writing any
pages before calling genfs_putpages(9). This prevents a situation in
which blocks can be queued for writing without a segment header.
* Correct computation of NRESERVE(), though it is still a gross
overestimate in most cases. Note that if NRESERVE() is too high, it
may be impossible to create files on the filesystem. We catch this
case on filesystem mount and refuse to mount r/w.
* Allow filesystems to be mounted whose block size is == MAXBSIZE.
* Somewhere along the line, ufs_bmaparray(9) started mangling UNWRITTEN
entries in indirect blocks again, triggering a failed assertion "daddr
<= LFS_MAX_DADDR". Explicitly convert to and from int32_t to correct
this. Should fix PR #29045.
* Add a high-water mark for the number of dirty pages any given LFS can
hold before triggering a flush. This is settable by sysctl, but off
(zero) by default.
* Be more careful about the MAX_BYTES and MAX_BUFS computations so we
shouldn't see "please increase to at least zero" messages.
* Note that VBLK and VCHR vnodes can have nonzero values in di_db[0]
even though their v_size == 0. Don't panic when we see this.
Fixes PR #26680.
* Change lfs_bfree to a signed quantity. The manner in which it is
processed before being passed to the cleaner means that sometimes it
may drop below zero, and the cleaner must be aware of this.
* Never report bfree < 0 (or higher than lfs_dsize) through
lfs_statfs(9). This prevents df(1) from ever telling us that our full
filesystems have 16TB free.
* Account space allocated through lfs_balloc(9) that does not have
associated buffer headers, so that the pagedaemon doesn't run us out
of segments.
* Return ENOSPC from lfs_balloc(9) when bfree drops to zero.
* Address a deadlock in lfs_bmapv/lfs_markv when the filesystem is being
unmounted. Because vfs_busy() is a shared lock, and
lfs_bmapv/lfs_markv mark the filesystem vfs_busy(), the cleaner can be
holding the lock that umount() is blocking on, then try to vfs_busy()
again in getnewvnode().

cleaner:

* Adapt lfs_cleanerd to use the fcntl call to get the Ifile filehandle,
so it need not be in the namespace.
* Make lfs_cleanerd be more careful when there are very few available
segments.
* Make lfs_cleanerd less verbose when the filesystem is unmounted.

newfs_lfs, fsck_lfs, and regression:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
not-yet-existent LFS. Make newfs_lfs(8) use this library, so it can
create LFSs whose Ifile is larger than one segment. Addresses PR #11110.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
-n flag.
* Remove the Ifile from the filesystem namespace. The cleaner now uses
a fcntl call on the root inode to find the Ifile filehandle. (As a
side-effect, addresses PR #29144.)
 1.15.2.3 02-Sep-2006  ghen Pull up following revision(s) (requested by jld in ticket #1494):
sbin/newfs_lfs/newfs.c: revision 1.19
When testing seek speed (for the -A option), use sector-aligned offsets
so the reads don't always fail, and also be more careful not to read off
the end of the disk. If a read does fail, error out instead of silently
leaving the loop early (and possibly dividing by zero seconds), because
it means our idea of the disk size is wrong, or worse.
This fixes PR bin/33199.
 1.15.2.2 20-May-2006  riz Pull up following revision(s) (requested by perseant in ticket #1327):
sbin/newfs_lfs/extern.h: revision 1.9
sbin/newfs_lfs/make_lfs.c: revision 1.7
sbin/newfs_lfs/newfs_lfs.8: revision 1.21
sbin/newfs_lfs/newfs.c: revision 1.20
newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.15.2.1 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.23.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.23.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.25.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.25.6.1 17-Apr-2012  yamt sync with head
 1.26.6.1 23-Jun-2013  tls resync from head
 1.24 15-Oct-2015  dholland Enable the creation of lfs64 volumes.

To create an lfs64 volume, use -w 64. You can also force a 32-bit
volume with -w 32, but this will fail on devices thta are too large.

lfs64 is the default for devices > 1TB. (1TB rather than 2TB because
daddr_t is signed and negative block numbers can cause interesting
complications.)

For now print a warning that the lfs64 format isn't finalized, because
it isn't. For now any lfs64 use should be limited to test data,
benchmarking, and so forth.
 1.23 04-Jan-2014  wiz New sentence, new line. Remove trailing whitespace.
 1.22 08-Apr-2009  joerg branches: 1.22.6; 1.22.12;
Fix markup.
 1.21 04-May-2006  perseant branches: 1.21.30;
newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.20 07-Aug-2003  agc branches: 1.20.6;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.19 23-Feb-2003  perseant Discourage the creation of new LFSv1 filesystems.
 1.18 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.17 21-Jan-2002  wiz Use mdoc macros instead of man ones.
 1.16 16-Nov-2001  wiz Punctuation fixes, sort SEE ALSO, use an mdoc macros instead of two man macros.
 1.15 16-Nov-2001  wiz Whitespace nits
 1.14 08-Sep-2001  mason The default version created by newfs_lfs without arguments is, in fact, 2.
 1.13 13-Jul-2001  perseant Merge the short-lived perseant-lfsv2 branch into the trunk.

Kernels and tools understand both v1 and v2 filesystems; newfs_lfs
generates v2 by default. Changes for the v2 layout include:

- Segments of non-PO2 size and arbitrary block offset, so these can be
matched to convenient physical characteristics of the partition (e.g.,
stripe or track size and offset).

- Address by fragment instead of by disk sector, paving the way for
non-512-byte-sector devices. In theory fragments can be as large
as you like, though in reality they must be smaller than MAXBSIZE in size.

- Use serial number and filesystem identifier to ensure that roll-forward
doesn't get old data and think it's new. Roll-forward is enabled for
v2 filesystems, though not for v1 filesystems by default.

- The inode free list is now a tailq, paving the way for undelete (undelete
is not yet implemented, but can be without further non-backwards-compatible
changes to disk structures).

- Inode atime information is kept in the Ifile, instead of on the inode;
that is, the inode is never written *just* because atime was changed.
Because of this the inodes remain near the file data on the disk, rather
than wandering all over as the disk is read repeatedly. This speeds up
repeated reads by a small but noticeable amount.

Other changes of note include:

- The ifile written by newfs_lfs can now be of arbitrary length, it is no
longer restricted to a single indirect block.

- Fixed an old bug where ctime was changed every time a vnode was created.
I need to look more closely to make sure that the times are only updated
during write(2) and friends, not after-the-fact during a segment write,
and certainly not by the cleaner.
 1.12 05-Jun-2001  wiz branches: 1.12.2;
Drop arguments of .Os.
 1.11 05-Dec-2000  perseant Add "-A" option to autoconfigure the segment size based on measured
bandwidth and seek time of the disk, using the "4 * bandwidth * seek
time" formula from Neefe-Matthews' 1997 paper. An RZ25 disk with this
option gets 200K segments. Reference the paper in the manual page.
 1.10 08-Nov-2000  hubertf xref lfs_cleanerd(8) in SEE ALSO
 1.9 08-Nov-2000  hubertf In SEE ALSO:
* it's dump_lfs(8), not dumplfs(8)
* xref mount_lfs(8)
 1.8 04-Jul-2000  perseant Tweak how lfs_avail is initialized, corresponding to changes in the
kernel.

Don't make more superblock segments than we have a record of in
the superblock; and print these out as we go, like newfs.

Add am "-M" flag to specify the number of reserved segments, with a note
in the man page not to use it.
 1.7 12-Feb-2000  perseant branches: 1.7.4;
Add -F flag to override newfs_lfs' preference for 4.4LFS-labelled partitions.
 1.6 05-Feb-2000  enami - The -B flag should be followed by logical segment size.
- Remove unnecessary comma at the end of SEE ALSO list.
 1.5 18-Jan-2000  perseant newfs_lfs now recognizes a zero p_sgs field to mean "use the default segment
size" (for consistency with bsize/fsize, and since segment size == block
size is never a valid combination).

Updated the man page to include explicit reasonable values for fsize, bsize,
and sgs, at suggestion from Hubert Feyrer.
 1.4 18-Jan-2000  perseant disklabel now understands the p_sgs partition field (shift to compute
segment size from block size).

newfs_lfs now reads the disklabel to find segment, block, and fragment
sizes. Because reading this info from the wrong fs type could result in
very poor fs layout (e.g. ffs has "16" where the segshift would go,
resulting in 512-*megabyte* segments for 8K blocks), newfs_lfs refuses
to create a filesystem on a partition not labeled "4.4LFS".

Man pages for newfs_lfs updated to reflect this change.
 1.3 16-Jan-2000  hubertf Document the proper fstype for LFS. (If the "default" 4.2BSD is used,
newfs_lfs runs fine, but I get hangs when writing to the disk)
 1.2 15-Jul-1999  perseant Address PR 7412: fix newfs_lfs.8 to list all real options for newfs_lfs;
also fix newfs_lfs to get rid of all sorts of useless options that applied
only to newfs_ffs. Corrected reference to the FFS paper to the reference
to the BSD-LFS paper.
 1.1 18-Mar-1999  perseant Change name of newlfs to newfs_lfs.
 1.7.4.1 14-Sep-2000  perseant Pull up LFS userland changes to correspond with the previous commit's
kernel changes (approved by thorpej):

[basesrc/libexec/lfs_cleanerd:]
cleanerd.c, 1.20--1.22 (MIN_FREE_SEG -> lfs_minfreeseg ;
read bfree/avail from CLEANERINFO ;
changes to definition of -n and -b)
lfs_cleanerd.8, 1.7 (update man page to current behavior)
library.c, 1.16 (fix comment)

[basesrc/sbin/fsck_lfs:]
pass5.c, 1.6 (calculate/fix lfs_avail and lfs_bfree)

[basesrc/sbin/newfs_lfs:]
config.h, 1.2--1.5 (MINFREE=20, remove FFS cruft ;
add DFL_MIN_FREE_SEGS=8 and MINFREE=10 ;
set DFL_MIN_FREE_SEGS=10 ;
set DFL_MIN_FREE_SEGS=20)
extern.h, 1.2 (correct function declaration for make_lfs)
newfs.c, 1.4 (add -M flag)
lfs.c, 1.13--1.14, 1.16--1.18 (change lfs_bfree initialization ;
MIN_FREE_SEG -> lfs_minfreeseg ;
only 10 superblocks and print nicely ;
correct init calculation of
lfs_bfree/lfs_avail to allow fs to
fill ;
make -N dtrt)

[basesrc/sbin/mount_lfs:]
mount_lfs.8, 1.7 (document -N, -b flags)
mount_lfs.c, 1.10 (default cleanerd to -b -n 4; add -N,
-b flags)

[basesrc/usr.sbin/dumplfs:]
dumplfs.c, 1.15 (print only the SEGUSEs specified with -s)
 1.12.2.2 13-Jul-2001  perseant Default to creating a v2 lfs, and print out the roll-forward id that
was used. Update newfs_lfs.8 to reflect new options.
 1.12.2.1 27-Jun-2001  perseant Import of what I've been calling "LFSv2", that is, LFS with some features
added that require changes to the on-disk data structures. These include:

- 64-bit time in everything but inodes
- User-specified segment offset, and segment size no longer
restricted to PO2.
- Serial number on segment summaries in addition to timestamp, and
a new volume identifier, to make roll-forward feasible without
fear of finding old data and thinking it was new.

Although I think this version works at least as well as what's on the trunk,
we're not done yet; hence this commit is going in on a branch and not on
the trunk. Enhancements that are not here yet include fragment addressing,
like FFS does, instead of block addressing.
 1.20.6.1 20-May-2006  riz Pull up following revision(s) (requested by perseant in ticket #1327):
sbin/newfs_lfs/extern.h: revision 1.9
sbin/newfs_lfs/make_lfs.c: revision 1.7
sbin/newfs_lfs/newfs_lfs.8: revision 1.21
sbin/newfs_lfs/newfs.c: revision 1.20
newfs_lfs(8) compoment of the recent superblock parameter addition. Change
the wording of the explanation of the -M option, detail a new -R option
that controls initial setting of the new parameter.
 1.21.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.6 21-Jan-2013  christos Split the make fs portion into a function; do argument tests inside the
function.
 1.5 05-Jun-2009  haad branches: 1.5.6; 1.5.12;
Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.4 11-Aug-2008  christos teach this about wedges.
 1.3 10-Sep-2001  christos branches: 1.3.34; 1.3.38;
- Remove old files.
- Port to NetBSD
XXX: *untested*
 1.2 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.1 01-Mar-1997  christos branches: 1.1.1;
From FreeBSD's mkdosfs:
- KNF
- cleaned up a few typos.
- use the msdosfs header files.
- separated Makefile and Makefile.boot, since we cannot build
bootcode.h (yet)
ToDo:
- Make it work on hard disks; only works on floppies
- Make it accept an msdos.sys io.sys and a command.com, to make
a real dos bootable disk.
 1.1.1.1 10-Sep-2001  christos Import FreeBSD's newfs_msdos
 1.3.38.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.34.1 28-Sep-2008  mjf Sync with HEAD.
 1.5.12.1 25-Feb-2013  tls resync with head
 1.5.6.1 23-Jan-2013  yamt sync with head
 1.3 10-Sep-2001  christos - Remove old files.
- Port to NetBSD
XXX: *untested*
 1.2 09-Jan-1998  perry RCS Id Police.
 1.1 01-Mar-1997  christos From FreeBSD's mkdosfs:
- KNF
- cleaned up a few typos.
- use the msdosfs header files.
- separated Makefile and Makefile.boot, since we cannot build
bootcode.h (yet)
ToDo:
- Make it work on hard disks; only works on floppies
- Make it accept an msdos.sys io.sys and a command.com, to make
a real dos bootable disk.
 1.2 10-Sep-2001  christos - Remove old files.
- Port to NetBSD
XXX: *untested*
 1.1 01-Mar-1997  christos From FreeBSD's mkdosfs:
- KNF
- cleaned up a few typos.
- use the msdosfs header files.
- separated Makefile and Makefile.boot, since we cannot build
bootcode.h (yet)
ToDo:
- Make it work on hard disks; only works on floppies
- Make it accept an msdos.sys io.sys and a command.com, to make
a real dos bootable disk.
 1.3 10-Sep-2001  christos - Remove old files.
- Port to NetBSD
XXX: *untested*
 1.2 09-Jan-1998  perry RCS Id Police.
 1.1 01-Mar-1997  christos From FreeBSD's mkdosfs:
- KNF
- cleaned up a few typos.
- use the msdosfs header files.
- separated Makefile and Makefile.boot, since we cannot build
bootcode.h (yet)
ToDo:
- Make it work on hard disks; only works on floppies
- Make it accept an msdos.sys io.sys and a command.com, to make
a real dos bootable disk.
 1.15 12-Oct-2019  martin When we end up with too few clusters for the requested FAT type after
configuring default values, retry with a smaller cluster size.
This makes the typical invocation to create a spec conformant EFI boot
partition work out of the box.
 1.14 04-Feb-2018  mrg branches: 1.14.4; 1.14.6;
updates for GCC 6.4:

identd has aliasing violations, use -fno-strict-aliasing.

newfs_msdos's getbpbinfo() has missing {} issues.

sysctl's kern_cp_id() has missing {} issues.
 1.13 14-Apr-2017  christos Use the create_size if given to compute the real size instead of stat'ing
the file again, which might have been larger to start with.
 1.12 16-Feb-2017  christos Allow 0 timestamp
 1.11 16-Feb-2017  christos add -T for reproducible builds (used in makefs)
 1.10 03-Apr-2016  mlelstv branches: 1.10.2; 1.10.4;
Use the same defaults for cluster sizes as Windows.
 1.9 05-Jan-2014  martin PR bin/46743: mark the "next free cluster" value in the file system
info block as unitialized.
 1.8 19-Oct-2013  christos fix unused variable warnings.
 1.7 03-Feb-2013  christos branches: 1.7.4;
don't truncate the file if an offset is given.
 1.6 27-Jan-2013  christos nbtool_config.h undefines _NETBSD_SOURCE, and that makes <sys/types.h> not
define cpuid_t, which makes <sys/mount.h> unincludable. Although this is a
bug in the build system, it is simpler to fix it here.
 1.5 24-Jan-2013  christos toolify
 1.4 24-Jan-2013  christos don't do the partition dance for makefs; we have no real disk
 1.3 23-Jan-2013  christos We don't need getdiskinfo() for makefs() since we always deal with an image.
 1.2 23-Jan-2013  christos fix regressions after split.
 1.1 21-Jan-2013  christos branches: 1.1.2;
Split the make fs portion into a function; do argument tests inside the
function.
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 21-Jan-2013  yamt file mkfs_msdos.c was added on branch yamt-pagecache on 2013-01-23 00:05:32 +0000
 1.7.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.4.2 25-Feb-2013  tls resync with head
 1.7.4.1 03-Feb-2013  tls file mkfs_msdos.c was added on branch tls-maxphys on 2013-02-25 00:28:10 +0000
 1.10.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.10.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.10.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14.6.1 12-Oct-2019  bouyer Pull up following revision(s) (requested by martin in ticket #303):
sbin/newfs_msdos/mkfs_msdos.c: revision 1.15
When we end up with too few clusters for the requested FAT type after
configuring default values, retry with a smaller cluster size.
This makes the typical invocation to create a spec conformant EFI boot
partition work out of the box.
 1.14.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.6 17-Feb-2017  wiz file system police.
 1.5 16-Feb-2017  christos Allow 0 timestamp
 1.4 16-Feb-2017  christos add -T for reproducible builds (used in makefs)
 1.3 16-Oct-2015  christos branches: 1.3.2; 1.3.4;
remove advertising clause.
 1.2 23-Jan-2013  christos branches: 1.2.4;
fix regressions after split.
 1.1 21-Jan-2013  christos branches: 1.1.2;
Split the make fs portion into a function; do argument tests inside the
function.
 1.1.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.2 23-Jan-2013  yamt sync with head
 1.1.2.1 21-Jan-2013  yamt file mkfs_msdos.h was added on branch yamt-pagecache on 2013-01-23 00:05:32 +0000
 1.2.4.2 25-Feb-2013  tls resync with head
 1.2.4.1 23-Jan-2013  tls file mkfs_msdos.h was added on branch tls-maxphys on 2013-02-25 00:28:10 +0000
 1.3.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.3.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.24 11-Dec-2020  ryoon Describe after example like other examples
 1.23 17-Feb-2017  wiz file system police.
 1.22 16-Feb-2017  christos add -T for reproducible builds (used in makefs)
 1.21 12-Sep-2016  sevan branches: 1.21.2;
Note the origin of the newfs_msdos command from FreeBSD 3.0.
Replace contraction.
s/filesystem/file system/
Bump date.
 1.20 24-Apr-2014  christos branches: 1.20.6;
Fix volume name (Ed Maste)
 1.19 18-Mar-2014  riastradh branches: 1.19.2;
Merge riastradh-drm2 to HEAD.
 1.18 20-Jul-2013  wiz Use Mt for email addresses.
 1.17 26-Mar-2009  wiz branches: 1.17.6; 1.17.12; 1.17.16;
New sentence, new line.
 1.16 26-Mar-2009  pooka Apply revisions 1.23 and 1.24 from FreeBSD to autocalculate the
necessary geometry when creating a file system directly to a file.

In addition, when creating, do not complain about the file not
being char special and do not try to execute device ioctl's on it.
 1.15 25-Nov-2006  scw branches: 1.15.28;
Don't use negative offsets from "bpb.bps" when writing out values such
as DOSMAGIC in the MBR. In non-512 byte media, the MBR is still 512
bytes in length.

Based on the patches provided in PR kern/17398 by Trevin Beattie.
 1.14 22-Sep-2004  thorpej Change the default volume label from "NO NAME" to "NO_NAME". Note the
default in the manual page.
 1.13 22-Sep-2004  thorpej Default the OEM ID to "NetBSD" rather than "BSD 4.4". (Geez, did 4.4BSD
even have a newfs_msdos command?)
 1.12 22-Sep-2004  thorpej Correct some examples, and note when it was first included in NetBSD,
not FreeBSD.
 1.11 24-Apr-2003  wiz branches: 1.11.2;
Bump date for last.
 1.10 21-Apr-2003  dbj add a SIGINFO handler progress indicator
 1.9 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.8 16-Nov-2001  wiz Sort sections.
 1.7 10-Sep-2001  christos - Remove old files.
- Port to NetBSD
XXX: *untested*
 1.6 10-Mar-1999  erh Add missing .El line.
 1.5 22-May-1998  msaitoh sort entries and delete extra periods in SEE also section.
 1.4 29-Apr-1998  fair fix bad .Xr references
 1.3 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.2 12-Mar-1997  christos Fix PR/3322, reference to non existant program.
 1.1 01-Mar-1997  christos branches: 1.1.1;
From FreeBSD's mkdosfs:
- KNF
- cleaned up a few typos.
- use the msdosfs header files.
- separated Makefile and Makefile.boot, since we cannot build
bootcode.h (yet)
ToDo:
- Make it work on hard disks; only works on floppies
- Make it accept an msdos.sys io.sys and a command.com, to make
a real dos bootable disk.
 1.1.1.1 10-Sep-2001  christos Import FreeBSD's newfs_msdos
 1.11.2.3 23-Sep-2004  jmc Pullup rev 1.14 (requested by thorpej in ticket #870)

Change the default volume label from "NO NAME" to "NO_NAME".
 1.11.2.2 23-Sep-2004  jmc Pullup rev 1.13 (requested by thorpej in ticket #869)

Default the OEM ID to "NetBSD" rather than "BSD 4.4".
 1.11.2.1 23-Sep-2004  jmc Pullup rev 1.12 (requested by thorpej in ticket #868)

Correct some examples, and note when it was first included
 1.15.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.17.16.1 23-Jul-2013  riastradh sync with HEAD
 1.17.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19.2.1 10-Aug-2014  tls Rebase.
 1.20.6.1 20-Mar-2017  pgoyette Sync with HEAD
 1.21.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.45 16-Feb-2017  christos Allow 0 timestamp
 1.44 16-Feb-2017  christos add -T for reproducible builds (used in makefs)
 1.43 23-Apr-2015  abs branches: 1.43.2; 1.43.4;
newfs_msdos allowed suffixes such as 'k', 'm' for some parameters,
but amusingly this did not include Block size, or Sectors per cluster.
Allow for all numeric parameters (If I want to specify the number
of drive heads as '1K', then why not?)
 1.42 23-Jan-2013  christos fix regressions after split.
 1.41 21-Jan-2013  christos Split the make fs portion into a function; do argument tests inside the
function.
 1.40 15-Dec-2012  jakllsch There are two problems with insisting the FAT file system size be a multiple
of track-size units: 2) the FAT metadata areas may not be a multiple of a
"track", 1) the partition may not be track-aligned to begin with, 0) what's
a "track"? is it something a robot rover leaves on Mars?
 1.39 04-Nov-2012  jakllsch According to current file(1) magic definitions an unlabeled FAT is
denoted with "NO NAME" rather than "NO_NAME".
 1.38 31-Jul-2012  jakllsch branches: 1.38.2;
Use correct values for minimum and maximum cluster counts for the various FAT
types. These values come from a publically-avaliable document of an
infallible source that must not be named due to a violation of the document's
license restrictions. This is justified by interoperability concerns.
 1.37 04-Jul-2012  jakllsch constify opts[]
 1.36 29-Aug-2011  joerg branches: 1.36.2;
Use __dead
 1.35 05-Mar-2011  pooka Set errno to 0 before strtoll() so that it can reliably be tested
afterwards. Fixes newfs_msdos at least on sparc. Incidentally,
the msdosfs tests also start working on sparc, which about halves
the number of test failures on that platform.
 1.34 11-Apr-2009  lukem fix sign-compare issues
 1.33 28-Mar-2009  he Add a cast to intmax_t and use %jd to print an off_t.
Fixes at least the alpha and amd64 builds.
 1.32 28-Mar-2009  pooka remove troublesome printf specifier
 1.31 26-Mar-2009  pooka Apply revisions 1.23 and 1.24 from FreeBSD to autocalculate the
necessary geometry when creating a file system directly to a file.

In addition, when creating, do not complain about the file not
being char special and do not try to execute device ioctl's on it.
 1.30 17-Feb-2009  christos Use the wedge size, not the disk size, from Yorick Hardy
 1.29 18-Jan-2009  mrg branches: 1.29.2;
Do not erroneously leave a truncated 16-bit sector
count on "large" (>=32MB) file systems when fetching the geometry from
the medium. This confuses some software (which is to say Windows)
when a device newfs(8)ed under NetBSD is transported to another
system. (Note: The rest of the code uses 'bsec', and DTRT for smaller
file systems.)

contributed anonymously.
 1.28 26-Dec-2008  jmcneill The kernel now accepts BPB with heads > 255, so don't limit the number
of drive heads.
 1.27 11-Aug-2008  christos branches: 1.27.2;
teach this about wedges.
 1.26 08-Feb-2007  drochner branches: 1.26.12; 1.26.16;
include <signal.h> where signal(3) is used
 1.25 21-Jan-2007  cbiere Avoid crash if the filename contains no digits.
 1.24 25-Nov-2006  scw Don't use negative offsets from "bpb.bps" when writing out values such
as DOSMAGIC in the MBR. In non-512 byte media, the MBR is still 512
bytes in length.

Based on the patches provided in PR kern/17398 by Trevin Beattie.
 1.23 16-Oct-2006  christos c99 initializers
 1.22 27-Sep-2006  christos Coverity CID 3788: comment out impossible code.
 1.21 25-May-2006  christos Coverity CID 830: Fix dead code issue
 1.20 23-May-2006  christos Coverity CID 3287: Comment out dead code.
 1.19 16-Apr-2005  tsutsui Add a tweak to default value settings for a number of drive heads
and a number of sectors per track.

According to sys/fs/msdosfs/msdosfs_vfsops.c:msdosfs_mountfs(),
the kernel doesn't accept BPB with spt (sector per track) > 63
or hds (drive heads) > 255, so if values taken from disklabel
don't match these restrictions, use popular BIOS default values
(255/63) instead.
 1.18 29-Oct-2004  dsl branches: 1.18.2;
Add (unsigned char) cast to ctype function
 1.17 22-Sep-2004  thorpej Change the default volume label from "NO NAME" to "NO_NAME". Note the
default in the manual page.
 1.16 22-Sep-2004  thorpej Default the OEM ID to "NetBSD" rather than "BSD 4.4". (Geez, did 4.4BSD
even have a newfs_msdos command?)
 1.15 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.14 05-Jan-2004  jmmv branches: 1.14.2;
Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.13 23-Nov-2003  lukem Determine the MBR partition type relevant for the resulting partition,
and display that.
 1.12 08-Oct-2003  lukem add some more detail to an error message
 1.11 13-Jul-2003  itojun snprintf
 1.10 21-Apr-2003  dbj add a SIGINFO handler progress indicator
 1.9 17-Sep-2001  toshii Uncomment-out part of FreeBSD code so that we can calculate partition
index from a filename.
 1.8 10-Sep-2001  pooka * expand device name to raw device, not block device (eg. wd0a -> /dev/rwd0a)
* #ifdef non-relevant FreeBSD slice consistency check
 1.7 10-Sep-2001  christos - Remove old files.
- Port to NetBSD
XXX: *untested*
 1.6 19-Feb-2001  cgd convert to use getprogname()
 1.5 04-Feb-2001  christos fix nested extern
 1.4 26-Jul-1999  cgd after determining the size of a file being used as a msdosfs, seek back to
its start so subsequent writes go to the right places.
 1.3 17-Oct-1997  drochner branches: 1.3.4;
make it compile again after msdosfs changes
 1.2 15-Sep-1997  lukem * cleanup for WARNS=1
 1.1 01-Mar-1997  christos branches: 1.1.1;
From FreeBSD's mkdosfs:
- KNF
- cleaned up a few typos.
- use the msdosfs header files.
- separated Makefile and Makefile.boot, since we cannot build
bootcode.h (yet)
ToDo:
- Make it work on hard disks; only works on floppies
- Make it accept an msdos.sys io.sys and a command.com, to make
a real dos bootable disk.
 1.1.1.1 10-Sep-2001  christos Import FreeBSD's newfs_msdos
 1.3.4.1 20-Aug-1999  cgd pull up rev 1.4 from trunk (cgd)
 1.14.2.2 23-Sep-2004  jmc Pullup rev 1.17 (requested by thorpej in ticket #870)

Change the default volume label from "NO NAME" to "NO_NAME".
 1.14.2.1 23-Sep-2004  jmc Pullup rev 1.16 (requested by thorpej in ticket #869)

Default the OEM ID to "NetBSD" rather than "BSD 4.4".
 1.18.2.1 01-May-2005  tron Pull up revision 1.19 (requested by tsutsui in ticket #230):
Add a tweak to default value settings for a number of drive heads
and a number of sectors per track.
According to sys/fs/msdosfs/msdosfs_vfsops.c:msdosfs_mountfs(),
the kernel doesn't accept BPB with spt (sector per track) > 63
or hds (drive heads) > 255, so if values taken from disklabel
don't match these restrictions, use popular BIOS default values
(255/63) instead.
 1.26.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.26.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.26.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.27.2.3 27-Nov-2009  sborrill Pull up the following revisions(s) (requested by tsutsui in ticket #1163):
sbin/newfs_msdos/newfs_msdos.c: revision 1.30

Make fs size detection get proper size rather than disk size.
Without this, newfs_msdos(8) assumes the target fs size is
whole disk size, so newfs_msdos(8) will fail or create wrong fs.
 1.27.2.2 02-Feb-2009  snj branches: 1.27.2.2.2; 1.27.2.2.4;
Pull up following revision(s) (requested by mrg in ticket #389):
sbin/newfs_msdos/newfs_msdos.c: revision 1.29
Do not erroneously leave a truncated 16-bit sector
count on "large" (>=32MB) file systems when fetching the geometry from
the medium. This confuses some software (which is to say Windows)
when a device newfs(8)ed under NetBSD is transported to another
system. (Note: The rest of the code uses 'bsec', and DTRT for smaller
file systems.)
contributed anonymously.
 1.27.2.1 22-Jan-2009  snj Pull up following revision(s) (requested by jmcneill in ticket #285):
sbin/newfs_msdos/newfs_msdos.c: revision 1.28
The kernel now accepts BPB with heads > 255, so don't limit the number
of drive heads.
 1.27.2.2.4.1 21-Apr-2010  matt sync to netbsd-5
 1.27.2.2.2.1 27-Nov-2009  sborrill Pull up the following revisions(s) (requested by tsutsui in ticket #1163):
sbin/newfs_msdos/newfs_msdos.c: revision 1.30

Make fs size detection get proper size rather than disk size.
Without this, newfs_msdos(8) assumes the target fs size is
whole disk size, so newfs_msdos(8) will fail or create wrong fs.
 1.29.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.36.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.2.3 23-Jan-2013  yamt sync with head
 1.36.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.36.2.1 30-Oct-2012  yamt sync with head
 1.38.2.2 25-Feb-2013  tls resync with head
 1.38.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.43.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.43.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.5 06-Aug-2011  dholland No longer any need for -Wno-pointer-sign here.
 1.4 20-Jun-2011  mrg remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.3 29-Aug-2008  gmcgarry branches: 1.3.16;
Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.2 11-May-2006  mrg branches: 1.2.20; 1.2.24;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.1 29-Dec-2005  tsutsui Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.2.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.3.16.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.6 12-Sep-2016  sevan Add AUTHORS section.
Bump date.
 1.5 10-Apr-2009  wiz Sort option descriptions.
 1.4 09-Apr-2009  pooka Support creating a file system to a regular file.
 1.3 04-Aug-2007  pooka branches: 1.3.16; 1.3.20;
typographical fixes

from Matthew Wala in misc/36729
 1.2 12-Jan-2006  wiz More markup, sort SEE ALSO, remove superfluous Pp.
 1.1 29-Dec-2005  tsutsui Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.3.20.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.3.16.2 04-Aug-2007  pooka typographical fixes

from Matthew Wala in misc/36729
 1.3.16.1 04-Aug-2007  pooka file newfs_sysvbfs.8 was added on branch matt-mips64 on 2007-08-04 10:45:37 +0000
 1.10 10-Jan-2017  christos fix includes, addr __RCSID
 1.9 23-Mar-2014  dholland branches: 1.9.8;
don't use sprintf
 1.8 29-Aug-2011  joerg branches: 1.8.2; 1.8.8;
Use __dead
 1.7 11-Apr-2009  lukem fix sign-compare issue
 1.6 11-Apr-2009  lukem fix sign-compare issue
 1.5 10-Apr-2009  wiz Sync usage with man page; remove 0xa0 character from usage.
 1.4 09-Apr-2009  pooka Support creating a file system to a regular file.
 1.3 25-Feb-2009  joerg Make function bodies static, the prototype already is.
 1.2 28-Apr-2008  martin branches: 1.2.6;
Remove clause 3 and 4 from TNF licenses
 1.1 29-Dec-2005  tsutsui branches: 1.1.20; 1.1.22;
Add preliminary support for System V Boot File System.
Written by UCHIYAMA Yasushi <uch@netbsd>.
 1.1.22.1 18-May-2008  yamt sync with head.
 1.1.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.2.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.8.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10 03-Jun-2023  lukem adapt to ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

Simplify CWARNFLAGS to use ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}
which works for both clang and gcc, and remove compiler-specific
equivalents.
 1.9 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.8 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.7 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.6 11-Jan-2017  joerg Disable a couple of warnings until further investigation.
 1.5 18-Mar-2014  riastradh branches: 1.5.8;
Merge riastradh-drm2 to HEAD.
 1.4 18-Jul-2013  reinoud Initial split up for making newfs_udf(8) routines suitable for makefs_udf(8)
 1.3 11-Apr-2009  lukem branches: 1.3.6; 1.3.12; 1.3.16;
Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.2 14-Jan-2009  he branches: 1.2.2;
Ensure that all the files in SRCS are *.c files (there were some
files matching *.o (!) in the list). Thanks to cube@ for spotting
what I could not see. Should fix issue with UPDATE builds across
the recent time_t merge and associated shared lib major bumps.
 1.1 14-May-2008  reinoud branches: 1.1.2; 1.1.4; 1.1.6;
Import writing part of the UDF file system making optical media like CD's
and DVD's behave like floppy discs. Writing is supported upto and including
version 2.01; version 2.50 and 2.60 will follow.

Also extending the UDF implementation to support symbolic links and
hardlinks.

Added are the mmcformat(8) tool to format rewritable CD/DVD discs and
newfs_udf(8).

Limitations:
all operations can be performed on the file system though the
sheduling is currently optimised for archiving workloads.

mv(1)/rename(2) is currently only implemented for non-directories.
 1.1.6.2 17-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2. Pull in things that are new,
and pull in some things that were missed in the last sync.
 1.1.6.1 14-May-2008  wrstuden file Makefile was added on branch wrstuden-revivesa on 2008-09-17 04:43:59 +0000
 1.1.4.3 17-Jan-2009  mjf Sync with HEAD.
 1.1.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.1 14-May-2008  mjf file Makefile was added on branch mjf-devfs2 on 2008-06-02 13:21:23 +0000
 1.1.2.2 18-May-2008  yamt sync with head.
 1.1.2.1 14-May-2008  yamt file Makefile was added on branch yamt-pf42 on 2008-05-18 12:30:54 +0000
 1.2.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.3.16.1 23-Jul-2013  riastradh sync with HEAD
 1.3.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.18 06-Aug-2013  wiz Fix article.
 1.17 06-Aug-2013  wiz Sort sections. Remove superfluous Ed.
 1.16 06-Aug-2013  reinoud Clarify volumeset name restrictions when specifying it in newfs_udf(8)
 1.15 06-Aug-2013  reinoud Fix misplaced BUGS section and fix layout
 1.14 05-Aug-2013  wiz Sort.
 1.13 05-Aug-2013  reinoud Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.12 20-Jul-2013  wiz Use Mt for email addresses.
 1.11 02-Jul-2013  wiz branches: 1.11.2;
Sort sections. New sentence, new line. Fix macro.
 1.10 02-Jul-2013  reinoud Update newfs_udf to allow for creating file images with -F and specifying
sector sizes with -S.

For this i had to recycle the -S parameter but its preserved as an extension
to the -P parameter. These parameters are hardly ever use though since using
either or both the origional -S and the -P parameter without specific values
would break the standard. Also the -F now has a double meaning.
 1.9 29-Jun-2013  reinoud Small rewording of the examples section.
 1.8 28-Apr-2011  wiz branches: 1.8.4; 1.8.10;
Sort options and option descriptions. Fix a typo. New sentence, new line.
 1.7 23-Dec-2009  mbalmer Bump date.
 1.6 23-Dec-2009  mbalmer Fix typo in command output.
 1.5 18-Jan-2009  lukem Use KiB MiB GiB instead of Kb Mb Gb
 1.4 26-Jul-2008  reinoud branches: 1.4.2; 1.4.4;
Add UDF 2.50 metadata partition creation to newfs_udf(8). It allows a
percentage to the volume space to be pre-allocated for metadata on format.
Implementations that can't extent the metadata partitions can thus use the
discs too.

Note that the kernel UDF code can't write to UDF 2.50 metadata partitions
yet; this is a work-in-progress.

Also note that the default formatting version choice is still version 2.01
i.e. without the metadata partition.
 1.3 21-Jun-2008  wiz Sort options.
New sentence, new line.
Use more markup.
Drop trailing whitespace.
Bump date for previous.
 1.2 19-Jun-2008  reinoud Allow UDF versions to be both specified as a hex value and as a float
value. Its now possible to specify version 2.50 as "2.50" or "0x250".
 1.1 14-May-2008  reinoud branches: 1.1.2; 1.1.4;
Import writing part of the UDF file system making optical media like CD's
and DVD's behave like floppy discs. Writing is supported upto and including
version 2.01; version 2.50 and 2.60 will follow.

Also extending the UDF implementation to support symbolic links and
hardlinks.

Added are the mmcformat(8) tool to format rewritable CD/DVD discs and
newfs_udf(8).

Limitations:
all operations can be performed on the file system though the
sheduling is currently optimised for archiving workloads.

mv(1)/rename(2) is currently only implemented for non-directories.
 1.1.4.4 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.3 29-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.1 14-May-2008  mjf file newfs_udf.8 was added on branch mjf-devfs2 on 2008-06-02 13:21:23 +0000
 1.1.2.2 18-May-2008  yamt sync with head.
 1.1.2.1 14-May-2008  yamt file newfs_udf.8 was added on branch yamt-pf42 on 2008-05-18 12:30:54 +0000
 1.4.4.2 09-Jan-2010  snj Pull up following revision(s) (requested by mbalmer in ticket #1209):
dist/pdisk/pdisk.c: revision 1.18
distrib/amiga/floppies/upgr/upgrade.sh: revision 1.9
sbin/newfs_udf/newfs_udf.8: revision 1.6
sbin/newfs_udf/udf_create.c: revision 1.17
Fix typo in command output.
 1.4.4.1 18-Feb-2009  snj branches: 1.4.4.1.4;
Pull up following revision(s) (requested by reinoud in ticket #444):
sbin/newfs_udf/newfs_udf.8: revision 1.5
sbin/newfs_udf/newfs_udf.c: revision 1.7
sbin/newfs_udf/udf_create.c: revision 1.14
Use KiB MiB GiB instead of Kb Mb Gb
 1.4.4.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.4.2.2 17-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2. Pull in things that are new,
and pull in some things that were missed in the last sync.
 1.4.2.1 26-Jul-2008  wrstuden file newfs_udf.8 was added on branch wrstuden-revivesa on 2008-09-17 04:43:59 +0000
 1.8.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.2.1 23-Jul-2013  riastradh sync with HEAD
 1.24 09-Apr-2022  riastradh newfs_udf(8): Nix trailing whitespace.

No functional change intended.
 1.23 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.22 19-Sep-2021  andvar fix various typos in comments, messages and documentation.
 1.21 20-Aug-2021  andvar fix various typos in comments and log messages.
 1.20 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.19 09-Mar-2016  christos branches: 1.19.16;
PR/50920: David Binderman: fix leak
 1.18 09-Aug-2013  reinoud Fix possible 32 bit issues. In practice hard to reach but better be safe than
sorry.
 1.17 06-Aug-2013  reinoud Switch back program version to the version of the newfs_udf/makefs code.

While here, visit the 80 columns police :)
 1.16 06-Aug-2013  reinoud Oops, forgot to export a_udf_version() that checks if the input string is a
valid UDF version notation.
 1.15 05-Aug-2013  reinoud Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.14 18-Jul-2013  reinoud Initial split up for making newfs_udf(8) routines suitable for makefs_udf(8)
 1.13 02-Jul-2013  reinoud branches: 1.13.2;
Update newfs_udf to allow for creating file images with -F and specifying
sector sizes with -S.

For this i had to recycle the -S parameter but its preserved as an extension
to the -P parameter. These parameters are hardly ever use though since using
either or both the origional -S and the -P parameter without specific values
would break the standard. Also the -F now has a double meaning.
 1.12 26-May-2011  reinoud branches: 1.12.4; 1.12.10;
Fix accidental use of logical && instead of binary & in rare case.

Bug noticed by Joerg and clang :)
 1.11 21-Jan-2011  reinoud When requesting to disable metadata partitions, also disable low formatting.
When no meta and not low formatting we can lower the required UDF version.
 1.10 21-Jan-2011  reinoud Fix typo in comment
 1.9 04-Jan-2011  wiz branches: 1.9.2;
Fix memory leaks. Found by cppcheck.
 1.8 17-Sep-2009  reinoud Update TODO message; we can format with meta data partitions, only not yet for
BD-R, i.e. UDF 2.60.
 1.7 18-Jan-2009  lukem Use KiB MiB GiB instead of Kb Mb Gb
 1.6 18-Jan-2009  lukem * Fix -Wsign-compare issues.
* Add some XXXs noting where we might want to check for 16bit overflow.
* Use uintNN_t instead of int if the values is read from or written to
using udf_rwNN().
 1.5 05-Aug-2008  pooka branches: 1.5.2; 1.5.4;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.4 26-Jul-2008  reinoud Add UDF 2.50 metadata partition creation to newfs_udf(8). It allows a
percentage to the volume space to be pre-allocated for metadata on format.
Implementations that can't extent the metadata partitions can thus use the
discs too.

Note that the kernel UDF code can't write to UDF 2.50 metadata partitions
yet; this is a work-in-progress.

Also note that the default formatting version choice is still version 2.01
i.e. without the metadata partition.
 1.3 19-Jun-2008  reinoud Allow UDF versions to be both specified as a hex value and as a float
value. Its now possible to specify version 2.50 as "2.50" or "0x250".
 1.2 19-Jun-2008  reinoud If the written out descriptor contains a file descriptor or an extended
file descriptor, update the location of the extended attribute space if
present.
 1.1 14-May-2008  reinoud branches: 1.1.2; 1.1.4;
Import writing part of the UDF file system making optical media like CD's
and DVD's behave like floppy discs. Writing is supported upto and including
version 2.01; version 2.50 and 2.60 will follow.

Also extending the UDF implementation to support symbolic links and
hardlinks.

Added are the mmcformat(8) tool to format rewritable CD/DVD discs and
newfs_udf(8).

Limitations:
all operations can be performed on the file system though the
sheduling is currently optimised for archiving workloads.

mv(1)/rename(2) is currently only implemented for non-directories.
 1.1.4.4 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.3 29-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.1 14-May-2008  mjf file newfs_udf.c was added on branch mjf-devfs2 on 2008-06-02 13:21:23 +0000
 1.1.2.2 18-May-2008  yamt sync with head.
 1.1.2.1 14-May-2008  yamt file newfs_udf.c was added on branch yamt-pf42 on 2008-05-18 12:30:54 +0000
 1.5.4.2 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #444):
sbin/newfs_udf/newfs_udf.8: revision 1.5
sbin/newfs_udf/newfs_udf.c: revision 1.7
sbin/newfs_udf/udf_create.c: revision 1.14
Use KiB MiB GiB instead of Kb Mb Gb
 1.5.4.1 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #444):
sbin/newfs_udf/newfs_udf.c: revision 1.6
sbin/newfs_udf/udf_create.c: revision 1.13
sbin/newfs_udf/udf_create.h: revision 1.3
* Fix -Wsign-compare issues.
* Add some XXXs noting where we might want to check for 16bit overflow.
* Use uintNN_t instead of int if the values is read from or written to
using udf_rwNN().
 1.5.2.2 17-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2. Pull in things that are new,
and pull in some things that were missed in the last sync.
 1.5.2.1 05-Aug-2008  wrstuden file newfs_udf.c was added on branch wrstuden-revivesa on 2008-09-17 04:43:59 +0000
 1.9.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.12.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.2.1 23-Jul-2013  riastradh sync with HEAD
 1.19.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.9 09-Apr-2022  riastradh newfs_udf(8): Nix trailing whitespace.

No functional change intended.
 1.8 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.7 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.6 30-Jun-2019  sevan branches: 1.6.2;
Add rcsid
 1.5 09-Aug-2013  reinoud branches: 1.5.4; 1.5.8; 1.5.22; 1.5.30;
Fix possible 32 bit issues. In practice hard to reach but better be safe than
sorry.
 1.4 06-Aug-2013  reinoud Switch back program version to the version of the newfs_udf/makefs code.

While here, visit the 80 columns police :)
 1.3 05-Aug-2013  reinoud Fix newfs(8) to compile again.
 1.2 05-Aug-2013  joerg Allow building UDF parts of makefs on !NetBSD.
 1.1 18-Jul-2013  reinoud branches: 1.1.2;
Initial split up for making newfs_udf(8) routines suitable for makefs_udf(8)
 1.1.2.2 23-Jul-2013  riastradh sync with HEAD
 1.1.2.1 18-Jul-2013  riastradh file newfs_udf.h was added on branch riastradh-drm2 on 2013-07-23 21:07:31 +0000
 1.5.30.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.30.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5.22.1 07-May-2021  martin Pull up following revision(s) (requested by mrg in ticket #1678):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100
usr.sbin/installboot/Makefile: revisions 1.53,1.54 (patch)
usr.sbin/installboot/installboot.h: revision 1.41 (patch)
usr.sbin/installboot/machines.c: revisisons 1.41,1.42 (patch)

Avoid depending on common symbols.
 1.5.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.8.1 09-Aug-2013  tls file newfs_udf.h was added on branch tls-maxphys on 2014-08-20 00:02:27 +0000
 1.5.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.4.1 09-Aug-2013  yamt file newfs_udf.h was added on branch yamt-pagecache on 2014-05-22 11:37:31 +0000
 1.6.2.1 30-Apr-2021  martin Pull up following revision(s) (requested by mrg in ticket #1263):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100

Avoid depending on common symbols.
 1.14 05-Feb-2024  andvar fix various typos in comments.
 1.13 28-May-2022  andvar fix various typos in comments, mainly origional->original,
extened->extended, incomming->incoming.
 1.12 22-May-2022  andvar fix various small typos, mainly in comments.
 1.11 15-May-2022  andvar s/wich/which in comments.
 1.10 07-May-2022  reinoud Data is written out in fixed sized packets; discs are normally a multiple of
the packet size but they don't have to be so never write past the last sector.
 1.9 26-Apr-2022  reinoud Fix endian bug also in commented out code
 1.8 26-Apr-2022  reinoud Fix endian bug : Logblks recorded in fe/efe VAT is 64 bits
 1.7 26-Apr-2022  reinoud Fix endian bug in permission storage
 1.6 26-Apr-2022  reinoud Fix endian bug with VAT 1.50 format
 1.5 25-Apr-2022  reinoud Fix endian bug in logical volume creation for metadata/VAT partitions.
 1.4 22-Apr-2022  reinoud Fix endian issues with UDF extended attributes
 1.3 22-Apr-2022  reinoud Fix endian issues with fsck_udf/newfs_udf/makefs
 1.2 09-Apr-2022  riastradh newfs_udf(8): Nix trailing whitespace.

No functional change intended.
 1.1 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.3 07-Aug-2022  andvar fix various typos in comments, documentation and messages.
mainly s/paramater/parameter/ and s/reduntant/redundant/.
 1.2 09-Apr-2022  riastradh newfs_udf(8): Nix trailing whitespace.

No functional change intended.
 1.1 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.32 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.31 06-Feb-2022  andvar fix various typos in comments, log messages and documentation.
mainly s/aparently/apparently/ and s/implmented/implemented/.
 1.30 20-Aug-2021  andvar fix various typos in comments and log messages.
 1.29 13-Apr-2021  mrg more GCC 10 fixes.

mDNSResponder: another wrong return local address

dhcp: ignore a seemingly impossible stringop overflow

hpacel: avoid maybe uninitialised error that is wrong.

rsh: avoid impossible malloc(0)

udf: cast pointers through (uintptr_t) to fool invalid boundary checks
 1.28 14-May-2020  msaitoh Remove extra semicolon.
 1.27 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.26 09-Dec-2018  christos branches: 1.26.2;
Address of packed member might not be aligned.
 1.25 16-Jun-2015  christos branches: 1.25.8; 1.25.14; 1.25.16;
fix error messages containing \n
 1.24 19-Oct-2013  christos fix unused variable warnings.
 1.23 10-Aug-2013  tron Fix tool build under Mac OS X by using gettimeofday(2) instead of
clock_gettime(2). This needs a proper auto-config check.
 1.22 06-Aug-2013  reinoud Switch back program version to the version of the newfs_udf/makefs code.

While here, visit the 80 columns police :)
 1.21 06-Aug-2013  reinoud Oops, forgot to export a_udf_version() that checks if the input string is a
valid UDF version notation.
 1.20 05-Aug-2013  joerg Allow building UDF parts of makefs on !NetBSD.
 1.19 05-Aug-2013  reinoud Fix memset() arguments to use the right type for sizeof() and streamline its
use of sizeof() to allways use the right type.
 1.18 05-Aug-2013  reinoud Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.17 23-Dec-2009  mbalmer branches: 1.17.6; 1.17.12;
Fix typo in command output.
 1.16 19-May-2009  reinoud Fix newfs_udf to create a valid disc images on bigendian machines.
 1.15 15-Feb-2009  dholland fix typo: "aprox." -> "approx." (approximate).
 1.14 18-Jan-2009  lukem branches: 1.14.2;
Use KiB MiB GiB instead of Kb Mb Gb
 1.13 18-Jan-2009  lukem * Fix -Wsign-compare issues.
* Add some XXXs noting where we might want to check for 16bit overflow.
* Use uintNN_t instead of int if the values is read from or written to
using udf_rwNN().
 1.12 26-Jul-2008  reinoud branches: 1.12.2; 1.12.4;
Add UDF 2.50 metadata partition creation to newfs_udf(8). It allows a
percentage to the volume space to be pre-allocated for metadata on format.
Implementations that can't extent the metadata partitions can thus use the
discs too.

Note that the kernel UDF code can't write to UDF 2.50 metadata partitions
yet; this is a work-in-progress.

Also note that the default formatting version choice is still version 2.01
i.e. without the metadata partition.
 1.11 24-Jun-2008  reinoud Use the new macros defined in ecma167-udf.h and also calculate the extended
attribute header crc check; not just the tag sum.
 1.10 22-Jun-2008  reinoud Rename functionname to be more in sync with the kernel function naming.
 1.9 22-Jun-2008  reinoud Initialise l_ea though technically not nessisary since its space is claimed
by a calloc() its more clear to explicitly initialise it to prevent
accidents might the routine be later changed.
 1.8 21-Jun-2008  reinoud DO set the birthtime please....
 1.7 20-Jun-2008  reinoud Factor out extended attribute header creation. The VAT and extended time
descriptors are now added by this function.

Extended attribute for birthtime added to (non-extended) file descriptors.
 1.6 19-Jun-2008  reinoud Remove superfluous crc and checksum calculations when we are already post
processing it later on writeout.
 1.5 19-Jun-2008  reinoud Don't keep a running pointer but calculate directly the data offset to
prepare for factoring out.
 1.4 19-Jun-2008  reinoud Move extended attribute header creation from VAT to all (non-extended) file
descriptor creations.
 1.3 19-Jun-2008  reinoud Clarify hack to move LVID sequence forward if there are bad blocks there
since the automatic bad block skipping is not yet done.
 1.2 19-Jun-2008  reinoud Fix commentZ
 1.1 14-May-2008  reinoud branches: 1.1.2; 1.1.4;
Import writing part of the UDF file system making optical media like CD's
and DVD's behave like floppy discs. Writing is supported upto and including
version 2.01; version 2.50 and 2.60 will follow.

Also extending the UDF implementation to support symbolic links and
hardlinks.

Added are the mmcformat(8) tool to format rewritable CD/DVD discs and
newfs_udf(8).

Limitations:
all operations can be performed on the file system though the
sheduling is currently optimised for archiving workloads.

mv(1)/rename(2) is currently only implemented for non-directories.
 1.1.4.4 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.3 29-Jun-2008  mjf Sync with HEAD.
 1.1.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.1 14-May-2008  mjf file udf_create.c was added on branch mjf-devfs2 on 2008-06-02 13:21:23 +0000
 1.1.2.2 18-May-2008  yamt sync with head.
 1.1.2.1 14-May-2008  yamt file udf_create.c was added on branch yamt-pf42 on 2008-05-18 12:30:54 +0000
 1.12.4.4 09-Jan-2010  snj Pull up following revision(s) (requested by mbalmer in ticket #1209):
dist/pdisk/pdisk.c: revision 1.18
distrib/amiga/floppies/upgr/upgrade.sh: revision 1.9
sbin/newfs_udf/newfs_udf.8: revision 1.6
sbin/newfs_udf/udf_create.c: revision 1.17
Fix typo in command output.
 1.12.4.3 06-Jun-2009  bouyer Pull up following revision(s) (requested by reinoud in ticket #770):
sys/fs/udf/udf_subr.c: revision 1.88, 1.89
sys/fs/udf/udf_bswap.h: revision 1.6, 1.7
sys/fs/udf/udf_allocation.c: revision 1.22, 1.23
sbin/newfs_udf/udf_create.c: revision 1.16
Fix *serious* bug in bswapping definitions for big endian machines.
ANSI-fy. No idea why they weren't so in the first place.
Fix newfs_udf to create a valid disc images on bigendian machines.
A descriptor's CRC lenth is 16 bit so use udf_rw16() on tag.desc_crc_len.
Forgot to use the udf_rw16() on the descriptor crc lengths of FID's!
Also fix a few dubiously formatted checks.
On creation of a new node, don't forget to set the length of the allocated
space in the right endian!
Account for the logical blocks recorded by the extent in the right endian!
 1.12.4.2 18-Feb-2009  snj branches: 1.12.4.2.4;
Pull up following revision(s) (requested by reinoud in ticket #444):
sbin/newfs_udf/newfs_udf.8: revision 1.5
sbin/newfs_udf/newfs_udf.c: revision 1.7
sbin/newfs_udf/udf_create.c: revision 1.14
Use KiB MiB GiB instead of Kb Mb Gb
 1.12.4.1 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #444):
sbin/newfs_udf/newfs_udf.c: revision 1.6
sbin/newfs_udf/udf_create.c: revision 1.13
sbin/newfs_udf/udf_create.h: revision 1.3
* Fix -Wsign-compare issues.
* Add some XXXs noting where we might want to check for 16bit overflow.
* Use uintNN_t instead of int if the values is read from or written to
using udf_rwNN().
 1.12.4.2.4.1 21-Apr-2010  matt sync to netbsd-5
 1.12.2.2 17-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2. Pull in things that are new,
and pull in some things that were missed in the last sync.
 1.12.2.1 26-Jul-2008  wrstuden file udf_create.c was added on branch wrstuden-revivesa on 2008-09-17 04:43:59 +0000
 1.14.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.17.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.17.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.25.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.25.16.1 10-Jun-2019  christos Sync with HEAD
 1.25.14.1 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.25.8.1 07-May-2021  martin Pull up following revision(s) (requested by mrg in ticket #1678):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100
usr.sbin/installboot/Makefile: revisions 1.53,1.54 (patch)
usr.sbin/installboot/installboot.h: revision 1.41 (patch)
usr.sbin/installboot/machines.c: revisisons 1.41,1.42 (patch)

Avoid depending on common symbols.
 1.26.2.1 30-Apr-2021  martin Pull up following revision(s) (requested by mrg in ticket #1263):

bin/pax/options.c: revision 1.119
usr.bin/config/scan.l: revision 1.32
usr.bin/make/main.c: revision 1.274
bin/pax/extern.h: revision 1.60
usr.bin/config/defs.h: revision 1.106
usr.bin/make/make.h: revision 1.105
sbin/newfs_udf/udf_create.c: revision 1.27 (patch)
sbin/newfs_udf/newfs_udf.h: revision 1.7 (patch)
usr.bin/config/main.c: revision 1.100

Avoid depending on common symbols.
 1.8 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.7 09-Aug-2013  reinoud Fix possible 32 bit issues. In practice hard to reach but better be safe than
sorry.
 1.6 06-Aug-2013  reinoud Oops, forgot to export a_udf_version() that checks if the input string is a
valid UDF version notation.
 1.5 05-Aug-2013  joerg Allow building UDF parts of makefs on !NetBSD.
 1.4 05-Aug-2013  reinoud Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.3 18-Jan-2009  lukem branches: 1.3.8; 1.3.14;
* Fix -Wsign-compare issues.
* Add some XXXs noting where we might want to check for 16bit overflow.
* Use uintNN_t instead of int if the values is read from or written to
using udf_rwNN().
 1.2 26-Jul-2008  reinoud branches: 1.2.2; 1.2.4;
Add UDF 2.50 metadata partition creation to newfs_udf(8). It allows a
percentage to the volume space to be pre-allocated for metadata on format.
Implementations that can't extent the metadata partitions can thus use the
discs too.

Note that the kernel UDF code can't write to UDF 2.50 metadata partitions
yet; this is a work-in-progress.

Also note that the default formatting version choice is still version 2.01
i.e. without the metadata partition.
 1.1 14-May-2008  reinoud branches: 1.1.2; 1.1.4;
Import writing part of the UDF file system making optical media like CD's
and DVD's behave like floppy discs. Writing is supported upto and including
version 2.01; version 2.50 and 2.60 will follow.

Also extending the UDF implementation to support symbolic links and
hardlinks.

Added are the mmcformat(8) tool to format rewritable CD/DVD discs and
newfs_udf(8).

Limitations:
all operations can be performed on the file system though the
sheduling is currently optimised for archiving workloads.

mv(1)/rename(2) is currently only implemented for non-directories.
 1.1.4.3 28-Sep-2008  mjf Sync with HEAD.
 1.1.4.2 02-Jun-2008  mjf Sync with HEAD.
 1.1.4.1 14-May-2008  mjf file udf_create.h was added on branch mjf-devfs2 on 2008-06-02 13:21:23 +0000
 1.1.2.2 18-May-2008  yamt sync with head.
 1.1.2.1 14-May-2008  yamt file udf_create.h was added on branch yamt-pf42 on 2008-05-18 12:30:54 +0000
 1.2.4.1 18-Feb-2009  snj Pull up following revision(s) (requested by reinoud in ticket #444):
sbin/newfs_udf/newfs_udf.c: revision 1.6
sbin/newfs_udf/udf_create.c: revision 1.13
sbin/newfs_udf/udf_create.h: revision 1.3
* Fix -Wsign-compare issues.
* Add some XXXs noting where we might want to check for 16bit overflow.
* Use uintNN_t instead of int if the values is read from or written to
using udf_rwNN().
 1.2.2.2 17-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2. Pull in things that are new,
and pull in some things that were missed in the last sync.
 1.2.2.1 26-Jul-2008  wrstuden file udf_create.h was added on branch wrstuden-revivesa on 2008-09-17 04:43:59 +0000
 1.3.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.11 01-Sep-2021  andvar fix few typos in comments.
 1.10 22-Aug-2021  andvar s/priviledge/privilege/ in comments/log messages and fix one typo in descriptor.
 1.9 02-Jan-2015  reinoud Fix volumesetname to comply to UDF 2.01 [2.2.2.5]
 1.8 25-Aug-2013  reinoud branches: 1.8.4; 1.8.8;
Add the blockingnr determination for the -rom versions
 1.7 06-Aug-2013  reinoud Fix memory leaks found by Coverity and fix memoryleaks in the new code
 1.6 05-Aug-2013  reinoud Fix newfs(8) to compile again.
 1.5 05-Aug-2013  joerg Allow building UDF parts of makefs on !NetBSD.
 1.4 05-Aug-2013  reinoud Fix memset() arguments to use the right type for sizeof() and streamline its
use of sizeof() to allways use the right type.
 1.3 05-Aug-2013  reinoud Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.2 18-Jul-2013  reinoud branches: 1.2.2;
Add comment to udf_do_rootdir(). Might eventually be moved to newfs_udf(8)
 1.1 18-Jul-2013  reinoud Initial split up for making newfs_udf(8) routines suitable for makefs_udf(8)
 1.2.2.2 23-Jul-2013  riastradh sync with HEAD
 1.2.2.1 18-Jul-2013  riastradh file udf_write.c was added on branch riastradh-drm2 on 2013-07-23 21:07:31 +0000
 1.8.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.8.1 25-Aug-2013  tls file udf_write.c was added on branch tls-maxphys on 2014-08-20 00:02:27 +0000
 1.8.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.4.1 25-Aug-2013  yamt file udf_write.c was added on branch yamt-pagecache on 2014-05-22 11:37:31 +0000
 1.5 06-Apr-2022  reinoud Refactor and rewrite of newfs_udf(8) and makefs(8) (-t udf) with a shared
section for fsck_udf(8).

Newfs_udf and makefs support predefined disc image profiles, harddisc
partitions (disklabel and wedges on all generic block devices) and all optical
media types on CD/DVD/BD writers.

Newfs_udf and makefs now also support formatting of UDF 2.50 with a metadata
partition.
 1.4 05-Aug-2013  reinoud branches: 1.4.4; 1.4.8;
Fix newfs(8) to compile again.
 1.3 05-Aug-2013  joerg Allow building UDF parts of makefs on !NetBSD.
 1.2 05-Aug-2013  reinoud Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.1 18-Jul-2013  reinoud branches: 1.1.2;
Initial split up for making newfs_udf(8) routines suitable for makefs_udf(8)
 1.1.2.2 23-Jul-2013  riastradh sync with HEAD
 1.1.2.1 18-Jul-2013  riastradh file udf_write.h was added on branch riastradh-drm2 on 2013-07-23 21:07:31 +0000
 1.4.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.4.8.1 05-Aug-2013  tls file udf_write.h was added on branch tls-maxphys on 2014-08-20 00:02:27 +0000
 1.4.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.4.1 05-Aug-2013  yamt file udf_write.h was added on branch yamt-pagecache on 2014-05-22 11:37:31 +0000
 1.2 10-May-2023  rillig newfs_udf: fix wording in comment
 1.1 05-Aug-2013  reinoud branches: 1.1.4; 1.1.8;
Adjust newfs_udf to be sharing code with the new `makefs -t udf' to be
comitted.
 1.1.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.8.1 05-Aug-2013  tls file unicode.h was added on branch tls-maxphys on 2014-08-20 00:02:27 +0000
 1.1.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.4.1 05-Aug-2013  yamt file unicode.h was added on branch yamt-pagecache on 2014-05-22 11:37:31 +0000
 1.6 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.5 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.4 05-Sep-2012  riz Remove -g from CPPFLAGS.
 1.3 10-Aug-2012  joerg Don't depend on HAVE_GCC being always defined.
 1.2 01-Jul-2011  mrg branches: 1.2.2;
remove HAVE_GCC == 4 conditional
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.2.2.1 30-Oct-2012  yamt sync with head
 1.11 27-Feb-2022  zafer fix typo
 1.10 10-Aug-2011  uch newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.9 09-Aug-2011  uch Fix warning message.
 1.8 09-Aug-2011  uch Check whether superblock is writable sector.
 1.7 22-Jul-2011  uch Fixed the problem that partition size over 8GiB(v7fs filesystem limit) failed newfs.
 1.6 19-Jul-2011  tron Use howmany() macro as it is used in a lot fo places in this tool anyway
as suggested by Tsugutomo Enami.
 1.5 19-Jul-2011  joerg Allow cross-compiling from Linux
 1.4 18-Jul-2011  tron Don't use roundup2(9) (which should have been howmany(9) anyway) to
fix builds on platforms other than NetBSD.
 1.3 18-Jul-2011  apb In sources that get compiled into the tools version of makefs, add:

#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif

This should fix cross-build problems, but I can't really test
that now, so I am not re-enabling the inclusion of v7fs support
in makefs.
 1.2 10-Jul-2011  uch fix freeblock count bug.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.4 12-Sep-2016  sevan Document newfs_v7fs appeared in NetBSD 6.0.
Add AUTHORS secton.
Bump date.
 1.3 10-Aug-2011  uch newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.2 27-Jun-2011  wiz Various improvements.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.5 10-Jan-2017  christos need <sys/stat.h>
 1.4 16-Jun-2015  christos branches: 1.4.2;
fix error messages containing \n
 1.3 10-Aug-2011  wiz Sync usage with man page.
 1.2 10-Aug-2011  uch newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.4.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 10-Aug-2011  uch newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.1 27-Jun-2011  uch 7th Edition(V7) File System support. and NetBSD symbolic-link, socket, FIFO extension. see newfs_v7fs(8).
 1.6 24-Mar-1997  christos - Makefile cleanups
 1.5 18-Oct-1996  thorpej Use ${INSTALL}.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 22-Dec-1994  cgd specify man pages the new way.
 1.2 23-Sep-1994  mycroft Add RCS ids, and clean up Makefile.
 1.1 23-Sep-1994  mycroft branches: 1.1.1;
Initial revision
 1.1.1.1 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.10 12-Sep-2016  sevan Mention author in AUTHORS section.
Bump date.
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.8 18-Nov-2001  wiz Improve grammar. Noted by Stoned Elipot.
 1.7 16-Nov-2001  wiz Whitespace nits
 1.6 05-Jun-2001  wiz Drop arguments of .Os.
 1.5 27-Jul-1999  hubertf Replace the existing version of nologin(8) with a rewrite that was done
according to the behaviour documented in the manual page. That way, the
copyright notice can be dropped.

I place the rewritten version into the public domain. Fixes PR 5784.
 1.4 15-Sep-1997  lukem fix .Nm usage
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 23-Sep-1994  mycroft Add RCS ids, and clean up Makefile.
 1.1 23-Sep-1994  mycroft branches: 1.1.1;
Initial revision
 1.1.1.1 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.5 27-Jul-1999  hubertf Replace the existing version of nologin(8) with a rewrite that was done
according to the behaviour documented in the manual page. That way, the
copyright notice can be dropped.

I place the rewritten version into the public domain. Fixes PR 5784.
 1.4 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 23-Sep-1994  mycroft Add RCS ids, and clean up Makefile.
 1.1 23-Sep-1994  mycroft branches: 1.1.1;
Initial revision
 1.1.1.1 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.6 03-Jun-2023  lukem bsd.own.mk: rename to CC_WNO_ADDRESS_OF_PACKED_MEMBER

Provide a single variable
CC_WNO_ADDRESS_OF_PACKED_MEMBER
with options for both clang and gcc, to replace
CLANG_NO_ADDR_OF_PACKED_MEMBER
CC_NO_ADDR_OF_PACKED_MEMBER
GCC_NO_ADDR_OF_PACKED_MEMBER

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.5 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.4 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.3 29-Apr-2017  nonaka branches: 1.3.2; 1.3.8;
nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.2 13-Feb-2017  nonaka branches: 1.2.2;
128 bit integers are displayed in decimal.

bn.h and bignum.c from netgpg.
 1.1 04-Jun-2016  nonaka branches: 1.1.2; 1.1.4;
nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.1.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.2.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.3.8.1 22-Apr-2018  pgoyette Sync with HEAD
 1.3.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.6 27-Feb-2023  andvar fix some typos in comments.
 1.5 24-May-2022  andvar fix various typos in comments, docs and log messages.
 1.4 10-Nov-2021  msaitoh s/offseting/offsetting/ in comment.
 1.3 04-Oct-2019  mrg avoid access uninitialised memory, found by gcc8, patch by agc@.
 1.2 08-Feb-2018  dholland branches: 1.2.4;
Typos.
 1.1 13-Feb-2017  nonaka branches: 1.1.2; 1.1.4; 1.1.8;
128 bit integers are displayed in decimal.

bn.h and bignum.c from netgpg.
 1.1.8.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.1.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.4.1 13-Feb-2017  bouyer file bignum.c was added on branch bouyer-socketcan on 2017-04-21 16:53:14 +0000
 1.1.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.1 13-Feb-2017  pgoyette file bignum.c was added on branch pgoyette-localcount on 2017-03-20 06:57:02 +0000
 1.2.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 13-Feb-2017  nonaka branches: 1.1.2; 1.1.4;
128 bit integers are displayed in decimal.

bn.h and bignum.c from netgpg.
 1.1.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.4.1 13-Feb-2017  bouyer file bn.h was added on branch bouyer-socketcan on 2017-04-21 16:53:14 +0000
 1.1.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.1 13-Feb-2017  pgoyette file bn.h was added on branch pgoyette-localcount on 2017-03-20 06:57:02 +0000
 1.6 05-Mar-2023  simonb In "devlist" mode, exit with a 0 return code if any nvme devices are
found, rather than exiting with 1 return code always.
 1.5 18-Apr-2018  nonaka branches: 1.5.12;
nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.4 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.3 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.2 04-Jun-2016  joerg branches: 1.2.8; 1.2.14;
Mark dead functions.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.14.2 22-Apr-2018  pgoyette Sync with HEAD
 1.2.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.2.8.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.5.12.1 25-Apr-2023  martin Pull up following revision(s) (requested by simonb in ticket #145):

sbin/nvmectl/devlist.c: revision 1.6

In "devlist" mode, exit with a 0 return code if any nvme devices are
found, rather than exiting with 1 return code always.
 1.6 05-Jul-2023  riastradh Revert "nvmectl(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.5 04-Jul-2023  riastradh nvmectl(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.4 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.3 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.2 29-Apr-2017  nonaka branches: 1.2.2; 1.2.8;
nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.1 04-Jun-2016  nonaka branches: 1.1.6;
nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.1.6.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.2.8.1 22-Apr-2018  pgoyette Sync with HEAD
 1.2.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.1 13-Feb-2017  nonaka branches: 1.1.2; 1.1.4;
128 bit integers are displayed in decimal.

bn.h and bignum.c from netgpg.
 1.1.4.2 21-Apr-2017  bouyer Sync with HEAD
 1.1.4.1 13-Feb-2017  bouyer file humanize_bignum.c was added on branch bouyer-socketcan on 2017-04-21 16:53:14 +0000
 1.1.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.2.1 13-Feb-2017  pgoyette file humanize_bignum.c was added on branch pgoyette-localcount on 2017-03-20 06:57:02 +0000
 1.9 17-Feb-2022  andvar remove one whitespace to align report, misalignment occured after typo fix.
 1.8 16-Feb-2022  andvar fix various typos, mainly in comments.
 1.7 27-Sep-2020  jdolecek show APSTA support status in identify
 1.6 01-Dec-2018  jdolecek since NVMe 1.2 (which defined the ONCS bit), the bit (4) is whether controller
supports 'Save' field in Set Features, and 'Select' field for Get Features,
not the support for the 'Set Features' command itself
 1.5 18-Apr-2018  nonaka branches: 1.5.2;
nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.4 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.3 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.2 04-Jun-2016  joerg branches: 1.2.8; 1.2.14;
Mark dead functions.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.14.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.2.14.2 22-Apr-2018  pgoyette Sync with HEAD
 1.2.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.2.8.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.5.2.1 10-Jun-2019  christos Sync with HEAD
 1.11 02-Feb-2023  mlelstv Data units read/written are counted in 1000s of 512 bytes.
Convert to human-readable value.
 1.10 31-Jul-2022  mlelstv branches: 1.10.2;
Fix build on 32bit.
 1.9 31-Jul-2022  mlelstv Report error code (SCT/SC).
 1.8 12-Feb-2022  andvar s/Expceted/Expected/ in log message and s/attribtues/attributes/ in comment.
 1.7 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.6 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.5 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.4 29-Apr-2017  nonaka branches: 1.4.2; 1.4.8;
nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.3 13-Feb-2017  nonaka branches: 1.3.2;
128 bit integers are displayed in decimal.

bn.h and bignum.c from netgpg.
 1.2 04-Jun-2016  joerg branches: 1.2.2; 1.2.4;
Mark dead functions.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3.2.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.4.8.2 22-Apr-2018  pgoyette Sync with HEAD
 1.4.8.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.4.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.10.2.1 05-Mar-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #112):

sbin/nvmectl/nvmectl.h: revision 1.10
sbin/nvmectl/logpage.c: revision 1.11
sbin/nvmectl/util.c: revision 1.3

Data units read/written are counted in 1000s of 512 bytes.

Convert to human-readable value.
 1.3 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.2 29-Apr-2017  nonaka branches: 1.2.2; 1.2.8;
nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.1 04-Jun-2016  nonaka branches: 1.1.6;
nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.1.6.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.2.8.1 22-Apr-2018  pgoyette Sync with HEAD
 1.2.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.6 27-Sep-2020  jdolecek add -s option for 'power' command, this instructs the controller to save
the value so it persists resets/whatnot; the NVMe specification lists
this as optional, so this only works if the controller supports it
 1.5 18-Apr-2018  nonaka nvmectl(8): Remove some wdc subcommands from man page.

- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor
 1.4 30-Apr-2017  wiz branches: 1.4.2; 1.4.8;
Remove unnecessary Pp. Add missing plural-s. More markup.
 1.3 29-Apr-2017  nonaka nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.2 05-Jun-2016  wiz branches: 1.2.6;
Try improving SYNOPSIS per my understanding of how this works.
Use more markup. Fix some markup.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.6.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.4.8.1 22-Apr-2018  pgoyette Sync with HEAD
 1.4.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.7 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.6 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.5 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.4 03-May-2017  christos branches: 1.4.2; 1.4.8;
sprinkle static and death
 1.3 29-Apr-2017  nonaka nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.2 04-Jun-2016  joerg branches: 1.2.6;
Mark dead functions.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.6.2 11-May-2017  pgoyette Sync with HEAD
 1.2.6.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.4.8.2 22-Apr-2018  pgoyette Sync with HEAD
 1.4.8.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.4.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.10 02-Feb-2023  mlelstv Data units read/written are counted in 1000s of 512 bytes.
Convert to human-readable value.
 1.9 27-Sep-2020  jdolecek branches: 1.9.6;
add -s option for 'power' command, this instructs the controller to save
the value so it persists resets/whatnot; the NVMe specification lists
this as optional, so this only works if the controller supports it
 1.8 18-Apr-2018  nonaka nvmectl(8): fix subcommand usage.
 1.7 17-Apr-2018  nonaka nvmectl(8): fix wdc command usage.
 1.6 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.5 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.4 03-May-2017  christos branches: 1.4.2; 1.4.8;
sprinkle static and death
 1.3 29-Apr-2017  nonaka nvmectl(8): sync with FreeBSD HEAD r316105.

- Expand the SMART / Health Information Log Page (Page 02) printout based on
NVM Express 1.2.1 Standard.
- Implement Intel-specific log pages.
- Implement HGST-specific log pages.
- Implement wdc-specific nvme control options.
- Add the ability to dump log pages directly in binary to stdout.
 1.2 04-Jun-2016  joerg branches: 1.2.6;
Mark dead functions.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.6.2 11-May-2017  pgoyette Sync with HEAD
 1.2.6.1 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.4.8.2 22-Apr-2018  pgoyette Sync with HEAD
 1.4.8.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.4.2.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.9.6.1 05-Mar-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #112):

sbin/nvmectl/nvmectl.h: revision 1.10
sbin/nvmectl/logpage.c: revision 1.11
sbin/nvmectl/util.c: revision 1.3

Data units read/written are counted in 1000s of 512 bytes.

Convert to human-readable value.
 1.5 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.4 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.3 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.2 14-Jul-2016  nonaka branches: 1.2.8; 1.2.14;
Fix RCS Id.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.14.2 22-Apr-2018  pgoyette Sync with HEAD
 1.2.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.2.8.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.6 27-Sep-2020  jdolecek add -s option for 'power' command, this instructs the controller to save
the value so it persists resets/whatnot; the NVMe specification lists
this as optional, so this only works if the controller supports it
 1.5 27-Sep-2020  jdolecek print current power state and workload as separate values for
'nvmectl power nvme0'
 1.4 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.3 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.2 04-Jun-2016  joerg branches: 1.2.8; 1.2.14;
Mark dead functions.
 1.1 04-Jun-2016  nonaka nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.2.14.2 22-Apr-2018  pgoyette Sync with HEAD
 1.2.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.2.8.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.3 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.2 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.1 04-Jun-2016  nonaka branches: 1.1.8; 1.1.14;
nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).
 1.1.14.2 22-Apr-2018  pgoyette Sync with HEAD
 1.1.14.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.1.8.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.3 02-Feb-2023  mlelstv Data units read/written are counted in 1000s of 512 bytes.
Convert to human-readable value.
 1.2 18-Apr-2018  nonaka branches: 1.2.2; 1.2.4; 1.2.16;
nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.1 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.2.16.1 05-Mar-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #112):

sbin/nvmectl/nvmectl.h: revision 1.10
sbin/nvmectl/logpage.c: revision 1.11
sbin/nvmectl/util.c: revision 1.3

Data units read/written are counted in 1000s of 512 bytes.

Convert to human-readable value.
 1.2.4.2 22-Apr-2018  pgoyette Sync with HEAD
 1.2.4.1 18-Apr-2018  pgoyette file util.c was added on branch pgoyette-compat on 2018-04-22 07:20:16 +0000
 1.2.2.2 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.2.2.1 18-Apr-2018  martin file util.c was added on branch netbsd-8 on 2018-04-19 15:37:56 +0000
 1.6 05-Jul-2023  riastradh Revert "nvmectl(8): Ensure A divides S before aligned_alloc(A, S)."

C17 lifted this restriction.
 1.5 04-Jul-2023  riastradh nvmectl(8): Ensure A divides S before aligned_alloc(A, S).

Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:

The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.

XXX pullup-10
 1.4 18-Apr-2018  nonaka nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.
 1.3 17-Apr-2018  nonaka nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.
 1.2 17-Mar-2018  jdolecek use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.1 29-Apr-2017  nonaka branches: 1.1.2; 1.1.4; 1.1.10;
Added missing file...

> nvmectl(8): sync with FreeBSD HEAD r316105.
>
> - Expand the SMART / Health Information Log Page (Page 02) printout based on
> NVM Express 1.2.1 Standard.
> - Implement Intel-specific log pages.
> - Implement HGST-specific log pages.
> - Implement wdc-specific nvme control options.
> - Add the ability to dump log pages directly in binary to stdout.
 1.1.10.2 22-Apr-2018  pgoyette Sync with HEAD
 1.1.10.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.1.4.1 19-Apr-2018  martin Pull up following revision(s) (requested by nonaka in ticket #781):

sbin/nvmectl/Makefile 1.4
sbin/nvmectl/bignum.c 1.2
sbin/nvmectl/devlist.c 1.3-1.5
sbin/nvmectl/firmware.c 1.3,1.4
sbin/nvmectl/identify.c 1.3-1.5
sbin/nvmectl/logpage.c 1.5-1.7
sbin/nvmectl/nvme.h 1.3
sbin/nvmectl/nvmectl.8 1.5
sbin/nvmectl/nvmectl.c 1.5-1.7
sbin/nvmectl/nvmectl.h 1.5-1.8
sbin/nvmectl/perftest.c 1.3-1.5
sbin/nvmectl/power.c 1.3,1.4
sbin/nvmectl/reset.c 1.2,1.3
sbin/nvmectl/util.c 1.1,1.2
sbin/nvmectl/wdc.c 1.2-1.4
sys/dev/ic/ld_nvme.c 1.20
sys/dev/ic/nvme.c 1.38,1.39
sys/dev/ic/nvmeio.h 1.2
sys/dev/ic/nvmereg.h 1.10,1.11
sys/dev/ic/nvmevar.h 1.16
sys/dev/pci/nvme_pci.c 1.20

nvmectl(8): Sync with FreeBSD nvmecontrol(8) r328763.

nvmectl(8): fix wdc command usage.

nvme(4): Added some delay before check RDY bit quirk when disabling device.
Pick from FreeBSD nvme(4) r326937.

Add some new structure fileds, opcodes and statuses from NVMe 1.3a.

nvmectl(8): Add big-endian support.
from FreeBSD nvmecontolr(8) r329824.

nvmectl(8): fix subcommand usage.

nvmectl(8): Remove some wdc subcommands from man page.
- wdc drive-log
- wdc get-crash-dump
- wdc purge
- wdc purge-monitor

Typos.

use setprogname()/getprogname(), do not hardcode the prognam name in fixed
strings
 1.1.2.2 02-May-2017  pgoyette Sync with HEAD - tag prg-localcount2-base1
 1.1.2.1 29-Apr-2017  pgoyette file wdc.c was added on branch prg-localcount2 on 2017-05-02 03:19:16 +0000
 1.18 07-Oct-2023  rin Drop -O[01] hacks for vax; no longer necessary for patched GCC 10

PR port-vax/57646: Import major vax toolchain fix by Kalvis Duckmanton

XXXRO: GCC 12 may require hacks for a while, but it turned out that
GCC 12 should be treated differently from older versions; a lot of new
files need -O[01] flags, while some may no longer require it.

I will take a look later.

Note that these hacks are not required if Kalvis's patches for GCC 12
are applied.

Keep doc/HACKS entries for a while (will be sync with update for GCC 12).

diff --git a/crypto/external/bsd/openssh/lib/Makefile b/crypto/external/bsd/openssh/lib/Makefile
index 96a93f5e396..4e38be1b642 100644
--- a/crypto/external/bsd/openssh/lib/Makefile
+++ b/crypto/external/bsd/openssh/lib/Makefile
@@ -117,12 +117,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
# XXX
COPTS.channels.c+= -fno-strict-aliasing

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.poly1305.c+= -O0
-COPTS.umac.c+= -O0
-.endif
-
COPTS.hostfile.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.sshkey.c+= ${CC_WNO_FORMAT_TRUNCATION}
COPTS.cipher.c+= -Wno-error=deprecated-declarations
diff --git a/distrib/utils/x_ping/Makefile b/distrib/utils/x_ping/Makefile
index f1c452a0d60..8ee77580a3f 100644
--- a/distrib/utils/x_ping/Makefile
+++ b/distrib/utils/x_ping/Makefile
@@ -12,10 +12,6 @@ CPPFLAGS+= -I${SRCDIR} -DCRUNCHOPS
DPADD= ${LIBM}
LDADD= -lm

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>

.PATH: ${SRCDIR}
diff --git a/external/apache2/argon2/lib/libargon2/Makefile.inc b/external/apache2/argon2/lib/libargon2/Makefile.inc
index d3f4470c6c7..6a1dd146d7d 100644
--- a/external/apache2/argon2/lib/libargon2/Makefile.inc
+++ b/external/apache2/argon2/lib/libargon2/Makefile.inc
@@ -16,7 +16,3 @@ CFLAGS+= -pthread
LDADD+=-lpthread
DPADD+=${LIBPTHREAD}
.endif
-
-.if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-.endif
diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc
index 2f524358f46..d5da774f293 100644
--- a/external/bsd/jemalloc/lib/Makefile.inc
+++ b/external/bsd/jemalloc/lib/Makefile.inc
@@ -53,12 +53,6 @@ COPTS.ctl.c+=-Wno-error=stack-protector
COPTS.stats.c+=-Wno-error=stack-protector
COPTS.tcache.c+=-Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-# in merge_overlapping_regs, at regrename.c
-COPTS.arena.c+=-O0
-COPTS.extent.c+=-O0
-.endif
-
SRCS+=${JEMALLOC_SRCS}

jemalloc.d jemalloc.pico jemalloc.o jemalloc.ln jemalloc.po jemalloc.go: \
diff --git a/external/bsd/mdocml/lib/libmandoc/Makefile b/external/bsd/mdocml/lib/libmandoc/Makefile
index 40d7e29ae88..dfd3077a2c7 100644
--- a/external/bsd/mdocml/lib/libmandoc/Makefile
+++ b/external/bsd/mdocml/lib/libmandoc/Makefile
@@ -39,11 +39,6 @@ tbl_opts.c

MAN= mandoc.3

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.mdoc_macro.c+=-O0
-.endif
-
COPTS.man_validate.c+=-Wno-error=array-bounds

.include <bsd.lib.mk>
diff --git a/external/gpl3/binutils.old/lib/libbfd/Makefile b/external/gpl3/binutils.old/lib/libbfd/Makefile
index 03477232b55..74a354532fa 100644
--- a/external/gpl3/binutils.old/lib/libbfd/Makefile
+++ b/external/gpl3/binutils.old/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/binutils/lib/libbfd/Makefile b/external/gpl3/binutils/lib/libbfd/Makefile
index 00cb2b20081..a3f0c25fd35 100644
--- a/external/gpl3/binutils/lib/libbfd/Makefile
+++ b/external/gpl3/binutils/lib/libbfd/Makefile
@@ -41,10 +41,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${BFD_MACHINE_ARCH} -I${DIST}/include -I. \
-DDEBUGDIR=\"${DEBUGDIR}\" -DLIBDIR=\"${LIBDIR}\" \
-DBINDIR=\"${BINDIR}\"

-.if (${BFD_MACHINE_ARCH} == "vax")
-CPPFLAGS.elf.c += -O0
-.endif
-
COPTS.pei-x86_64.c+= -Wno-stack-protector
COPTS.elfxx-mips.c+= -Wno-stack-protector
COPTS.elf.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-overflow :}
diff --git a/external/gpl3/gcc.old/lib/Makefile.sanitizer b/external/gpl3/gcc.old/lib/Makefile.sanitizer
index efd36ae4bee..5173a5109a0 100644
--- a/external/gpl3/gcc.old/lib/Makefile.sanitizer
+++ b/external/gpl3/gcc.old/lib/Makefile.sanitizer
@@ -88,22 +88,3 @@ COPTS+=-fno-builtin -fno-exceptions -fno-rtti -funwind-tables

# Can't profile without it`
#-fomit-frame-pointer
-
-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_allocator.cc += -O1
-COPTS.sanitizer_common.cc += -O1
-COPTS.sanitizer_common_libcdep.cc += -O1
-COPTS.sanitizer_coverage_libcdep.cc += -O1
-COPTS.sanitizer_coverage_mapping_libcdep.cc += -O1
-COPTS.sanitizer_deadlock_detector1.cc += -O1
-COPTS.sanitizer_mac.cc += -O1
-COPTS.sanitizer_netbsd.cc += -O1
-COPTS.sanitizer_posix.cc += -O1
-COPTS.sanitizer_printf.cc += -O1
-COPTS.sanitizer_procmaps_common.cc += -O1
-COPTS.sanitizer_stackdepot.cc += -O1
-COPTS.sanitizer_symbolizer_libcdep.cc += -O1
-COPTS.sanitizer_symbolizer_report.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
diff --git a/external/gpl3/gcc.old/lib/libasan/Makefile b/external/gpl3/gcc.old/lib/libasan/Makefile
index 1e6f9608abe..3da7bbf2f58 100644
--- a/external/gpl3/gcc.old/lib/libasan/Makefile
+++ b/external/gpl3/gcc.old/lib/libasan/Makefile
@@ -49,14 +49,6 @@ LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
LIBDPLIBS+= pthread ${NETBSDSRCDIR}/lib/libpthread
CPPFLAGS+=-DCAN_SANITIZE_UB=0

-.if ${MACHINE_ARCH} == "vax"
-COPTS.asan_allocator.cc += -O1
-COPTS.asan_report.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-COPTS.ubsan_diag.cc += -O1
-COPTS.ubsan_init.cc += -O1
-.endif
-
.if ${MACHINE_ARCH} == "mipsel" || ${MACHINE_ARCH} == "mipseb"
COPTS.asan_interceptors.cc += -O1
.endif
diff --git a/external/gpl3/gcc.old/lib/liblsan/Makefile b/external/gpl3/gcc.old/lib/liblsan/Makefile
index 4578544a9a8..ddb7981077c 100644
--- a/external/gpl3/gcc.old/lib/liblsan/Makefile
+++ b/external/gpl3/gcc.old/lib/liblsan/Makefile
@@ -16,11 +16,6 @@ LSAN_SRCS+= \
lsan_linux.cc \
lsan_thread.cc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lsan_allocator.cc += -O1
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= lsan
SRCS+= ${LSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/lib/libubsan/Makefile b/external/gpl3/gcc.old/lib/libubsan/Makefile
index 2e2faca7b1c..9de82550d14 100644
--- a/external/gpl3/gcc.old/lib/libubsan/Makefile
+++ b/external/gpl3/gcc.old/lib/libubsan/Makefile
@@ -26,10 +26,6 @@ UBSAN_SRCS= \
COPTS.${_s}.cc+=-frtti
.endfor

-.if ${MACHINE_ARCH} == "vax"
-COPTS.sanitizer_file.cc += -O1
-.endif
-
LIB= ubsan
SRCS+= ${UBSAN_SRCS}
LIBDPLIBS+= m ${NETBSDSRCDIR}/lib/libm
diff --git a/external/gpl3/gcc.old/usr.bin/cc1/Makefile b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
index c55e292ee8e..ff12a5be524 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1/Makefile
@@ -46,17 +46,6 @@ CPPFLAGS.default-c.c+= -I${BACKENDOBJ}
BUILDSYMLINKS+= ${GNUHOSTDIST}/gcc/config/sh/sh-c.cc sh-c.c
.endif

-.if ${MACHINE_CPU} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
index 3123ee0d60b..aab82ad3448 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1obj/Makefile
@@ -44,16 +44,8 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-.endif
+COPTS.c-cppbuiltin.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}
+COPTS.c-typeck.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} == 8:? -Wno-error=format-overflow :}

.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
diff --git a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
index b9c108251c5..e04e8fc7f53 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile
@@ -69,18 +69,6 @@ COPTS.objc-act.c+= -Wno-stack-protector
COPTS.objc-gnu-runtime-abi-01.c+= -Wno-stack-protector
COPTS.objc-next-runtime-abi-01.c+= -Wno-stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.c-decl.c+=-O0
-COPTS.c-typeck.c+=-O0
-COPTS.c-array-notation.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1obj-checksum.c+=-O0
-COPTS.decl.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
index 7936efd3a5e..7c54559e21a 100644
--- a/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/cc1plus/Makefile
@@ -31,23 +31,6 @@ CHECKSUM_OBJS= ${LIBBACKTRACEOBJ}/libbacktrace.a \

CFLAGS+= -Wno-error=stack-protector

-.if ${MACHINE_ARCH} == "vax"
-COPTS.call.c+=-O0
-COPTS.decl.c+=-O0
-COPTS.typeck2.c+=-O0
-COPTS.class.c+=-O0
-COPTS.typeck.c+=-O0
-COPTS.init.c+=-O0
-COPTS.semantics.c+=-O0
-COPTS.mangle.c+=-O0
-COPTS.constexpr.c+=-O0
-COPTS.c-common.c+=-O0
-COPTS.c-ada-spec.c+=-O0
-COPTS.cilk.c+=-O0
-COPTS.c-ubsan.c+=-O0
-COPTS.cc1plus-checksum.c+=-O0
-.endif
-
.if ${MACHINE_ARCH} == "mipseb" || ${MACHINE_ARCH} == "mipsel"
COPTS.c-common.c+=-O3
.endif
diff --git a/external/gpl3/gcc.old/usr.bin/gcc/Makefile b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
index 7a66d77ffc7..a5a4b1c3adf 100644
--- a/external/gpl3/gcc.old/usr.bin/gcc/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/gcc/Makefile
@@ -25,9 +25,6 @@ ${SRCS}: ${GCCARCH}/defs.mk
.include <bsd.info.mk>

COPTS.gcc.c= -Wno-stack-protector
-.if ${MACHINE_ARCH} == "vax"
-COPTS.dse.c= -O1
-.endif

.PATH: ${DIST}/gcc ${DIST}/gcc/doc ${DIST}/gcc/c

diff --git a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
index 751d1513eec..33aeb1c9898 100644
--- a/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile
@@ -14,10 +14,6 @@ SRCS= decNumber.c decContext.c decimal32.c decimal64.c decimal128.c
CPPFLAGS+= -I${.CURDIR}/arch/${GCC_MACHINE_ARCH} -I${DIST}/libdecnumber
CPPFLAGS+= -I${DIST}/libgcc

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.include <bsd.lib.mk>

# Force using C++ for this
diff --git a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
index 90f44a9fcf6..fd251464fb7 100644
--- a/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto-dump/Makefile
@@ -24,11 +24,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.backtrace"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
DPADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} ${LIBINTL} ${LIBZ} ${LIBM}

diff --git a/external/gpl3/gcc.old/usr.bin/lto1/Makefile b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
index 4c49161a64c..340d3c6124f 100644
--- a/external/gpl3/gcc.old/usr.bin/lto1/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/lto1/Makefile
@@ -21,11 +21,6 @@ COPTS.lto-common.c+= -Wno-stack-protector
.include "../Makefile.libcpp"
.include "../Makefile.libdecnumber"

-.if ${MACHINE_ARCH} == "vax"
-COPTS.lto-lang.c+=-O0
-COPTS.lto-symtab.c+=-O0
-.endif
-
LDADD+= ${LIBIBERTYOBJ}/libiberty.a
DPADD+= ${LIBIBERTYOBJ}/libiberty.a
LDADD+= ${LIBIBERTY} ${LIBMPC} ${LIBMPFR} ${LIBGMP} -lintl -lz -lm
diff --git a/external/gpl3/gdb.old/lib/libdecnumber/Makefile b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
index bcd4ae5b222..ce28811526b 100644
--- a/external/gpl3/gdb.old/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb.old/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libdecnumber/Makefile b/external/gpl3/gdb/lib/libdecnumber/Makefile
index c95d36e3dfa..e3169865304 100644
--- a/external/gpl3/gdb/lib/libdecnumber/Makefile
+++ b/external/gpl3/gdb/lib/libdecnumber/Makefile
@@ -18,10 +18,6 @@ CPPFLAGS+= -I${.CURDIR}/arch/${GDB_MACHINE_ARCH} \

SRCS= ${G_OBJS:.o=.c} ${G_SOURCES}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.decNumber.c=-O0
-.endif
-
.PATH: ${DIST}/libdecnumber ${DIST}/libdecnumber/dpd ${DIST}/libdecnumber/bid

.include <bsd.lib.mk>
diff --git a/external/gpl3/gdb/lib/libgdb/Makefile b/external/gpl3/gdb/lib/libgdb/Makefile
index b87a515d13a..c118c363975 100644
--- a/external/gpl3/gdb/lib/libgdb/Makefile
+++ b/external/gpl3/gdb/lib/libgdb/Makefile
@@ -66,12 +66,6 @@ CFLAGS:= ${CXXFLAGS} -std=gnu++17 -Wno-error=stack-protector

ada-exp.c: ada-lex.c

-.if ${MACHINE} == "vax"
-. if ${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 8
-COPTS.read.c+= -O0
-. endif
-.endif
-
# These are generated by implicit rules and are not easy to generate
CLEANDIRFILES+= \
ada-exp.c ada-lex.c \
diff --git a/external/mit/xorg/lib/gallium.old/Makefile b/external/mit/xorg/lib/gallium.old/Makefile
index 55b2fe3d1c1..bfa40c8974f 100644
--- a/external/mit/xorg/lib/gallium.old/Makefile
+++ b/external/mit/xorg/lib/gallium.old/Makefile
@@ -1211,10 +1211,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
# XXXGCC12
.if ${MACHINE_ARCH} == "m68k"
COPTS.st_glsl_to_tgsi.cpp += -O1
diff --git a/external/mit/xorg/lib/gallium/Makefile b/external/mit/xorg/lib/gallium/Makefile
index 6778a8c11c8..9f1422080fe 100644
--- a/external/mit/xorg/lib/gallium/Makefile
+++ b/external/mit/xorg/lib/gallium/Makefile
@@ -1428,10 +1428,6 @@ SYMLINKS+= gallium_dri.so.${SHLIB_MAJOR}.debug ${DRIDEBUGDIR}/${_d}_dri.so.${SHL
COPTS+= ${${ACTIVE_CC} == "clang":? -Wa,-Av8plus :}
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.nir.c += -O1
-.endif
-
COPTS.u_atomic.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 10:? -Wno-builtin-declaration-mismatch :}

.include <bsd.lib.mk>
diff --git a/external/mit/xorg/lib/libX11/Makefile.libx11 b/external/mit/xorg/lib/libX11/Makefile.libx11
index e103d9ace12..0e55c2a4732 100644
--- a/external/mit/xorg/lib/libX11/Makefile.libx11
+++ b/external/mit/xorg/lib/libX11/Makefile.libx11
@@ -471,11 +471,6 @@ COPTS.OpenDis.c+= -Wno-error # XXX xf86bigfstr.h
COPTS.XlibInt.c+= -Wno-error # XXX xcmiscstr.h
COPTS.XKBBind.c+= -Wno-deprecated-declarations # uses XKeycodeToKeysym

-# XXX
-.if ${MACHINE} == "vax"
-COPTS.lcWrap.c+= -O0
-.endif
-
CWARNFLAGS.clang+= -Wno-string-plus-int

.include "${NETBSDSRCDIR}/external/mit/xorg/tools/makekeys/Makefile.makekeys"
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile
index e86a63aaea7..678537066ed 100644
--- a/games/gomoku/Makefile
+++ b/games/gomoku/Makefile
@@ -9,10 +9,6 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}

-.if ${MACHINE} == "vax"
-COPTS.pickmove.c += -O0
-.endif
-
#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile
index e9c53f23ae5..b919dac17c6 100644
--- a/games/phantasia/Makefile
+++ b/games/phantasia/Makefile
@@ -52,7 +52,3 @@ map: map.c
./map | plot > /dev/tty

.include <bsd.prog.mk>
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/i18n_module/UTF7/Makefile b/lib/i18n_module/UTF7/Makefile
index 712c1515d42..7136f7f0cc3 100644
--- a/lib/i18n_module/UTF7/Makefile
+++ b/lib/i18n_module/UTF7/Makefile
@@ -3,6 +3,3 @@
SRCPRE=citrus_
.include <bsd.lib.mk>

-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.citrus_utf7.c+= -O0
-.endif
diff --git a/lib/libbz2/Makefile b/lib/libbz2/Makefile
index b2aea1e04b0..e60a2862d48 100644
--- a/lib/libbz2/Makefile
+++ b/lib/libbz2/Makefile
@@ -15,11 +15,6 @@ SRCS= blocksort.c huffman.c crctable.c randtable.c compress.c \
INCS= bzlib.h
INCSDIR= /usr/include

-# XXX huffman.c gets mis-compiled with 2.95.3
-.if ${MACHINE_ARCH} == "vax"
-COPTS+= -O0
-.endif
-
COPTS+= ${CC_WNO_IMPLICIT_FALLTHROUGH}

# XXX blocksort.c gets mis-compiled with 4.1
diff --git a/lib/libc/gdtoa/Makefile.inc b/lib/libc/gdtoa/Makefile.inc
index 132686fc33d..609da919803 100644
--- a/lib/libc/gdtoa/Makefile.inc
+++ b/lib/libc/gdtoa/Makefile.inc
@@ -44,10 +44,3 @@ SRCS+= dmisc.c \
.if ${MACHINE_ARCH} != "vax"
SRCS+= strtord.c
.endif
-
-# XXX revisit with newer GCC.
-# Ensure numbers like 0xffff319f5fa95963 print correctly
-# ("999999999999999.98", not garbage like "?A>C>@>C:BA;A><.:<")
-.if ${MACHINE_ARCH} == "vax" && defined(HAVE_GCC)
-COPTS.misc.c+= -O0
-.endif
diff --git a/lib/libcrypt/Makefile b/lib/libcrypt/Makefile
index cb3f89d6d09..e9c8be820da 100644
--- a/lib/libcrypt/Makefile
+++ b/lib/libcrypt/Makefile
@@ -30,9 +30,6 @@ SRCS+= crypt-argon2.c
SRCS+= ${src}
COPTS.${src}+= -fvisibility=hidden
. endfor
-. if ${MACHINE} == "vax"
-COPTS.blake2b.c+= -O0
-. endif
.endif

WARNS?= 5
diff --git a/libexec/ld.elf_so/Makefile b/libexec/ld.elf_so/Makefile
index f5baae1e883..24f7e1121e5 100644
--- a/libexec/ld.elf_so/Makefile
+++ b/libexec/ld.elf_so/Makefile
@@ -141,10 +141,6 @@ CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
COPTS.rtld.c+= -Wno-stack-protector
COPTS.symbol.c+=-Wno-stack-protector

-.if ${MACHINE_CPU} == "vax"
-COPTS.rtld.c+= -O0
-.endif
-
LDADD+= -Wl,--version-script=${.CURDIR}/symbols.map
LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
.if ${MKPICLIB} != "no"
diff --git a/sbin/fsck_ffs/Makefile.common b/sbin/fsck_ffs/Makefile.common
index 765638b2801..824e3bf2628 100644
--- a/sbin/fsck_ffs/Makefile.common
+++ b/sbin/fsck_ffs/Makefile.common
@@ -36,7 +36,3 @@ COPTS.ffs_appleufs.c+= -Wno-pointer-sign
.if ${MACHINE_ARCH} == "m68000"
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif
-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-.endif
diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile
index c039f73a1eb..3b0331e5880 100644
--- a/sbin/fsdb/Makefile
+++ b/sbin/fsdb/Makefile
@@ -39,12 +39,6 @@ COPTS.${f}.c+= -Wno-pointer-sign
COPTS.pass1.c+= -fno-tree-fre -fno-tree-lrs
.endif

-.if ${MACHINE_ARCH} == "vax"
-COPTS.pass1.c+= -O0
-COPTS.inode.c+= -O0
-COPTS.fsdb.c+= -O0
-.endif
-
CWARNFLAGS.gcc+= ${CC_WNO_ADDRESS_OF_PACKED_MEMBER}

.include <bsd.prog.mk>
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 40a44b9a038..ecfdbff4d3a 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -20,8 +20,4 @@ DPADD+=${LIBPROP}

.PATH: ${NETBSDSRCDIR}/sys/ufs/ext2fs ${FSCK}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mke2fs.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sbin/ping/Makefile b/sbin/ping/Makefile
index 4f33501ea7a..1f7f56e3ea5 100644
--- a/sbin/ping/Makefile
+++ b/sbin/ping/Makefile
@@ -12,8 +12,4 @@ CPPFLAGS+= -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}

-.if ${MACHINE_ARCH} == "vax"
-COPTS.ping.c=-O0
-.endif
-
.include <bsd.prog.mk>
diff --git a/sys/arch/vax/conf/Makefile.vax b/sys/arch/vax/conf/Makefile.vax
index cf095d54a86..c483eaa644a 100644
--- a/sys/arch/vax/conf/Makefile.vax
+++ b/sys/arch/vax/conf/Makefile.vax
@@ -34,7 +34,6 @@ GENASSYM_CONF= ${VAX}/vax/genassym.cf
CPPFLAGS+= -D_VAX_INLINE_
AFLAGS+= -x assembler-with-cpp -fno-pic
CFLAGS+= -fno-pic
-COPTS.wsmux.c+= ${${ACTIVE_CC} == "gcc" && ${HAVE_GCC:U0} >= 9:? -O1 :}


##
diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile
index 718c97ce857..4ef3840c753 100644
--- a/sys/lib/libsa/Makefile
+++ b/sys/lib/libsa/Makefile
@@ -96,7 +96,3 @@ SRCS+= ufs.c
lib${LIB}.o:: ${OBJS:O} __buildstdlib

CPPFLAGS+= -Wno-pointer-sign
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.bootp.c+= -O0
-.endif
diff --git a/sys/lib/libz/Makefile b/sys/lib/libz/Makefile
index 6945c0da6c6..61fb7d4f652 100644
--- a/sys/lib/libz/Makefile
+++ b/sys/lib/libz/Makefile
@@ -25,7 +25,3 @@ CLEANFILES+= lib${LIB}.o
.include <bsd.lib.mk>

lib${LIB}.o:: ${OBJS:O} __buildstdlib
-
-.if defined(HAVE_GCC) && ${MACHINE_ARCH} == "vax"
-COPTS.inftrees.c+= -O0
-.endif
diff --git a/sys/modules/lfs/Makefile b/sys/modules/lfs/Makefile
index 962538821a5..ea8f187e160 100644
--- a/sys/modules/lfs/Makefile
+++ b/sys/modules/lfs/Makefile
@@ -18,9 +18,4 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_inode.c ulfs_lookup.c \

WARNS= 3

-.if ${MACHINE} == "vax"
-# GCC 6.5 and 7.4 cannot compile this with -DDIAGNOSTIC and -O2/-O1
-COPTS.lfs_inode.c+= -O0
-.endif
-
.include <bsd.kmodule.mk>
diff --git a/sys/rump/fs/lib/liblfs/Makefile b/sys/rump/fs/lib/liblfs/Makefile
index abade3767d9..68b74c62502 100644
--- a/sys/rump/fs/lib/liblfs/Makefile
+++ b/sys/rump/fs/lib/liblfs/Makefile
@@ -17,9 +17,6 @@ SRCS+= ulfs_bmap.c ulfs_dirhash.c ulfs_extattr.c \


CFLAGS+= -DLFS_KERNEL_RFW
-.if ${MACHINE_ARCH} == "vax"
-COPTS.lfs_inode.c+=-O0
-.endif

.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff --git a/usr.sbin/mtrace/Makefile b/usr.sbin/mtrace/Makefile
index aef09db6198..9c125c15265 100644
--- a/usr.sbin/mtrace/Makefile
+++ b/usr.sbin/mtrace/Makefile
@@ -12,10 +12,6 @@ PROG= mtrace
SRCS= igmp.c inet.c kern.c mtrace.c
MAN= mtrace.8

-.if ${MACHINE_ARCH} == "vax"
-COPTS.mtrace.c=-O0
-.endif
-
BINMODE=4555
BINOWN= root

diff --git a/external/gpl3/gcc.old/usr.bin/backend/Makefile b/external/gpl3/gcc.old/usr.bin/backend/Makefile
index d69a26fe619..99e881c783d 100644
--- a/external/gpl3/gcc.old/usr.bin/backend/Makefile
+++ b/external/gpl3/gcc.old/usr.bin/backend/Makefile
@@ -533,68 +533,9 @@ COPTS.insn-recog.c+=-Wno-error

.if ${GCC_MACHINE_ARCH} == "vax"
CPPFLAGS+=-I${.CURDIR}/../../lib/libgcc/libgcov/arch/${GCC_MACHINE_ARCH}
-COPTS.builtins.c+=-O0
-COPTS.calls.c+=-O0
-COPTS.convert.c+=-O0
-COPTS.data-streamer-out.c+=-O0
-COPTS.dse.c+=-O0 # XXX port-vax/51967
-COPTS.dwarf2out.c+=-O0
-COPTS.expmed.c+=-O0
-COPTS.expr.c+=-O0 -Wno-error=tautological-compare
-COPTS.fixed-value.c+=-O0
-COPTS.fold-const.c+=-O0
-COPTS.generic-match.c+=-O0
-COPTS.gimple-fold.c+=-O0
-COPTS.gimple-match.c+=-O0
-COPTS.gimple-ssa-strength-reduction.c+=-O0
-COPTS.gimple-ssa-warn-restrict.c+=-O0
-COPTS.gimple.c+=-O0
-COPTS.internal-fn.c+=-O0
-COPTS.lto-streamer-out.c+=-O0
-COPTS.omp-low.c+=-O0
-COPTS.predict.c+=-O0
-COPTS.range-op.cc+=-O0
-COPTS.recog.c+=-O0
-COPTS.sanopt.c+=-O0
-COPTS.stmt.c+=-O0
-COPTS.stor-layout.c+=-O0
-COPTS.targhooks.c+=-O0
-COPTS.tree-affine.c+=-O0
-COPTS.tree-cfg.c+=-O0
-COPTS.tree-data-ref.c+=-O0
-COPTS.tree-eh.c+=-O0
-COPTS.tree-if-conv.c+=-O0
-COPTS.tree-object-size.c+=-O0
-COPTS.tree-parloops.c+=-O0
-COPTS.tree-predcom.c+=-O0
-COPTS.tree-pretty-print.c+=-O0
-COPTS.tree-ssa-alias.c+=-O0
-COPTS.tree-ssa-ccp.c+=-O0
-COPTS.tree-ssa-forwprop.c+=-O0
-COPTS.tree-ssa-loop-ivopts.c+=-O0
-COPTS.tree-ssa-loop-manip.c+=-O0
-COPTS.tree-ssa-loop-niter.c+=-O0
-COPTS.tree-ssa-math-opts.c+=-O0
-COPTS.tree-ssa-phiopt.c+= -O0
-COPTS.tree-ssa-pre.c+=-O0
-COPTS.tree-ssa-reassoc.c+=-O0
-COPTS.tree-ssa-strlen.c+=-O0
-COPTS.tree-ssa-uninit.c+=-O0
-COPTS.tree-ssa.c+=-O0
-COPTS.tree-switch-conversion.c+=-O0
-COPTS.tree-vect-data-refs.c+=-O0
-COPTS.tree-vect-loop-manip.c+=-O0
-COPTS.tree-vect-loop.c+=-O0
-COPTS.tree-vect-patterns.c+=-O0
-COPTS.tree-vect-stmts.c+=-O0
-COPTS.tree-vrp.c+=-O0
-COPTS.tree.c+=-O0
-COPTS.ubsan.c+=-O0
-COPTS.varasm.c+=-O0
-COPTS.vr-values.c+=-O0
-COPTS.web.c+=-O0
-COPTS.wide-int-range.cc+=-O0
-COPTS.wide-int.cc+=-O0
+
+COPTS.expmed.c+=-Wno-error=tautological-compare
+COPTS.expr.c+=-Wno-error=tautological-compare
.else
COPTS.tree.c= ${${ACTIVE_CC} == "clang" :? -O0 :}
.endif
 1.17 09-Nov-2013  christos branches: 1.17.36;
vax specific gcc 4.8.1 hacks
 1.16 13-Dec-2010  pooka branches: 1.16.6; 1.16.12;
RUMP_ACTION -> RUMPPRG
 1.15 11-Nov-2010  pooka add compile-conditional rumpclient support
 1.14 28-May-2007  tls Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.13 20-Feb-2001  bjh21 Add a dependency on libm.
 1.12 12-Jul-1999  itojun correct typo. s/LDADD/DPADD/
 1.11 02-Jul-1999  itojun IPsec support (specify policy on ping - quite useful to test
if IPsec is working or not) is added.
 1.10 24-Feb-1999  jwise Add code from Daniel Hagerty <hag@ai.mit.edu> to print standard deviation
when printing out final statistics line.

Closes PR bin/6198
 1.9 11-Mar-1997  christos - remove -g from Makefile
- fix setsockopt and recvfrom casts.
 1.8 11-Mar-1997  christos - Use err, warn, errx
- Don't use floor, because we would need libm
- Add maxwait option from old ping
- Add a centralized gethost() to get hostnames
- Fix PR/1014 and PR/2017; (adds -D, -T options, and -I and -t for unicast)
- Document exit status
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.4 16-Sep-1997  lukem imported from lite-2
 1.1.1.3 11-Mar-1997  christos From Vernon Schryver <vjs@sgi.com>
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.17.36.1 08-Oct-2023  martin Pull up following revision(s) (requested by rin in ticket #394):

external/gpl3/binutils/dist/gas/config/tc-vax.h: revision 1.10
tools/gcc/Makefile: revision 1.109
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.16
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.17
external/gpl3/binutils/dist/gas/config/tc-vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/recog.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/function.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/dse.c: revision 1.14 - 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.13
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.15
external/gpl3/gcc.old/dist/gcc/doc/tm.texi.in: revision 1.10
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/vax.c: revision 1.19
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.13
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.20
external/gpl3/gcc.old/dist/gcc/targhooks.c: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.14
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.15
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.16
external/gpl3/gcc.old/dist/gcc/config/vax/builtins.md: revision 1.13
external/gpl3/gcc.old/dist/gcc/doc/tm.texi: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.17
external/gpl3/gcc.old/dist/gcc/config/vax/vax.md: revision 1.18
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/config/vax/elf.h: revision 1.13
external/gpl3/gcc.old/dist/gcc/targhooks.h: revision 1.12
external/gpl3/gcc.old/dist/gcc/target.def: revision 1.10
external/gpl3/gcc.old/dist/gcc/rtlanal.c: revision 1.14
external/gpl3/gcc.old/dist/gcc/reload.c: revision 1.12
external/gpl3/gcc.old/usr.bin/gcc/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/lto-dump/Makefile: revision 1.3
external/gpl3/gcc.old/lib/Makefile.sanitizer: revision 1.7
external/gpl3/binutils.old/lib/libbfd/Makefile: revision 1.10
distrib/utils/x_ping/Makefile: revision 1.9
games/phantasia/Makefile: revision 1.38
external/apache2/argon2/lib/libargon2/Makefile.inc: revision 1.2
external/gpl3/gcc.old/lib/libubsan/Makefile: revision 1.8
external/bsd/mdocml/lib/libmandoc/Makefile: revision 1.13
sbin/ping/Makefile: revision 1.18
sbin/newfs_ext2fs/Makefile: revision 1.7
sys/lib/libz/Makefile: revision 1.24
sys/lib/libsa/Makefile: revision 1.97
external/gpl3/gcc.old/usr.bin/cc1objplus/Makefile: revision 1.3
external/gpl3/gdb/lib/libgdb/Makefile: revision 1.36
sys/modules/lfs/Makefile: revision 1.11
external/mit/xorg/lib/gallium/Makefile: revision 1.51
external/gpl3/gdb.old/lib/libdecnumber/Makefile: revision 1.10
external/mit/xorg/lib/libX11/Makefile.libx11: revision 1.26
libexec/ld.elf_so/Makefile: revision 1.148
external/bsd/jemalloc/lib/Makefile.inc: revision 1.16
external/gpl3/gcc.old/usr.bin/libdecnumber/Makefile: revision 1.14
crypto/external/bsd/openssh/lib/Makefile: revision 1.38
external/gpl3/gcc.old/usr.bin/backend/Makefile: revision 1.21
external/gpl3/gcc.old/usr.bin/cc1/Makefile: revision 1.12
external/gpl3/gcc.old/lib/libasan/Makefile: revision 1.11
external/gpl3/gcc.old/usr.bin/cc1plus/Makefile: revision 1.13
lib/libcrypt/Makefile: revision 1.36
external/gpl3/gdb/lib/libdecnumber/Makefile: revision 1.5
lib/libc/gdtoa/Makefile.inc: revision 1.13
games/gomoku/Makefile: revision 1.13
sbin/fsdb/Makefile: revision 1.43
external/gpl3/gcc.old/usr.bin/lto1/Makefile: revision 1.9
external/mit/xorg/lib/gallium.old/Makefile: revision 1.8
lib/libbz2/Makefile: revision 1.22
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.12
usr.sbin/mtrace/Makefile: revision 1.14
external/gpl3/gcc.old/usr.bin/cc1obj/Makefile: revision 1.13
sys/arch/vax/conf/Makefile.vax: revision 1.86
sys/rump/fs/lib/liblfs/Makefile: revision 1.18
sbin/fsck_ffs/Makefile.common: revision 1.3
external/gpl3/binutils/lib/libbfd/Makefile: revision 1.27
lib/i18n_module/UTF7/Makefile: revision 1.5
external/gpl3/gcc.old/lib/liblsan/Makefile: revision 1.7
doc/CHANGES (apply patch)
(all external/gpl3/gcc.old/ changes applied to external/gpl3/gcc/)

PR 57646: Import major vax toolchain fix.
 1.50 10-Sep-2011  wiz Another option order fix.
 1.49 10-Sep-2011  wiz Sort options and descriptions in standard order.
Remove unecessary Bk/Ek in SYNOPSIS.
 1.48 10-Sep-2011  christos PR/45257: Instead of passing a 32bit sec and 32 bit usec timestamp in little
endian format by default, pass a struct timespec in native host format. Add
-C flag to produce a compatible timestamp like before.
 1.47 21-Mar-2006  pavel Clarify and correct the description of the -R (Record Route) flag.
Reviewed by jnemeth, whith help from him.
 1.46 21-Mar-2006  pavel Bump date, requested by wiz.
 1.45 21-Mar-2006  pavel -I does work for unicast pings too (it sets the source address).
With some language help from dsl.
Reviewed by jnemeth.
 1.44 08-Jun-2004  cjep add -h option in synopsis. Fixes PR#25863 from Kouichirou Hiratsuka.
 1.43 07-Aug-2003  agc branches: 1.43.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.42 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.41 26-Oct-2002  jdolecek change description of -w option to match reality
this fixes bin/12113 by Jim Bernard and bin/16011 by gabriel rosenkoetter
 1.40 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.39 06-Apr-2002  bjh21 .Nm . -> .Nm "" .
 1.38 20-Dec-2001  wiz Sync options with usage.
 1.37 16-Nov-2001  wiz Simplify markup, use .Nx, sort sections.
 1.36 16-Nov-2001  wiz Whitespace nits
 1.35 10-Oct-2001  yamt - use IP_MAXPACKET instead of 65535.
- change max packet size from 65468 to 65467(= IP_MAXPACKET-60-8).
 1.34 25-Jun-2001  jhawk Update Dd to rev 1.31 (ipsec changes)
Some hosts and gateways ignore record route, but not "many." Of course,
more are firewalled. But that's not what was meant here.
Expand flood-pinging admonition to include multicast addresses.
Note flags that conflict with ping under Solaris and FreeBSD.
Reorder BUGS in rough order of significance.
 1.33 05-Jun-2001  wiz Drop arguments of .Os.
 1.32 03-Apr-2001  jhawk Xr icmp(4), inet(4), ip(4)
 1.31 02-Jul-1999  itojun IPsec support (specify policy on ping - quite useful to test
if IPsec is working or not) is added.
 1.30 19-Jun-1999  sommerfeld Support for ping -a: beep when packet received.
Slightly tweaked from version submitted by andrew@untraceable.net in PR7815
 1.29 12-Jun-1999  tron Fix a typo.
 1.28 29-Apr-1999  mjl Remove duplicate paragraph. Closes PR/7498 by Geoff C. Wing.
 1.27 07-Mar-1999  mycroft branches: 1.27.2;
Clean up SYNOPSIS formatting.
 1.26 22-Dec-1998  jtk typo: should be loose source routing
 1.25 17-Nov-1998  msaitoh delete .TP (because this document is written in "mdoc" format)
 1.24 25-Oct-1998  christos Update to the 980911 version from ftp.rhyolite.com:/src/ping.tar.Z
 1.23 14-Sep-1998  tv Restrict -l to the superuser as suggested in PR 3973 from <soren@t.dk>.
Also distinguish "-f" from "-i 0.x" in the superuser restriction messages.
 1.22 29-Apr-1998  fair fix bad .Xr references
 1.21 28-Apr-1998  fair Change occurrences of "UNIX" to .Ux or .At as appropriate.
 1.20 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.19 06-Nov-1997  fair Fix man page confusion about the -R option, per PR#4246
Add some paragraph breaks for readability,
and a traceroute(8) reference.
 1.18 03-Oct-1997  hubertf branches: 1.18.2;
PR misc/4206: internal -> interval;
Reported by William O Ferry.
 1.17 15-Sep-1997  lukem * cleanup .Nm
* deprecate register
* cleanup for WARNS=1
* bzero(), bcopy() -> memset(), memmove()
* prefix hex numbers with '0x'
 1.16 26-Jun-1997  kleink Fix formatting directives; from SAITOH Masanobu <msaitoh@spa.is.uec.ac.jp>
in PR misc/3795.
 1.15 01-Jun-1997  christos Update from Vernon Schryver, fixing the kluge to flush the route cache.
 1.14 10-Apr-1997  mikel flag is -f, not --f; from Saitoh Masanobu in PR misc/3469.
 1.13 18-Mar-1997  christos PR/3329: From David Jones: Add F_ONCE
 1.12 11-Mar-1997  christos - Use err, warn, errx
- Don't use floor, because we would need libm
- Add maxwait option from old ping
- Add a centralized gethost() to get hostnames
- Fix PR/1014 and PR/2017; (adds -D, -T options, and -I and -t for unicast)
- Document exit status
 1.11 06-Nov-1996  cgd make ping(8) print out statistics when given a SIGINFO.
 1.10 31-Dec-1995  ghudson The maxwait option was accidentally placed in the "options for
multicast pings" section of the description.
 1.9 02-Oct-1995  pk Fix typo (from Mark Weaver PR#1556);
 1.8 27-Jul-1995  ghudson Add and document options -w (to specify a maximum wait timeout, useful
for testing network interfaces) and -S (to specify a source address
on a machine with multiple interfaces).
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 29-Nov-1994  glass misc/596: fix from James Jegers for missing host and add cross ref to spray.
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.4 16-Sep-1997  lukem imported from lite-2
 1.1.1.3 11-Mar-1997  christos From Vernon Schryver <vjs@sgi.com>
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.2.1 06-Nov-1997  mellon Pull rev 1.19 up from trunk (fair)
 1.27.2.1 24-Jun-1999  perry pullup 1.27->1.30 (sommerfeld)
 1.43.2.1 13-Jun-2004  jdc Pull up revision 1.44 (requested by cjep in ticket #459).

add -h option in synopsis. Fixes PR#25863 from Kouichirou Hiratsuka.
 1.122 01-Dec-2022  christos fix sign.
 1.121 01-Dec-2022  christos Add a sanity check for the ip header length (from FreeBSD)
 1.120 22-May-2022  andvar fix various small typos, mainly in comments.
 1.119 07-Apr-2022  andvar fix various typos in comments.
 1.118 11-Jun-2021  rillig ping, ping6: fix comment about ID field

Since ping.c 1.76 and ping6.c 1.58 from 2004-04-22, the ID field
contains random bits instead of a process ID.
 1.117 02-Oct-2017  maya un-ifdef sgi. NFC
 1.116 17-Mar-2017  ryo Fix cksum calculation for clearing the cached route.

In ping.c:r1.104, the size of echoreply packet was changed to ICMP_MINLEN,
Therefore also calculation size must be ICMP_MINLEN.
 1.115 11-Jan-2017  joerg branches: 1.115.2;
Use an explicitly aligned buffer for ip.
 1.114 18-Dec-2016  dholland PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.

Reject packet intervals < 1 ns as they lead to infinite loops adding
zero timespecs.

Fix the behind-schedule behavior so it doesn't spend all its time in
that loop adding very small timespecs. Try ping -c 500 -i 0.000000001
to see this in action with the old ping.
 1.113 18-Dec-2016  dholland PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.

Check for values between INT_MAX and LONG_MAX (if they're different)
when using strtol to get an int. This applies to the -c and -l options;
the other uses were already checked.

Also limit the inter-packet interval given with -i to values that
don't cause integer overflow calling poll() with milliseconds.

Really large intervals (the number is read as floating point) can
produce positive poll() values but negative integers when converted to
struct timespec; this produces behavior akin to using -l at first and
could be construed as a local DoS vulnerability.
 1.112 07-Oct-2016  joerg Make optspace an array of uint8_t, since some of the bytes written into
it are outside the signed char range.
 1.111 31-Jul-2016  dholland Manipulate the signal masks so signals only arrive while we're waiting,
so they can't illegally reenter libc.

Fixes the problem Greg A. Woods describes in PR 51267, which might or
might not be the original submitter's problem.
 1.110 31-Jul-2016  dholland Don't call variables that are used "dummy".
 1.109 29-Nov-2014  christos branches: 1.109.2;
Adjust default packet size to 56 data bytes (64 total).
Make error messages consistent.
 1.108 27-Nov-2014  christos PR/49423: Martin Husemann: ping for small packets does not work in -7 or
-current
XXX: pullup 7?
 1.107 19-Oct-2013  christos branches: 1.107.4;
avoid bogus uninitialized gcc warning
 1.106 06-Mar-2013  yamt more precision for F_TIMING64
 1.105 30-Dec-2012  christos deduct phdrlen after computing max size.
 1.104 30-Dec-2012  christos 1. Allocate the max packet size before accounting for phdrlen, harmless.
2. In the clear-route-cache sendto, don't send 0 bytes (if -s was specified
with < 8, phdrlen would be 0).
3. Always send ICMP_MINLEN packets; this is what everyone else does. Makes
ping -s n where n < 8 work.
4. The condition for checking the data bytes was completely wrong. only check
the data bytes if we got all of them.
5. The condition for printing a newline was wrong; before it would not print
a newline before printing the data bytes, and it would append to the previous
error message.
 1.103 18-Sep-2012  msaitoh Fix a bug that misunderstand F_TIMING64, F_POLICY and F_AUTHHDR.
 1.102 04-Jan-2012  drochner branches: 1.102.2; 1.102.6; 1.102.8;
include <netipsec/ipsec.h> rather than <netinet6/ipsec.h> from userland
where possible, for consistency and compatibility to FreeBSD
(exception: KAME specific statistics gathering in netstat(1) and systat(1))
 1.101 11-Sep-2011  christos branches: 1.101.2;
print summary stats.
 1.100 10-Sep-2011  wiz Sort options and descriptions in standard order.
Remove unecessary Bk/Ek in SYNOPSIS.
 1.99 10-Sep-2011  christos PR/45257: Instead of passing a 32bit sec and 32 bit usec timestamp in little
endian format by default, pass a struct timespec in native host format. Add
-C flag to produce a compatible timestamp like before.
 1.98 27-Aug-2011  joerg static + __dead
 1.97 21-Aug-2011  christos handle the first loop where time == 0.
 1.96 20-Aug-2011  christos we need difftime to return a signed result, so clamp the timeval's to
uint32_t but then, return a signed result of their difference.
 1.95 19-Aug-2011  christos PR/45257: Ryo Shimizu: ping(8) prints bogus round-trip times after Year 2038
Clamp all time computations to 32 bits; idea from dsl@
 1.94 09-Aug-2011  joerg Don't use array access to compute addresses that are definitely beyond
the static array boundaries.
 1.93 11-Mar-2011  pooka Make get/setuid prog ops (so that i can do rump.ping -f regardless
of host privs).
 1.92 13-Dec-2010  pooka RUMP_ACTION -> RUMPPRG
 1.91 11-Nov-2010  pooka add compile-conditional rumpclient support
 1.90 02-Nov-2009  christos remove ancient ifdefs (Aleksej Saushev)
 1.89 11-Apr-2009  lukem fix sign-compare issues
 1.88 31-Mar-2009  christos PR/41111: Ed Ravin: ping -R gives misleading error when remote side doesn't
support record route
Deal with source route and record route specially giving a meaningful error
message.
Pullup to 5.0?
 1.87 08-Jan-2008  seanb branches: 1.87.10; 1.87.12; 1.87.16;
Shutdown sloop socket for read as it's never read on to
prevent mbufs from queueing in its recv buf.
PR:21459
 1.86 17-Jan-2007  hubertf branches: 1.86.4; 1.86.6;
Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.85 28-Sep-2006  elad Change error message to say "setuid", forgotten in previous commit.

Pointed out by Ray Lai, thanks!
 1.84 24-Sep-2006  elad On 2nd thought, setuid() is better here.
 1.83 24-Sep-2006  elad PR/28741: Michael Santos: ping does [not] drop root privileges

Moved socket calls way up, and called seteuid(getuid()).
 1.82 14-Jul-2006  yamt prtsig: remove a mysterious abort().
 1.81 03-Jun-2006  christos Use SA_NOKERNINFO instead of playing with the tty.
 1.80 01-Jun-2006  christos Factor out the tty code and explain we prefer to stop in the ^Z bg case
when we exit, rather than kill the tty setting.
 1.79 01-Jun-2006  christos PR/33623: Chuck Cranor: Ping stops when ran in the background
because it tries to set the tty not to print kerninfo. Change it
to only only play with the tty when ping is running in the foreground
(and will not stop when calling tcsetattr()). In my opinion, it is
preferable to print the kerninfo line with the ping info message
rather than to mess with the tty, but that's just me.
 1.78 09-May-2006  mrg change (mostly) int to socklen_t. GCC 4 doesn't like that int and
socklen_t are different signness.
 1.77 13-May-2004  kleink branches: 1.77.2; 1.77.4; 1.77.6;
There's no point in bringing PRNG output to network byteorder prior to
transmission.
 1.76 22-Apr-2004  itojun do not disclose endian. henning@openbsd
 1.75 26-Jan-2004  itojun branches: 1.75.2; 1.75.4; 1.75.6;
do not disclose endianness/sizeof(long) on probe packet. idea from openbsd
 1.74 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.73 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.72 14-Apr-2003  itojun permit -s 0. from Maxim Konovalov
 1.71 16-Nov-2002  itojun set sa_len right
 1.70 16-Nov-2002  itojun die if strdup fails
 1.69 16-Nov-2002  itojun use strlcpy. initialize sa_len correctly.
 1.68 21-Sep-2002  mycroft Touch up error/warning messages.
 1.67 21-Sep-2002  mycroft select() -> poll()
 1.66 12-Aug-2002  matt Add support for printing out messages about missing packet gaps. This is
done with the -v switch. If -q is also given with -v, then only the
packet gap messages will be printed along with summary after each gap
message.
 1.65 01-Aug-2002  itojun u_short cleansing (use u_int16_t where appropriate)
 1.64 31-May-2002  itojun clarify comment when nreceived > ntransmitted. from deraadt
 1.63 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.62 01-Nov-2001  lukem fix a couple of -Wshadow warnings
 1.61 10-Oct-2001  yamt - use IP_MAXPACKET instead of 65535.
- change max packet size from 65468 to 65467(= IP_MAXPACKET-60-8).
 1.60 09-Oct-2001  yamt - fix overrun bug.
- bump bufsize to fix "packet loss" with large packet.
 1.59 19-Feb-2001  cgd convert to use getprogname()
 1.58 12-Jan-2001  itojun correct use of howmany() for fd_set. commented by deraadt
 1.57 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.56 07-Oct-2000  itojun avoid fd_set overflow. see openbsd select(2).
 1.55 31-Jan-2000  itojun branches: 1.55.4;
sync with latest libipsec and kernel.
 1.54 20-Jan-2000  mycroft Fix data comparison to not overrun array bounds.
 1.53 04-Jul-1999  itojun do not pass NULL to errx().

From: Chris Joness <cjones@rupert.honors.montana.edu>
 1.52 04-Jul-1999  itojun do not bark even if ipsec policy setting for "route flushing 127.0.0.1"
ping socket is not successful. it usually means that the kernel is
not ipsec ready, and in that case this should be just okay.
 1.51 03-Jul-1999  kleink 0 -> STDIN_FILENO
 1.50 02-Jul-1999  itojun IPsec support (specify policy on ping - quite useful to test
if IPsec is working or not) is added.
 1.49 19-Jun-1999  sommerfeld Support for ping -a: beep when packet received.
Slightly tweaked from version submitted by andrew@untraceable.net in PR7815
 1.48 17-Apr-1999  mjl Correct nokerninfo tty flag being left set in most error cases.
Closes PR/7388 by Dave Huang <khym@bga.com>.
 1.47 08-Mar-1999  sommerfe branches: 1.47.2;
Don't bother doing stddev calculation when n==1, since that results in
a computation of 0.0/0.0.
On IEEE systems you get a NaN from this; non-IEEE systems probably
give you a SIGFPE.
 1.46 25-Feb-1999  jwise Once more around the hickory shrub. Faster and simpler stddev calculation from
Bill Studenmund.
 1.45 25-Feb-1999  jwise Fix calculation of standard deviation. From Brian C. Grayson <bgrayson@orac.ece.utexas.edu>
 1.44 24-Feb-1999  jwise Add code from Daniel Hagerty <hag@ai.mit.edu> to print standard deviation
when printing out final statistics line.

Closes PR bin/6198
 1.43 06-Nov-1998  christos char -> unsigned char
 1.42 26-Oct-1998  enami Fix usage string;
- option to specify maxwait is -w, not -i.
- add missing -h host and -Q option.
 1.41 25-Oct-1998  christos Update to the 980911 version from ftp.rhyolite.com:/src/ping.tar.Z
 1.40 01-Oct-1998  frueauf Add getuid() check if -f is set, fixes pr 6222 by Uwe Arndt.
 1.39 14-Sep-1998  tv Restrict -l to the superuser as suggested in PR 3973 from <soren@t.dk>.
Also distinguish "-f" from "-i 0.x" in the superuser restriction messages.
 1.38 14-Sep-1998  tv Nuke the termios stuff from the 1997/03/11 import, which prevents ping
from being run in the background of most shells without redirecting stdin
from /dev/null. (AFAICT, the termios stuff is useless and does not
interfere with SIGINFO handling.)
 1.37 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.36 16-Apr-1998  kleink Take into consideration that icmp_nextmtu is stored in network byte order;
from Leonard Samuelson in PR bin/5230.
 1.35 01-Dec-1997  christos PR/4615: David Jones: Ping usage does not show -o option.
 1.34 30-Nov-1997  christos Make the "failed to clear cached route" a warning only if verbose is set.
This always happens when lo0 is not configured and confuses new users.
 1.33 05-Nov-1997  cgd lint
 1.32 15-Sep-1997  lukem branches: 1.32.2;
* cleanup .Nm
* deprecate register
* cleanup for WARNS=1
* bzero(), bcopy() -> memset(), memmove()
* prefix hex numbers with '0x'
 1.31 17-Jul-1997  mikel convert to host byte order when printing stats of received ICMP
packets other than echo-replies; from Dave Huang in PR bin/3876
 1.30 01-Jun-1997  christos Update from Vernon Schryver, fixing the kluge to flush the route cache.
 1.29 02-Apr-1997  augustss Make ping obey the -n flag in places.
 1.28 24-Mar-1997  christos Don't allow < 1 sec ping interval to regular users.
 1.27 19-Mar-1997  christos Try adding `o' option again; connection died.
 1.26 19-Mar-1997  christos Take care of alignment problems on the alpha: From John Birell, via cgd.
 1.25 18-Mar-1997  christos PR/3329: From David Jones: Add F_ONCE
 1.24 13-Mar-1997  christos Fix PR/3327: rcvd_tbl index was assumed to be in host order, creating
incorrect dup reports. From enami tsugutomo
 1.23 11-Mar-1997  christos - remove -g from Makefile
- fix setsockopt and recvfrom casts.
 1.22 11-Mar-1997  christos - Use err, warn, errx
- Don't use floor, because we would need libm
- Add maxwait option from old ping
- Add a centralized gethost() to get hostnames
- Fix PR/1014 and PR/2017; (adds -D, -T options, and -I and -t for unicast)
- Document exit status
 1.21 06-Nov-1996  cgd make ping(8) print out statistics when given a SIGINFO.
 1.20 11-Aug-1995  cgd fix a couple of bugs pointed out by John Birrell, though fix some
differently he did. (1) don't assume that the timeval in
the packet is correctly aligned, (2) don't compare beyond the end
of the packet, (3) minor cast for printf happiness.
 1.19 27-Jul-1995  ghudson Add and document options -w (to specify a maximum wait timeout, useful
for testing network interfaces) and -S (to specify a source address
on a machine with multiple interfaces).
 1.18 26-Jun-1995  jtc sys/signal.h -> signal.h
 1.17 03-Jun-1995  mycroft Fill in sin_len.
 1.16 21-May-1995  mycroft Use inet_aton(), not inet_addr().
 1.15 22-Apr-1995  cgd if no packets were received, exit with status 1. this should be
documented somewhere. As suggested by Rens Troost.
 1.14 21-Mar-1995  mycroft Update to use timer{add,sub}().
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 18-Dec-1994  cgd -Wall cleanups from Jim Jegers
 1.11 31-Oct-1994  cgd will need <sys/queue.h>
 1.10 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.9 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.8 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.7 15-Dec-1993  hpeyerl Another multicast patch.
>From LBL and Steve Mccanne
 1.6 23-Sep-1993  mycroft Use doubles to rather than longs to avoid tsum overflowing so quickly.
 1.5 01-Aug-1993  mycroft Add RCS identifiers.
 1.4 22-Jul-1993  cgd have ping do the right thing, wrt microseconds.
actually, now it'll overflow its counters sooner than before, and everything
should *really* be converted to doubles and/or "unsigned long long"s
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.4 16-Sep-1997  lukem imported from lite-2
 1.1.1.3 11-Mar-1997  christos From Vernon Schryver <vjs@sgi.com>
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.32.2.2 05-May-1998  mycroft Pull up 1.36, per request of kleink.
 1.32.2.1 01-Dec-1997  mellon Pull rev 1.33, 1.34 and 1.35 up from trunk (christos) (reviewed by mellon)
 1.47.2.2 10-Oct-2000  he Pull up revision 1.57 (via patch, requested by is):
Format string cleanup.
 1.47.2.1 24-Jun-1999  perry pullup 1.47->1.48 (sommerfeld)
 1.55.4.2 18-Oct-2000  tv Pullup 1.56 [itojun]:
avoid fd_set overflow.
 1.55.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.75.6.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #11352):
sbin/ping/ping.c: revision 1.83 - 1.85
PR/28741: Michael Santos: ping does [not] drop root privileges
Moved socket calls way up, and called seteuid(getuid()).
On 2nd thought, setuid() is better here.
Change error message to say "setuid", forgotten in previous commit.
Pointed out by Ray Lai, thanks!
 1.75.4.2 11-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #11352):
sbin/ping/ping.c: revision 1.83 - 1.85
PR/28741: Michael Santos: ping does [not] drop root privileges
Moved socket calls way up, and called seteuid(getuid()).
On 2nd thought, setuid() is better here.
Change error message to say "setuid", forgotten in previous commit.
Pointed out by Ray Lai, thanks!
 1.75.4.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #11351):
sbin/ping/ping.c: revision 1.79, 1.80
PR/33623: Chuck Cranor: Ping stops when ran in the background
because it tries to set the tty not to print kerninfo. Change it
to only only play with the tty when ping is running in the foreground
(and will not stop when calling tcsetattr()). In my opinion, it is
preferable to print the kerninfo line with the ping info message
rather than to mess with the tty, but that's just me.
Factor out the tty code and explain we prefer to stop in the ^Z bg case
when we exit, rather than kill the tty setting.
 1.75.2.1 11-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #11352):
sbin/ping/ping.c: revision 1.83 - 1.85
PR/28741: Michael Santos: ping does [not] drop root privileges
Moved socket calls way up, and called seteuid(getuid()).
On 2nd thought, setuid() is better here.
Change error message to say "setuid", forgotten in previous commit.
Pointed out by Ray Lai, thanks!
 1.77.6.1 26-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #1818):
sbin/ping/ping.c: revisions 1.83 - 1.85
PR/28741: Michael Santos: ping does [not] drop root privileges
 1.77.4.1 26-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #1818):
sbin/ping/ping.c: revisions 1.83 - 1.85
PR/28741: Michael Santos: ping does [not] drop root privileges
 1.77.2.2 26-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #1818):
sbin/ping/ping.c: revisions 1.83 - 1.85
PR/28741: Michael Santos: ping does [not] drop root privileges
 1.77.2.1 26-Aug-2007  bouyer Pull up following revision(s) (requested by ghen in ticket #1817):
sbin/ping/ping.c: revisions 1.79 - 1.80
PR/33623: Chuck Cranor: Ping stops when ran in the background
because it tries to set the tty not to print kerninfo. Change it
to only only play with the tty when ping is running in the foreground
(and will not stop when calling tcsetattr()). In my opinion, it is
preferable to print the kerninfo line with the ping info message
rather than to mess with the tty, but that's just me.
Factor out the tty code and explain we prefer to stop in the ^Z bg case
when we exit, rather than kill the tty setting.
 1.86.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.86.4.1 23-Mar-2008  matt sync with HEAD
 1.87.16.1 21-Apr-2010  matt sync to netbsd-5
 1.87.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.87.10.1 03-May-2009  snj Pull up following revision(s) (requested by christos in ticket #636):
sbin/ping/ping.c: revision 1.88
PR/41111: Ed Ravin: ping -R gives misleading error when remote side doesn't
support record route
Deal with source route and record route specially giving a meaningful error
message.
 1.101.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.101.2.3 23-Jan-2013  yamt sync with head
 1.101.2.2 30-Oct-2012  yamt sync with head
 1.101.2.1 17-Apr-2012  yamt sync with head
 1.102.8.1 11-Jul-2017  snj Pull up following revision(s) (requested by dholland in ticket #1424):
sbin/ping/ping.c: revision 1.113 via patch
PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.
Check for values between INT_MAX and LONG_MAX (if they're different)
when using strtol to get an int. This applies to the -c and -l options;
the other uses were already checked.
Also limit the inter-packet interval given with -i to values that
don't cause integer overflow calling poll() with milliseconds.
Really large intervals (the number is read as floating point) can
produce positive poll() values but negative integers when converted to
struct timespec; this produces behavior akin to using -l at first and
could be construed as a local DoS vulnerability.
 1.102.6.4 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.102.6.3 23-Jun-2013  tls resync from head
 1.102.6.2 25-Feb-2013  tls resync with head
 1.102.6.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.102.2.2 11-Jul-2017  snj Pull up following revision(s) (requested by dholland in ticket #1424):
sbin/ping/ping.c: revision 1.113 via patch
PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.
Check for values between INT_MAX and LONG_MAX (if they're different)
when using strtol to get an int. This applies to the -c and -l options;
the other uses were already checked.
Also limit the inter-packet interval given with -i to values that
don't cause integer overflow calling poll() with milliseconds.
Really large intervals (the number is read as floating point) can
produce positive poll() values but negative integers when converted to
struct timespec; this produces behavior akin to using -l at first and
could be construed as a local DoS vulnerability.
 1.102.2.1 23-Oct-2012  riz branches: 1.102.2.1.2;
Pull up following revision(s) (requested by msaitoh in ticket #621):
sbin/ping/ping.c: revision 1.103
Fix a bug that misunderstand F_TIMING64, F_POLICY and F_AUTHHDR.
 1.102.2.1.2.1 11-Jul-2017  snj Pull up following revision(s) (requested by dholland in ticket #1424):
sbin/ping/ping.c: revision 1.113 via patch
PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.
Check for values between INT_MAX and LONG_MAX (if they're different)
when using strtol to get an int. This applies to the -c and -l options;
the other uses were already checked.
Also limit the inter-packet interval given with -i to values that
don't cause integer overflow calling poll() with milliseconds.
Really large intervals (the number is read as floating point) can
produce positive poll() values but negative integers when converted to
struct timespec; this produces behavior akin to using -l at first and
could be construed as a local DoS vulnerability.
 1.107.4.3 12-May-2017  snj Pull up following revision(s) (requested by ryo in ticket #1390):
sbin/ping/ping.c: revision 1.116
Fix cksum calculation for clearing the cached route.
In ping.c:r1.104, the size of echoreply packet was changed to ICMP_MINLEN,
Therefore also calculation size must be ICMP_MINLEN.
 1.107.4.2 18-Dec-2016  snj branches: 1.107.4.2.2;
Pull up following revision(s) (requested by dholland in ticket #1333):
sbin/ping/ping.c: revision 1.113
PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.
Check for values between INT_MAX and LONG_MAX (if they're different)
when using strtol to get an int. This applies to the -c and -l options;
the other uses were already checked.
Also limit the inter-packet interval given with -i to values that
don't cause integer overflow calling poll() with milliseconds.
Really large intervals (the number is read as floating point) can
produce positive poll() values but negative integers when converted to
struct timespec; this produces behavior akin to using -l at first and
could be construed as a local DoS vulnerability.
 1.107.4.1 14-Apr-2015  snj branches: 1.107.4.1.2; 1.107.4.1.4;
Pull up following revision(s) (requested by christos in ticket #692):
sbin/ping/ping.c: revisions 1.108, 1.109
PR/49423: Martin Husemann: ping for small packets does not work in -7 or
-current
--
Adjust default packet size to 56 data bytes (64 total).
Make error messages consistent.
 1.107.4.2.2.1 12-May-2017  snj Pull up following revision(s) (requested by ryo in ticket #1390):
sbin/ping/ping.c: revision 1.116
Fix cksum calculation for clearing the cached route.
In ping.c:r1.104, the size of echoreply packet was changed to ICMP_MINLEN,
Therefore also calculation size must be ICMP_MINLEN.
 1.107.4.1.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.107.4.1.2.2 12-May-2017  snj Pull up following revision(s) (requested by ryo in ticket #1390):
sbin/ping/ping.c: revision 1.116
Fix cksum calculation for clearing the cached route.
In ping.c:r1.104, the size of echoreply packet was changed to ICMP_MINLEN,
Therefore also calculation size must be ICMP_MINLEN.
 1.107.4.1.2.1 18-Dec-2016  snj Pull up following revision(s) (requested by dholland in ticket #1333):
sbin/ping/ping.c: revision 1.113
PR bin/36997 Zafer Aydogan: ping doesn't validate numeric inputs enough.
Check for values between INT_MAX and LONG_MAX (if they're different)
when using strtol to get an int. This applies to the -c and -l options;
the other uses were already checked.
Also limit the inter-packet interval given with -i to values that
don't cause integer overflow calling poll() with milliseconds.
Really large intervals (the number is read as floating point) can
produce positive poll() values but negative integers when converted to
struct timespec; this produces behavior akin to using -l at first and
could be construed as a local DoS vulnerability.
 1.109.2.4 20-Mar-2017  pgoyette Sync with HEAD
 1.109.2.3 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.109.2.2 04-Nov-2016  pgoyette Sync with HEAD
 1.109.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.115.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.2 11-Mar-2011  pooka Make get/setuid prog ops (so that i can do rump.ping -f regardless
of host privs).
 1.1 13-Dec-2010  pooka RUMP_ACTION -> RUMPPRG
 1.2 11-Mar-2011  pooka Make get/setuid prog ops (so that i can do rump.ping -f regardless
of host privs).
 1.1 13-Dec-2010  pooka RUMP_ACTION -> RUMPPRG
 1.3 11-Mar-2011  pooka Make get/setuid prog ops (so that i can do rump.ping -f regardless
of host privs).
 1.2 13-Dec-2010  pooka be a happy crunch build
 1.1 13-Dec-2010  pooka RUMP_ACTION -> RUMPPRG
 1.17 10-Oct-2017  christos user librumpres
 1.16 09-Sep-2015  ozaki-r Include several libc functions in rump.ping6

We need getaddrinfo, getifaddrs, if_indextoname and if_nametoindex
in addition to getnameinfo.
 1.15 06-Aug-2015  ozaki-r Introduce rump.ping6

We use ping6 frequently in ATF tests so let's have rump-ified one.
 1.14 14-Aug-2011  christos fix gcc warnings and eliminate duplicate code.
 1.13 22-Jun-2011  mrg apply some -Wno-error and/or -fno-strict-aliasing.


all of this should be looked at closer, but some of them are not
very trivial.
 1.12 28-May-2007  tls Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.11 07-May-2006  rpaulo Remove support support for RFC 2292.
 1.10 05-May-2006  rpaulo Add support for RFC 3542 Adv. Socket API for IPv6 (which obsoletes 2292).
* RFC 3542 isn't binary compatible with RFC 2292.
* RFC 2292 support is on by default but can be disabled.
* update ping6, telnet and traceroute6 to the new API.

From the KAME project (www.kame.net).
Reviewed by core.
 1.9 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.8 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.7 26-May-2002  itojun no need for KAME_SCOPEID
 1.6 07-Oct-2000  itojun repair fd_set size attack. from deraadt.
some of cleanups from kame (inet_ntop error check, unnecessary headers,
stddev computation like ping(8)).
$NetBSD$.
 1.5 13-Dec-1999  itojun branches: 1.5.4;
provide -S for source address specifier.
enable KAME scopeid hack.
cleanups in node information query.
(sync with latest KAME)
 1.4 12-Jul-1999  itojun branches: 1.4.4;
do not modify BINGRP as there's no reason for.

From: tsubai@netbsd.org
 1.3 02-Jul-1999  thorpej -D... belongs in CPPFLAGS
 1.2 01-Jul-1999  itojun enable -DIPSEC.
 1.1 01-Jul-1999  itojun ping for IPv6. try
ping6 ::1
on you node.
 1.4.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5.4.1 18-Oct-2000  tv Pullup by patch (sync with HEAD) [itojun]:
Format string cleanups by Bill Sommerfeld.
 1.34 07-Jun-2021  dholland In ping6, there's no blank space in the ping packets by default.

- document that if you use -p to specify a fill pattern you need to
make the packets bigger with -s;

- warn if -p is used and there's not at least one byte of fill space.

PR 56057
 1.33 23-Apr-2018  maxv Remove the "-R" option. It uses IPV6_REACHCONF, but we've never had
this.
 1.32 23-Apr-2018  wiz Sort options. Sort option descriptions. Remove Tn.
Sync usage (more) with man page.
 1.31 23-Apr-2018  maxv Remove the "hops" parameter, it uses RH0, which is deprecated by RFC5095,
and doesn't work on modern networks anymore.
 1.30 15-May-2015  kefren branches: 1.30.14;
Add options -X for deadline and -x for reply maxwait (flag names matching
FreeBSD). Unline FreeBSD, currently -x doesn't count late packets to statistics.
After discussion with, and help from ozaki-r@
Should fix PR/49896
 1.29 24-Apr-2015  christos Add the once -o option like ping
 1.28 08-Apr-2012  wiz Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.27 18-May-2006  rpaulo branches: 1.27.44;
There are no broadcast addresses in IPv6, so, kill a leftover from the
ping(8) man page.
 1.26 05-May-2006  rpaulo Add support for RFC 3542 Adv. Socket API for IPv6 (which obsoletes 2292).
* RFC 3542 isn't binary compatible with RFC 2292.
* RFC 2292 support is on by default but can be disabled.
* update ping6, telnet and traceroute6 to the new API.

From the KAME project (www.kame.net).
Reviewed by core.
 1.25 07-Sep-2003  wiz Consistently use 'RFC 1234' instead of 'RFC1234' or 'RFC-1234'.
From jmc@openbsd.
 1.24 15-Mar-2003  wiz IPsec, not ipsec. From Igor Sobrado in PR 20722.
 1.23 21-Dec-2002  wiz address has two ds, not three; from Adrian Mrva.
 1.22 26-May-2002  itojun KNF. remove unused variable "signo". from deraadt
 1.21 26-May-2002  itojun Xr ping6 8 -> Nm
 1.20 26-May-2002  wiz Sort sections and a grammar fix.
 1.19 26-May-2002  itojun sync with kame.
- use bind(2) to select source.
- KNF.
- -g option to specify intermediate gateway.
 1.18 16-Nov-2001  wiz Add space before ..., lose a .Pp.
 1.17 05-Jul-2001  itojun clarify -a. sync with kame
 1.16 22-Jun-2001  itojun sync with latest kame.
- sync usage/manpage with reality.
- stop pinging on "-f -c N".
 1.15 03-Apr-2001  jhawk Xr icmp(6), inet(6), ip(6)
 1.14 19-Mar-2001  itojun examples. suggested by deraadt. sync with kame
 1.13 12-Mar-2001  itojun -Q is not there. some comsetic sync with kame. NetBSD PR 12384.
 1.12 11-Nov-2000  itojun improve spec conformance of node information query (07).
sync with kame.
 1.11 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.10 04-Sep-2000  kleink For commands and utilities, use EXIT STATUS rather than RETURN VALUES as
appropriate (and documented in mdoc(7)).
 1.9 09-Aug-2000  itojun DNS compression support.
be more picky about DNS label validation.
(sync with kame)
 1.8 12-Jun-2000  itojun branches: 1.8.2;
better conformance to draft-ietf-ipngwg-icmp-name-lookups-05.
the old code was chimera of 03 and 05 draft.

-n by default, since IPv6 reverse lookup takes too much time.
use -H to enable reverse name lookup.
 1.7 18-May-2000  itojun branches: 1.7.2;
remove incorrect mention to sysexits.h. this closes PR 9707.
 1.6 28-Feb-2000  itojun support ping6 -a c
(request IPv4 mapped/compatible addrs from
draft-ietf-ipngwg-icmp-name-lookups-05.txt)
 1.5 31-Jan-2000  itojun sync with latest libipsec and kernel.
 1.4 15-Dec-1999  itojun add reference to RFC, and some more DESCRIPTION.
sync with latest KAME document.
 1.3 13-Dec-1999  itojun provide -S for source address specifier.
enable KAME scopeid hack.
cleanups in node information query.
(sync with latest KAME)
 1.2 04-Jul-1999  itojun branches: 1.2.4;
add NetBSD RCS ID.
 1.1 01-Jul-1999  itojun ping for IPv6. try
ping6 ::1
on you node.
 1.2.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.7.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.8.2.1 11-Mar-2001  he Pull up revisions 1.9-1.12 (requested by itojun):
Correct buffer management. Fix handling of short packets. More
robust signal handling. Print icmp6 name lookup packets better.
This syncs with current head of trunk.
 1.27.44.1 17-Apr-2012  yamt sync with head
 1.30.14.1 02-May-2018  pgoyette Synch with HEAD
 1.108 11-Jul-2025  andvar Fix various typos, mainly in comments and log/error messages.
 1.107 08-Apr-2022  andvar branches: 1.107.4;
fix various typos, mainly in comments, but also log messages, docs, game text.
 1.106 11-Jun-2021  rillig ping, ping6: fix comment about ID field

Since ping.c 1.76 and ping6.c 1.58 from 2004-04-22, the ID field
contains random bits instead of a process ID.
 1.105 07-Jun-2021  dholland In ping6, there's no blank space in the ping packets by default.

- document that if you use -p to specify a fill pattern you need to
make the packets bigger with -s;

- warn if -p is used and there's not at least one byte of fill space.

PR 56057
 1.104 23-May-2021  thorpej Make sure the output packet buffer and the control message buffer
are aligned.

Fixes bin/56198.
 1.103 24-Apr-2018  maxv branches: 1.103.8;
Add code 3 of paramprob, part of RFC7112: "IPv6 First Fragment has
incomplete IPv6 Header Chain". Handle this code in ping6.
 1.102 24-Apr-2018  maxv Remove annoying (void) casts.
 1.101 23-Apr-2018  maxv Remove double include and unused macros.
 1.100 23-Apr-2018  maxv Remove the "-R" option. It uses IPV6_REACHCONF, but we've never had
this.
 1.99 23-Apr-2018  maxv Fix usage(), A/E don't exist.
 1.98 23-Apr-2018  maxv Simplify: remove #ifdefs for constants that are always defined, and
remove their #else's (some of which can't compile, since they use values
that since got removed).
 1.97 23-Apr-2018  maxv Remove dead/broken code, we want to favor RFC3542 over RFC2292. No
functional change. traceroute6 and rtadvd did the same.
 1.96 23-Apr-2018  wiz Sort options. Sort option descriptions. Remove Tn.
Sync usage (more) with man page.
 1.95 23-Apr-2018  maxv Remove the "hops" parameter, it uses RH0, which is deprecated by RFC5095,
and doesn't work on modern networks anymore.
 1.94 15-Apr-2018  maxv typo in comment
 1.93 18-Dec-2016  dholland branches: 1.93.12;
Merge the PR 36997 fixes into ping6. It already didn't accept too
small or wildly too large intervals, but it did allow intervals that
failed at poll(). Since that's signed integer overflow and thus UB,
better not to.
 1.92 29-Feb-2016  riastradh branches: 1.92.2;
#ifdef forward declaration of setpolicy like definition.
 1.91 04-Nov-2015  ozaki-r Fix rump.ping6 -c N (N > 1) doesn't work

2nd packet and subsequent packets are sent based on SIGALRM and
it depends on poll(2) returns with EINTR by the signal. However,
currently poll is rump-ified while signals aren't so the signal
doesn't wake up poll and ping6 doesn't work expectedly.

Rump-ifying signals is unsure (nobody does it for now) and the
combination use of signals and poll makes the logic a bit complex.
So let's fix the defect by stopping using signals for packet
transmissions. The new logic is derived from ping(8).

Bonus: ping6 -i 0.01 works as we expect now while the original
didn't work enough fast.
 1.90 04-Nov-2015  ozaki-r Fix exit status when -c and -X is used

It exited with status 0 when at least one packet was received
and timed out. However, when we specify -c N (while N > 0),
we expect that it fails if it times out before all sent requests
are replied.
 1.89 04-Nov-2015  knakahara rump.ping6 supports "-S" option.
 1.88 06-Aug-2015  ozaki-r Introduce rump.ping6

We use ping6 frequently in ATF tests so let's have rump-ified one.
 1.87 15-May-2015  kefren Add options -X for deadline and -x for reply maxwait (flag names matching
FreeBSD). Unline FreeBSD, currently -x doesn't count late packets to statistics.
After discussion with, and help from ozaki-r@
Should fix PR/49896
 1.86 24-Apr-2015  christos Add the once -o option like ping
 1.85 17-Sep-2014  ozaki-r Remove out-of-date comments
 1.84 16-Sep-2014  christos PR/49206: ping6 dies with SIGINT even when it just fails to ping
When reusing the same handler for SIGALRM, make don't pretend you
got SIGINT.
 1.83 22-Aug-2014  matt Rework to be avoid a conditional assignment which results in:
sbin/ping6/ping6.c:1879:8: error: 'cbit.skip' may be used uninitialized in this function [-Werror=maybe-uninitialized]
cur += ntohs(cbit.skip) * 32;
 1.82 19-Oct-2013  christos branches: 1.82.4;
avoit type punning
 1.81 10-Sep-2012  msaitoh branches: 1.81.2;
Accept "-s 0"
 1.80 04-Jan-2012  drochner branches: 1.80.2;
include <netipsec/ipsec.h> rather than <netinet6/ipsec.h> from userland
where possible, for consistency and compatibility to FreeBSD
(exception: KAME specific statistics gathering in netstat(1) and systat(1))
 1.79 04-Jan-2012  drochner -consistently use "char *" for the compiled policy buffer in the
ipsec_*_policy() functions, as it was documented and used by clients
-remove "ipsec_policy_t" which was undocumented and only present
in the KAME version of the ipsec.h header
-misc cleanup of historical artefacts, and to remove unnecessary
differences between KAME ans FAST_IPSEC
 1.78 16-Sep-2011  plunky branches: 1.78.2;
NULL does not need a cast, here
 1.77 31-Aug-2011  christos put back the byte swapping code, and remove the double byte swapping.
 1.76 31-Aug-2011  riz Remove erroneous seq=ntohs(seq) introduced in rev. 1.74, which caused
icmp_seq numbers to increment by 256 instead of 1 on LE platforms.
 1.75 27-Aug-2011  joerg static + __dead + G/C pathmtu
 1.74 14-Aug-2011  christos fix gcc warnings and eliminate duplicate code.
 1.73 20-Sep-2010  ahoka Avoid NaN when calculating std-dev, which fixes a crash on VAX.
 1.72 11-Apr-2009  lukem fix sign-compare issues
 1.71 13-Oct-2008  dholland branches: 1.71.4;
Fix reversed test in connection with combining -i and -l. If some
packets have already sent because of the preload count handling, we
shouldn't start off by sending another one right away. The reversed
test causes ping6 to wait one interval before sending anything at all
if you don't use -l. PR bin/39732.
 1.70 23-Sep-2006  elad branches: 1.70.2; 1.70.18;
PR/30226: Nino Dehne: ping6(8) and ping(8) are inconsistent in the output
of round-trip times.

okay rpaulo@
 1.69 18-May-2006  rpaulo Replace the way we calculate the standard deviation with the unbiased form
for non-related samples. There are several websites that explain why we
should use this form instead of the normal formula to compute the std. dev.
(Wikipedia is one of them).
Also, ping(8) (where this "new" formula came from) already does it this way
so, I'm trying to score some extra points by making both utilities behave
the same way.

Thanks to wrtstuden@ for the initial clarification.
 1.68 07-May-2006  rpaulo Remove support support for RFC 2292.
 1.67 05-May-2006  rpaulo len should be socklen_t, not size_t. Spotted by
Juergen Hannken-Illjes <hannken@eis.cs.tu-bs.de>.
 1.66 05-May-2006  rpaulo Add support for RFC 3542 Adv. Socket API for IPv6 (which obsoletes 2292).
* RFC 3542 isn't binary compatible with RFC 2292.
* RFC 2292 support is on by default but can be disabled.
* update ping6, telnet and traceroute6 to the new API.

From the KAME project (www.kame.net).
Reviewed by core.
 1.65 17-Mar-2006  elad Fix an off-by-one found by Coverity, CID 1456.

I haven't looked, but I suggest security-officer@ looks into it to see if
this may be exploited passively?
 1.64 07-Jun-2005  he Add an initialization to appease -Wuninitialized.
Marked with XXXGCC for sun2 (found while building for it).

Reviewed by lukem.
 1.63 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.62 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.61 29-Oct-2004  dsl Add (unsigned char) cast to ctype function
 1.60 09-Jun-2004  itojun correct mistake in usage(). Chris Pinnock
 1.59 13-May-2004  kleink There's no point in bringing PRNG output to network byteorder prior to
transmission.
 1.58 22-Apr-2004  itojun do not disclose endian. henning@openbsd
 1.57 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.56 25-Jul-2003  itojun fix packet loss rate computation
 1.55 06-Jun-2003  cjep Fix typo. Noted by Sean Boudreau on tech-net.
 1.54 27-Mar-2003  perry do proper rounded packet loss calculations.
From Robert Elz in PR #20885
XXX This should be sent back to KAME
 1.53 05-Dec-2002  itojun correct the use of sizeof() on memset(). sync w/kame
 1.52 16-Nov-2002  itojun use strlcpy. sync w/kame
 1.51 25-Oct-2002  itojun be more picky about numeric arg parsing. sync w/kame
 1.50 23-Sep-2002  itojun reduce diff w/ kame
 1.49 21-Sep-2002  mycroft Touch up error/warning messages.
 1.48 21-Sep-2002  mycroft select() -> poll()
 1.47 08-Sep-2002  itojun ansi pedantic. sync w/kame
 1.46 31-May-2002  itojun clarify comment when nreceived > ntransmitted. from deraadt
 1.45 30-May-2002  itojun typo, from openbsd
 1.44 30-May-2002  thorpej Fix Missing %s in format string.
 1.43 26-May-2002  itojun KNF. remove unused variable "signo". from deraadt
 1.42 26-May-2002  itojun s/IPSec/IPsec/
 1.41 26-May-2002  itojun sync with kame.
- use bind(2) to select source.
- KNF.
- -g option to specify intermediate gateway.
 1.40 11-Mar-2002  itojun branches: 1.40.2;
no \n to warnx(3). From: Mike Pechkin <mpech@prosoft.org.lv>
 1.39 09-Jan-2002  darrenr should be using htons() to convert from a host byte order into a network
byte order, not ntohs().
 1.38 02-Nov-2001  lukem fix -Wshadow warning
 1.37 19-Aug-2001  itojun use bind(2) to support -S. snprintf return value audit from deraadt
 1.36 22-Jun-2001  itojun sync with latest kame.
- sync usage/manpage with reality.
- stop pinging on "-f -c N".
 1.35 09-May-2001  itojun correct -n handling.
 1.34 09-May-2001  itojun fix signal handling on ping6 -f <nonexisting peer>. from hash@iij.ad.jp.
sync with kame
 1.33 07-May-2001  kleink getopt(3): EOF -> -1.
 1.32 04-Feb-2001  itojun correct recvmsg() validation.
 1.31 26-Jan-2001  itojun more simpler signal handling. be more friendly with 4.3BSD-ish socket API
(linux/USAGI folks are using the code). sync with kame.
 1.30 12-Jan-2001  itojun avoid signal handler race. help from deraadt
 1.29 12-Jan-2001  itojun correct use of howmany() for fd_set. commented by deraadt
 1.28 31-Dec-2000  itojun indent and pedant. from deraadt. sync with kame
 1.27 22-Dec-2000  itojun call seteuid(getuid) too
 1.26 22-Dec-2000  itojun revoke root privilege earlierst possible.
 1.25 02-Dec-2000  itojun sync with latest kame.
- validate strdup() error on argument parsing.
- use strlcat on complex string manipulation.
 1.24 11-Nov-2000  itojun improve spec conformance of node information query (07).
sync with kame.
 1.23 08-Nov-2000  itojun - fix -s with small number (like < 8). kame 1.97 -> 1.99
- add fflush. kame 1.96 -> 1.97
- alpha friendly (printf format - %ld and others) kame 1.93 -> 1.94
sync with kame
 1.22 12-Oct-2000  itojun do not segv on too many args. sync with kame
 1.21 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.20 08-Oct-2000  itojun fix truncated response handling; sync with kame
 1.19 07-Oct-2000  itojun repair fd_set size attack. from deraadt.
some of cleanups from kame (inet_ntop error check, unnecessary headers,
stddev computation like ping(8)).
$NetBSD$.
 1.18 14-Aug-2000  itojun - bugfix: truncated FQDN printing
- allow < 1 second interval on -i (root only). from openbsd
 1.17 09-Aug-2000  itojun DNS compression support.
be more picky about DNS label validation.
(sync with kame)
 1.16 07-Jul-2000  itojun warnx?/errx? audit. don't pass variable/function return value alone.
use with "%s". from openbsd.
 1.15 12-Jun-2000  itojun branches: 1.15.2;
better conformance to draft-ietf-ipngwg-icmp-name-lookups-05.
the old code was chimera of 03 and 05 draft.

-n by default, since IPv6 reverse lookup takes too much time.
use -H to enable reverse name lookup.
 1.14 08-Jun-2000  itojun make sure to clear ni_flags field on -w.
 1.13 28-Feb-2000  itojun branches: 1.13.2;
support ping6 -a c
(request IPv4 mapped/compatible addrs from
draft-ietf-ipngwg-icmp-name-lookups-05.txt)
 1.12 16-Feb-2000  itojun use getnameinfo(), instead inet_ntop(), as much as possible.
(sync with latest kame)
 1.11 31-Jan-2000  itojun sync with latest libipsec and kernel.
 1.10 22-Jan-2000  tron Remove bogus declarations of "errno", "optind" and "optarg".
 1.9 13-Dec-1999  itojun provide -S for source address specifier.
enable KAME scopeid hack.
cleanups in node information query.
(sync with latest KAME)
 1.8 05-Dec-1999  jdolecek usage(): wrap lines so that they don't exceed 80 characters
 1.7 03-Dec-1999  itojun rcsid police
 1.6 04-Jul-1999  itojun branches: 1.6.4;
add NetBSD RCS ID.
 1.5 04-Jul-1999  itojun be friendly with non-IPsec kernel.
don't exit even if ipsec policy config fails.
 1.4 02-Jul-1999  itojun stop using __RCSID from UCB comment.
Hope this fixes PR 7892.
 1.3 02-Jul-1999  thorpej Fix some printf format problems.
 1.2 01-Jul-1999  thorpej Fix LP64 printf format problem.
 1.1 01-Jul-1999  itojun ping for IPv6. try
ping6 ::1
on you node.
 1.6.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.15.2.7 15-Dec-2002  he Pull up revision 1.53 (requested by itojun):
Correct the use of sizeof() on memset().
 1.15.2.6 09-May-2001  he Pull up revisions 1.33-1.35 (requested by he and itojun):
Use -1 instead of EOF with getopt(3).
Correct signal handling on ping6 -f <nonexisting peer>.
 1.15.2.5 11-Mar-2001  he Pull up revisions 1.23-1.24,1.26-1.32 (via patch, requested by itojun):
Correct buffer management. Fix handling of short packets. More
robust signal handling. Print icmp6 name lookup packets better.
This syncs up to the current head of the trunk.
 1.15.2.4 15-Dec-2000  he Pull up revision 1.25 (requested by itojun):
Validate strdup() error on argument parsing. Also, use strlcat()
on complex string manipulation.
 1.15.2.3 18-Oct-2000  tv Pullup by patch (sync with HEAD) [itojun]:
Format string cleanups by Bill Sommerfeld.
 1.15.2.2 16-Oct-2000  tv Pullup 1.22 (with -Wunused fix) [itojun]:
do not segv on too many args. sync with kame
 1.15.2.1 27-Jul-2000  itojun pullup (approved by releng-1-5)
printf-like format pedant. do not pass string variable alone. use "%s".
from openbsd.

/cvsroot/basesrc/sbin/swapctl/swapctl.c 1.14 -> 1.15
/cvsroot/basesrc/sbin/ping6/ping6.c 1.15 -> 1.16
/cvsroot/basesrc/sbin/disklabel/disklabel.c 1.84 -> 1.85
/cvsroot/basesrc/sbin/ccdconfig/ccdconfig.c 1.30 -> 1.31
 1.40.2.1 12-Dec-2002  he Pull up revision 1.53 (requested by itojun in ticket #1026):
Correct the use of sizeof() in memset().
 1.70.18.1 17-Jan-2009  mjf Sync with HEAD.
 1.70.2.1 31-Oct-2008  snj Pull up following revision(s) (requested by dholland in ticket #1214):
sbin/ping6/ping6.c: revision 1.71
Fix reversed test in connection with combining -i and -l. If some
packets have already sent because of the preload count handling, we
shouldn't start off by sending another one right away. The reversed
test causes ping6 to wait one interval before sending anything at all
if you don't use -l. PR bin/39732.
 1.71.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.78.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.78.2.2 30-Oct-2012  yamt sync with head
 1.78.2.1 17-Apr-2012  yamt sync with head
 1.80.2.1 22-Oct-2012  riz Pull up following revision(s) (requested by msaitoh in ticket #614):
sbin/ping6/ping6.c: revision 1.81
Accept "-s 0"
 1.81.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.82.4.1 04-Feb-2015  martin Pull up following revision(s) (requested by chs in ticket #493):
sbin/ping6/ping6.c: revision 1.83
Rework to avoid a conditional assignment which results in a
"maybe-uninitialized" warning
 1.92.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.93.12.2 02-May-2018  pgoyette Synch with HEAD
 1.93.12.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.103.8.1 31-May-2021  cjep sync with head
 1.107.4.1 02-Aug-2025  perseant Sync with HEAD
 1.2 04-Nov-2015  knakahara rump.ping6 supports "-S" option.
 1.1 06-Aug-2015  ozaki-r Introduce rump.ping6

We use ping6 frequently in ATF tests so let's have rump-ified one.
 1.2 04-Nov-2015  knakahara rump.ping6 supports "-S" option.
 1.1 06-Aug-2015  ozaki-r Introduce rump.ping6

We use ping6 frequently in ATF tests so let's have rump-ified one.
 1.2 04-Nov-2015  knakahara rump.ping6 supports "-S" option.
 1.1 06-Aug-2015  ozaki-r Introduce rump.ping6

We use ping6 frequently in ATF tests so let's have rump-ified one.
 1.6 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.5 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.4 23-Sep-2018  maxv Remove the userland part of ISDN. The kernel part is untouched for now.
ipppctl was actually an exact copy of pppoectl; there is no functional
change in pppoectl in this commit.
 1.3 28-May-2007  tls branches: 1.3.76; 1.3.78;
Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.2 16-Mar-2002  martin Rename ISDN devices, per discussion on tech-kern. The network devices
become ippp (ISDN ppp) and irip (ISDN raw IP). The character device now
are called: /dev/isdn (isdnd <-> kernel communication), /dev/isdnctl (dialing
and other control), /dev/isdntrc* (tracing), /dev/isdnbchan* (raw B channel
access, i.e. for user land PPP) and /dev/isdntel* (telephone devices, i.e.
for answering machines).
 1.1 10-Dec-2001  martin Move /usr/sbin/pppoectl to /sbin/pppoectl, so we can call it from
ifconfig.pppoe* files.

Rename the source directory and files to match the primary purpose
of this utility - probably noone is using this for ISDN now anymore,
as isdnd has simpler ways to acomplish the same.
 1.3.78.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.78.1 10-Jun-2019  christos Sync with HEAD
 1.3.76.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.32 25-Sep-2018  wiz Fix wrong macro, use An.
 1.31 23-Sep-2018  maxv Remove the userland part of ISDN. The kernel part is untouched for now.
ipppctl was actually an exact copy of pppoectl; there is no functional
change in pppoectl in this commit.
 1.30 12-Sep-2016  sevan branches: 1.30.12; 1.30.14;
pppoectl first appeared in NetBSD 1.6.
Bump date.
 1.29 12-Oct-2011  christos fix the date.
 1.28 12-Oct-2011  martin Two small fixes from David H. Gutteridge in PR bin/45454.
 1.27 31-Mar-2010  joerg Kill stray t.
 1.26 30-Mar-2010  joerg Assume o umlaut is transliterated by nroff as needed.
\\ -> \e
 1.25 09-Mar-2009  joerg Fix preamble to match order set out by mdoc(7). Discussed with wiz.
 1.24 19-Feb-2005  christos branches: 1.24.36;
PR/29457: Joachim Kuebart: pppoectl's config file does not allow # in passwords
Fixed, by passing FPARSELN_UNESCALL in parsing.
 1.23 02-Oct-2003  wiz Bump date for previous.
 1.22 02-Oct-2003  itojun use netmask of /32. as discusssed on tech-userlevel
 1.21 06-Sep-2003  wiz Punctuation nits.
 1.20 06-Sep-2003  martin Make LCP keepalive behaviour configurable.
 1.19 22-Mar-2003  mrg bump .Dt [from wiz]
 1.18 22-Mar-2003  mrg add a "-f configfile" option. the config file contains individual lines of
parameter=value pairs normally passed on the command line (# and \
continuation also works, yay fparseln), one per line. now you don't have
to run a program with a password on the command line.
 1.17 19-Dec-2002  wiz Drop trailing whitespace.
 1.16 19-Dec-2002  lukem It's ipppctl not ipppcontrol ...
Also add synopsis for ipppctl.
 1.15 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.14 01-Sep-2002  wiz Grammar improvement.
 1.13 01-Sep-2002  martin Add a "clear-auth-failure" command to reset the authentication failure
count without changing any (local) authentication settings.

Fixes kern/18071 ( without any kernel change ;-) )
 1.12 16-Aug-2002  itojun style (tab around $NetBSD$)
 1.11 14-Apr-2002  martin Fix copyright notice, sprinkle some $NetBSD$.
 1.10 16-Mar-2002  martin Rename ISDN devices, per discussion on tech-kern. The network devices
become ippp (ISDN ppp) and irip (ISDN raw IP). The character device now
are called: /dev/isdn (isdnd <-> kernel communication), /dev/isdnctl (dialing
and other control), /dev/isdntrc* (tracing), /dev/isdnbchan* (raw B channel
access, i.e. for user land PPP) and /dev/isdntel* (telephone devices, i.e.
for answering machines).
 1.9 04-Mar-2002  wiz Typo fix.
 1.8 04-Mar-2002  wiz Whitespace nit.
 1.7 02-Mar-2002  martin Add a "query-dns" parameter to tell the interface we would like to get
DNS settings from the peer and a "-n" option to retrieve the results
after the PPP connection is established.
 1.6 09-Jan-2002  martin Xref pppoe(4) and ifwatchd(8).
 1.5 07-Jan-2002  martin Display the authentication failure count (if non zero) and make the
limit settable.
 1.4 07-Jan-2002  wiz Fix two typos and a whitespace nit.
 1.3 06-Jan-2002  martin Make idle timeout settable and display it.
Bring the man page closer to reality.
 1.2 10-Dec-2001  wiz Lots of grammar fixes and other slight improvements.
 1.1 10-Dec-2001  martin Move /usr/sbin/pppoectl to /sbin/pppoectl, so we can call it from
ifconfig.pppoe* files.

Rename the source directory and files to match the primary purpose
of this utility - probably noone is using this for ISDN now anymore,
as isdnd has simpler ways to acomplish the same.
 1.24.36.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.30.14.1 10-Jun-2019  christos Sync with HEAD
 1.30.12.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.31 07-Aug-2022  andvar fix various typos in comments, documentation and messages.
mainly s/paramater/parameter/ and s/reduntant/redundant/.
 1.30 14-May-2021  yamaguchi Added a keyword to change keepalive interval
 1.29 11-May-2021  yamaguchi Make authproto not change when "authproto" is not in command option
 1.28 11-May-2021  yamaguchi Added keywords that are ipcp, noipcp, ipv6cp, noipv6cp
for configuring NCP
 1.27 23-Apr-2021  yamaguchi branches: 1.27.2;
Add a new option to enable SPPP_AUTHFLAG_PASSIVEAUTHPROTO flag
 1.26 25-Nov-2020  yamaguchi add -dd option for reference of the parameter about control protocols

reviewed by knakahara@n.o.
 1.25 23-Jan-2016  christos don't need mbuf.h!
 1.24 28-Aug-2011  mbalmer Remove duplicate static.
 1.23 27-Aug-2011  joerg static + __dead
 1.22 01-Jul-2011  joerg Fix memset usage.
 1.21 17-Mar-2006  rumble Check for allocation failures in malloc, calloc, realloc, asprintf, and
vasprintf and try to handle them.
 1.20 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.19 10-May-2005  martin Partly back out previous - do not free the linebuffer while still having
pointers into parts of it. Add a comment explaining why we prefer to
leak memory ;-)
Fixes PR bin/30174.
 1.18 19-Feb-2005  christos branches: 1.18.2;
Skip empty lines, and free the line buffer so that we don't leak.
 1.17 19-Feb-2005  christos PR/29457: Joachim Kuebart: pppoectl's config file does not allow # in passwords
Fixed, by passing FPARSELN_UNESCALL in parsing.
 1.16 01-Sep-2004  jdolecek fix typo
 1.15 13-Feb-2004  wiz Spell length with h after t. Inspired by a commit by brad@openbsd.
 1.14 06-Sep-2003  martin Make LCP keepalive behaviour configurable.
 1.13 12-Jul-2003  itojun use bounded string ops
 1.12 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.11 22-Mar-2003  mrg add a "-f configfile" option. the config file contains individual lines of
parameter=value pairs normally passed on the command line (# and \
continuation also works, yay fparseln), one per line. now you don't have
to run a program with a password on the command line.
 1.10 01-Sep-2002  martin Fix usage(). Noticed by itojun.
 1.9 01-Sep-2002  martin Add a "clear-auth-failure" command to reset the authentication failure
count without changing any (local) authentication settings.

Fixes kern/18071 ( without any kernel change ;-) )
 1.8 16-Aug-2002  itojun style (tab around $NetBSD$)
 1.7 21-Jun-2002  itojun correct usage (-n)
 1.6 02-Mar-2002  martin branches: 1.6.2;
Add a "query-dns" parameter to tell the interface we would like to get
DNS settings from the peer and a "-n" option to retrieve the results
after the PPP connection is established.
 1.5 07-Jan-2002  martin Improve usage message.
 1.4 07-Jan-2002  martin Display the authentication failure count (if non zero) and make the
limit settable.
 1.3 06-Jan-2002  martin Make idle timeout settable and display it.
Bring the man page closer to reality.
 1.2 04-Jan-2002  martin Adapt to new if_sppp.h ioctls.
Add -d option to dump PPPoE session state. XXX need to document this.
 1.1 10-Dec-2001  martin Move /usr/sbin/pppoectl to /sbin/pppoectl, so we can call it from
ifconfig.pppoe* files.

Rename the source directory and files to match the primary purpose
of this utility - probably noone is using this for ISDN now anymore,
as isdnd has simpler ways to acomplish the same.
 1.6.2.1 21-Jun-2002  lukem Pull up revision 1.7 (requested by itojun in ticket #340):
correct usage (-n)
 1.18.2.1 11-May-2005  tron Pull up revision 1.19 (requested by martin in ticket #282):
Partly back out previous - do not free the linebuffer while still having
pointers into parts of it. Add a comment explaining why we prefer to
leak memory ;-)
Fixes PR bin/30174.
 1.27.2.1 31-May-2021  cjep sync with head
 1.18 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.17 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.16 15-Dec-2010  pooka branches: 1.16.46;
Use RUMPPRG.

ok Greg Oster
 1.15 08-Nov-2010  pooka Update RUMP_ACTION to use rumpclient.

The server must of course have some disks configured. Let's say
we have this simple server with disks as a few sparse host files:

main()
{
rump_init();
rump_pub_etfs_register("/disk1", "./disk1.img", RUMP_ETFS_BLK);
rump_pub_etfs_register("/disk2", "./disk2.img", RUMP_ETFS_BLK);
rump_pub_etfs_register("/disk3", "./disk3.img", RUMP_ETFS_BLK);
rump_pub_etfs_register("/disk4", "./disk4.img", RUMP_ETFS_BLK);
pause();
}

And we run the server:

mainbus0 (root)
Kernelized RAIDframe activated
/disk1: hostpath ./disk1.img (97 GB)
/disk2: hostpath ./disk2.img (97 GB)
/disk3: hostpath ./disk3.img (97 GB)
/disk4: hostpath ./disk4.img (97 GB)

We can then configure the raid against the server:

> ./raidctl -c theraid.conf raid0

And lo, we have evidence of a level1 raid in the server dmesg:

raid0: RAID Level 1
raid0: Components: /disk1 /disk2 /disk3 /disk4
raid0: Total Sectors: 409599744 (199999 MB)

yea, i initialized it already in a previous run:

> ./raidctl -S raid0
Reconstruction is 100% complete.
Parity Re-write is 100% complete.
Copyback is 100% complete.
 1.14 11-Oct-2009  pooka close rump kernel file descriptors properly
 1.13 11-Oct-2009  pooka Support RUMP_ACTION, i.e. compile-time switch to make this execute
rump syscalls to configure raidframe in a rump kernel.
 1.12 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.11 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.10 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.9 04-Oct-2001  oster Remove cruft. We no longer need to look into sys/dev/raidframe to
find the needed include files.
 1.8 27-Jan-2001  oster Move parts of a RAID type mapping table from rf_layout.c to rf_configure.c.
This means we don't need to compile or link with rf_layout.c here.
 1.7 23-May-2000  thorpej Build with WARNS=2.
 1.6 07-Aug-1999  oster Move two functions from rf_strutils.c into rf_configure.c, removing
the need for rf_strutils.c.
 1.5 26-Mar-1999  oster Move COPTS to CPPFLAGS. Nuke some no-longer needed compile options.
 1.4 04-Feb-1999  oster Add missing NetBSD RCS ID's! Thanks to SAITOH Masanobu (msaitoh@netbsd.org)
for pointing this out.
 1.3 18-Jan-1999  lukem no need for CWARNFLAGS; ../Makefile.inc sets WARNS=1
 1.2 17-Jan-1999  matt Allow CFLAGS to be set in /etc/mk.conf
 1.1 13-Nov-1998  oster RAIDframe, version 1.1, from the Parallel Data Laboratory at
Carnegie Mellon University. Full RAID implementation, including
levels 0, 1, 4, 5, 6, parity logging, and a few other goodies.
Ported to NetBSD by Greg Oster.

raidctl is our userland configuration tool for RAIDframe.
 1.16.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 09-Feb-2011  pooka Exterminate a bug I created in 2009.
 1.1 15-Dec-2010  pooka branches: 1.1.2;
Use RUMPPRG.

ok Greg Oster
 1.1.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.82 25-Sep-2023  oster We no longer need the deprecated copyback functionality now that
incorporating a used spare is automatic.

Copyback has always been an issue, as to do a copyback all IO to
the array had to be suspended, and so was very, very unlikely to
have been used in anything resembling a production system.
 1.81 21-Sep-2023  oster Implement command-line configuration of simple RAID sets with raidctl
based on the usage pattern:

raidctl <device> create <level> <component1> <component2> ...

For example,

raidctl raid0 create mirror absent /dev/wd1e

will create a RAID level 1 (mirror) set with an absent first component
and /dev/wd1e as the second component. The resulting RAID device will
be marked as auto-configurable, will have a serial number set (based
on the current time), and parity will be initialized. Reasonable
performance values are automatically used by default for other parameters
normally specified in the configuration file.

Also: Only print out Autoconfig status if being verbose.
 1.80 17-Sep-2023  oster Implement hot removal of spares and components. From manu@.

Implement a long desired feature of automatically incorporating
a used spare into the array after a reconstruct.

Given the configuration:
Components:
/dev/wd0e: failed
/dev/wd1e: optimal
/dev/wd2e: optimal
Spares:
/dev/wd3e: spare

Running 'raidctl -F /dev/wd0e raid0' will now result in the
following configuration after a successful rebuild:
Components:
/dev/wd3e: optimal
/dev/wd1e: optimal
/dev/wd2e: optimal
No spares.

Thanks to manu@ for the development of the initial set of changes
which allowed the changes to automatically incorporate a used spare
to come to fruition. Thanks also to manu@ for useful discussions
about and additional testing of these changes.
 1.79 14-Jun-2022  kre branches: 1.79.2;
Implement "raidctl -t config-file"

This does the same config file parse that -c/-C do, but only
that (hence no raidframe device is needed, or accepted).

Any syntax errors in the config file will be reported, nothing
else happens.
 1.78 02-Aug-2021  oster Support on-demand re-scanning all devices to look for
autoconfig RAID sets. raidctl now supports looking
for autoconfig RAID sets with a new '-L' flag.
 1.77 27-May-2021  wiz Avoid using Pq.

In this case, the parentheses were wrong when a line was extended.
 1.76 27-May-2021  mrg move the basic history i wrote from raidctl(8) to raid(4), and
fix the x86 (thanks simonb) and sparc bootable dates, a couple
of spelling errors.
 1.75 26-May-2021  mrg update the list of platforms supporting loading kernels from raid.
expand the HISTORY section to include notable RF moments in netbsd.
bump date.
 1.74 18-Jan-2018  mrg branches: 1.74.10;
implement 32-bit compat support for raidframe.

convert several raidframe ioctls to be bitsize idempotent so that
they work the same in 32 and 64 bit worlds, allowing netbsd32 to
configure and query raid properly. remove useless 'row' in a few
places. add COMPAT_80 and put the old ioctls there.

raidframeio.h:
RAIDFRAME_TEST_ACC
- remove, unused
RAIDFRAME_GET_COMPONENT_LABEL
- convert to label not pointer to label
RAIDFRAME_CHECK_RECON_STATUS_EXT
RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT
RAIDFRAME_CHECK_COPYBACK_STATUS_EXT
- convert to progress info not pointer to info
RAIDFRAME_GET_INFO
- version entirely.
raidframevar.h:
- rf_recon_req{} has row, flags and raidPtr removed (they're
not a useful part of this interface.)
- RF_Config_s{} and RF_DeviceConfig_s{} have numRow/rows removed.
- RF_RaidDisk_s{} is re-ordered slightly to fix alignment
padding - the actual data was already OK.
- InstallSpareTable() loses row argument

rf_compat32.c has code for RF_Config_s{} in 32 bit mode, used
by RAIDFRAME_CONFIGURE and RAIDFRAME_GET_INFO32.

rf_compat80.c has code for rf_recon_req{}, RF_RaidDisk_s{} and
RF_DeviceConfig_s{} to handle RAIDFRAME_FAIL_DISK,
RAIDFRAME_GET_COMPONENT_LABEL, RAIDFRAME_CHECK_RECON_STATUS_EXT,
RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT,
RAIDFRAME_CHECK_COPYBACK_STATUS_EXT, RAIDFRAME_GET_INFO.

move several of the per-ioctl code blocks into separate functions.

add rf_recon_req_internal{} to replace old usage of global
rf_recon_req{} that had unused void * in the structure, ruining
it's 32/64 bit ABI.

add missing case for RAIDFRAME_GET_INFO50.

adjust raid tests to use the new .conf format, and add a case to
test the old method as well.

raidctl:
deal with lack of 'row' members in a couple of places.
fail request no longer takes row.
handle "START array" sections with just "numCol numSpare", ie
no "numRow" specified. for now, generate old-style configuration
but update raidctl.8 to specify the new style (keeping reference
to the old style.)

note that: RF_ComponentLabel_s::{row,num_rows} and
RF_SingleComponent_s::row are obsolete but not removed yet.
 1.73 20-Nov-2017  kardel support NAME=<wedge name> syntax for disks and spares
 1.72 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.71 06-Jan-2016  wiz branches: 1.71.8;
Use standard sort order for options.

Add -U to usage.
 1.70 06-Jan-2016  christos Access to the SET_LAST_UNIT ioctl.
 1.69 30-Jun-2015  wiz Bump date for previous. Add whitespace.
Fix some mandoc warnings.
 1.68 30-Jun-2015  sborrill Clarify that what was previously known as -A root is now -A forceroot, not
-A softroot and that -A root can still be used for historical reasons.
 1.67 03-Apr-2014  christos branches: 1.67.4;
Add the ability to "softroot" mount (i.e. mount root only when the raid
set contains the boot device), as opposed to "hardroot" (the previous
default which forces the raid to be root no matter what).
 1.66 07-Oct-2013  jdc Belatedly note root on RAIDframe support for sandpoint.
 1.65 20-Sep-2013  tron Note that NetBSD/amd64 can boot of RAID volumes.
 1.64 23-Mar-2012  njoly branches: 1.64.2;
Remove unexpected newline between Em macro and text.
 1.63 02-Aug-2011  wiz branches: 1.63.2; 1.63.4; 1.63.8; 1.63.10;
New sentence, new line.
 1.62 28-Jul-2011  buhrow Document the need for zeroing out the first 64 blocks of a replacement
component in a failed RAID set in order to avoid potentially configuring
RAId 1 sets with erroneous values taken from random extent data in the
replacement component partitions.
 1.61 27-Jan-2010  wiz + Fatal errors due to uninitialized components are ignored.
for -C. For dillo@
 1.60 27-Jan-2010  wiz Consistently use "START disks" in examples. Bump date.
 1.59 17-Nov-2009  wiz Remove trailing whitespace.
 1.58 17-Nov-2009  jld Bump date; also fix typo pointed out by snj@.
 1.57 17-Nov-2009  jld Finally commit the RAIDframe parity map Summer Of Code project.

Drastically reduces the amount of time spent rewriting parity after an
unclean shutdown by keeping better track of which regions might have had
outstanding writes. Enabled by default; can be disabled on a per-set
basis, or tuned, with the new raidctl(8) commands.

Discussed on tech-kern@ to a general air of approval; exhortations to
commit from mrg@, christos@, and others.

Thanks to Google for their sponsorship, oster@ for mentoring the
project, assorted developers for trying very hard to break it, and
probably more I'm forgetting.
 1.56 28-Aug-2008  wiz branches: 1.56.2; 1.56.8;
Drop trailing whitespace.
 1.55 26-Aug-2008  oster Bump date (before wizd).
 1.54 26-Aug-2008  oster Add description of some of the things 'raidctl -u' doesn't do.
 1.53 19-Aug-2008  oster We have the notion of an 'absent' disk, so use that in another example.
 1.52 02-May-2008  martin branches: 1.52.2;
Move TNF licenses to 2 clause form
 1.51 14-Dec-2007  explorer branches: 1.51.4; 1.51.6;
Fix a minor typo: wd0h was repeated, change second instance to wd1h as is likely intended.
 1.50 06-Aug-2007  oster branches: 1.50.2; 1.50.4; 1.50.8;
Talk a bit more about how the size of a RAID set is determined, and
of RF_PROTECTED_SECTORS. Requested by (and with comments from and
thanks to) Christoph (bad@).
 1.49 28-Feb-2005  wiz Bump date for previous.
 1.48 28-Feb-2005  oster Add a few more lines about the 'Parity status:' output of 'raidctl -s'.
This should address PR#29540.
 1.47 01-Feb-2005  wiz Give Dd the full month names as argument.
 1.46 31-Jan-2005  fredb Greg Oster just reminded me, I left out "vax".
 1.45 31-Jan-2005  fredb Sync with raid(4) regarding the architectures that support booting directly
from RAID 1, using language supplied by Anders Dinson in PR bin/29158, with
some additions by myself.
 1.44 24-May-2004  wiz Use Dq instead of quotes; bump date for previous.
 1.43 22-May-2004  oster Update docs to reflect the support for the word "absent" in the "disks"
section of RAID config files.
 1.42 16-May-2004  wiz Add commas in enumeration; bump date for previous.
 1.41 15-May-2004  dsl Add i386 to the list of systems that support booting from raid1.
RAID(4) also needs changing - if someone knows where the source is....
 1.40 11-Apr-2004  snj Bump date for last.
 1.39 11-Apr-2004  oster Swapping to RAID 5 is happy now. Remove indications to the contrary.
 1.38 29-Feb-2004  oster branches: 1.38.2;
Note in the description of hot-adding components that a component label is
not required for the component. Thanks to David Maxwell for the
documentation suggestion.
 1.37 02-Nov-2003  wiz Bump date for previous.
 1.36 02-Nov-2003  oster Add a couple little warnings about swapping to RAID 5 sets.
(it currently doesn't work.)
 1.35 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.34 16-Nov-2002  wiz Remove trailing space.
 1.33 16-Nov-2002  oster Catch up on some documentation stuff:
- add a note about adding 'swapoff=YES' to /etc/rc.conf
- add a note about not using raid0[cd] for a filesystem.
- filesystems -> file systems
 1.32 01-Oct-2002  wiz Use more markup.
 1.31 01-Oct-2002  wiz New sentence, new line. By Robert Elz with minimal fixes.
 1.30 11-Jul-2002  wiz Remove duplicate 'to'. From Ryo HAYASAKA in bin/17562.
 1.29 08-Feb-2002  ross branches: 1.29.2;
Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.28 21-Jan-2002  wiz Drop trailing whitespace.
 1.27 20-Jan-2002  oster Add a description of how to possibly recover a RAID set in the
event of a multiple disk failure.
 1.26 16-Nov-2001  wiz Don't abuse -unfilled for -literal; sort sections, sort SEE ALSO, drop
lots of unnecessary .Pps.
 1.25 16-Nov-2001  wiz Whitespace nits
 1.24 10-Jul-2001  lukem * add -G, which lists the configuration of the given raid set in the
same configuration format that -c and -C use.
this is useful if you're using autoconfig and you've misplaced the
/etc/raidXXX.conf files
* "filesystem" -> "file system", and other man page cleanups.
 1.23 05-Jun-2001  wiz Drop arguments of .Os.
 1.22 27-Oct-2000  oster - cleanup wording and add additional comments on such things as
"component1" and "raidctl -A yes"
- add a note about how to build a RAID set with a limited number of disks
(thanks to Simon Burge for suggestions)
- improve layout of 'raidctl -i' discussion (thanks to Hubert Feyrer)
- add a (small) section on Performance Tuning
 1.21 10-Aug-2000  oster Clarify a few things about parity. Add more documentation about RAID on RAID,
and root on RAID.
 1.20 05-Jul-2000  oster Add a .Sq for single quotes, instead of doing it by hand.
Fixes a formatting problem noted by Hubert Feyrer (Thanks Hubert!).
 1.19 02-Jun-2000  oster branches: 1.19.2;
Slight wording improvement on the 'raidctl -R' case.
 1.18 29-May-2000  oster Fix up some single quotes that messed up a line. (Thanks Wiz!)
 1.17 26-Feb-2000  oster branches: 1.17.2;
Update for 'options RAID_AUTOCONFIG'.
 1.16 26-Feb-2000  oster Add a few more examples, and a summary.
 1.15 25-Feb-2000  oster More updates, spelling fixes, etc.
 1.14 25-Feb-2000  oster First revamp of the docs. This is still work-in-progress. More to come
shortly.
 1.13 24-Feb-2000  oster Document the new autoconfiguration switches, and update the Usage: line.
More doc changes expected soon.
 1.12 22-Jan-2000  wiz it's -> its
 1.11 05-Jan-2000  oster - add '-v' (Verbose) option, which, most notably, provides
a spiffy lukemftp-inspired progress bar for parity re-writing,
reconstructs, copybacks, et al.

- make 'raidctl -P' wait until the parity has been updated before exiting
(it waited previously, but only because the parity re-write ioctl wouldn't
exit until the parity was successfully re-written)
 1.10 19-Nov-1999  kristerw Typos (from OpenBSD)
 1.9 10-Aug-1999  oster branches: 1.9.4;
Add two more options to raidctl:
-p check (and return) the status of the parity
-P check the status of the parity, and rebuild if necessary

Addresses PR#7494
 1.8 24-Mar-1999  mycroft Remove blank lines.
 1.7 06-Mar-1999  mycroft Fix minor formatting error.
 1.6 06-Mar-1999  mycroft Fix minor formatting error.
 1.5 02-Mar-1999  oster Update for recent changes: component labels, clean bits, adding hot
spares, and rebuilding components in-place. Re-arrange the
letters/options to make more sense (and make better use of the alphabet).
 1.4 18-Feb-1999  msaitoh fix typo
 1.3 04-Feb-1999  oster Add missing NetBSD RCS ID's! Thanks to SAITOH Masanobu (msaitoh@netbsd.org)
for pointing this out.
 1.2 10-Jan-1999  simonb Fix tpyo.
 1.1 13-Nov-1998  oster Oops. Forgot the man-page for 'raidctl' when the rest of 'raidctl' went in.
 1.9.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.17.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.2.3 30-Oct-2000  tv Pullup 1.22 [oster]:
- cleanup wording and add additional comments on such things as
"component1" and "raidctl -A yes"
- add a note about how to build a RAID set with a limited number of disks
(thanks to Simon Burge for suggestions)
- improve layout of 'raidctl -i' discussion (thanks to Hubert Feyrer)
- add a (small) section on Performance Tuning
 1.19.2.2 10-Aug-2000  oster Pullup of 1.20->1.21 (approved by thorpej)
Clarify a few things about parity. Add more documentation about RAID on RAID,
and root on RAID.
 1.19.2.1 05-Jul-2000  oster Add a .Sq for single quotes, instead of doing it by hand.
Fixes a formatting problem.

Approved by: thorpej
 1.29.2.1 09-Apr-2004  jmc Pullup patch (requested by oster in ticket #1555)

Add a couple little warnings about swapping to RAID 5 sets.
 1.38.2.2 23-May-2004  tron branches: 1.38.2.2.2;
Pull up revision 1.43 (requested by oster in ticket #378):
Update docs to reflect the support for the word "absent" in the "disks"
section of RAID config files.
 1.38.2.1 12-Apr-2004  grant Pull up revisions 1.39-1.40 (requested by oster in ticket #130):

Swapping to RAID 5 is happy now. Remove indications to the contrary.
 1.38.2.2.2.1 05-May-2005  riz Pull up revision 1.41-1.42, 1.44-1.46 (requested by fredb in ticket #1151):
Sync raidctl(8) with raid(4) regarding booting from RAID 1.
 1.50.8.2 06-Aug-2007  oster Talk a bit more about how the size of a RAID set is determined, and
of RF_PROTECTED_SECTORS. Requested by (and with comments from and
thanks to) Christoph (bad@).
 1.50.8.1 06-Aug-2007  oster file raidctl.8 was added on branch matt-mips64 on 2007-08-06 19:44:17 +0000
 1.50.4.1 27-Dec-2007  mjf Sync with HEAD.
 1.50.2.1 09-Jan-2008  matt sync with HEAD
 1.51.6.1 18-May-2008  yamt sync with head.
 1.51.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.51.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.52.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.56.8.1 21-Apr-2010  matt sync to netbsd-5
 1.56.2.2 20-Sep-2013  riz Pull up following revision(s) (requested by tron in ticket #1879):
sbin/raidctl/raidctl.8: revision 1.65
Note that NetBSD/amd64 can boot off RAID volumes.
 1.56.2.1 10-Dec-2009  snj branches: 1.56.2.1.2; 1.56.2.1.6;
Pull up following revision(s) (requested by tron in ticket #1187):
sbin/raidctl/raidctl.8: revisions 1.57-1.59 via patch
sbin/raidctl/raidctl.c: revision 1.42 via patch
sys/dev/raidframe/files.raidframe: revision 1.8 via patch
sys/dev/raidframe/rf_copyback.c: revision 1.42 via patch
sys/dev/raidframe/rf_disks.c: revision 1.72 via patch
sys/dev/raidframe/rf_driver.c: revision 1.122 via patch
sys/dev/raidframe/rf_engine.c: revision 1.40 via patch
sys/dev/raidframe/rf_kintf.h: revision 1.21 via patch
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.269 via patch
sys/dev/raidframe/rf_paritymap.c: revisions 1.1-1.3 via patch
sys/dev/raidframe/rf_paritymap.h: revision 1.1 via patch
sys/dev/raidframe/rf_parityscan.c: revision 1.33 via patch
sys/dev/raidframe/rf_parityscan.h: revision 1.8 via patch
sys/dev/raidframe/rf_raid.h: revision 1.38 via patch
sys/dev/raidframe/rf_reconstruct.c: revision 1.108 via patch
sys/dev/raidframe/rf_states.c: revision 1.44 via patch
sys/dev/raidframe/raidframeio.h: revision 1.6 via patch
sys/dev/raidframe/raidframevar.h: revision 1.13 via patch
Pull up the RAIDframe parity map Summer Of Code project.
Drastically reduces the amount of time spent rewriting parity after an
unclean shutdown by keeping better track of which regions might have had
outstanding writes. Enabled by default; can be disabled on a per-set
basis, or tuned, with the new raidctl(8) commands.
 1.56.2.1.6.1 20-Sep-2013  riz Pull up following revision(s) (requested by tron in ticket #1879):
sbin/raidctl/raidctl.8: revision 1.65
Note that NetBSD/amd64 can boot off RAID volumes.
 1.56.2.1.2.1 20-Sep-2013  riz Pull up following revision(s) (requested by tron in ticket #1879):
sbin/raidctl/raidctl.8: revision 1.65
Note that NetBSD/amd64 can boot off RAID volumes.
 1.63.10.1 20-Sep-2013  riz Pull up following revision(s) (requested by tron in ticket #948):
sbin/raidctl/raidctl.8: revision 1.65
Note that NetBSD/amd64 can boot off RAID volumes.
 1.63.8.1 20-Sep-2013  riz Pull up following revision(s) (requested by tron in ticket #948):
sbin/raidctl/raidctl.8: revision 1.65
Note that NetBSD/amd64 can boot off RAID volumes.
 1.63.4.1 20-Sep-2013  riz Pull up following revision(s) (requested by tron in ticket #948):
sbin/raidctl/raidctl.8: revision 1.65
Note that NetBSD/amd64 can boot off RAID volumes.
 1.63.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.63.2.1 17-Apr-2012  yamt sync with head
 1.64.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.67.4.2 14-Jul-2017  martin Pull up following revision(s) (requested by christos in ticket #1457):
sbin/raidctl/raidctl.c: revision 1.64
sbin/raidctl/raidctl.8: revision 1.70
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.341
sys/dev/raidframe/raidframeio.h: revision 1.7
Add a SET_LAST_UNIT ioctl.
Access to the SET_LAST_UNIT ioctl.
 1.67.4.1 05-Jul-2015  snj Pull up following revision(s) (requested by sborrill in ticket #863):
sbin/raidctl/raidctl.8: revisions 1.68, 1.69
Clarify that what was previously known as -A root is now -A forceroot, not
-A softroot and that -A root can still be used for historical reasons.
--
Bump date for previous. Add whitespace.
Fix some mandoc warnings.
 1.71.8.1 10-Sep-2018  martin Pull up following revision(s) (requested by nakayama in ticket #1019):

sbin/raidctl/rf_configure.h: revision 1.2
sbin/raidctl/rf_configure.c: revision 1.27
sbin/raidctl/rf_configure.c: revision 1.28
sbin/raidctl/rf_configure.c: revision 1.29
sbin/raidctl/raidctl.8: revision 1.73
sbin/raidctl/rf_configure.c: revision 1.30
sbin/raidctl/rf_configure.c: revision 1.31
sbin/raidctl/rf_configure.c: revision 1.32

support NAME=<wedge name> syntax for disks and spares

-

stop using magic constants
wrap long lines
use warn{,x}
make static
knf

-

White space and comment formatting. NFC.

-

With char bug[SIZE] using sizeof(bug[0]) is kind of boring, use
sizeof(bug) instead...

-

Avoid needless pointer calisthenics: &foo[0] -> foo

-

Several more cleanups:
1. Don't force use of "for" when "while" works better.
2. No need to check c != '\0' when we also check (c == ' ' || c == '\t')
3. Use the size of the buffer we're using, rather than a different one
(not really a concern, they're the same size)
4. Don't use fscanf() to read file data, use fgets() & sscanf().
5. After using a pointer as a char *, validate alignment before switching
to int * (can only fail if kernel #define gets set stupidly) Or #6...
6. Validate sparemap file name isn't too long for assigned space.
7. recognise that strlen() returns size_t - don't shove it into an int.
8. On out of mem, be more clear which allocation failed in warning msg.

ATF tests all pass. But I don't think they use sparemap files.
 1.74.10.1 31-May-2021  cjep sync with head
 1.79.2.2 28-Apr-2024  martin Pull up following revision(s) (requested by oster in ticket #675):

sbin/raidctl/raidctl.8: revision 1.81
sbin/raidctl/raidctl.c: revision 1.80

Implement command-line configuration of simple RAID sets with raidctl
based on the usage pattern:

raidctl <device> create <level> <component1> <component2> ...

For example,

raidctl raid0 create mirror absent /dev/wd1e

will create a RAID level 1 (mirror) set with an absent first component
and /dev/wd1e as the second component. The resulting RAID device will
be marked as auto-configurable, will have a serial number set (based
on the current time), and parity will be initialized. Reasonable
performance values are automatically used by default for other parameters
normally specified in the configuration file.

Also: Only print out Autoconfig status if being verbose.
 1.79.2.1 28-Apr-2024  martin Pull up following revision(s) (requested by oster in ticket #674):

sys/dev/raidframe/rf_raid.h: revision 1.52
sbin/raidctl/raidctl.8: revision 1.80
sys/dev/raidframe/rf_driver.c: revision 1.141
sys/dev/raidframe/rf_disks.c: revision 1.94
sys/dev/raidframe/rf_diskqueue.c: revision 1.64
sys/dev/raidframe/rf_diskqueue.h: revision 1.30
sys/dev/raidframe/rf_disks.h: revision 1.15
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.414
sys/dev/raidframe/rf_reconstruct.c: revision 1.129
sys/dev/raidframe/raidframeio.h: revision 1.12
sbin/raidctl/raidctl.c: revision 1.79

Implement hot removal of spares and components. From manu@.

Implement a long desired feature of automatically incorporating
a used spare into the array after a reconstruct.

Given the configuration:

Components:
/dev/wd0e: failed
/dev/wd1e: optimal
/dev/wd2e: optimal
Spares:
/dev/wd3e: spare

Running 'raidctl -F /dev/wd0e raid0' will now result in the
following configuration after a successful rebuild:

Components:
/dev/wd3e: optimal
/dev/wd1e: optimal
/dev/wd2e: optimal
No spares.

Thanks to manu@ for the development of the initial set of changes
which allowed the changes to automatically incorporate a used spare
to come to fruition. Thanks also to manu@ for useful discussions
about and additional testing of these changes.
 1.86 05-Nov-2024  rillig raidctl: fix <ctype.h> usage, remove redundant break statements
 1.85 05-Nov-2024  rillig raidctl: trim trailing whitespace
 1.84 05-Nov-2024  rillig raidctl: remove unused and undocumented option '-B'
 1.83 10-Feb-2024  andvar branches: 1.83.2;
fix various typos in comments and log messages.
 1.82 25-Sep-2023  oster We no longer need the deprecated copyback functionality now that
incorporating a used spare is automatic.

Copyback has always been an issue, as to do a copyback all IO to
the array had to be suspended, and so was very, very unlikely to
have been used in anything resembling a production system.
 1.81 21-Sep-2023  oster Remove a couple of unneeded comments.
 1.80 21-Sep-2023  oster Implement command-line configuration of simple RAID sets with raidctl
based on the usage pattern:

raidctl <device> create <level> <component1> <component2> ...

For example,

raidctl raid0 create mirror absent /dev/wd1e

will create a RAID level 1 (mirror) set with an absent first component
and /dev/wd1e as the second component. The resulting RAID device will
be marked as auto-configurable, will have a serial number set (based
on the current time), and parity will be initialized. Reasonable
performance values are automatically used by default for other parameters
normally specified in the configuration file.

Also: Only print out Autoconfig status if being verbose.
 1.79 17-Sep-2023  oster Implement hot removal of spares and components. From manu@.

Implement a long desired feature of automatically incorporating
a used spare into the array after a reconstruct.

Given the configuration:
Components:
/dev/wd0e: failed
/dev/wd1e: optimal
/dev/wd2e: optimal
Spares:
/dev/wd3e: spare

Running 'raidctl -F /dev/wd0e raid0' will now result in the
following configuration after a successful rebuild:
Components:
/dev/wd3e: optimal
/dev/wd1e: optimal
/dev/wd2e: optimal
No spares.

Thanks to manu@ for the development of the initial set of changes
which allowed the changes to automatically incorporate a used spare
to come to fruition. Thanks also to manu@ for useful discussions
about and additional testing of these changes.
 1.78 14-Jun-2022  kre branches: 1.78.2;
Implement "raidctl -t config-file"

This does the same config file parse that -c/-C do, but only
that (hence no raidframe device is needed, or accepted).

Any syntax errors in the config file will be reported, nothing
else happens.
 1.77 14-Jun-2022  kre In the previous (and some earlier) version(s) of raidctl.c
the following comment appeared:

/*
* After NetBSD 9, convert this to not output the numRow's value,
* which is no longer required or ever used.
*/

We are after NetBSD 9 (well after). The change requested in that
comment is made here, and the comment is thus removed.

A couple of places in rf_configure.c where a value for the "rows"
parameter was output in an error message (always simply as the
constant 0) have also been updated (those messages will no longer
include "row 0", which they always said previously). One of them
was also slightly reworded to be clearer what problem it was
experiencing (when it said 'unable to get device file' it meant
it was unable to locate the name for the device in the config file,
not that it was found, and there was some other problem with it).
 1.76 14-Jun-2022  kre Reorder the getopts() switch () (slightly) to sort the options. NFCI.
 1.75 14-Jun-2022  kre KNF (whitespace & 80 column limits) - NFCI.

This is the first of a series of 5 commits in this
directory, all coming within minutes or now.
 1.74 02-Aug-2021  oster Support on-demand re-scanning all devices to look for
autoconfig RAID sets. raidctl now supports looking
for autoconfig RAID sets with a new '-L' flag.
 1.73 01-Aug-2021  oster Move case 'l' to be in sorted order. No functional change.
 1.72 13-Sep-2020  mlelstv Allow components to be specified by wedge name.
 1.71 26-Sep-2019  mlelstv Need MIN in userland. Also some more signed/unsigned clashes.
 1.70 26-Sep-2019  mlelstv nspares is now unsigned. Validate and use as positive integer.
 1.69 06-Feb-2019  oster Correct printed IOCTL name that was incorrect since rev 1.5.
 1.68 04-Feb-2019  mrg - add the string length as an explicit parameter to get_time_string()
- remove casts when the same type is used on both sides
- expand hours_buffer[] to fit the range of hours in an 'int'
- add a work around for the sprintf() truncation checker that fails
to detect that 'minutes' and 'seconds' have a small range
 1.67 24-Mar-2018  nakayama branches: 1.67.2;
Follow the ioctl arg changes of RAIDFRAME_GET_COMPONENT_LABEL and
RAIDFRAME_CHECK_*_STATUS_EXT.

This should fix strange raidctl -s outputs reported in
current-users ML.
 1.66 18-Jan-2018  mrg branches: 1.66.2;
implement 32-bit compat support for raidframe.

convert several raidframe ioctls to be bitsize idempotent so that
they work the same in 32 and 64 bit worlds, allowing netbsd32 to
configure and query raid properly. remove useless 'row' in a few
places. add COMPAT_80 and put the old ioctls there.

raidframeio.h:
RAIDFRAME_TEST_ACC
- remove, unused
RAIDFRAME_GET_COMPONENT_LABEL
- convert to label not pointer to label
RAIDFRAME_CHECK_RECON_STATUS_EXT
RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT
RAIDFRAME_CHECK_COPYBACK_STATUS_EXT
- convert to progress info not pointer to info
RAIDFRAME_GET_INFO
- version entirely.
raidframevar.h:
- rf_recon_req{} has row, flags and raidPtr removed (they're
not a useful part of this interface.)
- RF_Config_s{} and RF_DeviceConfig_s{} have numRow/rows removed.
- RF_RaidDisk_s{} is re-ordered slightly to fix alignment
padding - the actual data was already OK.
- InstallSpareTable() loses row argument

rf_compat32.c has code for RF_Config_s{} in 32 bit mode, used
by RAIDFRAME_CONFIGURE and RAIDFRAME_GET_INFO32.

rf_compat80.c has code for rf_recon_req{}, RF_RaidDisk_s{} and
RF_DeviceConfig_s{} to handle RAIDFRAME_FAIL_DISK,
RAIDFRAME_GET_COMPONENT_LABEL, RAIDFRAME_CHECK_RECON_STATUS_EXT,
RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT,
RAIDFRAME_CHECK_COPYBACK_STATUS_EXT, RAIDFRAME_GET_INFO.

move several of the per-ioctl code blocks into separate functions.

add rf_recon_req_internal{} to replace old usage of global
rf_recon_req{} that had unused void * in the structure, ruining
it's 32/64 bit ABI.

add missing case for RAIDFRAME_GET_INFO50.

adjust raid tests to use the new .conf format, and add a case to
test the old method as well.

raidctl:
deal with lack of 'row' members in a couple of places.
fail request no longer takes row.
handle "START array" sections with just "numCol numSpare", ie
no "numRow" specified. for now, generate old-style configuration
but update raidctl.8 to specify the new style (keeping reference
to the old style.)

note that: RF_ComponentLabel_s::{row,num_rows} and
RF_SingleComponent_s::row are obsolete but not removed yet.
 1.65 06-Jan-2016  wiz Use standard sort order for options.

Add -U to usage.
 1.64 06-Jan-2016  christos Access to the SET_LAST_UNIT ioctl.
 1.63 08-Sep-2015  bad Rename argument of rf_output_devname() from devname to name to avoid a
warning about shadowing a global symbol when compiled by buildrump.sh.
Discussed with mrg.
 1.62 21-Jul-2015  mrg convert "component*" into "absent" for "START disks" part of the
output from "raidctl -G". now this actually works when fed back
into raidctl -[cC].
 1.61 30-Jun-2015  sborrill Compare correct length string for force option to -A
 1.60 26-Jun-2015  pooka &stars[offset] -> stars+offset. It's shorter!

Coincidentally, the change also works around a gcc 5.1 bug which causes
a segmentation fault when trying to compile the longer version (guess
the compiler got exhausted, or something).
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66345
 1.59 27-May-2015  christos use strtou
 1.58 27-May-2015  manu Better sanity check numbers given to raidctl(8)

Replace atoi(3) by strtol(3), and check that numbers are valid,
positive, and in int32_t range. The previous lack of check could
silently lead to the same serial being set to all RAID volumes
for instance because given numbers were bigger than INT_MAX. The
consequence is in an awful mess when RAIDframe would mix volumes...
 1.57 03-Apr-2014  christos branches: 1.57.4;
Add the ability to "softroot" mount (i.e. mount root only when the raid
set contains the boot device), as opposed to "hardroot" (the previous
default which forces the raid to be root no matter what).
 1.56 19-Oct-2013  christos fix unused variable warnings.
 1.55 12-Oct-2011  christos branches: 1.55.2; 1.55.4; 1.55.8;
PR/45456: Tetsuya Isaki: Don't mix stdio and write.
 1.54 28-Sep-2011  mrg print the serial number as an unsigned number.
 1.53 29-Aug-2011  joerg Use __dead
 1.52 19-Feb-2011  enami Define accessors for number of blocks and partition size in the
component label and use them where appropriate. Disscussed on tech-kern.
 1.51 09-Feb-2011  pooka Exterminate a bug I created in 2009.
 1.50 15-Dec-2010  pooka branches: 1.50.2;
Use RUMPPRG.

ok Greg Oster
 1.49 08-Nov-2010  pooka Update RUMP_ACTION to use rumpclient.

The server must of course have some disks configured. Let's say
we have this simple server with disks as a few sparse host files:

main()
{
rump_init();
rump_pub_etfs_register("/disk1", "./disk1.img", RUMP_ETFS_BLK);
rump_pub_etfs_register("/disk2", "./disk2.img", RUMP_ETFS_BLK);
rump_pub_etfs_register("/disk3", "./disk3.img", RUMP_ETFS_BLK);
rump_pub_etfs_register("/disk4", "./disk4.img", RUMP_ETFS_BLK);
pause();
}

And we run the server:

mainbus0 (root)
Kernelized RAIDframe activated
/disk1: hostpath ./disk1.img (97 GB)
/disk2: hostpath ./disk2.img (97 GB)
/disk3: hostpath ./disk3.img (97 GB)
/disk4: hostpath ./disk4.img (97 GB)

We can then configure the raid against the server:

> ./raidctl -c theraid.conf raid0

And lo, we have evidence of a level1 raid in the server dmesg:

raid0: RAID Level 1
raid0: Components: /disk1 /disk2 /disk3 /disk4
raid0: Total Sectors: 409599744 (199999 MB)

yea, i initialized it already in a previous run:

> ./raidctl -S raid0
Reconstruction is 100% complete.
Parity Re-write is 100% complete.
Copyback is 100% complete.
 1.48 16-Mar-2010  jld Give a more polite message for `raidctl -m` on a non-parity RAID set.
 1.47 13-Mar-2010  plunky fix sign-compare issue
 1.46 13-Mar-2010  jld Exclude parity map regions that don't actually exist from the dirty region count
in `raidctl -m`. Makes for less confusing output during `raidctl -i`.
 1.45 27-Jan-2010  christos use warn/err appropriately.
 1.44 27-Jan-2010  pooka error message: \n\n -> \n
 1.43 10-Dec-2009  jld Slight change to the wording of the parity map info: the parity is
"marked clean" after however much inactivity; it is *actually* clean
as soon as the component disks all do their thing (on the order of ms,
usually), just the same as before.

The bikeshed is now less of a taupe and more of an ecru.
 1.42 17-Nov-2009  jld Finally commit the RAIDframe parity map Summer Of Code project.

Drastically reduces the amount of time spent rewriting parity after an
unclean shutdown by keeping better track of which regions might have had
outstanding writes. Enabled by default; can be disabled on a per-set
basis, or tuned, with the new raidctl(8) commands.

Discussed on tech-kern@ to a general air of approval; exhortations to
commit from mrg@, christos@, and others.

Thanks to Google for their sponsorship, oster@ for mentoring the
project, assorted developers for trying very hard to break it, and
probably more I'm forgetting.
 1.41 11-Oct-2009  pooka Support RUMP_ACTION, i.e. compile-time switch to make this execute
rump syscalls to configure raidframe in a rump kernel.
 1.40 26-Jan-2009  tron Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.

Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.39 28-Apr-2008  martin branches: 1.39.4;
Remove clause 3 and 4 from TNF licenses
 1.38 02-Jun-2005  lukem branches: 1.38.4; 1.38.16; 1.38.20; 1.38.22;
appease gcc -Wuninitialized
 1.37 01-May-2005  oster Cleanup the meter code a bit -- a bunch of stuff wasn't even being used.
Fix a few overflow issues. (Thanks to beefy and pooka, among others)
 1.36 09-Feb-2005  xtraeme branches: 1.36.2;
Kill __P(), use ANSI function declarations; WARNS=3.
 1.35 29-Feb-2004  oster As suggested by Paul Ripke, have raidctl use raw devices by default.
 1.34 21-Oct-2003  fvdl Don't compare argc to NULL.
 1.33 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.32 15-Apr-2003  itojun correct questionable use of strncpy().
 1.31 16-Nov-2002  oster Cleanup and update usage().
 1.30 21-Mar-2002  simonb Open the raid device read-only for the commands that don't need
write access. With the default set up this allows users in group
operator to query the status of the raid devices.

Fixes PR admin/15840.
 1.29 04-Oct-2001  oster rf_configure.c
- remove dependence on stuff in sys/dev/raidframe
- now rely on <dev/raidframe/*>
- bring in some needed prototypes for local functions
- nuke RF_ASSERT's.
- drag in some needed RF_ERRORMSG's

raidctl.c
- rely on <dev/raidframe/*>
- welcome to the New Way of doing RAIDframe #includes.

(No functional changes.)
 1.28 26-Sep-2001  oster Since this is the only place it's used, nuke RF_DEV2RAIDID and
replace it with DISKUNIT.
 1.27 10-Jul-2001  lukem * add -G, which lists the configuration of the given raid set in the
same configuration format that -c and -C use.
this is useful if you're using autoconfig and you've misplaced the
/etc/raidXXX.conf files
* "filesystem" -> "file system", and other man page cleanups.
 1.26 19-Feb-2001  cgd convert to use getprogname()
 1.25 31-Oct-2000  lukem - use opendisk(3) instead of homegrown solution
- separate items in -s output with commas; much easier to read
- add maxOutstanding (aka queue len) to -s output
- sort #includes (per knf)
 1.24 19-Aug-2000  oster It is impolite to poll in a tight loop. (Thanks to Christos for noting
the problem.)
 1.23 03-Jun-2000  oster branches: 1.23.2;
In certain cases (e.g. where it makes sense) read/display the
component label for spare disks too.
 1.22 31-May-2000  oster Make sure we handle the 'no progress' case properly.
Thanks to Manuel Bouyer for noting the problem (and supplying a patch!).
 1.21 28-May-2000  oster Obtaining component labels from spares is not supported yet, but add
some code that makes some progress in that direction.
 1.20 28-May-2000  oster Cleanup ETA calculation stuff.
 1.19 28-May-2000  oster Have raidctl use the fine-grained progress info. ETA calculation stuff
needs to be cleaned up.
 1.18 23-May-2000  thorpej branches: 1.18.2;
Build with WARNS=2.
 1.17 23-May-2000  thorpej ioctl(2) commands are u_long, so do_meter() must take the same.
 1.16 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.15 23-Mar-2000  oster When displaying component labels, indicate whether or not the set is
marked as being the one that should be used for the root partition.
 1.14 25-Feb-2000  oster Reorganize a few things. Make the general status ('-s') a bit more verbose
by including component labels, and less verbose by removing some other stuff.
 1.13 24-Feb-2000  oster Document the new autoconfiguration switches, and update the Usage: line.
More doc changes expected soon.
 1.12 13-Feb-2000  oster - support for autoconfig setup and / on RAID setup
- new parts are still work-in-progress (no docs yet either)
 1.11 09-Jan-2000  oster Nuke a debugging printf that I forgot to remove before last commit.
 1.10 05-Jan-2000  oster - add '-v' (Verbose) option, which, most notably, provides
a spiffy lukemftp-inspired progress bar for parity re-writing,
reconstructs, copybacks, et al.

- make 'raidctl -P' wait until the parity has been updated before exiting
(it waited previously, but only because the parity re-write ioctl wouldn't
exit until the parity was successfully re-written)
 1.9 15-Aug-1999  oster rf_MakeConfig succeeds only if it returns 0, not if it returns
values 0 or greater.
 1.8 15-Aug-1999  oster Display the parity status as part of the status ('-s') display.
 1.7 10-Aug-1999  oster Add two more options to raidctl:
-p check (and return) the status of the parity
-P check the status of the parity, and rebuild if necessary

Addresses PR#7494
 1.6 02-Mar-1999  oster Update for recent changes: component labels, clean bits, adding hot
spares, and rebuilding components in-place. Re-arrange the
letters/options to make more sense (and make better use of the alphabet).
 1.5 24-Feb-1999  oster Clean things up a bit. Teach raidctl a little about component labels
and hot-adding of spares. New code is there, but not enabled (yet).
 1.4 04-Feb-1999  oster Add missing NetBSD RCS ID's! Thanks to SAITOH Masanobu (msaitoh@netbsd.org)
for pointing this out.
 1.3 26-Jan-1999  oster Take care of a few minor things due to the major RAIDframe cleanup.

Again, no functionality changes.
 1.2 12-Jan-1999  mjacob recover from errno.h changes
 1.1 13-Nov-1998  oster RAIDframe, version 1.1, from the Parallel Data Laboratory at
Carnegie Mellon University. Full RAID implementation, including
levels 0, 1, 4, 5, 6, parity logging, and a few other goodies.
Ported to NetBSD by Greg Oster.

raidctl is our userland configuration tool for RAIDframe.
 1.18.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.23.2.1 19-Aug-2000  oster Pullup 1.23->1.24. Approved by thorpej.
It is impolite to poll in a tight loop. (Thanks to Christos for noting
the problem.)
 1.36.2.2 31-Jan-2009  bouyer Pull up following revision(s) (requested by tron in ticket #1989):
sbin/raidctl/raidctl.c: revision 1.40
Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.
Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.36.2.1 28-May-2005  tron branches: 1.36.2.1.2; 1.36.2.1.4;
Pull up revision 1.37 (requested by oster in ticket #347):
Cleanup the meter code a bit -- a bunch of stuff wasn't even being used.
Fix a few overflow issues. (Thanks to beefy and pooka, among others)
 1.36.2.1.4.1 31-Jan-2009  bouyer Pull up following revision(s) (requested by tron in ticket #1989):
sbin/raidctl/raidctl.c: revision 1.40
Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.
Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.36.2.1.2.1 31-Jan-2009  bouyer Pull up following revision(s) (requested by tron in ticket #1989):
sbin/raidctl/raidctl.c: revision 1.40
Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.
Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.38.22.1 18-May-2008  yamt sync with head.
 1.38.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.38.16.1 31-Jan-2009  bouyer Pull up following revision(s) (requested by tron in ticket #1270):
sbin/raidctl/raidctl.c: revision 1.40
Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.
Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.38.4.1 31-Jan-2009  bouyer Pull up following revision(s) (requested by tron in ticket #1270):
sbin/raidctl/raidctl.c: revision 1.40
Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.
Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.39.4.4 13-Jun-2012  sborrill Pull up the following revisions(s) (requested by mrg in ticket #1774):
sbin/raidctl/raidctl.c: revision 1.52
sys/dev/raidframe/raidframevar.h: revision 1.15
sys/dev/raidframe/rf_copyback.c: revision 1.45
sys/dev/raidframe/rf_disks.c: revision 1.78
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.282,1.284
sys/dev/raidframe/rf_reconstruct.c: revision 1.111

Fix garbage values in partitionSizeHi with RAID array > 2TB. Stops the check against
rf_component_label_partitionsize() failing and stopping auto-configure.
 1.39.4.3 11-Dec-2009  sborrill Pull up the following revisions(s) (requested by tron in ticket #1191):
sbin/raidctl/raidctl.c: revision 1.43

Slight change to the wording of the parity map info: the parity is
"marked clean" after however much inactivity; it is *actually* clean
as soon as the component disks all do their thing (on the order of ms,
usually), just the same as before.
 1.39.4.2 10-Dec-2009  snj Pull up following revision(s) (requested by tron in ticket #1187):
sbin/raidctl/raidctl.8: revisions 1.57-1.59 via patch
sbin/raidctl/raidctl.c: revision 1.42 via patch
sys/dev/raidframe/files.raidframe: revision 1.8 via patch
sys/dev/raidframe/rf_copyback.c: revision 1.42 via patch
sys/dev/raidframe/rf_disks.c: revision 1.72 via patch
sys/dev/raidframe/rf_driver.c: revision 1.122 via patch
sys/dev/raidframe/rf_engine.c: revision 1.40 via patch
sys/dev/raidframe/rf_kintf.h: revision 1.21 via patch
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.269 via patch
sys/dev/raidframe/rf_paritymap.c: revisions 1.1-1.3 via patch
sys/dev/raidframe/rf_paritymap.h: revision 1.1 via patch
sys/dev/raidframe/rf_parityscan.c: revision 1.33 via patch
sys/dev/raidframe/rf_parityscan.h: revision 1.8 via patch
sys/dev/raidframe/rf_raid.h: revision 1.38 via patch
sys/dev/raidframe/rf_reconstruct.c: revision 1.108 via patch
sys/dev/raidframe/rf_states.c: revision 1.44 via patch
sys/dev/raidframe/raidframeio.h: revision 1.6 via patch
sys/dev/raidframe/raidframevar.h: revision 1.13 via patch
Pull up the RAIDframe parity map Summer Of Code project.
Drastically reduces the amount of time spent rewriting parity after an
unclean shutdown by keeping better track of which regions might have had
outstanding writes. Enabled by default; can be disabled on a per-set
basis, or tuned, with the new raidctl(8) commands.
 1.39.4.1 01-Feb-2009  snj branches: 1.39.4.1.4;
Pull up following revision(s) (requested by tron in ticket #323):
sbin/raidctl/raidctl.c: revision 1.40
Use correct format to print the "numBlocks" element in a RAIDframe
component label. raidctl(8) should now print the correct number of
blocks for RAID sets larger than 1TB.
Patch supplied by Bernhard Moellemann in PR bin/40479.
 1.39.4.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.50.2.2 05-Mar-2011  bouyer Sync with HEAD
 1.50.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.55.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.55.4.1 15-Nov-2015  bouyer Pull up following revision(s) (requested by manu in ticket #1304):
sbin/raidctl/raidctl.c: revision 1.58
Better sanity check numbers given to raidctl(8)
Replace atoi(3) by strtol(3), and check that numbers are valid,
positive, and in int32_t range. The previous lack of check could
silently lead to the same serial being set to all RAID volumes
for instance because given numbers were bigger than INT_MAX. The
consequence is in an awful mess when RAIDframe would mix volumes...
 1.55.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.57.4.4 14-Jul-2017  martin Pull up following revision(s) (requested by christos in ticket #1457):
sbin/raidctl/raidctl.c: revision 1.64
sbin/raidctl/raidctl.8: revision 1.70
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.341
sys/dev/raidframe/raidframeio.h: revision 1.7
Add a SET_LAST_UNIT ioctl.
Access to the SET_LAST_UNIT ioctl.
 1.57.4.3 05-Jul-2015  snj Pull up following revision(s) (requested by sborrill in ticket #862):
sbin/raidctl/raidctl.c: revision 1.61
Compare correct length string for force option to -A
 1.57.4.2 09-Jun-2015  snj Pull up following revision(s) (requested by martin in ticket #827):
sbin/raidctl/raidctl.c: revision 1.59
use strtou
 1.57.4.1 08-Jun-2015  snj Pull up following revision(s) (requested by manu in ticket #827):
sbin/raidctl/raidctl.c: revision 1.58
Better sanity check numbers given to raidctl(8)
Replace atoi(3) by strtol(3), and check that numbers are valid,
positive, and in int32_t range. The previous lack of check could
silently lead to the same serial being set to all RAID volumes
for instance because given numbers were bigger than INT_MAX. The
consequence is in an awful mess when RAIDframe would mix volumes...
 1.66.2.1 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.67.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.67.2.1 10-Jun-2019  christos Sync with HEAD
 1.78.2.2 28-Apr-2024  martin Pull up following revision(s) (requested by oster in ticket #675):

sbin/raidctl/raidctl.8: revision 1.81
sbin/raidctl/raidctl.c: revision 1.80

Implement command-line configuration of simple RAID sets with raidctl
based on the usage pattern:

raidctl <device> create <level> <component1> <component2> ...

For example,

raidctl raid0 create mirror absent /dev/wd1e

will create a RAID level 1 (mirror) set with an absent first component
and /dev/wd1e as the second component. The resulting RAID device will
be marked as auto-configurable, will have a serial number set (based
on the current time), and parity will be initialized. Reasonable
performance values are automatically used by default for other parameters
normally specified in the configuration file.

Also: Only print out Autoconfig status if being verbose.
 1.78.2.1 28-Apr-2024  martin Pull up following revision(s) (requested by oster in ticket #674):

sys/dev/raidframe/rf_raid.h: revision 1.52
sbin/raidctl/raidctl.8: revision 1.80
sys/dev/raidframe/rf_driver.c: revision 1.141
sys/dev/raidframe/rf_disks.c: revision 1.94
sys/dev/raidframe/rf_diskqueue.c: revision 1.64
sys/dev/raidframe/rf_diskqueue.h: revision 1.30
sys/dev/raidframe/rf_disks.h: revision 1.15
sys/dev/raidframe/rf_netbsdkintf.c: revision 1.414
sys/dev/raidframe/rf_reconstruct.c: revision 1.129
sys/dev/raidframe/raidframeio.h: revision 1.12
sbin/raidctl/raidctl.c: revision 1.79

Implement hot removal of spares and components. From manu@.

Implement a long desired feature of automatically incorporating
a used spare into the array after a reconstruct.

Given the configuration:

Components:
/dev/wd0e: failed
/dev/wd1e: optimal
/dev/wd2e: optimal
Spares:
/dev/wd3e: spare

Running 'raidctl -F /dev/wd0e raid0' will now result in the
following configuration after a successful rebuild:

Components:
/dev/wd3e: optimal
/dev/wd1e: optimal
/dev/wd2e: optimal
No spares.

Thanks to manu@ for the development of the initial set of changes
which allowed the changes to automatically incorporate a used spare
to come to fruition. Thanks also to manu@ for useful discussions
about and additional testing of these changes.
 1.83.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 10-Jan-2017  christos need <sys/stat.h> for fstat()
 1.2 09-Feb-2011  pooka branches: 1.2.26;
Exterminate a bug I created in 2009.
 1.1 15-Dec-2010  pooka branches: 1.1.2;
Use RUMPPRG.

ok Greg Oster
 1.1.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.2.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 09-Feb-2011  pooka Exterminate a bug I created in 2009.
 1.1 15-Dec-2010  pooka branches: 1.1.2;
Use RUMPPRG.

ok Greg Oster
 1.1.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.37 21-Jul-2022  kre PR bin/56917

If getfsspecname() fails that will usually mean that a NAME=wedge or
ROOT.x partition is unabailable. raidframe specified unavailable
partitions as "absent" so in this case, pass "absent" rather than the
unaltered NAME= or ROOT.x string, which the kernel has no clue what
do do with, and doesn't configure the raid at all.
 1.36 14-Jun-2022  kre Fix some config file parsing.

First, and what got me started on this set of cleanups, the queue
length in the "queue" section (START queue) is limited to what will
fit in a char without losing accuracy (I tried setting it to 200,
rather than the more common (universal?) 100 and found that the
value configured into the array was -56 instead.

Why the value needs to be passed through a char variable I have no
idea (it is an int in the filesystem raidframe headers) - but that's
the way it is done, and changing it would be an ABI change I believe
(and so need versioning to alter) and that isn't worth it for this
(or not now, IMO).

Instead check that the value in the char is the same value as was
read from the config file, and complain if not. Those of you with
unsigned chars will be able to have queue lengths up to 255, the
rest of us are limited to 127.

While looking at that, I noticed some code that obviously fails to
understand that scanf("%s") will never return a string containing
spaces, and proceeded to attempt to remove trailing spaces from the
result ... amusingly, after having used the result for its intended
purpose (non existent trailing spaces unremoved), after which that
buffer was never used again. That code is now gone (but for now,
just #if 0'd rather than actually deleted - it should be cleaned up
sometime).

Then I saw some other issues with how the config was parsed - a
simple (unbounded) scanf("%s") into a buffer, which hypothetically
might not be large enough (not a security issue really, raidctl has
no special privs, and it isn't likely that root could easily be
tricked into running it on a bogus config file - or not without
looking first anyway, and a huge long string would rather stand
out). Bound the string length to something reasonable, and
assert() that the buffer is big enough to contain it.

Lastly, in the event of one particular detected error in the
config file, the code would write a warning, but then just go
ahead and use the bad data (or nothing perhaps) anyway - a
failure of logic flow (unlikely to have ever happened, everyone
seems to simply copy the sample config from the man page, and
make minor adjustments as needed).

If any of these changes make any difference to anyone (except
me with my attempt to make longer queues - for no particularly
well thought out reason), I'd be very surprised.
 1.35 14-Jun-2022  kre In the previous (and some earlier) version(s) of raidctl.c
the following comment appeared:

/*
* After NetBSD 9, convert this to not output the numRow's value,
* which is no longer required or ever used.
*/

We are after NetBSD 9 (well after). The change requested in that
comment is made here, and the comment is thus removed.

A couple of places in rf_configure.c where a value for the "rows"
parameter was output in an error message (always simply as the
constant 0) have also been updated (those messages will no longer
include "row 0", which they always said previously). One of them
was also slightly reworded to be clearer what problem it was
experiencing (when it said 'unable to get device file' it meant
it was unable to locate the name for the device in the config file,
not that it was found, and there was some other problem with it).
 1.34 06-Sep-2020  mrg avoid trying to printf() a NULL as %s. fixes likely bug.
 1.33 18-Jan-2018  mrg implement 32-bit compat support for raidframe.

convert several raidframe ioctls to be bitsize idempotent so that
they work the same in 32 and 64 bit worlds, allowing netbsd32 to
configure and query raid properly. remove useless 'row' in a few
places. add COMPAT_80 and put the old ioctls there.

raidframeio.h:
RAIDFRAME_TEST_ACC
- remove, unused
RAIDFRAME_GET_COMPONENT_LABEL
- convert to label not pointer to label
RAIDFRAME_CHECK_RECON_STATUS_EXT
RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT
RAIDFRAME_CHECK_COPYBACK_STATUS_EXT
- convert to progress info not pointer to info
RAIDFRAME_GET_INFO
- version entirely.
raidframevar.h:
- rf_recon_req{} has row, flags and raidPtr removed (they're
not a useful part of this interface.)
- RF_Config_s{} and RF_DeviceConfig_s{} have numRow/rows removed.
- RF_RaidDisk_s{} is re-ordered slightly to fix alignment
padding - the actual data was already OK.
- InstallSpareTable() loses row argument

rf_compat32.c has code for RF_Config_s{} in 32 bit mode, used
by RAIDFRAME_CONFIGURE and RAIDFRAME_GET_INFO32.

rf_compat80.c has code for rf_recon_req{}, RF_RaidDisk_s{} and
RF_DeviceConfig_s{} to handle RAIDFRAME_FAIL_DISK,
RAIDFRAME_GET_COMPONENT_LABEL, RAIDFRAME_CHECK_RECON_STATUS_EXT,
RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT,
RAIDFRAME_CHECK_COPYBACK_STATUS_EXT, RAIDFRAME_GET_INFO.

move several of the per-ioctl code blocks into separate functions.

add rf_recon_req_internal{} to replace old usage of global
rf_recon_req{} that had unused void * in the structure, ruining
it's 32/64 bit ABI.

add missing case for RAIDFRAME_GET_INFO50.

adjust raid tests to use the new .conf format, and add a case to
test the old method as well.

raidctl:
deal with lack of 'row' members in a couple of places.
fail request no longer takes row.
handle "START array" sections with just "numCol numSpare", ie
no "numRow" specified. for now, generate old-style configuration
but update raidctl.8 to specify the new style (keeping reference
to the old style.)

note that: RF_ComponentLabel_s::{row,num_rows} and
RF_SingleComponent_s::row are obsolete but not removed yet.
 1.32 22-Nov-2017  kre Several more cleanups:
1. Don't force use of "for" when "while" works better.
2. No need to check c != '\0' when we also check (c == ' ' || c == '\t')
3. Use the size of the buffer we're using, rather than a different one
(not really a concern, they're the same size)
4. Don't use fscanf() to read file data, use fgets() & sscanf().
5. After using a pointer as a char *, validate alignment before switching
to int * (can only fail if kernel #define gets set stupidly) Or #6...
6. Validate sparemap file name isn't too long for assigned space.
7. recognise that strlen() returns size_t - don't shove it into an int.
8. On out of mem, be more clear which allocation failed in warning msg.

ATF tests all pass. But I don't think they use sparemap files.
 1.31 21-Nov-2017  christos Avoid needless pointer calisthenics: &foo[0] -> foo
 1.30 21-Nov-2017  kre With char bug[SIZE] using sizeof(bug[0]) is kind of boring, use
sizeof(bug) instead...
 1.29 20-Nov-2017  kre White space and comment formatting. NFC.
 1.28 20-Nov-2017  christos stop using magic constants
wrap long lines
use warn{,x}
make static
knf
 1.27 20-Nov-2017  kardel support NAME=<wedge name> syntax for disks and spares
 1.26 09-Mar-2016  christos branches: 1.26.8;
PR/50921: David Binderman: Fix memory leak
 1.25 27-Jan-2010  christos use warn/err appropriately.
 1.24 06-Apr-2009  lukem fix sign-compare issue
 1.23 19-Mar-2006  dan branches: 1.23.30;
close fp in several error paths, closing Coverity CIDs 1690, 1692.

"go" by go.
 1.22 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.21 26-Oct-2004  oster Cleanup a bit by nuking RF_Malloc macro, and add in some error
checking for the case where we can't allocate memory. (Not like
anyone uses this part of the code anyway.)
 1.20 26-Oct-2004  oster Strip off trailing \n's and spaces from configuration file lines.
Makes RAIDframe more forgiving if you accidentally add a space after
things like device names. Fixed at long last after a reminder over
the weekend.
 1.19 26-Oct-2004  oster How about we use the 'len' parameter to rf_get_next_nonblank_line()
instead of assuming all buffers are 256 bytes.
 1.18 13-Jul-2003  itojun use bouded string ops
 1.17 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.16 17-May-2003  itojun sscanf overrun
 1.15 04-Oct-2001  oster rf_configure.c
- remove dependence on stuff in sys/dev/raidframe
- now rely on <dev/raidframe/*>
- bring in some needed prototypes for local functions
- nuke RF_ASSERT's.
- drag in some needed RF_ERRORMSG's

raidctl.c
- rely on <dev/raidframe/*>
- welcome to the New Way of doing RAIDframe #includes.

(No functional changes.)
 1.14 04-Feb-2001  christos remove redundant prototypes.
 1.13 27-Jan-2001  oster Move parts of a RAID type mapping table from rf_layout.c to rf_configure.c.
This means we don't need to compile or link with rf_layout.c here.
 1.12 31-Dec-2000  wiz Check return value of fgets. Approved by Greg Oster.
 1.11 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.10 23-May-2000  thorpej branches: 1.10.4;
Apply indent.
 1.9 23-May-2000  thorpej Build with WARNS=2.
 1.8 13-Aug-1999  oster No need to include rf_sys.h.
 1.7 07-Aug-1999  oster Move two functions from rf_strutils.c into rf_configure.c, removing
the need for rf_strutils.c.
 1.6 26-Mar-1999  oster branches: 1.6.2;
Nuke unused code.
 1.5 04-Feb-1999  oster Add missing NetBSD RCS ID's! Thanks to SAITOH Masanobu (msaitoh@netbsd.org)
for pointing this out.
 1.4 26-Jan-1999  oster Take care of a few minor things due to the major RAIDframe cleanup.

Again, no functionality changes.
 1.3 12-Jan-1999  mjacob recover from errno.h changes
 1.2 23-Nov-1998  mrg fix compile errors on the alpha.
 1.1 13-Nov-1998  oster RAIDframe, version 1.1, from the Parallel Data Laboratory at
Carnegie Mellon University. Full RAID implementation, including
levels 0, 1, 4, 5, 6, parity logging, and a few other goodies.
Ported to NetBSD by Greg Oster.

raidctl is our userland configuration tool for RAIDframe.
 1.6.2.1 10-Oct-2000  he Pull up revision 1.11 (via patch, requested by is):
Format string cleanup.
 1.10.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.23.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.26.8.1 10-Sep-2018  martin Pull up following revision(s) (requested by nakayama in ticket #1019):

sbin/raidctl/rf_configure.h: revision 1.2
sbin/raidctl/rf_configure.c: revision 1.27
sbin/raidctl/rf_configure.c: revision 1.28
sbin/raidctl/rf_configure.c: revision 1.29
sbin/raidctl/raidctl.8: revision 1.73
sbin/raidctl/rf_configure.c: revision 1.30
sbin/raidctl/rf_configure.c: revision 1.31
sbin/raidctl/rf_configure.c: revision 1.32

support NAME=<wedge name> syntax for disks and spares

-

stop using magic constants
wrap long lines
use warn{,x}
make static
knf

-

White space and comment formatting. NFC.

-

With char bug[SIZE] using sizeof(bug[0]) is kind of boring, use
sizeof(bug) instead...

-

Avoid needless pointer calisthenics: &foo[0] -> foo

-

Several more cleanups:
1. Don't force use of "for" when "while" works better.
2. No need to check c != '\0' when we also check (c == ' ' || c == '\t')
3. Use the size of the buffer we're using, rather than a different one
(not really a concern, they're the same size)
4. Don't use fscanf() to read file data, use fgets() & sscanf().
5. After using a pointer as a char *, validate alignment before switching
to int * (can only fail if kernel #define gets set stupidly) Or #6...
6. Validate sparemap file name isn't too long for assigned space.
7. recognise that strlen() returns size_t - don't shove it into an int.
8. On out of mem, be more clear which allocation failed in warning msg.

ATF tests all pass. But I don't think they use sparemap files.
 1.2 20-Nov-2017  christos stop using magic constants
wrap long lines
use warn{,x}
make static
knf
 1.1 04-Oct-2001  oster branches: 1.1.92;
Add a pruned-down version of rf_configure.h. First step at disentangling
raidctl files from the hairy .h file mess.
 1.1.92.1 10-Sep-2018  martin Pull up following revision(s) (requested by nakayama in ticket #1019):

sbin/raidctl/rf_configure.h: revision 1.2
sbin/raidctl/rf_configure.c: revision 1.27
sbin/raidctl/rf_configure.c: revision 1.28
sbin/raidctl/rf_configure.c: revision 1.29
sbin/raidctl/raidctl.8: revision 1.73
sbin/raidctl/rf_configure.c: revision 1.30
sbin/raidctl/rf_configure.c: revision 1.31
sbin/raidctl/rf_configure.c: revision 1.32

support NAME=<wedge name> syntax for disks and spares

-

stop using magic constants
wrap long lines
use warn{,x}
make static
knf

-

White space and comment formatting. NFC.

-

With char bug[SIZE] using sizeof(bug[0]) is kind of boring, use
sizeof(bug) instead...

-

Avoid needless pointer calisthenics: &foo[0] -> foo

-

Several more cleanups:
1. Don't force use of "for" when "while" works better.
2. No need to check c != '\0' when we also check (c == ' ' || c == '\t')
3. Use the size of the buffer we're using, rather than a different one
(not really a concern, they're the same size)
4. Don't use fscanf() to read file data, use fgets() & sscanf().
5. After using a pointer as a char *, validate alignment before switching
to int * (can only fail if kernel #define gets set stupidly) Or #6...
6. Validate sparemap file name isn't too long for assigned space.
7. recognise that strlen() returns size_t - don't shove it into an int.
8. On out of mem, be more clear which allocation failed in warning msg.

ATF tests all pass. But I don't think they use sparemap files.
 1.2 26-Jan-1999  oster Never used, and certainly no longer needed.
 1.1 13-Nov-1998  oster RAIDframe, version 1.1, from the Parallel Data Laboratory at
Carnegie Mellon University. Full RAID implementation, including
levels 0, 1, 4, 5, 6, parity logging, and a few other goodies.
Ported to NetBSD by Greg Oster.

raidctl is our userland configuration tool for RAIDframe.
 1.2 26-Jan-1999  oster Never used, and certainly no longer needed.
 1.1 13-Nov-1998  oster RAIDframe, version 1.1, from the Parallel Data Laboratory at
Carnegie Mellon University. Full RAID implementation, including
levels 0, 1, 4, 5, 6, parity logging, and a few other goodies.
Ported to NetBSD by Greg Oster.

raidctl is our userland configuration tool for RAIDframe.
 1.8 03-Aug-2008  lukem Revert previous accidental commit of debug statements
 1.7 03-Aug-2008  lukem Avoid freeing memory in do_file() since it's called recursively
 1.6 26-Aug-2006  christos Programs that use efun.
 1.5 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.4 30-Nov-2002  lukem tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
 1.3 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.2 23-Nov-1999  mrg branches: 1.2.2;
we are rcorder.8 now.
 1.1 23-Nov-1999  mrg move rcorder to sbin.
 1.2.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4 26-Aug-2006  christos Programs that use efun.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.1 23-Nov-1999  mrg branches: 1.1.2;
move rcorder to sbin.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3 26-Aug-2006  christos Programs that use efun.
 1.2 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.1 23-Nov-1999  mrg branches: 1.1.2;
move rcorder to sbin.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5 03-Mar-2007  simonb No need to cast pointers to (char *) when passing to free(3).
 1.4 26-Aug-2006  christos Programs that use efun.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.1 23-Nov-1999  mrg branches: 1.1.2;
move rcorder to sbin.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.2 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.1 23-Nov-1999  mrg branches: 1.1.2;
move rcorder to sbin.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.5 09-Aug-2009  apb Allow rcorder-visualise.sh to accept an optional set of file names on
the command line. By default it uses /etc/rc.d/*, as before. Sample
usage: /usr/src/rcorder-visualise.sh /usr/src/etc/rc.d/*.
 1.4 15-Apr-2009  joerg branches: 1.4.2;
Speling.
 1.3 15-Apr-2009  joerg As noted by apb, don't slip in local pathes.
 1.2 15-Apr-2009  joerg Behave as documented and remove the dot call at the end.
Add RCS ID.
 1.1 15-Apr-2009  joerg Add a small script to visualize the rc dependency graph and point to it.
 1.4.2.2 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.4.2.1 15-Apr-2009  jym file rcorder-visualize.sh was added on branch jym-xensuspend on 2009-05-13 19:19:05 +0000
 1.2 23-Nov-1999  mrg we are rcorder.8 now.
 1.1 23-Nov-1999  mrg move rcorder to sbin.
 1.11 04-Feb-2024  mrg update my email address.
 1.10 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.9 20-Jul-2013  wiz Use Mt for email addresses.
 1.8 23-Jun-2005  peter branches: 1.8.44; 1.8.50; 1.8.56;
Add .An -nosplit to the beginning of the section.
Suggested by Thomas Klausner.
 1.7 23-Jun-2005  peter Use .An name Aq email.
 1.6 24-Apr-2003  perry Document what happens when you don't have any dependency lines in a
file, and downgrade "must" to "should" in a couple of places.
Answers a documentation complaint from Jeremy C. Reed in PR misc/21251
 1.5 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.4 16-Nov-2001  wiz Whitespace nits
 1.3 17-Jul-2000  mrg implement `# KEYWORD:' support, with two new arguments to rcorder, to kill
and skip keywords from the output list:

-k keyword only files with `# KEYWORD: keyword' will be printed.
-s keyword files with `# KEYWORD: keyword' will not be printed.

(multiple keywords can exist on a single line, and multiple lines may exist,
as with other special rcorder lines).

requested by lukem.
 1.2 05-Jul-2000  msaitoh remove extra period in SEE ALL section
 1.1 23-Nov-1999  mrg branches: 1.1.2; 1.1.6;
we are rcorder.8 now.
 1.1.6.1 18-Jul-2000  mrg pull up rcorder.c 1.5 and rcorder.8 1.3, approved by thorpej:
>implement `# KEYWORD:' support, with two new arguments to rcorder, to kill
>and skip keywords from the output list:
>
> -k keyword only files with `# KEYWORD: keyword' will be printed.
> -s keyword files with `# KEYWORD: keyword' will not be printed.
>
>(multiple keywords can exist on a single line, and multiple lines may exist,
>as with other special rcorder lines).
>
>requested by lukem.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.56.1 23-Jul-2013  riastradh sync with HEAD
 1.8.50.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.44.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19 05-Feb-2024  andvar s/dependancies/dependencies/ and s/independantly/independently/ in comments and
distrib notes.
 1.18 05-Sep-2016  sevan Drop main() prototype.
 1.17 19-Oct-2013  christos fix unused variable warnings.
 1.16 03-Aug-2008  lukem branches: 1.16.18; 1.16.24;
Avoid freeing memory in do_file() since it's called recursively
 1.15 29-May-2008  mrg remove clause #3 from my license where there are no other
copyright holders involved.
 1.14 26-Aug-2006  christos branches: 1.14.18; 1.14.20; 1.14.22;
Programs that use efun.
 1.13 21-Sep-2004  rumble Do not exceed 80 columns. No functional change.
 1.12 13-Oct-2003  agc Move Matt Green's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22396 by Joel Baker, the changes
were confirmed to the board by Matt Green.
 1.11 30-Nov-2002  lukem tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
 1.10 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.9 30-Jun-2002  lukem use strnode_add() to implement add_before()
 1.8 10-Apr-2002  christos don't whine about non-regular files. It is perfectly normal to keep a CVS
or RCS directory in /etc/rc.d.
 1.7 04-Aug-2000  enami Stop parsing once encountered non directive line as documented in man page.
 1.6 19-Jul-2000  enami Free storage allocated by fparseln.
 1.5 17-Jul-2000  mrg implement `# KEYWORD:' support, with two new arguments to rcorder, to kill
and skip keywords from the output list:

-k keyword only files with `# KEYWORD: keyword' will be printed.
-s keyword files with `# KEYWORD: keyword' will not be printed.

(multiple keywords can exist on a single line, and multiple lines may exist,
as with other special rcorder lines).

requested by lukem.
 1.4 10-May-2000  enami branches: 1.4.4;
Fix bug introduced in previous; don't leak file pointers.
 1.3 09-May-2000  enami Crunch only regular files and warn others.
 1.2 26-Apr-2000  thorpej Don't warn when two nodes provide the same thing; this can be quite
useful (read the big comment I added).
 1.1 23-Nov-1999  mrg branches: 1.1.2;
move rcorder to sbin.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.4.4.2 22-Jul-2000  enami Pullup revision 1.6 (requested by thorpej):
Free storage allocated by fparseln.
 1.4.4.1 18-Jul-2000  mrg pull up rcorder.c 1.5 and rcorder.8 1.3, approved by thorpej:
>implement `# KEYWORD:' support, with two new arguments to rcorder, to kill
>and skip keywords from the output list:
>
> -k keyword only files with `# KEYWORD: keyword' will be printed.
> -s keyword files with `# KEYWORD: keyword' will not be printed.
>
>(multiple keywords can exist on a single line, and multiple lines may exist,
>as with other special rcorder lines).
>
>requested by lukem.
 1.14.22.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.14.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.20.1 04-Jun-2008  yamt sync with head
 1.14.18.2 28-Sep-2008  mjf Sync with HEAD.
 1.14.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.24.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.18.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.3 30-Jun-2002  lukem KNF, remove unnecessary crap, ...
 1.2 16-Jan-2001  cgd comment or delete text after CPP directives.
 1.1 23-Nov-1999  mrg branches: 1.1.2;
move rcorder to sbin.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18 02-Aug-2002  wiz Support wtmpx.
 1.17 25-Apr-2000  hubertf Implement a "poweroff" command which is equivalent to "halt -p",
but allows powering down the system from an exec(2) call, e.g. via
a user which has "poweroff" as login shell.

The command name is modeled after Solaris.
 1.16 15-Sep-1997  lukem define WARNS?=1 for all of sbin/*
 1.15 19-Jul-1997  perry add WARNS=1
 1.14 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.13 17-Oct-1996  perry Remove boot_tahoe.8. We have no tahoe port.
 1.12 27-Jun-1996  leo Add the manual page.
 1.11 26-Jun-1996  thorpej Add boot_x68k.8 to the list of man pages to install; the distrib sets
expect it.
 1.10 08-Aug-1995  gwr branches: 1.10.6;
Add boot_sun3.8
 1.9 02-Jul-1995  briggs Reorder man page sources in makefile (alphabetize) and
add boot_mac68k.8.
 1.8 31-May-1995  mellon Make boot_pmax man page. (from jonathan)
 1.7 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 22-Dec-1994  cgd specify man pages the new way.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-Mar-1995  cgd from Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.6.2 28-Jun-1996  jtc Pulled up from rev 1.12 by request from Leo Weppelman
 1.10.6.1 26-Jun-1996  thorpej Update from trunk:

Add boot_x68k.8 to the list of man pages to install; the distrib sets
expect it.
 1.4 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.3 15-Oct-1996  leo Fix typo.
 1.2 15-Oct-1996  leo Be a bit more exact about when the bootloader decides to start NetBSD.
 1.1 27-Jun-1996  leo branches: 1.1.2;
Add the manual page.
 1.1.2.2 27-Jun-1996  leo Add the manual page.
 1.1.2.1 27-Jun-1996  leo file boot_atari.8 was added on branch netbsd-1-2 on 1996-06-27 11:07:57 +0000
 1.4 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.3 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.2 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.1 18-Mar-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-Mar-1995  cgd from Lite
 1.4 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.3 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.2 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.1 18-Mar-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-Mar-1995  cgd from Lite
 1.2 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.1 02-Jul-1995  briggs Reorder man page sources in makefile (alphabetize) and
add boot_mac68k.8.
 1.3 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.2 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.1 25-Apr-1995  mellon pmax boot documentation
 1.6 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.5 09-Aug-1996  mrg update for new reboot(2).
 1.4 25-Apr-1995  pk Bits from old reboot_sparc.8 man page.
 1.3 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.2 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.1 18-Mar-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-Mar-1995  cgd from Lite
 1.3 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.2 09-Aug-1996  mrg update for new reboot(2).
 1.1 08-Aug-1995  gwr Add boot_sun3.8
 1.4 17-Oct-1996  perry Remove boot_tahoe.8. We have no tahoe port.
 1.3 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.2 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.1 18-Mar-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-Mar-1995  cgd from Lite
 1.4 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.3 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.2 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.1 18-Mar-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-Mar-1995  cgd from Lite
 1.2 13-Mar-1997  perry The boot_${ARCH}.8 man files never belonged in reboot -- they have
been moved to man8.${ARCH}/boot.8. Note that this means that the
references in the pages to boot.8 are now actually true on many
architectures instead of being a lie on all.
 1.1 15-Jun-1996  oki branches: 1.1.2;
x68k system bootstrapping procedures.
 1.1.2.2 15-Jun-1996  oki x68k system bootstrapping procedures.
 1.1.2.1 15-Jun-1996  oki file boot_x68k.8 was added on branch netbsd-1-2 on 1996-06-15 18:54:23 +0000
 1.30 12-Sep-2016  sevan A standalone reboot utility showed up in 4.0BSD.
In AT&T UNIX init has a case for reboot and is present in the version shipped
with V5.
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s1/init.c

Amend HISTORY section.
Bump date.
 1.29 16-Feb-2011  wiz Add -vxz to SYNOPSIS and usage.
 1.28 16-Feb-2011  dyoung Add flags -v, -x, and -z for verbose, debug, and silent shutdowns,
respectively, by passing flags AB_VERBOSE, AB_DEBUG, and/or AB_SILENT to
reboot(2).
 1.27 12-Dec-2010  pooka branches: 1.27.2;
multicore update
 1.26 21-Oct-2008  lukem xref rescue(8)
 1.25 25-May-2008  wiz New sentence, new line.
 1.24 09-Feb-2008  dholland branches: 1.24.4; 1.24.6; 1.24.8;
Set off symbolic signal names (SIG...) with .Dv, and crossreference init(8).
From PR bin/36551 by Greg A. Woods. And while I'm here, fix a grammar nit.
 1.23 03-Jun-2007  uwe branches: 1.23.4; 1.23.6;
Document that reboot(8) passes any arguments to reboot(2) as bootstr.
 1.22 24-May-2007  jnemeth Add a caveat about reboot(8) not running shutdown scripts. This addresses
(at least partially) PR/35067 by Blair Sadewitz.
 1.21 07-Aug-2003  agc branches: 1.21.6; 1.21.16; 1.21.18;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.20 04-Apr-2003  wiz Bump date.
 1.19 04-Apr-2003  perry 1) Remove a reference to a 30 second delay left when Ignatios
backed out a 30 second delay from the program.
2) Add a CAVEATS section noting that the command cannot and should not
be stopped once started.
 1.18 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.17 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.16 17-Apr-2002  wiz Sync order of programs with their actions, noted by mrg.
 1.15 16-Nov-2001  wiz Sort SEE ALSO, use .Pp for paragraphs.
 1.14 16-Nov-2001  wiz Whitespace nits
 1.13 20-Jun-2001  mrg expand -n documentation; from sunos.
 1.12 25-Apr-2000  hubertf Implement a "poweroff" command which is equivalent to "halt -p",
but allows powering down the system from an exec(2) call, e.g. via
a user which has "poweroff" as login shell.

The command name is modeled after Solaris.
 1.11 19-Aug-1999  simonb "-l" means _don't_ log to syslog(3).
 1.10 03-Jul-1998  is Make halt and reboot wait up to 32 seconds after kill(-1, SIGTERM), but
check at 3 second intervals if any are left.
This will help slow machines to cleanly shut down X servers (to make the
console visible), databases, or Usenet news servers.
 1.9 06-Jun-1998  thorpej Add a -p option to halt(8), specifying that the system should be powered
down.
 1.8 20-Jan-1998  mycroft Correct the tense of one sentence.
 1.7 20-Jan-1998  mycroft Clean up documentation a bit, and document the `-l' option.
 1.6 20-Oct-1997  enami Fix .Nm usage.
 1.5 15-Sep-1997  lukem - use .Nm correctly
- use __progname instead of rindex(argv[0]) ...
 1.4 22-Jul-1997  mikel xref sync(8) not nonexistent sync(1), reorder xrefs
 1.3 05-Oct-1995  mycroft Add a `-d' option to force a dump. From John Kohl.
 1.2 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.1 18-Mar-1995  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 18-Mar-1995  cgd from Lite
 1.21.18.1 04-Jun-2007  wrstuden Update to today's netbsd-4.
 1.21.16.1 30-May-2007  riz Pull up following revision(s) (requested by jnemeth in ticket #676):
sbin/reboot/reboot.8: revision 1.22
Add a caveat about reboot(8) not running shutdown scripts. This addresses
(at least partially) PR/35067 by Blair Sadewitz.
 1.21.6.1 30-May-2009  snj Pull up following revision(s) (requested by jnemeth in ticket #2016):
sbin/reboot/reboot.8: revision 1.22
Add a caveat about reboot(8) not running shutdown scripts. This addresses
(at least partially) PR/35067 by Blair Sadewitz.
 1.23.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.23.4.1 23-Mar-2008  matt sync with HEAD
 1.24.8.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.24.6.1 04-Jun-2008  yamt sync with head
 1.24.4.2 17-Jan-2009  mjf Sync with HEAD.
 1.24.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.27.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.41 08-Aug-2019  roy reboot: fix arg order for logwtmpx(3)

Matches the correct order from init(1).

Thanks to Sascha Wildner <swildner@dragonflybsd.org>
 1.40 04-Nov-2012  christos branches: 1.40.30; 1.40.32;
include the headers that we need
 1.39 27-Aug-2011  joerg branches: 1.39.2; 1.39.8;
static + __dead
 1.38 16-Feb-2011  wiz Add -vxz to SYNOPSIS and usage.
 1.37 16-Feb-2011  dyoung Add flags -v, -x, and -z for verbose, debug, and silent shutdowns,
respectively, by passing flags AB_VERBOSE, AB_DEBUG, and/or AB_SILENT to
reboot(2).
 1.36 20-Jul-2008  lukem branches: 1.36.14;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.35 09-Feb-2008  dholland branches: 1.35.4; 1.35.8;
Add warn() in a couple places where it was missing, and clarify one of
the existing warnings slightly. Suggested by PR bin/36551 by Greg A. Woods.
 1.34 17-May-2007  christos branches: 1.34.4; 1.34.6;
Only eat the - if argv[0] starts with a -
 1.33 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.32 04-Apr-2003  perry 1) To eliminate a race condition in which the user could conceivably
try to quit or stop the program right at the moment after the it
sends a TSTP to init, move the kill(1, TSTP) to right after we
block most signals, instead of doing it just before.
2) To add TSTP to the signals we ignore. Once we start halting, it
really is not safe to try to stop at all. You can't change your
mind halfway through -- init will already be stopped and a TERM
will have been sent to everything on the system within
milliseconds of starting.
3) Adjust one comment for TNF
 1.31 02-Aug-2002  wiz Support wtmpx.
 1.30 02-Aug-2002  wiz de__P(), ANSIfy.
 1.29 20-Jul-2002  tsutsui Drop a trailing space in bootstr[] properly.
 1.28 19-Feb-2001  cgd convert to use getprogname()
 1.27 10-Jan-2001  lukem use openlog correctly...
 1.26 25-Apr-2000  hubertf Implement a "poweroff" command which is equivalent to "halt -p",
but allows powering down the system from an exec(2) call, e.g. via
a user which has "poweroff" as login shell.

The command name is modeled after Solaris.
 1.25 07-Mar-2000  jdolecek Ignore SIGPIPE, otherwise we might be stuck when run within a pipe.

Fix from bin/5359 by Nathan J Williams.
 1.24 09-Oct-1998  is Back out the wait-for-slowly-dying-processes change.
 1.23 29-Aug-1998  augustss Ignore some more signal during the reboot. Without this fix it's impossible
to e.g. reboot from a menu in the window manager as the reboot process
gets killed before it is done.
 1.22 26-Jul-1998  mycroft const poisoning.
 1.21 06-Jul-1998  is Change poll interval to 1 seconds, for machines booting _really_ fast.
 1.20 03-Jul-1998  is Make halt and reboot wait up to 32 seconds after kill(-1, SIGTERM), but
check at 3 second intervals if any are left.
This will help slow machines to cleanly shut down X servers (to make the
console visible), databases, or Usenet news servers.
 1.19 06-Jun-1998  thorpej Add a -p option to halt(8), specifying that the system should be powered
down.
 1.18 20-Jan-1998  mycroft Use warn*(3).
 1.17 20-Jan-1998  mycroft Clean up documentation a bit, and document the `-l' option.
 1.16 09-Dec-1997  mrg fix reboot arguments handling (from cgd).
 1.15 15-Sep-1997  lukem branches: 1.15.2;
- use .Nm correctly
- use __progname instead of rindex(argv[0]) ...
 1.14 19-Jul-1997  perry 1) Make WARNS=1 clean
2) to do 1), nuke the silly local version of err()
3) nuke "register" declarations.
 1.13 19-Jul-1997  perry fix pr-2619, from cgd. really obscure bug in exec'ing reboot when single user.
 1.12 17-Jul-1997  perry fix halt when used as login shell, from cgd in pr-2618
 1.11 16-Sep-1996  mrg only log the bootstr if it exists.
 1.10 10-Aug-1996  mrg use the SunOS derived RB_STRING.
 1.9 09-Aug-1996  mrg update for new reboot(2).
 1.8 05-Oct-1995  mycroft Add a `-d' option to force a dump. From John Kohl.
 1.7 18-Mar-1995  cgd pseudo-merge with Lite; man pages need to be merged seperately, but
that's really a port-specific thing. They probably should be updated, too.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 18-Dec-1994  cgd -Wall cleanups from Jim Jegers
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 18-Mar-1995  cgd from Lite
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15.2.1 09-Dec-1997  thorpej Pull up from trunk: fix reboot string passing (mrg)
 1.34.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.34.4.1 23-Mar-2008  matt sync with HEAD
 1.35.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.35.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.36.14.1 17-Feb-2011  bouyer Sync with HEAD
 1.39.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.39.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.40.32.1 09-Aug-2019  martin Pull up following revision(s) (requested by roy in ticket #34):

sbin/reboot/reboot.c: revision 1.41

reboot: fix arg order for logwtmpx(3)
Matches the correct order from init(8).

Thanks to Sascha Wildner <swildner@dragonflybsd.org>
 1.40.30.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.4 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 14-Feb-1994  cgd U* to NetBSD, as appropriate
 1.1 08-Feb-1994  chopps describes amiga's actions on exec of reboot
 1.5 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 14-Feb-1994  cgd U* to NetBSD, as appropriate
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 13-May-1993  cgd add hp300 man page
 1.9 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 14-Feb-1994  cgd U* to NetBSD, as appropriate
 1.6 14-Jan-1994  jtc Fix spelling errors
 1.5 01-Aug-1993  mycroft Add RCS indentifiers.
 1.4 13-Jun-1993  mycroft Update file names. This man page needs some more work.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 14-Feb-1994  cgd U* to NetBSD, as appropriate
 1.1 06-Dec-1993  briggs This is currently just the hp300 man page with the boot sequence
description removed. It needs to describe the macintosh boot
in some detail and perhaps note that the macintosh doesn't work
as described in all cases (yet).
 1.3 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 13-Jun-1994  phil We need this.
 1.4 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 18-Jan-1995  mellon Fixed formatting and expanded content
 1.1 18-Jan-1995  mellon reboot documentation for pmax
 1.4 23-Apr-1995  cgd remove these (deprecated) files. port maintainers were warned about
their impending disappearance a while ago; they can still be retrieved
from the attic.
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 14-Feb-1994  cgd U* to NetBSD, as appropriate
 1.1 13-Feb-1994  deraadt first cut
 1.8 20-Apr-2024  rillig {usr.,}{s,}bin: replace LINT_SUPPORTED with the standard NOLINT

While here, re-enable lint in those cases where lint was skipped due to
a bug in interpreting abstract types, which was fixed in cgram.y 1.469
from 2023-08-02.
 1.7 14-Sep-2021  rillig sbin: enable lint for almost all programs

The programs fsck_lfs and newfs_lfs both trigger a longstanding bug in
lint that is difficult to fix, so ignore them for now.

For resize_ffs, lint thinks that 'struct fs' is incomplete, but GCC and
Clang accept it. Needs further investigation.
 1.6 24-May-2020  jmcneill Use getfsspecname and getrawdiskname so we can resize by NAME= label.
 1.5 06-Apr-2015  jmcneill if the -p flag is specified, display a progress bar while growing the file-system
 1.4 15-Aug-2011  dholland branches: 1.4.20;
WARNS = 4
 1.3 05-Jan-2011  riz Add support for byteswapped file systems (big-endian on little-endian
host, and vice versa), to fix PR#44203.

Add support for growing (but not yet shrinking) UFS2 file systems. Partially
addresses PR#44205.

While I'm here, reformat the code for closer adherence to KNF.

Fairly extensive testing was performed, using the shortly-to-be-committed
updated ATF tests. Patch posted to tech-userlevel on 21 December 2010,
no comments.
 1.2 26-Apr-2009  lukem set WARNS=3 -- too many -Wsign-compare issues in the kernel ffs code
 1.1 21-Feb-2003  jtk branches: 1.1.40; 1.1.42;
Preliminary version of resize_ffs, based on der Mouse's fsresize tool.
I didn't have time to clean it up completely before my legal status
w.r.t. open source projects goes into limbo for a while. Other
developers are encouraged to play with the tool and get it into
release-worthy shape.

TODO list (see TODO file)

* verify it builds on -current, put it into release lists/etc. and src/sbin/Makefile
(built & tested on 1.6.1)
* make it ask questions before doing any work (confirm)
* create regression test suite (see discussions on tech-kern and
developers) and fix any bugs
* verify conversion to ANSI C didn't break anything
* port to UFS2
 1.1.42.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.1.40.1 18-Nov-2011  sborrill Pull up the following revisions(s) (requested by riz in ticket #1690):
distrib/sets/lists/base/mi patch
distrib/sets/lists/man/mi patch
sbin/Makefile patch
sbin/resize_ffs/Makefile patch
sbin/resize_ffs/TODO patch
sbin/resize_ffs/resize_ffs.8 patch
sbin/resize_ffs/resize_ffs.c patch

Fix resize_ffs(8) so that growing and shrinking all FFSv1
(including byteswapped) and growing FFSv2 file systems is supported.
 1.4.20.1 06-Aug-2015  snj Pull up following revision(s) (requested by skrll in ticket #909):
distrib/sets/lists/etc/mi: revision 1.237
distrib/sets/lists/tests/mi: revision 1.613
distrib/utils/embedded/conf/armv7.conf: revisions 1.1, 1.2
distrib/utils/embedded/conf/beagleboard.conf: delete
distrib/utils/embedded/conf/evbarm.conf: revisions 1.21, 1.22
distrib/utils/embedded/conf/rpi.conf: revisions 1.28, 1.29
distrib/utils/embedded/conf/rpi_inst.conf: revisions 1.7, 1.8
distrib/utils/embedded/conf/usermode.conf: revision 1.5
distrib/utils/embedded/conf/x86.conf: revision 1.5
distrib/utils/embedded/files/resize_disklabel: revision 1.1
distrib/utils/embedded/mkimage: revisions 1.49, 1.55-1.59
etc/defaults/rc.conf: revision 1.133
etc/etc.evbarm/Makefile.inc: revisions 1.72, 1.76
etc/rc.d/Makefile: revision 1.93 via patch
etc/rc.d/resize_root: revisions 1.1-1.3
etc/rc.d/root: revision 1.5
sbin/resize_ffs/Makefile: revision 1.5
sbin/resize_ffs/resize_ffs.8: revisions 1.14-1.16
sbin/resize_ffs/resize_ffs.c: revisions 1.39-1.44
share/man/man5/rc.conf.5: revision 1.158, 1.159
tests/sbin/resize_ffs/Makefile: revision 1.4
tests/sbin/resize_ffs/common.sh: revision 1.14
tests/sbin/resize_ffs/t_check.sh: revision 1.1
tests/sbin/resize_ffs/t_grow.sh: revision 1.9
tests/sbin/resize_ffs/t_grow_swapped.sh: revision 1.3
tests/sbin/resize_ffs/t_shrink.sh: revision 1.8
tests/sbin/resize_ffs/t_shrink_swapped.sh: revision 1.2
fix image building:
- round up the total size of the disk image
- fix fdisk offset for netbsd ffs images
--
Make get_dev_size work on regular files too.
--
Use `!= -1' instead of `== 0' out of paranoia.
--
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
--
New sentence, new line. Sort option descriptions.
--
Add resize_root boot operation. If resize_root=YES in rc.conf then
the system attempts to resize the root file system to fill it's
partition prior to mounting read-write. Useful for things like AMI
file system images. May eventually be used by arm images after
coming up with similar solution for increasing the parition size.
--
- Add new tests for -c check flag in resize_ffs
--
Bump date for previous.
it's -> its
--
Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().
--
factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.
--
Add support for auto-growing the root partition. Enable it for rpi.img.
--
initialize resize before pulling in board config
--
add KEYWORD: interactive, honour resize_root_flags and
resize_root_postcmd rc vars
--
if the -p flag is specified, display a progress bar while growing the
file-system
--
show resize_ffs progress bar when resizing root partition
--
fix typo in previous; pass -y unconditionally to resize_ffs, not -p
--
Rename beagleboard.img to armv7.img. The new image includes the same
kernels as beagleboard.img plus support for Raspberry Pi 2, ODROID-C1,
Cubieboard2, Cubietruck, Hummingbird A31, and Banana Pi.
--
Properly spell X' name. From X(7):
The X.Org Foundation requests that the following names be
used when
referring to this software:
X
X Window System
X Version 11
X Window System, Version 11
X11
--
Add some documentation:
Tell what this does, and what it expects from conf files
--
Cleanup: make_filesystems is not used any longer, purge remains
--
More cleanup:
Instead of first overwriting the *_evbarm functions with own code,
and then calling them from the regular functions, directly put the
code into the regular functions.
No more functions from evbarm.conf are used now.
Some variables are still used!
--
define TOOL_MKUBOOTIMAGE for mkimage
--
fix mkubootimage
 1.9 09-Sep-2013  riz Add an item to the list (SIGINFO support).
 1.8 05-Jan-2011  riz branches: 1.8.6; 1.8.12;
Add support for byteswapped file systems (big-endian on little-endian
host, and vice versa), to fix PR#44203.

Add support for growing (but not yet shrinking) UFS2 file systems. Partially
addresses PR#44205.

While I'm here, reformat the code for closer adherence to KNF.

Fairly extensive testing was performed, using the shortly-to-be-committed
updated ATF tests. Patch posted to tech-userlevel on 21 December 2010,
no comments.
 1.7 08-Dec-2010  riz Remove accidentally-resurrected TODO item.
 1.6 08-Dec-2010  riz If we're operating on a plain file instead of a device, ftruncate() it
to ensure it's been properly extended. Clears up some problems at certain
blocksizes which showed up during creation of atf tests, which is done
using file-backed file systems.
 1.5 03-Dec-2010  riz Turns out, plain-file usage is already supported. *blush*
 1.4 02-Dec-2010  riz Knock one off the list.
 1.3 01-Dec-2010  riz Update TODO for resize_ffs(8), adding some stuff and removing some
ancient bits.
 1.2 23-Feb-2003  lukem branches: 1.2.40;
(cross)builds on current ok
 1.1 21-Feb-2003  jtk Preliminary version of resize_ffs, based on der Mouse's fsresize tool.
I didn't have time to clean it up completely before my legal status
w.r.t. open source projects goes into limbo for a while. Other
developers are encouraged to play with the tool and get it into
release-worthy shape.

TODO list (see TODO file)

* verify it builds on -current, put it into release lists/etc. and src/sbin/Makefile
(built & tested on 1.6.1)
* make it ask questions before doing any work (confirm)
* create regression test suite (see discussions on tech-kern and
developers) and fix any bugs
* verify conversion to ANSI C didn't break anything
* port to UFS2
 1.2.40.1 18-Nov-2011  sborrill Pull up the following revisions(s) (requested by riz in ticket #1690):
distrib/sets/lists/base/mi patch
distrib/sets/lists/man/mi patch
sbin/Makefile patch
sbin/resize_ffs/Makefile patch
sbin/resize_ffs/TODO patch
sbin/resize_ffs/resize_ffs.8 patch
sbin/resize_ffs/resize_ffs.c patch

Fix resize_ffs(8) so that growing and shrinking all FFSv1
(including byteswapped) and growing FFSv2 file systems is supported.
 1.8.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.18 01-Oct-2017  christos PR/52590: David H. Gutteridge: Minor documentation improvements
 1.17 12-Sep-2016  sevan branches: 1.17.6;
Replace contractions.
 1.16 06-Apr-2015  jmcneill if the -p flag is specified, display a progress bar while growing the file-system
 1.15 29-Mar-2015  wiz New sentence, new line. Sort option descriptions.
 1.14 29-Mar-2015  chopps - Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
 1.13 28-Aug-2011  wiz branches: 1.13.20;
Move a sentence to where it makes more sense.
 1.12 28-Aug-2011  wiz New sentence, new line.
 1.11 27-Aug-2011  christos PR/45301: Julian Fagir: make clear that the unit is sectors and fix a typo.
While there, use errx, and sizeof(*var) instead of sizeof(type)
 1.10 05-Jan-2011  riz Add support for byteswapped file systems (big-endian on little-endian
host, and vice versa), to fix PR#44203.

Add support for growing (but not yet shrinking) UFS2 file systems. Partially
addresses PR#44205.

While I'm here, reformat the code for closer adherence to KNF.

Fairly extensive testing was performed, using the shortly-to-be-committed
updated ATF tests. Patch posted to tech-userlevel on 21 December 2010,
no comments.
 1.9 20-Dec-2010  riz Revert previous - inadvertant commit to wrong repository.
 1.8 20-Dec-2010  riz Pull in change from njoly@ in -current
 1.7 19-Dec-2010  njoly Add missing .Os macro.
 1.6 14-Dec-2010  wiz filesystem -> file system.
 1.5 31-Oct-2010  wiz Various improvements.
 1.4 30-Oct-2010  haad Add resize_ffs tool to build, change default behaviour to grow filesystem
to device size. Add parameter -s to specify size if user want to shrink
filesystem.

Apply some KNF, remove dead unused code.

Oked by christos@.
 1.3 10-Mar-2003  wiz branches: 1.3.40;
Sort sections; "file system" instead of filesystem; mdoc improvements;
new sentenence, new line.
 1.2 23-Feb-2003  lukem minor cosmetic tweak
 1.1 21-Feb-2003  jtk Preliminary version of resize_ffs, based on der Mouse's fsresize tool.
I didn't have time to clean it up completely before my legal status
w.r.t. open source projects goes into limbo for a while. Other
developers are encouraged to play with the tool and get it into
release-worthy shape.

TODO list (see TODO file)

* verify it builds on -current, put it into release lists/etc. and src/sbin/Makefile
(built & tested on 1.6.1)
* make it ask questions before doing any work (confirm)
* create regression test suite (see discussions on tech-kern and
developers) and fix any bugs
* verify conversion to ANSI C didn't break anything
* port to UFS2
 1.3.40.1 18-Nov-2011  sborrill Pull up the following revisions(s) (requested by riz in ticket #1690):
distrib/sets/lists/base/mi patch
distrib/sets/lists/man/mi patch
sbin/Makefile patch
sbin/resize_ffs/Makefile patch
sbin/resize_ffs/TODO patch
sbin/resize_ffs/resize_ffs.8 patch
sbin/resize_ffs/resize_ffs.c patch

Fix resize_ffs(8) so that growing and shrinking all FFSv1
(including byteswapped) and growing FFSv2 file systems is supported.
 1.13.20.2 23-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #1516):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.13.20.1 06-Aug-2015  snj branches: 1.13.20.1.2; 1.13.20.1.6;
Pull up following revision(s) (requested by skrll in ticket #909):
distrib/sets/lists/etc/mi: revision 1.237
distrib/sets/lists/tests/mi: revision 1.613
distrib/utils/embedded/conf/armv7.conf: revisions 1.1, 1.2
distrib/utils/embedded/conf/beagleboard.conf: delete
distrib/utils/embedded/conf/evbarm.conf: revisions 1.21, 1.22
distrib/utils/embedded/conf/rpi.conf: revisions 1.28, 1.29
distrib/utils/embedded/conf/rpi_inst.conf: revisions 1.7, 1.8
distrib/utils/embedded/conf/usermode.conf: revision 1.5
distrib/utils/embedded/conf/x86.conf: revision 1.5
distrib/utils/embedded/files/resize_disklabel: revision 1.1
distrib/utils/embedded/mkimage: revisions 1.49, 1.55-1.59
etc/defaults/rc.conf: revision 1.133
etc/etc.evbarm/Makefile.inc: revisions 1.72, 1.76
etc/rc.d/Makefile: revision 1.93 via patch
etc/rc.d/resize_root: revisions 1.1-1.3
etc/rc.d/root: revision 1.5
sbin/resize_ffs/Makefile: revision 1.5
sbin/resize_ffs/resize_ffs.8: revisions 1.14-1.16
sbin/resize_ffs/resize_ffs.c: revisions 1.39-1.44
share/man/man5/rc.conf.5: revision 1.158, 1.159
tests/sbin/resize_ffs/Makefile: revision 1.4
tests/sbin/resize_ffs/common.sh: revision 1.14
tests/sbin/resize_ffs/t_check.sh: revision 1.1
tests/sbin/resize_ffs/t_grow.sh: revision 1.9
tests/sbin/resize_ffs/t_grow_swapped.sh: revision 1.3
tests/sbin/resize_ffs/t_shrink.sh: revision 1.8
tests/sbin/resize_ffs/t_shrink_swapped.sh: revision 1.2
fix image building:
- round up the total size of the disk image
- fix fdisk offset for netbsd ffs images
--
Make get_dev_size work on regular files too.
--
Use `!= -1' instead of `== 0' out of paranoia.
--
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
--
New sentence, new line. Sort option descriptions.
--
Add resize_root boot operation. If resize_root=YES in rc.conf then
the system attempts to resize the root file system to fill it's
partition prior to mounting read-write. Useful for things like AMI
file system images. May eventually be used by arm images after
coming up with similar solution for increasing the parition size.
--
- Add new tests for -c check flag in resize_ffs
--
Bump date for previous.
it's -> its
--
Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().
--
factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.
--
Add support for auto-growing the root partition. Enable it for rpi.img.
--
initialize resize before pulling in board config
--
add KEYWORD: interactive, honour resize_root_flags and
resize_root_postcmd rc vars
--
if the -p flag is specified, display a progress bar while growing the
file-system
--
show resize_ffs progress bar when resizing root partition
--
fix typo in previous; pass -y unconditionally to resize_ffs, not -p
--
Rename beagleboard.img to armv7.img. The new image includes the same
kernels as beagleboard.img plus support for Raspberry Pi 2, ODROID-C1,
Cubieboard2, Cubietruck, Hummingbird A31, and Banana Pi.
--
Properly spell X' name. From X(7):
The X.Org Foundation requests that the following names be
used when
referring to this software:
X
X Window System
X Version 11
X Window System, Version 11
X11
--
Add some documentation:
Tell what this does, and what it expects from conf files
--
Cleanup: make_filesystems is not used any longer, purge remains
--
More cleanup:
Instead of first overwriting the *_evbarm functions with own code,
and then calling them from the regular functions, directly put the
code into the regular functions.
No more functions from evbarm.conf are used now.
Some variables are still used!
--
define TOOL_MKUBOOTIMAGE for mkimage
--
fix mkubootimage
 1.13.20.1.6.1 23-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #1516):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.13.20.1.2.1 23-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #1516):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.17.6.1 24-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #308):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.58 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.57 17-Nov-2022  chs branches: 1.57.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.56 08-Apr-2022  andvar fix various typos, mainly in comments, but also log messages, docs, game text.
 1.55 24-May-2020  jmcneill Use getfsspecname and getrawdiskname so we can resize by NAME= label.
 1.54 21-Apr-2019  maya wether -> whether
 1.53 09-Oct-2017  mlelstv branches: 1.53.4;
Fix computation of left-over fragments also for ufs2.

Fixes PR 52600.
 1.52 01-Oct-2017  christos PR/52590: David H. Gutteridge: Minor documentation improvements
 1.51 01-Oct-2017  mlelstv - More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
 1.50 30-Sep-2017  kre Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
 1.49 30-Sep-2017  riastradh Use int64_t for loop index so we don't iterate forever/until trap.
 1.48 28-Sep-2017  sborrill Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@

For example:

# df /data
Filesystem 1K-blocks Used Avail %Cap Mounted on
/dev/ccd0d -19974939099004 -19982708701532 -737868756431824584 0% /data

# dumpfs -s /dev/rccd0d
file system: /dev/rccd0d
format FFSv2
endian little-endian
location 65536 (-b 128)
magic 19540119 time Thu Sep 28 13:18:10 2017
superblock location 65536 id [ 595fa4a5 3363fe37 ]
cylgrp dynamic inodes FFSv2 sblock FFSv2 fslevel 5
nbfree 242773148 ndir 211185 nifree 650798800 nffree
215448
ncg 13933 size 2647654400 blocks -4993734774751
bsize 32768 shift 15 mask 0xffff8000
fsize 4096 shift 12 mask 0xfffff000
frag 8 shift 3 fsbtodb 3
bpg 23754 fpg 190032 ipg 46848
minfree 5% optim time maxcontig 2 maxbpg 4096
symlinklen 120 contigsumsize 2
maxfilesize 0x000800800805ffff
nindir 4096 inopb 128
avgfilesize 16384 avgfpdir 64
sblkno 24 cblkno 32 iblkno 40 dblkno 2968
sbsize 4096 cgsize 32768
csaddr 35792 cssize 225280
cgrotor 0 fmod 0 ronly 0 clean 0x01
wapbl version 0x1 location 2 flags 0x0
wapbl loc0 6354693888 loc1 131072 loc2 512 loc3 3
flags none
fsmnt /data
volname swuid 0
 1.47 24-Aug-2016  dholland branches: 1.47.6;
Fix handling of ffsv2 inode initialization. Retires PR 51116.
 1.46 17-Mar-2016  christos fix pasto
 1.45 17-Mar-2016  christos Appease gcc-5 from phone@
 1.44 06-Apr-2015  jmcneill if the -p flag is specified, display a progress bar while growing the file-system
 1.43 06-Apr-2015  mlelstv factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.
 1.42 06-Apr-2015  mlelstv Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().
 1.41 29-Mar-2015  chopps - Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
 1.40 28-Mar-2015  riastradh Use `!= -1' instead of `== 0' out of paranoia.
 1.39 28-Mar-2015  riastradh Make get_dev_size work on regular files too.
 1.38 23-Jun-2013  dholland branches: 1.38.6;
Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.37 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.36 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.35 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.34 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.33 20-Apr-2012  christos branches: 1.33.2;
fix cast in local macro
 1.32 27-Aug-2011  christos branches: 1.32.2;
PR/45301: Julian Fagir: make clear that the unit is sectors and fix a typo.
While there, use errx, and sizeof(*var) instead of sizeof(type)
 1.31 15-Aug-2011  dholland Fix another dodgy switch-jump.
 1.30 15-Aug-2011  dholland WARNS = 4
 1.29 15-Aug-2011  dholland Add missing __RCSID().
 1.28 15-Aug-2011  dholland Whitespace.
 1.27 15-Aug-2011  dholland Avoid switch-jumping into the middle of an if. Compiler output is unchanged.
 1.26 15-Aug-2011  dholland Minor KNF.
 1.25 05-Jan-2011  riz Add support for byteswapped file systems (big-endian on little-endian
host, and vice versa), to fix PR#44203.

Add support for growing (but not yet shrinking) UFS2 file systems. Partially
addresses PR#44205.

While I'm here, reformat the code for closer adherence to KNF.

Fairly extensive testing was performed, using the shortly-to-be-committed
updated ATF tests. Patch posted to tech-userlevel on 21 December 2010,
no comments.
 1.24 14-Dec-2010  wiz filesystem -> file system.
 1.23 14-Dec-2010  riz Be explicit about byteswapped and ffsv2 file systems being currently
unsupported, while catching up to some changes in my local tree which
will hopefully support them at some time in the future.

Also, change "device" variable to "special", to reflect the fact
that resize_ffs will work on a plain file.
 1.22 14-Dec-2010  riz Don't special-case v1 superblocks - especially with an incorrect
calculation.
 1.21 12-Dec-2010  riz Remove bogus check which is not actually testing anything useful,
and depending on file system data, can actually be a false error.

Fixes what I was actually testing for in bin/44209, though the
actual problem was not what I originally described.
 1.20 12-Dec-2010  mhitch Add support for old ffsv1 superblocks. After reading an old superblock,
copy appropriate data to where they are expected in the updated superblock.
When writing the updated superblock, move the updated values back to the
old ffsv1 superblock locations. Also check for old superblock format when
updating the last cylinder group and adjust cg_old_ncyl appropriately.
Derived from how mksf sets them. Should address PR bin/44209.
 1.19 08-Dec-2010  riz If we're operating on a plain file instead of a device, ftruncate() it
to ensure it's been properly extended. Clears up some problems at certain
blocksizes which showed up during creation of atf tests, which is done
using file-backed file systems.
 1.18 07-Dec-2010  riz As currently written, writeat() expects disk blocks, not fs blocks, so
when testing that the last sector of the new size is writeable, make
sure we're ACTUALLY writing in the new space, instead of possibly
overwriting something in the existing fs.

Discovered while writing tests - tests which uncovered file corruption at
certain block sizes.

XXX should rewrite writeat() to expect fs blocks instead of disk blocks.

OK mlelstv@
 1.17 02-Dec-2010  riz Use howmany() instead of "/" to calculate the number of cylinders for
the changed file system, so as to not drop a partial cylinder at the
end. Fixes PR bin/44177.
 1.16 01-Dec-2010  riz Do not look for a v1 file system at SBLOCK_UFS2, as this gets the wrong
superblock (first alternate) for a file system with 64k blocks.
Spotted by mhitch@.
 1.15 01-Dec-2010  riz Clean up this file:

- sync usage comment with current reality
- sort includes
- wrap lines
- use EXIT_FAILURE consistently
- make error messages consistent: Cannot->Can't
- Remove "Old FFSv1 macros" in favor of system macros in ufs/ffs/fs.h .
Leave dblksize() because it uses the on-disk dinode structure.

More cleanup is needed.
No functional changes intended.
 1.14 29-Nov-2010  riz Restore a couple of checks for updating the cg_old_ncyl value which
were commented out with XXX and a notation to "fix once fsck is fixed."
fsck seems to have been fixed for this particular issue sometime in the
7 years since the code was brought into the tree.

Update cg_old_niblk instead of cg_ni_blk, since this tool
currently supports ffsv1 only.

With these two changes, I can grow a file system and have the result
be clean according to fsck_ffs. Shrinking still results in an unclean
file system.

OK mhitch@

While I'm here, fix a typo in an error message.
 1.13 30-Oct-2010  haad Add resize_ffs tool to build, change default behaviour to grow filesystem
to device size. Add parameter -s to specify size if user want to shrink
filesystem.

Apply some KNF, remove dead unused code.

Oked by christos@.
 1.12 15-Dec-2007  perry branches: 1.12.10;
convert __attribute__s to applicable cdefs.h macros
 1.11 15-Dec-2007  perry include sys/cdefs.h so that __attribute__ can be fixed later
 1.10 08-Jul-2007  bouyer branches: 1.10.4; 1.10.6;
writeat() also expect offsets in DEV_BSIZE unit. This and the previous commit
should fix PR bin/35560. Thanks to Michael L. Hitch for pointing me at the
PR.
 1.9 05-Jul-2007  bouyer readat() expects the offset in DEV_BSIZE units. This made resize_ffs find the
filesystem on a vnd partition for me. It did grow the filesystem, and after
a fsck -f on the partition to fix a few superblock inconsistencies, all
looks good.
 1.8 03-Jun-2005  snj Fix a typo in a comment.
 1.7 21-Mar-2004  dsl Dunno why this code is playing 'hunt the superblock', but stop it
finding an ffsv1 sb at 64k.
Also stop it playing with fs that have 'FS_FLAGS_UPDATED' set.
It certainly doesn't act on that falg, and my guess is that it is
playing the pre-ffsv2 fs.
Fixes part of PR kern/24809
 1.6 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.5 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.4 03-Apr-2003  christos make this compile again.
 1.3 10-Mar-2003  wiz Correct program name in comments.
 1.2 21-Feb-2003  martin This program deals with on-disk structures.
s/daddr_t/int32_t/g for now (UFS2 will need other changes as well).
 1.1 21-Feb-2003  jtk Preliminary version of resize_ffs, based on der Mouse's fsresize tool.
I didn't have time to clean it up completely before my legal status
w.r.t. open source projects goes into limbo for a while. Other
developers are encouraged to play with the tool and get it into
release-worthy shape.

TODO list (see TODO file)

* verify it builds on -current, put it into release lists/etc. and src/sbin/Makefile
(built & tested on 1.6.1)
* make it ask questions before doing any work (confirm)
* create regression test suite (see discussions on tech-kern and
developers) and fix any bugs
* verify conversion to ANSI C didn't break anything
* port to UFS2
 1.10.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.10.4.1 09-Jan-2008  matt sync with HEAD
 1.12.10.1 18-Nov-2011  sborrill Pull up the following revisions(s) (requested by riz in ticket #1690):
distrib/sets/lists/base/mi patch
distrib/sets/lists/man/mi patch
sbin/Makefile patch
sbin/resize_ffs/Makefile patch
sbin/resize_ffs/TODO patch
sbin/resize_ffs/resize_ffs.8 patch
sbin/resize_ffs/resize_ffs.c patch

Fix resize_ffs(8) so that growing and shrinking all FFSv1
(including byteswapped) and growing FFSv2 file systems is supported.
 1.32.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.32.2.2 23-Jan-2013  yamt sync with head
 1.32.2.1 23-May-2012  yamt sync with head.
 1.33.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.33.2.2 23-Jun-2013  tls resync from head
 1.33.2.1 25-Feb-2013  tls resync with head
 1.38.6.3 23-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #1516):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.38.6.2 10-Sep-2016  snj branches: 1.38.6.2.2;
Pull up following revision(s) (requested by dholland in ticket #1242):
sbin/resize_ffs/resize_ffs.c: revision 1.47
Fix handling of ffsv2 inode initialization. Retires PR 51116.
 1.38.6.1 06-Aug-2015  snj branches: 1.38.6.1.2; 1.38.6.1.4;
Pull up following revision(s) (requested by skrll in ticket #909):
distrib/sets/lists/etc/mi: revision 1.237
distrib/sets/lists/tests/mi: revision 1.613
distrib/utils/embedded/conf/armv7.conf: revisions 1.1, 1.2
distrib/utils/embedded/conf/beagleboard.conf: delete
distrib/utils/embedded/conf/evbarm.conf: revisions 1.21, 1.22
distrib/utils/embedded/conf/rpi.conf: revisions 1.28, 1.29
distrib/utils/embedded/conf/rpi_inst.conf: revisions 1.7, 1.8
distrib/utils/embedded/conf/usermode.conf: revision 1.5
distrib/utils/embedded/conf/x86.conf: revision 1.5
distrib/utils/embedded/files/resize_disklabel: revision 1.1
distrib/utils/embedded/mkimage: revisions 1.49, 1.55-1.59
etc/defaults/rc.conf: revision 1.133
etc/etc.evbarm/Makefile.inc: revisions 1.72, 1.76
etc/rc.d/Makefile: revision 1.93 via patch
etc/rc.d/resize_root: revisions 1.1-1.3
etc/rc.d/root: revision 1.5
sbin/resize_ffs/Makefile: revision 1.5
sbin/resize_ffs/resize_ffs.8: revisions 1.14-1.16
sbin/resize_ffs/resize_ffs.c: revisions 1.39-1.44
share/man/man5/rc.conf.5: revision 1.158, 1.159
tests/sbin/resize_ffs/Makefile: revision 1.4
tests/sbin/resize_ffs/common.sh: revision 1.14
tests/sbin/resize_ffs/t_check.sh: revision 1.1
tests/sbin/resize_ffs/t_grow.sh: revision 1.9
tests/sbin/resize_ffs/t_grow_swapped.sh: revision 1.3
tests/sbin/resize_ffs/t_shrink.sh: revision 1.8
tests/sbin/resize_ffs/t_shrink_swapped.sh: revision 1.2
fix image building:
- round up the total size of the disk image
- fix fdisk offset for netbsd ffs images
--
Make get_dev_size work on regular files too.
--
Use `!= -1' instead of `== 0' out of paranoia.
--
- Add -c to check to see if grow/shrink is required
- Divide by DEV_BSIZE when returning size of file.
- Update manpage
--
New sentence, new line. Sort option descriptions.
--
Add resize_root boot operation. If resize_root=YES in rc.conf then
the system attempts to resize the root file system to fill it's
partition prior to mounting read-write. Useful for things like AMI
file system images. May eventually be used by arm images after
coming up with similar solution for increasing the parition size.
--
- Add new tests for -c check flag in resize_ffs
--
Bump date for previous.
it's -> its
--
Handle case in grow() where last cylinder group is too small for ufs2.
Align with code in shrink().
--
factor out geometry calculation and use this also in CheckOnly mode.
be a bit more verbose in Verbose mode.
--
Add support for auto-growing the root partition. Enable it for rpi.img.
--
initialize resize before pulling in board config
--
add KEYWORD: interactive, honour resize_root_flags and
resize_root_postcmd rc vars
--
if the -p flag is specified, display a progress bar while growing the
file-system
--
show resize_ffs progress bar when resizing root partition
--
fix typo in previous; pass -y unconditionally to resize_ffs, not -p
--
Rename beagleboard.img to armv7.img. The new image includes the same
kernels as beagleboard.img plus support for Raspberry Pi 2, ODROID-C1,
Cubieboard2, Cubietruck, Hummingbird A31, and Banana Pi.
--
Properly spell X' name. From X(7):
The X.Org Foundation requests that the following names be
used when
referring to this software:
X
X Window System
X Version 11
X Window System, Version 11
X11
--
Add some documentation:
Tell what this does, and what it expects from conf files
--
Cleanup: make_filesystems is not used any longer, purge remains
--
More cleanup:
Instead of first overwriting the *_evbarm functions with own code,
and then calling them from the regular functions, directly put the
code into the regular functions.
No more functions from evbarm.conf are used now.
Some variables are still used!
--
define TOOL_MKUBOOTIMAGE for mkimage
--
fix mkubootimage
 1.38.6.2.2.1 23-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #1516):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.38.6.1.4.1 18-Jan-2017  skrll Sync with netbsd-5
 1.38.6.1.2.1 23-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #1516):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.47.6.1 24-Oct-2017  snj Pull up following revision(s) (requested by sborrill in ticket #308):
sbin/resize_ffs/resize_ffs.8: revision 1.18
sbin/resize_ffs/resize_ffs.c: revision 1.48-1.53
Fix the most obvious integer overflow errors which can lead to superblock
corruption. Thanks to riastradh@
--
Use int64_t for loop index so we don't iterate forever/until trap.
--
Fix the syntax (pointed out by David H. Gutteridge on source-changes-d).
Fix the build...
--
- More fixes to use 64bit offsets.
- Compute left-over fragments also for FFS2.
--
PR/52590: David H. Gutteridge: Minor documentation improvements
--
Fix computation of left-over fragments also for ufs2.
Fixes PR 52600.
 1.53.4.1 10-Jun-2019  christos Sync with HEAD
 1.57.2.1 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.8 18-Sep-2025  mrg introduce a couple of new turn-off-gcc-warning variables and use them.

GCC 14 has a new annoying calloc() checker that we turn off in a bunch
of places, and there are a few more dangling-pointer issuse that come up,
but seem bogus.
 1.7 07-Sep-2020  mrg remove GCC_NO_ADDR_OF_PACKED_MEMBER for several subdir builds
that are now handled by lfs_accessors.h internally.
 1.6 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.5 05-Jun-2009  haad Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.4 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.3 07-Sep-2006  riz branches: 1.3.28;
include <bsd.own.mk>. From Geoff Wing on source-changes.
 1.2 05-Sep-2006  riz Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. (Shrinking a file system still seems to have problems,
though, independent of this change)
 1.1 23-Apr-2005  perseant branches: 1.1.2;
Provide a resize_lfs(8), including kernel and cleaner support. The current
implementation requires the fs to be mounted while resizing. Tested in both
directions, and everything appears to work happily, but ymmv.
 1.1.2.2 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.1.2.1 23-Apr-2005  tron file Makefile was added on branch netbsd-3 on 2005-05-07 15:18:05 +0000
 1.3.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.6 11-Mar-2009  joerg Fix preamble
 1.5 30-Apr-2008  martin branches: 1.5.6;
Convert TNF licenses to new 2 clause variant
 1.4 04-Sep-2006  wiz branches: 1.4.18; 1.4.20;
Bump date for previous.
 1.3 04-Sep-2006  riz Correct usage: "-s" is the flag for the new size of the LFS, not "-n".
 1.2 25-Apr-2005  wiz branches: 1.2.2;
New sentence, new line; non-argument options before
options with arguments (in SYNOPSIS); use standard section headers;
describe example.
 1.1 23-Apr-2005  perseant Provide a resize_lfs(8), including kernel and cleaner support. The current
implementation requires the fs to be mounted while resizing. Tested in both
directions, and everything appears to work happily, but ymmv.
 1.2.2.2 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.2.2.1 25-Apr-2005  tron file resize_lfs.8 was added on branch netbsd-3 on 2005-05-07 15:18:05 +0000
 1.4.20.1 18-May-2008  yamt sync with head.
 1.4.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.16 07-Aug-2023  mrg fix potentially uninitialised data being used.

found by GCC 12.
 1.15 22-Aug-2019  brad Use getdiskrawname to find the device name.

Reviewed by Christos
 1.14 02-Aug-2015  dholland branches: 1.14.16; 1.14.18;
Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.13 02-Aug-2015  dholland Don't include ufs headers.
 1.12 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.11 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.10 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.9 23-Mar-2014  dholland missed one
 1.8 23-Mar-2014  dholland don't use sprintf
 1.7 19-Jun-2013  christos make this compile again
 1.6 28-Apr-2008  martin branches: 1.6.20; 1.6.26;
Remove clause 3 and 4 from TNF licenses
 1.5 11-Nov-2006  jmmv branches: 1.5.18; 1.5.20;
Move lfs_cleanerd from /usr/libexec to /libexec. This is to allow putting
the root file system on a LFS volume.

Addresses PR bin/30407. No objections in tech-userlevel@.
 1.4 05-Sep-2006  riz Deal with wedges and the new disk geometry structures, instead of using
struct disklabel. (Shrinking a file system still seems to have problems,
though, independent of this change)
 1.3 04-Sep-2006  wiz errx() provides a newline on its own, so remove the one from the error string.
 1.2 02-Jun-2005  lukem Ensure verbose is initialized before using it.
Detected by gcc -Wuninitialized.
 1.1 23-Apr-2005  perseant branches: 1.1.2;
Provide a resize_lfs(8), including kernel and cleaner support. The current
implementation requires the fs to be mounted while resizing. Tested in both
directions, and everything appears to work happily, but ymmv.
 1.1.2.3 14-Jun-2005  tron Pull up revision 1.2 (requested by lukem in ticket #403):
Ensure verbose is initialized before using it.
Detected by gcc -Wuninitialized.
 1.1.2.2 07-May-2005  tron Apply patch (requested by perseant in ticket #242):
* fsck_lfs buffer cache fixes, including PR #29151
* Change fsck_lfs phase 0 message to reflect reality
* fsck_lfs: check phase 5 (cleanerinfo accounting) even on
roll-forward
* Keep better track of the free list during roll-forward, avoiding
a core dump
* Improve hash table use for fsck_lfs buffer and vnode cache
* Document fsck_lfs flag -f, and implement -q
* Add resize_lfs, including kernel support
* Add LFS to mountd's list of exportable filesystem types
* Make the LFS lkm work again [christos@]
* Add MP locking to the LFS kernel subsystem
* Fix pager_map deadlock in lfs_putpages()
* Avoid incomplete file extension that looks like "partial
truncation" to fsck
* Use lfs_malloc for cleaner malloc, since the cleaner often runs
in low-memory conditions.
* Use splay trees, not hash table, to track page allocation for
write.
* Fix mkdir panic on full fs
* Fix page accounting leak by counting differently.
* Use rightly named structure for lfs_getattr [skrll@]
* Cosmetic changes for readability.
 1.1.2.1 23-Apr-2005  tron file resize_lfs.c was added on branch netbsd-3 on 2005-05-07 15:18:05 +0000
 1.5.20.1 18-May-2008  yamt sync with head.
 1.5.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.26.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.6.26.1 23-Jun-2013  tls resync from head
 1.6.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14.18.1 02-Sep-2019  martin Pull up following revision(s) (requested by brad in ticket #110):

libexec/lfs_cleanerd/lfs_cleanerd.c: revision 1.59
libexec/lfs_cleanerd/lfs_cleanerd.8: revision 1.19
sbin/resize_lfs/resize_lfs.c: revision 1.15
usr.sbin/puffs/rump_lfs/rump_lfs.c: revision 1.19
libexec/lfs_cleanerd/lfs_cleanerd.c: revision 1.60
lib/libutil/getdiskrawname.c: revision 1.6
tests/fs/common/fstest_lfs.c: revision 1.7

Use getdiskrawname to find the device name.
Reviewed by Christos

-

Teach getdiskrawname and getdiskcookedname about zvols.
Reviewed by Christos

-

Add support for passing the raw device name separate from the
filesystem. This is useful in the case where the cleaner is compiled
into code, such as rump_lfs and the ATF tests. This helps to fix
bin/54488

-

The cleaner is compiled into rump_lfs and executed as a thread. Pass
in the raw device using the new -J option. This avoids the use of
getdiskrawname which is not particularly rump safe in this context and
insures that the rump container device is used for cleaning, not the
outer device.
 1.14.16.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.28 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.27 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.26 06-Aug-2011  dholland branches: 1.26.42;
Add wrapper functions around hash algorithm operations to avoid
undefined behavior arising from illegal function casts. As a side
effect, no longer need -Wno-pointer-sign either.
 1.25 20-Jun-2011  mrg remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.24 29-Aug-2008  gmcgarry branches: 1.24.16;
Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.23 11-May-2006  mrg branches: 1.23.20; 1.23.24;
sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.22 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.21 04-Feb-2001  christos revert previous change; not needed.
 1.20 04-Feb-2001  christos fix nested extern
 1.19 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.18 30-Jun-1997  lukem There's no need to install restore(8) setgid tty.
 1.17 27-May-1997  mrg remove the setuid bit.
 1.16 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.15 06-May-1997  gwr Use .PATH.c: ...
 1.14 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.13 22-Dec-1994  cgd specify man pages the new way.
 1.12 17-Jun-1994  mycroft Fix a couple of Makefile bogons.
 1.11 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.10 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.9 14-Nov-1993  cgd from Thomas Eberhardt <thomas@mathematik.uni-Bremen.de>:
Some reordering and modifications in the Makefiles for sh, dump,
restore to get dependicies right. The README in /usr/share/mk
states that it's a Bad Thing(tm) to add something after
.include <bsd.prog.mk>, but this seems the only way to get the
dependencies right.
 1.8 12-Nov-1993  cgd oops; fix that last
 1.7 12-Nov-1993  cgd add LDSTATIC
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 18-Jul-1993  mycroft Use ${COPY}, not -c for install.
 1.4 18-Apr-1993  mycroft Okay, so I was confused (but only a little).
 1.3 18-Apr-1993  mycroft Make rrestore target match normal program target.
(This should be in a separate directory, no?)
 1.2 08-Apr-1993  cgd make it copy when installing
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.23.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.23.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.24.16.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.26.42.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.55 12-Dec-2022  chs apply this commit from FreeBSD:

commit 9dda00df7e8f9279a43d92758df6a7e10a9aed95
Author: Chuck Silvers <chs@FreeBSD.org>
Date: Mon Dec 12 08:14:17 2022 -0800

restore: fix restore of NFS4 ACLs

Changing the mode bits on a file with an NFS4 ACL results in the
NFS4 ACL being replaced by one matching the new mode bits being set,
so when restoring a file with an NFS4 ACL, set the owner/group/mode first
and then set the NFS4 ACL, so that setting the mode does not throw away
the ACL that we just set.

Reviewed by: mckusick
Differential Revision: https://reviews.freebsd.org/D37618
 1.54 10-Dec-2022  chs apply this change from FreeBSD:

commit c028393d7072f1f88efd8d6e6c77bb9b15b3f3b6
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Fri Apr 11 21:48:14 2008 +0000

Correctly set file group when restore is run by a user other than root.
 1.53 23-Jun-2021  riastradh restore(8): Mark fail_dirtmp __dead to fix clang build.
 1.52 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.51 02-Mar-2015  enami Don't truncate at microseconds while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html
 1.50 09-Jun-2013  dholland branches: 1.50.6; 1.50.8;
Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.49 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.48 07-Apr-2009  lukem branches: 1.48.6; 1.48.12;
fix sign-compare issues
 1.47 18-Feb-2009  yamt remove a useless cast.
 1.46 19-Aug-2005  christos branches: 1.46.30;
64 bit inode changes
 1.45 27-Jun-2005  christos add const
 1.44 27-Jun-2005  christos sprinkle const.
 1.43 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.42 08-Jan-2005  fredb Make a judicious choice as to whether to apply the permissions
of the root inode of the dump to the current working directory,
rather than interrogate the user. Closes PR bin/24690. Reviewed
by bouyer, tron, imp.
 1.41 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.40 05-Nov-2003  fvdl Fix byteswapping a direntry. From Wolfgang Solfrank.
 1.39 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.38 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.37 09-May-2002  simonb Don't bother testing if a uint8_t is > 256 -- that test is always false.
 1.36 04-Jan-2002  lukem oops; another minor fix from rev 1.34 noticed by Simon Gerraty
 1.35 01-Nov-2001  lukem oops, remove temporary comment
 1.34 01-Nov-2001  lukem fix -Wshadow warnings
 1.33 12-May-1998  enami Don't actually set attributes of directory if -N flag is given.
 1.32 18-Mar-1998  bouyer Update for new headers.
 1.31 19-Oct-1997  mycroft Use futimes(2). Do {f,}utimes(2) *before* {f,}chflags(2), for obvious
reasons.
 1.30 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.29 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.28 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.27 06-Jul-1997  lukem as inspired by a commit message of Todd Miller <millert@cvs.openbsd.org>:
* cleanup a bit for -Wall
* use __progname instead of "restore"
 1.26 01-Jul-1997  lukem Support using $TMPDIR for rst{dir,modes}* files, so that large
restores can be done on machines with small /tmp's by setting TMPDIR
elsewhere. This shouldn't be a security issue as restore(8) isn't
set?id anymore.
 1.25 03-Jun-1997  lukem explicitly \0 terminate locname[] in treescan(). should fix [bin/2093]
 1.24 17-May-1997  pk * NULL => 0 (Arne Juul; PR#3629)
* Nuke spacoids
 1.23 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h> instead of "pathnames.h"
cleanup references/examples to use /dev/rst* instead of /dev/rmt*
minor .Nm usage cleanup in man page
 1.22 19-Mar-1997  lukem * use mkstemp() instead of mktemp()
* remove "register" qualifiers
 1.21 30-Nov-1996  cgd patches from Tom I Helbekkmo <tih@nhh.no> to deal with type-size issues,
so this works (better, at least) on 64-bit machines (e.g. alpha).
 1.20 24-Oct-1996  lukem use unique temporary files for all operations except 'r' and 'R', which still
base temp files on dumpdate. explain why in the man page. fixes [bin/2870]
 1.19 27-Sep-1996  thorpej Use snprintf() rather than sprintf().
 1.18 27-Sep-1996  thorpej Back out last change (and re-open PR); the patch is incomplete, and
I realized it _just_ as CVS checked the file back in.
 1.17 27-Sep-1996  thorpej Make unique temporary file names.
From Luke Mewburn <lukem@supp.cpr.itg.telecom.com.au>, PR #2544.
 1.16 19-Jun-1995  cgd branches: 1.16.6;
stat structure POSIXification
 1.15 11-Jun-1995  mycroft Back out previous change.
 1.14 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.11 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.10 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.9 18-Jun-1994  mycroft Simplify that code a little.
 1.8 18-Jun-1994  mycroft Fix a byte-order problem when reading directory entries from old file systems
that were on little-endian machines.
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 17-May-1994  cgd copyright foo
 1.5 25-Apr-1994  cgd kill some #ifndefs
 1.4 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.3 03-Aug-1993  mycroft Add an #endif I forgot.
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.6.1 06-Dec-1996  rat Pullup request from Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu>

>Make dump and restore usable on the alpha
 1.46.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.48.12.2 23-Jun-2013  tls resync from head
 1.48.12.1 25-Feb-2013  tls resync with head
 1.48.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.48.6.1 23-Jan-2013  yamt sync with head
 1.50.8.1 03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.50.6.1 03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.16 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.15 16-Feb-2008  matt Fix some inconsisent/conflicting definitions and missing parameters
 1.14 27-Jun-2005  christos branches: 1.14.10; 1.14.12;
add const
 1.13 27-Jun-2005  christos sprinkle const.
 1.12 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.11 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.10 27-Jul-2004  enami Add -D flag which computes the digest of each regular files in the archive
using specified algorithm (currently md5, rmd160 or sha1) and write them
to standard output.
 1.9 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.8 01-Nov-2001  lukem remove arg name in prototype decl
 1.7 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.6 15-Sep-1997  lukem branches: 1.6.4; 1.6.12;
* cleanup for WARNS=1
* fix use of .Nm
 1.5 06-Jul-1997  lukem as inspired by a commit message of Todd Miller <millert@cvs.openbsd.org>:
* cleanup a bit for -Wall
* use __progname instead of "restore"
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.2 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.1 22-Dec-1993  cgd branches: 1.1.1;
new version from CSRG, via BSDI, with fixes
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.6.12.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.6.4.1 10-Oct-2000  he Pull up revision 1.7 (requested by is):
Format string cleanup.
 1.14.12.1 18-Feb-2008  mjf Sync with HEAD.
 1.14.10.1 23-Mar-2008  matt sync with HEAD
 1.31 29-Aug-2021  christos Fix reversed test (thanks phone@)
 1.30 29-Aug-2021  christos fix wrong size (thanks mlelstv@)
 1.29 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.28 03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.27 22-Jan-2013  dholland branches: 1.27.30;
Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.26 07-Apr-2009  lukem branches: 1.26.6; 1.26.12;
fix sign-compare issues
 1.25 18-Dec-2006  christos branches: 1.25.22;
Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.24 19-Aug-2005  christos use d_fileno instead of d_ino for consistency
 1.23 19-Aug-2005  christos 64 bit inode changes
 1.22 27-Jun-2005  christos sprinkle const.
 1.21 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.20 08-Jan-2005  fredb Make a judicious choice as to whether to apply the permissions
of the root inode of the dump to the current working directory,
rather than interrogate the user. Closes PR bin/24690. Reviewed
by bouyer, tron, imp.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.18 19-Feb-2001  cgd convert to use getprogname()
 1.17 04-Feb-2001  christos fix nested extern
 1.16 09-Feb-1999  erh Make quoted strings work. (don't set the high bit of each character)
 1.15 03-Jan-1999  lukem user friendly enhancments.
reworked from [bin/6710] by Brian Grayson <bgrayson@ece.utexas.edu>
 1.14 10-Jan-1998  enami Document some undocumented options (-d and -N) and commands
in interactive mode (?, xit and Debug).
 1.13 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.11 06-Jul-1997  lukem as inspired by a commit message of Todd Miller <millert@cvs.openbsd.org>:
* cleanup a bit for -Wall
* use __progname instead of "restore"
 1.10 19-Mar-1997  lukem * use mkstemp() instead of mktemp()
* remove "register" qualifiers
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.7 30-Jan-1995  mycroft Don't mix stat flags and inode flags.
 1.6 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.5 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.26.12.1 25-Feb-2013  tls resync with head
 1.26.6.1 23-Jan-2013  yamt sync with head
 1.27.30.1 10-Jun-2019  christos Sync with HEAD
 1.37 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.36 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.35 22-Jan-2013  dholland branches: 1.35.30;
Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.34 29-Aug-2011  joerg branches: 1.34.2; 1.34.8;
Use __dead
 1.33 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.32 20-Mar-2006  christos branches: 1.32.20; 1.32.24;
Coverity CID 2305: Fix memory leak.
 1.31 27-Jun-2005  christos sprinkle const.
 1.30 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.29 08-Jan-2005  fredb Make a judicious choice as to whether to apply the permissions
of the root inode of the dump to the current working directory,
rather than interrogate the user. Closes PR bin/24690. Reviewed
by bouyer, tron, imp.
 1.28 24-Oct-2004  wiz Sort options in usage.
 1.27 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.26 27-Jul-2004  wiz Add -D to usage; shorten -b argument for usage's sake; format usage.
Man page nits.
 1.25 27-Jul-2004  enami Whitespace nits.
 1.24 27-Jul-2004  enami Add -D flag which computes the digest of each regular files in the archive
using specified algorithm (currently md5, rmd160 or sha1) and write them
to standard output.
 1.23 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.22 18-Nov-2002  enami Don't allocate struct entry one by one; it just wastes memory.
 1.21 19-Feb-2001  cgd convert to use getprogname()
 1.20 09-Jun-2000  enami Force -t or -N flag disables -u flag (but -t case is just for sanity).
 1.19 09-Nov-1999  drochner branches: 1.19.2;
Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
 1.18 24-Jun-1998  christos branches: 1.18.6;
Add an unlink (-u) flag so that we can use this for installs.
 1.17 10-Jan-1998  enami Document some undocumented options (-d and -N) and commands
in interactive mode (?, xit and Debug).
 1.16 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.15 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.14 06-Jul-1997  lukem as inspired by a commit message of Todd Miller <millert@cvs.openbsd.org>:
* cleanup a bit for -Wall
* use __progname instead of "restore"
 1.13 01-Jul-1997  lukem Support using $TMPDIR for rst{dir,modes}* files, so that large
restores can be done on machines with small /tmp's by setting TMPDIR
elsewhere. This shouldn't be a security issue as restore(8) isn't
set?id anymore.
 1.12 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h> instead of "pathnames.h"
cleanup references/examples to use /dev/rst* instead of /dev/rmt*
minor .Nm usage cleanup in man page
 1.11 15-Mar-1996  scottr Be more paranoid with our effective uid.
 1.10 06-Feb-1996  mrg support $TAPE.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 21-Feb-1995  mycroft Document the getopt(3) option syntax, and some other documentation cleanup.
 1.7 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.6 20-Feb-1995  mycroft Fix core dumps on certain types of invalid options.
 1.5 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.32.24.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.32.20.1 28-Sep-2008  mjf Sync with HEAD.
 1.34.8.1 25-Feb-2013  tls resync with head
 1.34.2.1 23-Jan-2013  yamt sync with head
 1.35.30.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.7 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h> instead of "pathnames.h"
cleanup references/examples to use /dev/rst* instead of /dev/rmt*
minor .Nm usage cleanup in man page
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 17-May-1994  cgd copyright foo
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.56 18-Jul-2018  wiz Remove superfluous macro.
 1.55 15-Jul-2018  dholland Document what rrestore is (was once) for. PR 53442.
CVS: ----------------------------------------------------------------------
 1.54 03-Jul-2017  wiz branches: 1.54.4; 1.54.6;
Remove workaround for ancient HTML generation code.
 1.53 30-Mar-2013  rodent s/user code/user mode/1
 1.52 30-Jan-2009  enami branches: 1.52.8; 1.52.14;
Use indent-synopsis instead of iS register. The latter is a register
used in BSD derived .Nm implementation.
 1.51 30-Apr-2007  tron Bump date because of last change.
 1.50 30-Apr-2007  tron Improve example of restoring a complete filesystem with "restore -r":
- NetBSD's "newfs" doesn't accept a second (non-option) argument.
Patch provided by Jeff Ito in PR bin/36241.
- Use "sd0" instead of "rp0" because NetBSD's doesnt have a disk driver
called "rp".
- Use "/dev/rst0" instead of "/dev/rst8". With NetBSD's device numbering
scheme a system would have to have 9 tape drives to get "/dev/rst8".
 1.49 11-Jan-2005  wiz branches: 1.49.2; 1.49.10;
Bump date for recent changes.
 1.48 08-Jan-2005  fredb Make a judicious choice as to whether to apply the permissions
of the root inode of the dump to the current working directory,
rather than interrogate the user. Closes PR bin/24690. Reviewed
by bouyer, tron, imp.
 1.47 24-Oct-2004  wiz Sort options.
 1.46 23-Oct-2004  snj Kill trailing whitespace introduced in the last revision.
 1.45 23-Oct-2004  snj Bump date for last, fix a spelling error, sprinkle some Dq, change
some wording.
 1.44 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.43 27-Jul-2004  wiz Add -D to usage; shorten -b argument for usage's sake; format usage.
Man page nits.
 1.42 27-Jul-2004  enami Add -D flag which computes the digest of each regular files in the archive
using specified algorithm (currently md5, rmd160 or sha1) and write them
to standard output.
 1.41 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.40 30-Jun-2003  wiz Quote punctuation so it gets marked up.
 1.39 26-May-2003  lukem * Document $RCMD_CMD in environ(7).
* Cross-reference rcmd(1), rcmd(3), and environ(7) as appropriate.

Should fix [bin/21670] from Geoff Wing.
 1.38 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.37 04-Feb-2003  perry "Utilize" has exactly the same meaning as "use," but it is more
difficult to read and understand. Most manuals of English style
therefore say that you should use "use".
 1.36 21-Dec-2002  wiz system with two ss, from Adrian Mrva.
 1.35 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.34 07-Dec-2001  wiz One '\' too many.
 1.33 16-Nov-2001  wiz Sort sections, use .Ic for a non-NetBSD program instead of .Xr.
 1.32 05-Jun-2001  wiz Drop arguments of .Os.
 1.31 09-Jun-2000  enami Force -t or -N flag disables -u flag (but -t case is just for sanity).
 1.30 23-May-2000  enami branches: 1.30.2;
Make sure that sentences end at the end of source line for better
formatted output.
 1.29 19-Nov-1999  enami Keep SEE ALSO list in alphabetical order.
 1.28 19-Nov-1999  enami Use .Ar macro for the files to be extracted.
 1.27 19-Nov-1999  enami Don't pass so many args to .Nd macro. It just overflows.
 1.26 01-Jul-1999  abs branches: 1.26.4;
Note the default tape device is taken from _PATH_DEFTAPE in /usr/include/paths.h
 1.25 28-Jun-1999  abs Default device is nrst0 not rst0
 1.24 27-Jul-1998  msaitoh branches: 1.24.2;
fix a small bug.
 1.23 24-Jun-1998  christos Add an unlink (-u) flag so that we can use this for installs.
 1.22 29-Apr-1998  fair fix bad .Xr references
 1.21 10-Jan-1998  enami Document some undocumented options (-d and -N) and commands
in interactive mode (?, xit and Debug).
 1.20 10-Jan-1998  enami Fix a typo; s/Complaints/Complains/ (pointed by Mike Long).
 1.19 11-Nov-1997  mrg add missing .Nm sections.
 1.18 20-Oct-1997  enami branches: 1.18.2;
Fix .Nm usage.
 1.17 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.16 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.15 01-Jul-1997  lukem Support using $TMPDIR for rst{dir,modes}* files, so that large
restores can be done on machines with small /tmp's by setting TMPDIR
elsewhere. This shouldn't be a security issue as restore(8) isn't
set?id anymore.
 1.14 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h> instead of "pathnames.h"
cleanup references/examples to use /dev/rst* instead of /dev/rmt*
minor .Nm usage cleanup in man page
 1.13 24-Dec-1996  mikel remove mkfs(8) xref; PR 3041
 1.12 24-Oct-1996  lukem use unique temporary files for all operations except 'r' and 'R', which still
base temp files on dumpdate. explain why in the man page. fixes [bin/2870]
 1.11 02-Feb-1996  phil Add /dev/rst* to FILES section. (pr 601) (Matches mt man page.)
 1.10 02-Feb-1996  phil Change default tape name in documentation from /dev/rmt? to /dev/rmt8 to
match pathnames.h. (pr #601)
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 21-Feb-1995  mycroft Document the getopt(3) option syntax, and some other documentation cleanup.
 1.7 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 14-Jan-1994  jtc Fix spelling errors
 1.4 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.3 05-Oct-1993  jtc Make sure all items in the SEE ALSO list are comma separated
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.2.1 11-Nov-1997  mrg pull up from trunk: add missing .Nm sections.
 1.24.2.1 02-Jul-1999  perry pullup 1.24->1.25 (abs): Correct default device from /dev/rst0 to /dev/nrst0
 1.26.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.30.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.49.10.1 30-Apr-2007  bouyer Pull up following revision(s) (requested by tron in ticket #600):
sbin/restore/restore.8: revisions 1.50, 1.51
Improve example of restoring a complete filesystem with "restore -r":
- NetBSD's "newfs" doesn't accept a second (non-option) argument.
Patch provided by Jeff Ito in PR bin/36241.
- Use "sd0" instead of "rp0" because NetBSD's doesnt have a disk driver
called "rp".
- Use "/dev/rst0" instead of "/dev/rst8". With NetBSD's device numbering
scheme a system would have to have 9 tape drives to get "/dev/rst8".
Bump date because of last change.
 1.49.2.1 27-May-2007  bouyer Pull up following revision(s) (requested by tron in ticket #1771):
sbin/restore/restore.8: revisions 1.50 - 1.51
Improve example of restoring a complete filesystem with "restore -r":
- NetBSD's "newfs" doesn't accept a second (non-option) argument.
Patch provided by Jeff Ito in PR bin/36241.
- Use "sd0" instead of "rp0" because NetBSD's doesnt have a disk driver
called "rp".
- Use "/dev/rst0" instead of "/dev/rst8". With NetBSD's device numbering
scheme a system would have to have 9 tape drives to get "/dev/rst8".
Bump date because of last change.
 1.52.14.1 23-Jun-2013  tls resync from head
 1.52.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.54.6.1 10-Jun-2019  christos Sync with HEAD
 1.54.4.1 28-Jul-2018  pgoyette Sync with HEAD
 1.22 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.21 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.20 18-Dec-2006  christos branches: 1.20.36; 1.20.42;
Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.19 19-Aug-2005  christos 64 bit inode changes
 1.18 27-Jun-2005  christos add const
 1.17 27-Jun-2005  christos sprinkle const.
 1.16 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.15 21-Oct-2003  fvdl Don't use NULL as a case value.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.13 18-Jan-2001  enami If possible, detect more case that file is missing on the tape.
XXX we still may lose if a file of highest inode number requested
XXX to extract was missing or one of multiple dump tape is lost.
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.11 06-Jul-1997  lukem as inspired by a commit message of Todd Miller <millert@cvs.openbsd.org>:
* cleanup a bit for -Wall
* use __progname instead of "restore"
 1.10 04-Jul-1997  pk NULL => 0 (from Arne Juul; addendum to PR#3237)
 1.9 18-Jun-1997  lukem Fix problem with duplicate entries when changing from LEAF to NODE;
only the first link of a inode was being removed, not all of them.
From Kirk McKusick <mckusick@McKusick.COM> via thorpej
 1.8 19-Mar-1997  lukem * use mkstemp() instead of mktemp()
* remove "register" qualifiers
 1.7 27-Sep-1996  thorpej Use snprintf() rather than sprintf().
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20.42.1 25-Feb-2013  tls resync with head
 1.20.36.1 23-Jan-2013  yamt sync with head
 1.23 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.22 05-Apr-2020  joerg Fix depenency on common symbols in sbin.
 1.21 27-Dec-2019  msaitoh s/opration/operation/
 1.20 06-Aug-2011  dholland branches: 1.20.42;
Add wrapper functions around hash algorithm operations to avoid
undefined behavior arising from illegal function casts. As a side
effect, no longer need -Wno-pointer-sign either.
 1.19 06-Aug-2011  dholland Simplify silly code and make it closer to type-safe. This causes amd64
gcc to reorder two pairs of instructions for some reason but the object
files are otherwise unchanged.
 1.18 27-Jun-2005  christos sprinkle const.
 1.17 08-Jan-2005  fredb Make a judicious choice as to whether to apply the permissions
of the root inode of the dump to the current working directory,
rather than interrogate the user. Closes PR bin/24690. Reviewed
by bouyer, tron, imp.
 1.16 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.15 27-Jul-2004  enami Add -D flag which computes the digest of each regular files in the archive
using specified algorithm (currently md5, rmd160 or sha1) and write them
to standard output.
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.13 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.12 18-Nov-2002  enami Don't allocate struct entry one by one; it just wastes memory.
 1.11 24-Aug-2001  wiz heirarchy -> hierarchy
 1.10 24-Jun-1998  christos Add an unlink (-u) flag so that we can use this for installs.
 1.9 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.8 01-Jul-1997  lukem Support using $TMPDIR for rst{dir,modes}* files, so that large
restores can be done on machines with small /tmp's by setting TMPDIR
elsewhere. This shouldn't be a security issue as restore(8) isn't
set?id anymore.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 17-May-1994  cgd copyright foo
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20.42.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3 22-Dec-1993  mycroft Clean up deleted files.
 1.2 01-Aug-1993  mycroft Add RCS indentifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 08-Jun-1994  mycroft Clean up deleted files.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.31 10-Feb-2024  andvar s/indicies/indices/ in comments.
 1.30 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.29 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.28 16-Sep-2011  plunky branches: 1.28.2; 1.28.8;
NULL does not need a cast, here
 1.27 04-Jan-2011  wiz Fix fd leak. Found by cppcheck.
 1.26 12-May-2010  mbalmer Fix grammar in a line of output.
From Hywel Mallett via FreeBSD.
 1.25 07-Apr-2009  lukem fix sign-compare issues
 1.24 22-Feb-2009  yamt remove a useless cast.
 1.23 19-Aug-2005  christos branches: 1.23.28; 1.23.30;
64 bit inode changes
 1.22 27-Jun-2005  christos add const
 1.21 27-Jun-2005  christos sprinkle const.
 1.20 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.19 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.18 25-Nov-2002  enami Also, don't allocate string entries one by one. Instead, allocate one page
and divide it, to reduce memory usage.
 1.17 18-Nov-2002  enami Typo in comment.
 1.16 18-Nov-2002  enami Don't allocate struct entry one by one; it just wastes memory.
 1.15 12-Aug-2002  itojun calloc() arg mistake. it's (nelem, size). from openbsd
 1.14 19-Jun-2001  wiz `existent', not `existant'
 1.13 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.12 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.11 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.10 19-Mar-1997  lukem * use mkstemp() instead of mktemp()
* remove "register" qualifiers
 1.9 30-Nov-1996  cgd patches from Tom I Helbekkmo <tih@nhh.no> to deal with type-size issues,
so this works (better, at least) on 64-bit machines (e.g. alpha).
 1.8 18-Mar-1995  cgd branches: 1.8.6;
convert to new RCS Id conventions; reduce my headache
 1.7 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.6 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.5 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.4 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.6.1 06-Dec-1996  rat Pullup request from Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu>

>Make dump and restore usable on the alpha
 1.23.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.23.28.1 21-Nov-2010  riz Pull up following revision(s) (requested by mbalmer in ticket #1397):
sbin/restore/symtab.c: revision 1.26
Fix grammar in a line of output.
From Hywel Mallett via FreeBSD.
 1.28.8.1 25-Feb-2013  tls resync with head
 1.28.2.1 23-Jan-2013  yamt sync with head
 1.75 05-Feb-2024  andvar triple "r" typos, mainly s/interrrupt/interrupt/ in comments and one definition.
 1.74 12-Dec-2022  chs apply this commit from FreeBSD:

commit 9dda00df7e8f9279a43d92758df6a7e10a9aed95
Author: Chuck Silvers <chs@FreeBSD.org>
Date: Mon Dec 12 08:14:17 2022 -0800

restore: fix restore of NFS4 ACLs

Changing the mode bits on a file with an NFS4 ACL results in the
NFS4 ACL being replaced by one matching the new mode bits being set,
so when restoring a file with an NFS4 ACL, set the owner/group/mode first
and then set the NFS4 ACL, so that setting the mode does not throw away
the ACL that we just set.

Reviewed by: mckusick
Differential Revision: https://reviews.freebsd.org/D37618
 1.73 10-Dec-2022  chs apply this change from FreeBSD:

commit c028393d7072f1f88efd8d6e6c77bb9b15b3f3b6
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Fri Apr 11 21:48:14 2008 +0000

Correctly set file group when restore is run by a user other than root.
 1.72 05-May-2022  mrg include the filename in the panic message for missing data.

instead of merely seeing:
getfile: lost data
now this is seen:
getfile: lost data: ./usr/libdata/debug/usr/libexec/cc1.debug
 1.71 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.70 11-Mar-2021  msaitoh s/skiping/skipping/
 1.69 03-Sep-2020  bouyer If we hit an unknown header type (likely to be a corrupt record), and
the user choose to not abort, skip to the next header instead of trying
to use it.
This allowed me to recover files from a corrupt dump, instead of
getting a segfault.
 1.68 02-Mar-2015  enami Don't truncate at microseconds while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html
 1.67 22-Jan-2013  dholland branches: 1.67.8; 1.67.10;
Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.66 29-Aug-2011  joerg branches: 1.66.2; 1.66.8;
Use __dead
 1.65 06-Aug-2011  dholland Add wrapper functions around hash algorithm operations to avoid
undefined behavior arising from illegal function casts. As a side
effect, no longer need -Wno-pointer-sign either.
 1.64 06-Aug-2011  dholland Simplify silly code and make it closer to type-safe. This causes amd64
gcc to reorder two pairs of instructions for some reason but the object
files are otherwise unchanged.
 1.63 07-Apr-2009  lukem fix sign-compare issues
 1.62 18-Feb-2009  yamt remove a useless cast.
 1.61 26-Dec-2008  hannken branches: 1.61.2;
Make restore work for Linux dump volumes by ignoring extended attribute
records on these volumes. Tested with Centos 5.2.

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.60 16-Feb-2008  matt branches: 1.60.4; 1.60.10;
Fix some inconsisent/conflicting definitions and missing parameters
 1.59 09-Feb-2007  hannken branches: 1.59.4; 1.59.6;
Add support for Solaris ufsdump volumes with more than 512*1024 inodes.
Here the bitmaps are written as

CLRI or BITS with c_count <= 512
ADDR* for the remaining blocks

Remove the bitmap handling from getfile(), remove xtrmap() and xtrmapskip().
Add new function getbitmap() modeled after getfile() that does bitmap
allocation, bitmap expansion and sets maxino.

Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.58 18-Dec-2006  christos Convert a couple of "(void)&" constructs to volatile.
Flag various unused parameters in restore and dump so that these will
compile with -Wextra. (Note: restore uses some stuff from dump.)
 1.57 30-Oct-2006  christos branches: 1.57.2;
find rmd160.h
 1.56 16-Oct-2006  christos c99 iniitializer
 1.55 25-Sep-2005  elad Use crypto/rmd160.h.
 1.54 19-Aug-2005  christos 64 bit inode changes
 1.53 27-Jun-2005  christos sprinkle const.
 1.52 17-Feb-2005  xtraeme branches: 1.52.2;
Kill __P(), use ANSI function declarations.
 1.51 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.50 27-Jul-2004  enami Add -D flag which computes the digest of each regular files in the archive
using specified algorithm (currently md5, rmd160 or sha1) and write them
to standard output.
 1.49 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.48 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.47 27-Mar-2003  taca Since "host" is used when RRESTORE is defined, enclose variable definition
with "#ifdef RRESTORE" and "#endif".
 1.46 25-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.45 19-Feb-2002  perseant Don't forget to update curfile, if tape begins with TS_ADDR type block.
In particular, this means that if one member (say the last member) of a tape
set begins with continuation blocks, restore will not consider that tape
to contain all the inodes (curfile.ino==0 at the beginning of the tape).

Close PR #15545.
 1.44 23-Dec-2001  lukem fix compile issues now that on-tape times are int32_t instead of time_t
 1.43 24-Jan-2001  enami Remove incorrect advice for lint; the control may return from panic().
 1.42 07-Jul-2000  enami Extract file flags of symbolic link.
 1.41 23-May-2000  enami Add comment and sanity check about why we need not to skip remaining
blocks if we are reading inode bitmaps.
 1.40 19-May-2000  enami Correctly extract the inode maps bigger than 512 tape blocks.
 1.39 27-Jan-2000  sommerfeld Fix PR9282: restore doesn't print dump header on dumps from host with
unset hostname.
 1.38 03-Jan-1999  lukem branches: 1.38.2;
user friendly enhancments.
reworked from [bin/6710] by Brian Grayson <bgrayson@ece.utexas.edu>
 1.37 24-Jun-1998  christos Add an unlink (-u) flag so that we can use this for installs.
 1.36 01-Apr-1998  kleink Need <time.h> for ctime() prototype.
 1.35 30-Mar-1998  mrg use static int, not just static
 1.34 13-Dec-1997  enami Fix the bug introduced in last change; pass IFCHR or IFBLK bit to
mknod(2) via mode.
 1.33 18-Nov-1997  enami Use file mode 0600 when creating special file or fifo.
Suggested by Charles M. Hannum.
 1.32 18-Nov-1997  enami Restore file attributes after extracting regular file. Fixes PR#4515
from stephen.ma@jtec.com.au:

- call getfile() before altering file attributes.
- open file with mode 0600 instead of 0666 so that file won't remain
group or world readable/writable even if getfile() terminated.
- also, move skipfile() before altering file attributes in IF{CHR,BLK} and
IFIFO case for symmetry (suggested by Charles M. Hannum).
 1.31 19-Oct-1997  mycroft branches: 1.31.2;
Use futimes(2). Do {f,}utimes(2) *before* {f,}chflags(2), for obvious
reasons.
 1.30 08-Oct-1997  enami Restore owner/group/mode/atime/mtime of symbolic links.
 1.29 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.28 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.27 06-Jul-1997  lukem as inspired by a commit message of Todd Miller <millert@cvs.openbsd.org>:
* cleanup a bit for -Wall
* use __progname instead of "restore"
 1.26 15-Apr-1997  lukem use _PATH_DEFTAPE from <paths.h> instead of "pathnames.h"
cleanup references/examples to use /dev/rst* instead of /dev/rmt*
minor .Nm usage cleanup in man page
 1.25 19-Mar-1997  lukem * use mkstemp() instead of mktemp()
* remove "register" qualifiers
 1.24 26-Dec-1996  cjs Fix typo: PR bin/3059
 1.23 04-Dec-1996  mycroft Make sure to byte-swap all of the relevant fields; especially c_flags.
 1.22 30-Nov-1996  cgd When initializing 'fssize,' the size of the data buffer to be used when
writing data to the file system, if the "optimal" file system I/O
operation block size is less than TP_BSIZE, leave fssize alone (i.e.
at its default setting of MAXBSIZE). This was causing restore's
stack to be trashed, because the end-of-buffer checking/flushing code
around line 680 would never notice that the buffer was full (because
it'd be comparing a buffer segment index, which would always be >= 1, to
fssize / TP_BSIZE, which could be zero in that case), and would keep
filling and filling and filling...
 1.21 30-Nov-1996  cgd patches from Tom I Helbekkmo <tih@nhh.no> to deal with type-size issues,
so this works (better, at least) on 64-bit machines (e.g. alpha).
 1.20 15-Mar-1996  scottr branches: 1.20.4;
Be more paranoid with our effective uid.
 1.19 19-Jun-1995  cgd stat structure POSIXification
 1.18 11-Jun-1995  mycroft Back out previous change.
 1.17 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.16 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.15 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.14 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.13 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.12 18-Sep-1994  mycroft Allow extracting FIFOs.
 1.11 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.10 17-May-1994  cgd copyright foo
 1.9 25-Apr-1994  cgd kill some #ifndefs
 1.8 02-Apr-1994  cgd just kill the cast completely
 1.7 01-Apr-1994  cgd bad cast
 1.6 01-Mar-1994  cgd Check correct header when looking at tape number.
from thomas@mathematik.uni-Bremen.de
 1.5 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 20-Apr-1993  mycroft Fix message.
 1.2 25-Mar-1993  cgd restore didn't understand dirs which spanned more than one volume.
fixed by patch from Gene Stark (gene@stark.uucp).
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20.4.2 10-Dec-1996  mycroft From trunk:
Add some missing byte-swaps, so this works across endians.
 1.20.4.1 06-Dec-1996  rat Pullup request from Chris G Demetriou <Chris_G_Demetriou@ux2.sp.cs.cmu.edu>

>Make dump and restore usable on the alpha
 1.31.2.2 14-Dec-1997  mellon Pull rev 1.34 up from trunk (enami)
 1.31.2.1 18-Nov-1997  mellon Pull rev 1.32 and 1.33 up from trunk (enami)
 1.38.2.2 11-Oct-2000  he Pull up revisions 1.40-1.41 (requested by enami):
Make restore correctly handle large dumps with large inode maps.
Fixes PR#11188.
 1.38.2.1 31-Jan-2000  he Pull up revision 1.39 (requested by sommerfeld):
Print the header even on dumps from a system with an unset
host name. Fixes PR#9282.
 1.52.2.1 03-Mar-2007  bouyer Pull up following revision(s) (requested by hannken in ticket #1674):
sbin/restore/tape.c: revision 1.59
Add support for Solaris ufsdump volumes with more than 512*1024 inodes.
Here the bitmaps are written as
CLRI or BITS with c_count <= 512
ADDR* for the remaining blocks
Remove the bitmap handling from getfile(), remove xtrmap() and xtrmapskip().
Add new function getbitmap() modeled after getfile() that does bitmap
allocation, bitmap expansion and sets maxino.
Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.57.2.1 04-Mar-2007  bouyer Pull up following revision(s) (requested by hannken in ticket #483):
sbin/restore/tape.c: revision 1.59 via patch
Add support for Solaris ufsdump volumes with more than 512*1024 inodes.
Here the bitmaps are written as
CLRI or BITS with c_count <= 512
ADDR* for the remaining blocks
Remove the bitmap handling from getfile(), remove xtrmap() and xtrmapskip().
Add new function getbitmap() modeled after getfile() that does bitmap
allocation, bitmap expansion and sets maxino.
Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.59.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.59.4.1 23-Mar-2008  matt sync with HEAD
 1.60.10.1 02-Jan-2009  snj Pull up following revision(s) (requested by hannken in ticket #210):
include/protocols/dumprestore.h: revision 1.15
sbin/restore/tape.c: revision 1.61
Make restore work for Linux dump volumes by ignoring extended attribute
records on these volumes. Tested with Centos 5.2.
Reviewed by: Manuel Bouyer <bouyer@netbsd.org>
 1.60.4.1 17-Jan-2009  mjf Sync with HEAD.
 1.61.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.66.8.1 25-Feb-2013  tls resync with head
 1.66.2.1 23-Jan-2013  yamt sync with head
 1.67.10.1 03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.67.8.1 03-Mar-2016  martin Pull up following revision(s) (requested by nakayama in ticket #1096):
bin/mv/mv.c: revision 1.44
bin/cp/utils.c: revision 1.43-1.44
lib/librumphijack/hijack.c: revision 1.112-1.115
usr.bin/touch/touch.c: revision 1.33
sbin/restore/tape.c: revision 1.68
sbin/restore/dirs.c: revision 1.51
Don't truncate at sub-microsecond while preserving timestamps.

One of motivation of this change is to make the behavior of test(1)
-nt/ot with preserved copy (like cp -p) closer to the NetBSD 6.
Of course whether full timestamps are kept or not depends also on
underlying file system.

The ifdef added in mv(1) since existing ifdefs was our local change
to compile it on solaris (though I couldn't test it):
http://mail-index.netbsd.org/tech-userlevel/2014/11/28/msg008831.html

Fix the name of failed function in warning message.

Hijack utimensat(2) so that t_vfs test passes after cp(1)/mv(1) are
changed to use the system call. Linux also has this system call, but
not tested this on linux.

Also hijack futimens(2) so that t_sh test passes.

Define a generic ATCALL() and use it to implement utimensat()
Make ATCALL() behave for absolute paths too.
 1.24 19-Jun-2021  christos Add external attribute dumping and restoring support from FreeBSD.
Does not fully work yet, attributes are being saved and restored correctly,
but don't appear in the restored files somehow.
 1.23 22-Jan-2013  dholland Stuff UFS_ in front of a few of ufs's symbols to reduce namespace
pollution. Specifically:
ROOTINO -> UFS_ROOTINO
WINO -> UFS_WINO
NXADDR -> UFS_NXADDR
NDADDR -> UFS_NDADDR
NIADDR -> UFS_NIADDR
MAXSYMLINKLEN -> UFS_MAXSYMLINKLEN
MAXSYMLINKLEN_UFS[12] -> UFS[12]_MAXSYMLINKLEN (for consistency)

Sort out ext2fs's misuse of NDADDR and NIADDR; fortunately, these have
the same values in ext2fs and ffs.

No functional change intended.
 1.22 19-Aug-2005  christos branches: 1.22.44; 1.22.50;
64 bit inode changes
 1.21 27-Jun-2005  christos add const
 1.20 27-Jun-2005  christos sprinkle const.
 1.19 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.18 22-Oct-2004  bouyer Add an option (-M) to write a mtree specification (which needs to be passed
through sort before being feed to mtree) with file flags, instead of restoring
file flags at the same time as other attributes. Fix various issue with
schg, uchg, sappnd or uappnd flags which cause restore to fail in some case.
Discussed on tech-userlevel:
http://mail-index.netbsd.org/tech-userlevel/2004/10/12/0000.html
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.16 25-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.15 01-Nov-2001  lukem fix -Wshadow warnings
 1.14 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.13 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* fix use of .Nm
 1.11 19-Mar-1997  lukem * use mkstemp() instead of mktemp()
* remove "register" qualifiers
 1.10 27-Sep-1996  thorpej Use snprintf() rather than sprintf().
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 20-Feb-1995  mycroft Use atexit() rather than tweaking every exit() to call the cleanup function.
 1.7 28-Dec-1994  mycroft Mostly sync with CSRG.
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 19-Feb-1994  cgd light clean and check error codes
 1.3 22-Dec-1993  cgd new version from CSRG, via BSDI, with fixes
 1.2 01-Aug-1993  mycroft Add RCS identifiers.
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.22.50.1 25-Feb-2013  tls resync with head
 1.22.44.1 23-Jan-2013  yamt sync with head
 1.6 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.5 14-Jan-2020  christos .include bsd.own.mk for ${NETBSDSRCDIR}
 1.4 06-Dec-2019  riastradh Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.3 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.2 13-Oct-1997  mycroft branches: 1.2.112; 1.2.114;
Remove bogons.
 1.1 13-Oct-1997  explorer Add rndctl(8) and man page
 1.2.114.1 17-Dec-2019  martin Pull up following revision(s) (requested by riastradh in ticket #563):

sbin/rndctl/rndctl.c: revision 1.31
sbin/rndctl/rndctl.8: revision 1.23
sbin/rndctl/Makefile: revision 1.4 (adapted)
sbin/rndctl/namespace.h: revision 1.1

Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.2.112.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1 06-Dec-2019  riastradh branches: 1.1.2; 1.1.6;
Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.1.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.6.1 06-Dec-2019  martin file namespace.h was added on branch phil-wifi on 2020-04-08 14:07:20 +0000
 1.1.2.2 17-Dec-2019  martin Pull up following revision(s) (requested by riastradh in ticket #563):

sbin/rndctl/rndctl.c: revision 1.31
sbin/rndctl/rndctl.8: revision 1.23
sbin/rndctl/Makefile: revision 1.4 (adapted)
sbin/rndctl/namespace.h: revision 1.1

Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.1.2.1 06-Dec-2019  martin file namespace.h was added on branch netbsd-9 on 2019-12-17 12:45:30 +0000
 1.31 02-Oct-2025  riastradh rndctl(8): Nix trailing whitespace in man page.

No functional change intended.
 1.30 25-Jun-2025  gutteridge rndctl.8: add more detail about the -l and -v options
 1.29 06-Apr-2021  riastradh branches: 1.29.8;
Clarify wording further based on private feedback.
 1.28 06-Apr-2021  riastradh Clarify security model of rndctl -S files.
 1.27 02-Apr-2021  nia rndctl.8: reflect current reality
 1.26 07-May-2020  riastradh Touch up rndctl(8) a bit.
 1.25 07-May-2020  wiz Add -i to SYNOPSIS.
 1.24 06-May-2020  riastradh Tweak logic to decide whether a medium is safe for an rndseed.

- Teach rndctl to load the seed, but treat it as zero entropy, if the
medium is read-only or if the update fails.

- Teach rndctl to accept `-i' flag instructing it to ignore the
entropy estimate in the seed.

- Teach /etc/rc.d/random_seed to:
(a) assume nonlocal file systems are unsafe, and use -i, but
(b) assume / is safe, even if it is nonlocal.
If the medium is nonwritable, leave it to rndctl to detect that.
(Could use statvfs and check for ST_LOCAL in rndctl, I guess, but I
already implemented it this way.)

Treating nonlocal / as safe is a compromise: it's up to the operator
to secure the network for (e.g.) nfs mounts, but that's true whether
we're talking entropy or not -- if the adversary has access to the
network that you've mounted / from, they can do a lot more damage
anyway; this reduces warning fatigue for diskless systems, e.g. test
racks.
 1.23 06-Dec-2019  riastradh Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.22 10-Aug-2014  wiz branches: 1.22.24; 1.22.26;
Sort options and mark them as optional.
Bump date for previous.
 1.21 10-Aug-2014  tls Merge tls-earlyentropy branch into HEAD.
 1.20 23-Nov-2011  wiz branches: 1.20.6; 1.20.16;
Sort option descriptions, bump date for previous.
 1.19 23-Nov-2011  tls Load entropy at system boot (only works at securelevel < 1); save
at system shutdown. Disable with random_seed=NO in rc.conf if desired.

Goes to some trouble to never load or save to network filesystems.

Entropy should really be loaded by the boot loader but I am still
sorting out how to pass it to the kernel.
 1.18 01-Oct-2011  pgoyette branches: 1.18.2;
Fix typo
 1.17 04-Jan-2009  apb Add a list of device types for use with "rndctl -t ${typename}".
 1.16 06-Nov-2008  apb Adjust synopsis and description to make it clear that -d devname and
-t devtype are mutually exclusive.
 1.15 25-Feb-2003  wiz branches: 1.15.16; 1.15.32; 1.15.40;
.Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.14 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.13 01-Oct-2002  wiz Sort options. Fix grammar. Use more mdoc.
 1.12 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.11 16-Nov-2001  wiz Sort sections, use standard headers, sort SEE ALSO.
 1.10 16-Nov-2001  wiz Whitespace nits
 1.9 05-Jun-2001  wiz Drop arguments of .Os.
 1.8 05-Oct-2000  enami Don't explain -s twice.
 1.7 28-Aug-2000  joda document -s
 1.6 20-Jun-2000  sommerfeld branches: 1.6.2;
revised rndctl which can display pool statistics.
 1.5 10-Mar-1999  erh branches: 1.5.8;
Add missing .El line.
 1.4 22-May-1998  msaitoh sort entries and delete extra periods in SEE also section.
 1.3 04-Nov-1997  explorer Update copyright message (I wrote this, not the template of the day)
 1.2 20-Oct-1997  enami branches: 1.2.2;
Fix .Nm usage.
 1.1 13-Oct-1997  explorer Add rndctl(8) and man page
 1.2.2.1 04-Nov-1997  mellon Pull rev 1.3 up from trunk (explorer)
 1.5.8.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.2 20-Jun-2000  sommerfeld revised rndctl which can display pool statistics.
 1.6.2.1 20-Jun-2000  sommerfeld file rndctl.8 was added on branch netbsd-1-5 on 2000-06-20 02:40:11 +0000
 1.15.40.2 08-Jan-2009  snj Pull up following revision(s) (requested by apb in ticket #231):
sbin/rndctl/rndctl.8: revision 1.17
Add a list of device types for use with "rndctl -t ${typename}".
 1.15.40.1 08-Jan-2009  snj Pull up following revision(s) (requested by apb in ticket #231):
sbin/rndctl/rndctl.8: revision 1.16
Adjust synopsis and description to make it clear that -d devname and
-t devtype are mutually exclusive.
 1.15.32.1 17-Jan-2009  mjf Sync with HEAD.
 1.15.16.1 11-Feb-2009  ober Pull up following revision(s) (requested by dholland in ticket #1274):
sbin/rndctl/rndctl.8: revision 1.16
Adjust synopsis and description to make it clear that -d devname and
-t devtype are mutually exclusive.
 1.18.2.1 17-Apr-2012  yamt sync with head
 1.20.16.1 07-Apr-2014  tls Update rndctl(8) to add the -v option, which gives us more robust information
on entropy collection and estimation.
 1.20.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.22.26.1 17-Dec-2019  martin Pull up following revision(s) (requested by riastradh in ticket #563):

sbin/rndctl/rndctl.c: revision 1.31
sbin/rndctl/rndctl.8: revision 1.23
sbin/rndctl/Makefile: revision 1.4 (adapted)
sbin/rndctl/namespace.h: revision 1.1

Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.22.24.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.29.8.1 02-Aug-2025  perseant Sync with HEAD
 1.41 11-Apr-2023  riastradh rndctl(8): Take omitted name/type as empty device name.

This can now be used to change flags for all sources at once.

XXX pullup-10
 1.40 04-Apr-2021  nia branches: 1.40.6;
rndctl(8): to -l, add a "samples" column separate to "bits"

rename the "bits" column to "estimated bits".

this provides a clear indication when a source is being used, but
not increasing the entropy counter.

this commit fixes an unrelated bug where verbose output functioned
incorrectly when a class of device was specified with -t.

while here, reduce code duplication.

"gofer it" riastradh@
 1.39 04-Apr-2021  nia rndctl(8): remove no-longer-useful stats from -s

these are always 0 now.

"gofer it" riastradh@
 1.38 02-Apr-2021  nia rndctl: make -l's "Flags" field reflect current reality

don't print "legacy options" RND_FLAG_ESTIMATE_TIME and
"RND_FLAG_ESTIMATE_VALUE"

only print "estimate" if we have actually counted any bits from
something, since it's no longer really possible to "enable estimation".

ideally, there should also be a "samples" field so it's clear
collected bits are not being counted.
 1.37 12-May-2020  simonb Whitespace alignment nits.
 1.36 07-May-2020  riastradh Trigger entropy consolidation before saving seed.

This way, whenever /etc/security runs infrequently (daily), or the
operator manually issues rndctl -S, we ensure that all samples taken
during the entire boot are hashed together in the seed for the next
boot.

This should be infrequent enough that it's unlikely to enable the
iterative-guessing attacks that we try to mitigate by not frequently
consolidating entropy.
 1.35 07-May-2020  riastradh Rework rndctl seed load sequence again.

Go back to the book's order, now that writing to /dev/random
guarantees to consolidate entropy -- this way the _next_ boot is no
less secure than the current boot, in the event that entropy sources
like interrupt timings provided any security that we just don't know
how to measure honestly.

Make sure to open the old seed to overwrite and the new seed to write
anew first so that we can determine whether the medium is read-only
before accepting the file's entropy estimate.
 1.34 06-May-2020  riastradh Tweak logic to decide whether a medium is safe for an rndseed.

- Teach rndctl to load the seed, but treat it as zero entropy, if the
medium is read-only or if the update fails.

- Teach rndctl to accept `-i' flag instructing it to ignore the
entropy estimate in the seed.

- Teach /etc/rc.d/random_seed to:
(a) assume nonlocal file systems are unsafe, and use -i, but
(b) assume / is safe, even if it is nonlocal.
If the medium is nonwritable, leave it to rndctl to detect that.
(Could use statvfs and check for ST_LOCAL in rndctl, I guess, but I
already implemented it this way.)

Treating nonlocal / as safe is a compromise: it's up to the operator
to secure the network for (e.g.) nfs mounts, but that's true whether
we're talking entropy or not -- if the adversary has access to the
network that you've mounted / from, they can do a lot more damage
anyway; this reduces warning fatigue for diskless systems, e.g. test
racks.
 1.33 30-Apr-2020  riastradh Sort includes.
 1.32 30-Apr-2020  riastradh Accept both byte orders for random seed in `rndctl -L'.

The file format was defined with a machine-dependent 32-bit integer
field (the estimated number of bits of entropy in the process that
generated it). Take whichever byte order gives a number that is
reasonable, i.e. lower than the number of bits in the buffer.

Continue to have `rndctl -S' generate it in machine-dependent byte
order for now, so that if you roll back to an older rndctl(8) then
`rndctl -L' on the same machine will still be able to load it with
the right entropy estimate. In a future revision, perhaps we can
change it to be little-endian.
 1.31 06-Dec-2019  riastradh Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.30 13-Apr-2015  riastradh branches: 1.30.16; 1.30.18;
Use <sys/rndio.h> instead of <sys/rnd.h>.
 1.29 10-Aug-2014  wiz Sync usage with manpage a bit more.
 1.28 10-Aug-2014  tls Merge tls-earlyentropy branch into HEAD.
 1.27 15-Jan-2014  apb branches: 1.27.2;
Overwrite the seed file from the beginning, using pwrite(2).
 1.26 15-Jan-2014  joerg Fix arguments for write.
 1.25 14-Aug-2012  jruoho branches: 1.25.2;
Use _PATH_URANDOM from paths(3).
 1.24 02-Feb-2012  tls Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.23 17-Dec-2011  apb Make "rndctl -L" overwrite the file with zeros, not with the
same data that was just read from the file.
 1.22 26-Nov-2011  tls Make the rndsave structure public -- the kernel will learn to read it
and sysinst may learn to write it (since, on some systems, most of
the keyboard input they ever get happens to be during install). Fix a
couple of minor problems with the random_seed rc script addition.
 1.21 23-Nov-2011  tls Load entropy at system boot (only works at securelevel < 1); save
at system shutdown. Disable with random_seed=NO in rc.conf if desired.

Goes to some trouble to never load or save to network filesystems.

Entropy should really be loaded by the boot loader but I am still
sorting out how to pass it to the kernel.
 1.20 27-Aug-2011  joerg branches: 1.20.2;
static + const + __dead
 1.19 05-Apr-2009  lukem fix sign-compare issues
 1.18 06-Nov-2008  apb branches: 1.18.2;
* Instead of silently ignoring extra args, print a usage error. This
adddresses the silent failure reported in PR 39862 by Brian A. Seklecki
* Adjust usage message to match the synopsis in the man page.
 1.17 27-Jun-2005  christos branches: 1.17.4; 1.17.20; 1.17.28;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.16 13-Jul-2003  itojun strlcat
 1.15 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.14 17-May-2003  itojun do not hardcode buffer size
 1.13 18-Aug-2002  gmcgarry Type 'network' was an alias for 'net' and was changed to "net" in
rev 1.5. Remove duplicate. Reported by Christian Biere in PR17976.
 1.12 19-May-2002  enami Since all members in rndpoolstat_t are unsigned, print them so. PR#14584.
 1.11 11-Sep-2001  enami - Recognize new type `rng'.
- Use getprogname().
 1.10 08-Sep-2001  enami Don't punt on really unknown type of device when fetching name of it.
Instead, warn and just print it as ???.
 1.9 08-Sep-2001  enami Cosmetic changes.
 1.8 28-Aug-2000  joda document -s
 1.7 25-Aug-2000  joda initialize sflag to zero; discovered on Digital UNIX, where I got
random (no pun intended) functionality
 1.6 20-Jun-2000  sommerfeld branches: 1.6.2;
revised rndctl which can display pool statistics.
 1.5 30-Mar-1999  mycroft branches: 1.5.8;
Make the usage string match the man page.
 1.4 28-Feb-1999  explorer flags and type are seperate now
 1.3 09-Jan-1998  perry RCS Id Police.
 1.2 13-Oct-1997  explorer clean up warnings, gads
 1.1 13-Oct-1997  explorer Add rndctl(8) and man page
 1.5.8.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.6.2.2 18-Sep-2002  itojun pullup 1.7 (hash@iij.ad.jp)
initialize sflag to zero; discovered on Digital UNIX, where I got
random (no pun intended) functionality
 1.6.2.1 20-Jun-2000  itojun file rndctl.c was added on branch netbsd-1-5 on 2002-09-18 15:56:19 +0000
 1.17.28.1 08-Jan-2009  snj Pull up following revision(s) (requested by apb in ticket #231):
sbin/rndctl/rndctl.c: revision 1.18
* Instead of silently ignoring extra args, print a usage error. This
adddresses the silent failure reported in PR 39862 by Brian A. Seklecki
* Adjust usage message to match the synopsis in the man page.
 1.17.20.1 17-Jan-2009  mjf Sync with HEAD.
 1.17.4.1 11-Feb-2009  ober Pull up following revision(s) (requested by dholland in ticket #1274):
sbin/rndctl/rndctl.c: revision 1.18
* Instead of silently ignoring extra args, print a usage error. This
adddresses the silent failure reported in PR 39862 by Brian A. Seklecki
* Adjust usage message to match the synopsis in the man page.
 1.18.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.20.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.20.2.2 30-Oct-2012  yamt sync with head
 1.20.2.1 17-Apr-2012  yamt sync with head
 1.25.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.27.2.2 17-Jul-2014  tls Adjustments to the "earlyentropy" branch in response to the various
discussions beginning with my initial proposal
http://mail-index.netbsd.org/tech-kern/2014/04/08/msg016876.html and
particularly the long discussion of cprng_fast() performance (e.g.
https://mail-index.netbsd.org/tech-crypto/2014/04/21/msg000642.html).

In particular:

* Per-CPU, lockless cprng_fast replacement using Dennis Ferguson's
"ccrand" implementation of ChaCha8.

* libkern arc4random() is gone, gone, gone.

* Entropy estimator reverted to 32-bit recordkeeping and timestamps
per Dennis' comments and analysis.

* LZF entropy estimator removed: it required a great deal of state,
and rejected only truly pathological input.

I have not yet reverted the changes that provide LZF in the kernel
as generic functionality; I will likely revert those changes prior
to any merge of this branch to HEAD.
 1.27.2.1 07-Apr-2014  tls Update rndctl(8) to add the -v option, which gives us more robust information
on entropy collection and estimation.
 1.30.18.2 15-Jul-2020  martin Pull up following revision(s) (requested by riastradh in ticket #1006):

sbin/rndctl/rndctl.c: revision 1.32
sbin/rndctl/rndctl.c: revision 1.33

Accept both byte orders for random seed in `rndctl -L'.

The file format was defined with a machine-dependent 32-bit integer
field (the estimated number of bits of entropy in the process that
generated it). Take whichever byte order gives a number that is
reasonable, i.e. lower than the number of bits in the buffer.

Continue to have `rndctl -S' generate it in machine-dependent byte
order for now, so that if you roll back to an older rndctl(8) then
`rndctl -L' on the same machine will still be able to load it with
the right entropy estimate. In a future revision, perhaps we can
change it to be little-endian.

Sort includes.
 1.30.18.1 17-Dec-2019  martin Pull up following revision(s) (requested by riastradh in ticket #563):

sbin/rndctl/rndctl.c: revision 1.31
sbin/rndctl/rndctl.8: revision 1.23
sbin/rndctl/Makefile: revision 1.4 (adapted)
sbin/rndctl/namespace.h: revision 1.1

Teach `rndctl -L' to update the seed file, not just delete it.

The seed file is updated by entering the old seed into the system and
then hashing the old seed together with data from /dev/urandom, and
writing it atomically with write-to-temporary/rename-to-permanent.

This way, interruption by crash or power loss does not obliterate
your persistent entropy (unless it causes file system corruption).
 1.30.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.40.6.1 31-Jul-2023  martin Pull up following revision(s) (requested by riastradh in ticket #273):

sys/kern/kern_entropy.c: revision 1.59
sbin/rndctl/rndctl.c: revision 1.41

entropy(9): Allow changing flags on all entropy sources at once.

Entropy sources should all have nonempty names, and this will enable
an operator to, for example, disable all but a specific entropy
source.

rndctl(8): Take omitted name/type as empty device name.

This can now be used to change flags for all sources at once.
 1.33 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.32 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.31 13-Dec-2017  christos branches: 1.31.4;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.
 1.30 10-Oct-2017  christos user librumpres
 1.29 14-Sep-2015  ozaki-r Include a few additional libc functions in rump.route to make it work with inet6

getaddrinfo and if_nametoindex are newly added to interpret interface names
in IPv6 link-local addresses. if_nametoindex looks not used in rump.route,
but it is needed because it is used indirectly from getaddrinfo.

From s-yamaguchi@IIJ
 1.28 15-May-2015  ozaki-r Fix rump.{netstat,route} shows host's interface names in link local addresses

Interface names of IPv6 link local addresses are resolved
by getnameinfo(3). So we need to rump-ify it as well as
if_indextoname and getifaddrs.
 1.27 22-Apr-2015  ozaki-r Fix rump.route shows host's interface names

Let it use rump-ified if_indextoname and getifaddrs
to get rump kernel's interfaces, which is the same way
as ifconfig.
 1.26 06-Nov-2014  christos Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.25 13-Dec-2010  pooka branches: 1.25.24;
Convert from RUMP_ACTION to RUMPPRG.
 1.24 04-Nov-2010  pooka Support RUMP_ACTION to compile a rump kernel client.
 1.23 26-Aug-2006  matt Remove XNS and CCITT/X25 bits.
 1.22 10-Jan-2005  lukem Only compile in IPv6 support if ${USE_INET6} != "no"

MKINET6 is for providing IPv6 infrastructure.
USE_INET6 is for compiling IPv6 support into the programs (needs MKINET6).
 1.21 26-Oct-2003  lukem Use ${HOST_SH} instead of `sh'.

If necessary, pull in <bsd.sys.mk> to get the definition of HOST_SH;
Makefiles that pull in one of (most of) <bsd.*.mk> will get this anyway.
 1.20 03-Jul-1999  itojun s/CFLAGS/CPPFLAGS/ for -D and -I.
 1.19 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.18 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.17 09-May-1997  mycroft Eliminate bogus redefinitions of standard targets.
 1.16 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.15 22-Feb-1997  thorpej Now that non-superuser can open the routing socket, this program no
longer needs to be setuid-root. Superuser status is required to
alter the routing table, but is enforced by the kernel.
 1.14 15-Nov-1996  gwr Note that distrib/utils/x_route uses these files.
 1.13 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.12 19-Apr-1995  cgd route.o, not route, depends on keywords.h. from jhawk@mit.edu; pr 978
 1.11 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.10 22-Dec-1994  cgd specify man pages the new way.
 1.9 20-May-1994  cgd don't need that 'all' line.
 1.8 13-May-1994  cgd need dep. first
 1.7 13-May-1994  mycroft Clean up import.
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 25-Apr-1993  mycroft Reenable building keywords.h dynamically.
 1.4 25-Apr-1993  mycroft Compile X.25, OSI, and NS code.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25.24.1 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.31.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.16 07-Sep-2006  dogcow remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.15 09-Aug-2005  ginsbach More style nits (KNF); casts and sizeof's are not followed by a space.
 1.14 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.13 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.12 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.11 15-Sep-1997  lukem wrap line @ 80 columns
 1.10 15-Sep-1997  lukem * cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF
 1.9 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.8 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.15 06-Nov-2014  christos Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.14 21-Oct-2009  snj branches: 1.14.24;
Remove 3rd and 4th clauses in christos' license. OK christos.
 1.13 10-Sep-2008  dyoung Constify.
 1.12 09-Sep-2008  dyoung Constify.
 1.11 09-Sep-2008  dyoung Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.
 1.10 09-Sep-2008  dyoung Use bool.
 1.9 23-Sep-2006  dyoung branches: 1.9.18; 1.9.22;
Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().
 1.8 07-Sep-2006  dogcow remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.7 25-Jan-2006  christos PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.
 1.6 15-Aug-2005  ginsbach Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.
 1.5 09-Aug-2005  ginsbach Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]
 1.4 26-Jun-2005  christos const poisoning.
 1.3 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.2 24-Oct-2001  atatat Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.
 1.1 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.9.22.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.9.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.14.24.1 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.7 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.6 20-Apr-1995  mycroft Implement the document `-llinfo' flag.
 1.5 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.4 13-May-1994  mycroft Clean up import.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11 04-Apr-2016  ozaki-r Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.10 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.9 11-Nov-2011  gdt branches: 1.9.6;
Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
 1.8 26-Jun-2010  kefren branches: 1.8.6;
add MPLS clue - mpls and tag keywords
 1.7 12-May-2010  christos PR/40455: Mihai Chelaru: Add noreject noblackhole options
 1.6 06-Aug-2006  dyoung Add route keywords -nocloned, -nocloning.
 1.5 19-Jul-2003  jrf This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.
 1.4 27-Jan-2001  itojun regen
 1.3 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.2 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.1 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.8.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.8.6.1 17-Apr-2012  yamt sync with head
 1.9.6.1 23-Jun-2013  tls resync from head
 1.14 04-Apr-2016  ozaki-r Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.13 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.12 11-Nov-2011  gdt branches: 1.12.6;
Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
 1.11 26-Jun-2010  kefren branches: 1.11.6;
add MPLS clue - mpls and tag keywords
 1.10 12-May-2010  christos PR/40455: Mihai Chelaru: Add noreject noblackhole options
 1.9 06-Aug-2006  dyoung Add route keywords -nocloned, -nocloning.
 1.8 26-Jun-2005  christos const poisoning.
 1.7 19-Jul-2003  jrf This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.
 1.6 27-Jan-2001  itojun regen
 1.5 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.4 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.3 16-Dec-1996  cgd declare the keywords structure 'extern' in keywords.h, to avoid a common defn.
 1.2 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 25-Apr-1993  mycroft Clean up deleted files.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.11.6.1 17-Apr-2012  yamt sync with head
 1.12.6.1 23-Jun-2013  tls resync from head
 1.11 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.10 11-Nov-2011  gdt branches: 1.10.6;
Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
 1.9 26-Jun-2010  kefren branches: 1.9.6;
add MPLS clue - mpls and tag keywords
 1.8 12-May-2010  kefren Update also keywords.{c,h} generator in order to reflect latest changes.
 1.7 19-Jul-2003  jrf This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.
 1.6 27-Jan-2001  itojun add a keyword, cloned
 1.5 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.4 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.3 16-Dec-1996  cgd declare the keywords structure 'extern' in keywords.h, to avoid a common defn.
 1.2 15-Nov-1996  gwr Remove comment that was no longer applicable.
 1.1 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.9.6.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.6.1 17-Apr-2012  yamt sync with head
 1.10.6.1 23-Jun-2013  tls resync from head
 1.5 03-Apr-2020  martin Make route and netstat share the same struct progops (and initialization
code)
 1.4 02-Apr-2020  christos Add a prog_setsockopt (thanks kre@)
 1.3 06-Nov-2014  christos branches: 1.3.16;
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.2 13-Dec-2010  pooka branches: 1.2.24;
be a happy crunch build
 1.1 13-Dec-2010  pooka Convert from RUMP_ACTION to RUMPPRG.
 1.2.24.1 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.3.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.65 02-Jan-2021  uwe route(8): group RTF_GATEWAY and ~RTF_GATEWAY (-iface).

While here, tweak RTF_GATEWAY description. Passive voice elsewhere in
this table is used to talk about the routes themselves, while here
it's about packets.
 1.64 02-Jan-2021  uwe route(8): be consistent about capitalization.
 1.63 02-Jan-2021  uwe route(8): don't split -blackhole and -noblackhole.
 1.62 29-Aug-2020  christos Document 'L'
 1.61 31-Jul-2018  sevan Remove references to XNS
 1.60 04-Jul-2017  wiz branches: 1.60.4; 1.60.6;
Use Ex.
 1.59 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.58 19-Jun-2017  wiz Remove unnecessary Pp.
 1.57 16-Jun-2017  ozaki-r Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.
 1.56 04-Apr-2016  ozaki-r branches: 1.56.8;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.55 23-Mar-2015  roy Add RTF_BROADCAST to mark routes used for the broadcast address when
they are created on the fly. This makes it clear what the route is for
and allows an optimisation in ip_output() by avoiding a call to
in_broadcast() because most of the time we do talk to a host.
It also avoids a needless allocation for the storage of llinfo_arp and
thus vanishes from arp(8) - it showed as incomplete anyway so this
is a nice side effect.

Guard against this and routes marked with RTF_BLACKHOLE in
ip_fastforward().
While here, guard against routes marked with RTF_BLACKHOLE in
ip6_fastforward().
RTF_BROADCAST is IPv4 only, so don't bother checking that here.
 1.54 26-Feb-2015  roy Teach route(8) about RTF_LOCAL.
 1.53 01-Dec-2014  christos Complete the routing argument table by including the ID's used in the routing
display.
 1.52 12-Nov-2014  christos PR/47704: Takahiro HAYASHI: Add -L flag
 1.51 07-Nov-2014  christos Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.
 1.50 05-Nov-2013  kefren Remove esis reference
 1.49 07-Oct-2013  dholland english usage patrol
 1.48 24-Jul-2013  kefren Add -tag description as suggested in PR/45071
 1.47 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.46 11-Nov-2011  gdt branches: 1.46.6;
Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
 1.45 17-Jul-2011  dholland branches: 1.45.2;
prune stray commas
 1.44 03-Jul-2011  wiz Whitespace nit.
 1.43 03-Jul-2011  kefren Mention -mpls and -tag and xref mpls(4)
bin/45071
 1.42 16-Jun-2011  yamt xref link_addr for -link.
 1.41 12-May-2010  christos branches: 1.41.4;
PR/40455: Mihai Chelaru: Add noreject noblackhole options
 1.40 06-Aug-2006  wiz Bump date for previous.
 1.39 06-Aug-2006  dyoung Document -nocloning, -nocloned flags. Shift a couple of columns
right by a character width, to make room for the new flags.
 1.38 29-Jan-2006  wiz Use default option order (AaBbCc...).
 1.37 25-Jan-2006  christos PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.
 1.36 02-Oct-2003  itojun correct typo. PR misc/22944
 1.35 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.34 07-Aug-2003  wiz Bump date for flushall description.
 1.33 19-Jul-2003  jrf This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.
 1.32 03-Jun-2003  itojun permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos
 1.31 25-Feb-2003  wiz Split .Nm with other macro arguments on two lines.
 1.30 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.29 08-Feb-2002  hubertf branches: 1.29.2;
the modifiers (-inet6, ...) do not only affect the behaviour of "flush",
but at least also of "get", so make the wording a bit more general.
 1.28 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.27 16-Nov-2001  wiz Punctuation fix, sort sections, sort SEE ALSO.
 1.26 24-Oct-2001  atatat Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw
 1.25 18-Oct-2001  christos PR/14286: reed@reedmedia.net: Explain default.
 1.24 20-Jul-2001  itojun make prefixlen work on IPv4 too
 1.23 05-Jun-2001  wiz Fix Nd and some whitespace and punctuation.
 1.22 05-Jun-2001  wiz Drop arguments of .Os.
 1.21 27-Apr-2001  manu Added a few examples and a reference to sysctl to enable IP forwarding
Approved by Christos
 1.20 27-Jan-2001  itojun support -cloned command line flag.
i don't think anyone ever going to use it.
 1.19 17-Jul-1999  itojun tweak IPv6 case so that "route show" does not truncate numeric IPv6 address.

PR: 7955
 1.18 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.17 24-Mar-1999  mycroft Remove spurious .ne's.
 1.16 04-Mar-1999  bgrayson Typo fixed
 1.15 23-Oct-1998  lukem * implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).
 1.14 29-Apr-1998  fair fix bad .Xr references
 1.13 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF
 1.11 27-Aug-1997  mikel fix numerous tyops and use some -mdoc macros to advantage
 1.10 10-Jul-1997  mikel comment out xref to XNSrouted(8)
 1.9 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.8 22-Feb-1997  carrel Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.
 1.7 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.29.2.1 02-Oct-2003  tron Pull up revision 1.36 (requested by itojun in ticket #1494):
correct typo. PR misc/22944
 1.41.4.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.45.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.2.1 17-Apr-2012  yamt sync with head
 1.46.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.46.6.1 23-Jun-2013  tls resync from head
 1.56.8.1 07-Jul-2017  martin Pull up following revision(s) (requested by ozaki-r in ticket #107):
usr.sbin/arp/arp.c: revision 1.56
sys/net/rtsock.c: revision 1.218
sys/net/if_llatbl.c: revision 1.20
usr.sbin/arp/arp.c: revision 1.57
sys/net/rtsock.c: revision 1.219
sys/net/if_llatbl.c: revision 1.21
usr.sbin/arp/arp.c: revision 1.58
tests/net/net_common.sh: revision 1.19
sys/netinet6/nd6.h: revision 1.84
sys/netinet6/nd6.h: revision 1.85
tests/net/arp/t_arp.sh: revision 1.23
sys/netinet6/in6.c: revision 1.246
tests/net/arp/t_arp.sh: revision 1.24
sys/netinet6/in6.c: revision 1.247
tests/net/arp/t_arp.sh: revision 1.25
sys/netinet6/in6.c: revision 1.248
tests/net/arp/t_arp.sh: revision 1.26
usr.sbin/ndp/ndp.c: revision 1.49
tests/net/arp/t_arp.sh: revision 1.27
tests/net/ndp/t_ndp.sh: revision 1.20
tests/net/arp/t_arp.sh: revision 1.28
tests/net/ndp/t_ndp.sh: revision 1.21
tests/net/arp/t_arp.sh: revision 1.29
tests/net/ndp/t_ndp.sh: revision 1.22
tests/net/ndp/t_ndp.sh: revision 1.23
tests/net/route/t_flags6.sh: revision 1.13
tests/net/ndp/t_ndp.sh: revision 1.24
tests/net/route/t_flags6.sh: revision 1.14
tests/net/ndp/t_ndp.sh: revision 1.25
tests/net/route/t_flags6.sh: revision 1.15
tests/net/ndp/t_ndp.sh: revision 1.26
sbin/route/rtutil.c: revision 1.9
tests/net/ndp/t_ndp.sh: revision 1.27
tests/net/ndp/t_ndp.sh: revision 1.28
tests/net/net/t_ipv6address.sh: revision 1.14
tests/net/ndp/t_ra.sh: revision 1.28
tests/net/ndp/t_ndp.sh: revision 1.29
sys/net/route.h: revision 1.113
tests/net/ndp/t_ra.sh: revision 1.29
sys/net/rtsock.c: revision 1.220
sys/net/rtsock.c: revision 1.221
sys/net/rtsock.c: revision 1.222
sys/net/rtsock.c: revision 1.223
tests/net/route/t_route.sh: revision 1.13
sys/net/rtsock.c: revision 1.224
sys/net/route.c: revision 1.196
sys/net/if_llatbl.c: revision 1.19
sys/net/route.c: revision 1.197
sbin/route/route.c: revision 1.156
tests/net/route/t_flags.sh: revision 1.16
tests/net/route/t_flags.sh: revision 1.17
usr.sbin/ndp/ndp.c: revision 1.50
tests/net/route/t_flags.sh: revision 1.18
sys/netinet/in.c: revision 1.204
tests/net/route/t_flags.sh: revision 1.19
sys/netinet/in.c: revision 1.205
tests/net/arp/t_arp.sh: revision 1.30
tests/net/arp/t_arp.sh: revision 1.31
sys/net/if_llatbl.h: revision 1.11
tests/net/arp/t_arp.sh: revision 1.32
sys/net/if_llatbl.h: revision 1.12
tests/net/arp/t_arp.sh: revision 1.33
sys/netinet6/nd6.c: revision 1.233
sys/netinet6/nd6.c: revision 1.234
sys/netinet/if_arp.c: revision 1.251
sys/netinet6/nd6.c: revision 1.235
sys/netinet/if_arp.c: revision 1.252
sbin/route/route.8: revision 1.57
sys/net/rtsock.c: revision 1.214
sys/net/rtsock.c: revision 1.215
sys/net/rtsock.c: revision 1.216
sys/net/rtsock.c: revision 1.217
whitespace police
Simplify
We can assume that rt_ifp is always non-NULL.
Sending a routing message (RTM_ADD) on adding an llentry
A message used to be sent on adding a cloned route. Restore the
behavior for backward compatibility.
Requested by ryo@
Drop RTF_CONNECTED from a result of RTM_GET for ARP/NDP entries
ARP/NDP entries aren't connected routes.
Reported by ryo@
Support -c <count> option for route monitor
route command exits if it receives <count> routing messages where
<count> is a value specified by -c.
The option is useful to get only particular message(s) in a test script.
Test routing messages emitted on operations of ARP/NDP entries
Do netstat -a for an appropriate protocol
Add missing declarations for cleanup
Set net.inet.arp.keep only if it's required
Don't create a permanent L2 cache entry on adding an address to an interface
It was created to copy FreeBSD, however actually the cache isn't
necessary. Remove it to simplify the code and reduce the cost to
maintain it (e.g., keep a consistency with a corresponding local
route).
Fix typo
Fix in_lltable_match_prefix
The function has not been used but will be used soon.
Remove unused function (nd6_rem_ifa_lle)
Allow in6_lltable_free_entry to be called without holding the afdata lock of ifp as well as in_lltable_free_entry
This behavior is a bit odd and should be fixed in the future...
Purge ARP/NDP entries on an interface when the interface is down
Fix PR kern/51179
Purge all related L2 caches on removing a route
The change addresses situations similar to PR 51179.
Purge L2 caches on changing an interface of a route
The change addresses situations similar to PR 51179.
Test implicit removals of ARP/NDP entries
One test case reproudces PR 51179.
Fix build of kernels without both INET and INET6
Tweak lltable_sysctl_dumparp
- Rename lltable_sysctl_dumparp to lltable_sysctl_dump
because it's not only for ARP
- Enable it not only for INET but also for INET6
Fix usage of routing messages on arp -d and ndp -d
It didn't work as we expected; we should set RTA_GATEWAY not
RTA_IFP on RTM_GET to return an if_index and the kernel should
use it on RTM_DELETE.
Improve backward compatibility of (fake) routing messages on adding an ARP/NDP entry
A message originally included only DST and GATEWAY. Restore it.
Fix ifdef; care about a case w/ INET6 and w/o INET
Drop RTF_UP from a routing message of a deleted ARP/NDP entry
Check existence of ARP/NDP entries
Checking ARP/NDP entries is valid rather than checking routes.
Fix wrong comment
Drop RTF_LLINFO flag (now it's RTF_LLDATA) from local routes
They don't have llinfo anymore. And also the change fixes unexpected
behavior of ARP proxy.
Restore ARP/NDP entries to route show and netstat -r
Requested by dyoung@ some time ago
Enable to remove multiple ARP/NDP entries for one destination
The kernel can have multiple ARP/NDP entries which have an indentical
destination on different interfaces. This is normal and can be
reproduce easily by ping -I or ping6 -S. We should be able to remove
such entries.
arp -d <ip> and ndp -d <ip> are changed to fetch all ARP/NDP entries
and remove matched entries. So we can remove multiple entries
described above. This fetch all and selective removal behavior is
the same as arp <ip> and ndp <ip>; they also do fetch all entries
and show only matched entries.
Related to PR 51179
Check if ARP/NDP entries are purged when a related route is deleted
 1.60.6.1 10-Jun-2019  christos Sync with HEAD
 1.60.4.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.169 10-Apr-2022  andvar fix various typos in comments and output/log messages.
 1.168 02-Apr-2020  christos Add a prog_setsockopt (thanks kre@)
 1.167 14-Mar-2020  roy route: Enable receive error reporting on the routing socket
 1.166 22-Feb-2020  kamil Avoid undefined behavior

route.c:1523:20, left shift of 1073741824 by 1 places cannot be represented
in type 'int'
 1.165 22-Jan-2020  roy route: address flags are more useful than interface flags for address msgs
 1.164 22-Jan-2020  roy route: Decode the correct flags for interface address messages
 1.163 02-Sep-2019  roy route(8): Show addres for RTM_LOSING

While here, add /* FALLTHROUGH */.
 1.162 31-Aug-2019  roy route(8): show addrs for RTM_MISS
 1.161 22-Aug-2019  roy route(8): print RTM_CHANGE messages

XXX Pullup -9
 1.160 14-Aug-2018  roy branches: 1.160.2;
Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.
 1.159 23-Mar-2018  roy branches: 1.159.2;
Handle the routing socket overflowing gracefully.
 1.158 13-Dec-2017  christos branches: 1.158.2;
Use the definitions from the standard header files and replace homebrew
snprintb with the libutil one.
 1.157 13-Dec-2017  uwe Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.

PR bin/52815
 1.156 16-Jun-2017  ozaki-r Support -c <count> option for route monitor

route command exits if it receives <count> routing messages where
<count> is a value specified by -c.

The option is useful to get only particular message(s) in a test script.
 1.155 17-Mar-2017  roy branches: 1.155.4;
Report the PID for the process changing the address.
 1.154 04-Apr-2016  ozaki-r branches: 1.154.2; 1.154.4;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.153 23-Jan-2016  christos no need for <sys/mbuf.h>
 1.152 17-Jan-2016  christos PR/50671: David Binderman: fix memory leak.
 1.151 23-Mar-2015  roy Add RTF_BROADCAST to mark routes used for the broadcast address when
they are created on the fly. This makes it clear what the route is for
and allows an optimisation in ip_output() by avoiding a call to
in_broadcast() because most of the time we do talk to a host.
It also avoids a needless allocation for the storage of llinfo_arp and
thus vanishes from arp(8) - it showed as incomplete anyway so this
is a nice side effect.

Guard against this and routes marked with RTF_BLACKHOLE in
ip_fastforward().
While here, guard against routes marked with RTF_BLACKHOLE in
ip6_fastforward().
RTF_BROADCAST is IPv4 only, so don't bother checking that here.
 1.150 26-Feb-2015  roy Teach route(8) about RTF_LOCAL.
 1.149 20-Dec-2014  prlw1 MKINET6=no build fixes

http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html
 1.148 17-Dec-2014  roy Note that RTM_CHANGE can also change the gateway
 1.147 12-Nov-2014  christos PR/47704: Takahiro HAYASHI: Add -L flag
 1.146 07-Nov-2014  christos Now that the code can support tags and verbose route printing, enable them.
Also document previously undocumented flags.
 1.145 06-Nov-2014  christos Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.144 19-Oct-2013  christos branches: 1.144.4;
use correct function
 1.143 19-Oct-2013  christos use symbolic flags
 1.142 19-Oct-2013  christos use scopeid functions
 1.141 18-Oct-2013  christos avoid pointer gymnastics
 1.140 01-Mar-2013  joerg Retire OSI network stack. OK core@
 1.139 04-Oct-2012  uwe Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.
 1.138 08-Aug-2012  christos branches: 1.138.2;
remove useless rump headers.
 1.137 17-Mar-2012  christos PR/42179: Christoph Badura: Be a little friendlier about missing args.
 1.136 26-Dec-2011  christos branches: 1.136.2;
Off by one and clarity improvement from Christian Biere
 1.135 24-Dec-2011  christos PR/45661: Henning Petersen: Overlapping buffer in route.c.
 1.134 11-Nov-2011  gdt Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
 1.133 07-Oct-2011  joerg branches: 1.133.2;
Simplify.
 1.132 29-Aug-2011  joerg Use __dead
 1.131 01-Jul-2011  joerg Fix memset usage.
 1.130 22-Jun-2011  kefren don't compile tag functions if SMALL is defined. Should fix the build
 1.129 21-Jun-2011  kefren Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation
 1.128 01-Feb-2011  matt Add a new AF/PF_ROUTE which is 64-bit clean which makes the routing socket
interface (and its associated sysctls) act identically for both 32 and 64 bit
programs. The old unclean one remains for backward compatibility.
 1.127 13-Dec-2010  pooka branches: 1.127.2;
Convert from RUMP_ACTION to RUMPPRG.
 1.126 12-Nov-2010  roy Support the new RTM_IFINFO and RTM_CHGADDR messages.
 1.125 05-Nov-2010  pooka adapt to new rumpclient_init() signature
 1.124 04-Nov-2010  pooka #ifdef variable correctly
 1.123 04-Nov-2010  pooka be consistent in what to leave outside of SMALL
 1.122 04-Nov-2010  pooka Support RUMP_ACTION to compile a rump kernel client.
 1.121 26-Jun-2010  kefren add MPLS clue - mpls and tag keywords
 1.120 12-May-2010  christos PR/40455: Mihai Chelaru: Add noreject noblackhole options
 1.119 28-Dec-2008  christos parse unsigned long with strtoul not atoi
 1.118 10-Sep-2008  dyoung branches: 1.118.6;
Get the socket addresses for dst/gateway/netmask/interface/ifaddr
out of the global namespace.
 1.117 10-Sep-2008  dyoung Don't cast a sockunion * to sockaddr *. Instead, reference the
sockaddr inside of the sockunion.
 1.116 10-Sep-2008  dyoung Delete superfluous casts to void *.
 1.115 10-Sep-2008  dyoung Constify.
 1.114 10-Sep-2008  dyoung Constify.
 1.113 10-Sep-2008  dyoung Constify.

For clarity's sake, do not assign a new value to inet_makenetandmask()'s
argument, `inet'.
 1.112 09-Sep-2008  dyoung Extract subroutine extract_addrs() for reuse, later.

Replace the anonymous constant, 0, with AF_UNSPEC.
 1.111 09-Sep-2008  dyoung Constify.
 1.110 09-Sep-2008  dyoung Shorten a staircase. Remove superfluous parentheses from return
statements. Constify.
 1.109 09-Sep-2008  dyoung Use a union and sizeof() to avoid a cast and an anonymous constant
buffer length, respectively.
 1.108 09-Sep-2008  dyoung Use bool.
 1.107 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.106 18-Feb-2007  hubertf branches: 1.106.12; 1.106.16;
TSEL() is const char* now
 1.105 11-Nov-2006  apb Fix a bug that caused 0.0.0.0/0 to be treated like 0.0.0.0/32.

foo << 32 is undefined per section 6.5.7 of the C99 standard
if foo is (or is promoted to) a 32-bit type.
 1.104 23-Sep-2006  dyoung Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().
 1.103 23-Sep-2006  dyoung Move the #ifndef SMALL code together.
 1.102 23-Sep-2006  dyoung Use the symbol AF_UNSPEC instead of 0 as appropriate.
 1.101 23-Sep-2006  dyoung Remove dead code.
 1.100 26-Aug-2006  matt Remove XNS and CCITT/X25 bits.
 1.99 06-Aug-2006  dyoung KNF err(3), errx(3) usage, indentation, braces.
 1.98 06-Aug-2006  dyoung Add route keywords -nocloned, -nocloning.
 1.97 29-Jan-2006  wiz Use default option order (AaBbCc...).
 1.96 26-Jan-2006  is Print the INET netmask if it is non-contiguous.
 1.95 25-Jan-2006  christos PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.
 1.94 25-Jan-2006  christos PR/32629: Yves-Emmanuel JUTARD: Type errors in sbin/route/route.c, another
u_char/char conflict.
 1.93 31-Aug-2005  ginsbach Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.
 1.92 30-Aug-2005  ginsbach Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).
 1.91 15-Aug-2005  ginsbach Make sure that a netmask socket address value prints appropriately when the
family is unset. Either the destination or interface address socket address
family value is used. This change prevents the following sort of output:

RTM_NEWADDR: address being added to iface: len 60, metric 0, flags:<UP>
sockaddrs: <NETMASK,IFA,BRD>
(0) 00.00.ff.00.00 127.0.0.1 127.0.0.1

With this change the last line becomes:

255.0.0.0 127.0.0.1 127.0.0.1

Also make sure that when using a generated inet netmask the address family
is set. With this change a generated netmask will print appropriately
when using the verbose (-v) option.
 1.90 12-Aug-2005  ginsbach Make sure the get command always exits non-zero on error. This makes things
like the following work as expected.

#!/bin/sh

if ! route -sn get default >/dev/null 2>&1; then
echo default gateway not set
exit 1
fi
echo default gateway set

Handle routing socket write(2) errors when they occur. This produces
better diagnostics by allowing for handling of the special route errno
values ESRCH, EBUSY, and ENOBUFS even with the quiet (-q) option or
when doing a get command.
 1.89 12-Aug-2005  ginsbach Trim the local domain name in routename() for INET6 lookups; similar to
INET lookups.
 1.88 10-Aug-2005  he Make this build for __GNUC__ <= 2 (i.e. for vax). The cast to
caddr_t removes a const qualifier. Instead, cast the first element
of the subtraction to "struct sockaddr *" to work around the problem.
 1.87 09-Aug-2005  ginsbach Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]
 1.86 09-Aug-2005  ginsbach Fix the default case in sodump(). Printing the address of the "which"
string isn't really that useful. Instead print the string and the value
of sa_family.
 1.85 09-Aug-2005  ginsbach More style nits (KNF); casts and sizeof's are not followed by a space.
 1.84 20-Jul-2005  ginsbach switch is not a function, so add a space; sort switch elements
alphabetically (KNF).
 1.83 15-Jul-2005  ginsbach * Exit non-zero error code when flushroute() fails operating on the
routing socket, e.g. running route flush as non-root.

* When quiet (-q) don't append error string to a non-existent
diagnostic output (stdout). The error diagnostic is still written
to stderr. [from FreeBSD]

* Use warn(3) in place of perror(3).
 1.82 26-Jun-2005  christos const poisoning.
 1.81 25-Jun-2005  dyoung Teach route(8) to print the messages generated by net80211.
 1.80 19-May-2005  ginsbach Convert prefixlen() to ANSI function declaration. Missed by earlier
conversion.
 1.79 19-May-2005  ginsbach Due to a limitation in inet_addr(3) it was not possible to specify a
netmask value of 0xffffffff (INADDR_NONE). Fix by using inet_aton(3).
Note it was possible to specify the same mask as the dotted quad
255.255.255.255 because of a later call to gethostbyname(3).
[From FreeBSD]
 1.78 13-May-2005  ginsbach Fix botched prior commit. Additional debugging error messages mistakenly
committed.
 1.77 12-May-2005  ginsbach * Honor -net when using CIDR (net/mask) notation. This differs
from the default CIDR (host/mask) interpretation. As discussed on
tech-net.

* Use errx() in place of fprintf() and exit(). Make the error message
formats consistent.
 1.76 10-May-2005  ginsbach Fix macro NEXTADDR so that the names, like so_dst, are printed
rather than u. The preprocessor doesn't do replacement within
strings, so the # string creation operator must be used.
 1.75 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.74 16-Nov-2004  itojun NI_WITHSCOPEID was not picked up by IETF standardization process.
 1.73 15-May-2004  itojun bump buffer size for any_ntoa(), for huge sa_len
 1.72 15-May-2004  itojun 2-byte read overrun for unknown sockaddr. from openbsd
XXX out[64], is it safe? what if sa_len > 23?
 1.71 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.70 01-Oct-2003  itojun print prefixlen on -show
 1.69 16-Sep-2003  cube Remove a comment that referred to a non-committed part of the patch I
submitted for bin/17613. Ok'd by mrg@.
 1.68 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.67 19-Jul-2003  jrf This is an updated submitted patch originally written by Jim Rees
and sent in by Greg Hudson as seen in PR misc/3227. Basically what it
does is adds a flushall option which deletes all but localhost routes.
This is done by andoring in a flag called doall (1 means do all routes
including gateway, 0 means do a regular flush). I have seen some
platforms that do this. I tested it out on ipv4 only, it works as
advertised. Commit was approved by christos@.
 1.66 11-Jun-2003  christos PR/21856: Robert Elz: Changes to route(8) to allow /n instead of -prefixlen
for INET6
 1.65 03-Jun-2003  itojun permit foo/bar notation, like "route add 10.0.0.0/8 127.0.0.1".
originally by provos
 1.64 17-May-2003  itojun strlcpy [a few mistakes found]
 1.63 21-Apr-2003  jrf This addresses PR 17613 when certain methods of adding routes would
muck up the routing tables. The patch was submitted by Quentin Garnier
<netbsd@quatriemek.com> and tweaked a little after it was reviewed
by Christos Zoulas <christos@netbsd.org>. Final change/commit approved
by Christos.
 1.62 03-Apr-2003  jrf Made a note in the code about the -d and -d options brought up in
PR 18674. Thanks to Chris Jones for pointing it out.
 1.61 18-Oct-2002  itojun correct prefixlen handling for IPv4.
 1.60 18-Oct-2002  itojun Make prefixlen check to make sure its argument is present before deref
from openbsd
 1.59 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.58 10-Jun-2002  itojun permit DNS names to address portion. they will be considered as RTF_HOST
if specified as destination (as there's no getnetbyname in IPv6).
 1.57 05-Jun-2002  itojun if we're unsure about prefixlen, don't say "128".
 1.56 05-Jun-2002  itojun more correct ion to RTF_HOST handling.
 1.55 04-Jun-2002  itojun do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>
 1.54 20-May-2002  itojun branches: 1.54.2;
raise RTF_HOST if destination is a host (/128). from ume
 1.53 21-Feb-2002  christos PR/15672: Love: route monitor missing info
 1.52 15-Nov-2001  christos Make route exit with a non-zero error code when operations to the routing
socket fails. eg, running route add 1.2.3.4 5.6.7.8 as non root.
 1.51 02-Nov-2001  lukem fix -Wshadow warnings
 1.50 24-Oct-2001  atatat Provide a short output format for the get command that only prints the
address corresponding to RTA_GATEWAY, or nothing if it doesn't exist.
Modify the exit value of route depending on this, so that one can do
stuff like:

#!/bin/sh
gw=`route -sn get default 2>/dev/null`
if [ -z "$gw" ]; then
echo no default route
exit 1
fi
ping -w1 -c1 $gw >/dev/null 2>&1
if ! route -sn get $gw >/dev/null; then
echo default gateway not responding
exit 1
fi
echo default gateway is at $gw
 1.49 24-Oct-2001  atatat Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.
 1.48 20-Jul-2001  itojun off-by-one error in -prefixlen arg validation (do not permit 129 on IPv6)
 1.47 20-Jul-2001  itojun make prefixlen work on IPv4 too
 1.46 16-Jul-2001  bad The way pmsg_addrs() is used requires that it always prints a newline and
flushes stdout before returning.

Previously the decoded output for a message was stuck in stdio buffers until
the next arrived.
 1.45 19-Feb-2001  cgd convert to use getprogname()
 1.44 04-Feb-2001  christos remove nested externs.
 1.43 27-Jan-2001  itojun support -cloned command line flag.
i don't think anyone ever going to use it.
 1.42 27-Jan-2001  itojun mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.
 1.41 27-Jan-2001  itojun support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us
 1.40 27-Jan-2001  itojun remove use of uninitialized route (struct ortentry).
it seems that the bug was born during 4.3reno -> 4.4Lite1 transition.
 1.39 10-Oct-2000  itojun on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.
 1.38 04-May-2000  sommerfeld branches: 1.38.4;
Allow INET6 to be used with SMALL without undefined symbols
 1.37 20-Apr-2000  itojun use scoped notation for link-local multicast too.
 1.36 20-Apr-2000  itojun support extended scoped address notation (fe80::1%de0).
it hides implementation detail (embedded ifid) from the users.
 1.35 03-Dec-1999  itojun don't make "-prefixlen 64" a default in -inet6 case. the past behavior
was not compatible with past practice ("route get" did not work right).

sync with recent KAME.
 1.34 01-Nov-1999  sommerfeld Display local address associated with route (if any) in "route get".
 1.33 03-Sep-1999  itojun branches: 1.33.2;
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179
 1.32 06-Jul-1999  mjacob Incorrect integration. ctime takes a time_t value, not a long.
 1.31 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.30 23-Oct-1998  lukem branches: 1.30.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).
 1.29 26-Jul-1998  mycroft const poisoning.
 1.28 01-Apr-1998  kleink Need <time.h> for time() prototype.
 1.27 05-Feb-1998  ross 64-bit sweep, "route -v show" was spinning forever.
 1.26 16-Nov-1997  christos Use {warn,err}{,x}(3) instead of printf's
 1.25 01-Oct-1997  enami Don't declare optind.
 1.24 16-Sep-1997  lukem resolve conflicts from lite-2 import
 1.23 15-Sep-1997  lukem * cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF
 1.22 02-Sep-1997  thorpej Fix uninitialized pointer botch when attempting to flush an already
empty routing table. From Matthias Scheler <tron@lyssa.owl.de>, in
PR #4074.
 1.21 27-Apr-1997  thorpej Don't SEGV if a qualifier is passed without an argument. From
Geoff Wing <mason@primenet.com.au>, fixes PR #2700.
 1.20 21-Apr-1997  mrg KNF. be safe with buffers.
 1.19 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.18 22-Feb-1997  carrel Remove uid checks since the kernel now handles this and route(1) is no
longer setuid.
Document the "Permission denied" msg in the man page since this is
_slightly_ less clear than route(1)'s old error msg.
 1.17 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.16 15-Apr-1996  cgd check returns of inet_addr() and inet_network() against INADDR_NONE,
not -1, per the manual page. on 64-bit systems like the alpha, -1 will
never equal (unsigned long)INADDR_NONE.
 1.15 07-Jan-1996  pk Produce less output on -q as promised by the man page (John Hawkinson; PR#998).
 1.14 20-Apr-1995  mycroft Interface-specific routes can be static.
 1.13 20-Apr-1995  mycroft Implement the document `-llinfo' flag.
 1.12 18-Apr-1995  mycroft Remove extra `break;'.
 1.11 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.10 24-Dec-1994  cgd kill some extraneous equal signs.
 1.9 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.8 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.7 13-May-1994  mycroft Clean up import.
 1.6 01-Aug-1993  mycroft Add RCS identifiers.
 1.5 25-Apr-1993  mycroft Compile X.25, OSI, and NS code.
 1.4 18-Apr-1993  mycroft Cleanup for GCC 2.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.30.2.1 14-Jan-2002  he Pull up revision 1.46 (requested by bad):
Fix problem where an output message would be stuck in stdio buffers
until the next one arrived.
 1.33.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.38.4.6 18-Oct-2002  itojun sbin/route/route.c 1.60-1.61 via patch

Correct prefixlen option handling.

(itojun)
 1.38.4.5 29-Jul-2001  he Pull up revision 1.46 (requested by bad):
Make sure decoded output from ``route monitor'' gets properly
flushed.
 1.38.4.4 05-Apr-2001  he Pull up revision 1.42 (requested by itojun):
Mark cloned routes with RTF_CLONED. Present it in ``netstat -r''
output by ``c''.
 1.38.4.3 05-Apr-2001  he Pull up revision 1.41 (requested by itojun):
Support RTF_BLACKHOLE routes.
 1.38.4.2 05-Apr-2001  he Pull up revision 1.40 (requested by itojun):
Remove use of uninitialized route (struct ortentry).
 1.38.4.1 17-Oct-2000  tv Pullup 1.39 [itojun]:
on "route monitor", print RTM_IFANNOUNCE, RTM_IFINFO (new #), and others.
 1.54.2.4 26-Jan-2003  jmc Pullup revisions 1.57-1.58 (requested by fredb in ticket #1080)
permit DNS names to address portion. they will be considered as
RTF_HOST if specified as destination (as there's no getnetbyname in
IPv6).
 1.54.2.3 21-Oct-2002  lukem Pull up revision 1.60 (requested by itojun in ticket #923):
Make prefixlen check to make sure its argument is present before deref
from openbsd
 1.54.2.2 06-Jun-2002  lukem Pull up revisions 1.56-1.57 (requested by itojun in ticket #185):
1.56:
more correct ion to RTF_HOST handling.
1.57:
if we're unsure about prefixlen, don't say "128".
 1.54.2.1 05-Jun-2002  lukem Pull up revision 1.55 (requested by itojun in ticket #160):
do not have -prefixlen 128 on RTF_HOST.
From: Dawid Szymanski <dawszy@arhea.net>
 1.106.16.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.106.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.106.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.106.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.118.6.1 11-May-2010  matt Fixup for u_quad_t change for route interface.
 1.127.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.133.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.133.2.2 30-Oct-2012  yamt sync with head
 1.133.2.1 17-Apr-2012  yamt sync with head
 1.136.2.1 17-Oct-2012  riz Pull up following revision(s) (requested by uwe in ticket #592):
sbin/route/route.c: revision 1.139
Fix fallout from 1.129 that converted sou::so_foo from unions to
pointers but missed (char *)&soup->so_foo => (char *)soup->so_foo in
mask_addr(). It worked by luck - unless it didn't: due to pointer
numerology on amd64 route add -net ClassC without explicit /24 prefix
length specification would result into /16 destination instead of /24.
 1.138.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.138.2.2 23-Jun-2013  tls resync from head
 1.138.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.144.4.3 03-Jan-2018  snj Pull up following revision(s) (requested by uwe in ticket #1542):
sbin/route/route.c: revision 1.157
Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.
PR bin/52815
 1.144.4.2 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.144.4.1 29-Dec-2014  martin Pull up following revision(s) (requested by prlw1 in ticket #358):
sbin/route/route.c: revision 1.149
external/apache2/mDNSResponder/dist/mDNSPosix/mDNSPosix.c: revision 1.7
external/bsd/ipf/dist/lib/printhost.c: revision 1.3
usr.sbin/lpr/common_source/common.c: revision 1.43
usr.sbin/lpr/common_source/Makefile: revision 1.12
external/bsd/ipf/dist/lib/printhostmask.c: revision 1.3
external/bsd/ipf/dist/lib/save_v1trap.c: revision 1.2
external/bsd/dhcpcd/dist/dhcpcd.c: revision 1.21
external/bsd/tcpdump/bin/Makefile: revision 1.12
external/bsd/ipf/dist/lib/save_v2trap.c: revision 1.2
external/bsd/ipf/dist/tools/lexer.c: revision 1.2
external/bsd/ppp/usr.sbin/pppd/sys-bsd.c: revision 1.3
external/bsd/ipf/dist/lib/printipfexpr.c: revision 1.2
MKINET6=no build fixes
http://mail-index.netbsd.org/tech-net/2014/12/13/msg004898.html
 1.154.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.154.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.155.4.4 25-Aug-2018  martin Pull up following revision(s) (requested by roy in ticket #976):

sbin/route/route.c: revision 1.160

Resolve every route(4) message type before printing anything more about it
other than the type and length.

This solves the issue where RTM_ONEWADDR is received and it tries to
parse route information from it.
 1.155.4.3 09-Apr-2018  bouyer Pull up following revision(s) (requested by roy in ticket #724):
tests/net/icmp/t_ping.c: revision 1.19
sys/netinet6/raw_ip6.c: revision 1.166
sys/netinet6/ip6_input.c: revision 1.195
sys/net/raw_usrreq.c: revision 1.59
sys/sys/socketvar.h: revision 1.151
sys/kern/uipc_socket2.c: revision 1.128
tests/lib/libc/sys/t_recvmmsg.c: revision 1.2
lib/libc/sys/recv.2: revision 1.38
sys/net/rtsock.c: revision 1.239
sys/netinet/udp_usrreq.c: revision 1.246
sys/netinet6/icmp6.c: revision 1.224
tests/net/icmp/t_ping.c: revision 1.20
sys/netipsec/keysock.c: revision 1.63
sys/netinet/raw_ip.c: revision 1.172
sys/kern/uipc_socket.c: revision 1.260
tests/net/icmp/t_ping.c: revision 1.22
sys/kern/uipc_socket.c: revision 1.261
tests/net/icmp/t_ping.c: revision 1.23
sys/netinet/ip_mroute.c: revision 1.155
sbin/route/route.c: revision 1.159
sys/netinet6/ip6_mroute.c: revision 1.123
sys/netatalk/ddp_input.c: revision 1.31
sys/netcan/can.c: revision 1.3
sys/kern/uipc_usrreq.c: revision 1.184
sys/netinet6/udp6_usrreq.c: revision 1.138
tests/net/icmp/t_ping.c: revision 1.18
socket: report receive buffer overflows
Add soroverflow() which increments the overflow counter, sets so_error
to ENOBUFS and wakes the receive socket up.
Replace all code that manually increments this counter with soroverflow().
Add soroverflow() to raw_input().
This allows userland to detect route(4) overflows so it can re-sync
with the current state.
socket: clear error even when peeking
The error has already been reported and it's pointless requiring another
recv(2) call just to clear it.
socket: remove now incorrect comment that so_error is only udp
As it can be affected by route(4) sockets which are raw.
rtsock: log dropped messages that we cannot report to userland
Handle ENOBUFS when receiving messages.
Don't send messages if the receiver has died.
Sprinkle more soroverflow().
Handle ENOBUFS in recv
Handle ENOBUFS in sendto
Note value received. Harden another sendto for ENOBUFS.
Handle the routing socket overflowing gracefully.
Allow a valid sendto .... duh
Handle errors better.
Fix test for checking we sent all the data we asked to.
 1.155.4.2 21-Dec-2017  snj Pull up following revision(s) (requested by uwe in ticket #448):
sbin/route/route.c: revision 1.157
Fix typo in flag name. We should probably just use IFFBITS string
that <net/if.h> defines.
PR bin/52815
 1.155.4.1 07-Jul-2017  martin Pull up following revision(s) (requested by ozaki-r in ticket #107):
usr.sbin/arp/arp.c: revision 1.56
sys/net/rtsock.c: revision 1.218
sys/net/if_llatbl.c: revision 1.20
usr.sbin/arp/arp.c: revision 1.57
sys/net/rtsock.c: revision 1.219
sys/net/if_llatbl.c: revision 1.21
usr.sbin/arp/arp.c: revision 1.58
tests/net/net_common.sh: revision 1.19
sys/netinet6/nd6.h: revision 1.84
sys/netinet6/nd6.h: revision 1.85
tests/net/arp/t_arp.sh: revision 1.23
sys/netinet6/in6.c: revision 1.246
tests/net/arp/t_arp.sh: revision 1.24
sys/netinet6/in6.c: revision 1.247
tests/net/arp/t_arp.sh: revision 1.25
sys/netinet6/in6.c: revision 1.248
tests/net/arp/t_arp.sh: revision 1.26
usr.sbin/ndp/ndp.c: revision 1.49
tests/net/arp/t_arp.sh: revision 1.27
tests/net/ndp/t_ndp.sh: revision 1.20
tests/net/arp/t_arp.sh: revision 1.28
tests/net/ndp/t_ndp.sh: revision 1.21
tests/net/arp/t_arp.sh: revision 1.29
tests/net/ndp/t_ndp.sh: revision 1.22
tests/net/ndp/t_ndp.sh: revision 1.23
tests/net/route/t_flags6.sh: revision 1.13
tests/net/ndp/t_ndp.sh: revision 1.24
tests/net/route/t_flags6.sh: revision 1.14
tests/net/ndp/t_ndp.sh: revision 1.25
tests/net/route/t_flags6.sh: revision 1.15
tests/net/ndp/t_ndp.sh: revision 1.26
sbin/route/rtutil.c: revision 1.9
tests/net/ndp/t_ndp.sh: revision 1.27
tests/net/ndp/t_ndp.sh: revision 1.28
tests/net/net/t_ipv6address.sh: revision 1.14
tests/net/ndp/t_ra.sh: revision 1.28
tests/net/ndp/t_ndp.sh: revision 1.29
sys/net/route.h: revision 1.113
tests/net/ndp/t_ra.sh: revision 1.29
sys/net/rtsock.c: revision 1.220
sys/net/rtsock.c: revision 1.221
sys/net/rtsock.c: revision 1.222
sys/net/rtsock.c: revision 1.223
tests/net/route/t_route.sh: revision 1.13
sys/net/rtsock.c: revision 1.224
sys/net/route.c: revision 1.196
sys/net/if_llatbl.c: revision 1.19
sys/net/route.c: revision 1.197
sbin/route/route.c: revision 1.156
tests/net/route/t_flags.sh: revision 1.16
tests/net/route/t_flags.sh: revision 1.17
usr.sbin/ndp/ndp.c: revision 1.50
tests/net/route/t_flags.sh: revision 1.18
sys/netinet/in.c: revision 1.204
tests/net/route/t_flags.sh: revision 1.19
sys/netinet/in.c: revision 1.205
tests/net/arp/t_arp.sh: revision 1.30
tests/net/arp/t_arp.sh: revision 1.31
sys/net/if_llatbl.h: revision 1.11
tests/net/arp/t_arp.sh: revision 1.32
sys/net/if_llatbl.h: revision 1.12
tests/net/arp/t_arp.sh: revision 1.33
sys/netinet6/nd6.c: revision 1.233
sys/netinet6/nd6.c: revision 1.234
sys/netinet/if_arp.c: revision 1.251
sys/netinet6/nd6.c: revision 1.235
sys/netinet/if_arp.c: revision 1.252
sbin/route/route.8: revision 1.57
sys/net/rtsock.c: revision 1.214
sys/net/rtsock.c: revision 1.215
sys/net/rtsock.c: revision 1.216
sys/net/rtsock.c: revision 1.217
whitespace police
Simplify
We can assume that rt_ifp is always non-NULL.
Sending a routing message (RTM_ADD) on adding an llentry
A message used to be sent on adding a cloned route. Restore the
behavior for backward compatibility.
Requested by ryo@
Drop RTF_CONNECTED from a result of RTM_GET for ARP/NDP entries
ARP/NDP entries aren't connected routes.
Reported by ryo@
Support -c <count> option for route monitor
route command exits if it receives <count> routing messages where
<count> is a value specified by -c.
The option is useful to get only particular message(s) in a test script.
Test routing messages emitted on operations of ARP/NDP entries
Do netstat -a for an appropriate protocol
Add missing declarations for cleanup
Set net.inet.arp.keep only if it's required
Don't create a permanent L2 cache entry on adding an address to an interface
It was created to copy FreeBSD, however actually the cache isn't
necessary. Remove it to simplify the code and reduce the cost to
maintain it (e.g., keep a consistency with a corresponding local
route).
Fix typo
Fix in_lltable_match_prefix
The function has not been used but will be used soon.
Remove unused function (nd6_rem_ifa_lle)
Allow in6_lltable_free_entry to be called without holding the afdata lock of ifp as well as in_lltable_free_entry
This behavior is a bit odd and should be fixed in the future...
Purge ARP/NDP entries on an interface when the interface is down
Fix PR kern/51179
Purge all related L2 caches on removing a route
The change addresses situations similar to PR 51179.
Purge L2 caches on changing an interface of a route
The change addresses situations similar to PR 51179.
Test implicit removals of ARP/NDP entries
One test case reproudces PR 51179.
Fix build of kernels without both INET and INET6
Tweak lltable_sysctl_dumparp
- Rename lltable_sysctl_dumparp to lltable_sysctl_dump
because it's not only for ARP
- Enable it not only for INET but also for INET6
Fix usage of routing messages on arp -d and ndp -d
It didn't work as we expected; we should set RTA_GATEWAY not
RTA_IFP on RTM_GET to return an if_index and the kernel should
use it on RTM_DELETE.
Improve backward compatibility of (fake) routing messages on adding an ARP/NDP entry
A message originally included only DST and GATEWAY. Restore it.
Fix ifdef; care about a case w/ INET6 and w/o INET
Drop RTF_UP from a routing message of a deleted ARP/NDP entry
Check existence of ARP/NDP entries
Checking ARP/NDP entries is valid rather than checking routes.
Fix wrong comment
Drop RTF_LLINFO flag (now it's RTF_LLDATA) from local routes
They don't have llinfo anymore. And also the change fixes unexpected
behavior of ARP proxy.
Restore ARP/NDP entries to route show and netstat -r
Requested by dyoung@ some time ago
Enable to remove multiple ARP/NDP entries for one destination
The kernel can have multiple ARP/NDP entries which have an indentical
destination on different interfaces. This is normal and can be
reproduce easily by ping -I or ping6 -S. We should be able to remove
such entries.
arp -d <ip> and ndp -d <ip> are changed to fetch all ARP/NDP entries
and remove matched entries. So we can remove multiple entries
described above. This fetch all and selective removal behavior is
the same as arp <ip> and ndp <ip>; they also do fetch all entries
and show only matched entries.
Related to PR 51179
Check if ARP/NDP entries are purged when a related route is deleted
 1.158.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.158.2.1 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.159.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.159.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.159.2.1 10-Jun-2019  christos Sync with HEAD
 1.160.2.4 24-Jan-2020  martin Pull up following revision(s) (requested by roy in ticket #646):

sbin/route/route.c: revision 1.164
sbin/route/route.c: revision 1.165

route: Decode the correct flags for interface address messages
route: address flags are more useful than interface flags for address msgs
 1.160.2.3 05-Sep-2019  martin Pull up following revision(s) (requested by roy in ticket #172):

sbin/route/route.c: revision 1.163

route(8): Show addres for RTM_LOSING
While here, add /* FALLTHROUGH */.
 1.160.2.2 01-Sep-2019  martin Pull up following revision(s) (requested by roy in ticket #150):

sbin/route/route.c: revision 1.162

route(8): show addrs for RTM_MISS
 1.160.2.1 26-Aug-2019  martin Pull up following revision(s) (requested by roy in ticket #108):

sbin/route/route.c: revision 1.161

route(8): print RTM_CHANGE messages
XXX Pullup -9
 1.3 03-Apr-2020  martin Make route and netstat share the same struct progops (and initialization
code)
 1.2 02-Apr-2020  christos Add a prog_setsockopt (thanks kre@)
 1.1 13-Dec-2010  pooka branches: 1.1.46;
Convert from RUMP_ACTION to RUMPPRG.
 1.1.46.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.4 31-Oct-2022  andvar fix various typos in comments and one output message.
 1.3 03-Apr-2020  martin Make route and netstat share the same struct progops (and initialization
code)
 1.2 02-Apr-2020  christos Add a prog_setsockopt (thanks kre@)
 1.1 13-Dec-2010  pooka branches: 1.1.46;
Convert from RUMP_ACTION to RUMPPRG.
 1.1.46.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11 29-Aug-2020  christos Instead of defining RTF_LLINFO, use RTF_LLDATA
 1.10 13-Jul-2017  manu Fix route and netstat -r output when built with -DSMALL

A missing \n caused the routing table to be printed all in one line
if -DSMALL was used.
 1.9 28-Jun-2017  ozaki-r Restore ARP/NDP entries to route show and netstat -r

Requested by dyoung@ some time ago
 1.8 04-Apr-2016  ozaki-r branches: 1.8.8;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.7 23-Jan-2016  christos no need for <sys/mbuf.h>
 1.6 23-Mar-2015  roy Add RTF_BROADCAST to mark routes used for the broadcast address when
they are created on the fly. This makes it clear what the route is for
and allows an optimisation in ip_output() by avoiding a call to
in_broadcast() because most of the time we do talk to a host.
It also avoids a needless allocation for the storage of llinfo_arp and
thus vanishes from arp(8) - it showed as incomplete anyway so this
is a nice side effect.

Guard against this and routes marked with RTF_BLACKHOLE in
ip_fastforward().
While here, guard against routes marked with RTF_BLACKHOLE in
ip6_fastforward().
RTF_BROADCAST is IPv4 only, so don't bother checking that here.
 1.5 26-Feb-2015  roy Teach route(8) about RTF_LOCAL.
 1.4 07-Jan-2015  christos branches: 1.4.2;
make netname4 match the netname6 signature avoiding a NULL pointer.
 1.3 12-Nov-2014  christos PR/47704: Takahiro HAYASHI: Add -L flag
 1.2 08-Nov-2014  christos give a little more space
 1.1 06-Nov-2014  christos Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.4.2.4 26-Jul-2017  snj Pull up following revision(s) (requested by manu in ticket #1454):
sbin/route/rtutil.c: revision 1.10
Fix route and netstat -r output when built with -DSMALL
A missing \n caused the routing table to be printed all in one line
if -DSMALL was used.
 1.4.2.3 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #395):
sbin/route/rtutil.c: revision 1.4
sbin/route/rtutil.h: revision 1.3
usr.bin/netstat/if.c: revision 1.81
make netname4 match the netname6 signature avoiding a NULL pointer.
adjust to the netname4 prototype.
 1.4.2.2 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.4.2.1 07-Jan-2015  martin file rtutil.c was added on branch netbsd-7 on 2015-01-08 11:01:01 +0000
 1.8.8.2 25-Jul-2017  snj Pull up following revision(s) (requested by manu in ticket #131):
sbin/route/rtutil.c: revision 1.10
Fix route and netstat -r output when built with -DSMALL
A missing \n caused the routing table to be printed all in one line
if -DSMALL was used.
 1.8.8.1 07-Jul-2017  martin Pull up following revision(s) (requested by ozaki-r in ticket #107):
usr.sbin/arp/arp.c: revision 1.56
sys/net/rtsock.c: revision 1.218
sys/net/if_llatbl.c: revision 1.20
usr.sbin/arp/arp.c: revision 1.57
sys/net/rtsock.c: revision 1.219
sys/net/if_llatbl.c: revision 1.21
usr.sbin/arp/arp.c: revision 1.58
tests/net/net_common.sh: revision 1.19
sys/netinet6/nd6.h: revision 1.84
sys/netinet6/nd6.h: revision 1.85
tests/net/arp/t_arp.sh: revision 1.23
sys/netinet6/in6.c: revision 1.246
tests/net/arp/t_arp.sh: revision 1.24
sys/netinet6/in6.c: revision 1.247
tests/net/arp/t_arp.sh: revision 1.25
sys/netinet6/in6.c: revision 1.248
tests/net/arp/t_arp.sh: revision 1.26
usr.sbin/ndp/ndp.c: revision 1.49
tests/net/arp/t_arp.sh: revision 1.27
tests/net/ndp/t_ndp.sh: revision 1.20
tests/net/arp/t_arp.sh: revision 1.28
tests/net/ndp/t_ndp.sh: revision 1.21
tests/net/arp/t_arp.sh: revision 1.29
tests/net/ndp/t_ndp.sh: revision 1.22
tests/net/ndp/t_ndp.sh: revision 1.23
tests/net/route/t_flags6.sh: revision 1.13
tests/net/ndp/t_ndp.sh: revision 1.24
tests/net/route/t_flags6.sh: revision 1.14
tests/net/ndp/t_ndp.sh: revision 1.25
tests/net/route/t_flags6.sh: revision 1.15
tests/net/ndp/t_ndp.sh: revision 1.26
sbin/route/rtutil.c: revision 1.9
tests/net/ndp/t_ndp.sh: revision 1.27
tests/net/ndp/t_ndp.sh: revision 1.28
tests/net/net/t_ipv6address.sh: revision 1.14
tests/net/ndp/t_ra.sh: revision 1.28
tests/net/ndp/t_ndp.sh: revision 1.29
sys/net/route.h: revision 1.113
tests/net/ndp/t_ra.sh: revision 1.29
sys/net/rtsock.c: revision 1.220
sys/net/rtsock.c: revision 1.221
sys/net/rtsock.c: revision 1.222
sys/net/rtsock.c: revision 1.223
tests/net/route/t_route.sh: revision 1.13
sys/net/rtsock.c: revision 1.224
sys/net/route.c: revision 1.196
sys/net/if_llatbl.c: revision 1.19
sys/net/route.c: revision 1.197
sbin/route/route.c: revision 1.156
tests/net/route/t_flags.sh: revision 1.16
tests/net/route/t_flags.sh: revision 1.17
usr.sbin/ndp/ndp.c: revision 1.50
tests/net/route/t_flags.sh: revision 1.18
sys/netinet/in.c: revision 1.204
tests/net/route/t_flags.sh: revision 1.19
sys/netinet/in.c: revision 1.205
tests/net/arp/t_arp.sh: revision 1.30
tests/net/arp/t_arp.sh: revision 1.31
sys/net/if_llatbl.h: revision 1.11
tests/net/arp/t_arp.sh: revision 1.32
sys/net/if_llatbl.h: revision 1.12
tests/net/arp/t_arp.sh: revision 1.33
sys/netinet6/nd6.c: revision 1.233
sys/netinet6/nd6.c: revision 1.234
sys/netinet/if_arp.c: revision 1.251
sys/netinet6/nd6.c: revision 1.235
sys/netinet/if_arp.c: revision 1.252
sbin/route/route.8: revision 1.57
sys/net/rtsock.c: revision 1.214
sys/net/rtsock.c: revision 1.215
sys/net/rtsock.c: revision 1.216
sys/net/rtsock.c: revision 1.217
whitespace police
Simplify
We can assume that rt_ifp is always non-NULL.
Sending a routing message (RTM_ADD) on adding an llentry
A message used to be sent on adding a cloned route. Restore the
behavior for backward compatibility.
Requested by ryo@
Drop RTF_CONNECTED from a result of RTM_GET for ARP/NDP entries
ARP/NDP entries aren't connected routes.
Reported by ryo@
Support -c <count> option for route monitor
route command exits if it receives <count> routing messages where
<count> is a value specified by -c.
The option is useful to get only particular message(s) in a test script.
Test routing messages emitted on operations of ARP/NDP entries
Do netstat -a for an appropriate protocol
Add missing declarations for cleanup
Set net.inet.arp.keep only if it's required
Don't create a permanent L2 cache entry on adding an address to an interface
It was created to copy FreeBSD, however actually the cache isn't
necessary. Remove it to simplify the code and reduce the cost to
maintain it (e.g., keep a consistency with a corresponding local
route).
Fix typo
Fix in_lltable_match_prefix
The function has not been used but will be used soon.
Remove unused function (nd6_rem_ifa_lle)
Allow in6_lltable_free_entry to be called without holding the afdata lock of ifp as well as in_lltable_free_entry
This behavior is a bit odd and should be fixed in the future...
Purge ARP/NDP entries on an interface when the interface is down
Fix PR kern/51179
Purge all related L2 caches on removing a route
The change addresses situations similar to PR 51179.
Purge L2 caches on changing an interface of a route
The change addresses situations similar to PR 51179.
Test implicit removals of ARP/NDP entries
One test case reproudces PR 51179.
Fix build of kernels without both INET and INET6
Tweak lltable_sysctl_dumparp
- Rename lltable_sysctl_dumparp to lltable_sysctl_dump
because it's not only for ARP
- Enable it not only for INET but also for INET6
Fix usage of routing messages on arp -d and ndp -d
It didn't work as we expected; we should set RTA_GATEWAY not
RTA_IFP on RTM_GET to return an if_index and the kernel should
use it on RTM_DELETE.
Improve backward compatibility of (fake) routing messages on adding an ARP/NDP entry
A message originally included only DST and GATEWAY. Restore it.
Fix ifdef; care about a case w/ INET6 and w/o INET
Drop RTF_UP from a routing message of a deleted ARP/NDP entry
Check existence of ARP/NDP entries
Checking ARP/NDP entries is valid rather than checking routes.
Fix wrong comment
Drop RTF_LLINFO flag (now it's RTF_LLDATA) from local routes
They don't have llinfo anymore. And also the change fixes unexpected
behavior of ARP proxy.
Restore ARP/NDP entries to route show and netstat -r
Requested by dyoung@ some time ago
Enable to remove multiple ARP/NDP entries for one destination
The kernel can have multiple ARP/NDP entries which have an indentical
destination on different interfaces. This is normal and can be
reproduce easily by ping -I or ping6 -S. We should be able to remove
such entries.
arp -d <ip> and ndp -d <ip> are changed to fetch all ARP/NDP entries
and remove matched entries. So we can remove multiple entries
described above. This fetch all and selective removal behavior is
the same as arp <ip> and ndp <ip>; they also do fetch all entries
and show only matched entries.
Related to PR 51179
Check if ARP/NDP entries are purged when a related route is deleted
 1.4 30-Jun-2019  sevan Add rcsid
 1.3 07-Jan-2015  christos branches: 1.3.2; 1.3.18;
make netname4 match the netname6 signature avoiding a NULL pointer.
 1.2 12-Nov-2014  christos PR/47704: Takahiro HAYASHI: Add -L flag
 1.1 06-Nov-2014  christos Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.3.18.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.3 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #395):
sbin/route/rtutil.c: revision 1.4
sbin/route/rtutil.h: revision 1.3
usr.bin/netstat/if.c: revision 1.81
make netname4 match the netname6 signature avoiding a NULL pointer.
adjust to the netname4 prototype.
 1.3.2.2 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.3.2.1 07-Jan-2015  martin file rtutil.h was added on branch netbsd-7 on 2015-01-08 11:01:01 +0000
 1.51 29-Aug-2020  christos Make the "interesting" flags match the netstat ones, so:

route show -inet
netstat -r -f inet

outputs match.
 1.50 04-Apr-2016  ozaki-r Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.49 23-Jan-2016  christos no need for <sys/mbuf.h>
 1.48 23-Mar-2015  roy Add RTF_BROADCAST to mark routes used for the broadcast address when
they are created on the fly. This makes it clear what the route is for
and allows an optimisation in ip_output() by avoiding a call to
in_broadcast() because most of the time we do talk to a host.
It also avoids a needless allocation for the storage of llinfo_arp and
thus vanishes from arp(8) - it showed as incomplete anyway so this
is a nice side effect.

Guard against this and routes marked with RTF_BLACKHOLE in
ip_fastforward().
While here, guard against routes marked with RTF_BLACKHOLE in
ip6_fastforward().
RTF_BROADCAST is IPv4 only, so don't bother checking that here.
 1.47 26-Feb-2015  roy Teach route(8) about RTF_LOCAL.
 1.46 06-Nov-2014  christos Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.45 01-Mar-2013  joerg branches: 1.45.8;
Retire OSI network stack. OK core@
 1.44 11-Nov-2011  gdt branches: 1.44.6;
Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.

RTF_ANNOUNCE was defined as RTF_PROTO2. The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
(Neither of these flags are used anywhere. Both have been removed
to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
 1.43 04-Feb-2011  martin branches: 1.43.4;
Use RT_ROUNDUP() and friends from sys/route.h instead of homegrown
variants.
 1.42 13-Dec-2010  pooka branches: 1.42.2;
Convert from RUMP_ACTION to RUMPPRG.
 1.41 26-Jun-2010  kefren add MPLS clue - mpls and tag keywords
 1.40 26-Jan-2010  is Add AF_APPLETALK support to getnameinfo(); make "route show" use it.
Doesn't print "ranges" yet (should it be done here?); only numeric
output.
 1.39 17-Mar-2009  lukem fix sign-compare issues
 1.38 10-Sep-2008  dyoung branches: 1.38.4;
Constify.
 1.37 09-Sep-2008  dyoung Use EXIT_FAILURE instead of anonymous constant '1'.
 1.36 09-Sep-2008  dyoung Use bool.
 1.35 16-Oct-2006  christos branches: 1.35.18; 1.35.22;
add missing initializer
 1.34 23-Sep-2006  pooka print the L flag for routes with llinfo. makes you not wonder why
non-llinfo routes are being printed for route show -llinfo
 1.33 23-Sep-2006  dyoung Let us qualify 'route flush' and 'route show' commands with -llinfo
and -host flags, which is useful for displaying/flushing ARP entries:

# route -n show -inet -llinfo -host
Routing table

Internet:
Destination Gateway Flags
169.254.1.119 link#1 UH
169.254.230.110 00:02:6f:21:e6:6e UH
# route -n flush -inet -llinfo -host
169.254.1.119 done
169.254.230.110 0.2.6f.21.e6.6e done
169.254.237.70 done
# route -n show -inet -llinfo -host
Routing table
#

This will help me address bin/11079, "dhclient may require arp and sed".

Extract common code from flushroutes() and show(), creating
parse_show_opts().

While I'm here, make small cosmetic changes to flushroutes().
 1.32 23-Sep-2006  dyoung Remove dead code.
 1.31 07-Sep-2006  dogcow remove more vestiges of CCITT, LLC, HDLC, NS, and NSIP.
 1.30 26-Aug-2006  matt Remove XNS and CCITT/X25 bits.
 1.29 25-Jan-2006  christos PR/32632: Yves-Emmanuel JUTARD: Improvment suggestion in 'route' display.
Add a new -S flag that prints a space for missing flags.
 1.28 31-Aug-2005  ginsbach Add full IPv6 syntax support when route is built with -DSMALL and -DINET6.
Fixes PR/23937. Adapted from supplied patch.
 1.27 30-Aug-2005  ginsbach Clean up some minor nits:
+ style (KNF).
. don't cast NULL
. white space clean up
+ use consistent format for error messages.
+ plug memory leaks and avoid malloc(0).
+ verbose message should display even when routing table is empty
(flushroutes).
 1.26 09-Aug-2005  ginsbach Accept protocol flags, i.e. -inet, -inet6, with the show command.
[From OpenBSD via DragonFly BSD]
 1.25 09-Aug-2005  ginsbach More style nits (KNF); casts and sizeof's are not followed by a space.
 1.24 26-Jun-2005  christos const poisoning.
 1.23 13-May-2005  ginsbach Adjust field width for route -n show similar to netstat -rn when displaying
INET6 route entries.
 1.22 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.21 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.20 17-May-2003  itojun strlcpy [a few mistakes found]
 1.19 24-Oct-2001  atatat Print a R on reject routes to indicate that they're not normal routes,
and check netmask (or prefix) length as well as the destination
address when determining if a route is a "default" or not. This means
that the output from 'route show' will no longer say:

Internet6:
Destination Gateway Flags
default localhost UG
default localhost UG

but instead

Internet6:
Destination Gateway Flags
::/104 localhost UGR
::/96 localhost UGR

which makes much more sense.
 1.18 06-Oct-2001  bjh21 When dumping the routing table, use getnameinfo() to print link-layer
addresses rather than doing it ourselves and falling back to link_ntoa().
 1.17 27-Jan-2001  itojun mark cloned routes with RTF_CLONED. present it with netstat -r by "c".

let static routes overwrite cloned routes, as cloned routes can come back again
if necessary. behavior same as freebsd/bsdi, code partially from bsdi42.
(NRL rt->rt_parent was not added)
should fix PR 11916 and maybe some other PRs with ARP behavior.

recompilation of usr.sbin/route6d is suggested.
 1.16 27-Jan-2001  itojun support RTF_BLACKHOLE.

XXX route show is total duplicate of netstat -r, we need to either remove
route show, or share the same source code, otherwise maintenance cost
bites (and is biting) us
 1.15 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.14 09-Nov-1999  drochner branches: 1.14.4;
Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
 1.13 03-Sep-1999  itojun branches: 1.13.4;
remove false fix for routing socket align issue.
 1.12 03-Sep-1999  itojun fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179
 1.11 17-Jul-1999  itojun tweak IPv6 case so that "route show" does not truncate numeric IPv6 address.

PR: 7955
 1.10 12-Jul-1999  itojun avoid using constants, use #define'd values.
 1.9 02-Jul-1999  itojun IPv6-ready route command (-inet6 and -prefixlen are added)
 1.8 23-Oct-1998  lukem branches: 1.8.2;
* implement -f; flush all routes before executing command
* reset af to 0 in flushroutes() and newroute()
* cleanup -DSMALL:
- `flush' and AF_APPLETALK is supported (the latter had partial support)
- AF_NS, AF_ISO, and AF_CCITT are not supported at all (rather than being
- partially unsupported).
 1.7 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.6 01-Dec-1997  kleink Recognize AF_APPLETALK as "AppleTalk".
 1.5 16-Nov-1997  christos Use {warn,err}{,x}(3) instead of printf's
 1.4 15-Sep-1997  lukem * cleanup for WARNS=1
* use .Nm correctly
* deprecate register
* getopt returns -1 not EOF
 1.3 21-Apr-1997  mrg be safe with buffers.
 1.2 03-Apr-1997  christos - Add netatalk bits
- Add prototypes
- Fix printf formats
 1.1 15-Nov-1996  gwr As discussed some time ago, add a "show" sub-command.
Also allow compilation with -DSMALL to ommit support for
non-essential protocols (i.e. when built into a ramdisk).
Use a less hack-ish way to generate keywords.[ch] and just
check in the result (helps ../../distrib/utils/x_route).
 1.8.2.1 10-Oct-2000  he Pull up revision 1.15 (requested by is):
Format string cleanup.
 1.13.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.14.4.3 05-Apr-2001  he Pull up revision 1.17 (requested by itojun):
Mark cloned routes with RTF_CLONED. Present it in ``netstat -r''
output by ``c''.
 1.14.4.2 05-Apr-2001  he Pull up revision 1.16 (requested by itojun):
Support RTF_BLACKHOLE routes.
 1.14.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.35.22.1 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.35.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.38.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.42.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.43.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.43.4.1 17-Apr-2012  yamt sync with head
 1.44.6.1 23-Jun-2013  tls resync from head
 1.45.8.1 08-Jan-2015  martin Pull up following revision(s) (requested by prlw1 in ticket #390):
usr.bin/netstat/mroute.c: revision 1.25
usr.bin/netstat/Makefile: revision 1.40
sbin/route/prog_ops.h: revision 1.3
sbin/route/rtutil.c: revision 1.1
sbin/route/rtutil.h: revision 1.1
usr.bin/netstat/mroute6.c: revision 1.15
sbin/route/extern.h: revision 1.15
usr.bin/netstat/show.c: file removal
usr.bin/netstat/main.c: revision 1.93
usr.bin/netstat/route.c: revision 1.83
usr.bin/netstat/netstat.h: revision 1.51
distrib/utils/x_route/Makefile: revision 1.18
sbin/route/show.c: revision 1.46
usr.bin/netstat/if.c: revision 1.80
sbin/route/route.c: revision 1.145
sbin/route/Makefile: revision 1.26
Factor out the netstat route printing code and use it here. There is no
point in having 2 different copies; fixes PR/49371
 1.27 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.26 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.25 25-Aug-2011  joerg branches: 1.25.42;
main.c uses non-literal format strings.
 1.24 14-Aug-2011  christos document non-literal strings
 1.23 28-May-2007  tls Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.22 06-Jun-1999  thorpej Use pidfile(3).
 1.21 23-Feb-1999  christos Oops remove WARNS=1
 1.20 23-Feb-1999  christos Resolve conflicts.
 1.19 26-Aug-1998  christos Avoid interraction between pppd and routed, by trying to discover new
interfaces every time there is a new route, irrespective of timeout period.
 1.18 11-Oct-1997  mycroft Use bsd.subdir.mk as appropriate.
 1.17 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.16 10-Aug-1996  thorpej Add a manual page link from routed(8) to rdisc(8) as suggested by
Giles Lean <giles@nemeton.com.au> on the tech-net@NetBSD.ORG mailing
list. The rationale for this is that folks may be used to rdisc(8)
or in.rdisc(8) on other systems, and may not realize that NetBSD
implements ICMP Router Discovery in the routed(8) program.
 1.15 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.14 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.13 31-May-1995  ragge Took away use of vax inline functions. Didn't work anyway.
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 22-Dec-1994  cgd specify man pages the new way.
 1.10 15-May-1994  cgd don't do query and trace
 1.9 13-May-1994  mycroft Clean up import.
 1.8 28-Jan-1994  cgd don't need -lutil
 1.7 30-Dec-1993  cgd Undo that last change. It was 100%, beyond a doubt, completely bogus.
afswitch and af_max were still used, but since they was declared 'common'
by virtue of their declaration in af.h, the symbols were defined at link-
time, and their contents were considered BSS -- init to zero.
Now, you and i know that jumping to zero causes a core dump...
Therefore: af.c has been resurrected, so the procedure pointers actually
point to procedures, tables.c has had it's change nuked, and af.h
has been changed so afswitch and af_max are declared as 'extern'.
It's obvious that that 'fix' wasn't even tested.
 1.6 18-Dec-1993  mycroft Move inet_default into tables.c, and remove all of af.c, as it is no longer
used.
 1.5 28-Oct-1993  cgd remove query and trace from subdir lists; they're for debugging only.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.6 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25.42.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.12 24-Jul-1995  ws RIP address families are still 2 bytes
 1.11 13-Jul-1995  cgd fix a stupid bug; wrong size was being used for sin_len.
 1.10 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.9 24-May-1995  mycroft Format police.
 1.8 24-May-1995  christos Fix bug in af_format where the formatted address was returned in the same
static buffer. When af_format is used more than once in the same printf
statement, the second call will overwrite the first. Changed af_format to
take a buffer and the buffer size where to place the formatted string.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.8 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 13-May-1994  mycroft Clean up import.
 1.5 30-Dec-1993  cgd Undo that last change. It was 100%, beyond a doubt, completely bogus.
afswitch and af_max were still used, but since they was declared 'common'
by virtue of their declaration in af.h, the symbols were defined at link-
time, and their contents were considered BSS -- init to zero.
Now, you and i know that jumping to zero causes a core dump...
Therefore: af.c has been resurrected, so the procedure pointers actually
point to procedures, tables.c has had it's change nuked, and af.h
has been changed so afswitch and af_max are declared as 'extern'.
It's obvious that that 'fix' wasn't even tested.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.28 02-Oct-2017  maya unifdef sgi. NFCI
 1.27 12-Feb-2012  wiz Remove duplicate RS_LOCAL. From cppcheck via Henning Petersen in PR 46000.
 1.26 29-Aug-2011  joerg branches: 1.26.2;
Use __dead
 1.25 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.24 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.23 21-Apr-2004  christos constification lossage (hi gimpy)
 1.22 30-Nov-2002  christos sync with routed 2.27
 1.21 02-Nov-2001  lukem fix -Wshadow warnings
 1.20 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.19 15-Jan-2001  itojun specify interface by using interface index (set/getsockopt with 0.0.0.0/8).
 1.18 23-Feb-1999  christos Resolve conflicts.
 1.17 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.16 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.15 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.14 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.13 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.12 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.11 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.10 21-Mar-1995  mycroft Update to use timer{add,sub}().
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.7 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.6 13-May-1994  mycroft Clean up import.
 1.5 13-Apr-1994  cgd light comment change
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.26.2.1 17-Apr-2012  yamt sync with head
 1.31 02-Oct-2017  maya unifdef sgi. NFCI
 1.30 24-Jun-2012  kardel PR/44647: commit fix proposed by Takahiro HAYASHI
verified to be working in -current and also helps NetBSD-6 BETA2
 1.29 13-Oct-2010  martin branches: 1.29.6; 1.29.8;
Memcpy into local variable to ensure proper alignement.
Fixes PR port-sparc64/43965.
 1.28 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.27 28-Dec-2008  christos fix printf formats.
 1.26 14-Aug-2007  dyoung branches: 1.26.10; 1.26.16; 1.26.20;
Don't nul-terminate the interface name in a sockaddr_dl that is
part of an ifa_msghdr returned by sysctl(3), because that could
overwrite the ifam_len field of the following ifa_msgher. Instead,
copy the interface name out of the sockaddr_dl, and then nul-terminate.
Fixes the bug reported by Frank Kardel on current-users@. Thanks
Frank for reporting, and for testing the fix.
 1.25 17-Mar-2006  christos Coverity CID 2671: Fix use of ifp after free.
 1.24 30-Nov-2002  christos sync with routed 2.27
 1.23 02-Nov-2001  lukem fix -Wshadow warnings
 1.22 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.21 15-Jan-2001  itojun specify interface by using interface index (set/getsockopt with 0.0.0.0/8).
 1.20 11-Jun-2000  christos Revert 1.18 -> 1.19; causes infinite loops on machines that use ppp and
do active routing.
 1.19 02-Mar-2000  christos branches: 1.19.2;
remove the once hack; vjs says it is not necessary with the monotonic
time kludge. We'll see.
 1.18 19-Nov-1999  bouyer Ignore RTM_OIFINFO messages (send by a COMPAT_14 kernel).
 1.17 23-Feb-1999  christos branches: 1.17.6;
Resolve conflicts.
 1.16 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.15 26-Aug-1998  christos Avoid interraction between pppd and routed, by trying to discover new
interfaces every time there is a new route, irrespective of timeout period.
 1.14 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.13 15-Sep-1997  lukem use memmove, memcmp, memset instead of bcopy, bcmp, bzero
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.11 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.10 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.9 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.8 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.17.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.26.20.1 16-Aug-2010  matt Change to new route message sematics
 1.26.16.1 21-Nov-2010  riz Pull up following revision(s) (requested by martin in ticket #1460):
sbin/routed/if.c: revision 1.29
Memcpy into local variable to ensure proper alignement.
Fixes PR port-sparc64/43965.
 1.26.10.1 17-Jan-2009  mjf Sync with HEAD.
 1.29.8.1 02-Jul-2012  jdc Pull up revision 1.30 (requested by kardel in ticket #376).

PR/44647: commit fix proposed by Takahiro HAYASHI
verified to be working in -current and also helps NetBSD-6 BETA2
 1.29.6.1 30-Oct-2012  yamt sync with head
 1.10 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.9 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.6 06-Aug-1994  mycroft Fix `maskof' function which was returning `netof', per Brad Parker.
 1.5 13-May-1994  mycroft branches: 1.5.2;
Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 06-Aug-1994  mycroft update from trunk
 1.31 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.30 09-May-2006  mrg change (mostly) int to socklen_t. GCC 4 doesn't like that int and
socklen_t are different signness.
 1.29 01-Dec-2002  agc Fix compilation problems on non-i386.
 1.28 30-Nov-2002  christos sync with routed 2.27
 1.27 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.26 02-Mar-2000  christos add a comment on about how tracing is secured, but still keep it disabled.
 1.25 23-Feb-1999  christos Resolve conflicts.
 1.24 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.23 24-Oct-1998  christos Disable and log RIP_TRACEON and RIP_TRACEOFF. They are insecure.
 1.22 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.21 15-Sep-1997  lukem branches: 1.21.2;
use memmove, memcmp, memset instead of bcopy, bcmp, bzero
 1.20 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.19 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.18 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.17 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.16 13-Jul-1995  christos Fix bugs cgd pointed out.
 1.15 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.14 28-May-1995  jtc <sys/errno.h> -> <errno.h>
<sys/signal.h> -> <signal.h>
<sys/syslog.h> -> <syslog.h>
 1.13 24-May-1995  mycroft s/an active/a passive/
 1.12 24-May-1995  christos Fix bug in af_format where the formatted address was returned in the same
static buffer. When af_format is used more than once in the same printf
statement, the second call will overwrite the first. Changed af_format to
take a buffer and the buffer size where to place the formatted string.
 1.11 24-Apr-1995  cgd fix arguments to tracing functions and/or cast, to avoid warnings.
 1.10 21-Mar-1995  mycroft Update to use timer{add,sub}().
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.7 23-Sep-1994  mycroft Remove some more uses of obsolete functions.
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.21.2.1 25-Oct-1998  cgd pull up rev 1.23 from trunk (christos)
 1.9 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.8 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 13-May-1994  mycroft Clean up import.
 1.5 11-Dec-1993  cgd fix from Brad Parker <brad@fcr.com> to curb routed inflation when
using MULTICAST. it wasn't properly ignoring the new interface flags.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.43 07-Apr-2022  andvar fix various typos in comments.
 1.42 02-Oct-2017  maya unifdef sgi. NFCI
 1.41 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.40 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.39 06-Jul-2004  wiz branches: 1.39.26; 1.39.30;
usage: -F was missing the /mask part. Based on PR 26063
by Kouichirou Hiratsuka.
 1.38 17-May-2004  wiz Remove unimplemented and undescribed -p option from usage and man page
SYNOPSIS. Noted by Jeff Ito.
 1.37 13-May-2004  wiz Remove option letter from getopt string, since it does not
have a case handler below. From aaron@openbsd.
 1.36 27-Mar-2004  christos From Vernon Schryver:

Wolfgang Solfrank has explained the problem with router discovery
in `routed` in a way I can understand.

Let's assume that the configured preference of the interface is 5.
This gets converted to 0x80000005 through the use of the UNSIGN_PREF
macro. Later on, this value gets put into the PREF macro, which
compares it against the interface metric(s) (let's assume those
values to be 0 for now). Of course the 0x80000005, cast to int,
is much less than 0, so the clamping rule is triggered, which
gives us a value of 1. This is then converted via SIGN_PREF into
0x80000001 and put into the message. Certainly, this isn't what
was intended.
 1.35 14-Nov-2003  enami Initialize an uninitialized variable.
 1.34 06-Sep-2003  itojun use arc4random
 1.33 13-Aug-2003  itojun avoid FD_SET overrun. from openbsd
 1.32 21-Apr-2003  itojun strcpy/sprintf cleanup. from openbsd
 1.31 30-Nov-2002  christos sync with routed 2.27
 1.30 02-Nov-2001  lukem branches: 1.30.2;
fix -Wshadow warnings
 1.29 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.28 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.27 15-Jan-2001  itojun specify interface by using interface index (set/getsockopt with 0.0.0.0/8).
 1.26 10-Jan-2001  lukem deprecate LOG_ODELAY; it's the default
 1.25 10-Oct-2000  is Format string cleanups by Bill Sommerfeld.
 1.24 02-Mar-2000  christos branches: 1.24.4;
add a usec_fudge to make sure that time increases monotonically.
printf format changes.
 1.23 06-Jun-1999  thorpej Use pidfile(3).
 1.22 25-Feb-1999  ross branches: 1.22.2;
LP64 tweak in printf(3) instance
 1.21 23-Feb-1999  christos Resolve conflicts.
 1.20 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.19 06-Jul-1998  mrg - use an array MAXHOSTNAMELEN+1 size to hold hostnames
- ensure hostname from gethostname() is nul-terminated in all cases
- minor KNF
- use MAXHOSTNAMELEN over various other values/defines
- be safe will buffers that hold hostnames
 1.18 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.17 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.16 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.15 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.14 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.13 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.12 28-May-1995  jtc <sys/errno.h> -> <errno.h>
<sys/signal.h> -> <signal.h>
<sys/syslog.h> -> <syslog.h>
 1.11 23-Mar-1995  mycroft Fix typo in previous.
 1.10 21-Mar-1995  mycroft Use POSIX signals.
 1.9 21-Mar-1995  mycroft Fix typo.
 1.8 21-Mar-1995  mycroft Update to use timer{add,sub}().
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.22.2.1 10-Oct-2000  he Pull up revision 1.25 (requested by is):
Format string cleanup.
 1.24.4.2 07-Apr-2004  jmc Pullup patch (requested by ws in ticket #131)

Fix invalid cast wrt router discovery.
 1.24.4.1 18-Oct-2000  tv Pullup sbin string format fixes [is].
See "cvs log" for explicit revision numbers per file, from sommerfeld.
 1.30.2.1 01-Apr-2004  jmc Pullup patch (requested by ws in ticket #1642)

Fix invalid cast wrt router discovery.
 1.39.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.39.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.2 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.1 03-Feb-1997  christos branches: 1.1.1;
Initial revision
 1.1.1.1 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.25 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.24 21-Mar-2006  christos Coverity CID 2742: Avoid NULL deref.
 1.23 18-Mar-2006  christos Coverity CID 1079: Possible NULL deref.
 1.22 30-Nov-2002  christos sync with routed 2.27
 1.21 02-Nov-2001  lukem fix -Wshadow warnings
 1.20 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.19 15-Jan-2001  itojun specify interface by using interface index (set/getsockopt with 0.0.0.0/8).
 1.18 20-Jul-2000  thorpej In walk_supply(), test for IS_PASSIVE in ifp->int_state, not
ifp->int_if_flags (IFF_* bits).
 1.17 23-Feb-1999  christos branches: 1.17.10;
Resolve conflicts.
 1.16 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.15 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.14 15-Sep-1997  lukem use memmove, memcmp, memset instead of bcopy, bcmp, bzero
 1.13 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.12 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.11 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.10 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.9 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.17.10.1 20-Jul-2000  thorpej Pull up rev. 1.18:
In walk_supply(), test for IS_PASSIVE in ifp->int_state, not
ifp->int_if_flags (IFF_* bits).
 1.26 16-Jan-2012  christos PR/45842: Henning Petersen: compare fgets with NULL not 0
 1.25 24-May-2011  joerg branches: 1.25.4;
Use bitwise operators, logical and with a constant doesn't make sense
 1.24 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.23 18-Mar-2006  christos Coverity CID 2307: Possible memory leak.
 1.22 18-Mar-2006  christos Coverity CID 2306: Possible memory leak.
 1.21 18-Mar-2006  christos Coverity CID 1080: Possible NULL deref.
 1.20 03-Jul-2003  itojun strcat -> strlcat
 1.19 21-Apr-2003  itojun strcpy/sprintf cleanup. from openbsd
 1.18 15-Apr-2003  itojun use snprintf. there are more...
 1.17 30-Nov-2002  christos sync with routed 2.27
 1.16 08-Aug-2002  itojun bitmask operation mistake audit (s/&&/&/). from openbsd
 1.15 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.14 21-Jul-2000  thorpej Make sure IS_PASSIVE gets set on a parm's int_state when the
passive option is used in an if=xxx clause.
 1.13 23-Feb-1999  christos branches: 1.13.10;
Resolve conflicts.
 1.12 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.11 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.10 30-Mar-1998  mrg use static int, not just static
 1.9 04-Feb-1998  christos y2k fixes: use strptime...
 1.8 19-Sep-1997  christos Fix uninitialized variable warning.
 1.7 15-Sep-1997  lukem use memmove, memcmp, memset instead of bcopy, bcmp, bzero
 1.6 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.5 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.4 29-Jan-1997  ws Shifting by 32 on a 32-bit machine is undefined
(and in fact -1 << 32 results in -1 on e.g. x86)
 1.3 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.5 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.4 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.13.10.1 21-Jul-2000  thorpej Pull up rev. 1.14:
Make sure IS_PASSIVE gets set on a parm's int_state when the
passive option is used in an if=xxx clause.
 1.25.4.1 17-Apr-2012  yamt sync with head
 1.11 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.10 23-Feb-1999  christos Resolve conflicts.
 1.9 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.8 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.7 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.5 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14 05-Dec-2021  msaitoh s/prefering/preferring/ in comment.
 1.13 25-Feb-2006  wiz Fix typos, reported by Alexey Dobriyan ("Gathered from Linux"),
forwarded by jmc@openbsd.
 1.12 06-Dec-2002  thorpej Avoid strict alias warnings.
 1.11 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.10 02-Mar-2000  christos add an unsigned cast; looks safe and innocent, but it might not be...
 1.9 22-Mar-1999  christos Revert cast to (int) that caused core-dumps.
 1.8 23-Feb-1999  christos Resolve conflicts.
 1.7 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.6 16-Sep-1997  lukem If One splits a line for cosmetic reasons, One should ensure that the
preceeding line has a \ if it's part of a #define...
 1.5 15-Sep-1997  lukem use memmove, memcmp, memset instead of bcopy, bcmp, bzero
 1.4 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.3 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.3 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.7 27-Feb-2025  rillig routed: remove extra semicolon at the end of a function-like macro

No binary change.
 1.6 05-Feb-2005  xtraeme branches: 1.6.104;
Kill __P().
 1.5 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.4 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.3 16-Oct-1996  perry RCSid Police
 1.2 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.1 24-Sep-1996  christos branches: 1.1.1;
Initial revision
 1.1.1.2 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.1 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.6.104.1 02-Aug-2025  perseant Sync with HEAD
 1.17 09-May-2006  mrg change (mostly) int to socklen_t. GCC 4 doesn't like that int and
socklen_t are different signness.
 1.16 18-Mar-2006  christos Coverity CID 2432: Dereference before NULL check.
 1.15 27-Mar-2004  christos From Vernon Schryver:

Wolfgang Solfrank has explained the problem with router discovery
in `routed` in a way I can understand.

Let's assume that the configured preference of the interface is 5.
This gets converted to 0x80000005 through the use of the UNSIGN_PREF
macro. Later on, this value gets put into the PREF macro, which
compares it against the interface metric(s) (let's assume those
values to be 0 for now). Of course the 0x80000005, cast to int,
is much less than 0, so the clamping rule is triggered, which
gives us a value of 1. This is then converted via SIGN_PREF into
0x80000001 and put into the message. Certainly, this isn't what
was intended.
 1.14 30-Nov-2002  christos sync with routed 2.27
 1.13 02-Nov-2001  lukem branches: 1.13.2;
fix -Wshadow warnings
 1.12 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.11 15-Jan-2001  itojun specify interface by using interface index (set/getsockopt with 0.0.0.0/8).
 1.10 02-Mar-2000  christos branches: 1.10.4;
protability cast.
 1.9 23-Feb-1999  christos Resolve conflicts.
 1.8 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.7 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.6 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.5 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.4 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.3 10-Aug-1996  mycroft Make sure to fill in the whole sockaddr_in when sending a discovery packet.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.5 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.4 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.10.4.1 07-Apr-2004  jmc Pullup patch (requested by ws in ticket #131)

Fix invalid cast wrt router discovery.
 1.13.2.1 01-Apr-2004  jmc Pullup patch (requested by ws in ticket #1642)

Fix invalid cast wrt router discovery.
 1.45 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.44 17-May-2004  wiz Remove unimplemented and undescribed -p option from usage and man page
SYNOPSIS. Noted by Jeff Ito.
 1.43 27-Mar-2004  christos From Vernon Schryver:

Wolfgang Solfrank has explained the problem with router discovery
in `routed` in a way I can understand.

Let's assume that the configured preference of the interface is 5.
This gets converted to 0x80000005 through the use of the UNSIGN_PREF
macro. Later on, this value gets put into the PREF macro, which
compares it against the interface metric(s) (let's assume those
values to be 0 for now). Of course the 0x80000005, cast to int,
is much less than 0, so the clamping rule is triggered, which
gives us a value of 1. This is then converted via SIGN_PREF into
0x80000001 and put into the message. Certainly, this isn't what
was intended.
 1.42 07-Sep-2003  wiz Consistently use 'RFC 1234' instead of 'RFC1234' or 'RFC-1234'.
From jmc@openbsd.
 1.41 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.40 18-Dec-2002  wiz Sort sections, new sentences begin on new lines, add a missing line,
fix a typo.
 1.39 30-Nov-2002  christos sync with routed 2.27
 1.38 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.37 12-May-2002  wiz branches: 1.37.2;
Spelling fixes, from Sergey Svishchev in kern/16650.
 1.36 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.35 21-Jan-2002  wiz Use mdoc macros instead of man ones.
 1.34 16-Nov-2001  wiz Punctuation fix, sort sections, lose a .Pp.
 1.33 01-Oct-2001  kleink "kernel switch ipforwarding" -> "sysctl net.inet.ip.forwarding".
 1.32 05-Jun-2001  wiz Drop arguments of .Os.
 1.31 06-May-2001  wiz Improve usage of `comprise' according to Webster and misc/10893
by Jim Bernard.
 1.30 03-Apr-2001  wiz Don't xref gated(8) and htable(8), which we don't have.
 1.29 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.28 07-Nov-2000  lukem fix up various .Nm abuses:
- keep the case consistent between the actual name and what's referenced.
e.g, if it's `foo', don't use '.Nm Foo' at the start of a sentence.
- remove unnecessary `.Nm foo' after the first occurrence (except for
using `.Nm ""' if there's stuff following, or for the 2nd and so on
occurrences in a SYNOPSIS
- use Sx, Ic, Li, Em, Sq, and Xr as appropriate
 1.27 05-Oct-2000  ad insure -> ensure
 1.26 05-Jul-2000  msaitoh remove extra period in SEE ALL section
 1.25 02-Mar-2000  christos branches: 1.25.4;
typos and clarifications
 1.24 23-Feb-1999  christos Resolve conflicts.
 1.23 13-Nov-1998  abs Fix typo 'with routing loop' to 'with a routing loop'
 1.22 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.21 21-Oct-1998  lukem spell daemon correctly in the opening paragraph...
 1.20 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.19 29-Apr-1998  fair fix bad .Xr references
 1.18 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.17 11-Nov-1997  mrg add missing .Nm sections.
 1.16 15-Sep-1997  lukem branches: 1.16.2;
* cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.15 26-Jun-1997  kleink Fix formatting directives; from SAITOH Masanobu <msaitoh@spa.is.uec.ac.jp>
in PR misc/3795.
 1.14 25-Mar-1997  perry fix 3128 from SAITOH Masanobu.
this consisted of nuking a duplicated paragraph; I did it slightly
differently than suggested.
 1.13 08-Mar-1997  mouse alternate -> alternative, per PR 2643
 1.12 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.11 27-Jan-1997  perry fix some nits from SAITOH Masanobu, pr-3149
 1.10 23-Jan-1997  mikel eliminate duplicate paragraph and fix typos; PR misc/3128
 1.9 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.8 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.7 06-Feb-1996  scottr Grammar police, noted by Peter Seebach <seebs@solon.com>; closes PR #1704.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.2.1 11-Nov-1997  mrg pull up from trunk: add missing .Nm sections.
 1.25.4.2 07-Apr-2004  jmc Pullup patch (requested by ws in ticket #132)

Update manual page to describe default route preferences better
 1.25.4.1 04-Apr-2001  he Pull up revision 1.30 (via patch, requested by wiz):
Don't xref gated(8) and htable(8), which we don't have.
 1.37.2.1 01-Apr-2004  jmc Pullup patch (requested by ws in ticket #1643)

Fix inconsistency between manual page and RFC 1256.
 1.5 20-Oct-1996  thorpej Remove the redundant copy of this file.
Suggested by David Carrel <carrel@ipsec.com>, PR #2872.
 1.4 24-Sep-1996  christos explicitly enumerate the ripv1 fields.
 1.3 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.4 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.15 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.14 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.13 21-May-1995  mycroft Use inet_aton(), not inet_addr().
 1.12 24-Apr-1995  cgd fix arguments to tracing functions and/or cast, to avoid warnings.
 1.11 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.10 23-Dec-1994  cgd kill some redundant includes.
 1.9 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.8 31-Oct-1994  cgd pull in helpful includes.
 1.7 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.6 13-May-1994  mycroft Clean up import.
 1.5 11-Dec-1993  cgd fix from Brad Parker <brad@fcr.com> to curb routed inflation when
using MULTICAST. it wasn't properly ignoring the new interface flags.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.28 06-Feb-2018  mrg update for GCC 6:

- read_rt() has a missing {} issue.
 1.27 20-Dec-2016  ozaki-r Fix that routed deletes local routes

routed previousely ignored local routes, which have RTF_LOCAL flag, because
such routes have RTF_LLINFO and routed ignored routes having the flag. When
we obsoleted RTF_LLINFO, we removed the ignoring logic from routed, then
routed started removing local routes unexpectedly.

Fix this behavior by teaching local routes to routed to ignore them.

kardel@ reported the issue and helped testing, thanks!
 1.26 07-Oct-2016  joerg Shuffle pointer magic to not depend on temporary overaligned pointers
into a packed structure.
 1.25 04-Apr-2016  ozaki-r branches: 1.25.2;
Separate nexthop caches from the routing table

By this change, nexthop caches (IP-MAC address pair) are not stored
in the routing table anymore. Instead nexthop caches are stored in
each network interface; we already have lltable/llentry data structure
for this purpose. This change also obsoletes the concept of cloning/cloned
routes. Cloned routes no longer exist while cloning routes still exist
with renamed to connected routes.

Noticeable changes are:
- Nexthop caches aren't listed in route show/netstat -r
- sysctl(NET_RT_DUMP) doesn't return them
- If RTF_LLDATA is specified, it returns nexthop caches
- Several definitions of routing flags and messages are removed
- RTF_CLONING, RTF_XRESOLVE, RTF_LLINFO, RTF_CLONED and RTM_RESOLVE
- RTF_CONNECTED is added
- It has the same value of RTF_CLONING for backward compatibility
- route's -xresolve, -[no]cloned and -llinfo options are removed
- -[no]cloning remains because it seems there are users
- -[no]connected is introduced and recommended
to be used instead of -[no]cloning
- route show/netstat -r drops some flags
- 'L' and 'c' are not seen anymore
- 'C' now indicates a connected route
- Gateway value of a route of an interface address is now not
a L2 address but "link#N" like a connected (cloning) route
- Proxy ARP: "arp -s ... pub" doesn't create a route

You can know details of behavior changes by seeing diffs under tests/.

Proposed on tech-net and tech-kern:
http://mail-index.netbsd.org/tech-net/2016/03/11/msg005701.html
 1.24 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.23 28-Dec-2008  christos fix printf formats.
 1.22 06-Jul-2004  mycroft branches: 1.22.26; 1.22.38;
PR 9431: if rnh_addradd() fails, total_routes will be wrong.
 1.21 21-Apr-2004  christos constification lossage (hi gimpy)
 1.20 21-Apr-2003  itojun branches: 1.20.2;
strcpy/sprintf cleanup. from openbsd
 1.19 15-Apr-2003  itojun use snprintf. there are more...
 1.18 15-Apr-2003  itojun array seems too small
 1.17 06-Dec-2002  thorpej Avoid strict alias warnings.
 1.16 30-Nov-2002  christos sync with routed 2.27
 1.15 02-Nov-2001  lukem fix -Wshadow warnings
 1.14 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.13 02-Mar-2000  christos make local functions static and portability casts.
 1.12 11-Feb-2000  christos PR/9390: Jarkko Torppa: Routed leaks memory when route addition fails.
 1.11 19-Nov-1999  bouyer Ignore RTM_OIFINFO messages (send by a COMPAT_14 kernel).
 1.10 25-Feb-1999  ross branches: 1.10.6;
LP64 tweaks.
 1.9 23-Feb-1999  christos Resolve conflicts.
 1.8 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.7 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.6 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.5 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.4 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.3 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.5 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.4 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.10.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.20.2.1 10-Jul-2004  tron Pull up revision 1.22 (requested by mycroft in ticket #615):
PR 9431: if rnh_addradd() fails, total_routes will be wrong.
 1.22.38.1 16-Aug-2010  matt Change to new route message sematics
 1.22.26.1 17-Jan-2009  mjf Sync with HEAD.
 1.25.2.2 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.25.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.8 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.7 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.15 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.14 28-May-1995  jtc <sys/errno.h> -> <errno.h>
<sys/signal.h> -> <signal.h>
<sys/syslog.h> -> <syslog.h>
 1.13 24-May-1995  christos Fix bug in af_format where the formatted address was returned in the same
static buffer. When af_format is used more than once in the same printf
statement, the second call will overwrite the first. Changed af_format to
take a buffer and the buffer size where to place the formatted string.
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 23-Dec-1994  cgd kill some redundant includes.
 1.10 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.9 31-Oct-1994  cgd pull in helpful includes.
 1.8 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.7 13-May-1994  mycroft Clean up import.
 1.6 30-Dec-1993  cgd Undo that last change. It was 100%, beyond a doubt, completely bogus.
afswitch and af_max were still used, but since they was declared 'common'
by virtue of their declaration in af.h, the symbols were defined at link-
time, and their contents were considered BSS -- init to zero.
Now, you and i know that jumping to zero causes a core dump...
Therefore: af.c has been resurrected, so the procedure pointers actually
point to procedures, tables.c has had it's change nuked, and af.h
has been changed so afswitch and af_max are declared as 'extern'.
It's obvious that that 'fix' wasn't even tested.
 1.5 18-Dec-1993  mycroft Move inet_default into tables.c, and remove all of af.c, as it is no longer
used.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.8 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.33 02-Oct-2017  maya unifdef sgi. NFCI
 1.32 06-Apr-2009  lukem fix sign-compare issue
 1.31 22-Mar-2006  christos branches: 1.31.30;
Coverity CID 1301: Return early if we could not open /dev/null
 1.30 21-Apr-2004  christos constification lossage (hi gimpy)
 1.29 12-Jul-2003  itojun sprintf can return negative
 1.28 21-Apr-2003  itojun strcpy/sprintf cleanup. from openbsd
 1.27 30-Nov-2002  christos sync with routed 2.27
 1.26 24-Sep-2001  wiz va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
 1.25 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.24 02-Mar-2000  christos portability casts and re-indentation of some code.
 1.23 23-Feb-1999  christos Resolve conflicts.
 1.22 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.21 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.20 19-Oct-1997  mycroft Use S_IS*(), not S_IF*.
 1.19 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.18 15-Sep-1997  lukem use memmove, memcmp, memset instead of bcopy, bcmp, bzero
 1.17 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.16 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.15 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.14 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.13 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.12 28-May-1995  jtc <sys/errno.h> -> <errno.h>
<sys/signal.h> -> <signal.h>
<sys/syslog.h> -> <syslog.h>
 1.11 24-Apr-1995  cgd fix arguments to tracing functions and/or cast, to avoid warnings.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 30-Jan-1995  mycroft Use S_IS*().
 1.8 23-Dec-1994  cgd kill some redundant includes.
 1.7 18-Dec-1994  cgd some -Wall changes, from Jim Jegers, improved (in some cases) by me.
still needs a bit of work, but closer.
 1.6 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.7 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.6 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.5 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.4 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.3 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.31.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.9 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.8 20-Jun-1995  christos - Support rip version 2.
- Add ansi prototypes.
- Be less internet centric.
- Convert queues to use <sys/queue.h> so we don't need -lcompat
 1.7 24-Apr-1995  cgd fix arguments to tracing functions and/or cast, to avoid warnings.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 13-May-1994  mycroft Clean up import.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 14-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8 26-May-2011  joerg Default to -Wno-sign-compare -Wno-pointer-sign for clang.
Push -Wno-array-bounds down to the cases that depend on it.
Selectively disable warnings for 3rd party software or non-trivial
issues to be reviewed later to get clang -Werror to build most of the
tree.
 1.7 23-Apr-2002  msaitoh don't override LDSTATIC if NOPIC is defined.
 1.6 02-Mar-1998  cgd allow LDSTATIC definition to be overridden by bsd.own.mk/mk.conf
 1.5 10-Oct-1997  mikel link rtquery against dynamic libs; from Soren S. Jorvang in PR bin/4178
 1.4 20-Jun-1997  pk Install `rtquery' in /usr/sbin.
 1.3 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.4 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.2 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.1 03-Feb-1997  christos branches: 1.1.1;
Initial revision
 1.1.1.1 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.20 11-Sep-2009  wiz Add xref to pkgsrc/net/gated, so people know where to find gated(8).
Improve markup of RFCs in SEE ALSO.
Sort options.
Bump date.
 1.19 23-Sep-2003  wiz Correct error in previous, noted by Nick Hudson.
 1.18 07-Sep-2003  wiz Consistently use 'RFC 1234' instead of 'RFC1234' or 'RFC-1234'.
From jmc@openbsd.
 1.17 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.16 16-Nov-2001  wiz Sort SEE ALSO.
 1.15 05-Jun-2001  wiz Drop argument of .Os.
 1.14 23-Feb-1999  christos Resolve conflicts.
 1.13 22-Nov-1998  msaitoh s/ and and / and /
 1.12 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.11 18-Aug-1998  msaitoh fix a roff command bug
 1.10 29-Apr-1998  fair fix bad .Xr references
 1.9 11-Oct-1997  enami - Use .Nm "" instead of .Nm rtquery in SYNOPSIS.
- Don't use captialized wort to refer command name.
- Delete period at the end of ``SEE ALSO'' list.
- Use .Xr instead of .Em to refer routed.
 1.8 10-Oct-1997  lukem all but the first .Nm in SYNOPSIS need to be spelt out. [bin/4256]
 1.7 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.6 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.5 27-Jan-1997  perry fix some nits from SAITOH Masanobu, pr-3149
 1.4 17-Jan-1997  perry fix .I which should be .Em, from SAITOH Masanobu in pr-3109
 1.3 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.4 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.25 23-Mar-2014  dholland don't use sprintf
 1.24 19-Oct-2013  christos gcc warns about array bounds limits, but unfortunately the API here requires
flex arrays in a union which is not allowed. So do a trivial pointer assignment
to baffle gcc again.
 1.23 29-Aug-2011  joerg branches: 1.23.2; 1.23.8;
Use __dead
 1.22 26-Oct-2009  christos merge 2.32 which is actually 2.31. Most important change is:
- use multicast over point-to-point (GRE) links as proposed by Dan Lukes.
 1.21 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.20 15-Dec-2007  perry branches: 1.20.4; 1.20.8;
convert __attribute__s to applicable cdefs.h macros
 1.19 16-Sep-2007  ragge branches: 1.19.2;
__attribute -> __attribute__.
 1.18 10-May-2006  mrg branches: 1.18.10;
quell GCC 4.1 uninitialised variable warnings.

XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
 1.17 09-May-2006  mrg change (mostly) int to socklen_t. GCC 4 doesn't like that int and
socklen_t are different signness.
 1.16 30-Nov-2002  christos sync with routed 2.27
 1.15 06-Apr-2001  wiz Negative exit code cleanup: Replace exit(-x) with exit(x).
As seen on tech-userlevel.
 1.14 10-Mar-2001  christos sync with version 2.24. Vernon says:
The most significant [fix] involves so called "remote" interfaces
configured in the kludge file to with what appear to be colliding
networks. Edward Mascarenhas <eddiem@vihar.engr.sgi.com> found
the problem and the fix, and I think has tested it in the SGI
network.
 1.13 27-Jul-2000  thorpej Pull in <md5.h> rather than defining our own MD5 structures (!).
 1.12 02-Mar-2000  christos portability casts
 1.11 19-Aug-1999  christos negative ip octets don't make sense. Now we print byte swapped but the
addresses are at least recognizable without negating :-)
 1.10 23-Feb-1999  christos Resolve conflicts.
 1.9 25-Oct-1998  christos Update to 980910 from ftp.rhyolite.com
 1.8 02-Jun-1998  thorpej Merge the 980602 RIPv2/Router Discovery routed. Fixes floods of host routes
generated when one of the interfaces on the network does not support
broadcast (e.g. HIPPI or ATM).

From Vern Schryver <vjs@rhyolite.com>
 1.7 02-Jun-1998  kleink Remove the unrecognized `-v' option from the usage information;
from Geoff C. Wing in PR bin/5521.
 1.6 30-Mar-1998  mrg add noreturn attribute, and fix the return value of main.
 1.5 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* bcmp, bcopy, bzero, rindex -> memcmp, memmove, memset, strrchr
* correct use of .Nm
 1.4 03-Feb-1997  christos - resolve conflicts.
- remove md5 stuff; it is in libc.
- define MCAST_PPP_BUG, until we fix if_ppp.c
 1.3 24-Sep-1996  christos - resolve conflicts
- try to follow rcsid style more closely
- fix rn_walktree callback routine signatures.
 1.2 10-Aug-1996  thorpej - Finished up merge.

- Add some prototypes and definitions for types as necessary,
wrapped in __NetBSD__ to maintain portability.

- Explicit size types in structures that go out the wire.

- RCS id police.
 1.1 10-Aug-1996  thorpej branches: 1.1.1;
Initial revision
 1.1.1.5 23-Feb-1999  christos Latest version of routed(8) from Vernon Schryver <vjs@calcite.rhyolite.com>
 1.1.1.4 02-Jun-1998  thorpej Latest RIPv2/Router Discovery routed, from Vern Schryver <vjs@rhyolite.com>
 1.1.1.3 03-Feb-1997  christos New version from ftp.sgi.com:sgi/src/routed.tar.Z
 1.1.1.2 24-Sep-1996  christos Latest version of routed(8) from Vernon Schryver <vjs@sgi.com>
 1.1.1.1 10-Aug-1996  thorpej A leaner, meaner routed(8), implementing RIPv1, RIPv2, and ICMP Router
Discovery, courtesy of Vernon Schryver <vjs@sgi.com>. Thanks!
 1.18.10.2 09-Jan-2008  matt sync with HEAD
 1.18.10.1 06-Nov-2007  matt sync with HEAD
 1.19.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.20.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.20.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.23.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26 23-Dec-2016  mrg for 64 bit mips platforms where we built userland largely as n32 by
default, build a handful of tools as n64 so they work properly.

unfortunately, they're also static as dynamic n64 has a problem.

of these tools pstat is probably the lowest hanging fruit to convert
to sysctl. systat would be close were it not for the netstat screen,
which includes netstat itself.

the rest are difficult to perhaps foolish.


the upside is that netstat, pmap and fstat all work properly now.
 1.25 13-Jun-2001  wiz branches: 1.25.84;
Use getbootfile(3) instead of _PATH_UNIX by default.
Sprinkle some const.
 1.24 02-Jan-2001  joda use gzip instead of compress
 1.23 19-Feb-1998  thorpej NetBSD/mips uses new libkvm now, savecore_old.c is dead.
 1.22 19-Feb-1998  thorpej Simplify savecore_old test ... MACHINE_ARCH == "mips".
 1.21 18-Feb-1998  thorpej i386
 1.20 08-May-1997  gwr Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
 1.19 06-May-1997  gwr Use .PATH.c: ...
 1.18 25-Apr-1997  thorpej mvme68k uses the new crash dump format now.
 1.17 23-Apr-1997  scottr mac68k uses new libkvm, now.
 1.16 09-Apr-1997  thorpej hp300 uses new savecore now
 1.15 30-Mar-1997  thorpej Sun3x and PowerPC both use new libkvm.
 1.14 08-Feb-1997  matthias The pc532 port now uses the new libkvm.
 1.13 18-Nov-1996  pk sparc uses new savecore.c
 1.12 01-Oct-1996  cgd add alpha to the list of ports that use new savecore
 1.11 12-May-1996  mhitch Add amiga to the list of ports using the new savecore.
 1.10 08-May-1996  gwr Add sun3 to the list of ports using the new savecore.
Add -lkvm when linking the new savecore.
 1.9 30-Mar-1996  cgd since the only difference between the old 'savecore' and the new one
is savecore.c, move it back into the 'savecore' dir (renamed as
savecore_old.c) so that the build is more 'normal,' and more like what
it used to be.
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 22-Dec-1994  cgd specify man pages the new way.
 1.6 11-Jun-1994  mycroft Fix up RCS ids.
 1.5 10-Jun-1994  pk Update to 4.4-lite.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.25.84.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.37 15-Mar-2012  njoly Use Lk macro when dealing with URLs. While here update or remove some
dead URL links. Another part of PR/29238.
 1.36 13-Sep-2011  wiz branches: 1.36.2;
Fix typo.
 1.35 12-Sep-2011  christos document that dumpdir is now optional
 1.34 07-Mar-2009  ad Add crash(8), a utility to diagnose kernel crashes. This is basically
ddb running on crash dumps, but with two notable changes:

- Breakpoints, watches, etc are obviously never going to work so they
are not handled.

- You can pipe output to the shell, e.g. ps | grep foo

Items remaining to be done:

- Port it to architectures other than i386. This isn't difficult, just
a case of making db_disasm.c/db_trace.c or their equivalent compile
and work.

- Make more of the "show" commands work, e.g "show uvmexp".
 1.33 21-Oct-2004  dsainty branches: 1.33.38;
Rearrange the option formatting to be both prettier and more complete
 1.32 16-Oct-2004  snj New sentence, new line; use .Dq instead of ``''.
 1.31 16-Oct-2004  dsainty Bump date for -n description
 1.30 16-Oct-2004  dsainty Added -n option, which tests for a present core but doesn't write it
to disk or clear it (does 'nothing').

http://mail-index.netbsd.org/tech-userlevel/2004/10/09/0000.html
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.28 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.27 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.26 16-Nov-2001  wiz Sort sections.
 1.25 16-Nov-2001  wiz Whitespace nits
 1.24 12-Sep-2001  lukem explicitly set the default compression level to 1 (from the implicit 6),
because it's significantly faster and doesn't use that much more disk space.
 1.23 12-Sep-2001  lukem Add "-Z level" to control the compression level that -z uses (which
defaults to -Z 6). Depending on the relative speed of the CPU
versus disk, "-zZ1" might be faster than no compression at all.
 1.22 20-Aug-2001  wiz Document more explicitly that the kernel must be `secure' according to
secure_path to be used automatically. (Of course, you can override with the
-N option.)
Addresses bin/13665.
 1.21 13-Jun-2001  wiz Note usage of getbootfile(3); sort SEE ALSO section according to
mdoc.samples(7).
 1.20 05-Jun-2001  wiz Drop arguments of .Os.
 1.19 03-Apr-2001  wiz Xref send-pr 1, not 8. Whitespace fixes while I'm here.
 1.18 02-Jan-2001  joda use gzip instead of compress
 1.17 07-Dec-2000  wiz Don't mention rc(8), we're using rc.d now.
 1.16 27-Mar-2000  pooka branches: 1.16.4;
.core.Z, not .Z.core.

Reported by Wolfgang Helbig in pr/9684
 1.15 20-Nov-1999  sommerfeld Include clues on what to do with the crash dump once you've got it
 1.14 17-Sep-1999  is branches: 1.14.4;
Clarify description of ``-c''. (See PR 4511)
 1.13 20-Oct-1997  enami Fix .Nm usage.
 1.12 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
* deprecate register
 1.11 27-Jun-1995  briggs Note the proper name for the core file instead of vmcore, and note the
names used when the -z option is present.
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 13-Jun-1994  cgd kill U word
 1.8 11-Jun-1994  mycroft Fix up RCS ids.
 1.7 10-Jun-1994  pk Update to 4.4-lite, local changes to man page.
 1.6 01-Aug-1993  mycroft Add RCS indentifiers.
 1.5 28-Apr-1993  cgd bsd->netbsd
 1.4 28-Apr-1993  cgd kernel name is /bsd
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.16.4.1 04-Apr-2001  he Pull up revision 1.19 (via patch, requested by wiz):
Xref send-pr 1, not 8 + whitespace fixes.
 1.33.38.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.36.2.1 17-Apr-2012  yamt sync with head
 1.90 03-Apr-2020  maxv Avoid overflows when reading strings.
 1.89 06-Nov-2019  mrg elide recently introduced warnings that trigger in normal cases, eg:

savecore: dump_exists:471: kvm_read newdumpmag: _kvm_kvatop(ffffffff8180030c)
 1.88 27-Dec-2018  mrg avoid infinite loop in kmem_check(). fixes bug introduced in previous.
 1.87 06-Nov-2018  mrg put a bunch of the kvm_read + warn on failure code into a macro that
describes more about what failed. now errors tell you which actual
variable was being requested instead of simply saying "not yours".

tested on amd64 as working. written for arm64 testing.
 1.86 13-May-2013  christos branches: 1.86.26; 1.86.28;
- avoid using globals where it is simple.
- simplify: only use stdio for output.
 1.85 07-Apr-2012  christos branches: 1.85.2;
factor out rawname() from dump, fsck, savecore.
 1.84 13-Sep-2011  christos branches: 1.84.2;
print the missing flag if missing argument...
 1.83 12-Sep-2011  christos - always print corrupted dump messages instead of silently failing
- don't require /var/crash to be specified, default to it
- determine and print the kernel name
- print all messages to syslog
 1.82 29-Aug-2011  joerg static + __dead
 1.81 18-Aug-2009  dogcow Instead of exiting with an obscure error message if -N /kernelname isn't
specified, blithely assume the kernel will consume around 20 megs.
 1.80 06-Apr-2009  lukem fix sign-compare issues
 1.79 21-Mar-2009  tls Fix savecore so it uses /dev/ksyms when it can (doesn't override libkvm
default). Fixes misc/38425.
 1.78 28-Dec-2008  christos branches: 1.78.2;
fix dev_t format.
 1.77 05-Dec-2008  ad Enable the faked ELF kernel by default, now that ksyms output works with
gdb. Makes it possible to do post-mortem debugging on a modular kernel.
 1.76 20-Oct-2008  ad branches: 1.76.2;
- Add code to produce a fake ELF kernel containing only symbol info. Done
by extracting ksyms state from the dump, so we have symbols for modules
loaded at the time of the crash. If ksyms extraction fails, this falls
back to the current behaviour of copying /netbsd.

- Leave it disabled for the moment: (1) we are about to branch (2) most
tools understand the artificial kernel but gdb has trouble with it for
some reason.
 1.75 09-Oct-2008  joerg Explicitly check that the dump device is not the console, a tty or pty.
While the list is adhoc, the problems reported are always with
/dev/console. Adresses PR 38425 and similiar issues with Xen.
 1.74 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.73 20-Apr-2008  ad branches: 1.73.2;
sync() a couple of times to benefit diagnosis of sloppy kernel code that
crashes during boot to multiuser.
 1.72 15-Jan-2008  ad branches: 1.72.4; 1.72.6;
Don't use the block device to read crashdumps, if possible.
 1.71 12-Nov-2007  pooka branches: 1.71.2;
tyop: _time_seconf -> _time_second
 1.70 18-Dec-2006  christos branches: 1.70.4;
from Anon Ymous: remove (void)&var;
 1.69 16-Oct-2006  christos c99 initializers
 1.68 09-Jul-2006  kardel accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)
 1.67 07-Jun-2006  kardel support timecounters (struct time gone, use time_second then)
 1.66 17-Mar-2006  hubertf Free some allocated memory in the failure case when trying to
fetch the panic string.

Fixes Coverity CID 1856.
 1.65 16-Oct-2004  dsainty branches: 1.65.6;
Added -n option, which tests for a present core but doesn't write it
to disk or clear it (does 'nothing').

http://mail-index.netbsd.org/tech-userlevel/2004/10/09/0000.html
 1.64 14-Jul-2004  tls Fix an integer overflow that prevented saving cores from machines with
more than 2GB of RAM.

"dumpsize" in the on-disk core header is in pages, but, unfortunately,
c.size in our kcore format is an unsigned 32-bit int, gross.

We sleaze it, using a 64-bit int internally here and handing it to
libkvm as a *signed* 32-bit int. Won't always work, but shouldn't be
broken any worse than it is now, and sometimes work better.

We must fix the kcore format and libkvm.
 1.63 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.62 30-Mar-2004  christos Give a 60 day leeway instead of a week when judging if the dumptime is valid.
7 days is too short when you are debugging time problems.
 1.61 07-Aug-2003  agc branches: 1.61.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.60 18-May-2003  itojun simplify by strlcpy
 1.59 06-Dec-2002  thorpej Remove prototype for non-existent function log().
 1.58 27-Sep-2002  drochner use humanize_number(3) for progress printout
 1.57 19-Mar-2002  christos branches: 1.57.2;
PR/15502: Wolfgang Rupprecht: savecore fails for > 2GB files.
 1.56 06-Mar-2002  tsutsui Change type of dumpmag and newdumpmag from int to u_int32_t
since they hold 32bit unsigned magic numbers. (sync with kernels)
 1.55 01-Nov-2001  lukem fix a couple of -Wshadow warnings
 1.54 12-Sep-2001  lukem explicitly set the default compression level to 1 (from the implicit 6),
because it's significantly faster and doesn't use that much more disk space.
 1.53 12-Sep-2001  lukem Add "-Z level" to control the compression level that -z uses (which
defaults to -Z 6). Depending on the relative speed of the CPU
versus disk, "-zZ1" might be faster than no compression at all.
 1.52 13-Jun-2001  wiz Use getbootfile(3) instead of _PATH_UNIX by default.
Sprinkle some const.
 1.51 06-May-2001  simonb If the position of the formatted panic string can be found in the
message buffer, use that instead of the raw panic string.

Suggested by Jason Thorpe eons ago.
 1.50 11-Jan-2001  martin Make option flag variables static. This avoids a conflict between
'int compress' in savecore.c and the function 'compress' in libz.
Gnu ld 2.10 (with BFD 2.10) used on sparc64 warns this conflict
(symbol "compress" changed size).
 1.49 02-Jan-2001  joda use gzip instead of compress
 1.48 02-Jan-2001  lukem Bump the field width of `K to go' from 6 to 8; some systems have more
than 999999 KB of RAM... (this will suffice until it's common to have
~ 100 GB of RAM :)
 1.47 11-Dec-2000  wiz Back out sysctl part for now, awaiting the result of further discussion,
on request of Andrew Doran.
 1.46 08-Dec-2000  wiz Output proper warning if dumplo == -1 (as it can happen on macppc without
swap partition), instead of "kvm_dump_mkheader: Pread: Invalid argument".
 1.45 07-Dec-2000  wiz de-__P(), and generally try to be more conforming to the new NetBSD style.
Use %m in syslog strings where appropriate.
Reduce warnings with WARNS=2.
 1.44 07-Dec-2000  wiz Fix argument handling, which was pretty broken.
If sysctl supports it, try to get the kernel name with CPU_BOOTED_KERNEL.
Get current kernels version string in all cases.
Adapt some error messages to the correct kernel name.
Reviewed by Simon Burge.
 1.43 08-Oct-2000  darrenr initialize kernel to _PATH_UNIX and remove local variables in functions
which are essentially copies of kernel.
 1.42 01-Oct-2000  darrenr savecore was looking up dumpdev, etc, from the wrong kernel
 1.41 01-Aug-2000  eeh time is a `struct timeval' not a `time_t', so read it in properly.
 1.40 02-Aug-1999  mycroft branches: 1.40.8;
s/on device/in [dirname]/, to be a bit clearer...
 1.39 01-Jul-1999  cgd Remove an extraneous fclose() call which would cause savecore to crash
if the bounds file was unwritable (e.g. because /var was read-only).
Fix supplied by Ronald Khoo in PR#7887.
 1.38 27-Feb-1999  sommerfe branches: 1.38.2;
Crash dumps should *not* be world readable.
 1.37 23-Jul-1998  sommerfe Avoid truncating partition size in freespace calculation
 1.36 01-Apr-1998  kleink Need <time.h> for time() and ctime() prototypes.
 1.35 18-Feb-1998  thorpej Avoid
 1.34 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.33 16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.32 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
* deprecate register
 1.31 25-Aug-1997  kleink Lseek(2) usage cleanup: the use of L_SET/L_INCR/L_XTND is deprecated,
use SEEK_SET/SEEK_CUR/SEEK_END instead.
 1.30 19-May-1997  pk More error checking.
 1.29 21-Apr-1997  mrg set umask for savecore.
 1.28 01-Oct-1996  cgd make datas item copied out from kernel (panicstr) and/or used as kvm pointers
(panicloc) be 'long's, not 'int's.
 1.27 23-Jun-1996  leo If kvm_dump_mkheader() returns 0, simply state 'no core dump' instead
of logging and error.
 1.26 18-Mar-1996  leo Omit kd_live argument to kvm_dump_mkheader().
 1.25 16-Mar-1996  leo New libkvm/savecore implementation. With the following differences:
1) savecore will not access the dump or live-kernel directly. It
will always use the kvm-functions. Allowing it to work on kernels
that don't have a 1-1 PA-VA mapping.
2) the kvm-lib has some additional functions to accomplish 1
- kvm_dump_mkheader()
- kvm_dump_wrtheader()
- kvm_dump_inval()
3) the file formats of the dump generated by the kernel and the dump
generated by savecore have been changed. The file format now looks
like the format produced for 'normal' core dumps.
Ports not yet supporting the new kvm-format will be using libkvm.old/
savecore.old for the time being.
 1.24 08-Mar-1996  mycroft Put the compression suffix *last*.
 1.23 24-Jul-1995  cgd set dumpsize in dump_exists(), not save_core(), so that minfree check
works again. solves pr 1257, but sets dumpsize earlier than suggested
in that pr, so that dumpsize is set if a core doesn't appear to be
present (because dumpsize would be used if the '-f' flag is given).
 1.22 25-Jun-1995  cgd fix verbose printf of dumplo, clean up printfs slightly
 1.21 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.20 04-Jan-1995  mycroft Fix getopt string and test on return value.
 1.19 31-Oct-1994  cgd oops; get rid of previous (iffy) zopen declaration
 1.18 31-Oct-1994  cgd make a proto for zopen (yech)
 1.17 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.16 18-Sep-1994  deraadt prototype zopen()
NBPG --> getpagesize()
 1.15 17-Sep-1994  mycroft vmunix --> kernel (for variable names), and make the core file naming
convention match that of other executables.
 1.14 11-Jun-1994  mycroft Fix up RCS ids.
 1.13 10-Jun-1994  pk Update to 4.4-lite, local changes to man page.
 1.12 31-May-1994  pk Initialize return value from save_core() in case dumpsize == 0.
 1.11 27-May-1994  pk Don't clear dump if writing it to the filesystem fails (eg. file system full)
 1.10 21-Apr-1994  cgd queue/struct changes
 1.9 06-Apr-1994  cgd kill two casts
 1.8 06-Apr-1994  cgd serious perversion:
most of the 'off' arguments to Lseek() (the internal lseek() wrapper)
are unsigned longs. we need them to be sign extended, though, so change
Lseek() to take a 'long' rather than an 'off_t', and let the compiler
do the dirty work via implicit casts.
 1.7 04-Apr-1994  cgd lseek stuff, and clean up. this is perverse.
 1.6 14-Feb-1994  cgd correct ok() calculation for all architectures.
 1.5 08-Dec-1993  pk Check for dumpdev being NODEV. If so, exit silently, unless verbose is on.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.38.2.1 02-Jul-1999  perry pullup 1.38->1.39 (cgd)
 1.40.8.1 07-Aug-2000  mrg pull up 1.41 (approved by jhawk):
>time is a `struct timeval' not a `time_t', so read it in properly.
 1.57.2.1 23-Jul-2004  tron Apply patch (requested by dbj in ticket 1724):
Fix problems when building the netbsd-1-6 branch with GCC 3.3.3.
 1.61.2.3 14-Jul-2004  tron Pull up revision 1.64 (requested by tls in ticket #650):
Fix an integer overflow that prevented saving cores from machines with
more than 2GB of RAM.
"dumpsize" in the on-disk core header is in pages, but, unfortunately,
c.size in our kcore format is an unsigned 32-bit int, gross.
We sleaze it, using a 64-bit int internally here and handing it to
libkvm as a *signed* 32-bit int. Won't always work, but shouldn't be
broken any worse than it is now, and sometimes work better.
We must fix the kcore format and libkvm.
 1.61.2.2 14-Jul-2004  tls revert accidental commit to branch
 1.61.2.1 14-Jul-2004  tls Fix an integer overflow that prevented saving cores from machines with
more than 2GB of RAM.

"dumpsize" in the on-disk core header is in pages, but, unfortunately,
c.size in our kcore format is an unsigned 32-bit int, gross.

We sleaze it, using a 64-bit int internally here and handing it to
libkvm as a *signed* 32-bit int. Won't always work, but shouldn't be
broken any worse than it is now, and sometimes work better.

We must fix the kcore format and libkvm.
 1.65.6.2 22-Apr-2006  simonb Sync with head.
 1.65.6.1 04-Feb-2006  simonb If we have timecounters, read time_second from the kernel for the
dump time instead of time.tv.sec.
 1.70.4.2 23-Mar-2008  matt sync with HEAD
 1.70.4.1 09-Jan-2008  matt sync with HEAD
 1.71.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.72.6.1 18-May-2008  yamt sync with head.
 1.72.4.3 17-Jan-2009  mjf Sync with HEAD.
 1.72.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.72.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.73.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.76.2.2 28-Nov-2009  bouyer Pull up following revision(s) (requested by dogcow in ticket #1157):
sbin/savecore/savecore.c: revision 1.81
Instead of exiting with an obscure error message if -N /kernelname isn't
specified, blithely assume the kernel will consume around 20 megs.
 1.76.2.1 24-Mar-2009  snj branches: 1.76.2.1.4;
Pull up following revision(s) (requested by tls in ticket #598):
sbin/savecore/savecore.c: revision 1.79
Fix savecore so it uses /dev/ksyms when it can (doesn't override libkvm
default). Fixes misc/38425.
 1.76.2.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.78.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.84.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.84.2.1 17-Apr-2012  yamt sync with head
 1.85.2.1 23-Jun-2013  tls resync from head
 1.86.28.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.86.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.86.28.1 10-Jun-2019  christos Sync with HEAD
 1.86.26.2 18-Jan-2019  pgoyette Synch with HEAD
 1.86.26.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.6 19-Feb-1998  thorpej NetBSD/mips uses new libkvm now, savecore_old.c is dead.
 1.5 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.4 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
* deprecate register
 1.3 26-Aug-1997  veego Remove a ( from an removed cast.
 1.2 25-Aug-1997  kleink Lseek(2) usage cleanup: the use of L_SET/L_INCR/L_XTND is deprecated,
use SEEK_SET/SEEK_CUR/SEEK_END instead.
 1.1 16-Mar-1996  leo branches: 1.1.1;
Initial revision
 1.1.1.1 16-Mar-1996  leo old savecore - do not update
 1.4 10-Jan-2017  kamil Adapt funopen(3) call after switch to new zlib(3)

In the prototype of the gzclose() function of changed from:

typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */

to:

typedef voidp gzFile;

This caused type mismatch when calling funopen(3) as:
'int (*)(void *)' != 'int (*)(struct gzFile_s *)'

Cast gzclose to (int (*)(void *)) when used in funopen(3).
 1.3 25-Dec-2012  mbalmer branches: 1.3.12;
Consistent use of return.
 1.2 27-Jun-2005  christos branches: 1.2.46; 1.2.52;
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.1 02-Jan-2001  joda use gzip instead of compress
 1.2.52.1 25-Feb-2013  tls resync with head
 1.2.46.1 23-Jan-2013  yamt sync with head
 1.3.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.11 24-Jan-2023  mlelstv Work on swapped-endian FFS.
 1.10 07-Sep-2020  mrg branches: 1.10.6;
remove GCC_NO_ADDR_OF_PACKED_MEMBER for several subdir builds
that are now handled by lfs_accessors.h internally.
 1.9 06-Sep-2020  mrg add support for new GCC 9 warnings that may be too much to fix
right now. new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree. mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it. (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.) clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
 1.8 01-May-2007  perseant Add a "-b" option to search a partition for valid alternate superblocks,
rather than searching the disk for partitions. Also, test LFS superblock
checksums before we report them.
 1.7 10-Sep-2005  xtraeme branches: 1.7.4;
Specify the scan_ffs manpage, otherwise it will use scan_ffs.1.
 1.6 10-Sep-2005  wiz Fold scan_lfs.8 into scan_ffs.8. It's the same program, after all.
Ok'd by xtraeme.
 1.5 31-Jul-2005  xtraeme Add scan_lfs(8), utility to find LFS partitions on disk, useful
to recover lost disklabels.
 1.4 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.3 15-Jun-2005  christos WARNS=4, misc cleanups.
- void casts
- remove unused notreached
- use a loop instead of code duplication
- use switches and #define constants
 1.2 15-Jun-2005  kleink No need to define SRCS here.
 1.1 15-Jun-2005  xtraeme Add scan_ffs(8) from OpenBSD, it was modified to support FFSv2
for NetBSD (with different blocksizes). Utility to find
FFSv1 and FFSv2 partitions on disks, useful to recover lost
disklabels.

Reviewed by christos.
 1.7.4.3 21-Aug-2006  tron Apply patch (request by ghen in ticket #1470):
Avoid "-std=c99" if building NetBSD-vax which still uses GCC 2.95.3.
This fixes the broken build of NetBSD-vax.
 1.7.4.2 11-Aug-2006  riz Pull up following revision(s) via patch (requested by ghen in ticket #1460):
distrib/sets/lists/base/mi: revision 1.556, 1.565
distrib/sets/lists/man/mi: revision 1.792, 1.814
sbin/Makefile: revision 1.94
sbin/scan_ffs/Makefile: revision 1.1-1.3, 1.5-1.7
sbin/scan_ffs/scan_ffs.c: revision 1.1-1.9
sbin/scan_ffs/scan_ffs.8: revision 1.1-1.6 via patch
Add scan_ffs(8) from OpenBSD, modified for NetBSD to support FFSv2 and
LFS (scan_lfs(8)). Utility to find FFSv1, FFSv2 and LFS partitions on
disks, useful to recover lost disklabels.
 1.7.4.1 10-Sep-2005  riz file Makefile was added on branch netbsd-3 on 2006-08-11 04:41:25 +0000
 1.10.6.1 22-Feb-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #94):

sbin/scan_ffs/Makefile: revision 1.11
sbin/scan_ffs/scan_ffs.c: revision 1.37

Work on swapped-endian FFS.
 1.14 01-May-2007  xtraeme Bump date.
 1.13 01-May-2007  perseant Add a "-b" option to search a partition for valid alternate superblocks,
rather than searching the disk for partitions. Also, test LFS superblock
checksums before we report them.
 1.12 17-Oct-2006  wiz Improve English.
 1.11 14-Oct-2006  xtraeme Detect FFSv1 partitions with fragsize/blocksize greater than
2048/16384.
 1.10 10-Sep-2006  wiz Sort options in usage and SYNOPSIS.
 1.9 07-Sep-2006  xtraeme Change -f to -F, per mrg's suggestion.
 1.8 07-Sep-2006  xtraeme Add -f file support. Useful to search for partitions on disk images.
 1.7 12-Aug-2006  ghen scan_ffs(8) has been pulled up into netbsd-3 and thus will have
"first appeared in NetBSD 3.1", not 4.0.
 1.6 10-Sep-2005  wiz branches: 1.6.2; 1.6.4;
Fold scan_lfs.8 into scan_ffs.8. It's the same program, after all.
Ok'd by xtraeme.
 1.5 09-Sep-2005  wiz Improve wording and comma usage.
 1.4 19-Jun-2005  wiz Remove superfluous .El; a slight wording change.
 1.3 19-Jun-2005  wiz Incorporate my review comments.
 1.2 15-Jun-2005  peter fix the date, use .An for names, correct the name (scanffs -> scan_ffs),
.Ox/.Nx for OpenBSD/NetBSD, mention appearance in NetBSD.
 1.1 15-Jun-2005  xtraeme Add scan_ffs(8) from OpenBSD, it was modified to support FFSv2
for NetBSD (with different blocksizes). Utility to find
FFSv1 and FFSv2 partitions on disks, useful to recover lost
disklabels.

Reviewed by christos.
 1.6.4.2 11-Aug-2006  riz Pull up following revision(s) via patch (requested by ghen in ticket #1460):
distrib/sets/lists/base/mi: revision 1.556, 1.565
distrib/sets/lists/man/mi: revision 1.792, 1.814
sbin/Makefile: revision 1.94
sbin/scan_ffs/Makefile: revision 1.1-1.3, 1.5-1.7
sbin/scan_ffs/scan_ffs.c: revision 1.1-1.9
sbin/scan_ffs/scan_ffs.8: revision 1.1-1.6 via patch
Add scan_ffs(8) from OpenBSD, modified for NetBSD to support FFSv2 and
LFS (scan_lfs(8)). Utility to find FFSv1, FFSv2 and LFS partitions on
disks, useful to recover lost disklabels.
 1.6.4.1 10-Sep-2005  riz file scan_ffs.8 was added on branch netbsd-3 on 2006-08-11 04:41:25 +0000
 1.6.2.2 14-Sep-2006  riz Pull up following revision(s) (requested by wiz in ticket #156):
sbin/scan_ffs/scan_ffs.8: revision 1.10
sbin/scan_ffs/scan_ffs.c: revision 1.13
Sort options in usage and SYNOPSIS.
 1.6.2.1 10-Sep-2006  riz Pull up following revision(s) (requested by xtraeme in ticket #146):
sbin/scan_ffs/scan_ffs.8: revision 1.7
sbin/scan_ffs/scan_ffs.8: revision 1.8
sbin/scan_ffs/scan_ffs.8: revision 1.9
sbin/scan_ffs/scan_ffs.c: revision 1.10
sbin/scan_ffs/scan_ffs.c: revision 1.11
sbin/scan_ffs/scan_ffs.c: revision 1.12
Add -f file support. Useful to search for partitions on disk images.
Change -f to -F, per mrg's suggestion.
- Change the cast of st_size to uint64_t to avoid future problems
with large files.
- u_uintXX_t -> uintXX_t
 1.37 24-Jan-2023  mlelstv Work on swapped-endian FFS.
 1.36 17-Nov-2022  chs branches: 1.36.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.35 20-Jan-2022  christos O_CLOEXEC is not a mode :-)
 1.34 20-Jan-2022  christos - use /dev/tty instead of stderr for SIGINFO messages
- use uintmax_t instead of ull
- print fractional percentage to show that we are making progress on large
disks.
 1.33 19-Jan-2022  mrg add SIGINFO support. now you can know how far along the scan is.
 1.32 15-Oct-2015  dholland Teach scan_ffs about lfs64.
(and also about byte-swapped lfs volumes, which might or might not
actually work)
 1.31 02-Aug-2015  dholland Add a (draft) 64-bit superblock. Make things build again.

Add pieces of support for using both superblock types where
convenient, and specifically to the superblock accessors, but don't
actually enable it anywhere.

First substantive step on PR 50000.
 1.30 02-Aug-2015  dholland Use accessor functions for the version field of the lfs superblock.
I thought at first maybe the cases that test the version should be
rolled into the accessors, but on the whole I think the conclusion on
that is no.
 1.29 02-Aug-2015  dholland Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.
 1.28 28-Jul-2015  dholland Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.
 1.27 24-Jul-2015  dholland More lfs superblock accessors.
(This changes the rest of the code over; all the accessors were
already added.)

The difference between this commit and the previous one is arbitrary,
but the previous one passed the regression tests on its own so I'm
keeping it separate to help with any bisections that might be needed
in the future.
 1.26 24-Jul-2015  dholland Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.
 1.25 23-Jun-2013  dholland Stick ffs_ in front of the following macros:
fragstoblks()
blkstofrags()
fragnum()
blknum()

to finish the job of distinguishing them from the lfs versions, which
Christos renamed the other day.

I believe this is the last of the overtly ambiguous exported symbols
from ffs... or at least, the last of the ones that conflicted with lfs.
ffs still pollutes the C namespace very broadly (as does ufs) and this
needs quite a bit more cleanup.

XXX: boo on macros with lowercase names. But I'm not tackling that just yet.
 1.24 23-Jun-2013  dholland Stick ffs_, ext2_, chfs_, filecore_, cd9660_, or mfs_ in front of
the following symbols so as to disambiguate fully. (Christos already
did the lfs ones.)

lblkno
lblktosize
lfragtosize
numfrags
blkroundup
fragroundup
 1.23 23-Jun-2013  dholland fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.22 19-Jun-2013  dholland Rename ambiguous macros:
MAXDIRSIZE -> UFS_MAXDIRSIZE or LFS_MAXDIRSIZE
NINDIR -> FFS_NINDIR, EXT2_NINDIR, LFS_NINDIR, or MFS_NINDIR
INOPB -> FFS_INOPB, LFS_INOPB
INOPF -> FFS_INOPF, LFS_INOPF
blksize -> ffs_blksize, ext2_blksize, or lfs_blksize
sblksize -> ffs_blksize

These are not the only ambiguously defined filesystem macros, of
course, there's a pile more. I may not have found all the ambiguous
definitions of blksize(), too, as there are a lot of other things
called 'blksize' in the system.
 1.21 11-Apr-2009  lukem branches: 1.21.6; 1.21.12;
fix sign-compare issues
 1.20 15-Dec-2007  perry branches: 1.20.12;
convert __attribute__s to applicable cdefs.h macros
 1.19 06-Oct-2007  xtraeme branches: 1.19.2;
Use a two clause license for all the code I contributed.

The envsys code will be changed later.
 1.18 01-May-2007  xtraeme branches: 1.18.4;
Add -b flag into usage().
 1.17 01-May-2007  perseant Add a "-b" option to search a partition for valid alternate superblocks,
rather than searching the disk for partitions. Also, test LFS superblock
checksums before we report them.
 1.16 16-Feb-2007  xtraeme * There's no need to use an int to store the returned value of
ffs_checkver() and later use it in the switch statement, just
use ffs_checkver.
* Remove unneded <sys/queue.h> header.
* Remove LFS from fstypes, it was never used.
* Increase SBCOUNT to 128, works faster.
* Remove unneded casts.
* (-F mode) close fd when the scan has finished or if pread() failed.
* (-F mode) print total size of file.
 1.15 15-Oct-2006  xtraeme Use O_DIRECT (aka Direct I/O) when -F is used.
 1.14 14-Oct-2006  xtraeme Detect FFSv1 partitions with fragsize/blocksize greater than
2048/16384.
 1.13 10-Sep-2006  wiz Sort options in usage and SYNOPSIS.
 1.12 08-Sep-2006  xtraeme - Change the cast of st_size to uint64_t to avoid future problems
with large files.
- u_uintXX_t -> uintXX_t
 1.11 07-Sep-2006  xtraeme Change -f to -F, per mrg's suggestion.
 1.10 07-Sep-2006  xtraeme Add -f file support. Useful to search for partitions on disk images.
 1.9 02-Sep-2005  xtraeme branches: 1.9.2; 1.9.4;
Remove an extra conditional while searching for LFS superblocks,
it's not needed.
 1.8 09-Aug-2005  he Undefine the 17 macros commonly defined by <ufs/ffs/fs.h> and
<ufs/lfs/lfs.h> before including the second of them, and also after
including the second, to ensure the rest of the code doesn't depend
on their (ambigious) definition.

This fixes a build problem for vax; gcc 2.95.3's preprocessor
apparently doesn't like redefinition of macros.

Discussed with xtraeme.
 1.7 09-Aug-2005  xtraeme * Replace lseek() and read() calls with one single pread()
* Align cpg/sgs correctly.
 1.6 31-Jul-2005  christos Pass lint and get/setprogname.
 1.5 31-Jul-2005  xtraeme Add scan_lfs(8), utility to find LFS partitions on disk, useful
to recover lost disklabels.
 1.4 23-Jun-2005  xtraeme Add missing '\n' into usage().
 1.3 15-Jun-2005  christos WARNS=4, misc cleanups.
- void casts
- remove unused notreached
- use a loop instead of code duplication
- use switches and #define constants
 1.2 15-Jun-2005  kleink Use EXIT_{SUCCESS,FAILURE}.
 1.1 15-Jun-2005  xtraeme Add scan_ffs(8) from OpenBSD, it was modified to support FFSv2
for NetBSD (with different blocksizes). Utility to find
FFSv1 and FFSv2 partitions on disks, useful to recover lost
disklabels.

Reviewed by christos.
 1.9.4.2 11-Aug-2006  riz Pull up following revision(s) via patch (requested by ghen in ticket #1460):
distrib/sets/lists/base/mi: revision 1.556, 1.565
distrib/sets/lists/man/mi: revision 1.792, 1.814
sbin/Makefile: revision 1.94
sbin/scan_ffs/Makefile: revision 1.1-1.3, 1.5-1.7
sbin/scan_ffs/scan_ffs.c: revision 1.1-1.9
sbin/scan_ffs/scan_ffs.8: revision 1.1-1.6 via patch
Add scan_ffs(8) from OpenBSD, modified for NetBSD to support FFSv2 and
LFS (scan_lfs(8)). Utility to find FFSv1, FFSv2 and LFS partitions on
disks, useful to recover lost disklabels.
 1.9.4.1 02-Sep-2005  riz file scan_ffs.c was added on branch netbsd-3 on 2006-08-11 04:41:25 +0000
 1.9.2.2 14-Sep-2006  riz Pull up following revision(s) (requested by wiz in ticket #156):
sbin/scan_ffs/scan_ffs.8: revision 1.10
sbin/scan_ffs/scan_ffs.c: revision 1.13
Sort options in usage and SYNOPSIS.
 1.9.2.1 10-Sep-2006  riz Pull up following revision(s) (requested by xtraeme in ticket #146):
sbin/scan_ffs/scan_ffs.8: revision 1.7
sbin/scan_ffs/scan_ffs.8: revision 1.8
sbin/scan_ffs/scan_ffs.8: revision 1.9
sbin/scan_ffs/scan_ffs.c: revision 1.10
sbin/scan_ffs/scan_ffs.c: revision 1.11
sbin/scan_ffs/scan_ffs.c: revision 1.12
Add -f file support. Useful to search for partitions on disk images.
Change -f to -F, per mrg's suggestion.
- Change the cast of st_size to uint64_t to avoid future problems
with large files.
- u_uintXX_t -> uintXX_t
 1.18.4.2 09-Jan-2008  matt sync with HEAD
 1.18.4.1 06-Nov-2007  matt sync with HEAD
 1.19.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.20.12.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.21.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.21.12.1 23-Jun-2013  tls resync from head
 1.21.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.2.1 22-Feb-2023  martin Pull up following revision(s) (requested by mlelstv in ticket #94):

sbin/scan_ffs/Makefile: revision 1.11
sbin/scan_ffs/scan_ffs.c: revision 1.37

Work on swapped-endian FFS.
 1.3 10-Sep-2005  wiz Fold scan_lfs.8 into scan_ffs.8. It's the same program, after all.
Ok'd by xtraeme.
 1.2 31-Jul-2005  xtraeme typo
 1.1 31-Jul-2005  xtraeme Add scan_lfs(8), utility to find LFS partitions on disk, useful
to recover lost disklabels.
 1.4 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.3 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.2 18-Oct-1998  thorpej yoops, build manpage (duh)
 1.1 15-Oct-1998  thorpej scsictl(8) - a program to manipulate SCSI devices and busses. Currently
supports:

Devices: identify, reassign blocks, reset

Busses: reset, scan for devices

Coming soon, device formatting, mode page editing, device freeze/thaw, etc.
 1.7 21-Feb-2012  jakllsch constify command data argument to scsi_command().
 1.6 28-Apr-2008  martin branches: 1.6.20;
Remove clause 3 and 4 from TNF licenses
 1.5 05-Feb-2005  xtraeme branches: 1.5.26; 1.5.28;
Kill __P(), use ANSI function declarations; WARNS=3.
 1.4 26-Jun-2002  mjacob Add a bunch of stuff from Bob Nestor that fixes format to allow one to
specify device logical blocksize.

Furthermore, it also adds an 'immediate' option, which then sends more modern
devices into formatting in the background. scsictl still waits around and
sends a TEST UNIT READY every 10 seconds and, based upon the sense data
it gets back after the invariable CHECK CONDITION, prints out a progress
indicator (based upon SKSV progress in the sense data).

While we're at it, add a 'tur', 'reserve', 'release', 'start' and 'stop'
functions to the device commands.

Fix a long standing bug in scsi_command- the value in retsts is an integral
value- not a bitmask.
 1.3 05-Sep-2001  thorpej branches: 1.3.2;
Fixup scsi_mode_select().
 1.2 12-Nov-1998  thorpej Simple support for formatting a SCSI disk. This will be enhanced in
the near future.
 1.1 15-Oct-1998  thorpej scsictl(8) - a program to manipulate SCSI devices and busses. Currently
supports:

Devices: identify, reassign blocks, reset

Busses: reset, scan for devices

Coming soon, device formatting, mode page editing, device freeze/thaw, etc.
 1.3.2.1 28-Jul-2003  he Pull up revision 1.4 (requested by thorpej in ticket #764):
Several changes/updates to scsictl:
o Allow specification of logical blocksize
o Add 'getcache' and 'setcache' commands
o Add 'tur', 'reserve', 'release', 'start', and 'stop' functions
o Add an 'immediate' option to do formatting in the background
o Fix bug in scsi_command -- value in resets is an int not a
bitmask
o Fix usage of errx() / warnx() and remove unneeded trailing \n
 1.5.28.1 18-May-2008  yamt sync with head.
 1.5.26.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.20.1 17-Apr-2012  yamt sync with head
 1.11 28-Dec-2023  andvar s/informtion/information/ in comments.
 1.10 24-Jan-2022  andvar s/begining/beginning/ in comments and messages.
 1.9 22-Jun-2011  mrg when checking for SKSV data, use the same test as before. fixes an
always true conditional GCC 4.5 found, and is also a real bug fix.
 1.8 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7 11-Feb-2008  dyoung branches: 1.7.4; 1.7.6;
Do not #include <sys/device.h> from userland.
 1.6 05-Feb-2005  xtraeme branches: 1.6.16; 1.6.18;
Kill __P(), use ANSI function declarations; WARNS=3.
 1.5 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.4 17-May-2003  itojun use strlcpy
 1.3 15-Mar-1999  thorpej Remove some extra spaces.
 1.2 24-Feb-1999  jwise Code to check if a cooked device was specified was failing even if the
cooked device was opened successfully. Also fix a typo.

Fixes second part of PR bin/6883 for Soren S. Jorvang <soren@t.dk>
 1.1 15-Oct-1998  thorpej scsictl(8) - a program to manipulate SCSI devices and busses. Currently
supports:

Devices: identify, reassign blocks, reset

Busses: reset, scan for devices

Coming soon, device formatting, mode page editing, device freeze/thaw, etc.
 1.6.18.1 18-Feb-2008  mjf Sync with HEAD.
 1.6.16.1 23-Mar-2008  matt sync with HEAD
 1.7.6.1 18-May-2008  yamt sync with head.
 1.7.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.14 21-Feb-2012  jakllsch Prevent stack buffer overflow when copying too-large-CDB into request.
 1.13 21-Feb-2012  jakllsch constify command data argument to scsi_command().
 1.12 28-Apr-2008  martin branches: 1.12.20;
Remove clause 3 and 4 from TNF licenses
 1.11 21-Feb-2005  thorpej branches: 1.11.26; 1.11.28;
Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.10 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.9 08-Sep-2003  agc Make this compile after the recent changes to the kernel.
 1.8 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.7 08-Oct-2002  soren Add missing \n in error.
 1.6 26-Jun-2002  mjacob Add a bunch of stuff from Bob Nestor that fixes format to allow one to
specify device logical blocksize.

Furthermore, it also adds an 'immediate' option, which then sends more modern
devices into formatting in the background. scsictl still waits around and
sends a TEST UNIT READY every 10 seconds and, based upon the sense data
it gets back after the invariable CHECK CONDITION, prints out a progress
indicator (based upon SKSV progress in the sense data).

While we're at it, add a 'tur', 'reserve', 'release', 'start' and 'stop'
functions to the device commands.

Fix a long standing bug in scsi_command- the value in retsts is an integral
value- not a bitmask.
 1.5 05-Sep-2001  thorpej branches: 1.5.2;
Fixup scsi_mode_select().
 1.4 15-May-2001  bouyer Adapt for MODE SENSE/SELECT changes in kernel.
 1.3 17-Apr-2001  ad Let '\377' be whitespace.
 1.2 12-Nov-1998  thorpej Simple support for formatting a SCSI disk. This will be enhanced in
the near future.
 1.1 15-Oct-1998  thorpej scsictl(8) - a program to manipulate SCSI devices and busses. Currently
supports:

Devices: identify, reassign blocks, reset

Busses: reset, scan for devices

Coming soon, device formatting, mode page editing, device freeze/thaw, etc.
 1.5.2.1 28-Jul-2003  he Pull up revisions 1.6-1.7 (requested by thorpej in ticket #764):
Several changes/updates to scsictl:
o Allow specification of logical blocksize
o Add 'getcache' and 'setcache' commands
o Add 'tur', 'reserve', 'release', 'start', and 'stop' functions
o Add an 'immediate' option to do formatting in the background
o Fix bug in scsi_command -- value in resets is an int not a
bitmask
o Fix usage of errx() / warnx() and remove unneeded trailing \n
 1.11.28.1 18-May-2008  yamt sync with head.
 1.11.26.1 02-Jun-2008  mjf Sync with HEAD.
 1.12.20.1 17-Apr-2012  yamt sync with head
 1.34 09-Nov-2024  rillig scsictl.8: brush up markup
 1.33 09-Nov-2024  mlelstv Add 'identify vpd' to also report Vital Product Data that identifies the device.
 1.32 21-Aug-2022  mlelstv branches: 1.32.4;
Add REPORT_LUNS command.
 1.31 08-Mar-2017  tsutsui Fix format.
 1.30 20-Nov-2016  wiz branches: 1.30.2;
Whitespace, sort.
 1.29 20-Nov-2016  dholland Add crossreference to scsi(4) per note in PR 9627.
 1.28 19-Nov-2016  wiz Bump date for previous.

Use more and more appropriate markup while here.
 1.27 19-Nov-2016  flxd Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
 1.26 29-Mar-2013  christos branches: 1.26.6; 1.26.10; 1.26.12;
Document debug
 1.25 30-Apr-2008  martin branches: 1.25.20; 1.25.22; 1.25.26;
Convert TNF licenses to new 2 clause variant
 1.24 23-Jan-2007  wiz branches: 1.24.12; 1.24.14;
Bump date for previous.
 1.23 22-Jan-2007  bouyer Kimura Fuyuki, bin/35216: add a setspeed command, to set the highest speed
that the optical drive should use for reading data.
 1.22 07-Jan-2005  wiz New sentence, new line. Simplify macro usage.
 1.21 07-Jan-2005  ginsbach Add command to read the defect data from a direct access device.
 1.20 16-Sep-2004  erh Add a couple cross-references to make similar ctl commands easier to find.
 1.19 01-Sep-2003  wiz Bump date for last.
 1.18 01-Sep-2003  mycroft Add a flushcache command -- I need it for my DVD+RW.
 1.17 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.16 03-Sep-2002  thorpej * Add "getcache" and "setcache" commands to get/set basic cache
parameters (enables, really).
* Fix an error in the manpage.
* Shuffle some code to group things together better.
 1.15 26-Jun-2002  wiz Punctuation vs. markup nits, and use .Dq instead of double quotes.
 1.14 26-Jun-2002  mjacob Add a bunch of stuff from Bob Nestor that fixes format to allow one to
specify device logical blocksize.

Furthermore, it also adds an 'immediate' option, which then sends more modern
devices into formatting in the background. scsictl still waits around and
sends a TEST UNIT READY every 10 seconds and, based upon the sense data
it gets back after the invariable CHECK CONDITION, prints out a progress
indicator (based upon SKSV progress in the sense data).

While we're at it, add a 'tur', 'reserve', 'release', 'start' and 'stop'
functions to the device commands.

Fix a long standing bug in scsi_command- the value in retsts is an integral
value- not a bitmask.
 1.13 16-Nov-2001  wiz branches: 1.13.2;
Sort sections, use standard section headers.
 1.12 18-Jul-2001  wiz Fix a typo, and capitalize SCSI in one place.
 1.11 18-Jul-2001  bouyer Add and document a 'detach' command.
 1.10 05-Jun-2001  wiz Drop arguments of .Os.
 1.9 03-Apr-2001  jdolecek xref se(4) now that the manpage is built and installed
 1.8 03-Apr-2001  wiz Don't xref nonexisting se(4).
 1.7 11-Feb-2001  ad Fix typo.
 1.6 08-Jul-2000  kleink Use .Pa.
 1.5 07-Mar-2000  jdolecek Add a note about what and where is printed for 'scan' command.
Addresses bin/9227 by <johnr@spimageworks.com>
 1.4 28-Sep-1999  ad Make `all' a synonym for the `any' keyword.
 1.3 30-Jul-1999  hubertf branches: 1.3.2;
Collect all little usage-messages spread around into one place,
and as a side effect, print the available commands (and their
usage) if no command is given on the command line.

Approved by Jason Thorpe.
 1.2 15-Oct-1998  thorpej Oops, finish the description of the "scan" bus command.
 1.1 15-Oct-1998  thorpej scsictl(8) - a program to manipulate SCSI devices and busses. Currently
supports:

Devices: identify, reassign blocks, reset

Busses: reset, scan for devices

Coming soon, device formatting, mode page editing, device freeze/thaw, etc.
 1.3.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.13.2.1 28-Jul-2003  he Pull up revisions 1.14-1.16 (requested by thorpej in ticket #764):
Several changes/updates to scsictl:
o Allow specification of logical blocksize
o Add 'getcache' and 'setcache' commands
o Add 'tur', 'reserve', 'release', 'start', and 'stop' functions
o Add an 'immediate' option to do formatting in the background
o Fix bug in scsi_command -- value in resets is an int not a
bitmask
o Fix usage of errx() / warnx() and remove unneeded trailing \n
 1.24.14.1 18-May-2008  yamt sync with head.
 1.24.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.26.1 23-Jun-2013  tls resync from head
 1.25.22.1 15-Jan-2017  snj Pull up following revision(s) (requested by flxd in ticket #1418):
sbin/scsictl/scsictl.8: 1.27, 1.29, 1.30 via patch
sbin/scsictl/scsictl.c: revision 1.39 via patch
sys/dev/scsipi/scsi_disk.h: revision 1.32
Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit
supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
--
Bump date for previous.
--
Add crossreference to scsi(4) per note in PR 9627.
Whitespace, sort.
 1.25.20.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.26.12.1 18-Jan-2017  skrll Sync with netbsd-5
 1.26.10.2 20-Mar-2017  pgoyette Sync with HEAD
 1.26.10.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.26.6.1 03-Dec-2016  martin Pull up following revision(s) (requested by flxd in ticket #1276):
sys/dev/scsipi/scsi_disk.h: revision 1.32
sbin/scsictl/scsictl.8: revision 1.27-1.30
sbin/scsictl/scsictl.c: revision 1.39
Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit
supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
Bump date for previous.
Use more and more appropriate markup while here.
Add crossreference to scsi(4) per note in PR 9627.
Whitespace, sort.
 1.30.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.32.4.1 02-Aug-2025  perseant Sync with HEAD
 1.42 10-Nov-2024  riastradh scsictl(8): KNF

No functional change intended.
 1.41 09-Nov-2024  mlelstv Add 'identify vpd' to also report Vital Product Data that identifies the device.
 1.40 21-Aug-2022  mlelstv branches: 1.40.4;
Add REPORT_LUNS command.
 1.39 19-Nov-2016  flxd Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
 1.38 18-Oct-2014  snj branches: 1.38.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.37 12-Jan-2013  jakllsch branches: 1.37.8; 1.37.12;
We supply data with the FORMAT UNIT command, so tell the kernel which
direction it is to go (write).
 1.36 12-Jan-2013  jakllsch take sizeof actual symbol we are memsetting
 1.35 03-Nov-2012  jakllsch make a bunch of globals static
 1.34 03-Nov-2012  jakllsch drop write-only variable
 1.33 29-Aug-2011  joerg branches: 1.33.2; 1.33.4; 1.33.8;
Use __dead
 1.32 24-May-2011  joerg Decide on printing an int as int and not as short.
 1.31 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.30 02-Feb-2008  christos branches: 1.30.4; 1.30.6;
PR/37932: Yakovetsky Vladimir: build distribution with USE_FORT fails
fix buffer overflow
 1.29 22-Jan-2007  bouyer branches: 1.29.4; 1.29.6;
Kimura Fuyuki, bin/35216: add a setspeed command, to set the highest speed
that the optical drive should use for reading data.
 1.28 02-Jun-2005  lukem Ensure that "setcache <mode>" doesn't use random data for "byte2"
("setcache <mode> save" DTRT).
Found by gcc -Wuninitialized.

Appease other -Wuninitialized warnings.
 1.27 21-Feb-2005  thorpej branches: 1.27.2;
Part 1 of a cleanup pass over the SCSI subsystem. The aim is to name
everything "scsi_*", since we really are talking about the SCSI command
set, ATAPI transport not withstanding. Improve the names of many structures,
and prepend "SCSI_" onto all SCSI command opcodes. Place items described
by the SCSI Primary Commands document into scsi_spc.h.
 1.26 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.25 07-Jan-2005  ginsbach Add command to read the defect data from a direct access device.
 1.24 01-Jun-2004  fair Increase the SCSI command timeout for device start & stop from 10
to 30 seconds, per PR 25734. I've seen this problem myself. I think
that scsictl should:

1. accept a timeout flag/parameter to set the timeout to an arbitrary
value other than the default.

2. support a verbose mode that would report the timeout value before
the command is started, and then report how long the command actually
took to complete, though I suppose the latter could also be done
by using time(1).
 1.23 05-Jan-2004  jmmv branches: 1.23.2;
Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.22 01-Sep-2003  mycroft Add prevent/allow commands.
 1.21 01-Sep-2003  mycroft Add a flushcache command -- I need it for my DVD+RW.
 1.20 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.19 26-Sep-2002  petrov Added debug command to support SCIOCDEBUG.
 1.18 03-Sep-2002  thorpej * Add "getcache" and "setcache" commands to get/set basic cache
parameters (enables, really).
* Fix an error in the manpage.
* Shuffle some code to group things together better.
 1.17 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.16 26-Jun-2002  mjacob Add a bunch of stuff from Bob Nestor that fixes format to allow one to
specify device logical blocksize.

Furthermore, it also adds an 'immediate' option, which then sends more modern
devices into formatting in the background. scsictl still waits around and
sends a TEST UNIT READY every 10 seconds and, based upon the sense data
it gets back after the invariable CHECK CONDITION, prints out a progress
indicator (based upon SKSV progress in the sense data).

While we're at it, add a 'tur', 'reserve', 'release', 'start' and 'stop'
functions to the device commands.

Fix a long standing bug in scsi_command- the value in retsts is an integral
value- not a bitmask.
 1.15 14-Apr-2002  tsutsui branches: 1.15.2;
21600000 -> 6*60*60*1000 (timeout in six hours for format command)
 1.14 18-Jul-2001  bouyer Add and document a 'detach' command.
 1.13 15-May-2001  bouyer Adapt for MODE SENSE/SELECT changes in kernel.
 1.12 01-Apr-2001  ad Remove superfluous newlines in calls to errx().
 1.11 19-Feb-2001  cgd convert to use getprogname()
 1.10 27-Oct-1999  mycroft Increase the format timeout to 6 hours.
 1.9 04-Oct-1999  mycroft Make `reassign' actually work.
 1.8 28-Sep-1999  ad Make `all' a synonym for the `any' keyword.
 1.7 13-Aug-1999  mjl branches: 1.7.2;
Clarify usage message.
 1.6 30-Jul-1999  hubertf Collect all little usage-messages spread around into one place,
and as a side effect, print the available commands (and their
usage) if no command is given on the command line.

Approved by Jason Thorpe.
 1.5 24-Feb-1999  jwise Code to check if a cooked device was specified was failing even if the
cooked device was opened successfully. Also fix a typo.

Fixes second part of PR bin/6883 for Soren S. Jorvang <soren@t.dk>
 1.4 12-Nov-1998  thorpej Simple support for formatting a SCSI disk. This will be enhanced in
the near future.
 1.3 17-Oct-1998  thorpej Fix a thinko in the device opening code.
 1.2 15-Oct-1998  thorpej Fix a couple of usage strings.
 1.1 15-Oct-1998  thorpej scsictl(8) - a program to manipulate SCSI devices and busses. Currently
supports:

Devices: identify, reassign blocks, reset

Busses: reset, scan for devices

Coming soon, device formatting, mode page editing, device freeze/thaw, etc.
 1.7.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.2.1 28-Jul-2003  he Pull up revisions 1.16-1.18 (requested by thorpej in ticket #764):
Several changes/updates to scsictl:
o Allow specification of logical blocksize
o Add 'getcache' and 'setcache' commands
o Add 'tur', 'reserve', 'release', 'start', and 'stop' functions
o Add an 'immediate' option to do formatting in the background
o Fix bug in scsi_command -- value in resets is an int not a
bitmask
o Fix usage of errx() / warnx() and remove unneeded trailing \n
 1.23.2.1 01-Jun-2004  jmc Pullup rev 1.24 (requested by fair in ticket #431)

Increase the SCSI command timeout for device start & stop from 10
to 30 seconds. PR#25734
 1.27.2.1 14-Jun-2005  tron Pull up revision 1.28 (requested by lukem in ticket #402):
Ensure that "setcache <mode>" doesn't use random data for "byte2"
("setcache <mode> save" DTRT).
Found by gcc -Wuninitialized.
Appease other -Wuninitialized warnings.
 1.29.6.1 18-Feb-2008  mjf Sync with HEAD.
 1.29.4.1 23-Mar-2008  matt sync with HEAD
 1.30.6.1 18-May-2008  yamt sync with head.
 1.30.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.33.8.2 25-Feb-2013  tls resync with head
 1.33.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.33.4.1 15-Jan-2017  snj Pull up following revision(s) (requested by flxd in ticket #1418):
sbin/scsictl/scsictl.8: 1.27, 1.29, 1.30 via patch
sbin/scsictl/scsictl.c: revision 1.39 via patch
sys/dev/scsipi/scsi_disk.h: revision 1.32
Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit
supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
--
Bump date for previous.
--
Add crossreference to scsi(4) per note in PR 9627.
Whitespace, sort.
 1.33.2.2 23-Jan-2013  yamt sync with head
 1.33.2.1 16-Jan-2013  yamt sync with (a bit old) head
 1.37.12.1 18-Jan-2017  skrll Sync with netbsd-5
 1.37.8.1 03-Dec-2016  martin Pull up following revision(s) (requested by flxd in ticket #1276):
sys/dev/scsipi/scsi_disk.h: revision 1.32
sbin/scsictl/scsictl.8: revision 1.27-1.30
sbin/scsictl/scsictl.c: revision 1.39
Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit
supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
Bump date for previous.
Use more and more appropriate markup while here.
Add crossreference to scsi(4) per note in PR 9627.
Whitespace, sort.
 1.38.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.40.4.1 02-Aug-2025  perseant Sync with HEAD
 1.13 04-Jan-2012  drochner -consistently use "char *" for the compiled policy buffer in the
ipsec_*_policy() functions, as it was documented and used by clients
-remove "ipsec_policy_t" which was undocumented and only present
in the KAME version of the ipsec.h header
-misc cleanup of historical artefacts, and to remove unnecessary
differences between KAME ans FAST_IPSEC
 1.12 29-Oct-2009  christos branches: 1.12.6;
no need for noinput
 1.11 20-Apr-2009  drochner define YY_NO_INPUT where appropriate, from Kurt J. Lidl per PR misc/41160
 1.10 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.9 16-Dec-2005  jmc branches: 1.9.30;
Redo previous rework to generate yacc/lex output again and remove generated
copies from the import as they don't compile clean across all archs.
 1.8 15-Dec-2005  jmc Don't yacc/lex here as dist includes generated copies already and depending
on timestamps it's possible for gcc2 on vax to get confused on which .h
to use.
 1.7 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.6 24-Feb-2005  manu branches: 1.6.2;
Define SADB_X_EALG_AESCBC=SADB_X_EALG_AES, as we define SADB_X_EALG_AES
in <net/pfkeyv2.h> while ipsec-tools uses SADB_X_EALG_AESCBC in the code.
 1.5 19-Feb-2005  thorpej Additional cleanup pass.
 1.4 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.3 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.2 29-Oct-2000  itojun use YHEADER, not YFLAGS+=-d. from kre
 1.1 13-Jun-2000  itojun branches: 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file Makefile was added on branch minoura-xpg4dl on 2000-06-22 16:05:47 +0000
 1.6.2.1 03-Sep-2005  snj Apply patch (requested by tron in ticket #741):
Update ipsec-tools to version 0.6.1.
 1.9.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.12.6.1 17-Apr-2012  yamt sync with head
 1.18 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.17 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.16 29-Oct-2004  dsl Add (unsigned char) cast to ctype function, reworked to fit on one line
 1.15 25-Apr-2004  jonathan Initial commit of a port of the FreeBSD implementation of RFC 2385
(MD5 signatures for TCP, as used with BGP). Credit for original
FreeBSD code goes to Bruce M. Simpson, with FreeBSD sponsorship
credited to sentex.net. Shortening of the setsockopt() name
attributed to Vincent Jardin.

This commit is a minimal, working version of the FreeBSD code, as
MFC'ed to FreeBSD-4. It has received minimal testing with a ttcp
modified to set the TCP-MD5 option; BMS's additions to tcpdump-current
(tcpdump -M) confirm that the MD5 signatures are correct. Committed
as-is for further testing between a NetBSD BGP speaker (e.g., quagga)
and industry-standard BGP speakers (e.g., Cisco, Juniper).


NOTE: This version has two potential flaws. First, I do see any code
that verifies recieved TCP-MD5 signatures. Second, the TCP-MD5
options are internally padded and assumed to be 32-bit aligned. A more
space-efficient scheme is to pack all TCP options densely (and
possibly unaligned) into the TCP header ; then do one final padding to
a 4-byte boundary. Pre-existing comments note that accounting for
TCP-option space when we add SACK is yet to be done. For now, I'm
punting on that; we can solve it properly, in a way that will handle
SACK blocks, as a separate exercise.

In case a pullup to NetBSD-2 is requested, this adds sys/netipsec/xform_tcp.c
,and modifies:

sys/net/pfkeyv2.h,v 1.15
sys/netinet/files.netinet,v 1.5
sys/netinet/ip.h,v 1.25
sys/netinet/tcp.h,v 1.15
sys/netinet/tcp_input.c,v 1.200
sys/netinet/tcp_output.c,v 1.109
sys/netinet/tcp_subr.c,v 1.165
sys/netinet/tcp_usrreq.c,v 1.89
sys/netinet/tcp_var.h,v 1.109
sys/netipsec/files.netipsec,v 1.3
sys/netipsec/ipsec.c,v 1.11
sys/netipsec/ipsec.h,v 1.7
sys/netipsec/key.c,v 1.11
share/man/man4/tcp.4,v 1.16
lib/libipsec/pfkey.c,v 1.20
lib/libipsec/pfkey_dump.c,v 1.17
lib/libipsec/policy_token.l,v 1.8
sbin/setkey/parse.y,v 1.14
sbin/setkey/setkey.8,v 1.27
sbin/setkey/token.l,v 1.15

Note that the preceding two revisions to tcp.4 will be
required to cleanly apply this diff.
 1.14 12-Sep-2003  itojun support DUMP by sysctl
 1.13 07-Sep-2003  itojun committed by mistake
 1.12 07-Sep-2003  itojun warn that port-number does not work for gateway config. PR kern/22715
add reference. bump date.
 1.11 26-Jul-2003  mrg add another (void *) cast to appease gcc3.3
 1.10 01-Jul-2003  itojun more error traps on malloc failure. accept "-E null".
various pedantic checks. from kame
 1.9 06-Dec-2002  thorpej Avoid strict alias warnings.
 1.8 14-May-2002  itojun sync with latest kame setkey(8), modulo icmp6 hack.
pfkey.c is now more picky about buffer length validation.
spddump (setkey -DP) will print lifetime information.
 1.7 02-Nov-2001  lukem fix -Wshadow warnings
 1.6 20-Sep-2001  toshii Fix a typo which prevented manual keying from working.
 1.5 07-Sep-2001  itojun upgrade to the latest KAME setkey(8). allows FQDN hostname in commands.
"add localhost localhost esp 9999 -E des-cbc hogehoge" adds two keys,
for 127.0.0.1 and ::1
 1.4 16-Feb-2001  thorpej Add a "deleteall" command that takes a src/dst/protocol.
 1.3 04-Feb-2001  christos remove redundant decl
 1.2 18-Jul-2000  itojun sync with recent net/pfkeyv2.h change (sorry forgot to commit). from kame
 1.1 13-Jun-2000  itojun branches: 1.1.2; 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file parse.y was added on branch minoura-xpg4dl on 2000-06-22 16:05:47 +0000
 1.1.2.1 25-Jul-2000  itojun pullup 1.1 -> 1.2 (approved by releng-1-5)
sync with recent net/pfkeyv2.h change (sorry forgot to commit). from kame
 1.4 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.3 07-Sep-2001  itojun upgrade to the latest KAME setkey(8). allows FQDN hostname in commands.
"add localhost localhost esp 9999 -E des-cbc hogehoge" adds two keys,
for 127.0.0.1 and ::1
 1.2 14-Jun-2000  itojun branches: 1.2.4;
update examples, so that they would at least pass the parser.
 1.1 13-Jun-2000  itojun move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.2.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.2.4.1 14-Jun-2000  minoura file sample.cf was added on branch minoura-xpg4dl on 2000-06-22 16:05:48 +0000
 1.4 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.3 07-Sep-2001  itojun upgrade to the latest KAME setkey(8). allows FQDN hostname in commands.
"add localhost localhost esp 9999 -E des-cbc hogehoge" adds two keys,
for 127.0.0.1 and ::1
 1.2 18-Jul-2000  itojun sync with the current usage. from kame.

note th at the file will not be installed into locations like
/usr/sibn or /sbin.
 1.1 13-Jun-2000  itojun branches: 1.1.2; 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file scriptdump.pl was added on branch minoura-xpg4dl on 2000-06-22 16:05:49 +0000
 1.1.2.1 25-Jul-2000  itojun pullup 1.1 -> 1.2 (approved by releng-1-5)

sync with the current usage. from kame.

note that the file will not be installed into locations like
/usr/sbin or /sbin.
 1.30 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.29 29-Apr-2004  wiz Bump date for previous.
 1.28 25-Apr-2004  jonathan Initial commit of a port of the FreeBSD implementation of RFC 2385
(MD5 signatures for TCP, as used with BGP). Credit for original
FreeBSD code goes to Bruce M. Simpson, with FreeBSD sponsorship
credited to sentex.net. Shortening of the setsockopt() name
attributed to Vincent Jardin.

This commit is a minimal, working version of the FreeBSD code, as
MFC'ed to FreeBSD-4. It has received minimal testing with a ttcp
modified to set the TCP-MD5 option; BMS's additions to tcpdump-current
(tcpdump -M) confirm that the MD5 signatures are correct. Committed
as-is for further testing between a NetBSD BGP speaker (e.g., quagga)
and industry-standard BGP speakers (e.g., Cisco, Juniper).


NOTE: This version has two potential flaws. First, I do see any code
that verifies recieved TCP-MD5 signatures. Second, the TCP-MD5
options are internally padded and assumed to be 32-bit aligned. A more
space-efficient scheme is to pack all TCP options densely (and
possibly unaligned) into the TCP header ; then do one final padding to
a 4-byte boundary. Pre-existing comments note that accounting for
TCP-option space when we add SACK is yet to be done. For now, I'm
punting on that; we can solve it properly, in a way that will handle
SACK blocks, as a separate exercise.

In case a pullup to NetBSD-2 is requested, this adds sys/netipsec/xform_tcp.c
,and modifies:

sys/net/pfkeyv2.h,v 1.15
sys/netinet/files.netinet,v 1.5
sys/netinet/ip.h,v 1.25
sys/netinet/tcp.h,v 1.15
sys/netinet/tcp_input.c,v 1.200
sys/netinet/tcp_output.c,v 1.109
sys/netinet/tcp_subr.c,v 1.165
sys/netinet/tcp_usrreq.c,v 1.89
sys/netinet/tcp_var.h,v 1.109
sys/netipsec/files.netipsec,v 1.3
sys/netipsec/ipsec.c,v 1.11
sys/netipsec/ipsec.h,v 1.7
sys/netipsec/key.c,v 1.11
share/man/man4/tcp.4,v 1.16
lib/libipsec/pfkey.c,v 1.20
lib/libipsec/pfkey_dump.c,v 1.17
lib/libipsec/policy_token.l,v 1.8
sbin/setkey/parse.y,v 1.14
sbin/setkey/setkey.8,v 1.27
sbin/setkey/token.l,v 1.15

Note that the preceding two revisions to tcp.4 will be
required to cleanly apply this diff.
 1.27 21-Oct-2003  itojun aes-xcbc-mac is now an RFC. bump date.
 1.26 12-Sep-2003  itojun support DUMP by sysctl
 1.25 08-Sep-2003  wiz Punctuation nit; bump date for previous.
 1.24 08-Sep-2003  itojun make it possible to process files.
 1.23 07-Sep-2003  itojun "tagged" policy is not introduced to netbsd-current yet
 1.22 07-Sep-2003  itojun warn that port-number does not work for gateway config. PR kern/22715
add reference. bump date.
 1.21 25-Jul-2003  itojun support new algorithms
 1.20 22-Jul-2003  itojun support hmac-sha2
 1.19 04-Jul-2003  wiz Bump date for last.
 1.18 01-Jul-2003  itojun more error traps on malloc failure. accept "-E null".
various pedantic checks. from kame
 1.17 30-Jun-2003  wiz Remove unnecessary space before dot.
 1.16 27-May-2003  itojun correct bad RFC ref. KAME problem report 480
 1.15 15-Mar-2003  wiz Fix some typos. From Igor Sobrado in PR 20722.
 1.14 14-May-2002  itojun sync with latest kame setkey(8), modulo icmp6 hack.
pfkey.c is now more picky about buffer length validation.
spddump (setkey -DP) will print lifetime information.
 1.13 16-Nov-2001  wiz Slightly improve markup in two places, sort sections.
 1.12 16-Nov-2001  wiz Whitespace nits
 1.11 07-Sep-2001  itojun upgrade to the latest KAME setkey(8). allows FQDN hostname in commands.
"add localhost localhost esp 9999 -E des-cbc hogehoge" adds two keys,
for 127.0.0.1 and ::1
 1.10 16-Aug-2001  itojun we have never supported lzs. sync with kame
 1.9 12-Aug-2001  itojun sync with latest kame. clarifies hex key and other things.
 1.8 05-Jun-2001  wiz Drop trailing dot in Nd.
 1.7 16-Feb-2001  thorpej Add a "deleteall" command that takes a src/dst/protocol.
 1.6 15-Oct-2000  itojun have description on -v. sync with kame
 1.5 03-Oct-2000  itojun support rijndael-cbc.
 1.4 20-Sep-2000  gmcgarry Fix spelling.
 1.3 04-Sep-2000  kleink For commands and utilities, use EXIT STATUS rather than RETURN VALUES as
appropriate (and documented in mdoc(7)).
 1.2 01-Jul-2000  itojun mention resesrved SPI range, which is not usable from userland
 1.1 13-Jun-2000  itojun branches: 1.1.2; 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file setkey.8 was added on branch minoura-xpg4dl on 2000-06-22 16:05:49 +0000
 1.1.2.2 04-Oct-2000  itojun pullup (approved by releng-1-5)
rijndael-cbc userland support.

usr.sbin/netstat/ipsec.c 1.2 -> 1.3
sbin/setkey/setkey.8 1.4 -> 1.5
sbin/setkey/setkey.c 1.1 -> 1.2
sbin/setkey/token.l 1.2 -> 1.3
lib/libipsec/pfkey_dump.c 1.8 -> 1.9
usr.sbin/tcpdump/ipsec_doi.h 1.2 -> 1.3
usr.sbin/tcpdump/isakmp.h 1.3 -> 1.4
usr.sbin/tcpdump/print-isakmp.h 1.5 -> 1.6
 1.1.2.1 01-Jul-2000  itojun pullup 1.1 -> 1.2: (approved by: releng-1-5)
mention resesrved SPI range, which is not usable from userland
 1.14 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.13 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.12 23-Jul-2004  yamt ignore promiscuous messages by checking sadb_msg_pid.

ok'ed by itojun.
 1.11 12-Sep-2003  itojun support DUMP by sysctl
 1.10 08-Sep-2003  itojun make it possible to use /kern/ipsec{sp,sa} for dumping policy/SA. it will
workaround the issue with socket buffer size in PF_KEY SADB_DUMP.
 1.9 08-Sep-2003  wiz Add file ... mode to usage.
 1.8 08-Sep-2003  itojun make it possible to process files.
 1.7 01-Jul-2003  itojun more error traps on malloc failure. accept "-E null".
various pedantic checks. from kame
 1.6 15-Apr-2003  itojun use NI_MAX*. 10 is not enough for port number. sync w/kame
 1.5 07-Sep-2001  itojun upgrade to the latest KAME setkey(8). allows FQDN hostname in commands.
"add localhost localhost esp 9999 -E des-cbc hogehoge" adds two keys,
for 127.0.0.1 and ::1
 1.4 07-May-2001  kleink getopt(3): EOF -> -1.
 1.3 20-Dec-2000  cgd avoid use of ANSI C trigraph ??/
 1.2 03-Oct-2000  itojun support rijndael-cbc.
 1.1 13-Jun-2000  itojun branches: 1.1.2; 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file setkey.c was added on branch minoura-xpg4dl on 2000-06-22 16:05:50 +0000
 1.1.2.1 04-Oct-2000  itojun pullup (approved by releng-1-5)
rijndael-cbc userland support.

usr.sbin/netstat/ipsec.c 1.2 -> 1.3
sbin/setkey/setkey.8 1.4 -> 1.5
sbin/setkey/setkey.c 1.1 -> 1.2
sbin/setkey/token.l 1.2 -> 1.3
lib/libipsec/pfkey_dump.c 1.8 -> 1.9
usr.sbin/tcpdump/ipsec_doi.h 1.2 -> 1.3
usr.sbin/tcpdump/isakmp.h 1.3 -> 1.4
usr.sbin/tcpdump/print-isakmp.h 1.5 -> 1.6
 1.4 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.3 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.2 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.1 13-Jun-2000  itojun branches: 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file test-pfkey.c was added on branch minoura-xpg4dl on 2000-06-22 16:05:51 +0000
 1.3 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.2 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.1 13-Jun-2000  itojun branches: 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file test-policy.c was added on branch minoura-xpg4dl on 2000-06-22 16:05:51 +0000
 1.18 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.17 17-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.16 25-Apr-2004  jonathan Initial commit of a port of the FreeBSD implementation of RFC 2385
(MD5 signatures for TCP, as used with BGP). Credit for original
FreeBSD code goes to Bruce M. Simpson, with FreeBSD sponsorship
credited to sentex.net. Shortening of the setsockopt() name
attributed to Vincent Jardin.

This commit is a minimal, working version of the FreeBSD code, as
MFC'ed to FreeBSD-4. It has received minimal testing with a ttcp
modified to set the TCP-MD5 option; BMS's additions to tcpdump-current
(tcpdump -M) confirm that the MD5 signatures are correct. Committed
as-is for further testing between a NetBSD BGP speaker (e.g., quagga)
and industry-standard BGP speakers (e.g., Cisco, Juniper).


NOTE: This version has two potential flaws. First, I do see any code
that verifies recieved TCP-MD5 signatures. Second, the TCP-MD5
options are internally padded and assumed to be 32-bit aligned. A more
space-efficient scheme is to pack all TCP options densely (and
possibly unaligned) into the TCP header ; then do one final padding to
a 4-byte boundary. Pre-existing comments note that accounting for
TCP-option space when we add SACK is yet to be done. For now, I'm
punting on that; we can solve it properly, in a way that will handle
SACK blocks, as a separate exercise.

In case a pullup to NetBSD-2 is requested, this adds sys/netipsec/xform_tcp.c
,and modifies:

sys/net/pfkeyv2.h,v 1.15
sys/netinet/files.netinet,v 1.5
sys/netinet/ip.h,v 1.25
sys/netinet/tcp.h,v 1.15
sys/netinet/tcp_input.c,v 1.200
sys/netinet/tcp_output.c,v 1.109
sys/netinet/tcp_subr.c,v 1.165
sys/netinet/tcp_usrreq.c,v 1.89
sys/netinet/tcp_var.h,v 1.109
sys/netipsec/files.netipsec,v 1.3
sys/netipsec/ipsec.c,v 1.11
sys/netipsec/ipsec.h,v 1.7
sys/netipsec/key.c,v 1.11
share/man/man4/tcp.4,v 1.16
lib/libipsec/pfkey.c,v 1.20
lib/libipsec/pfkey_dump.c,v 1.17
lib/libipsec/policy_token.l,v 1.8
sbin/setkey/parse.y,v 1.14
sbin/setkey/setkey.8,v 1.27
sbin/setkey/token.l,v 1.15

Note that the preceding two revisions to tcp.4 will be
required to cleanly apply this diff.
 1.15 21-Oct-2003  fvdl Don't assign NULL to a char.
 1.14 12-Sep-2003  itojun support DUMP by sysctl
 1.13 07-Sep-2003  itojun committed by mistake
 1.12 07-Sep-2003  itojun warn that port-number does not work for gateway config. PR kern/22715
add reference. bump date.
 1.11 25-Jul-2003  itojun support new algorithms
 1.10 22-Jul-2003  itojun cleanup
 1.9 01-Jul-2003  itojun more error traps on malloc failure. accept "-E null".
various pedantic checks. from kame
 1.8 22-May-2003  itojun permit scoped addr notation in policy string (-P esp/tunnel/foo%scope-bar%scope/use). from francis dupont. sync w/kame
 1.7 14-May-2002  itojun sync with latest kame setkey(8), modulo icmp6 hack.
pfkey.c is now more picky about buffer length validation.
spddump (setkey -DP) will print lifetime information.
 1.6 07-Sep-2001  itojun upgrade to the latest KAME setkey(8). allows FQDN hostname in commands.
"add localhost localhost esp 9999 -E des-cbc hogehoge" adds two keys,
for 127.0.0.1 and ::1
 1.5 16-Feb-2001  thorpej Add a "deleteall" command that takes a src/dst/protocol.
 1.4 29-Oct-2000  itojun use YHEADER, not YFLAGS+=-d. from kre
 1.3 03-Oct-2000  itojun support rijndael-cbc.
 1.2 18-Jul-2000  itojun sync with recent net/pfkeyv2.h change (sorry forgot to commit). from kame
 1.1 13-Jun-2000  itojun branches: 1.1.2; 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file token.l was added on branch minoura-xpg4dl on 2000-06-22 16:05:52 +0000
 1.1.2.2 04-Oct-2000  itojun pullup (approved by releng-1-5)
rijndael-cbc userland support.

usr.sbin/netstat/ipsec.c 1.2 -> 1.3
sbin/setkey/setkey.8 1.4 -> 1.5
sbin/setkey/setkey.c 1.1 -> 1.2
sbin/setkey/token.l 1.2 -> 1.3
lib/libipsec/pfkey_dump.c 1.8 -> 1.9
usr.sbin/tcpdump/ipsec_doi.h 1.2 -> 1.3
usr.sbin/tcpdump/isakmp.h 1.3 -> 1.4
usr.sbin/tcpdump/print-isakmp.h 1.5 -> 1.6
 1.1.2.1 25-Jul-2000  itojun pullup 1.1 -> 1.2 (approved by releng-1-5)
sync with recent net/pfkeyv2.h change (sorry forgot to commit). from kame
 1.2 19-Feb-2005  thorpej Switch to ipsec-tools for libipsec, setkey, and racoon. From
Emmanuel Dreyfus, with some small changes by me.
 1.1 13-Jun-2000  itojun branches: 1.1.4;
move setkey(8) from usr.sbin to sbin, to enable us to initialize
IPsec manual key before /usr mount..
(based on "don't use cvsmove" discussion i have seen, I did not use cvsmove)
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 13-Jun-2000  minoura file vchar.h was added on branch minoura-xpg4dl on 2000-06-22 16:05:52 +0000
 1.11 11-Apr-2009  lukem Enable WARNS=4 by default except for:
dump dump_lfs fsck_ffs fsck_lfs fsdb mount_smbfs
newfs_ext2fs newfs_lfs resize_lfs setkey
 1.10 28-May-2007  tls branches: 1.10.22;
Add new Makefile knob, USE_FORT, which extends USE_SSP by turning on the
FORTIFY_SOURCE feature of libssp, thus checking the size of arguments to
various string and memory copy and set functions (as well as a few system
calls and other miscellany) where known at function entry. RedHat has
evidently built all "core system packages" with this option for some time.

This option should be used at the top of Makefiles (or Makefile.inc where
this is used for subdirectories) but after any setting of LIB.

This is only useful for userland code, and cannot be used in libc or in
any code which includes the libc internals, because it overrides certain
libc functions with macros. Some effort has been made to make USE_FORT=yes
work correctly for a full-system build by having the bsd.sys.mk logic
disable the feature where it should not be used (libc, libssp iteself,
the kernel) but no attempt has been made to build the entire system with
USE_FORT and doing so will doubtless expose numerous bugs and misfeatures.

Adjust the system build so that all programs and libraries that are setuid,
directly handle network data (including serial comm data), perform
authentication, or appear likely to have (or have a history of having)
data-driven bugs (e.g. file(1)) are built with USE_FORT=yes by default,
with the exception of libc, which cannot use USE_FORT and thus uses
only USE_SSP by default. Tested on i386 with no ill results; USE_FORT=no
per-directory or in a system build will disable if desired.
 1.9 14-Mar-2007  christos - sprinkle static
- pass WARNS=4 and lint
- use size_t/time_t where appropriate
- get/setprogname()
- before executing rc.shutdown, set the real user id to 0, because shutdown
scripts may depend on it (for example su depends on being root).
- use warn instead of perror, and make sure we use the right errno.
 1.8 11-Oct-1997  mycroft branches: 1.8.20; 1.8.30; 1.8.32;
Make these executables world-readable.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 17-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 31-Jul-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 17-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.32.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.8.30.1 17-Jul-2007  liamjfoy Pull up following revision(s) (requested by jnemeth in ticket #771):
sbin/shutdown/Makefile: revision 1.9
sbin/shutdown/shutdown.c: revision 1.47
sbin/shutdown/shutdown.c: revision 1.48
- sprinkle static
- pass WARNS=4 and lint
- use size_t/time_t where appropriate
- get/setprogname()
- before executing rc.shutdown, set the real user id to 0, because shutdown
scripts may depend on it (for example su depends on being root).
- use warn instead of perror, and make sure we use the right errno.

PR/36626 - Jukka Salmi -- fails to compile if DEBUG is defined
 1.8.20.1 30-May-2009  snj Pull up following revision(s) (requested by jnemeth in ticket #2019):
sbin/shutdown/Makefile: revision 1.9
sbin/shutdown/shutdown.c: revision 1.45-1.48
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
PR/31531: Takahiro Kambe: shutdown(8) quietly exit if execed from login shell
- sprinkle static
- pass WARNS=4 and lint
- use size_t/time_t where appropriate
- get/setprogname()
- before executing rc.shutdown, set the real user id to 0, because shutdown
scripts may depend on it (for example su depends on being root).
- use warn instead of perror, and make sure we use the right errno.
PR/36626 - Jukka Salmi -- fails to compile if DEBUG is defined
 1.10.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.9 19-Aug-2004  christos Deal with RESCUEDIR
 1.8 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.7 29-Oct-1998  bad Run /etc/rc.shutdown when the final shutdown time has come.

Thanks to Ted Lemon for helping with my English.
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 17-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 17-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.38 15-Feb-2023  uwe shutdown(8): markup fixes
 1.37 15-Feb-2023  uwe shutdown(8): fix -width cargo cult
 1.36 15-Feb-2023  jschauma adjust width of flag arg to align more nicely
 1.35 01-Jul-2022  wiz Fix At argument and remove superfluous Pp.
 1.34 01-Jul-2022  kre Bring shutdown(8) into the 21st century.

I found this juxtaposition in the shutdown man page kind of
interesting:

time Time is the time at which shutdown will bring the system down
and may be the word now or a future time in one of two formats:
... [2nd format:] [[[[[cc]yy]mm]dd]hh]mm, ...
If the century [cc] is not specified, it defaults to 1900 for
years [yy] between 69 and 99, ...

In that, all the "[text]" except the one "[[[[["(etc) sequence are my
interjections, The ellipses ("...") represent where I omitted irrelevant
(for here) text.

Interesting yes, bizarre also. Requiring a future time, and then
defaulting to the (long gone) 20th century (for any random year)
makes no sense at all. So I fixed it.

In another hundred years or so, anytime from 2100 onwards, but best
left at least a decade into the new century, it will need altering again.
[One could write the code to automate this adjustment, but the man
page would still need updating.] More significant changes will be
needed as the 101st century approaches (years 10000 and beyond), as
then a 2 digit century will no longer be adequate. Call me then, and
if I'm able, I'll fix it.

If someone really has a need to schedule a shutdown for sometime
between 1969 and 1999 that can still be done by explicitly giving
the "19" cc value. It is just no longer ever the default.

Otherwise, now, years 20..90 mean the 21st century (2020..2099)
(the first 2 of those are already unusable, but, IMO, that's OK)
and years 00..19 mean the 22nd century (2100..2119) (except that
00, 2100, is still technically the final year of the 21st century).

This is advance planning for near the end of the 21st century when
someone wants to schedule a shutdown for early in the following
century, and can't be bothered typing the 2 century digits.
 1.33 14-Sep-2016  kre Update the history, shutdown was first in 4.1 BSD (and existed earlier).
Ride date bump for previous update.
 1.32 12-Sep-2016  sevan shutdown appeared as a standalone utility in 4.2BSD release, in 4BSD its a
target in init.
http://www.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/src/cmd/init.c
http://www.tuhs.org/cgi-bin/utree.pl?file=4.2BSD/usr/src/etc/shutdown.c

Amend HISTORY.
Bump date.
 1.31 04-Oct-2011  dholland Fix thinko about halt vs. poweroff; from Moritz Wilhelmy in PR 45141.
 1.30 16-Feb-2011  wiz Add -vxz to SYNOPSIS. Sort.
 1.29 16-Feb-2011  dyoung Add flags -v, -x, and -z for verbose, debug, and silent shutdowns,
respectively, by passing flags AB_VERBOSE, AB_DEBUG, and/or AB_SILENT to
reboot(2).
 1.28 21-Oct-2008  lukem branches: 1.28.14;
xref rescue(8)
 1.27 09-Feb-2008  dholland branches: 1.27.4;
Improvements and clarifications to log messages and also to the man page.
Partially cherry-picked from or inspired by PR bin/36551 by Greg A. Woods,
plus some additional grammar/usage/clarity adjustments while I was passing
through. Any mistakes are mine.
 1.26 07-Aug-2003  agc branches: 1.26.22; 1.26.24;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.25 30-Jun-2003  wiz Add Ns.
 1.24 18-Oct-2002  wiz New sentence, new line in last. Bump date for last.
 1.23 18-Oct-2002  atatat Add "-b bootstr" for shutdown to pass to reboot(8), so that shutdown
(which runs rc.shutdown, which might do stuff like, say, save your
ipnat or ipf state for restoration on reboot) can tell machines (sparc
and sun3 machines presently) how to boot.
 1.22 16-Nov-2001  wiz Whitespace nits
 1.21 17-Oct-2000  wiz change mentioning of `login' to a .Xr in one place
 1.20 25-Jul-2000  jdolecek backoff rev 1.18 & 1.19 - it's made obsolete by last rc.d changes and using
arbitrary hard time limit for /etc/rc.shutdown is not right anyway
 1.19 20-Jul-2000  jdolecek fix synopsis line so that the -T syntax is right
 1.18 20-Jul-2000  jdolecek when running /etc/rc.shutdown, don't wait on it until it completes
indefinitely - by default, wait maximum of 300 seconds only
the timeout is settable via new -T flag
Adjust history to mention addition of shutdown hooks and -T option on manpage,
also move description of -D further up and slighly adjust.

This fixes bin/10637.
 1.17 29-Oct-1998  bad branches: 1.17.10;
Run /etc/rc.shutdown when the final shutdown time has come.

Thanks to Ted Lemon for helping with my English.
 1.16 29-Oct-1998  bad Delete redundant "the".
 1.15 09-Oct-1998  enami Sort options in SYNOPSIS alphabetically.
 1.14 06-Jun-1998  thorpej Add a -p option, to power down the system at the specified time.
 1.13 29-Apr-1998  fair fix bad .Xr references
 1.12 23-Mar-1998  fair add -D (no detach) option, per PR#4810
 1.11 20-Jan-1998  mycroft Document previous changes.
 1.10 20-Jan-1998  perry make Y2K compliant and document as such.
 1.9 16-Sep-1997  lukem branches: 1.9.2;
resolve conflicts from lite-2 merge
 1.8 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* fix .Nm usage
 1.7 09-Jul-1997  jtk add -d option to shutdown, as companion to reboot's -d flag (force crash dump)
 1.6 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.5 17-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 17-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.2.1 29-Jan-1998  mellon Pull up 1.10 and 1.11 (mycroft)
 1.17.10.2 25-Jul-2000  jdolecek pullup rev 1.20 from trunk (approved by thorpej):
backoff rev. 1.17.10.1 - it's made obsolete by last rc.d changes and using
arbitrary hard time limit for /etc/rc.shutdown is not right anyway
 1.17.10.1 20-Jul-2000  jdolecek pullup from trunk (approved by thorpej):
wait only finite time for completition of /etc/rc.shutdown - default is
300 seconds, that value is adjustable by new -T flag
Mention addition of shutdown hooks and -T option in HISTORY, slighly adjust
also description of -D flag and move it where it alhabetically belongs.

This fixes bin/10637.
 1.26.24.1 18-Feb-2008  mjf Sync with HEAD.
 1.26.22.1 23-Mar-2008  matt sync with HEAD
 1.27.4.1 17-Jan-2009  mjf Sync with HEAD.
 1.28.14.1 17-Feb-2011  bouyer Sync with HEAD
 1.59 07-Dec-2024  martin As discussed on tech-userlevel: pass a "what" argument to /etc/rc.shutdown
describing why we are shutting down. This allows e.g. for UPS actions
if we are powering down.
 1.58 01-Jul-2022  kre branches: 1.58.4;
Bring shutdown(8) into the 21st century.

I found this juxtaposition in the shutdown man page kind of
interesting:

time Time is the time at which shutdown will bring the system down
and may be the word now or a future time in one of two formats:
... [2nd format:] [[[[[cc]yy]mm]dd]hh]mm, ...
If the century [cc] is not specified, it defaults to 1900 for
years [yy] between 69 and 99, ...

In that, all the "[text]" except the one "[[[[["(etc) sequence are my
interjections, The ellipses ("...") represent where I omitted irrelevant
(for here) text.

Interesting yes, bizarre also. Requiring a future time, and then
defaulting to the (long gone) 20th century (for any random year)
makes no sense at all. So I fixed it.

In another hundred years or so, anytime from 2100 onwards, but best
left at least a decade into the new century, it will need altering again.
[One could write the code to automate this adjustment, but the man
page would still need updating.] More significant changes will be
needed as the 101st century approaches (years 10000 and beyond), as
then a 2 digit century will no longer be adequate. Call me then, and
if I'm able, I'll fix it.

If someone really has a need to schedule a shutdown for sometime
between 1969 and 1999 that can still be done by explicitly giving
the "19" cc value. It is just no longer ever the default.

Otherwise, now, years 20..90 mean the 21st century (2020..2099)
(the first 2 of those are already unusable, but, IMO, that's OK)
and years 00..19 mean the 22nd century (2100..2119) (except that
00, 2100, is still technically the final year of the 21st century).

This is advance planning for near the end of the 21st century when
someone wants to schedule a shutdown for early in the following
century, and can't be bothered typing the 2 century digits.
 1.57 07-Aug-2017  uwe Use NULL instead of 0 for null pointer.
 1.56 28-Mar-2014  apb When the third arg to fwrite() is a size in bytes, then the second arg
should be 1. sizeof(*mbuf) happens to equal 1, but it's better not
to rely on that.
 1.55 27-Aug-2011  joerg branches: 1.55.2; 1.55.8;
statc + __dead
 1.54 16-Feb-2011  wiz Add -b and -vxz to usage.
 1.53 16-Feb-2011  dyoung Add flags -v, -x, and -z for verbose, debug, and silent shutdowns,
respectively, by passing flags AB_VERBOSE, AB_DEBUG, and/or AB_SILENT to
reboot(2).
 1.52 09-Jun-2010  riz branches: 1.52.2;
Remove _PATH_NOLOGIN before reboot, as well as before exit(), to prevent
a root file system which has been marked read-only in fstab from continuing
to prevent logins after reboot. From Ian D. Leroux in PR#43390.
 1.51 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.50 09-Feb-2008  dholland branches: 1.50.4; 1.50.8;
Improvements and clarifications to log messages and also to the man page.
Partially cherry-picked from or inspired by PR bin/36551 by Greg A. Woods,
plus some additional grammar/usage/clarity adjustments while I was passing
through. Any mistakes are mine.
 1.49 15-Dec-2007  perry convert __attribute__s to applicable cdefs.h macros
 1.48 10-Jul-2007  jnemeth branches: 1.48.4; 1.48.6;
PR/36626 - Jukka Salmi -- fails to compile if DEBUG is defined
 1.47 14-Mar-2007  christos - sprinkle static
- pass WARNS=4 and lint
- use size_t/time_t where appropriate
- get/setprogname()
- before executing rc.shutdown, set the real user id to 0, because shutdown
scripts may depend on it (for example su depends on being root).
- use warn instead of perror, and make sure we use the right errno.
 1.46 07-Mar-2006  jnemeth branches: 1.46.4; 1.46.6;
PR/31531: Takahiro Kambe: shutdown(8) quietly exit if execed from login shell
 1.45 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.44 05-Feb-2005  xtraeme branches: 1.44.2;
Finish previous (use ANSI function declarations) this time.
 1.43 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations.
 1.42 05-Nov-2004  dsl Add (unsigned char) cast to ctype functions
 1.41 09-Oct-2004  dsainty Comment typo: unecessary->unnecessary
 1.40 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.39 18-Oct-2002  atatat Add "-b bootstr" for shutdown to pass to reboot(8), so that shutdown
(which runs rc.shutdown, which might do stuff like, say, save your
ipnat or ipf state for restoration on reboot) can tell machines (sparc
and sun3 machines presently) how to boot.
 1.38 20-Dec-2000  cgd __CONCAT does token pasting, not string concatnation. if something like:
__CONCAT("foo","bar");
actually works to concantate strings, it's because the preprocessor expands
it into "foo""bar" as separate strings, and then ANSI string concatenation
is performed on that. It's more straightforward to just use ANSI string
concatenation directly, and newer GCCs complain (rightly) about misuse
of token pasting.
 1.37 25-Jul-2000  jdolecek backoff rev 1.36 - it's made obsolete by last rc.d changes and using
arbitrary hard time limit for /etc/rc.shutdown is not right anyway
 1.36 20-Jul-2000  jdolecek when running /etc/rc.shutdown, don't want on it until it completes
indefinitely - by default, wait maximum of 300 seconds only
the timeout is settable via new -T flag
Adjust history to mention addition of shutdown hooks and -T option on manpage

This fixes bin/10637.
 1.35 31-Oct-1999  is branches: 1.35.6;
exect->execve.
During my investigation, no reason could be found to enable tracing.
Fixes PR 7782 by Christoph Martin.
 1.34 22-Nov-1998  bad branches: 1.34.4;
testo. We want to source /etc/rc.shutdown.

Fixes PR #6474.
 1.33 29-Oct-1998  bad Run /etc/rc.shutdown when the final shutdown time has come.

Thanks to Ted Lemon for helping with my English.
 1.32 09-Oct-1998  enami Initialize the global variable `shuttime' with current time when
user requested to shutdown now, so that correct time is written in
/etc/nologin.
 1.31 09-Oct-1998  enami Add -p option in usage.
 1.30 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.29 26-Jul-1998  mycroft const poisoning.
 1.28 05-Jul-1998  mrg KNF. ensure hostname is nul-terminated
 1.27 06-Jun-1998  thorpej Add a -p option, to power down the system at the specified time.
 1.26 01-Apr-1998  kleink Need <time.h> for ctime(), time(), localtime() and mktime() prototypes.
 1.25 23-Mar-1998  fair add -D (no detach) option, per PR#4810
 1.24 21-Jan-1998  mycroft Oops; remove DEBUG.
 1.23 21-Jan-1998  mycroft Slight code rearrangement.
 1.22 20-Jan-1998  mycroft Document previous changes.
 1.21 20-Jan-1998  mycroft Recognize `-' only if it is the only argument after the time.
 1.20 20-Jan-1998  mycroft Allow `-dh'. Rearrange a bit.
 1.19 20-Jan-1998  mycroft Use err*(3) and warn*(3). Fix reading of the message from stdin.
 1.18 20-Jan-1998  mycroft Allow a century to be specified.
Don't validate the mmddhhmm values; mktime(3) does it.
 1.17 20-Jan-1998  perry make Y2K compliant and document as such.
 1.16 01-Oct-1997  enami branches: 1.16.2;
Don't delcare optind.
 1.15 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.14 15-Sep-1997  lukem * cleanup for WARNS=1
* deprecate register
* fix .Nm usage
 1.13 10-Jul-1997  mikel cleanup for gcc -Wall
 1.12 09-Jul-1997  jtk add -d option to shutdown, as companion to reboot's -d flag (force crash dump)
 1.11 23-Jan-1997  mikel eliminate possibility that execle() will be called with one too many
arguments.
 1.10 11-Dec-1996  thorpej After passing the terminating NULL for the argv list to execle(),
don't forget the (NULL) envp.
From Lennart Augustsson <augustss@cs.chalmers.se>, PR #2737.
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.7 17-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.6 17-Sep-1994  mycroft Don't remove /etc/nologin if `-k' was used.
 1.5 16-Feb-1994  cgd when warning, actually warn about the correct thing!
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 17-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.2.1 29-Jan-1998  mellon Pull up 1.17-1.24 (mycroft)
 1.34.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.35.6.2 25-Jul-2000  jdolecek pullup rev 1.37 from trunk (approved by thorpej):
backoff rev. 1.35.6.1 - it's made obsolete by last rc.d changes and using
arbitrary hard time limit for /etc/rc.shutdown is not right anyway
 1.35.6.1 20-Jul-2000  jdolecek pullup from trunk (approved by thorpej):
wait only finite time for completition of /etc/rc.shutdown - default is
300 seconds, that value is adjustable by new -T flag
Mention addition of shutdown hooks and -T option in HISTORY, slighly adjust
also description of -D flag and move it where it alhabetically belongs.

This fixes bin/10637.
 1.44.2.1 30-May-2009  snj Pull up following revision(s) (requested by jnemeth in ticket #2019):
sbin/shutdown/Makefile: revision 1.9
sbin/shutdown/shutdown.c: revision 1.45-1.48
Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
PR/31531: Takahiro Kambe: shutdown(8) quietly exit if execed from login shell
- sprinkle static
- pass WARNS=4 and lint
- use size_t/time_t where appropriate
- get/setprogname()
- before executing rc.shutdown, set the real user id to 0, because shutdown
scripts may depend on it (for example su depends on being root).
- use warn instead of perror, and make sure we use the right errno.
PR/36626 - Jukka Salmi -- fails to compile if DEBUG is defined
 1.46.6.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.46.4.1 17-Jul-2007  liamjfoy Pull up following revision(s) (requested by jnemeth in ticket #771):
sbin/shutdown/Makefile: revision 1.9
sbin/shutdown/shutdown.c: revision 1.47
sbin/shutdown/shutdown.c: revision 1.48
- sprinkle static
- pass WARNS=4 and lint
- use size_t/time_t where appropriate
- get/setprogname()
- before executing rc.shutdown, set the real user id to 0, because shutdown
scripts may depend on it (for example su depends on being root).
- use warn instead of perror, and make sure we use the right errno.

PR/36626 - Jukka Salmi -- fails to compile if DEBUG is defined
 1.48.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.48.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.48.4.2 23-Mar-2008  matt sync with HEAD
 1.48.4.1 09-Jan-2008  matt sync with HEAD
 1.50.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.50.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.52.2.1 17-Feb-2011  bouyer Sync with HEAD
 1.55.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.55.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.58.4.1 02-Aug-2025  perseant Sync with HEAD
 1.10 08-Jul-2006  tsutsui Misc fixes for sl(4) and slattach(8) man pages:
- note that ifconfig(8) create subcommand is required before slattach(8)
- network addresses aren't defined by slattach(8) but ifconfig(8)
- Add a BUGS section in slattach(8) to note that currently there is no way to
specify/see an interface name to be attached
- move description about link[0-2] flags from slattach(8) to sl(4)
(rather than adding a new description...)
- move description about SLIP limitations to a new BUGS section in sl(4)
- remove inappropriate MLINKS of slip.8 to slattach.8
- create MLINKS of slip.4 to sl.4 instead
- add some more xrefs

Ok'ed by christos, and closes PR kern/33672 and PR bin/33923.
 1.9 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.8 05-Feb-2005  xtraeme Kill __P(), use ANSI function declarations; WARNS=3.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.4 31-Jul-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.30 19-Jan-2020  thorpej Remove the strip(4) - Starmode Radio IP - pseudo-device driver. It is
long since obsolete.
 1.29 12-Nov-2018  christos Improve examples and netmask information (from Dan Plassche)
 1.28 08-Jul-2006  tsutsui branches: 1.28.84; 1.28.86;
Misc fixes for sl(4) and slattach(8) man pages:
- note that ifconfig(8) create subcommand is required before slattach(8)
- network addresses aren't defined by slattach(8) but ifconfig(8)
- Add a BUGS section in slattach(8) to note that currently there is no way to
specify/see an interface name to be attached
- move description about link[0-2] flags from slattach(8) to sl(4)
(rather than adding a new description...)
- move description about SLIP limitations to a new BUGS section in sl(4)
- remove inappropriate MLINKS of slip.8 to slattach.8
- create MLINKS of slip.4 to sl.4 instead
- add some more xrefs

Ok'ed by christos, and closes PR kern/33672 and PR bin/33923.
 1.27 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.26 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.25 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.24 05-Dec-2001  wiz Sort options. Improve english in DIAGNOSTICS.
[Pointed at this file by augustss.]
 1.23 05-Jun-2001  wiz Drop arguments of .Os.
 1.22 12-Sep-1999  kleink Use full month names with .Dd, as per mdoc.samples(7).
 1.21 03-Sep-1999  proff -n don't detach from tty
 1.20 19-Mar-1999  tron Add "-l" to "SYNOPSIS" section and use same order as "slattach" when
printing command line usage.
 1.19 23-Mar-1998  fair add the ability to run SLIP with CLOCAL set, per PR#3586
 1.18 04-Dec-1997  msaitoh Fix SYNOPSIS section.
 1.17 17-Nov-1997  thorpej Document the STRIP-related options.
 1.16 11-Nov-1997  mrg add missing .Nm sections.
 1.15 20-Oct-1997  scottr branches: 1.15.2;
Add support for DTR/CTS flow control, from Bill Studenmund.
 1.14 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
* deprecate register
 1.13 10-Aug-1996  explorer Reference the new sl(4) page
 1.12 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.11 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.10 13-Aug-1994  mycroft Don't capitalize program name in SYNOPSIS.
 1.9 13-Aug-1994  mycroft Document what link[0-2] do.
 1.8 01-Apr-1994  cgd branches: 1.8.2;
fix type, from Mark Weaver
 1.7 10-Dec-1993  cgd deal with change in setting of slip params
 1.6 02-Dec-1993  mycroft From: Ian McDonnell <imcd@apriori.demon.co.uk>
* Initialize termios struct before using it, from the current tty settings.
* Set speed earlier. (This, combined with the above, was causing DTR to be
dropped briefly on startup.)
* Add `-m' option to avoid using HUPCL.
Also:
* Remove findspeed() altogether, as we don't need it and it's ugly.
* Use tcgetattr() and tcsetattr() rather than TIOCGETA and TIOCSETA. The
former is POSIX; the latter is not.
 1.5 01-Aug-1993  mycroft Add RCS indentifiers.
 1.4 08-Apr-1993  cgd patched w/changes from blymn@mulga.awadi.com.AU (Brett Lymn) to
fix things like flow control support, SLIP option support etc.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.2.2 13-Aug-1994  mycroft update from trunk
 1.8.2.1 13-Aug-1994  mycroft update from trunk
 1.15.2.2 17-Nov-1997  thorpej Sync w/ trunk.
 1.15.2.1 11-Nov-1997  mrg pull up from trunk: add missing .Nm sections.
 1.28.86.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.86.1 10-Jun-2019  christos Sync with HEAD
 1.28.84.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.33 20-Oct-2013  mbalmer attach tty line discipline by name, not by number. remove unused case value. lgtm christos
 1.32 30-Dec-2011  christos branches: 1.32.6;
PR/45759: Khanh-Dang Nguyen Thu Lam: slattach(8) is not compatible with
pseudo-terminals. Fixed by ignoring the error for the DTR ioctl.
 1.31 27-Aug-2011  joerg branches: 1.31.2;
static + __dead
 1.30 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.29 05-Feb-2005  xtraeme branches: 1.29.26; 1.29.30;
Kill __P(), use ANSI function declarations; WARNS=3.
 1.28 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.27 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.26 16-Jan-2003  kleink Rename `sigset' locals to avoid symbol shadowing warning.
 1.25 20-Dec-2001  soren Sync getopt() / man page with actual getopt options.
 1.24 19-Feb-2001  cgd convert to use getprogname()
 1.23 04-Feb-2001  christos fix nested extern
 1.22 03-Sep-1999  proff use daemon(3) instead of vanilla fork()
use err(3) instead of perror..exit
add new flag: -n don't detach from tty
 1.21 23-Mar-1998  fair add the ability to run SLIP with CLOCAL set, per PR#3586
 1.20 17-Nov-1997  thorpej Cosmetic changes.
 1.19 20-Oct-1997  scottr branches: 1.19.2;
Add support for DTR/CTS flow control, from Bill Studenmund.
 1.18 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
* deprecate register
 1.17 19-May-1996  jonathan Support attaching a STRIP line via the "-t strip" flag.
It has been suggested that a separate "stattach" command would be better.
 1.16 21-Mar-1995  mycroft Use POSIX signals.
 1.15 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.14 18-Dec-1994  cgd -Wall cleanups from Jim Jegers
 1.13 31-Oct-1994  cgd pull in string.h
 1.12 23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.11 10-Feb-1994  cgd oops; last patch to slattach should have been to sliplogin!
 1.10 10-Feb-1994  cgd update for slip.h
 1.9 10-Dec-1993  cgd deal with change in setting of slip params
 1.8 02-Dec-1993  mycroft From: Ian McDonnell <imcd@apriori.demon.co.uk>
* Initialize termios struct before using it, from the current tty settings.
* Set speed earlier. (This, combined with the above, was causing DTR to be
dropped briefly on startup.)
* Add `-m' option to avoid using HUPCL.
Also:
* Remove findspeed() altogether, as we don't need it and it's ugly.
* Use tcgetattr() and tcsetattr() rather than TIOCGETA and TIOCSETA. The
former is POSIX; the latter is not.
 1.7 01-Aug-1993  mycroft Add RCS identifiers.
 1.6 29-Jun-1993  brezak Support 38400, 57600, and 115200 tty speeds.
 1.5 28-Apr-1993  cgd fixed:
SLATTACH hangs up on connect to modem port
reported by: bugs@rafal.slip.uiuc.edu
 1.4 08-Apr-1993  cgd patched w/changes from blymn@mulga.awadi.com.AU (Brett Lymn) to
fix things like flow control support, SLIP option support etc.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 23-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.19.2.1 17-Nov-1997  thorpej Sync w/ trunk.
 1.29.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.29.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.31.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.31.2.1 17-Apr-2012  yamt sync with head
 1.32.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1 29-Jun-2007  rumble Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.3 13-May-2009  wiz Sort option descriptions.
 1.2 30-Jun-2007  rumble Make mount_efs.8 and svhlabel.8 reference one another.
 1.1 29-Jun-2007  rumble Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.7 07-Feb-2013  apb getrawpartition(3) may fail, so call it only once and test for failure.
Coverity CID 274527.
 1.6 27-Aug-2011  joerg branches: 1.6.2; 1.6.8;
__dead + kill main prototype.
 1.5 06-Apr-2009  lukem fix sign-compare issue
 1.4 30-Jun-2007  rumble branches: 1.4.22;
When checking for an EFS filesystem just read in the whole superblock,
rather than jump to the hard-coded magic field offset.
 1.3 30-Jun-2007  rumble Add missing include.
 1.2 29-Jun-2007  rumble Superblock magic numbers are #define'd, so use them.
 1.1 29-Jun-2007  rumble Add read-only support for SGI's Extent File System.

Reviewed by pooka@.
 1.4.22.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.6.8.1 25-Feb-2013  tls resync with head
 1.6.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5 27-Aug-2006  martin As discussed on tech-userlevel: enhance the -A/-U commands to take a -t
auto flag, which queries all local harddisks for swap partitions/
wedges and adds/removes them as swap device, a -f option to use the
first found swap device as dump device, and a -o option to only
auto-configure the dump device, but leave swap alone.

Add a -n option to make swapctl only say what it would do, but not
change any system state.
 1.4 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.3 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.

Reviewed by mrg@.
 1.2 12-Jun-1997  mrg link to swapon.
 1.1 12-Jun-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 12-Jun-1997  mrg swapctl program for new swap code.
 1.46 08-Jul-2024  pgoyette s/point mount/mount point/
 1.45 04-Feb-2024  mrg branches: 1.45.2;
update my email address.
 1.44 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.43 20-Jul-2013  wiz Use Mt for email addresses.
 1.42 01-Jun-2011  jruoho branches: 1.42.4; 1.42.10; 1.42.14;
Clarify placement of commas. From Snader_LB on freenode/#netbsd-code.
 1.41 24-Sep-2009  apb Make the exit status from "swapctl -A" and "swapctl -U" tri-state:
0 for success; 1 for error; and 2 when no devices of the appropriate type
are defined in fstab(5). Previously, "no apropriate devices" was
indistinguishable from "error".
 1.40 29-May-2008  mrg remove clause #3 from my license where there are no other
copyright holders involved.
 1.39 02-Aug-2007  he branches: 1.39.10; 1.39.12; 1.39.14; 1.39.16;
Re-phrase description of -A option, as per suggestion from Jukka Salmi
at netbsd-users@ and with a slight tweak by myself -- at the end the last
dump device will remain as the single active dump device.
Fix a nearby typo.
Bump date.
 1.38 02-Sep-2006  wiz Sort sections. Fix typo. Start sentence with upper-case letter.
 1.37 27-Aug-2006  martin Add a caveats section describing potential problems with autoconfigured
swap partitons.
 1.36 27-Aug-2006  martin As discussed on tech-userlevel: enhance the -A/-U commands to take a -t
auto flag, which queries all local harddisks for swap partitions/
wedges and adds/removes them as swap device, a -f option to use the
first found swap device as dump device, and a -o option to only
auto-configure the dump device, but leave swap alone.

Add a -n option to make swapctl only say what it would do, but not
change any system state.
 1.35 23-Aug-2006  wiz Sort options. Sync usage with man page.
 1.34 23-Aug-2006  wiz Sort sections. Fix typos.
 1.33 22-Aug-2006  martin Only one -D synopsis line
 1.32 22-Aug-2006  martin Allow unsetting the dump device via "swapctl -D none".
For -l (list swap partitions) and -z (list dump device) return a usefull
error status, so scripts can easily decide if swap or dump are configured.
 1.31 08-Jun-2004  wiz Drop trailing whitespace.
 1.30 08-Jun-2004  cjep Add options for swapon in the Synopsis section. Closes PR#25866 from
Kouichirou Hiratsuka.
 1.29 21-Dec-2003  mrg branches: 1.29.2;
bump date for previous
 1.28 20-Dec-2003  mrg support "-g" and "-m" as well as "-k" and "-h". swapctl & swaplist code
from Martin Weber, adapted for pstat by myself.
 1.27 20-Dec-2003  mrg add a "-h" (humanize_number(3)) option to swapctl(8) and pstat(8), from
Martin Weber in PR#23805.

ps: now we only need someone to do ls(1) :-)
 1.26 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.25 24-Jan-2003  hubertf Mention that the mount point for a remote swap file must exist as a directory.
Sanity checked by salo.
 1.24 01-Oct-2002  wiz New sentence, new line. Use some more mdoc.
 1.23 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.22 16-Nov-2001  wiz Sort sections, use standard section headers.
 1.21 01-Oct-2001  wiz Remove swapoff mention, per misc/14120.
Some whitespace, section name, section order fixes while I'm here.
 1.20 05-Jun-2001  wiz Drop arguments of .Os.
 1.19 11-Apr-2001  mrg add a section on swap priorities. document the round robin scheme.
fixes half of PR#12610.
 1.18 17-Nov-2000  mrg support new `swapctl -z' that shows the dump device.
 1.17 05-Mar-2000  lukem * add support for -U, which is the opposite of -A (i.e, it unconfigures
all swap devices in /etc/fstab).
* fix description of -D
 1.16 13-Jan-2000  ad swapctl(SWAP_OFF, ...) now works.
 1.15 23-Feb-1999  mrg add a new fstab type "dp" for the user-specified dump device.
change swapctl -A to see this and add it via swapctl(2). also
add a new swapctl -D <device> to change the dump device on the
fly.
 1.14 22-May-1998  msaitoh sort entries and delete extra periods in SEE also section.
 1.13 10-Feb-1998  mrg make swapctl exit with non-zero if -A and nothing swapped on
 1.12 26-Jan-1998  ross Typo corrections.
 1.11 11-Nov-1997  mrg add missing .Nm sections.
 1.10 23-Oct-1997  mrg oops; forgot to update the license here.
 1.9 20-Oct-1997  enami branches: 1.9.2;
Fix .Nm usage.
 1.8 15-Sep-1997  lukem * fix .Nm usage
* prototype main() for WARNS=1
 1.7 03-Aug-1997  mikel note that swapoff is unsupported; from Brian Grayson in PR misc/3930
 1.6 26-Jun-1997  perry move -t option to stand on its own and change a bit.
add a WARNINGS about the dangers of running without swap or only using
swap files if you have local disk to fsck.
 1.5 25-Jun-1997  thorpej Add a "-t blk|noblk" device type option to swapctl -A. This allows the
user to specify "only add block devices" or "only add non-block devices".
This is useful during early system startup where swapping may be needed
before swap files are available (e.g. if fsck'ing large file systems).
 1.4 15-Jun-1997  mrg note what N in priority=N means.
 1.3 15-Jun-1997  mrg make option lists much clearer.
 1.2 15-Jun-1997  mrg document nfsmntpt option, re-arrange a little.
 1.1 12-Jun-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 12-Jun-1997  mrg swapctl program for new swap code.
 1.9.2.2 11-Nov-1997  mrg pull up from trunk: add missing .Nm sections.
 1.9.2.1 23-Oct-1997  mrg pull up from trunk: oops; forgot to update the license here.
 1.29.2.1 13-Jun-2004  jdc Pull up revision 1.30 (requested by cjep in ticket #460).

Add options for swapon in the Synopsis section. Closes PR#25866 from
Kouichirou Hiratsuka.
 1.39.16.2 02-Aug-2007  he Re-phrase description of -A option, as per suggestion from Jukka Salmi
at netbsd-users@ and with a slight tweak by myself -- at the end the last
dump device will remain as the single active dump device.
Fix a nearby typo.
Bump date.
 1.39.16.1 02-Aug-2007  he file swapctl.8 was added on branch matt-mips64 on 2007-08-02 18:53:47 +0000
 1.39.14.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.39.12.1 04-Jun-2008  yamt sync with head
 1.39.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.42.14.1 23-Jul-2013  riastradh sync with HEAD
 1.42.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.42.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.45.2.1 02-Aug-2025  perseant Sync with HEAD
 1.43 01-Mar-2023  kre Fix a typo in a newly added comment.

Someone please tell me why these things become obvious only after
the code has been committed!

NFC
 1.42 01-Mar-2023  kre When processing swapon -a (or swapctl -A, or swapctl -U) ignore lines in
fstab that have nothing to do with swapping (fs_type is neither "sw" nor "dp")
before running getfsspecname() on the fs_spec field of the line.

This avoids entries like this:

NAME=OFTEN_UNCONNECTED /local/archived ffs rw,log,noauto 0 0

in fstab from generating spurious error messages when the wedge named
is not currently connected to the system - that is the drive on which the
wedge exists is not connected, or not powered on. "noauto" handles that
for some other uses, the "0"s in fs_freq and fs_passno work for other uses,
but swap{on,ctl} never look at those fields (not for this purpose).

Non "sw"/"dp" lines were being ignored anyway, but not until (a little) later.
 1.41 04-Apr-2022  andvar fix various typos, mainly in comments.
 1.40 11-Oct-2015  mrg don't stop processing /etc/fstab when one entry fails, both for
add and remove loops. now when you add a new swap file and run
"swapctl -A" it won't give up after the existing one gives EBUSY
and move on to the rest.
 1.39 01-Jan-2013  dsl Explicitly include sys/ioctl.h
 1.38 26-Dec-2012  mlelstv Allow named wedges to be used on command line, also fix name lookup
for the dump device.
 1.37 07-Apr-2012  christos branches: 1.37.2;
use getfsspecname()
 1.36 27-Aug-2011  joerg branches: 1.36.2;
static + __dead
 1.35 24-Sep-2009  apb Make the exit status from "swapctl -A" and "swapctl -U" tri-state:
0 for success; 1 for error; and 2 when no devices of the appropriate type
are defined in fstab(5). Previously, "no apropriate devices" was
indistinguishable from "error".
 1.34 28-Dec-2008  christos fix dev_t format.
 1.33 29-May-2008  mrg remove clause #3 from my license where there are no other
copyright holders involved.
 1.32 27-Aug-2006  martin branches: 1.32.18; 1.32.20; 1.32.22;
As discussed on tech-userlevel: enhance the -A/-U commands to take a -t
auto flag, which queries all local harddisks for swap partitions/
wedges and adds/removes them as swap device, a -f option to use the
first found swap device as dump device, and a -o option to only
auto-configure the dump device, but leave swap alone.

Add a -n option to make swapctl only say what it would do, but not
change any system state.
 1.31 23-Aug-2006  wiz Sort options. Sync usage with man page.
 1.30 22-Aug-2006  martin Allow unsetting the dump device via "swapctl -D none".
For -l (list swap partitions) and -z (list dump device) return a usefull
error status, so scripts can easily decide if swap or dump are configured.
 1.29 12-Jun-2005  christos Remove some const. This is better than using __UNCONST at the second
argument of swapctl.
 1.28 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.

Reviewed by mrg@.
 1.27 10-Jan-2005  lukem support RESCUEDIR (for mount_nfs and umount)
 1.26 08-Jun-2004  cjep Fix usage string (i.e. add information about -z). Fixes PR#25865 from
Kouichirou Hiratsuka.
 1.25 20-Dec-2003  mrg branches: 1.25.2;
support "-g" and "-m" as well as "-k" and "-h". swapctl & swaplist code
from Martin Weber, adapted for pstat by myself.
 1.24 20-Dec-2003  mrg add a "-h" (humanize_number(3)) option to swapctl(8) and pstat(8), from
Martin Weber in PR#23805.

ps: now we only need someone to do ls(1) :-)
 1.23 21-Oct-2003  fvdl The 3rd argument to swapctl() is an int, don't pass NULL in it.
 1.22 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.21 18-Sep-2002  drochner print something sensible on -z if no dump device is set
 1.20 21-Jun-2002  jdolecek Support 'dp' as mount option for 'sw' fstype, so it DTRT for entries like:
/dev/wd0b none swap sw,dp 0 0
 1.19 26-Nov-2001  pooka Add word "WARNING" when complaining about swap being world-read/writeable
to clarify that this was not an error condition and that swap was indeed
added despite the problem.
 1.18 19-Feb-2001  cgd convert to use getprogname()
 1.17 17-Nov-2000  lukem fix incorrect comment; -d does work!
 1.16 17-Nov-2000  mrg support new `swapctl -z' that shows the dump device.
 1.15 07-Jul-2000  itojun warnx?/errx? audit. don't pass variable/function return value alone.
use with "%s". from openbsd.
 1.14 13-Apr-2000  mrg branches: 1.14.4;
use <sys/swap.h>. should have happened years ago.
 1.13 13-Mar-2000  soren Fix doubled 'the's.
 1.12 05-Mar-2000  lukem * add support for -U, which is the opposite of -A (i.e, it unconfigures
all swap devices in /etc/fstab).
* fix description of -D
 1.11 26-Apr-1999  mrg add a -D line to usage().
 1.10 23-Feb-1999  mrg add a new fstab type "dp" for the user-specified dump device.
change swapctl -A to see this and add it via swapctl(2). also
add a new swapctl -D <device> to change the dump device on the
fly.
 1.9 26-Jul-1998  mycroft const poisoning.
 1.8 10-Feb-1998  mrg make swapctl exit with non-zero if -A and nothing swapped on
 1.7 10-Oct-1997  mrg remove advertising clause from all my licenses.
 1.6 15-Sep-1997  lukem * fix .Nm usage
* prototype main() for WARNS=1
 1.5 11-Jul-1997  mikel add comparisons to NULL implicit in my last changes
 1.4 25-Jun-1997  thorpej Add a "-t blk|noblk" device type option to swapctl -A. This allows the
user to specify "only add block devices" or "only add non-block devices".
This is useful during early system startup where swapping may be needed
before swap files are available (e.g. if fsck'ing large file systems).
 1.3 24-Jun-1997  mikel include <err.h> for err*() and warn*() prototypes
cast long to int for use by printf("%d",..)
add parens for gcc -Wall
 1.2 15-Jun-1997  thorpej Totally rework the command parsing, eliminating a few walk-offs of
bogus pointers, etc.
 1.1 12-Jun-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 12-Jun-1997  mrg swapctl program for new swap code.
 1.14.4.1 27-Jul-2000  itojun pullup (approved by releng-1-5)
printf-like format pedant. do not pass string variable alone. use "%s".
from openbsd.

/cvsroot/basesrc/sbin/swapctl/swapctl.c 1.14 -> 1.15
/cvsroot/basesrc/sbin/ping6/ping6.c 1.15 -> 1.16
/cvsroot/basesrc/sbin/disklabel/disklabel.c 1.84 -> 1.85
/cvsroot/basesrc/sbin/ccdconfig/ccdconfig.c 1.30 -> 1.31
 1.25.2.1 13-Jun-2004  jdc Pull up revision 1.26 (requested by cjep in ticket #460).

Fix usage string (i.e. add information about -z). Fixes PR#25865 from
Kouichirou Hiratsuka.
 1.32.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.32.20.1 04-Jun-2008  yamt sync with head
 1.32.18.2 17-Jan-2009  mjf Sync with HEAD.
 1.32.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.36.2.2 23-Jan-2013  yamt sync with head
 1.36.2.1 17-Apr-2012  yamt sync with head
 1.37.2.1 25-Feb-2013  tls resync with head
 1.6 29-May-2008  mrg remove clause #3 from my license where there are no other
copyright holders involved.
 1.5 22-Aug-2006  martin branches: 1.5.18; 1.5.20; 1.5.22;
Allow unsetting the dump device via "swapctl -D none".
For -l (list swap partitions) and -z (list dump device) return a usefull
error status, so scripts can easily decide if swap or dump are configured.
 1.4 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.

Reviewed by mrg@.
 1.3 20-Dec-2003  mrg add a "-h" (humanize_number(3)) option to swapctl(8) and pstat(8), from
Martin Weber in PR#23805.

ps: now we only need someone to do ls(1) :-)
 1.2 10-Oct-1997  mrg remove advertising clause from all my licenses.
 1.1 12-Jun-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 12-Jun-1997  mrg swapctl program for new swap code.
 1.5.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.20.1 04-Jun-2008  yamt sync with head
 1.5.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.19 11-Dec-2023  mlelstv Avoid overflow of totals.
 1.18 31-May-2016  pgoyette Minor formatting change in swapctl -l as noted in my PR bin/51155
 1.17 06-Apr-2009  lukem redo previous to fix amd64 build
 1.16 06-Apr-2009  lukem fix sign-compare issue
 1.15 29-May-2008  mrg branches: 1.15.4;
remove clause #3 from my license where there are no other
copyright holders involved.
 1.14 22-Aug-2006  martin branches: 1.14.18; 1.14.20; 1.14.22;
Allow unsetting the dump device via "swapctl -D none".
For -l (list swap partitions) and -z (list dump device) return a usefull
error status, so scripts can easily decide if swap or dump are configured.
 1.13 09-Feb-2005  xtraeme Kill __P(), use ANSI function declarations, constify; WARNS=3.

Reviewed by mrg@.
 1.12 20-Dec-2003  mrg support "-g" and "-m" as well as "-k" and "-h". swapctl & swaplist code
from Martin Weber, adapted for pstat by myself.
 1.11 20-Dec-2003  mrg add a "-h" (humanize_number(3)) option to swapctl(8) and pstat(8), from
Martin Weber in PR#23805.

ps: now we only need someone to do ls(1) :-)
 1.10 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.9 19-Aug-2000  soren Add space in summary printf.
 1.8 08-Oct-1998  mrg branches: 1.8.10;
print the strerror if swapctl fails.
 1.7 29-Aug-1998  mrg <vm/vm_swap.h> -> <sys/swap.h>
 1.6 29-Aug-1998  mrg add a `char se_path[PATH_MAX]' member to struct swapent, that
the pathname of the swap device is saved into. add a char *swd_path
member to struct swapdev, that contains a copy of the pathname
(using malloc(9)). rename swapctl(2)'s SWAP_STATS to SWAP_OSTATS,
and add a new SWAP_STATS command (number). make swapctl(SWAP_STATS,
...) [new version] copy the path out. if COMPAT_13, also include
support for SWAP_OSTATS. also fix a minor bug in swapctl(2).

the point of this is that swapfiles are now shown in `swapctl -l'.
 1.5 17-Jun-1998  ross Fix this to correctly do swapctl -l for regions > 2^31 bytes.
We include <inttypes.h> in case at some point in the future we do things
the SUSV2 way and originate the 64-bit scalar defs there.
 1.4 10-Oct-1997  mrg branches: 1.4.2;
remove advertising clause from all my licenses.
 1.3 21-Jul-1997  mrg free() what you malloc().
 1.2 25-Jun-1997  mikel include <err.h> for err*() and warn*() prototypes
fix some printf() formats to take long args instead of int
 1.1 12-Jun-1997  mrg branches: 1.1.1;
Initial revision
 1.1.1.1 12-Jun-1997  mrg swapctl program for new swap code.
 1.4.2.1 25-Sep-1998  cgd Pull up part of rev 1.6 ("test correct return value", mrg)
 1.8.10.1 03-Sep-2000  soren Pull up rev 1.9:
> date: 2000/08/19 21:31:58; author: soren; state: Exp; lines: +2 -2
> Add space in summary printf.
 1.14.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.14.20.1 04-Jun-2008  yamt sync with head
 1.14.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.22 18-Aug-2019  kamil sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.21 29-Nov-2012  christos branches: 1.21.30; 1.21.32;
use the proper variable
 1.20 13-Dec-2010  pooka branches: 1.20.6; 1.20.12;
RUMP_ACTION -> RUMPPRG
 1.19 05-Nov-2010  pooka make sysctl(8) work as a rump client
 1.18 13-Feb-2009  uebayasi Comment out CFLAGS+=-g.
 1.17 06-Apr-2005  christos branches: 1.17.28; 1.17.30;
PPR/29909: Manuel Bouyer: sysctl dumps core if kern.consdev returns unknown
device. If we cannot determine the device name of the console, print the
console dev_t in hex.
 1.16 25-Mar-2004  atatat Move sysctlbyname(), sysctlnametomib(), and sysctlgetmibinfo() from
sysctl(8) into libc, making the minor number jump. Add prototypes to
sys/sysctl.h, fix sets, modify man pages, etc. That oughta cover it.
 1.15 04-Dec-2003  atatat New sysctl(8) binary. Performs auto-discovery and can add/remove
nodes from the tree. Never needs to be recompiled again.
 1.14 30-Nov-2002  lukem tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
 1.13 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.12 20-Mar-2002  christos handle new emulation sysctls, and cleanup function duplication.
 1.11 12-Mar-2000  tsarna Add a "-f file" flag to process directives from a file.
 1.10 17-Jan-2000  itojun don't install /usr/sbin/sysctl (backward compat symlink)
 1.9 17-Jan-2000  itojun move sysctl to /sbin/sysctl. symlink from /usr/sbin/sysctl
is supplied for backward compatibility.

add /sbin/sysctl to base/mi (does not remove /usr/sbin/sysctl
as we have a symlink)
 1.8 17-Jan-2000  itojun Moved from usr.sbin/sysctl/Makefile,v
 1.7 03-Jul-1999  itojun s/CFLAGS/CPPFLAGS/ for -D and -I.
 1.6 02-Jul-1999  itojun IPv6/IPsec sysctl MIB support.
 1.5 05-Mar-1998  christos WARNSify
 1.4 18-Oct-1997  lukem enable WARNS=1 by default, but disable in unclean 3rd party code
 1.3 30-Sep-1995  thorpej New-style RCS ids.
 1.2 22-Dec-1994  cgd specify man pages the new way.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd sysctl-of-fish
 1.17.30.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.17.28.1 08-Dec-2010  riz Pull up following revision(s) (requested by uwe in ticket #1490):
usr.bin/mkdep/Makefile: revision 1.16
sbin/dump_lfs/Makefile: revision 1.10
usr.sbin/services_mkdb/Makefile: revision 1.5
sbin/ifconfig/Makefile: revision 1.40
usr.sbin/racoonctl/Makefile: revision 1.3
sbin/sysctl/Makefile: revision 1.18
Comment out CFLAGS+=-g.
Disable debug.
 1.20.12.1 25-Feb-2013  tls resync with head
 1.20.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.21.32.1 19-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #95):

sbin/sysctl/prog_ops.h: revision 1.3
sbin/sysctl/sysctl_rumpops.c: revision 1.2
sbin/sysctl/sysctl_hostops.c: revision 1.2
sbin/sysctl/Makefile: revision 1.22
sbin/sysctl/sysctl.c: revision 1.162

sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.21.30.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7 25-Mar-2004  atatat Move sysctlbyname(), sysctlnametomib(), and sysctlgetmibinfo() from
sysctl(8) into libc, making the minor number jump. Add prototypes to
sys/sysctl.h, fix sets, modify man pages, etc. That oughta cover it.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.5 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.4 17-Jan-2000  itojun Moved from usr.sbin/sysctl/pathconf.c,v
 1.3 01-Nov-1997  lukem getopt returns -1 not EOF
 1.2 30-Sep-1995  thorpej New-style RCS ids.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd sysctl-of-fish
 1.3 18-Aug-2019  kamil sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.2 13-Dec-2010  pooka branches: 1.2.46; 1.2.48;
use crunchops for crunchables
 1.1 13-Dec-2010  pooka RUMP_ACTION -> RUMPPRG
 1.2.48.1 19-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #95):

sbin/sysctl/prog_ops.h: revision 1.3
sbin/sysctl/sysctl_rumpops.c: revision 1.2
sbin/sysctl/sysctl_hostops.c: revision 1.2
sbin/sysctl/Makefile: revision 1.22
sbin/sysctl/sysctl.c: revision 1.162

sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.2.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.162 03-Aug-2011  christos allow -q flag to work for reads.
 1.161 30-Sep-2009  elad Remove stale references to the "read only at securelevel [12]" flags in
the documentation and code comments.
 1.160 01-Apr-2009  christos Don't print an error with sysctl -w name?=value if name does not exist.
Should be pulled up to 5.0
 1.159 11-Nov-2008  reed branches: 1.159.2;
Reference secmodel_securelevel(9) manual page.
 1.158 02-May-2008  martin branches: 1.158.4;
Move TNF licenses to 2 clause form
 1.157 04-Dec-2006  pavel branches: 1.157.12; 1.157.14;
Move the description of sysctl MIBs from sysctl.3 to a new manual page
sysctl.7. Remove the list of MIBs from sysctl.8 so we don't have to
maintain duplicate information, as proposed by YAMAMOTO Takashi on
tech-userlevel. Also remove references to header files from sysctl.8.

The numeric constants remain documented, they are still needed in some
cases. See the discussion on tech-userlevel. ("mib list in sysctl.8")

OK by YAMAMOTO Takashi.
 1.156 25-Nov-2006  christos branches: 1.156.2;
PR/34837: Mindaguas: Add SysV SHM dynamic reallocation and locking to the
physical memory
 1.155 22-Nov-2006  elad Initial implementation of PaX Segvguard (this is still work-in-progress,
it's just to get it out of my local tree).
 1.154 26-Sep-2006  elad Change the PaX mprotect(2) restrictions' "global_protection" knob to
just "global" -- it's shorter and more readable. Update documentation.
 1.153 05-Sep-2006  rpaulo Import of TCP ECN algorithm for congestion control.
Both available for IPv4 and IPv6.
Basic implementation test results are available at
http://netbsd-soc.sourceforge.net/projects/ecn/testresults.html.

Work sponsored by the Google Summer of Code project 2006.
Special thanks to Kentaro Kurahone, Allen Briggs and Matt Thomas for their
help, comments and support during the project.
 1.152 04-Sep-2006  liamjfoy add net.inet.ip.maxflows. Bump date.
 1.151 08-Aug-2006  wiz Bump date for previous.
 1.150 08-Aug-2006  kardel document timecounter sysctls
 1.149 14-Jul-2006  elad branches: 1.149.2;
move security.setid_core.* to kern.coredump.setid.*, as requested by yamt@.
 1.148 14-Jul-2006  elad okay, since there was no way to divide this to two commits, here it goes..

introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.

this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.

as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.

also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.

tons of input from yamt@, wrstuden@, martin@, and christos@.
 1.147 29-May-2006  liamjfoy bump date (.Dd)
 1.146 29-May-2006  liamjfoy document Common Address Redundancy Protocol sysctls, aka CARP

ok joerg@
 1.145 16-May-2006  elad Introduce PaX MPROTECT -- mprotect(2) restrictions used to strengthen
W^X mappings.

Disabled by default.

First proposed in:

http://mail-index.netbsd.org/tech-security/2005/12/18/0000.html

More information in:

http://pax.grsecurity.net/docs/mprotect.txt

Read relevant parts of options(4) and sysctl(3) before using!

Lots of thanks to the PaX author and Matt Thomas.
 1.144 06-Mar-2006  christos add the 3 opencrypto sysctls.
 1.143 04-Feb-2006  wiz Bump date for security.*
 1.142 02-Feb-2006  elad - make use of the recently added mode_bits for security.setid_core.mode;
- document setid_core variables.
 1.141 14-Jan-2006  elad add some more to kern.
 1.140 14-Jan-2006  elad remove dup cnmagic.
 1.139 14-Jan-2006  elad Sync and sort ddb, hw, kern, vm.
 1.138 13-Jan-2006  elad oops - this should not have been commited. remove sugid_coredump line.
 1.137 13-Jan-2006  elad grrr... another space -> tab...
 1.136 13-Jan-2006  elad space -> tab
 1.135 13-Jan-2006  elad Sync net.{inet,inet6,key}
 1.134 21-Dec-2005  yamt add vm.inactivepct.
 1.133 13-Dec-2005  yamt add vm.idlezero. noted by Hubert Feyrer.
 1.132 27-Nov-2005  yamt bump date for the previous.
 1.131 27-Nov-2005  yamt add ddb.commandonenter.
 1.130 15-Oct-2005  xtraeme Mention "kern.bufq.strategies", bump date.
 1.129 06-Oct-2005  wiz Add missing comma.
 1.128 03-Oct-2005  elad Document security level for sysctl and security.curtain.

Hi Hubert! :)
 1.127 24-Sep-2005  rpaulo Document kern.hardclock_ticks. Pointed out by Hubert.
 1.126 23-Sep-2005  wiz Drop trailing whitespace.
 1.125 21-Sep-2005  xtraeme Mention vfs.sync.*, bump date.
 1.124 06-Sep-2005  rpaulo Handle net.inet.tcp.debug, net.inet.tcp.debx, net.ns.spp.debug and
net.ns.spp.debx. Bump man page date.
 1.123 04-Aug-2005  rpaulo Added net.bpf.peers and net.bpf.stats and bumped the date.
 1.122 24-May-2005  wiz Bump date for previous. <> -> \*[Lt]\*[Gt].
 1.121 24-May-2005  elad Add man-page bits about the 'count' node.
 1.120 20-May-2005  elad Remove common code for returning supported fingerprints. This is done now
via sysctl(8) using kern.veriexec.algorithms.

Also add an entry for the 'algorithms' variable in sysctl.8 forgotten in
the last commit.
 1.119 19-May-2005  elad Some changes in veriexec.

New features:

- Add a veriexec_report() routine to make most reporting consistent and
remove some common code.
- Add 'strict' mode that controls how veriexec behaves.
- Add sysctl knobs:
o kern.veriexec.verbose controls verbosity levels. Value: 0, 1.
o kern.veriexec.strict controls strict level. Values: 0, 1, 2. See
documentation in sysctl(3) for details.
o kern.veriexec.algorithms returns a string with a space separated
list of supported hashing algorithms in veriexec.
- Updated documentation in man pages for sysctl(3) and sysctl(8).

Bug fixes:

- veriexec_removechk(): Code cleanup + handle FINGERPRINT_NOTEVAL
correctly.
- exec_script(): Don't pass 0 as flag when executing a script; use the
defined VERIEXEC_INDIRECT - which is 1. Makes indirect execution
enforcement work.
- Fix some printing formats and types..
 1.118 26-Dec-2004  christos branches: 1.118.2;
PR/28782: OBATA Akio: Document that kern.rtc_offset is writable.
 1.117 21-Nov-2004  jdolecek add vfs.cd9660.utf8_joliet, and couple other vfs.* entries while here

bump date and add TNF copyright
 1.116 15-Oct-2004  daniel Add vm.bufcache, vm.bufmem, vm.bufmem_lowater, m.bufmem_hiwater (PR misc/27247, misc/27233).
 1.115 27-Aug-2004  wiz Bump date for removal of net.key.random_int.
 1.114 27-Aug-2004  itojun remove net.key.random_int
 1.113 28-Apr-2004  snj Bump date for last.
 1.112 28-Apr-2004  ragge Note net.inet.arp.* entries.
 1.111 24-Mar-2004  wiz branches: 1.111.2;
Remove duplicate and superfluous words.
 1.110 24-Mar-2004  snj Bump date for last.
 1.109 24-Mar-2004  atatat Bring sysctl man pages up to date (wrt new query interface, the
versioning, and descriptions).
 1.108 22-Jan-2004  wiz Bump date for previous.
 1.107 22-Jan-2004  jonathan Document net.bpf.maxbufsize in sysctl(8).
NB: bpf isn't a PF_, so where to list it in sysctl(3)?
 1.106 08-Jan-2004  atatat Used to say "type=", but now says "size=" since that's what it's
supposed to say.
 1.105 31-Dec-2003  wiz Simplify Oo/Oc to Op, since it has only one simple short argument.
 1.104 30-Dec-2003  atatat Update sysctl.8 man page to cover all the new stuff.
 1.103 15-Oct-2003  wiz Slight option ordering change.
 1.102 27-Sep-2003  dsl Forgot the date....
 1.101 27-Sep-2003  dsl Add kern.drivers and kern.root_partition to match recent kern_sysctl.c
Add kern.root_device which was absent.
 1.100 21-Sep-2003  wiz Combine multiple single-letter options.
 1.99 20-Sep-2003  grant add -e flag to set the separator to '=' where the default is ' = '.
this allows sysctl output to fed back into itself. inspired by
FreeBSD's sysctl(8).

ok'd by atatat.
 1.98 17-Sep-2003  grant put flags in a list with descriptions. add proper description of -w.
 1.97 07-Aug-2003  wiz Mention /etc/sysctl.conf. Bump date. Closes PR 22213.
 1.96 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.95 04-Jul-2003  wiz Bump date for last, and replace some \*[Lt]/\*[Gt] with .Aq.
 1.94 03-Jul-2003  ragge Add somaxkva.
 1.93 19-Apr-2003  christos add tcp.ident.
 1.92 12-Apr-2003  christos add checkinterface
 1.91 17-Mar-2003  wiz Consistent tab usage.
 1.90 15-Mar-2003  wiz Use "its" instead of "it's" where appropriate.
From Soren Jacobsen in PR 20730.
 1.89 06-Mar-2003  thorpej hw.physpages -> hw.physmem64, hw.userpages -> hw.usermem64
 1.88 01-Mar-2003  thorpej Document net.inet.tcp.init_win_local.
 1.87 27-Feb-2003  thorpej Document hw.physpages and hw.userpages.
 1.86 02-Feb-2003  kleink Add sysconf(3) knobs for recent additions.
 1.85 01-Feb-2003  kleink Add several missing items, and be less rageous about memory locking.
 1.84 11-Dec-2002  jdolecek Add kern.forkfsleep sysctl - set/get time (in miliseconds) for which
process would be forced to sleep in fork() if it hits either global
or user maxproc limit. Default is zero (no forced sleep).
Maximum is 20 seconds.
 1.83 11-Dec-2002  scw Add two sysctls: kern.labelsector and kern.labeloffset.
These are of use to userland code which previously depended on the
hard-coded values of LABELSECTOR and LABELOFFSET to figure out the
location of the disklabel for a particular platform.

With the introduction of umbrella ports such as evbarm, evbmips, etc,
the location of the disklabel may vary between kernels for the same
MACHINE. This sysctl will allow userland programs to remain independent
of the particular flavour of MACHINE in such cases.
 1.82 07-Nov-2002  manu Added two sysctl-able flags: proc.curproc.stopfork and proc.curproc.stopexec
that can be used to block a process after fork(2) or exec(2) calls. The
new process is created in the SSTOP state and is never scheduled for running.

This feature is designed so that it is esay to attach the process using gdb
before it has done anything.

It works also with sproc, kthread_create, clone...
 1.81 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.80 01-Oct-2002  wiz Replace some \*[Lt]...\*[Gt] with .Aq ...
 1.79 29-May-2002  msaitoh document vfs.nfs.iothreads
 1.78 28-May-2002  itojun document net.inet6.ip6.maxfrags
 1.77 19-May-2002  itojun branches: 1.77.2;
document net.key.* sysctl. provide sysctl MIB for controlling
proposal payload on ACQUIRE message. sync w/kame
 1.76 14-May-2002  itojun rename: net.inet6.ip6.bindv6only -> net.inet6.ip6.v6only
sync w/kame.
 1.75 24-Mar-2002  sommerfeld Add -q flag, for use with -w and -f, which suppresses output after a set.
 1.74 08-Feb-2002  ross Generate <>& symbolically. I'm avoiding .../dist/... directories for now.
 1.73 28-Jan-2002  simonb Document the new kern.tkstat.* sysctls.
 1.72 27-Jan-2002  simonb Prod from lukem - remember to add hw.disk* here too.
 1.71 24-Dec-2001  chs update for changed vm knobs.
 1.70 30-Oct-2001  wiz Sort sections, whitespace nits.
 1.69 30-Oct-2001  kml Added descriptions of the new sysctls for controlling the disposition
of IPv4 routes added via redirects, rediraccept and redirtimeout.
 1.68 20-Aug-2001  hubertf Remove duplicate listing of "net.inet.tcp.init_win" system variable as
reported in PR 13760 by Don Yuniskis <auryn@gci-net.com>
 1.67 16-Jun-2001  jdolecek Add port of high performance pipe implementation written by John S. Dyson
for FreeBSD project. Besides huge speed boost compared with socketpair-based
pipes, this implementation also uses pagable kernel memory instead of mbufs.

Significant differences to FreeBSD version:
* uses uvm_loan() facility for direct write
* async/SIGIO handling correct also for sync writer, async reader
* limits settable via sysctl, amountpipekva and nbigpipes available via sysctl
* pipes are unidirectional - this is enforced on file descriptor level
for now only, the code would be updated to take advantage of it
eventually
* uses lockmgr(9)-based locks instead of home brew variant
* scatter-gather write is handled correctly for direct write case, data
is transferred by PIPE_DIRECT_CHUNK bytes maximum, to avoid running out of kva

All FreeBSD/NetBSD specific code is within appropriate #ifdef, in preparation
to feed changes back to FreeBSD tree.

This pipe implementation is optional for now, add 'options NEW_PIPE'
to your kernel config to use it.
 1.66 27-Mar-2001  itojun net.inet.ip.maxfragpackets defines the maximum size of ip reass queue
(prevents fragment flood from chewing up mbuf memory space).
derived from KAME net.inet6.ip6.maxfragpackets.
 1.65 09-Mar-2001  chs add UBC memory-usage balancing. we track the number of pages in use for
each of the basic types (anonymous data, executable image, cached files)
and prevent the pagedaemon from reusing a given page if that would reduce
the count of that type of page below a sysctl-setable minimum threshold.
the thresholds are controlled via three new sysctl tunables:
vm.anonmin, vm.vnodemin, and vm.vtextmin. these tunables are the
percentages of pageable memory reserved for each usage, and we do not allow
the sum of the minimums to be more than 95% so that there's always some
memory that can be reused.
 1.64 07-Feb-2001  itojun during ip6/icmp6 inbound packet processing, do not call log() nor printf() in
normal operation (/var can get filled up by flodding bogus packets).
sysctl net.inet6.icmp6.nd6_debug will turn on diagnostic messages.
(#define ND6_DEBUG will turn it on by default)

improve stats in ND6 code.

lots of synchronziation with kame (including comments and cometic ones).
 1.63 26-Jan-2001  hubertf Document that there's currently no registry for vendor sysctls.
After discussion with John Hawkinson and Frank van der Linden.
 1.62 10-Jan-2001  hubertf * Document the vendor.* sysctl branch
* in sysctl.3, sort the list of CTL_ prefixes and sync with sysctl.h
 1.61 21-Dec-2000  itojun document net.inet6.icmp6.mtudisc_{lo,hi}wat.
 1.60 08-Nov-2000  eeh Document new hw.cnmagic sysctl(8) variable.
 1.59 26-Oct-2000  jdolecek add couple of missing entries, update kern.maxptys entry - it is not raise only
 1.58 15-Oct-2000  bjh21 Ah, so _that_'s how you get a backslash in a macro argument.
Thanks to itojun for pointing it out.
 1.57 15-Oct-2000  bjh21 Various formatting cleanups (mostly to use .Ql).
Note that getting a single backslash inside Ql seems to need SIXTEEN
of them in the source!
 1.56 26-Sep-2000  jdolecek fix typo (remplaced --> replaced)
 1.55 09-Sep-2000  jdolecek document kern.maxptys/KERN_MAXPTYS
note that kern.maxvnodes is raise only
 1.54 26-Aug-2000  itojun implement net.inet6.ip6.{anon,low}port{min,max} sysctl variable.
 1.53 26-Aug-2000  itojun document net.inet.ip.lowport{min,max}
 1.52 28-Jul-2000  itojun nuke net.inet*.ip*.*ratelimit.
 1.51 27-Jul-2000  itojun add net.inet.tcp.rstppslimit
 1.50 10-Jul-2000  itojun document sysctl variable "net.inet.icmp.errppslimit".
 1.49 09-Jul-2000  itojun add description for net.inet6.icmp6.{errppslimit,nd6_maxnudhint}
 1.48 27-Jun-2000  mrg <vm/vm_param.h> is now <uvm/uvm_param.h>
 1.47 23-May-2000  itojun branches: 1.47.4;
correct FILES section. mention IPv6/IPsec headers.
 1.46 08-Apr-2000  soren Update usage with -f.
 1.45 12-Mar-2000  tsarna Add a "-f file" flag to process directives from a file.
 1.44 27-Feb-2000  itojun add hw.alignbytes sysctl mib. this gives you the value of ALIGNBYTES
at the kernel compilation time (ALIGNBYTES that the kernel uses).
 1.43 26-Feb-2000  itojun remove net.inet6.ip6.nd6_proxyall sysctl.
support "ndp -s <ip6> <mac> proxy" for proxy NDP.
 1.42 17-Feb-2000  fvdl List vfs.generic.usermount in manpage. Don't try to handle machdep.diskinfo
for the i386, thus avoiding a warning message in 'sysctl -a'.
 1.41 15-Feb-2000  thorpej Note net.inet.icmp.errratelimit and net.inet.tcp.rstratelimit.
 1.40 09-Feb-2000  jdolecek Add reference to the include file with TCP sysctl constants. Fixes bin/9378.
 1.39 06-Feb-2000  fair Document KERN_LOGSIGEXIT.
sort sysctl variable list in sysctl.8
 1.38 17-Jan-2000  itojun Moved from usr.sbin/sysctl/sysctl.8,v
 1.37 06-Jan-2000  itojun make IPV6_BINDV6ONLY setsockopt available. it controls behavior of
AF_INET6 wildcard listening socket. heavily documented in ip6(4).
net.inet6.ip6.bindv6only defines default value. default is 1.

"options INET6_BINDV6ONLY" removes any code fragment that supports
IPV6_BINDV6ONLY == 0 case (not defopt'ed as use of this is rare).
 1.36 06-Jan-2000  itojun add missing variables under net.inet6.ip6.
 1.35 02-Jan-2000  itojun add net.inet6.icmp6.nodeinfo sysctl.
this allows you to disable/enable ICMPv6 node information query/reply
processing (which tells remote end the gethostname(3) setting, interface
addresses on the node, and some other things - documented in
draft-ietf-ipngwg-icmp-name-lookup* or something alike).

to test it, try ping6 -w ::1 with nodeinfo=0 and nodeinfo=1.
(sync with kame change)
 1.34 17-Dec-1999  garbled Fix some minor typos and word usage nits.
 1.33 18-Nov-1999  kristerw Typos (from OpenBSD)
 1.32 14-Oct-1999  jdolecek document ddb.fromconsole & DBCTL_FROMCONSOLE, description taken from options(4)
 1.31 28-Sep-1999  bouyer Add handling of the proc hierarchy. Document it, as well as kern.defcorename.
 1.30 02-Jul-1999  itojun branches: 1.30.2;
IPv6/IPsec sysctl MIB support.
 1.29 23-May-1999  ad Add new sysctl (net.inet.tcp.log_refused) that when set, causes refused TCP
connections to be logged.
 1.28 26-Apr-1999  thorpej Add support for kern.mbuf.*
 1.27 28-Mar-1999  kleink Forgot to add these a while ago.
 1.26 10-Sep-1998  mouse Create tcp.keepidle, tcp.keepintvl, tcp.keepcnt, tcp.slowhz sysctls.
 1.25 28-Jun-1998  nathanw Document shortcorename support and control.
 1.24 24-May-1998  kleink Permit checking the availability of the POSIX File Synchronization Option
(a/k/a fsync(2)), System V style message queues, semaphores and shared memory
at runtime by adding a sysctl variable for each.
 1.23 02-May-1998  thorpej Note net.inet.tcp.ack_on_push.
 1.22 30-Apr-1998  thorpej Note the existence of net.inet.ip.mtudisctimeout.
 1.21 30-Apr-1998  thorpej Note the presence of net.inet.tcp.: mssdflt, sack, win_scale, timestamps,
compat_42, cwm, cwm_burstsize.
 1.20 13-Apr-1998  kml Fix to ensure that the correct MSS is advertised for loopback
TCP connections by using the MTU of the interface. Also added
a knob, mss_ifmtu, to force all connections to use the MTU of
the interface to calculate the advertised MSS.
 1.19 06-Feb-1998  perry macroize BSD, NetBSD, FreeBSD and misc cleanup
 1.18 05-Jan-1998  lukem document net.inet.ip.anonport{min,max}
 1.17 11-Dec-1997  thorpej Mention net.inet.tcp.init_win.
 1.16 11-Dec-1997  thorpej Fix a paste-o.
 1.15 18-Oct-1997  kml branches: 1.15.2;
change sysctl net.inet.icmp.mtudisc to net.inet.ip.mtudisc
 1.14 17-Oct-1997  thorpej Note net.inet.ip.subnetsarelocal.
 1.13 19-Sep-1997  leo Commit userland part of pr-1891.
 1.12 28-Jul-1997  thorpej Document new UDP and TCP tunables.
 1.11 06-Jun-1997  veego Update the manpage for hw.machine_arch.
 1.10 29-May-1997  cgd Fix broken uses of Dd. Both the mdoc and mdoc.samples pages agree:
.Dd is supposed to be invoked like:
.Dd month day, year
e.g. ".Dd January 25, 1989", rather than:
.Dd "month day, year"
which is what these pages did.
 1.9 23-Apr-1997  cjs added net.inet.ip.allowsrcrt
 1.8 09-Jan-1997  thorpej Grok and document CTL_DDB.
 1.7 17-Jul-1996  explorer Document the new autonice sysctls
 1.6 16-Jan-1996  thorpej Add a net.inet.ip.directed-broadcast sysctl as suggested by
Darren Reed <darrenr@vitruvius.arbld.unimelb.edu.au> in PR #1227.
This change is slightly different than the one submitted by Darren in
that the DIRECTED_BROADCAST compile-time option will behave like it used
to so that existing configurations utilizing it won't have to change.
 1.5 15-Jan-1996  thorpej Add net.inet.ip.forwsrcrt: if zero, the system will not forward
source-routed packets. Note this value is protected by kernel security
level; it can only be changed if securelevel < 1.
 1.4 30-Sep-1995  thorpej New-style RCS ids.
 1.3 30-Sep-1995  thorpej Add support for the net.inet.tcp sysctl group and document. From
John Kohl <jtk@kolvir.blrc.ma.us>.
 1.2 04-Aug-1995  thorpej Mention the `kern.maxpartitions' and `kern.rawpartition' variables.
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 09-May-1994  cgd sysctl-of-fish
 1.15.2.1 11-Dec-1997  thorpej Pull up from trunk: fix paste-o.
 1.30.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.47.4.9 15-Mar-2003  he Pull up revision 1.79 (via patch, requested by msaitoh in ticket #18):
Document vfs.nfs.iothreads.
 1.47.4.8 07-Jun-2001  he Apply patch (requested by he):
Typo correction; add a plural ``s'' to ``maxfragpacket''.
 1.47.4.7 24-Apr-2001  he Pull up revision 1.66 (requested by itojun):
Introduce net.inet.ip.maxfragpackets, which controls the maximum
number of IPv4 fragment reassembly queue entries. Defends against
certain DoS attacks.
 1.47.4.6 26-Feb-2001  he Um, undo one more commit done in error.
 1.47.4.5 26-Feb-2001  he Pull up revisions 1.62-1.63 (requested by hubertf):
Document the vendor.* sysctl branch, and note that we currently
have no registry for these sysctl values.
 1.47.4.4 26-Sep-2000  jdolecek pullup rev. 1.56 (approved by thorpej):
fix typo (remplaced --> replaced)
 1.47.4.3 27-Aug-2000  itojun pullup (approved by releng-1-5)

> implement net.inet6.ip6.{anon,low}port{min,max} sysctl variable.

> cvs rdiff -r1.67 -r1.68 basesrc/lib/libc/gen/sysctl.3
> cvs rdiff -r1.53 -r1.54 basesrc/sbin/sysctl/sysctl.8
> cvs rdiff -r1.18 -r1.19 syssrc/sys/netinet6/in6.h
> cvs rdiff -r1.29 -r1.30 syssrc/sys/netinet6/in6_pcb.c
> cvs rdiff -r1.3 -r1.4 syssrc/sys/netinet6/in6_src.c
> cvs rdiff -r1.25 -r1.26 syssrc/sys/netinet6/ip6_input.c
> cvs rdiff -r1.14 -r1.15 syssrc/sys/netinet6/ip6_var.h
 1.47.4.2 27-Aug-2000  itojun pullup (approved by releng-1-5)
> document net.inet.ip.lowport{min,max}
> cvs rdiff -r1.66 -r1.67 basesrc/lib/libc/gen/sysctl.3
> cvs rdiff -r1.52 -r1.53 basesrc/sbin/sysctl/sysctl.8
 1.47.4.1 16-Aug-2000  itojun pullup (approved by releng-1-5)

document *ppslimit.

sbin/sysctl/sysctl.8 1.48 -> 1.52
lib/libc/gen/sysctl.3 1.60 -> 1.63, 1.64 -> 1.65
 1.77.2.1 30-May-2002  tv Pull up revision 1.79 (requested by msaitoh in ticket #81):
document vfs.nfs.iothreads
 1.111.2.2 04-Jun-2007  bouyer Pull up following revision(s) (requested by adrianp in ticket #11330):
sys/netinet6/ip6_input.c: revision 1.102 via patch
sys/netinet6/route6.c: revision 1.18 via patch
sys/netinet6/ip6_var.h: revisions 1.41-1.42 via patch
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
 1.111.2.1 12-Nov-2004  jmc branches: 1.111.2.1.2;
Pullup rev 1.116 (requested by daniel in ticket #926)

Add vm.bufcache, vm.bufmem, vm.bufmem_lowater, m.bufmem_hiwater
 1.111.2.1.2.2 04-Jun-2007  bouyer Pull up following revision(s) (requested by adrianp in ticket #11330):
sys/netinet6/ip6_input.c: revision 1.102 via patch
sys/netinet6/route6.c: revision 1.18 via patch
sys/netinet6/ip6_var.h: revisions 1.41-1.42 via patch
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
 1.111.2.1.2.1 18-Jun-2005  riz branches: 1.111.2.1.2.1.2;
Pull up revision 1.118 (requested by peter in ticket #1998):
PR/28782: OBATA Akio: Document that kern.rtc_offset is writable.
 1.111.2.1.2.1.2.1 04-Jun-2007  bouyer Pull up following revision(s) (requested by adrianp in ticket #11330):
sys/netinet6/ip6_input.c: revision 1.102 via patch
sys/netinet6/route6.c: revision 1.18 via patch
sys/netinet6/ip6_var.h: revisions 1.41-1.42 via patch
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
 1.118.2.5 26-Apr-2007  ghen Pull up following revision(s) (requested by christos in ticket #1766):
sys/netinet6/ip6_input.c: revision 1.102 via patch
sys/netinet6/route6.c: revision 1.18 via patch
sys/netinet6/ip6_var.h: revision 1.41 via patch
sys/netinet6/ip6_var.h: revision 1.42 via patch
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
fix typo.
 1.118.2.4 10-Jun-2005  tron branches: 1.118.2.4.2; 1.118.2.4.4;
Pull up revision 1.122 (requested by elad in ticket #389):
Bump date for previous. <> -> *[Lt]*[Gt].
 1.118.2.3 10-Jun-2005  tron Pull up revision 1.121 (requested by elad in ticket #389):
Add man-page bits about the 'count' node.
 1.118.2.2 10-Jun-2005  tron Pull up revision 1.120 (requested by elad in ticket #389):
Remove common code for returning supported fingerprints. This is done now
via sysctl(8) using kern.veriexec.algorithms.
Also add an entry for the 'algorithms' variable in sysctl.8 forgotten in
the last commit.
 1.118.2.1 10-Jun-2005  tron Pull up revision 1.119 (requested by elad in ticket #389):
Some changes in veriexec.
New features:
- Add a veriexec_report() routine to make most reporting consistent and
remove some common code.
- Add 'strict' mode that controls how veriexec behaves.
- Add sysctl knobs:
o kern.veriexec.verbose controls verbosity levels. Value: 0, 1.
o kern.veriexec.strict controls strict level. Values: 0, 1, 2. See
documentation in sysctl(3) for details.
o kern.veriexec.algorithms returns a string with a space separated
list of supported hashing algorithms in veriexec.
- Updated documentation in man pages for sysctl(3) and sysctl(8).
Bug fixes:
- veriexec_removechk(): Code cleanup + handle FINGERPRINT_NOTEVAL
correctly.
- exec_script(): Don't pass 0 as flag when executing a script; use the
defined VERIEXEC_INDIRECT - which is 1. Makes indirect execution
enforcement work.
- Fix some printing formats and types..
 1.118.2.4.4.1 26-Apr-2007  ghen Pull up following revision(s) (requested by christos in ticket #1766):
sys/netinet6/ip6_input.c: revision 1.102 via patch
sys/netinet6/route6.c: revision 1.18 via patch
sys/netinet6/ip6_var.h: revision 1.41 via patch
sys/netinet6/ip6_var.h: revision 1.42 via patch
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
fix typo.
 1.118.2.4.2.1 26-Apr-2007  ghen Pull up following revision(s) (requested by christos in ticket #1766):
sys/netinet6/ip6_input.c: revision 1.102 via patch
sys/netinet6/route6.c: revision 1.18 via patch
sys/netinet6/ip6_var.h: revision 1.41 via patch
sys/netinet6/ip6_var.h: revision 1.42 via patch
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
fix typo.
 1.149.2.2 08-Sep-2006  rpaulo Pull up following revision(s) (requested by liamjfoy in ticket #127):
lib/libc/gen/sysctl.3: revision 1.181
sbin/sysctl/sysctl.8: revision 1.152
add net.inet.ip.maxflows. Bump date.
document net.inet.ip.maxflows. dump date.
 1.149.2.1 12-Aug-2006  riz Pull up following revision(s) (requested by kardel in ticket #14):
sbin/sysctl/sysctl.8: revision 1.150 - 1.151
document timecounter sysctls
Bump date for previous.
 1.156.2.1 28-Apr-2007  bouyer Pull up following revision(s) (requested by christos in ticket #587):
sys/netinet6/ip6_input.c: revision 1.102
sys/netinet6/route6.c: revision 1.18
sys/netinet6/ip6_var.h: revision 1.41
sys/netinet6/ip6_var.h: revision 1.42
sbin/sysctl/sysctl.8: patch
Disable processing of routing header type 0 packets since they can be used
of DoS attacks. Provide a sysctl to re-enable them (net.inet6.ip6.rht0).
Information from:
http://www.secdev.org/conf/IPv6_RH_security-csw07.pdf
fix typo.
 1.157.14.1 18-May-2008  yamt sync with head.
 1.157.12.2 17-Jan-2009  mjf Sync with HEAD.
 1.157.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.158.4.2 01-Apr-2009  snj Pull up following revision(s) (requested by christos in ticket #635):
sbin/sysctl/sysctl.8: revision 1.160
sbin/sysctl/sysctl.c: revision 1.129
Don't print an error with sysctl -w name?=value if name does not exist.
Should be pulled up to 5.0
 1.158.4.1 12-Nov-2008  snj Pull up following revision(s) (requested by reed in ticket #46):
sbin/sysctl/sysctl.8: revision 1.159
lib/libc/gen/sysctl.3: revision 1.195
Reference secmodel_securelevel(9) manual page.
 1.159.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.165 02-Apr-2023  ryo commonize case block
 1.164 02-Apr-2023  ryo don't pass add=1 to print_tree() when displaying by specifying nodes.

For example, "sysctl -w kern.mbuf=" had been displayed extra node names in the MIB.
# sysctl -w kern.mbuf=
kern.mbuf.mbuf.msize = 512
kern.mbuf.mbuf.mclbytes = 2048
:
 1.163 28-Dec-2021  christos kern.hashstat takes too long and it is meaningless here.
 1.162 18-Aug-2019  kamil sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.161 30-Oct-2018  kre branches: 1.161.2;
kern.boottime was changed from a struct timeval to a struct timespec
in January 2009 (the Christos' time merge, when time_t went to 64 bits).

sysctl needs to catch up. (So do other progs, which will happen, eventually,
but most of them are unaffected in any practical way.)

If you are running a system (NetBSD 6 or later) without this change, try
sysctl -nn kern.boottime
and marvel at the result (in theory, seconds.microseconds) most
probably being something like:
jinx$ sysctl -nn kern.boottime
1540801874.999995564
(There is a 1 in 1000 chance your system will have booted
in the interval [0 , 999999] nanoseconds after some second,
in which case this will not be observed. You should get
(almost) the same value after this change - just now it is as
it should be (there should now always be 9 digits after the '.').

On the other hand, if you're on a big-endian 64 bit host (running
64 bit sysctl) you would have always seen 0 for the microseconds field.
That should be fixed by this.

In sysctl(7) also document what we mean by "the time the system booted".

XXX Pullup -8
XXX Pullup -7
XXX Pullup -6 (oops, missed that one...)
 1.160 04-Feb-2018  mrg branches: 1.160.2; 1.160.4;
updates for GCC 6.4:

identd has aliasing violations, use -fno-strict-aliasing.

newfs_msdos's getbpbinfo() has missing {} issues.

sysctl's kern_cp_id() has missing {} issues.
 1.159 13-Apr-2017  christos say ipsec stats are viewable with netstat.
 1.158 31-Jul-2016  dholland branches: 1.158.2;
Apply patch from PR 43587, mostly from martin and kre. When writing a
sysctl variable using ?= fails with EPERM, don't print an error
message.

Ideally setting a sysctl to the same value it already has should also
not fail regardless of permissions, but this would need to be done in
the kernel.
 1.157 13-Dec-2015  christos branches: 1.157.2;
mention ip6addrctl
 1.156 17-Aug-2015  knakahara Add intrctl(8).
 1.155 09-Nov-2014  christos remove debugging
 1.154 09-Nov-2014  christos add handler for /kern/evcnt and print the actual error when failing.
 1.153 16-May-2014  martin Get rid of all sysc_init_field uses - initialize fields directly in C99
notation.
 1.152 16-May-2014  martin Do not loop over children if a node is not marked as CTLTYPE_NODE.
 1.151 10-Jan-2014  christos branches: 1.151.2;
use __func__, EXIT_{SUCCESS,FAILURE}
 1.150 10-Jan-2014  pooka give err() some reason to avoid:
sysctl.c:2713:5: error: zero-length gnu_printf format string [-Werror=format-zero-length]
 1.149 13-Dec-2012  msaitoh Add missing free() in error path.
 1.148 07-Dec-2012  christos use __BITMAP_TYPE
 1.147 05-Dec-2012  christos fix bug found by clang.
 1.146 01-Dec-2012  christos switch from fd_set to bitmap macros, by popular demand.
 1.145 29-Nov-2012  christos put back line I accidentally deleted.
 1.144 29-Nov-2012  christos add a handler for the reserved port sysctl variable.
 1.143 02-Jun-2012  dsl branches: 1.143.2;
Add support for unsigned decimal values.
 1.142 15-Mar-2012  joerg Add __printflike attribution to use vprintf and friends with an argument
as format string.
 1.141 11-Mar-2012  christos PR/44961: Jukka Ruohonen: for sysctl's with built-in handlers, return OPNOTSUPP
if we don't have handlers instead of using the handler we have and silently
failing on attempts to write a node that cannot be written.
 1.140 12-Feb-2012  christos branches: 1.140.2;
Only print errors when -A or required. Fix the error message to match others.
 1.139 04-Jan-2012  drochner include <netipsec/ipsec.h> rather than <netinet6/ipsec.h> from userland
where possible, for consistency and compatibility to FreeBSD
(exception: KAME specific statistics gathering in netstat(1) and systat(1))
 1.138 29-Aug-2011  joerg branches: 1.138.2;
Use __dead
 1.137 24-Aug-2011  christos Instead of using strncat and re-scanning the strings all the time, use and
append printf function.
 1.136 03-Aug-2011  christos no -A or -a with -q
 1.135 03-Aug-2011  christos allow -q flag to work for reads.
 1.134 16-Apr-2011  christos PR/44864: Paul Ripke: Compile regular expressions on demand and only once.
 1.133 13-Dec-2010  pooka RUMP_ACTION -> RUMPPRG
 1.132 05-Nov-2010  pooka make sysctl(8) work as a rump client
 1.131 11-Apr-2010  mrg implement CTLTYPE_BOOL support. it was entirely missing. HI MATT!
 1.130 30-Sep-2009  elad Remove stale references to the "read only at securelevel [12]" flags in
the documentation and code comments.
 1.129 01-Apr-2009  christos Don't print an error with sysctl -w name?=value if name does not exist.
Should be pulled up to 5.0
 1.128 20-Mar-2009  lukem fix sign-compare issues
 1.127 18-Mar-2009  pgoyette Format the address/offset of hexdump in hex, not decimal.

Addresses my PR bin/41035
 1.126 05-Mar-2009  njoly Add missing free() in machdep_diskinfo().
 1.125 28-Dec-2008  christos branches: 1.125.2;
fix dev_t format.
 1.124 20-Jul-2008  lukem branches: 1.124.2;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.123 29-Apr-2008  martin branches: 1.123.2;
Convert to new 2 clause license
 1.122 21-Dec-2006  elad branches: 1.122.12; 1.122.14;
PR/35304: C J Coleman: Off-by-one nul byte overwrite in mode_bits routine
of sbin/sysctl
 1.121 18-Dec-2006  christos Exit with non-zero on errors.
 1.120 02-Nov-2006  christos branches: 1.120.2;
PR/34965: Nicolas Joly: sysctl(1) small memory leak
 1.119 01-Nov-2006  christos prefix name in kern.drivers
 1.118 15-Oct-2006  christos support printing kern.drivers
 1.117 30-Jul-2006  elad CTLFLAG_READONLY1 and CTLFLAG_READONLY2 were deprecated in earlier commit, remove them here too
 1.116 14-Jul-2006  elad move security.setid_core.* to kern.coredump.setid.*, as requested by yamt@.
 1.115 30-Mar-2006  jnemeth Coverity CID 2784: Add more checks for value==NULL.
 1.114 26-Mar-2006  christos Coverity CID 2763: Add more checks for value==NULL.
 1.113 26-Mar-2006  christos Coverity CID 2764: Avoid null reference
 1.112 22-Mar-2006  christos Coverity CID 786: Avoid NULL dereference.
 1.111 08-Feb-2006  christos detect integer overflow differently. previous change broke negative sysctl
values.
 1.110 05-Feb-2006  christos PR/17441: John F. Woods: integer sysctl does not accept numbers > 0x7fffffff
Use unsigned int in the range comparison, and use strerror() instead of
home brewed error strings.
 1.109 02-Feb-2006  elad - make use of the recently added mode_bits for security.setid_core.mode;
- document setid_core variables.
 1.108 02-Feb-2006  elad add support for parsing file mode bits.

when printed, you'll see something like "0600 (rw-------)", like the
ls output. when reading input you can either specify octal mode (0600)
or chmod-like (u=rw).

ideas from atatat@ and kjk@; okay and lots of help from atatat@.
 1.107 06-Sep-2005  rpaulo Handle net.inet.tcp.debug, net.inet.tcp.debx, net.ns.spp.debug and
net.ns.spp.debx. Bump man page date.
 1.106 28-Aug-2005  rpaulo net.inet?.*.stats are viewable with netstat(1).
 1.105 04-Aug-2005  rpaulo Inform the user that net.bpf.stats and net.bpf.peers are viewable with
netstat(1).
 1.104 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.103 16-Jun-2005  christos Add code to handle cp_id. From atatat.
 1.102 06-Apr-2005  christos PPR/29909: Manuel Bouyer: sysctl dumps core if kern.consdev returns unknown
device. If we cannot determine the device name of the console, print the
console dev_t in hex.
 1.101 28-Mar-2005  christos make sysctl -n print the real console tty name and -nn print the numeric
value.
XXX: -n means don't print name, not numeric. We should stop overloading
it and use a different flag.
 1.100 23-Mar-2005  atatat If a "create" or "destroy" operation succeeds, mark the cached tree as
"stale" so that the next time we try to read or write to it, we can
purge (and refresh) it.

Addresses PR 29222.
 1.99 19-Mar-2005  atatat Fix possible segmentation fault when retrieving descriptions. Thought
I committed this a while ago. I guess the fact that no one filed a pr
meant no one else found it. :)
 1.98 18-Mar-2005  atatat Use regexes instead of static lists of annoying numbers to recognize
sysctl nodes that have "helpers". This is more concise, imho more
easy to understand, and has the added bonus of making it *possible* to
assign helpers to dynamically numbered nodes.
 1.97 15-Mar-2005  atatat branches: 1.97.2;
Make requestors of kern.file2 be referred to pstat (the same as
kern.file) and add EINVAL to the list of errno values which are
silently ignored when walking the tree.
 1.96 17-Dec-2004  atatat Pass dynamic buffer pointer to display_string(), not static buffer
pointer. Causes...misfunction if the kernel says the buffer needs to
be too much larger.
 1.95 17-Oct-2004  jdolecek constify handlers[]
 1.94 25-Apr-2004  atatat When converting a string to a number, also make sure that you didn't
convert an empty string to a zero.

Follow on to PR bin/25115 in private email.
 1.93 23-Apr-2004  atatat Allocate adjusted size, not fixed size.
 1.92 22-Apr-2004  atatat Some lint cleaning, strip leading (and sometimes trailing) whitespace
from values to be assigned when processing a file. Clean up error
reporting (print the name of the file and the line number), and tidy
some numeric conversions. Continue after most "errors" when
processing a -f argument.

Addresses PR bin/25115.
 1.91 14-Apr-2004  atatat If the node was specifically requested but has no description, print
the "no description" message instead of skipping (as happens when
recursing into a subtree). This does not apply to non-node-type
nodes.
 1.90 08-Apr-2004  atatat Don't copy the size that sysctl gave back directly, copy the size of
the description. *thwap*
 1.89 08-Apr-2004  atatat Don't copy the size that sysctl gave back directly, copy the size of
the description.
 1.88 08-Apr-2004  atatat Do nothing else for nodes with no children if -d is used (dflag is
set). Otherwise, some nodes (those with "printers") will also print
the "use foo ..." message.
 1.87 06-Apr-2004  atatat Add -d flag to usage message(s).
 1.86 26-Mar-2004  he branches: 1.86.2;
Make this too gcc2-compileable.
 1.85 25-Mar-2004  atatat Move sysctlbyname(), sysctlnametomib(), and sysctlgetmibinfo() from
sysctl(8) into libc, making the minor number jump. Add prototypes to
sys/sysctl.h, fix sets, modify man pages, etc. That oughta cover it.
 1.84 24-Mar-2004  atatat Implement sysctl descriptions. Now all that remains is actually to
write them.
 1.83 24-Mar-2004  atatat Tango on sysctl_createv() and flags. The flags have all been renamed,
and sysctl_createv() now uses more arguments.
 1.82 20-Mar-2004  atatat A little syntactic sugar
 1.81 20-Feb-2004  atatat Make this:

% sysctl -A kern.cp_time

(and also "sysctl -A" without the kern.cp_time argument) print this:

kern.cp_time: user = 851648, nice = 683496, sys = 69383, ...
kern.cp_time.0: user = 85648, nice = 68496, sys = 6983, ...
...

instead of just:

kern.cp_time.0: user = 85648, nice = 68496, sys = 6983, ...
...
 1.80 19-Feb-2004  atatat More better display of kern.cp_time for MP machines. Now we use one
sysctl() call to query for each of three different display modes:

(1) sum across all cpus

% sysctl kern.cp_time
kern.cp_time: user = 93240, nice = 1507, sys = 17252, ...

(2) data for just cpu 0

% sysctl kern.cp_time.0
kern.cp_time.0: user = 93282, nice = 1507, sys = 17264, ...

(3) each cpu individually up to hw.ncpu

% sysctl -A kern.cp_time
kern.cp_time.0: user = 93349, nice = 1507, sys = 17280, ...
kern.cp_time.1: user = 93403, nice = 1507, sys = 17291, ...
...
 1.79 19-Feb-2004  atatat Miscellaneous display bugfixes.
 1.78 19-Feb-2004  atatat Rename sysctlnametomib() to sysctlgetmibinfo() and add FreeBSD
compatible sysctlnametomib() and sysctlbyname() functions.

These are intended to move to libc real soon now.
 1.77 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.76 04-Dec-2003  atatat sysctlnametomib() is a private function for the moment.
 1.75 04-Dec-2003  atatat New sysctl(8) binary. Performs auto-discovery and can add/remove
nodes from the tree. Never needs to be recompiled again.
 1.74 10-Nov-2003  jonathan Make per-protocol network input queue stats visible to userland via
sysctl. Add a protocol-independent sysctl handler to show the per-protocol
"struct ifq' statistics. Add IP(v4) specific call to the handler.
Other protocols can show their per-protocol input statistics by
allocating a sysclt node and calling sysctl_ifq() with their own struct ifq *.

As posted to tech-kern plus improvements/cleanup suggested by Andrew Brown.
 1.73 21-Sep-2003  wiz Combine multiple single-letter options.
 1.72 20-Sep-2003  grant add -e flag to set the separator to '=' where the default is ' = '.
this allows sysctl output to fed back into itself. inspired by
FreeBSD's sysctl(8).

ok'd by atatat.
 1.71 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.70 17-Jun-2003  simonb Remove the KERN_DRIVERS case handler (prototype code?).
 1.69 16-Jun-2003  dsl Print hw.cnmagic as escaped hex bytes (unless -n given).
Change 'special' to be a numeral not a bit, it isn't ever used as a bit
and I can't see why it should ever be used that way.
 1.68 31-May-2003  thorpej Avoid a strict-alias warning in gcc 3.3.
 1.67 18-May-2003  itojun simplify more
 1.66 18-May-2003  itojun simplify by strlcpy/cat
 1.65 06-Apr-2003  lukem Tweak behaviour introduced in rev 1.50;
* by default, warning messages go to stderr
* if -A or -a is used, send warning messages to stdout instead.

The behaviour in 1.50 meant that
somevar=`sysctl -n machdep.booted_kernel 2>/dev/null`
could end up with $somevar="machdep.booted_kernel: the value is not available"
rather than the more useful $somevar="".

(This way, "sysctl -A | grep ..." is still useful.)
 1.64 07-Mar-2003  fvdl Quell formwat warning for LP64 for the diskinfo printf.
 1.63 22-Jan-2003  dsl display machdep.diskinfo for i386 and x86_84
(agreed by christos)
 1.62 24-Dec-2002  manu On Darwin, mach_init is the system bootstrap process. It is responsible
for forking the traditional UNIX init(8) and it does the Mach port naming
service. We need mach_init for the naming service, but unfortunately, it
will only act as such if its PID is 1. We introduce a sysctl
(emul.darwin.init_pid) to fool a given process into thinking its PID is 1.
That way we can get mach_init into behaving as the name server.

Typical use:
/sbin/sysctl -w emul.darwin.init_pid=$$ ; exec /emul/darwin/sbin/mach_init
 1.61 30-Nov-2002  lukem tweaks for fparseln(3) move from libutil to libc:
- remove #include <util.h> if nothing else needed it
- remove LDFLAGS+=-lutil if nothing else needed it
 1.60 09-Nov-2002  manu Added sysctl to change all IRIX kernel values reported by uname and systeminfo:
OS name, hw name, kernel version, and so forth.
 1.59 03-Nov-2002  simonb When printing out nodes of type "string", don't print anything if
sysctl() reports that 0 bytes were returned.

Reported by Matt Green with "sysctl hw.disknames" on a system with no
disks.
 1.58 24-Mar-2002  sommerfeld branches: 1.58.2;
Add -q flag, for use with -w and -f, which suppresses output after a set.
 1.57 20-Mar-2002  christos remove debugging line.
 1.56 20-Mar-2002  christos handle new emulation sysctls, and cleanup function duplication.
 1.55 31-Jan-2002  christos fix inconsistencies with USEAPP; centralize the flags check so that we
don't have to deal with it in the future.
 1.54 28-Jan-2002  simonb Descend into kern.tkstat.
 1.53 28-Jan-2002  simonb ANSIfy.
 1.52 27-Jan-2002  simonb Fix a tyop in a comment.
 1.51 27-Jan-2002  simonb Teach sysctl(8) that hw.diskstats is a structure.
 1.50 24-Dec-2001  lukem change a lot of the "error" messages to display to stdout instead of
stderr, so that "sysctl -A" output is actually usable. requested by perry
 1.49 27-Jul-2001  itojun show net.inet6.tcp6.* as mirror image of net.inet.tcp. better for future
INET-less kernels.
 1.48 02-Jul-2001  jdolecek pipe sysctl stuff is now in <sys/pipe.h>
 1.47 16-Jun-2001  jdolecek Add port of high performance pipe implementation written by John S. Dyson
for FreeBSD project. Besides huge speed boost compared with socketpair-based
pipes, this implementation also uses pagable kernel memory instead of mbufs.

Significant differences to FreeBSD version:
* uses uvm_loan() facility for direct write
* async/SIGIO handling correct also for sync writer, async reader
* limits settable via sysctl, amountpipekva and nbigpipes available via sysctl
* pipes are unidirectional - this is enforced on file descriptor level
for now only, the code would be updated to take advantage of it
eventually
* uses lockmgr(9)-based locks instead of home brew variant
* scatter-gather write is handled correctly for direct write case, data
is transferred by PIPE_DIRECT_CHUNK bytes maximum, to avoid running out of kva

All FreeBSD/NetBSD specific code is within appropriate #ifdef, in preparation
to feed changes back to FreeBSD tree.

This pipe implementation is optional for now, add 'options NEW_PIPE'
to your kernel config to use it.
 1.46 09-Mar-2001  chs add UBC memory-usage balancing. we track the number of pages in use for
each of the basic types (anonymous data, executable image, cached files)
and prevent the pagedaemon from reusing a given page if that would reduce
the count of that type of page below a sysctl-setable minimum threshold.
the thresholds are controlled via three new sysctl tunables:
vm.anonmin, vm.vnodemin, and vm.vtextmin. these tunables are the
percentages of pageable memory reserved for each usage, and we do not allow
the sum of the minimums to be more than 95% so that there's always some
memory that can be reused.
 1.45 19-Feb-2001  cgd convert to use getprogname()
 1.44 04-Feb-2001  christos fix nested extern.
 1.43 09-Jan-2001  fvdl Number of toplevel names grew by one, account for it.
 1.42 05-Jan-2001  lukem use %ll_ instead of the less standard %q_
 1.41 19-Jul-2000  enami Free storage allocated by fparseln.
 1.40 15-Jul-2000  simonb Handle KERN_MSGBUF and KERN_CONSDEV gracefully.
 1.39 15-Jul-2000  itojun sync with sys/sysctl.h change (is it the right way to workaround this?)
 1.38 26-Jun-2000  mrg we now need <uvm/uvm_param.h>
 1.37 07-Jun-2000  itojun branches: 1.37.2;
s/PIMCTL/PIM6CTL/ to avoid future confusion.
 1.36 29-May-2000  matt LP64 format problems. u_int64_t on alpha != %llu
 1.35 29-May-2000  simonb cp_time[] is an array of u_int64_t's now.
 1.34 27-May-2000  simonb branches: 1.34.2;
Handle kern.proc_args as well.
 1.33 27-May-2000  simonb s/fprintf(stdout/printf(/
 1.32 27-May-2000  simonb Deal with new structure returning sysctl()s.
 1.31 21-Apr-2000  simonb Fix minor annoyance - when showing the boottime, the ctime() result
already has a trailing newline, so don't add an extra one.
 1.30 14-Apr-2000  simonb Don't declare 'extern opt*' getopt variables.
 1.29 08-Apr-2000  soren Update usage with -f.
 1.28 12-Mar-2000  tsarna Fix warning.
 1.27 12-Mar-2000  tsarna Add a "-f file" flag to process directives from a file.
 1.26 17-Feb-2000  fvdl List vfs.generic.usermount in manpage. Don't try to handle machdep.diskinfo
for the i386, thus avoiding a warning message in 'sysctl -a'.
 1.25 12-Feb-2000  thorpej Support vm.nkmempages.
 1.24 06-Feb-2000  itojun fix include file path.
 1.23 17-Jan-2000  itojun Moved from usr.sbin/sysctl/sysctl.c,v
 1.22 28-Sep-1999  bouyer Add handling of the proc hierarchy. Document it, as well as kern.defcorename.
 1.21 30-Jul-1999  itojun branches: 1.21.2;
do not include sys/netinet6/in6_systm.h, this has been empty.
 1.20 02-Jul-1999  itojun IPv6/IPsec sysctl MIB support.
 1.19 26-Apr-1999  thorpej Add support for kern.mbuf.*
 1.18 13-Nov-1998  thorpej Direct the user to use nfsstat to print nfs statistics.
 1.17 13-Nov-1998  thorpej Implement support for the vfs. toplevel.
 1.16 11-Mar-1998  thorpej Fix typos lossage on the Alpha.
 1.15 05-Mar-1998  tron Include unistd.h to import declaration of getopt(3)
 1.14 05-Mar-1998  christos WARNSify
 1.13 01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.12 06-Feb-1998  jonathan Tell user to use xnptdc to view kern.ntptime, as a workaround until
sysctl and libntp agree about "progname".
Based on a patch suggested by Soren S. Jorvang <soren@t.dk> in PR bin/4433.
 1.11 01-Nov-1997  lukem getopt returns -1 not EOF
 1.10 09-Jan-1997  thorpej Grok and document CTL_DDB.
 1.9 30-Sep-1995  thorpej New-style RCS ids.
 1.8 30-Sep-1995  thorpej Add support for the net.inet.tcp sysctl group and document. From
John Kohl <jtk@kolvir.blrc.ma.us>.
 1.7 07-Jun-1995  cgd typeof(timeval.tv_sec) != time_t
 1.6 02-Jun-1995  pk Correct argument in error msg. (PR #1087)
 1.5 23-Dec-1994  cgd be safe with types
 1.4 18-Sep-1994  mycroft Print tickadj.
 1.3 13-May-1994  cgd re-enable net sysctl code
 1.2 09-May-1994  cgd punt networking goo for now
 1.1 09-May-1994  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 01-Mar-1998  fvdl Import 4.4BSD-Lite2
 1.1.1.1 09-May-1994  cgd sysctl-of-fish
 1.21.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.34.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.37.2.4 10-Nov-2002  itojun sbin/sysctl/sysctl.c 1.59

When printing out nodes of type "string", don't print anything if
sysctl() reports that 0 bytes were returned. Reported by Matt Green.

(simonb)
 1.37.2.3 22-Jul-2000  simonb Pull up rev 1.40:
Handle KERN_MSGBUF and KERN_CONSDEV gracefully.
 1.37.2.2 22-Jul-2000  enami Pullup revision 1.41 (requested by thorpej):
Free storage allocated by fparseln.
 1.37.2.1 15-Jul-2000  itojun pullup 1.38 -> 1.39 (requested by releng-1-5)
sync with sys/sysctl.h change (constify)
 1.58.2.1 15-Nov-2002  lukem Pull up revision 1.59 (requested by simon in ticket #958):
When printing out nodes of type "string", don't print anything if
sysctl() reports that 0 bytes were returned.
Reported by Matt Green with "sysctl hw.disknames" on a system with no
disks.
--
 1.86.2.10 28-Apr-2004  jmc branches: 1.86.2.10.2;
Pullup rev 1.94 (requested by atatat in ticket #192)

When converting a string to a number, also make sure that you didn't
convert an empty string to a zero. PR#25115
 1.86.2.9 26-Apr-2004  jdc Pull up revision 1.93 (requested by atatat in ticket #181)

Allocate adjusted size, not fixed size.
 1.86.2.8 22-Apr-2004  tron Pull up revision 1.92 (requested by atatat in ticket #174):
Some lint cleaning, strip leading (and sometimes trailing) whitespace
from values to be assigned when processing a file. Clean up error
reporting (print the name of the file and the line number), and tidy
some numeric conversions. Continue after most "errors" when
processing a -f argument.
Addresses PR bin/25115.
 1.86.2.7 16-Apr-2004  tron Pull up revision 1.91 (requested by atatat in ticket #136):
If the node was specifically requested but has no description, print
the "no description" message instead of skipping (as happens when
recursing into a subtree). This does not apply to non-node-type
nodes.
 1.86.2.6 08-Apr-2004  jdc Pull up revision 1.90 (requested by atatat in ticket #94)

Don't copy the size that sysctl gave back directly, copy the size of
the description. *thwap*
 1.86.2.5 08-Apr-2004  jdc Pull up revision 1.89 (requested by atatat in ticket #92)

Don't copy the size that sysctl gave back directly, copy the size of
the description.
 1.86.2.4 08-Apr-2004  jdc Backout previous. It contained the changes for both
tickets #92 and #94 (instead of just #92).
 1.86.2.3 08-Apr-2004  jdc Pull up revision 1.89 (requested by atatat in ticket #92)

Don't copy the size that sysctl gave back directly, copy the size of
the description.
 1.86.2.2 08-Apr-2004  jdc Pull up revision 1.88 (requested by atatat in ticket #88)

Do nothing else for nodes with no children if -d is used (dflag is
set). Otherwise, some nodes (those with "printers") will also print
the "use foo ..." message.
 1.86.2.1 07-Apr-2004  jmc Pullup rev 1.87 (requested by atatat in ticket #81)

Add -d flag to usage message(s).
 1.86.2.10.2.1 06-Apr-2005  he Pull up revision 1.96 (requested by atatat in ticket #1048):
Pass dynamic buffer pointer to display_string(), not static
buffer pointer. This fixes a problem if the kernel says the
buffer needs to be too much larger.
 1.97.2.3 23-Mar-2005  tron Pull up revision 1.100 (requested by atatat in ticket #52):
If a "create" or "destroy" operation succeeds, mark the cached tree as
"stale" so that the next time we try to read or write to it, we can
purge (and refresh) it.
Addresses PR 29222.
 1.97.2.2 20-Mar-2005  tron Pull up revision 1.99 (requested by atatat in ticket #36):
Fix possible segmentation fault when retrieving descriptions. Thought
I committed this a while ago. I guess the fact that no one filed a pr
meant no one else found it. :)
 1.97.2.1 19-Mar-2005  tron Pull up revision 1.98 (requested by atatat in ticket #11):
Use regexes instead of static lists of annoying numbers to recognize
sysctl nodes that have "helpers". This is more concise, imho more
easy to understand, and has the added bonus of making it *possible* to
assign helpers to dynamically numbered nodes.
 1.120.2.1 30-Dec-2006  riz Pull up following revision(s) (requested by elad in ticket #298):
sbin/sysctl/sysctl.c: revision 1.122
PR/35304: C J Coleman: Off-by-one nul byte overwrite in mode_bits routine
of sbin/sysctl
 1.122.14.1 18-May-2008  yamt sync with head.
 1.122.12.3 17-Jan-2009  mjf Sync with HEAD.
 1.122.12.2 28-Sep-2008  mjf Sync with HEAD.
 1.122.12.1 02-Jun-2008  mjf Sync with HEAD.
 1.123.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.124.2.2 13-Jan-2013  bouyer Pull up following revision(s) (requested by msaitoh in ticket #1832):
sbin/sysctl/sysctl.c: revision 1.149 via patch
Add missing free() in error path.
 1.124.2.1 01-Apr-2009  snj Pull up following revision(s) (requested by christos in ticket #635):
sbin/sysctl/sysctl.8: revision 1.160
sbin/sysctl/sysctl.c: revision 1.129
Don't print an error with sysctl -w name?=value if name does not exist.
Should be pulled up to 5.0
 1.125.2.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.138.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.138.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.138.2.2 30-Oct-2012  yamt sync with head
 1.138.2.1 17-Apr-2012  yamt sync with head
 1.140.2.1 25-Dec-2012  snj Pull up following revision(s) (requested by msaitoh in ticket #757):
sbin/sysctl/sysctl.c: revision 1.149
Add missing free() in error path.
 1.143.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.143.2.1 25-Feb-2013  tls resync with head
 1.151.2.1 10-Aug-2014  tls Rebase.
 1.157.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.157.2.1 06-Aug-2016  pgoyette Sync with HEAD
 1.158.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.160.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.160.4.1 10-Jun-2019  christos Sync with HEAD
 1.160.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.161.2.1 19-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #95):

sbin/sysctl/prog_ops.h: revision 1.3
sbin/sysctl/sysctl_rumpops.c: revision 1.2
sbin/sysctl/sysctl_hostops.c: revision 1.2
sbin/sysctl/Makefile: revision 1.22
sbin/sysctl/sysctl.c: revision 1.162

sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.2 18-Aug-2019  kamil sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.1 13-Dec-2010  pooka branches: 1.1.46; 1.1.48;
RUMP_ACTION -> RUMPPRG
 1.1.48.1 19-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #95):

sbin/sysctl/prog_ops.h: revision 1.3
sbin/sysctl/sysctl_rumpops.c: revision 1.2
sbin/sysctl/sysctl_hostops.c: revision 1.2
sbin/sysctl/Makefile: revision 1.22
sbin/sysctl/sysctl.c: revision 1.162

sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.1.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 18-Aug-2019  kamil sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.1 13-Dec-2010  pooka branches: 1.1.46; 1.1.48;
RUMP_ACTION -> RUMPPRG
 1.1.48.1 19-Aug-2019  martin Pull up following revision(s) (requested by kamil in ticket #95):

sbin/sysctl/prog_ops.h: revision 1.3
sbin/sysctl/sysctl_rumpops.c: revision 1.2
sbin/sysctl/sysctl_hostops.c: revision 1.2
sbin/sysctl/Makefile: revision 1.22
sbin/sysctl/sysctl.c: revision 1.162

sysctl: Add indirection of symbols to remove clash with sanitizers

Add indirection and symbol renaming under MKSANITIZER for the linked in
version of sysctlbyname and sysctlgetmibinfo.
 1.1.46.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.10 25-Mar-2004  atatat Move sysctlbyname(), sysctlnametomib(), and sysctlgetmibinfo() from
sysctl(8) into libc, making the minor number jump. Add prototypes to
sys/sysctl.h, fix sets, modify man pages, etc. That oughta cover it.
 1.9 24-Mar-2004  atatat Remove #define of __USE_NEW_SYSCTL. I'm not even sure I remember what
I used it for, but we certainly don't need it now.
 1.8 24-Mar-2004  atatat This file should have a copyright notice on it.
 1.7 24-Mar-2004  atatat New node version and layout. This should take care of the netbsd32
emulation problem, formalizes the versioning (should it ever be needed
again), and provides a slot for descriptions.
 1.6 24-Mar-2004  atatat The new sysctl query interface returns the same information as the old
one, but you must pass in an empty node that indicates the version
you're using.
 1.5 24-Mar-2004  atatat Tango on sysctl_createv() and flags. The flags have all been renamed,
and sysctl_createv() now uses more arguments.
 1.4 19-Feb-2004  atatat Rename sysctlnametomib() to sysctlgetmibinfo() and add FreeBSD
compatible sysctlnametomib() and sysctlbyname() functions.

These are intended to move to libc real soon now.
 1.3 19-Feb-2004  atatat Avoid using things that don't smell like they're the right size (the
size should be a multiple of sizeof(struct sysctlnode)), and avoid
leaking memory in the case of things that don't have children.
 1.2 04-Dec-2003  atatat sysctlnametomib() is a private function for the moment.
 1.1 04-Dec-2003  atatat New sysctl(8) binary. Performs auto-discovery and can add/remove
nodes from the tree. Never needs to be recompiled again.
 1.5 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.4 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=3
 1.3 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.2 22-Dec-1994  cgd specify man pages the new way.
 1.1 30-Mar-1994  cgd add 'ttyflags', to set driver specific tty flags
 1.12 06-Oct-2006  elad PR/13478: Greg A. Woods: some tty-related documentation fixes

Patch applied with "minor tweaks" from me, thanks!
 1.11 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.10 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.9 16-Nov-2001  wiz Whitespace nits
 1.8 05-Jun-2001  wiz Drop arguments of .Os.
 1.7 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.6 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.5 06-Apr-1999  pk branches: 1.5.6;
1, 2, 3 and.. 4!
 1.4 24-Nov-1997  lukem branches: 1.4.2;
fix .Nx usage (use 1.0 instead of 0.9a, etc), and other minor cleanups
 1.3 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 30-Mar-1994  cgd add 'ttyflags', to set driver specific tty flags
 1.4.2.1 07-Apr-1999  pk Pull up from trunk: copyright text warts.
 1.5.6.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19 04-May-2014  mrg open the tty with O_RDWR|O_NONBLOCK. it seems valid to ask for
write permission when we're setting flags, and ucom(4) has an
existing workaround for a bug when O_RDWR is not used, and thus
ttyflags would not work for ucom devices.
 1.18 27-Aug-2011  joerg branches: 1.18.2; 1.18.8; 1.18.18;
static + __dead
 1.17 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.16 17-Jan-2007  hubertf branches: 1.16.12; 1.16.16;
Remove more duplicate #includes,
from Slava Semushin <slava.semushin@gmail.com>
 1.15 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=3
 1.14 12-Jul-2003  itojun use strlcat/strlcpy
 1.13 14-Feb-2003  grant 'NetBSD.org' and some mdoc fixes.
 1.12 14-Jun-2000  cgd sweep of my licenses (userland files w/o only my copyright) for
consistency. (no functional changes)
 1.11 14-Jun-2000  cgd fix up NetBSD RCS Ids to match the standard, and the leading comment as
to match as well. No functional changes.
 1.10 20-Oct-1997  scottr branches: 1.10.10;
Add support for DTR/CTS flow control, from Bill Studenmund.
 1.9 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
 1.8 09-Apr-1996  cgd recent changes cause this to require <string.h> for proper prototyping.
Include it.
 1.7 17-Mar-1996  christos Fix PR/2222: ttyflags hex flag printing in verbose mode reflected the
TIOCFLAG_ values not the TTY_ values. Fixed to print the flags as strings
to avoid confusion.
 1.6 13-Aug-1995  cgd don't complain about errors opening 'on' ttys, if the error is ENXIO.
 1.5 23-Apr-1995  cgd slightly clean rcs ids, etc.
 1.4 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.3 19-Apr-1994  cgd don't complain if ENXIO on open and not verbose
 1.2 30-Mar-1994  cgd be a bit smarter when being verbose
 1.1 30-Mar-1994  cgd add 'ttyflags', to set driver specific tty flags
 1.10.10.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.16.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.16.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.18.18.1 10-Aug-2014  tls Rebase.
 1.18.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.18.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.14 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.13 09-Feb-2005  xtraeme WARNS=3.
 1.12 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.11 09-Nov-2001  lukem Change -F from "special must be a regular file" to "special can be any type,
and don't attempt to do any file name translation (e.g, search in fstab)".

In the non -F case, search for special in fstab. If found, convert fs_spec
to a raw device name. In any case, use opendisk(3) to open the device.
 1.10 19-Aug-2001  lukem - add -F; indicates "special" is a file system image in a regular file
- reorder "special" validation to after option parsing
- use getopt(3) instead of homegrown code
- add getnum() to parse and validate a number
- clean up man page
- ansi KNF, WARNS=2
 1.9 15-Jan-1999  bouyer branches: 1.9.4;
#include machine/bswap.h and remove -lutil.
 1.8 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.7 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.6 22-Dec-1994  cgd specify man pages the new way.
 1.5 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.4 31-Jul-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.9.4.1 19-Oct-1999  fvdl Add CPPFLAGS+=-I${.CURDIR}/../../sys for convenience. This should be
reverted before the branch is merged with the trunk.
 1.49 17-Jan-2022  christos update date
 1.48 17-Jan-2022  kim Move the possible optimize_preference values back under the -o flag
 1.47 18-Jun-2020  wiz The ACL flag is -p, not -n.
 1.46 07-Jun-2020  wiz Sort option descriptions.
 1.45 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.44 09-Aug-2014  wiz Bump date for previous. New sentence, new line. Use more markup.
Remove superfluous Pp in list.
 1.43 09-Aug-2014  mlelstv add -S option to adjust the superblock for different sector sizes. While
the kernel ignores this information, userland tools rely on it.

This is needed when moving images between devices of different sector size.
 1.42 03-Dec-2012  wiz Document how to resize the WAPBL log size.
Based on patch by Edgar Fuß <ef@math.uni-bonn.de>.
 1.41 08-Apr-2012  wiz branches: 1.41.2;
Remove unnecessary Bk/Ek pairs from SYNOPSIS.
No effective change except where I used the opportunity to sort options
and/or option descriptions.
 1.40 06-Mar-2011  wiz branches: 1.40.4;
Fix punctuation markup; new sentence, new line.
 1.39 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.38 22-Feb-2009  ad branches: 1.38.2;
PR kern/26878 FFSv2 + softdep = livelock (no free ram)
PR kern/16942 panic with softdep and quotas
PR kern/19565 panic: softdep_write_inodeblock: indirect pointer #1 mismatch
PR kern/26274 softdep panic: allocdirect_merge: ...
PR kern/26374 Long delay before non-root users can write to softdep partitions
PR kern/28621 1.6.x "vp != NULL" panic in ffs_softdep.c:4653 while unmounting a softdep (+quota) filesystem
PR kern/29513 FFS+Softdep panic with unfsck-able file-corruption
PR kern/31544 The ffs softdep code appears to fail to write dirty bits to disk
PR kern/31981 stopping scsi disk can cause panic (softdep)
PR kern/32116 kernel panic in softdep (assertion failure)
PR kern/32532 softdep_trackbufs deadlock
PR kern/37191 softdep: locking against myself
PR kern/40474 Kernel panic after remounting raid root with softdep

Retire softdep, pass 2. As discussed and later formally announced on the
mailing lists.
 1.37 31-Jul-2008  simonb branches: 1.37.4;
Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.36 20-Dec-2004  hubertf branches: 1.36.26; 1.36.30; 1.36.32;
Add comment that there are strings attached to the fish. Beware!
(Source: http://www.livejournal.com/community/unixhistory/1808.html)
 1.35 18-Nov-2004  hubertf Remove (wrong?) default for minfree, xref newfs.8 instead.
Suggested by Ignatios.
 1.34 26-Apr-2004  grant according to newfs(8) and reality, the default minfree value is actually
5%, not 10%. make it so.
 1.33 07-Aug-2003  agc branches: 1.33.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.32 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.31 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.30 21-Dec-2002  wiz dependent only has es, no as; from Adrian Mrva.
 1.29 16-Nov-2001  wiz Sort sections.
 1.28 16-Nov-2001  wiz Whitespace nits
 1.27 09-Nov-2001  lukem Change -F from "special must be a regular file" to "special can be any type,
and don't attempt to do any file name translation (e.g, search in fstab)".

In the non -F case, search for special in fstab. If found, convert fs_spec
to a raw device name. In any case, use opendisk(3) to open the device.
 1.26 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.25 03-Sep-2001  lukem comment the commenting-out, to reduce confusion
 1.24 03-Sep-2001  lukem - rename option `-t trackskew' to `-k trackskew', for consistency with newfs(8)
- add CHANGEVAL() macro, which does the hard work of changing a parameter
- sort options in usage()
- use .ig [ ... ] .. to comment out sections of man pages (instead
of .\" at the start of each line
 1.23 19-Aug-2001  lukem - add -F; indicates "special" is a file system image in a regular file
- reorder "special" validation to after option parsing
- use getopt(3) instead of homegrown code
- add getnum() to parse and validate a number
- clean up man page
- ansi KNF, WARNS=2
 1.22 05-Jun-2001  wiz Drop arguments of .Os.
 1.21 05-Mar-2001  aymeric Move reference to article on soft-updates from tunefs.8 to mount_ffs.8
OK'd by Ignatios.
 1.20 15-Jun-2000  fvdl branches: 1.20.2;
Disable (unifdef for now) tunefs -n <disable|enable>, this is done via
a mount option now.
 1.19 27-Apr-2000  nathanw branches: 1.19.2;
Finish describing what the soft dependancy code does.
Add a reference to the McKusick/Ganger Usenix paper.

Addresses PR#8838.
 1.18 30-Mar-2000  jdolecek State the possible values of optimize_prefernce in description of
-o flag. Fixes bin/9706.
 1.17 28-Jan-2000  wiz reorder long descriptions for arguments to be in alphabetical order.
XXX: shouldn't 'enable' and 'disable' for -n be marked up in some way?
 1.16 15-Nov-1999  fvdl Fix typo.
 1.15 15-Nov-1999  fvdl Update for soft updates code.
 1.14 07-Mar-1999  mycroft branches: 1.14.4; 1.14.8;
Clean up SYNOPSIS formatting.
 1.13 20-Oct-1997  enami Fix .Nm usage.
 1.12 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.11 15-Sep-1997  lukem * fix .Nm usage
* prototype main() to pass WARNS=1
 1.10 27-Dec-1996  mikel oops, missed a comma.
 1.9 26-Dec-1996  mikel eliminate obsolete references to mkfs(8);
from Klaus Klein <kleink@layla.inka.de>
 1.8 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.7 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.6 20-Apr-1994  cgd back to 10%, per mkm
 1.5 12-Apr-1994  cgd documentation, general cleanup. ick.
 1.4 01-Aug-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.14.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.19.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.20.2.2 25-Nov-2001  he Pull up revision 1.26 (requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.20.2.1 25-Nov-2001  he Pull up revisions 1.23-1.25 (requested by lukem):
Add ``-F'' option, and rename ``-t'' option to ``-k''.
 1.33.2.1 29-Apr-2004  jmc Pullup rev 1.34 (requested by grant in ticket #208)

According to newfs(8) and reality, the default minfree value is actually
5%, not 10%.
 1.36.32.2 28-Jul-2008  simonb A wapbl(8) should be a wapbl(4).

Found by wizd.
 1.36.32.1 28-Jul-2008  simonb Add support for creating a WAPBL log in the filesystem. Will
create an in-filesystem log on first "mount -o log" if one doesn't
exist, and will then continue to use same log in the future. See
(soon to be added) wapbl(4) for more info.

Adds a new B_CONTIG low-level allocation flag that uses hints in
"struct ffs_inode_ext" to lay out an ffs file's data contiguously.

Thanks to Greg Oster for helping with the design of this and to
Antti Kantee for code review and suggestions.
 1.36.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.36.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.37.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.38.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.40.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.40.4.1 17-Apr-2012  yamt sync with head
 1.41.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.41.2.1 25-Feb-2013  tls resync with head
 1.58 07-Jan-2023  chs ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:

commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000

This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.

To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.

Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000

One last pass to get all the unsigned comparisons correct.


In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.57 19-Dec-2022  chs tunefs: clarify that "-a" refers to NFSv4 ACLs
 1.56 17-Nov-2022  chs branches: 1.56.2;
Restore backward compatibility of UFS2 with previous NetBSD releases by
disabling support in UFS2 for extended attributes (including ACLs).
Add a new variant of UFS2 called "UFS2ea" that does support extended attributes.
Add new fsck_ffs operations "-c ea" and "-c no-ea" to convert file systems
from UFS2 to UFS2ea and vice-versa (both of which delete all existing extended
attributes in the process).
 1.55 18-Sep-2021  christos Change the default for ACLs to be posix1e instead of nfsv4 to match FreeBSD.
Requested by chuq.
 1.54 26-Nov-2020  dholland Add missing newlines to ACL prints in tunefs; from Jan Schaumann in PR 55824.
 1.53 08-Aug-2020  christos Find the if a device points to an active filesystem by looking at the mount
list.
 1.52 16-May-2020  christos Add ACL support for FFS. From FreeBSD.
 1.51 09-Apr-2020  christos Refresh the superblock in memory if changing a mounted partition.
 1.50 12-Apr-2019  pgoyette Add missing space in "quotas disabled" output from tunefs -N
 1.49 26-Aug-2015  mlelstv branches: 1.49.16;
Use getfsspecname also when not found in /etc/fstab.
 1.48 09-Aug-2014  mlelstv add -S option to adjust the superblock for different sector sizes. While
the kernel ignores this information, userland tools rely on it.

This is needed when moving images between devices of different sector size.
 1.47 26-Apr-2014  martin Provide proper alignement for "buf" - it is casted to a struct fs pointer,
so it requires the same alignement.
Fixes crashes on armv5.
 1.46 23-Jun-2013  dholland branches: 1.46.4;
fsbtodb() -> FFS_FSBTODB(), EXT2_FSBTODB(), or MFS_FSBTODB()
dbtofsb() -> FFS_DBTOFSB() or EXT2_DBTOFSB()

(Christos already did the lfs ones a few days back)
 1.45 07-Apr-2012  christos branches: 1.45.2;
use getfsspecname()
 1.44 29-Aug-2011  joerg branches: 1.44.2;
Use __dead
 1.43 06-Mar-2011  bouyer merge the bouyer-quota2 branch. This adds a new on-disk format
to store disk quota usage and limits, integrated with ffs
metadata. Usage is checked by fsck_ffs (no more quotacheck)
and is covered by the WAPBL journal. Enabled with kernel
option QUOTA2 (added where QUOTA was enabled in kernel config files),
turned on with tunefs(8) on a per-filesystem
basis. mount_mfs(8) can also turn quotas on.

See http://mail-index.netbsd.org/tech-kern/2011/02/19/msg010025.html
for details.
 1.42 13-Sep-2009  bouyer branches: 1.42.2;
Restore change from 1.39 after previous commit.
 1.41 13-Sep-2009  bouyer Allow tunefs to clear any type of WAPBL log, not only in-filesystem
ones. Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.40 17-Aug-2009  bouyer fix pasto: UFS_WAPBL_FLAGS_CREATE_LOG is "create-log" not "clear-log"
 1.39 07-Apr-2009  lukem fix sign-compare issue
 1.38 22-Feb-2009  ad PR kern/26878 FFSv2 + softdep = livelock (no free ram)
PR kern/16942 panic with softdep and quotas
PR kern/19565 panic: softdep_write_inodeblock: indirect pointer #1 mismatch
PR kern/26274 softdep panic: allocdirect_merge: ...
PR kern/26374 Long delay before non-root users can write to softdep partitions
PR kern/28621 1.6.x "vp != NULL" panic in ffs_softdep.c:4653 while unmounting a softdep (+quota) filesystem
PR kern/29513 FFS+Softdep panic with unfsck-able file-corruption
PR kern/31544 The ffs softdep code appears to fail to write dirty bits to disk
PR kern/31981 stopping scsi disk can cause panic (softdep)
PR kern/32116 kernel panic in softdep (assertion failure)
PR kern/32532 softdep_trackbufs deadlock
PR kern/37191 softdep: locking against myself
PR kern/40474 Kernel panic after remounting raid root with softdep

Retire softdep, pass 2. As discussed and later formally announced on the
mailing lists.
 1.37 31-Jul-2008  simonb branches: 1.37.2; 1.37.4; 1.37.6; 1.37.8;
Just use printf(...) instead of fprintf(stdout, ...).
 1.36 31-Jul-2008  simonb Pretty-print the journal log size with humanize_number(3).
 1.35 31-Jul-2008  simonb Merge the simonb-wapbl branch. From the original branch commit:

Add Wasabi System's WAPBL (Write Ahead Physical Block Logging)
journaling code. Originally written by Darrin B. Jewell while
at Wasabi and updated to -current by Antti Kantee, Andy Doran,
Greg Oster and Simon Burge.

OK'd by core@, releng@.
 1.34 20-Jul-2008  lukem branches: 1.34.2;
Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.33 19-Jan-2005  xtraeme branches: 1.33.26; 1.33.30;
Remove main() prototype.
 1.32 25-Jun-2004  wiz Remove removed options from usage. From Kouichirou Hiratsuka in PR 25874.
 1.31 27-Mar-2004  dsl don'e require FS_FLAGS_UPDATED be set for ffsv2
 1.30 21-Mar-2004  dsl When searching for the superblock, don't pick an ffsv1 superblock from the
location where we expect to find an ffsv2 superblock.
It could be the first alternate for a ffsv1 filesystem with 64k blocks.
Fixes part of PR kern/24809
 1.29 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.28 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.27 02-Apr-2003  fvdl Add support for UFS2. UFS2 is an enhanced FFS, adding support for
64 bit block pointers, extended attribute storage, and a few
other things.

This commit does not yet include the code to manipulate the extended
storage (for e.g. ACLs), this will be done later.

Originally written by Kirk McKusick and Network Associates Laboratories for
FreeBSD.
 1.26 09-Nov-2001  lukem move guts of non-F special parsing into separate openpartition() func
 1.25 09-Nov-2001  lukem Change -F from "special must be a regular file" to "special can be any type,
and don't attempt to do any file name translation (e.g, search in fstab)".

In the non -F case, search for special in fstab. If found, convert fs_spec
to a raw device name. In any case, use opendisk(3) to open the device.
 1.24 06-Sep-2001  lukem Incorporate the enhanced ffs_dirpref() by Grigoriy Orlov, as found in
FreeBSD (three commits; the initial work, man page updates, and a fix
to ffs_reload()), with the following differences:
- Be consistent between newfs(8) and tunefs(8) as to the options which
set and control the tuning parameters for this work (avgfilesize & avgfpdir)
- Use u_int16_t instead of u_int8_t to keep track of the number of
contiguous directories (suggested by Chuck Silvers)
- Work within our FFS_EI framework
- Ensure that fs->fs_maxclusters and fs->fs_contigdirs don't point to
the same area of memory

The new algorithm has a marked performance increase, especially when
performing tasks such as untarring pkgsrc.tar.gz, etc.

The original FreeBSD commit messages are attached:

=====
mckusick 2001/04/10 01:39:00 PDT
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.

------

One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.

First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:

1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35

2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50

You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html

Test Results

tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66

"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.

------

Algorithm description

The old dirpref algorithm is described in comments:

/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/

A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.

What I mean by a big file system ?

1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.

The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.

My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/

My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.

My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.

The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:

int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */

These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.

I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.

Obtained from: Grigoriy Orlov <gluk@ptci.ru>
=====

=====
iedowse 2001/04/23 17:37:17 PDT
Pre-dirpref versions of fsck may zero out the new superblock fields
fs_contigdirs, fs_avgfilesize and fs_avgfpdir. This could cause
panics if these fields were zeroed while a filesystem was mounted
read-only, and then remounted read-write.

Add code to ffs_reload() which copies the fs_contigdirs pointer
from the previous superblock, and reinitialises fs_avgf* if necessary.

Reviewed by: mckusick
=====

=====
nik 2001/04/10 03:36:44 PDT
Add information about the new options to newfs and tunefs which set the
expected average file size and number of files per directory. Could do
with some fleshing out.
=====
 1.23 03-Sep-2001  lukem - rename option `-t trackskew' to `-k trackskew', for consistency with newfs(8)
- add CHANGEVAL() macro, which does the hard work of changing a parameter
- sort options in usage()
- use .ig [ ... ] .. to comment out sections of man pages (instead
of .\" at the start of each line
 1.22 19-Aug-2001  lukem - add -F; indicates "special" is a file system image in a regular file
- reorder "special" validation to after option parsing
- use getopt(3) instead of homegrown code
- add getnum() to parse and validate a number
- clean up man page
- ansi KNF, WARNS=2
 1.21 17-Aug-2001  lukem remove third argument (`int ns') from ffs_sb_swap(), and let ffs_sb_swap()
determine the endianness of the `struct fs *o' superblock from o->fs_magic
and set needswap as necessary, rather than trusting the caller to get
it right. invariably, almost every caller of ffs_sb_swap() was calling it
with ns set to the wrong value for ns anyway!
ansi KNF ffs_bswap.c declarations whilst here.

this fixes all sorts of problems when trying to use other-endian file systems,
notably the kernel trying to access memory *way* off, possibly corrupting or
panicing, and userland programs SEGVing and/or corrupting things (e.g,
"fsck_ffs -B" to swap a file system endianness).

whilst the previous rev of ffs_bswap.c (1.10, 2000/12/23) made this problem
worse, i suspect that the problem was always there and previous versions
just happened not to trash things at the wrong time.

FFS_EI should now be a lot more stable.
 1.20 15-Jun-2000  fvdl branches: 1.20.2;
Disable (unifdef for now) tunefs -n <disable|enable>, this is done via
a mount option now.
 1.19 15-Nov-1999  fvdl branches: 1.19.2;
Update for soft updates code.
 1.18 15-Jan-1999  bouyer branches: 1.18.4; 1.18.8;
#include machine/bswap.h and remove -lutil.
 1.17 25-Aug-1998  ross from Erik Bertelsen <erik@mediator.uni-c.dk>
{ put } { in } { lots } { of } { these } { to } { shut } { up } { egcs }
 1.16 28-Jul-1998  mycroft __AUDIT__ cleanup.
 1.15 26-Jul-1998  mycroft const poisoning.
 1.14 26-Mar-1998  thorpej Need <string.h> for memcpy() prototype.
 1.13 18-Mar-1998  bouyer Add support for non-native byteorder FFS.
 1.12 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.11 15-Sep-1997  lukem * fix .Nm usage
* prototype main() to pass WARNS=1
 1.10 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.9 30-Jan-1995  mycroft Use S_IS*().
 1.8 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.7 20-Apr-1994  cgd back to 10%, per mkm
 1.6 12-Apr-1994  cgd documentation, general cleanup. ick.
 1.5 12-Apr-1994  cgd off_t casts, from Thomas Eberhardt
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.18.4.1 19-Oct-1999  fvdl Bring in Kirk McKusick's FFS softdep code on a branch.
 1.19.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.20.2.3 25-Nov-2001  he Pull up revision 1.24 (requested by lukem):
Pull in enhanced ffs_dirpref() algorithm, which provides a
substantial performance improvement through better locality
between parent/child directories and their files, and by easing
the pressure on the buffer cache for metadata operations.
 1.20.2.2 25-Nov-2001  he Pull up revisions 1.22-1.23 (requested by lukem):
Add ``-F'' option, and rename ``-t'' option to ``-k''.
 1.20.2.1 25-Nov-2001  he Pull up revision 1.21 (requested by lukem):
Call ffs_sb_swap() with the correct arguments. Fixes problems
with using other-endian file systems.
 1.33.30.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.33.26.1 28-Sep-2008  mjf Sync with HEAD.
 1.34.2.3 28-Jul-2008  simonb Fix a printf(3) format.

Noticed by martin@.
 1.34.2.2 28-Jul-2008  simonb Add support for creating a WAPBL log in the filesystem. Will
create an in-filesystem log on first "mount -o log" if one doesn't
exist, and will then continue to use same log in the future. See
(soon to be added) wapbl(4) for more info.

Adds a new B_CONTIG low-level allocation flag that uses hints in
"struct ffs_inode_ext" to lay out an ffs file's data contiguously.

Thanks to Greg Oster for helping with the design of this and to
Antti Kantee for code review and suggestions.
 1.34.2.1 20-Jul-2008  simonb file tunefs.c was added on branch simonb-wapbl on 2008-07-28 12:40:06 +0000
 1.37.8.1 21-Apr-2010  matt sync to netbsd-5
 1.37.6.1 25-Aug-2009  snj Pull up following revision(s) (requested by bouyer in ticket #917):
sbin/tunefs/tunefs.c: revision 1.40
fix pasto: UFS_WAPBL_FLAGS_CREATE_LOG is "create-log" not "clear-log"
 1.37.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.37.2.2 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1036):
sbin/fsck_ffs/extern.h: revision 1.25 via patch
sbin/fsck_ffs/setup.c: revision 1.88 via patch
sbin/fsck_ffs/wapbl.c: revision 1.4 via patch
sbin/tunefs/tunefs.c: revision 1.41 via patch
sys/ufs/ffs/ffs_vfsops.c: revision 1.252 via patch
sys/ufs/ffs/ffs_wapbl.c: revision 1.13 via patch
Allow tunefs to clear any type of WAPBL log, not only in-filesystem
ones. Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
Do some basic checks of the WAPBL journal, to abort the boot before the
kernel refuse to mount a filesystem read-write (booting a system
multiuser with critical filesystems read-only is bad):
Add a check_wapbl() which will check some WAPBL values in the superblock,
and try to read the journal via wapbl_replay_start() if there is one.
pfatal() if one of these fail (abort boot if in preen mode,
as "CONTINUE" otherwise). In non-preen mode the bogus journal will
be cleared.
check_wapbl() is always called if the superblock supports WAPBL.
Even if FS_DOWAPBL is not there, there could be flags asking the
kernel to clear or create a log with bogus values which would cause the
kernel refuse to mount the filesystem.
Discussed in
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
--
If the WAPBL journal can't be read (ffs_wapbl_replay_start() fails),
mount the filesystem anyway if MNT_FORCE is present.
This allows to still boot single-user a system with a corrupted
WAPBL on /, and so get a chance to run fsck to fix it.
http://mail-index.netbsd.org/tech-kern/2009/08/17/msg005896.html
and followups.
 1.37.2.1 25-Aug-2009  snj Pull up following revision(s) (requested by bouyer in ticket #917):
sbin/tunefs/tunefs.c: revision 1.40
fix pasto: UFS_WAPBL_FLAGS_CREATE_LOG is "create-log" not "clear-log"
 1.42.2.1 20-Jan-2011  bouyer Snapshot of work in progress on a modernised disk quota system:
- new quotactl syscall (versionned for backward compat), which takes
as parameter a path to a mount point, and a prop_dictionary
(in plistref format) describing commands and arguments.
For each command, status and data are returned as a prop_dictionary.
quota commands features will be added to take advantage of this,
exporting quota data or getting quota commands as plists.

- new on disk-format storage (all 64bit wide), integrated to metadata for
ffs (and playing nicely with wapbl).
Quotas are enabled on a ffs filesystem via superblock flags.
tunefs(8) can enable or disable quotas.
On a quota-enabled filesystem, fsck_ffs(8) will track per-uid/gid
block and inode usages, and will check and update quotas in Pass 6.
quota usage and limits are stored in unliked files (one for users,
one for groups)l fsck_ffs(8) will create the files if needed, or
free them if needed. This means that after enabling or disabling
quotas on a filesystem; a fsck_ffs(8) run is required.
quotacheck(8) is not needed any more, on a unclean shutdown
fsck or journal replay will take care of fixing quotas.
newfs(8) can create a ready-to-mount quota-enabled filesystem
(superblock flags are set and quota inodes are created).
Other new features or semantic changes:
- default quota datas, applied to users or groups which don't already
have a quota entry
- per-user/group grace time (instead of a filesystem global one)
- 0 really means "nothing allowed at all", not "no limit".
If you want "no limit", set the limit to UQUAD_MAX (tools will
understand "unlimited" and "-")

A quota file is structured as follow:
it starts with a header, containing a few per-filesystem values,
and the default quota limits.
Quota entries are linked together as a simple list, each entry has a
pointer (as an offset withing the file) to the next.
The header has a pointer to a list of free quota entries, and
a hash table of in-use entries. The size of the hash table depends
on the filesystem block size (header+hash table should fit in the
first block). The file is not sparse and is a multiple of
filesystem block size (when the free quota entry list is empty a new
filesystem block is allocated). quota entries to not cross
filesystem block boundaries.

In memory, the kernel keeps a cache of recently used quota entries
as a reference to the block number, and offset withing the block.
The quota entry itself is keept in the buf cache.

fsck_ffs(8), tunefs(8) and newfs(8) supports are completed (with
related atf tests :)
The kernel can update disk usage and report it via quotactl(2).

Todo: enforce quotas limits (limits are not checked by kernel yet)
update repquota, edquota and rpc.rquotad to the new world
implement compat_50_quotactl ioctl.
update quotactl(2) man page

fsck_ffs required fixes so that allocating new blocks or inodes will
properly update the superblock and cg sumaries. This was not an issue up
to now because superblock and cg sumaries check happened last, but now
allocations or frees can happen in pass 6.
 1.44.2.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.44.2.1 17-Apr-2012  yamt sync with head
 1.45.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.46.4.1 10-Aug-2014  tls Rebase.
 1.49.16.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.49.16.1 10-Jun-2019  christos Sync with HEAD
 1.56.2.2 13-May-2023  martin Pull up following revision(s) (requested by chs in ticket #160):

usr.sbin/makefs/ffs/ffs_alloc.c: revision 1.31
sbin/tunefs/tunefs.c: revision 1.58
sbin/fsck_ffs/setup.c: revision 1.105
sbin/fsck_ffs/pass5.c: revision 1.56
usr.sbin/makefs/ffs.c: revision 1.74
usr.sbin/makefs/ffs/mkfs.c: revision 1.42
usr.sbin/makefs/Makefile: revision 1.40
sys/ufs/ffs/fs.h: revision 1.71
sbin/fsdb/fsdb.c: revision 1.54
sbin/resize_ffs/resize_ffs.c: revision 1.58
sbin/fsck_ffs/pass4.c: revision 1.29
usr.sbin/makefs/ffs/ffs_extern.h: revision 1.9
sbin/newfs/mkfs.c: revision 1.133
sys/ufs/ffs/ffs_alloc.c: revision 1.172
sbin/fsck_ffs/pass1b.c: revision 1.24
usr.sbin/dumpfs/dumpfs.c: revision 1.68
sys/ufs/ffs/ffs_extern.h: revision 1.88
usr.sbin/quotacheck/quotacheck.c: revision 1.51
sys/ufs/ffs/ffs_subr.c: revision 1.54
sbin/fsck_ffs/main.c: revision 1.91
sbin/fsck_ffs/pass1.c: revision 1.63

ufs: fixed signed/unsigned bugs affecting large file systems

Apply these commits from FreeBSD:
commit e870d1e6f97cc73308c11c40684b775bcfa906a2
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Wed Feb 10 20:10:35 2010 +0000
This fix corrects a problem in the file system that treats large
inode numbers as negative rather than unsigned. For a default
(16K block) file system, this bug began to show up at a file system
size above about 16Tb.
To fully handle this problem, newfs must be updated to ensure that
it will never create a filesystem with more than 2^32 inodes. That
patch will be forthcoming soon.
Reported by: Scott Burns, John Kilburg, Bruce Evans
Followup by: Jeff Roberson
PR: 133980
MFC after: 2 weeks

commit 81479e688b0f643ffacd3f335b4b4bba460b769d
Author: Kirk McKusick <mckusick@FreeBSD.org>
Date: Thu Feb 11 18:14:53 2010 +0000
One last pass to get all the unsigned comparisons correct.

In additional to the changes from FreeBSD, this commit includes quite a few
related changes to appease -Wsign-compare.
 1.56.2.1 20-Dec-2022  martin Pull up following revision(s) (requested by chs in ticket #10):

sbin/tunefs/tunefs.c: revision 1.57

tunefs: clarify that "-a" refers to NFSv4 ACLs
 1.1 31-Jul-2018  khorben branches: 1.1.2; 1.1.4;
Add a port of the umb(4) driver from OpenBSD

The umb(4) driver provides support for USB MBIM (Mobile Broadband
Interface Model) devices.

MBIM devices establish connections via cellular networks such as GPRS,
UMTS, and LTE. They appear as a regular point-to-point network interface, transporting raw IP frames.

Required configuration parameters like PIN and APN have to be set with
umbctl(8), a new tool specific to this driver. The IP address is configured
automatically; the default route and DNS server information have to be set
separately.

The driver is not fully functional yet, it is therefore still marked as
experimental and disabled by default. Any help welcome to complete it!

Tested on NetBSD/amd64, with a Sierra Wireless EM7345 LTE modem on a Lenovo
ThinkPad T440s. No functional change expected otherwise.
 1.1.4.2 10-Jun-2019  christos Sync with HEAD
 1.1.4.1 31-Jul-2018  christos file Makefile was added on branch phil-wifi on 2019-06-10 22:05:36 +0000
 1.1.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.1.2.1 31-Jul-2018  pgoyette file Makefile was added on branch pgoyette-compat on 2018-09-06 06:55:21 +0000
 1.3 22-Mar-2020  khorben Forbid command line parameters when parsing configuration files

This behaviour was ambiguous at best.
While there, also correct the usage screen, and the corresponding manual
page.
 1.2 01-Aug-2018  wiz branches: 1.2.2; 1.2.4;
Various improvements to the man page.
 1.1 31-Jul-2018  khorben Add a port of the umb(4) driver from OpenBSD

The umb(4) driver provides support for USB MBIM (Mobile Broadband
Interface Model) devices.

MBIM devices establish connections via cellular networks such as GPRS,
UMTS, and LTE. They appear as a regular point-to-point network interface, transporting raw IP frames.

Required configuration parameters like PIN and APN have to be set with
umbctl(8), a new tool specific to this driver. The IP address is configured
automatically; the default route and DNS server information have to be set
separately.

The driver is not fully functional yet, it is therefore still marked as
experimental and disabled by default. Any help welcome to complete it!

Tested on NetBSD/amd64, with a Sierra Wireless EM7345 LTE modem on a Lenovo
ThinkPad T440s. No functional change expected otherwise.
 1.2.4.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 01-Aug-2018  christos file umbctl.8 was added on branch phil-wifi on 2019-06-10 22:05:36 +0000
 1.2.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.2.2.1 01-Aug-2018  pgoyette file umbctl.8 was added on branch pgoyette-compat on 2018-09-06 06:55:21 +0000
 1.4 13-May-2020  khorben Fix and improve parsing of configuration files

XXX pull-up to netbsd-9
 1.3 22-Mar-2020  khorben Forbid command line parameters when parsing configuration files

This behaviour was ambiguous at best.
While there, also correct the usage screen, and the corresponding manual
page.
 1.2 02-Aug-2018  roy branches: 1.2.2; 1.2.4;
Mark _error() as printflikee
 1.1 31-Jul-2018  khorben Add a port of the umb(4) driver from OpenBSD

The umb(4) driver provides support for USB MBIM (Mobile Broadband
Interface Model) devices.

MBIM devices establish connections via cellular networks such as GPRS,
UMTS, and LTE. They appear as a regular point-to-point network interface, transporting raw IP frames.

Required configuration parameters like PIN and APN have to be set with
umbctl(8), a new tool specific to this driver. The IP address is configured
automatically; the default route and DNS server information have to be set
separately.

The driver is not fully functional yet, it is therefore still marked as
experimental and disabled by default. Any help welcome to complete it!

Tested on NetBSD/amd64, with a Sierra Wireless EM7345 LTE modem on a Lenovo
ThinkPad T440s. No functional change expected otherwise.
 1.2.4.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.4.2 10-Jun-2019  christos Sync with HEAD
 1.2.4.1 02-Aug-2018  christos file umbctl.c was added on branch phil-wifi on 2019-06-10 22:05:36 +0000
 1.2.2.2 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.2.2.1 02-Aug-2018  pgoyette file umbctl.c was added on branch pgoyette-compat on 2018-09-06 06:55:21 +0000
 1.21 03-Jun-2023  lukem bsd.own.mk: rename GCC_NO_* to CC_WNO_*

Rename compiler-warning-disable variables from
GCC_NO_warning
to
CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
 1.20 23-Apr-2020  christos make umount NAME= work
 1.19 13-Oct-2019  mrg introduce some common variables for use in GCC warning disables:

GCC_NO_FORMAT_TRUNCATION -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints. many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
 1.18 01-Jul-2013  christos branches: 1.18.28;
Instead of borrowing the mount code to get the nfs arguments, just use
the system call directly. It is shorter and works...
 1.17 29-Jun-2013  christos Use the protocol we mounted the filesystem with instead of always udp.
(untested, but should fail back to udp).
 1.16 21-Jan-2006  dsl Izumi Tsutsui pointed out that we don't need vfslist.c (from ../mount)
if we are defining SMALL.
 1.15 21-Jan-2006  dsl Set -DSMALL if SMALLPROG defined - ie building install ramdisk images.
Removes the code that uses rpc to query remote systems about nfs mounts.
The last references to the xdr routines escape - saving 64k+
 1.14 20-Jan-2005  xtraeme WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.13 19-Jan-2005  xtraeme Remove main() prototype; WARNS=2
 1.12 19-Aug-2002  lukem Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path
 1.11 10-Oct-1997  christos CFLAGS->CPPFLAGS
 1.10 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.9 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.8 22-Dec-1994  cgd specify man pages the new way.
 1.7 17-Jun-1994  mycroft Fix a couple of Makefile bogons.
 1.6 08-Jun-1994  mycroft Update from 4.4-Lite, with local changes.
 1.5 08-Oct-1993  cgd there is no librpc any more
 1.4 31-Jul-1993  mycroft Add RCS indentifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.18.28.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.23 01-Jul-2025  kre PR bin/59495

Make umount less noisy when a single -v is used (just say
what has been unmounted), and only include details of
running (or not running) external umount_fstype progs
when more than one -v is given.

While here, make it more clear in the messages produce
when the -F (fake it) option is used, that nothing was
actually unmounted (just what would have been).

Man page updated to match.
 1.22 29-May-2025  gutteridge umount.8: note a limitation of the -d option

(As discussed in PR bin/57903.)
 1.21 25-Mar-2025  gutteridge umount.8: some minor corrections after -d addition

Use the term "unconfigure" rather than "detach", since that's what's
consistently used elsewhere to describe this on NetBSD (as opposed to
other OSes the commit is mimicking). Also fix grammar and reflect the
date this materially changed, source-wise (rather than the day the
patch arrived, over a year ago).
 1.20 25-Mar-2025  christos GitHub/31: Ricardo Branco: Add -d flag to umount to detach vnds, like FreeBSD
and Linux.
 1.19 22-Jan-2022  wiz branches: 1.19.4;
Fix grammar
 1.18 07-Jun-2017  abhinav s/filesystem/file system/
 1.17 12-Sep-2016  sevan umount appeared in V1
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/man/man1/umount.1

Amend HISTORY.
Bump date.
 1.16 26-Jun-2016  dholland Document external unmount programs. PR 698. Bump date.
 1.15 17-May-2009  mjf Add an exmaple of unmounting all file systems apart from NFS and MFS
e.g,

umount -a -t nonfs,mfs

This makes it clear that the "no prefix" only needs to be on the first
file-system argument to -t. The mount(8) man page has a clear example
of this but for some reason umount(8) was missing one.
 1.14 30-Dec-2005  mjl Typo fix (to umount is not yet a verb). Via OpenBSD bugs mailing list.
 1.13 21-Apr-2004  wiz Call -t argument fstypelist, to be in sync with code
and usage. Okayed by christos.
 1.12 21-Apr-2004  christos Make options match reality and agree with the source.
Don't document -A; it is there for compatibility only, and we want to
deprecate its use.
 1.11 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.10 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.9 05-Jun-2001  wiz Drop arguments of .Os.
 1.8 06-Jun-2000  chs change ``-a'' to be a synonym for ``-A''.
addresses PR 7629.
 1.7 17-Apr-1998  fair branches: 1.7.8;
Changes to implement "-R" (raw) option to umount, per PR#4030.
 1.6 18-Dec-1997  mikel document -F flag; part of PR 4030 from der Mouse
 1.5 20-Oct-1997  enami Fix .Nm usage.
 1.4 16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.3 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
 1.2 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.1 08-Jun-1994  mycroft branches: 1.1.1;
Update from 4.4-Lite, with local changes.
 1.1.1.2 16-Sep-1997  lukem imported from lite-2
 1.1.1.1 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.7.8.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.19.4.1 02-Aug-2025  perseant Sync with HEAD
 1.56 01-Jul-2025  kre PR bin/59495

Make umount less noisy when a single -v is used (just say
what has been unmounted), and only include details of
running (or not running) external umount_fstype progs
when more than one -v is given.

While here, make it more clear in the messages produce
when the -F (fake it) option is used, that nothing was
actually unmounted (just what would have been).

Man page updated to match.
 1.55 25-Mar-2025  christos move sfs declaration in #ifdef SMALL
 1.54 25-Mar-2025  christos GitHub/31: Ricardo Branco: Add -d flag to umount to detach vnds, like FreeBSD
and Linux.
 1.53 23-Apr-2020  christos branches: 1.53.8;
make umount NAME= work
 1.52 26-Jun-2016  dholland Don't assume that getaddrinfo sets the result pointer to null when it
fails. (In fact it probably doesn't...)
 1.51 26-Jun-2016  dholland Fix previous to avoid using an uninitialized pointer when using -R (raw).
 1.50 26-Jun-2016  dholland If an external unmount program of the form "umount_TYPE" exists
(e.g. umount_ffs, umount_nfs, etc.) exec it instead of calling
unmount(2).

Closes PR 698.

Note that the original plan for the PR also involved adding a generic
facility to store an alternate FS type name in the kernel to use when
unmounting. This was intended to support filesystems implemented as
loopback nfs servers, where the visible mount would be of type "nfs"
pointing at localhost; in that case one would want to be able to
provide an additional string in order to run an unmount program that
would both remove that mount and also shut down the loopback nfs
server daemon.

However, in the 21+ years since the PR was filed, loopback nfs servers
have gone out of favor (for good reasons) so I don't see any need to
worry about this case at present, especially since the PR has been
hanging around this long anyway. (If anyone still has a loopback nfs
server that they want to use a custom unmount program with, file a new
PR and assign it to me and I'll deal with it specifically in the nfs
mount args structure, which unmount already knows how to retrieve and
examine.)

It is my understanding that filesystems implemented with fuse (which
has displaced the loopback nfs server model) can already set the FS
type field so no further work is needed to allow them to use a custom
unmount program. If this is not the case, please let me know and I'll
attend to it.

There is no longer any need that I see to provide a general facility
for storing an alternate filesystem type name.

(One might also ask whether there's any real need for this
functionality at all any more; this is a fair question, but (a) the
change is small and (b) there are certainly cases when doing FS
research where you want a custom unmount program; been there & done
that.)
 1.49 26-Jun-2016  dholland When SMALL, if realpath() fails, warn() using the failing path instead
of the buffer realpath has declined to write anything into.
 1.48 27-Jun-2015  manu Remove useless and harmful sync(2) call in umount(8)

Remove sync(2) call before unmount(2) in umount(8). This sync(2) is useless
since unmount(2) will perform a VFS_SYNC anyway.

But moreover, this sync(2) may be harmful, as there are some situation where
it cannot return (unreachable NFS server, for instance), causing umount -f
to be uneffective.
 1.47 02-Jul-2013  christos branches: 1.47.6;
move proto to small
 1.46 01-Jul-2013  christos Instead of borrowing the mount code to get the nfs arguments, just use
the system call directly. It is shorter and works...
 1.45 29-Jun-2013  christos one copy of the name is enough, and free it.
 1.44 29-Jun-2013  christos Use the protocol we mounted the filesystem with instead of always udp.
(untested, but should fail back to udp).
 1.43 05-Aug-2008  pooka branches: 1.43.18; 1.43.24;
Refactor mount utilities to provide a mount_fs_parseargs() routine.
Use this routine both in mount_fs and rump_fs to provide equivalent
command line parameters and therefore usage interchangeability.
While doing this, combine some common mountgoop to mountprog.h
 1.42 20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.41 15-Dec-2007  perry branches: 1.41.4; 1.41.8;
convert __attribute__s to applicable cdefs.h macros
 1.40 17-Jul-2007  christos branches: 1.40.4; 1.40.6;
kill MFSNAMELEN
 1.39 16-Jul-2007  pooka Make all mount(2) return value error checks against -1. Some file
systems just checked != 0, breaking MNT_GETARGS. Others worked with < 0,
but make them check against -1 too for consistency. And sprinkle some
stylish line wrapping where appropriate.
 1.38 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.37 31-Jan-2005  erh Fix PR#3205 for the -a case: when the list of mount points comes from the
kernel, always use "raw" mode (-R option) so unmounting odd mount points works.
Also, fix available options in SMALL mode to include -R, not -r.
 1.36 19-Jan-2005  xtraeme Remove main() prototype; WARNS=2
 1.35 01-Sep-2004  chs pass data to a function via an argument instead of via a global variable.
this avoids a name collision with libcurses functions when both are
present in a crunched static binary. part of PR 26458.
 1.34 21-Apr-2004  christos add #ifdef SMALL so that we can use this in the install media.
 1.33 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.32 12-Mar-2004  dsl stop umount temporarily modifying what might be argv[n].
 1.31 12-Mar-2004  dsl KNF and const sprinkle
 1.30 12-Mar-2004  dsl Fix 'umount host:/filesystem' - it is documented on the man page but hasn't actually
worked for 10 years!
Remove the (broken) code that once supported 'umount /filesystem@host' since that
syntax isn't used anywhere.
Fixes PR bin/22099
 1.29 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.28 20-Jun-2000  fvdl branches: 1.28.2;
Adapt to new RPC interface. Use getaddrinfo(), not gethostbyname().
 1.27 06-Jun-2000  chs change ``-a'' to be a synonym for ``-A''.
addresses PR 7629.
 1.26 09-Nov-1999  drochner branches: 1.26.2;
Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
 1.25 02-Aug-1999  sommerfeld branches: 1.25.4;
Fix PR7747: umount -R dumps core
(fix by Ronald Khoo from PR applied)
 1.24 17-Apr-1998  fair Changes to implement "-R" (raw) option to umount, per PR#4030.
 1.23 01-Apr-1998  kleink No need to include <sys/socketvar.h>.
 1.22 18-Dec-1997  mikel document -F flag; part of PR 4030 from der Mouse
 1.21 01-Nov-1997  drochner Since umount works from the top we have to traverse the information
returned by getmountinfo() from the top too. Otherwise we get
the wrong mount data in case of 2 mounts on 1 pountpoint.
 1.20 16-Sep-1997  lukem branches: 1.20.2;
resolve conflicts from lite-2 merge
 1.19 15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
 1.18 21-May-1997  pk Code previous somewhat more compactly.
 1.17 21-May-1997  pk Do not force the ISBLK and ISDIR checks on the mount point.
 1.16 11-May-1996  mycroft Use kernel mount info rather than fstab. From greywolf@starwolf.com, slightly
modified.
 1.15 22-Sep-1995  mycroft Fix the case where stat() fails, so that the file system is still unmounted.
 1.14 18-Jun-1995  cgd don't assume f_fstypename is larger than MFSNAMELEN or is nul-terminated
 1.13 18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.12 30-Jan-1995  mycroft Make arg to selected() const. Disallow multiple `-t' options.
 1.11 30-Jan-1995  mycroft Cosmetic changes to type list parsing.
 1.10 30-Jan-1995  mycroft Be careful to only parse the host name from the mount path for NFS mounts.
 1.9 25-Aug-1994  cgd branches: 1.9.2;
several fixes from Mark Weaver <mhw@cs.brown.edu>, relating to error
reporting. (pr 431)
 1.8 23-Aug-1994  cgd fix from John Kohl to return correct status when unmounting named fs's.
 1.7 08-Jun-1994  mycroft branches: 1.7.2;
Update from 4.4-Lite, with local changes.
 1.6 14-Apr-1994  cgd fs type names, and much clean
 1.5 05-Dec-1993  deraadt should bzero automatic sockaddr's before use
 1.4 01-Aug-1993  mycroft Add RCS identifiers.
 1.3 23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2 22-Mar-1993  cgd added rcs ids to all files
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3 16-Sep-1997  lukem imported from lite-2
 1.1.1.2 13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.7.2.1 23-Aug-1994  mycroft update from trunk
 1.9.2.2 25-Aug-1994  cgd several fixes from Mark Weaver <mhw@cs.brown.edu>, relating to error
reporting. (pr 431)
 1.9.2.1 25-Aug-1994  cgd file umount.c was added on branch netbsd-1-0 on 1994-08-25 02:14:02 +0000
 1.20.2.1 02-Nov-1997  mellon Pull rev 1.21 up from trunk (drochner)
 1.25.4.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.26.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.28.2.2 20-Jun-2000  fvdl Adapt to new RPC interface. Use getaddrinfo(), not gethostbyname().
 1.28.2.1 20-Jun-2000  fvdl file umount.c was added on branch netbsd-1-5 on 2000-06-20 00:45:25 +0000
 1.40.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.40.4.1 09-Jan-2008  matt sync with HEAD
 1.41.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.41.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.43.24.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.43.18.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.47.6.1 04-Nov-2015  riz Pull up following revision(s) (requested by manu in ticket #882):
sbin/umount/umount.c: revision 1.48
sys/nfs/nfsmount.h: revision 1.53
sys/nfs/nfs_var.h: revision 1.94
sys/nfs/nfs_iod.c: revision 1.7
sys/nfs/nfs_socket.c: revision 1.197
sys/nfs/nfs_bio.c: revision 1.191
sys/nfs/nfs_vfsops.c: revision 1.230
sys/nfs/nfs_clntsocket.c: revision 1.3
Remove useless and harmful sync(2) call in umount(8)
Remove sync(2) call before unmount(2) in umount(8). This sync(2) is useless
since unmount(2) will perform a VFS_SYNC anyway.
But moreover, this sync(2) may be harmful, as there are some situation where
it cannot return (unreachable NFS server, for instance), causing umount -f
to be uneffective.
Fix soft NFS force unmount
For many reasons, forcibly unmounting a soft NFS mount could hang forever.
Here are the fixes:
- Introduce decents timeouts in operation that awaited NFS server reply.
- On timeout, fails operations on soft mounts with EIO.
- Introduce NFSMNT_DISMNTFORCE to let the filesystem know that a
force unmount is ongoing. This causes timeouts to be reduced and
prevents the NFS client to attempt reconnecting to the NFS server.
Also fix a race condition where some asynchronous I/O could reference
destroyed mount structures. We fix this by awaiting asynchronous I/O
to drain before proceeding.
Reviewed by Chuck Silvers.
 1.53.8.1 02-Aug-2025  perseant Sync with HEAD
 1.14 24-Jul-2008  dholland Adjust this to not need -Wno-pointer-sign.
 1.13 21-Jul-2008  gmcgarry Add HAVE_PCC tests for -Wno-pointer-sign.
 1.12 28-Nov-2006  elad branches: 1.12.18; 1.12.22;
Make Veriexec use proplib(3) for kernel-userland data passing.

Obviously, this breaks the already unstable Veriexec ABI, but that's
it. Some cool additions are planned to be introduced, and this just
makes it so that NetBSD 4.0 users will be able to easily use them as
well.

This also removes the fingerprint type name limit, so relevant code
was adjusted.

Thoroughly tested (even uncovered a bug in proplib! thanks for fixing
that cube@!). Documentation updated.
 1.11 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.10 27-Jun-2005  christos Move WARNS=3 to the Makefile.inc, and add a little const to the remaining
programs that did not compile before.
 1.9 06-May-2005  jmc Need -I. here as well so OBJDIR's work correctly in all cases
 1.8 25-Apr-2005  blymn Remove veriexec(4) man page.
 1.7 21-Apr-2005  christos Minor cleanups, KNF, error handling consistency.
 1.6 21-Apr-2005  he Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.5 20-Apr-2005  blymn Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.4 20-Jan-2005  xtraeme branches: 1.4.2;
WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.3 19-Jan-2005  xtraeme Kill __P(); WARNS=2
 1.2 26-Apr-2003  jdolecek don't compile this -static, depend on MKDYNAMICROOT check in ../Makefile.inc
for that
 1.1 23-Nov-2002  blymn Renamed verified exec fingerprint loader.
 1.4.2.5 10-Jul-2005  tron Pull up revision 1.9 (requested by blymn in ticket #569):
Need -I. here as well so OBJDIR's work correctly in all cases
 1.4.2.4 10-Jun-2005  tron Pull up revision 1.8 (requested by elad in ticket #389):
Remove veriexec(4) man page.
 1.4.2.3 10-Jun-2005  tron Pull up revision 1.7 (requested by elad in ticket #389):
Minor cleanups, KNF, error handling consistency.
 1.4.2.2 10-Jun-2005  tron Pull up revision 1.6 (requested by elad in ticket #389):
Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.4.2.1 10-Jun-2005  tron Pull up revision 1.5 (requested by elad in ticket #389):
Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.12.22.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.12.18.1 28-Sep-2008  mjf Sync with HEAD.
 1.3 24-Apr-2005  blymn branches: 1.3.2;
Move veriexec(4) man page to correct place.
 1.2 22-Apr-2005  wiz Grammar, wording, and punctuation improvements. Sort SEE ALSO. Remove some superfluous .Pp.
 1.1 20-Apr-2005  blymn Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.3.2.3 10-Jun-2005  tron Pull up file removal (requested by elad in ticket #389):
Move veriexec(4) man page to correct place.
 1.3.2.2 10-Jun-2005  tron Pull up revision 1.2 (requested by elad in ticket #389):
Grammar, wording, and punctuation improvements. Sort SEE ALSO. Remove
some superfluous .Pp.
 1.3.2.1 10-Jun-2005  tron Pull up revision 1.1 (requested by elad in ticket #389):
Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.40 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.39 18-Mar-2014  riastradh Merge riastradh-drm2 to HEAD.
 1.38 20-Jul-2013  wiz Use Mt for email addresses.
 1.37 28-Apr-2011  wiz branches: 1.37.4; 1.37.10; 1.37.14;
Mark up file as argument.
 1.36 28-Apr-2011  wiz security(7), not (8).
 1.35 31-Aug-2008  dholland Document -v. PR 39441 from Stathis Kamperis. Bump date.
 1.34 18-Feb-2008  elad branches: 1.34.4; 1.34.8;
Following input from Matthew Mondor, some Veriexec documentation changes:

- Document the signatures file format in a veriexec(5) man-page,
- Document the strict levels and a general Veriexec intro in veriexec(8)
instead of security(8).

Okay blymn@.
 1.33 15-Feb-2008  elad Allow no signatures file to be specified for the "load" command, and use
the default one in such cases.

Update command usage and documentation to reflect the above.
 1.32 10-Feb-2008  elad Xref security(8) from veriexec(4), veriexec(9), veriexecctl(8), and
veriexecgen(8).

Suggested by Matthew Mondor.
 1.31 13-Dec-2007  wiz Whitespace and HTML output fixes.
 1.30 15-May-2007  elad branches: 1.30.4; 1.30.6;
Some Veriexec stuff that's been rotting in my tree for months.

Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.

- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.

- Fix memory leak in rename handling when overwriting a monitored
file.

- Fix table deletion logic.

- Don't prevent query requests if not in learning mode.


KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.

- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.

- veriexec_report() was removed, it is now internal.

- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.

- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.


New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.

- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:

# veriexecctl dump > /etc/signatures

Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.

Idea from Brett Lymn.

- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:

# veriexecctl flush

- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.

- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.


Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.

- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.

- Some of the messages Veriexec prints were improved.

- Various documentation fixes.


All relevant man-pages were updated to reflect the above changes.

Binary compatibility with existing veriexecctl binaries is maintained.
 1.29 29-Nov-2006  elad branches: 1.29.2; 1.29.4; 1.29.6;
Support escaping characters in the path so that spaces etc. are allowed
in entries for Veriexec.

This has been requested for a long time, most recently by Brad Harder.

Thanks a lot to Michael van Elst for the patch, done during the latest
hackathon.
 1.28 30-Sep-2006  elad If Veriexec enforces access type, don't allow mmap() to use PROT_EXEC on
files that don't have the "indirect" flag. Also change the "library" alias
in veriexecctl(8) to mean "file, indirect".

okay blymn@
 1.27 17-Sep-2006  elad .Sh -> .Ss

mmm mdoclint. :)
 1.26 16-Sep-2006  elad Reference veriexecgen(8) instead of the old scripts. Bump date.
 1.25 16-Sep-2006  elad Scripts don't have to be *shell* scripts.
 1.24 22-Jul-2006  elad no VERIFIED_EXEC anymore, just a pseudo-device.
 1.23 14-Jul-2006  elad misc cleanup: remove #if 0 code, unused var, and make pretty.
 1.22 12-Dec-2005  wiz Grammar improvement.
 1.21 12-Dec-2005  elad Add and document a "query" keyword to veriexecctl. Usage:

/sbin/veriexecctl query /path/to/file

will print out filename, device, inode, evaluation status, entry flags,
fingerprint, and fingerprinting algorithm.
 1.20 10-Dec-2005  elad Add and document a VERIEXEC_DELETE operation for Veriexec.

We can now delete an entry from the tables using

veriexecctl delete /path/to/file

or remove an entire table using

veriexecctl delete /mount_point

(any directory will work for the mount point it's on)
 1.19 05-Oct-2005  wiz Make sentence more readable.
 1.18 05-Oct-2005  elad Introduce per-page fingerprints in Veriexec.

This closes a hole pointed out by Thor Lancelot Simon on tech-kern ~3
years ago.

The problem was with running binaries from remote storage, where our
kernel (and Veriexec) has no control over any changes to files.

An attacker could, after the fingerprint has been verified and
program loaded to memory, inject malicious code into the backing
store on the remote storage, followed by a forced flush, causing
a page-in of the malicious data from backing store, bypassing
integrity checks.

Initial implementation by Brett Lymn.
 1.17 07-Aug-2005  wiz Bump date for previous; use more markup.
 1.16 06-Aug-2005  blymn Add and document some convenience aliases for commonly required option
combinations.
 1.15 02-Aug-2005  elad Sync with reality.

- Verified Exec -> Veriexec
- pseudo-device is `veriexec'
- veriexec.conf -> signatures, and mention /etc/signatures as the default
location
- We use veriexec's strict level, not the system securelevel
- Mention the `direct' option
- Mention that the signatures file can have multiple options in a single
entry, comma-separated
- Mention that both `direct' and `indirect' access modes are implied
if no access modes are explicitly mention in the options
- Bump date
 1.14 13-Jun-2005  wiz Bump date for previous.
 1.13 13-Jun-2005  elad Remove bits about deprecated 'fingerprints' command.
 1.12 20-May-2005  elad Remove common code for returning supported fingerprints. This is done now
via sysctl(8) using kern.veriexec.algorithms.

Also add an entry for the 'algorithms' variable in sysctl.8 forgotten in
the last commit.
 1.11 24-Apr-2005  blymn Add bugs sub-heading to warn about whitespace in filenames.
 1.10 22-Apr-2005  wiz Add Xr to veriexec.4.
 1.9 22-Apr-2005  wiz Mention command names in SYNOPSIS; add gen_rmd160 to SEE ALSO;
improve formatting; bump date.
 1.8 20-Apr-2005  blymn Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.7 06-Jan-2005  wiz branches: 1.7.2;
Remove unnecessary dot, and bump date for new SEE ALSO section.
 1.6 06-Jan-2005  hubertf Add SEE ALSO section pointing at the scripts to create signatures

XXX they should be installed as veriexec_gen_* IMHO,
XXX not dwell in /usr/share/examples
 1.5 06-Mar-2004  wiz Bump date for previous.
 1.4 06-Mar-2004  blymn Fix error in description of signature file syntax (thanks to Chrisian
Biere)
Fix wording to match changed syntax line
Add some clarifications to the wording
Improve vertical spacing of some sections.
 1.3 19-Jan-2003  atatat The next release will be 2.0, not 1.7.
 1.2 21-Dec-2002  wiz Remove traces of old names (verifiedexec_load and /dev/verifiedexec).
 1.1 23-Nov-2002  blymn Renamed verified exec fingerprint loader.
 1.7.2.10 15-Aug-2005  tron Pull up revision 1.17 (requested by elad in ticket #655):
Bump date for previous; use more markup.
 1.7.2.9 15-Aug-2005  tron Pull up revision 1.16 (requested by elad in ticket #655):
Add and document some convenience aliases for commonly required option
combinations.
 1.7.2.8 12-Aug-2005  snj Pull up revision 1.15 (requested by elad in ticket #645):
Sync with reality.
- Verified Exec -> Veriexec
- pseudo-device is `veriexec'
- veriexec.conf -> signatures, and mention /etc/signatures as the default
location
- We use veriexec's strict level, not the system securelevel
- Mention the `direct' option
- Mention that the signatures file can have multiple options in a single
entry, comma-separated
- Mention that both `direct' and `indirect' access modes are implied
if no access modes are explicitly mention in the options
- Bump date
 1.7.2.7 02-Jul-2005  tron Pull up revision 1.14 (requested by elad in ticket #487):
Bump date for previous.
 1.7.2.6 02-Jul-2005  tron Pull up revision 1.13 (requested by elad in ticket #487):
Remove bits about deprecated 'fingerprints' command.
 1.7.2.5 10-Jun-2005  tron Pull up revision 1.12 (requested by elad in ticket #389):
Remove common code for returning supported fingerprints. This is done now
via sysctl(8) using kern.veriexec.algorithms.
Also add an entry for the 'algorithms' variable in sysctl.8 forgotten in
the last commit.
 1.7.2.4 10-Jun-2005  tron Pull up revision 1.11 (requested by elad in ticket #389):
Add bugs sub-heading to warn about whitespace in filenames.
 1.7.2.3 10-Jun-2005  tron Pull up revision 1.10 (requested by elad in ticket #389):
Add Xr to veriexec.4.
 1.7.2.2 10-Jun-2005  tron Pull up revision 1.9 (requested by elad in ticket #389):
Mention command names in SYNOPSIS; add gen_rmd160 to SEE ALSO;
improve formatting; bump date.
 1.7.2.1 10-Jun-2005  tron Pull up revision 1.8 (requested by elad in ticket #389):
Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.29.6.1 22-Feb-2008  bouyer Apply patch, requested by elad in ticket #1080:
sbin/veriexecctl/veriexecctl.8: patch
reflect reality in the veriexecctl(8) man-page.
 1.29.4.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.29.2.1 22-Feb-2008  bouyer Apply patch, requested by elad in ticket #1080:
sbin/veriexecctl/veriexecctl.8: patch
reflect reality in the veriexecctl(8) man-page.
 1.30.6.2 18-Feb-2008  mjf Sync with HEAD.
 1.30.6.1 27-Dec-2007  mjf Sync with HEAD.
 1.30.4.2 23-Mar-2008  matt sync with HEAD
 1.30.4.1 09-Jan-2008  matt sync with HEAD
 1.34.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.34.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.37.14.1 23-Jul-2013  riastradh sync with HEAD
 1.37.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.37.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.40 10-Jan-2017  christos need <sys/stat.h> ... for stat()
 1.39 16-Jun-2015  christos branches: 1.39.2;
fix error messages containing \n
 1.38 26-Apr-2015  maxv Be a bit more verbose if the kernel rejects a file
 1.37 27-Jul-2014  dholland branches: 1.37.2;
Fix snprintf usage and, while here, don't trundle off the end of an
array. Part of PR 47976 from Henning Petersen.
 1.36 09-Feb-2014  maxv branches: 1.36.2;
Fix error message; argv[1] could be NULL
 1.35 29-Aug-2011  joerg branches: 1.35.2; 1.35.8;
Use __dead
 1.34 16-Mar-2009  lukem fix sign-compare issues
 1.33 31-Aug-2008  dholland branches: 1.33.4;
Remove trailing whitespace. Noted in PR 39440 by Stathis Kamperis.
 1.32 31-Aug-2008  dholland Don't dump core if given no arguments. Fixes PR 39440 from Stathis Kamperis
(but with a different patch).
 1.31 15-Feb-2008  elad branches: 1.31.4; 1.31.8;
Allow no signatures file to be specified for the "load" command, and use
the default one in such cases.

Update command usage and documentation to reflect the above.
 1.30 06-Sep-2007  xtraeme branches: 1.30.2;
CID 4498: print_entry() returning without freeing 'fp'.

Ok by rmind@.
 1.29 17-Aug-2007  pavel branches: 1.29.2;
Attempt at fixing build failures after proplib was converted to bool:
FALSE -> false, TRUE -> true, boolean_t -> bool, int -> bool when
appropriate, include stdbool.h . proplib.h no longer provides boolean_t,
so it is necessary to change to bool.

From Tom Spindler (dogcow@).
 1.28 15-May-2007  oster Add missing #include <sys/ioctl.h> to make this build without warnings.
 1.27 15-May-2007  elad Some Veriexec stuff that's been rotting in my tree for months.

Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.

- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.

- Fix memory leak in rename handling when overwriting a monitored
file.

- Fix table deletion logic.

- Don't prevent query requests if not in learning mode.


KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.

- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.

- veriexec_report() was removed, it is now internal.

- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.

- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.


New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.

- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:

# veriexecctl dump > /etc/signatures

Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.

Idea from Brett Lymn.

- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:

# veriexecctl flush

- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.

- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.


Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.

- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.

- Some of the messages Veriexec prints were improved.

- Various documentation fixes.


All relevant man-pages were updated to reflect the above changes.

Binary compatibility with existing veriexecctl binaries is maintained.
 1.26 29-Nov-2006  elad Type changed from size_t to uint64_t, adjust format string.
Pointed out by Tom Spindler, thanks!
 1.25 28-Nov-2006  elad Make Veriexec use proplib(3) for kernel-userland data passing.

Obviously, this breaks the already unstable Veriexec ABI, but that's
it. Some cool additions are planned to be introduced, and this just
makes it so that NetBSD 4.0 users will be able to easily use them as
well.

This also removes the fingerprint type name limit, so relevant code
was adjusted.

Thoroughly tested (even uncovered a bug in proplib! thanks for fixing
that cube@!). Documentation updated.
 1.24 21-Nov-2006  elad Update my email address.
 1.23 14-Jul-2006  elad misc cleanup: remove #if 0 code, unused var, and make pretty.
 1.22 14-Jul-2006  elad oops, forgot to handle new abi for "query", noted by he@, thanks!
 1.21 14-Jul-2006  elad okay, since there was no way to divide this to two commits, here it goes..

introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.

this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.

as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.

also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.

tons of input from yamt@, wrstuden@, martin@, and christos@.
 1.20 13-Dec-2005  dsl Use PRIu64 to print ino_t (maybe there should be a PRIino_t somewhere....)
 1.19 12-Dec-2005  elad Add and document a "query" keyword to veriexecctl. Usage:

/sbin/veriexecctl query /path/to/file

will print out filename, device, inode, evaluation status, entry flags,
fingerprint, and fingerprinting algorithm.
 1.18 10-Dec-2005  elad Add and document a VERIEXEC_DELETE operation for Veriexec.

We can now delete an entry from the tables using

veriexecctl delete /path/to/file

or remove an entire table using

veriexecctl delete /mount_point

(any directory will work for the mount point it's on)
 1.17 05-Oct-2005  elad Introduce per-page fingerprints in Veriexec.

This closes a hole pointed out by Thor Lancelot Simon on tech-kern ~3
years ago.

The problem was with running binaries from remote storage, where our
kernel (and Veriexec) has no control over any changes to files.

An attacker could, after the fingerprint has been verified and
program loaded to memory, inject malicious code into the backing
store on the remote storage, followed by a forced flush, causing
a page-in of the malicious data from backing store, bypassing
integrity checks.

Initial implementation by Brett Lymn.
 1.16 13-Jun-2005  elad Some refactoring and bugfixes:

- Report line numbers correctly.
- Don't perform a 2nd pass when there are were errors during 1st.
- Support multiple, comma-separated flags. This is mostly a reworking of
some parser internals preparing for planned features.
 1.15 03-Jun-2005  elad No need for this one, apparently. Reported by Hisashi T Fujinaka.
 1.14 03-Jun-2005  elad Don't create duplicate tables for the same device.
 1.13 01-Jun-2005  elad Newline in end of usage.
 1.12 30-May-2005  elad Warn when failing to load an entry; don't fail the whole process.
 1.11 21-May-2005  skrll Remove unused variables.
 1.10 20-May-2005  elad Remove leftovers from Vexec.
 1.9 20-May-2005  elad Remove common code for returning supported fingerprints. This is done now
via sysctl(8) using kern.veriexec.algorithms.

Also add an entry for the 'algorithms' variable in sysctl.8 forgotten in
the last commit.
 1.8 21-Apr-2005  christos Minor cleanups, KNF, error handling consistency.
 1.7 21-Apr-2005  he Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.6 20-Apr-2005  blymn Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.5 06-Mar-2004  blymn branches: 1.5.6;
Made error messages more descriptive.
 1.4 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.3 21-Dec-2002  wiz Remove traces of old names (verifiedexec_load and /dev/verifiedexec).
 1.2 06-Dec-2002  thorpej Need <stdlib.h> for exit() prototype.
 1.1 23-Nov-2002  blymn Renamed verified exec fingerprint loader.
 1.5.6.11 02-Jul-2005  tron Pull up revision 1.16 (requested by elad in ticket #487):
Some refactoring and bugfixes:
- Report line numbers correctly.
- Don't perform a 2nd pass when there are were errors during 1st.
- Support multiple, comma-separated flags. This is mostly a reworking of
some parser internals preparing for planned features.
 1.5.6.10 10-Jun-2005  tron Pull up revision 1.15 (requested by elad in ticket #390):
No need for this one, apparently. Reported by Hisashi T Fujinaka.
 1.5.6.9 10-Jun-2005  tron Pull up revision 1.14 (requested by elad in ticket #389):
Don't create duplicate tables for the same device.
 1.5.6.8 10-Jun-2005  tron Pull up revision 1.13 (requested by elad in ticket #389):
Newline in end of usage.
 1.5.6.7 10-Jun-2005  tron Pull up revision 1.12 (requested by elad in ticket #389):
Warn when failing to load an entry; don't fail the whole process.
 1.5.6.6 10-Jun-2005  tron Pull up revision 1.11 (requested by elad in ticket #389):
Remove unused variables.
 1.5.6.5 10-Jun-2005  tron Pull up revision 1.10 (requested by elad in ticket #389):
Remove leftovers from Vexec.
 1.5.6.4 10-Jun-2005  tron Pull up revision 1.9 (requested by elad in ticket #389):
Remove common code for returning supported fingerprints. This is done now
via sysctl(8) using kern.veriexec.algorithms.
Also add an entry for the 'algorithms' variable in sysctl.8 forgotten in
the last commit.
 1.5.6.3 10-Jun-2005  tron Pull up revision 1.8 (requested by elad in ticket #389):
Minor cleanups, KNF, error handling consistency.
 1.5.6.2 10-Jun-2005  tron Pull up revision 1.7 (requested by elad in ticket #389):
Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.5.6.1 10-Jun-2005  tron Pull up revision 1.6 (requested by elad in ticket #389):
Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.29.2.2 23-Mar-2008  matt sync with HEAD
 1.29.2.1 06-Nov-2007  matt sync with HEAD
 1.30.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.31.8.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.31.4.1 28-Sep-2008  mjf Sync with HEAD.
 1.33.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.35.8.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.35.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.36.2.1 10-Aug-2014  tls Rebase.
 1.37.2.1 19-May-2015  snj Pull up following revision(s) (requested by maxv in ticket #764):
sbin/veriexecctl/veriexecctl.c: revision 1.38
share/man/man9/veriexec.9: revision 1.10
sys/conf/files: revision 1.1128
sys/dev/verified_exec.c: revisions 1.70, 1.71
sys/kern/kern_veriexec.c: revisions 1.1-1.8
sys/kern/kern_verifiedexec.c: delete
Rename kern_verifiedexec.c to kern_veriexec.c. "Veriexec" is the name of
the subsystem, not "Verifiedexec".

The revisions of kern_verifiedexec.c are now in Attic/.

No change between kern_verifiedexec.c and kern_veriexec.c.

Also, update the man page accordingly.

Okayed by christos@ and blymn@ some months ago.
--
KNF
--
Don't mix veriexec lock and file lock in veriexec_file_verify().

Now:
- 'veriexec_op_lock' needs to be held when calling veriexec_file_verify()
- the 'file_lock_state' argument indicates if the file is locked
- add some KASSERTs
--
Instead of duplicating code, add veriexec_fp_status(). Also reorder a
useless goto.
--
Make veriexec_renamechk() more readable. Also add a KASSERT on vte_count.

No real functional change
--
If we already have an entry for the file being loaded, return EEXIST, don't
silently skip it.
--
Remove FreeBSD.

ok elad@
--
KASSERT x then y, not (x && y).
--
KNF
--
Not to add even more confusion in an already overcomplicated subsystem,
remove the FreeBSD code. This code is likely to be outdated, and Veriexec
is in all cases not available on FreeBSD.
--
Be a bit more verbose if the kernel rejects a file
 1.39.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.12 06-Jun-2020  thorpej Update for proplib(3) API changes.
 1.11 31-Aug-2008  dholland Remove trailing whitespace. Noted in PR 39440 by Stathis Kamperis.
 1.10 15-May-2007  elad branches: 1.10.12; 1.10.16;
Some Veriexec stuff that's been rotting in my tree for months.

Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.

- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.

- Fix memory leak in rename handling when overwriting a monitored
file.

- Fix table deletion logic.

- Don't prevent query requests if not in learning mode.


KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.

- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.

- veriexec_report() was removed, it is now internal.

- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.

- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.


New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.

- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:

# veriexecctl dump > /etc/signatures

Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.

Idea from Brett Lymn.

- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:

# veriexecctl flush

- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.

- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.


Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.

- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.

- Some of the messages Veriexec prints were improved.

- Various documentation fixes.


All relevant man-pages were updated to reflect the above changes.

Binary compatibility with existing veriexecctl binaries is maintained.
 1.9 28-Nov-2006  elad Make Veriexec use proplib(3) for kernel-userland data passing.

Obviously, this breaks the already unstable Veriexec ABI, but that's
it. Some cool additions are planned to be introduced, and this just
makes it so that NetBSD 4.0 users will be able to easily use them as
well.

This also removes the fingerprint type name limit, so relevant code
was adjusted.

Thoroughly tested (even uncovered a bug in proplib! thanks for fixing
that cube@!). Documentation updated.
 1.8 21-Nov-2006  elad Update my email address.
 1.7 14-Jul-2006  elad misc cleanup: remove #if 0 code, unused var, and make pretty.
 1.6 14-Jul-2006  elad okay, since there was no way to divide this to two commits, here it goes..

introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.

this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.

as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.

also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.

tons of input from yamt@, wrstuden@, martin@, and christos@.
 1.5 12-Dec-2005  elad Add and document a "query" keyword to veriexecctl. Usage:

/sbin/veriexecctl query /path/to/file

will print out filename, device, inode, evaluation status, entry flags,
fingerprint, and fingerprinting algorithm.
 1.4 20-May-2005  elad branches: 1.4.2;
Remove leftovers from Vexec.
 1.3 21-Apr-2005  christos Minor cleanups, KNF, error handling consistency.
 1.2 21-Apr-2005  he Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.1 21-Apr-2005  blymn Add missing header file.
 1.4.2.5 10-Jun-2005  tron Pull up revision 1.4 (requested by elad in ticket #389):
Remove leftovers from Vexec.
 1.4.2.4 10-Jun-2005  tron Pull up revision 1.3 (requested by elad in ticket #389):
Minor cleanups, KNF, error handling consistency.
 1.4.2.3 10-Jun-2005  tron Pull up revision 1.2 (requested by elad in ticket #389):
Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.4.2.2 10-Jun-2005  tron Pull up revision 1.1 (requested by elad in ticket #389):
Add missing header file.
 1.4.2.1 20-May-2005  tron file veriexecctl.h was added on branch netbsd-3 on 2005-06-10 14:50:26 +0000
 1.10.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.15 24-May-2011  joerg input is unused.
 1.14 29-Oct-2009  christos use %option instead of #define YY_NO_...
 1.13 28-Oct-2009  christos we don't need unput
 1.12 31-Aug-2008  dholland Remove trailing whitespace. Noted in PR 39440 by Stathis Kamperis.
 1.11 15-May-2007  elad branches: 1.11.12; 1.11.16;
Some Veriexec stuff that's been rotting in my tree for months.

Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.

- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.

- Fix memory leak in rename handling when overwriting a monitored
file.

- Fix table deletion logic.

- Don't prevent query requests if not in learning mode.


KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.

- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.

- veriexec_report() was removed, it is now internal.

- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.

- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.


New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.

- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:

# veriexecctl dump > /etc/signatures

Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.

Idea from Brett Lymn.

- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:

# veriexecctl flush

- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.

- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.


Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.

- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.

- Some of the messages Veriexec prints were improved.

- Various documentation fixes.


All relevant man-pages were updated to reflect the above changes.

Binary compatibility with existing veriexecctl binaries is maintained.
 1.10 29-Nov-2006  elad Support escaping characters in the path so that spaces etc. are allowed
in entries for Veriexec.

This has been requested for a long time, most recently by Brad Harder.

Thanks a lot to Michael van Elst for the patch, done during the latest
hackathon.
 1.9 28-Nov-2006  elad Make Veriexec use proplib(3) for kernel-userland data passing.

Obviously, this breaks the already unstable Veriexec ABI, but that's
it. Some cool additions are planned to be introduced, and this just
makes it so that NetBSD 4.0 users will be able to easily use them as
well.

This also removes the fingerprint type name limit, so relevant code
was adjusted.

Thoroughly tested (even uncovered a bug in proplib! thanks for fixing
that cube@!). Documentation updated.
 1.8 21-Nov-2006  elad Update my email address.
 1.7 05-Jan-2006  elad Allow multiple lines entries using '\' at the end of the line.
Simplified by martin@, thanks. :)
 1.6 13-Jun-2005  elad Some refactoring and bugfixes:

- Report line numbers correctly.
- Don't perform a 2nd pass when there are were errors during 1st.
- Support multiple, comma-separated flags. This is mostly a reworking of
some parser internals preparing for planned features.
 1.5 21-Apr-2005  blymn Fix format type error in yyerror printf.
 1.4 21-Apr-2005  christos Minor cleanups, KNF, error handling consistency.
 1.3 20-Apr-2005  blymn Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.2 19-Jan-2005  xtraeme branches: 1.2.2;
Kill __P(); WARNS=2
 1.1 23-Nov-2002  blymn Renamed verified exec fingerprint loader.
 1.2.2.4 02-Jul-2005  tron Pull up revision 1.6 (requested by elad in ticket #487):
Some refactoring and bugfixes:
- Report line numbers correctly.
- Don't perform a 2nd pass when there are were errors during 1st.
- Support multiple, comma-separated flags. This is mostly a reworking of
some parser internals preparing for planned features.
 1.2.2.3 10-Jun-2005  tron Pull up revision 1.5 (requested by elad in ticket #389):
Fix format type error in yyerror printf.
 1.2.2.2 10-Jun-2005  tron Pull up revision 1.4 (requested by elad in ticket #389):
Minor cleanups, KNF, error handling consistency.
 1.2.2.1 10-Jun-2005  tron Pull up revision 1.3 (requested by elad in ticket #389):
Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.11.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.12.1 28-Sep-2008  mjf Sync with HEAD.
 1.26 16-Mar-2009  lukem fix sign-compare issues
 1.25 31-Aug-2008  dholland branches: 1.25.4;
Remove trailing whitespace. Noted in PR 39440 by Stathis Kamperis.
 1.24 24-Jul-2008  dholland Adjust this to not need -Wno-pointer-sign.
 1.23 01-Oct-2007  xtraeme branches: 1.23.8; 1.23.12;
Remove intval from %union, it's unused... ok christos@.
 1.22 17-Aug-2007  pavel branches: 1.22.2;
Attempt at fixing build failures after proplib was converted to bool:
FALSE -> false, TRUE -> true, boolean_t -> bool, int -> bool when
appropriate, include stdbool.h . proplib.h no longer provides boolean_t,
so it is necessary to change to bool.

From Tom Spindler (dogcow@).
 1.21 15-May-2007  elad Some Veriexec stuff that's been rotting in my tree for months.

Bug fixes:
- Fix crash reported by Scott Ellis on current-users@.

- Fix race conditions in enforcing the Veriexec rename and remove
policies. These are NOT security issues.

- Fix memory leak in rename handling when overwriting a monitored
file.

- Fix table deletion logic.

- Don't prevent query requests if not in learning mode.


KPI updates:
- fileassoc_table_run() now takes a cookie to pass to the callback.

- veriexec_table_add() was removed, it is now done internally. As a
result, there's no longer a need for VERIEXEC_TABLESIZE.

- veriexec_report() was removed, it is now internal.

- Perform sanity checks on the entry type, and enforce default type
in veriexec_file_add() rather than in veriexecctl.

- Add veriexec_flush(), used to delete all Veriexec tables, and
veriexec_dump(), used to fill an array with all Veriexec entries.


New features:
- Add a '-k' flag to veriexecctl, to keep the filenames in the kernel
database. This allows Veriexec to produce slightly more accurate
logs under certain circumstances. In the future, this can be either
replaced by vnode->pathname translation, or combined with it.

- Add a VERIEXEC_DUMP ioctl, to dump the entire Veriexec database.
This can be used to recover a database if the file was lost.
Example usage:

# veriexecctl dump > /etc/signatures

Note that only entries with the filename kept (that is, were loaded
with the '-k' flag) will be dumped.

Idea from Brett Lymn.

- Add a VERIEXEC_FLUSH ioctl, to delete all Veriexec entries. Sample
usage:

# veriexecctl flush

- Add a 'veriexec_flags' rc(8) variable, and make its default have
the '-k' flag. On systems using the default signatures file
(generaetd from running 'veriexecgen' with no arguments), this will
use additional 32kb of kernel memory on average.

- Add a '-e' flag to veriexecctl, to evaluate the fingerprint during
load. This is done automatically for files marked as 'untrusted'.


Misc. stuff:
- The code for veriexecctl was massively simplified as a result of
eliminating the need for VERIEXEC_TABLESIZE, and now uses a single
pass of the signatures file, making the loading somewhat faster.

- Lots of minor fixes found using the (still under development)
Veriexec regression testsuite.

- Some of the messages Veriexec prints were improved.

- Various documentation fixes.


All relevant man-pages were updated to reflect the above changes.

Binary compatibility with existing veriexecctl binaries is maintained.
 1.20 08-Dec-2006  elad Don't reset entry-type for every flag_spec.
 1.19 28-Nov-2006  elad branches: 1.19.2;
Make Veriexec use proplib(3) for kernel-userland data passing.

Obviously, this breaks the already unstable Veriexec ABI, but that's
it. Some cool additions are planned to be introduced, and this just
makes it so that NetBSD 4.0 users will be able to easily use them as
well.

This also removes the fingerprint type name limit, so relevant code
was adjusted.

Thoroughly tested (even uncovered a bug in proplib! thanks for fixing
that cube@!). Documentation updated.
 1.18 21-Nov-2006  elad Update my email address.
 1.17 30-Sep-2006  elad If Veriexec enforces access type, don't allow mmap() to use PROT_EXEC on
files that don't have the "indirect" flag. Also change the "library" alias
in veriexecctl(8) to mean "file, indirect".

okay blymn@
 1.16 05-Sep-2006  elad Fix two horrible bugs found during a routine audit session with Brett Lymn.

First one was incorrectly loading entries -- we were treating each file as
a mount, which resulted in huge mess. I have no excuse for how I didn't
catch this earlier.

Second, use the table name we create for the Veriexec sysctl node and not
the fixed "table0".

Both are fileassoc(9) integration fallout.
 1.15 14-Jul-2006  elad branches: 1.15.2;
misc cleanup: remove #if 0 code, unused var, and make pretty.
 1.14 14-Jul-2006  elad okay, since there was no way to divide this to two commits, here it goes..

introduce fileassoc(9), a kernel interface for associating meta-data with
files using in-kernel memory. this is very similar to what we had in
veriexec till now, only abstracted so it can be used more easily by more
consumers.

this also prompted the redesign of the interface, making it work on vnodes
and mounts and not directly on devices and inodes. internally, we still
use file-id but that's gonna change soon... the interface will remain
consistent.

as a result, veriexec went under some heavy changes to conform to the new
interface. since we no longer use device numbers to identify file-systems,
the veriexec sysctl stuff changed too: kern.veriexec.count.dev_N is now
kern.veriexec.tableN.* where 'N' is NOT the device number but rather a
way to distinguish several mounts.

also worth noting is the plugging of unmount/delete operations
wrt/fileassoc and veriexec.

tons of input from yamt@, wrstuden@, martin@, and christos@.
 1.13 05-Oct-2005  elad Introduce per-page fingerprints in Veriexec.

This closes a hole pointed out by Thor Lancelot Simon on tech-kern ~3
years ago.

The problem was with running binaries from remote storage, where our
kernel (and Veriexec) has no control over any changes to files.

An attacker could, after the fingerprint has been verified and
program loaded to memory, inject malicious code into the backing
store on the remote storage, followed by a forced flush, causing
a page-in of the malicious data from backing store, bypassing
integrity checks.

Initial implementation by Brett Lymn.
 1.12 06-Aug-2005  blymn Add and document some convenience aliases for commonly required option
combinations.
 1.11 02-Aug-2005  elad Support multiple entry types. Direct, indirect, and file can now be
combined in the signatures file using commas.
 1.10 13-Jun-2005  elad Some refactoring and bugfixes:

- Report line numbers correctly.
- Don't perform a 2nd pass when there are were errors during 1st.
- Support multiple, comma-separated flags. This is mostly a reworking of
some parser internals preparing for planned features.
 1.9 27-May-2005  elad Don't access a NULL pointer.
 1.8 20-May-2005  elad Remove leftovers from Vexec.
 1.7 21-Apr-2005  christos Minor cleanups, KNF, error handling consistency.
 1.6 21-Apr-2005  he Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.5 20-Apr-2005  blymn Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.4 19-Jan-2005  xtraeme branches: 1.4.2;
Kill __P(); WARNS=2
 1.3 06-Mar-2004  blymn Removed arbitrary 255 character limit on file field
Verify that the path in the file field is not > MAXPATHLEN, if it is
too long then skip that entry in the signature file.
 1.2 21-Dec-2002  wiz Remove traces of old names (verifiedexec_load and /dev/verifiedexec).
 1.1 23-Nov-2002  blymn Renamed verified exec fingerprint loader.
 1.4.2.8 15-Aug-2005  tron Pull up revision 1.12 (requested by elad in ticket #655):
Add and document some convenience aliases for commonly required option
combinations.
 1.4.2.7 12-Aug-2005  snj Pull up revision 1.11 (requested by elad in ticket #644):
Support multiple entry types. Direct, indirect, and file can now be
combined in the signatures file using commas.
 1.4.2.6 02-Jul-2005  tron Pull up revision 1.10 (requested by elad in ticket #487):
Some refactoring and bugfixes:
- Report line numbers correctly.
- Don't perform a 2nd pass when there are were errors during 1st.
- Support multiple, comma-separated flags. This is mostly a reworking of
some parser internals preparing for planned features.
 1.4.2.5 10-Jun-2005  tron Pull up revision 1.9 (requested by elad in ticket #389):
Don't access a NULL pointer.
 1.4.2.4 10-Jun-2005  tron Pull up revision 1.8 (requested by elad in ticket #389):
Remove leftovers from Vexec.
 1.4.2.3 10-Jun-2005  tron Pull up revision 1.7 (requested by elad in ticket #389):
Minor cleanups, KNF, error handling consistency.
 1.4.2.2 10-Jun-2005  tron Pull up revision 1.6 (requested by elad in ticket #389):
Make this compile again after the latest overhaul.
Use -I${.CURDIR} instead of -I. to support placement of objects elsewhere.
Make sure arguments to ctype functions are unsigned char by changing the
type of one function argument.
Fix "local declaration shadows global" warnings by renaming variables.
Fix printing of size_t variable to use %zu format instead of %u.
 1.4.2.1 10-Jun-2005  tron Pull up revision 1.5 (requested by elad in ticket #389):
Rototill of the verified exec functionality.
* We now use hash tables instead of a list to store the in kernel
fingerprints.
* Fingerprint methods handling has been made more flexible, it is now
even simpler to add new methods.
* the loader no longer passes in magic numbers representing the
fingerprint method so veriexecctl is not longer kernel specific.
* fingerprint methods can be tailored out using options in the kernel
config file.
* more fingerprint methods added - rmd160, sha256/384/512
* veriexecctl can now report the fingerprint methods supported by the
running kernel.
* regularised the naming of some portions of veriexec.
 1.15.2.1 08-Sep-2006  riz Pull up following revision(s) (requested by elad in ticket #121):
sbin/veriexecctl/veriexecctl_parse.y: revision 1.16
sys/dev/verified_exec.c: revision 1.43
Fix two horrible bugs found during a routine audit session with Brett Lymn.
First one was incorrectly loading entries -- we were treating each file as
a mount, which resulted in huge mess. I have no excuse for how I didn't
catch this earlier.
Second, use the table name we create for the Veriexec sysctl node and not
the fixed "table0".
Both are fileassoc(9) integration fallout.
 1.19.2.1 09-Dec-2006  bouyer Pull up following revision(s) (requested by elad in ticket #265):
sbin/veriexecctl/veriexecctl_parse.y: revision 1.20
Don't reset entry-type for every flag_spec.
 1.22.2.1 06-Nov-2007  matt sync with HEAD
 1.23.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.23.8.1 28-Sep-2008  mjf Sync with HEAD.
 1.25.4.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.1 04-Nov-2000  thorpej Add a program to manipulate watchdog timers.
 1.28 23-Sep-2022  riastradh wdogctl(8): Minor tweak suggested by a passing umarell.

Plus another wording improvement.
 1.27 22-Sep-2022  uwe wdogctl(8): fix -width in previous
 1.26 22-Sep-2022  riastradh wdogctl(8): Rework prose and markup in man page.

No functional change.
 1.25 11-Jul-2020  jruoho Xref x86/tco(4) instead of the parent x86/ichlpcib(4) bridge.
 1.24 11-Aug-2011  mbalmer Xr pwdog(4).
 1.23 19-Mar-2011  wiz Add missing comma.
 1.22 18-Mar-2011  jruoho Xref x86/ichlpcib(4) instead of ichlpcib(4).
 1.21 17-Jan-2011  jmcneill Xr acpiwdrt(4)
 1.20 23-Dec-2010  hauke First release that shipped wdogctl(8) was 1.6, not 1.5.1.
 1.19 18-May-2009  wiz Sort SEE ALSO.
 1.18 09-Jan-2008  xtraeme Xref gcscpcib(4).
 1.17 29-Dec-2007  xtraeme Xref itesio(4).
 1.16 23-Nov-2007  xtraeme branches: 1.16.2;
Mention evbarm/iopwdog(4) and swwdog(4).
 1.15 23-Nov-2007  xtraeme Mention some watchdog drivers in SEE ALSO and don't mention envsys(4)
or envstat(8), they don't have nothing in common with watchdogs.

<wizd> Bump date.
 1.14 13-Aug-2006  wiz branches: 1.14.8;
Bump date for new -x.
 1.13 13-Aug-2006  dyoung Add a flag to wdogctl(8), -x, that activates a user-mode timer that
is NOT disarmed when wdogctl closes the watchdog device. The -x
mode protects against the case where the kernel kills wdogctl,
sshd, and other essential userland programs (due to memory exhaustion,
for example), lobotomizing a mission-critical NetBSD system and
necessitating an operator visit to reboot it.
 1.12 21-Jan-2005  wiz "-offset indent" is fine for option lists -- re-add it,
backing out previous. jmmv does not disagree.
 1.11 13-Jan-2005  jmmv Remove extra indentation from the options list.
 1.10 11-Jan-2005  wiz Sort options. Fix a typo. Bump date for -e/-t.
 1.9 09-Jan-2005  smb Add a software watchdog timer facility. Because this slightly
changes the "tickle" model of wdogctl(8), it was modified as well;
while I was in there, I cleaned up the argument parsing.

The code was reviewed by simonb@.
 1.8 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.7 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.6 29-Jul-2002  wiz Format the path to a file with .Pa.
 1.5 29-Jul-2002  thorpej Note that not all watchdog timers can be disarmed once armed, and that
when such a case is encountered, an error message will be displayed and
the timer will remain armed if an attempt to disarm it is made.
 1.4 16-Nov-2001  wiz branches: 1.4.2;
Use standard section headers.
 1.3 05-Jun-2001  wiz Drop arguments of .Os.
 1.2 26-Nov-2000  ad typo
 1.1 04-Nov-2000  thorpej Add a program to manipulate watchdog timers.
 1.4.2.2 30-Jul-2002  lukem Pull up revision 1.6 (requested by thorpej in ticket #578):
Format the path to a file with .Pa.
 1.4.2.1 30-Jul-2002  lukem Pull up revision 1.5 (requested by thorpej in ticket #577):
Note that not all watchdog timers can be disarmed once armed, and that
when such a case is encountered, an error message will be displayed and
the timer will remain armed if an attempt to disarm it is made.
 1.14.8.2 23-Mar-2008  matt sync with HEAD
 1.14.8.1 09-Jan-2008  matt sync with HEAD
 1.16.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.16.2.1 23-Nov-2007  mjf file wdogctl.8 was added on branch mjf-devfs on 2008-02-18 21:04:18 +0000
 1.21 06-May-2015  pgoyette Use _PATH_WATCHDOG from <paths.h> instead of locally-defined value.
 1.20 27-Aug-2011  joerg static + __dead
 1.19 04-Jan-2011  wiz Fix fd leaks. Found by cppcheck.
 1.18 16-Mar-2009  lukem fix sign-compare issues
 1.17 13-Aug-2006  wiz branches: 1.17.28;
Add -x to usage.
 1.16 13-Aug-2006  dyoung Add a flag to wdogctl(8), -x, that activates a user-mode timer that
is NOT disarmed when wdogctl closes the watchdog device. The -x
mode protects against the case where the kernel kills wdogctl,
sshd, and other essential userland programs (due to memory exhaustion,
for example), lobotomizing a mission-critical NetBSD system and
necessitating an operator visit to reboot it.
 1.15 31-Aug-2005  dyoung If ioctl(,WDOGIOC_SMODE,) fails, kill the child process before
killing self, instead of the other way around.

Fixes a bug where the child process would use 100% CPU spinning
while it waited for its parent to arm a non-existent watchdog timer.
Now, the child process gets killed, as was intended.
 1.14 31-Aug-2005  dyoung Cosmetic: KNF.
 1.13 12-Jan-2005  drochner apply "& WDOG_MODE_MASK" at some places, fixes termination of the
usermode tickler process and watchdog display,
make error handling more reasonable in case a wdog disappeared
 1.12 11-Jan-2005  wiz Sort options in usage.
 1.11 09-Jan-2005  smb Add a software watchdog timer facility. Because this slightly
changes the "tickle" model of wdogctl(8), it was modified as well;
while I was in there, I cleaned up the argument parsing.

The code was reviewed by simonb@.
 1.10 05-Jan-2004  jmmv Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.9 13-Jul-2003  itojun use bounded string op
 1.8 23-Jun-2003  agc Add NetBSD RCS Ids.
 1.7 20-Feb-2001  cgd use getprogname()
 1.6 04-Feb-2001  christos fix nested extern
 1.5 11-Jan-2001  soren Remove extern __progname from enable_user(); no longer used.
 1.4 11-Jan-2001  lukem use explicit name rather than __progname in openlog
 1.3 10-Jan-2001  lukem don't use LOG_CONS
fix typo
 1.2 06-Nov-2000  minoura #include <string.h> for strlen() and strcpy().
 1.1 04-Nov-2000  thorpej Add a program to manipulate watchdog timers.
 1.17.28.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.17 25-Dec-2021  mlelstv Add support for a read-only edid attribute that shows the result of
WSDISPLAYIO_GET_EDID.

Uses code from sys/dev/videomode to parse and print the edid data.
 1.16 26-Oct-2021  rillig wsconsctl: revert adding LINTFLAGS

https://mail-index.netbsd.org/source-changes-d/2021/10/26/msg013482.html
https://mail-index.netbsd.org/source-changes-d/2021/10/26/msg013483.html
 1.15 11-Oct-2021  rillig wsconsctl: include correct header for lint

Running lint in non-tools mode picked up the header from the installed
system, not the one corresponding to the source code. The installed
header on NetBSD 9.99.88 does not define WSMOUSECFG_MAX yet.
 1.14 26-Oct-2008  apb Pass SED=${TOOL_SED:Q} in the environment to scripts run during the build.
 1.13 19-Oct-2008  apb Use ${TOOL_AWK} instead of ${AWK} or plain "awk" in make commands.
Pass AWK=${TOOL_AWK:Q} to shell scripts that use awk.
 1.12 20-Jan-2005  xtraeme branches: 1.12.26;
WARNS=2 is the default defined in sbin/Makefile.inc. (thanks wiz)
 1.11 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.10 21-Oct-2003  lukem Rework how MAKEVERBOSE operates:

* Don't bother prefixing commands with a line of ${_MKCMD}\
and instead rely upon "make -s". This is less intrusive on
all the Makefiles than the former. Idea from David Laight.

* Rename the variables use to print messages. The scheme now is:
_MKMSG_FOO Run _MKMSG 'foo'
_MKTARGET_FOO Run _MKMSG_FOO ${.TARGET}
From discussion with Alistair Crooks.
 1.9 19-Oct-2003  lukem rework to use the newer _MKMSGCREATE (et al) macros
 1.8 19-Oct-2003  lukem support MAKEVERBOSE and use ${HOST_SH}
 1.7 01-Aug-2003  lukem Rework how dependency generation is performed:

* DPSRCS contains extra dependencies, but is _NOT_ added to CLEANFILES.
This is a change of behaviour. If a Makefile wants the clean semantics
it must specifically append to CLEANFILES.
Resolves PR toolchain/5204.

* To recap: .d (depend) files are generated for all files in SRCS and DPSRCS
that have a suffix of: .c .m .s .S .C .cc .cpp .cxx

* If YHEADER is set, automatically add the .y->.h to DPSRCS & CLEANFILES

* Ensure that ${OBJS} ${POBJS} ${LOBJS} ${SOBJS} *.d depend upon ${DPSRCS}

* Deprecate the (short lived) DEPENDSRCS


Update the various Makefiles to these new semantics; generally either
adding to CLEANFILES (because DPSRCS doesn't do that anymore), or replacing
specific .o dependencies with DPSRCS entries.

Tested with "make -j 8 distribution" and "make distribution".
 1.6 29-Jul-2003  lukem move ${DEPENDSRCS} target to after .include <bsd.*.mk>
 1.5 28-Jul-2003  lukem Use ${DEPENDSRCS} as a target instead of .depend, now that
<bsd.dep.mk> builds .depend from .dep files.
 1.4 30-Jan-2002  tv Move the inclusion of <bsd.prog.mk> up so that keysym.h can have ${DESTDIR}
properly in its dependency list.
 1.3 03-Jul-2000  matt More include fixups and GCC 2.96 nonsense
 1.2 10-Jan-1999  augustss Make keysym.h depend on dev/wscons/wsksymdef.h.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.12.26.1 17-Jan-2009  mjf Sync with HEAD.
 1.19 20-Oct-2024  mlelstv Handle EDID data larger than 256 bytes.
 1.18 20-Oct-2024  mlelstv Retrieve configured console font with WSDISPLAYIO_GFONT.
 1.17 25-Dec-2021  mlelstv branches: 1.17.4;
Add support for a read-only edid attribute that shows the result of
WSDISPLAYIO_GET_EDID.

Uses code from sys/dev/videomode to parse and print the edid data.
 1.16 20-Mar-2012  matt Convert to C89 function definitions
 1.15 28-Apr-2008  martin branches: 1.15.20;
Remove clause 3 and 4 from TNF licenses
 1.14 13-Aug-2006  uwe branches: 1.14.18; 1.14.20;
Mark splash.enable and splash.progress write-only, there are no ioctls
to get the values.
 1.13 18-Feb-2006  jmcneill branches: 1.13.2;
Add the ability to control the splash screen.
wsconsctl -d -w splash.enable=<1|0> to toggle the splash screen, and
wsconsctl -d -w splash.progress=1 to update the splash animation
 1.12 05-Feb-2006  jmmv Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.11 30-Apr-2005  jmmv Do not use FLG_MODIFY to mark color settings. I thought this was used to
denote that a flag was readable/writeable, but that is achieved by passing
a 0 as the flags.

Thanks to uwe@ for finding this out and explaining me why it was wrong.
 1.10 27-Feb-2005  uwe branches: 1.10.2;
Support backlight, brightness and contrast wsdisplay paramteres.
Useful for hpc* ports.
 1.9 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.8 30-Jul-2004  jmmv Add 2004 to copyright notice as these has been significantly modified recently.
 1.7 30-Jul-2004  jmmv Do not show several variables when they are not available.

At the moment this only affects the display part, hiding console colors,
border color and/or console scrollback if their respective ioctls are
not supported by the running kernel.

Trying to write to these variables will still fail with the correct ioctl
error message.
 1.6 29-Jul-2004  jmmv Implement border color customization in wscons(4), only available for vga(4)
at the moment.

This includes the addition of two new wsdisplay ioctls, WSDISPLAY_{G,S}BORDER,
one to get the actual color and one to set it, respectively. Possible colors
match those defined by ANSI (and listed in wsdisplayvar.h).

It also adds two accessops to the underlying graphics device, getborder and
setborder, which mach their ioctl counterparts.

Two kernel options are added: WSDISPLAY_CUSTOM_BORDER, which enables the
ioctls described above (to customize the border color from userland after
boot), and WSDISPLAY_BORDER_COLOR, which sets the color at boot time.
The former is enabled by default on the GENERIC kernel, but not on INSTALL
(among others). The later is always commented out, leaving the usual black
border as a default.

wsconsctl is modified to allow accessing this value easily. For example,
'wsconsctl -d -w border=blue'.
 1.5 28-Jul-2004  jmmv Implement support to dynamically change wscons console and kernel colors.

Two new ioctls are added to the wsdisplay device, named WSDISPLAY_GMSGATTRS
and WSDISPLAY_SMSGATTRS, used to retrieve the actual values and set them,
respectively (the name, if you are wondering, comes from "message attributes").

A new emulop is added to the underlying display driver (only vga, for now)
which sets the new attribute for the whole screen, without having to clear
it. This is optional, which means that this also works with other drivers
that don't have this new operation.

Five new kernel options have been added, although only documented in
i386 kernels (for now):
- WSDISPLAY_CUSTOM_OUTPUT, which enables the ioctls described above to
change the colors dynamically from userland. This is enabled by default
in the GENERIC kernel (as well as others) but disabled on all INSTALL*
kernels (as this feature is useless there).
- WS_DEFAULT_COLATTR, WS_DEFAULT_MONOATTR, WS_DEFAULT_BG and WS_DEFAULT_FG,
which specify the default colors for the console at boot time. These have
the same meaning as the (already existing) WS_KERNEL_* variables.

wsconsctl is modified to add msg.default.{attrs,bg,fg} and
msg.kernel.{attrs,bg,fg} to the display part, so that colors can be changed
after boot.

Tested on NetBSD/i386 with vga (and vga in mono mode), and on NetBSD/mac68k.
No objections in tech-kern@.
 1.4 03-Jun-2004  christos If scrolling support is not compiled in the kernel, fail gracefully.
 1.3 28-May-2004  christos PR/19925: David Ferlier: add scrolling support to wscons
 1.2 07-Apr-2002  hannken branches: 1.2.4;
Allow setting display's font.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.2.4.2 07-Jun-2004  tron Pull up revision 1.4 (requested by recht in ticket #451):
If scrolling support is not compiled in the kernel, fail gracefully.
 1.2.4.1 07-Jun-2004  tron Pull up revision 1.3 (requested by recht in ticket #451):
PR/19925: David Ferlier: add scrolling support to wscons
 1.10.2.1 01-May-2005  tron Pull up revision 1.11 (requested by jmmv in ticket #227):
Do not use FLG_MODIFY to mark color settings. I thought this was used to
denote that a flag was readable/writeable, but that is achieved by passing
a 0 as the flags.
Thanks to uwe@ for finding this out and explaining me why it was wrong.
 1.13.2.1 14-Aug-2006  ghen Pull up following revision(s) (requested by uwe in ticket #22):
sbin/wsconsctl/display.c: revision 1.14
Mark splash.enable and splash.progress write-only, there are no ioctls
to get the values.
 1.14.20.1 18-May-2008  yamt sync with head.
 1.14.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.15.20.1 17-Apr-2012  yamt sync with head
 1.17.4.1 02-Aug-2025  perseant Sync with HEAD
 1.12 22-Sep-2021  mlelstv fail on error, not on success.
 1.11 13-Sep-2020  mlelstv Document keyboard mode ioctls and let wsconsctl manage it.
 1.10 23-Nov-2018  mlelstv When merging entries with the keyboard map, print only the resulting changes.

While here, replace bcopy with standad memcpy.
 1.9 28-Apr-2008  martin branches: 1.9.60; 1.9.62;
Remove clause 3 and 4 from TNF licenses
 1.8 05-Feb-2006  jmmv branches: 1.8.20; 1.8.22;
Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.7 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.6 30-Jul-2004  jmmv Add 2004 to copyright notice as these has been significantly modified recently.
 1.5 28-Jun-2004  christos PR/26101: Dheeraj: WSKBDIO_GETSCROLL: Operation not supported by device
should not be fatal.
 1.4 28-May-2004  christos PR/19925: David Ferlier: add scrolling support to wscons
 1.3 19-Sep-2001  ad branches: 1.3.4;
- Sync device lists with wsconsio.h.
- Get/set keyclick on keyboards that support it.
 1.2 06-Jul-2000  hannken Fix type of WSKBDIO_?ETENCODING.
 1.1 28-Dec-1998  hannken branches: 1.1.10;
wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.1.10.1 07-Jul-2000  hannken Pull up revision 1.2:
- fix type of kbdencoding.
 1.3.4.2 02-Jul-2004  he Pull up revision 1.5 (requested by recht in ticket #574):
It should not be a fatal error If the WSKBDIO_GETSCROLL is
not supported by the device. Fixes PR#26101.
 1.3.4.1 07-Jun-2004  tron Pull up revision 1.4 (requested by recht in ticket #451):
PR/19925: David Ferlier: add scrolling support to wscons
 1.8.22.1 18-May-2008  yamt sync with head.
 1.8.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.62.1 10-Jun-2019  christos Sync with HEAD
 1.9.60.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.10 29-Jan-2010  drochner follow KS_GROUP_Ascii->KS_GROUP_Plain rename in kernel,
noticed by Andreas Gustafsson
 1.9 06-Apr-2009  lukem fix sign-compare issues
 1.8 28-Apr-2008  martin branches: 1.8.6;
Remove clause 3 and 4 from TNF licenses
 1.7 05-Feb-2006  jmmv branches: 1.7.20; 1.7.22;
Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.6 26-Jun-2005  christos constify.
 1.5 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.4 03-Jul-2000  matt More include fixups and GCC 2.96 nonsense
 1.3 08-Feb-1999  hannken Numbers 0..9 must be treated as keysyms depending on context. Allow
`unknown_%d' for keysym with value `%d' so wsconsctl may read its own
output. Closes PR 6888.
 1.2 02-Jan-1999  nathanw Update for the 1990s: don't try to pass an integer in a pointer in ksym2name().
Makes this build on the alpha.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.7.22.1 18-May-2008  yamt sync with head.
 1.7.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.12 23-Oct-2012  christos allow non-command keysyms to be mapped as commands (experimental)
 1.11 23-Oct-2012  christos - remove obsolete = { syntac
- print context for yyerror()
- add a production to clarify a syntax error
 1.10 27-Aug-2011  joerg branches: 1.10.2; 1.10.8;
Mark yyerror as static and dead.
 1.9 30-Nov-2010  phx Allow standalone commands to be recognized, as in the in-kernel keymaps.
Also allow the Cmd token. Examples:
keycode 210 = Cmd Cmd_BrightnessUp
keycode 211 = Cmd_VolumeToggle
 1.8 06-Apr-2009  lukem fix sign-compare issues
 1.7 28-Apr-2008  martin branches: 1.7.6;
Remove clause 3 and 4 from TNF licenses
 1.6 05-Feb-2006  jmmv branches: 1.6.20; 1.6.22;
Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.5 26-Jun-2005  christos constify.
 1.4 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.3 27-Jun-2004  itohy Fix typos in comment.
 1.2 08-Feb-1999  hannken Numbers 0..9 must be treated as keysyms depending on context. Allow
`unknown_%d' for keysym with value `%d' so wsconsctl may read its own
output. Closes PR 6888.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.6.22.1 18-May-2008  yamt sync with head.
 1.6.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.10.8.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.10.2.1 30-Oct-2012  yamt sync with head
 1.7 24-May-2011  joerg input is unused
 1.6 30-Nov-2010  phx Allow standalone commands to be recognized, as in the in-kernel keymaps.
Also allow the Cmd token. Examples:
keycode 210 = Cmd Cmd_BrightnessUp
keycode 211 = Cmd_VolumeToggle
 1.5 28-Oct-2009  christos add %option noyywrap
 1.4 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3 05-Feb-2006  jmmv branches: 1.3.20; 1.3.22;
Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.2 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.3.22.1 18-May-2008  yamt sync with head.
 1.3.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.2 26-Jun-2005  christos constify.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.11 28-Sep-2021  nia wsconsctl: allow the new "precision scrolling" variables to be configured
 1.10 24-Dec-2012  khorben Added complete support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.

Reviewed by uwe@ (thank you!)
 1.9 24-Dec-2012  khorben Added read-only support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.

Reviewed by uwe@ (thank you!)
 1.8 28-Apr-2008  martin branches: 1.8.20; 1.8.22; 1.8.26;
Remove clause 3 and 4 from TNF licenses
 1.7 05-Feb-2006  jmmv branches: 1.7.20; 1.7.22;
Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.6 05-Feb-2006  jmmv Fix two pastos in the code to set 'samplerate'.
 1.5 05-Feb-2006  jmmv Add support to automatically repeat mouse button events in wsmouse(4) and
change wsconsctl(4) so that this is configurable.

This is specially useful for mice that provide page up/down buttons instead
of a real wheel and that do not send events repeatedly from the hardware.
(E.g.: Logitech Marble Mouse.)

No objections in tech-kern@.
 1.4 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.3 15-Nov-1999  ad If we changed the sample rate or resolution, then say so.
 1.2 11-Nov-1999  ad Allow setting mouse resolution and sample rate.
 1.1 28-Dec-1998  hannken branches: 1.1.6;
wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.1.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.7.22.1 18-May-2008  yamt sync with head.
 1.7.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.26.1 25-Feb-2013  tls resync with head
 1.8.22.1 11-Feb-2013  riz Pull up following revision(s) (requested by khorben in ticket #814):
sbin/wsconsctl/wsconsctl.h: revision 1.12
sbin/wsconsctl/mouse.c: revision 1.9
sbin/wsconsctl/mouse.c: revision 1.10
sbin/wsconsctl/util.c: revision 1.31
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).
Reviewed by uwe@ (thank you!)
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).
Reviewed by uwe@ (thank you!)
Added read-only support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.
Reviewed by uwe@ (thank you!)
Added complete support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.
Reviewed by uwe@ (thank you!)
 1.8.20.1 23-Jan-2013  yamt sync with head
 1.34 20-Oct-2024  mlelstv Add descriptions for all display types in wsconsio.h.
 1.33 25-Dec-2021  mlelstv branches: 1.33.4;
Add support for a read-only edid attribute that shows the result of
WSDISPLAYIO_GET_EDID.

Uses code from sys/dev/videomode to parse and print the edid data.
 1.32 23-Nov-2018  mlelstv When merging entries with the keyboard map, print only the resulting changes.

While here, replace bcopy with standad memcpy.
 1.31 24-Dec-2012  khorben branches: 1.31.28; 1.31.30;
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).

Reviewed by uwe@ (thank you!)
 1.30 15-Dec-2011  phx branches: 1.30.2; 1.30.6;
Amiga wscons/Xorg support, first phase.
Implemented wscons for CV64 and CV64/3D. Other graphics cards drivers are
prepared for it, but will not be attempted before Xorg is not running.
The wscons support is disabled by default. A GENERIC kernel should behave
like always. Use WSCONS to try out a kernel with wscons support.
Done by rkujawa@ and phx@.
 1.29 06-Feb-2011  pooka branches: 1.29.4;
update macro names to match new ones
(i don't know why they changed, just fixing the build)
 1.28 06-Apr-2009  lukem branches: 1.28.2;
fix sign-compare issues
 1.27 28-Apr-2008  martin branches: 1.27.6;
Remove clause 3 and 4 from TNF licenses
 1.26 19-Jun-2006  gdamore branches: 1.26.20; 1.26.22;
Initial import of bluetooth stack on behalf of Iain Hibbert. (plunky@,
NetBSD Foundation Membership still pending.) This stack was written by
Iain under sponsorship from Itronix Inc.

The stack includes support for rfcomm networking (networking via your
bluetooth enabled cell phone), hid devices (keyboards/mice), and headsets.

Drivers for both PCMCIA and USB bluetooth controllers are included.
 1.25 05-Feb-2006  jmmv Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.24 05-Feb-2006  jmmv Add support to automatically repeat mouse button events in wsmouse(4) and
change wsconsctl(4) so that this is configurable.

This is specially useful for mice that provide page up/down buttons instead
of a real wheel and that do not send events repeatedly from the hardware.
(E.g.: Logitech Marble Mouse.)

No objections in tech-kern@.
 1.23 26-Jun-2005  christos constify.
 1.22 31-Jan-2005  joff o Add missing SGI wskbd type
o Add new MATRIXKP wskbd type
 1.21 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.20 30-Jul-2004  jmmv Do not show several variables when they are not available.

At the moment this only affects the display part, hiding console colors,
border color and/or console scrollback if their respective ioctls are
not supported by the running kernel.

Trying to write to these variables will still fail with the correct ioctl
error message.
 1.19 28-Jul-2004  jmmv Implement support to dynamically change wscons console and kernel colors.

Two new ioctls are added to the wsdisplay device, named WSDISPLAY_GMSGATTRS
and WSDISPLAY_SMSGATTRS, used to retrieve the actual values and set them,
respectively (the name, if you are wondering, comes from "message attributes").

A new emulop is added to the underlying display driver (only vga, for now)
which sets the new attribute for the whole screen, without having to clear
it. This is optional, which means that this also works with other drivers
that don't have this new operation.

Five new kernel options have been added, although only documented in
i386 kernels (for now):
- WSDISPLAY_CUSTOM_OUTPUT, which enables the ioctls described above to
change the colors dynamically from userland. This is enabled by default
in the GENERIC kernel (as well as others) but disabled on all INSTALL*
kernels (as this feature is useless there).
- WS_DEFAULT_COLATTR, WS_DEFAULT_MONOATTR, WS_DEFAULT_BG and WS_DEFAULT_FG,
which specify the default colors for the console at boot time. These have
the same meaning as the (already existing) WS_KERNEL_* variables.

wsconsctl is modified to add msg.default.{attrs,bg,fg} and
msg.kernel.{attrs,bg,fg} to the display part, so that colors can be changed
after boot.

Tested on NetBSD/i386 with vga (and vga in mono mode), and on NetBSD/mac68k.
No objections in tech-kern@.
 1.18 02-Apr-2004  heas Add descriptions for SGI & Sun specific displays that were added to wsconsio.h
in revisions 1.59 - 1.61.
 1.17 21-Jan-2004  heas Add text descriptions for wskbd types sun and sun-type5.
 1.16 31-Jan-2003  thomas Define Atari keyboard type.
 1.15 10-Dec-2002  itohy Add WSKBD_TYPE_MAPLE and WSMOUSE_TYPE_MAPLE for Dreamcast Maple bus devices.
 1.14 07-Apr-2002  hannken Allow setting display's font.
 1.13 24-Feb-2002  ad Add WSMOUSE_TYPE_MAXINE.
 1.12 13-Jan-2002  jandberg added amiga display/mouse/keyboard types
 1.11 04-Dec-2001  ad Fix typo; pointed out by Gregory McGarry. :-)
 1.10 04-Dec-2001  gmcgarry Update for new HP devices. Add some others while here.
Pointed out by Andrew Doran.
 1.9 19-Sep-2001  ad - Sync device lists with wsconsio.h.
- Get/set keyclick on keyboards that support it.
 1.8 14-Mar-2000  sato add some keyboard and mouse type from sys/dev/wscons/wsconsio.h.
 1.7 13-Mar-2000  ad Add new framebuffer types since 1.4 and change descriptions on a few
existing entries.
 1.6 21-Dec-1999  drochner remove a leftover debug message
 1.5 10-Nov-1999  drochner allow to set multiple keyboard "variants" simultanously.
Follows PR kern/8456 by Michael Eriksson <eramore@era-t.ericsson.se>,
implemented diffently.
 1.4 30-Dec-1998  augustss branches: 1.4.6;
Add USB keyboard type.
 1.3 30-Dec-1998  augustss Add a wscons display type `unknown' that the generic VGA driver can
return until someone fixes it for real.
 1.2 30-Dec-1998  augustss Add a special wsmouse type for USB mice.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.4.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.26.22.1 18-May-2008  yamt sync with head.
 1.26.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.27.6.1 13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.28.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.29.4.2 23-Jan-2013  yamt sync with head
 1.29.4.1 17-Apr-2012  yamt sync with head
 1.30.6.1 25-Feb-2013  tls resync with head
 1.30.2.1 11-Feb-2013  riz Pull up following revision(s) (requested by khorben in ticket #814):
sbin/wsconsctl/wsconsctl.h: revision 1.12
sbin/wsconsctl/mouse.c: revision 1.9
sbin/wsconsctl/mouse.c: revision 1.10
sbin/wsconsctl/util.c: revision 1.31
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).
Reviewed by uwe@ (thank you!)
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).
Reviewed by uwe@ (thank you!)
Added read-only support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.
Reviewed by uwe@ (thank you!)
Added complete support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.
Reviewed by uwe@ (thank you!)
 1.31.30.1 10-Jun-2019  christos Sync with HEAD
 1.31.28.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.33.4.1 02-Aug-2025  perseant Sync with HEAD
 1.30 13-Jul-2020  nia Move description of keyboard layouts to wskbd.4, add newer layouts

Previously, the best reference was pckbd.4. This does not make much
sense to read if you are on, say, an evbarm device with only USB.

wsconsctl.8 contained a vaguer description of supported language names,
which isn't very useful because you can't pass full language names
to the command. Point readers to wskbd.4 instead.

Note in the wskbd.4 page that while all layouts are generally supported
by pckbd(4) and ukbd(4), older keyboard interfaces might only support
a subset.
 1.29 12-Jul-2020  nia More keyboard layouts
 1.28 14-Feb-2012  wiz branches: 1.28.42;
Fix typo.
 1.27 09-Jun-2009  snj branches: 1.27.6;
Mention a number of keyboard encodings.
From Jukka Ruohonen in PR kern/15955.
 1.26 29-Nov-2008  jnemeth PR/40059 - Bug Hunting -- add Xref to wscons.conf(5)
 1.25 30-Apr-2008  martin branches: 1.25.4; 1.25.6;
Convert TNF licenses to new 2 clause variant
 1.24 22-Oct-2006  christos branches: 1.24.2; 1.24.14; 1.24.18; 1.24.20;
Mention include proper file for keyboard defines; from Zafer.
 1.23 11-Sep-2005  wiz Fix typo. From YOMURA Masanori in private mail.
 1.22 24-Jul-2005  wiz Sort options. Various other fixes.
 1.21 24-Jul-2005  rpaulo Add examples for scroll.fastlines and scroll.slowlines.
Also, bump the man page date.

ok wiz@, hubertf@
 1.20 03-May-2005  augustss Show an example of turning off auto repeat.
 1.19 03-May-2005  wiz Fix a typo and add an s.
 1.18 03-May-2005  augustss Add an example for setting keyboard auto repeat rate.
 1.17 29-Apr-2005  augustss Change the default controlling devices to /dev/wskbd and /dev/wsmouse
(instead wskbd0 and wsmouse0), this way changes will affect all devices
instead of just the first one.
 1.16 05-Apr-2005  hubertf Portuguese keyboards are supported to.
By Rui Paulo in PR 29884.
 1.15 30-Jul-2004  jmmv branches: 1.15.2;
Add 2004 to copyright notice as these has been significantly modified recently.
 1.14 30-Jul-2004  jmmv Add an example on how to change the kernel message colors. This is
illustrative because it shows the use of the '-d' flag and how one can
set multiple variables in the same run of wsconsctl(8).
 1.13 13-May-2004  wiz Add comma in enumeration.
 1.12 13-May-2004  pooka + note finnish encoding
+ shuffle things around a bit, since the encodings we were listing
were not countries (most of them were languages)
 1.11 05-Apr-2003  wiz branches: 1.11.4;
Some minor fixes from Soren Jacobsen in PR 21017.
 1.10 25-Feb-2003  wiz .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
 1.9 03-Oct-2002  wiz New sentence, new line. From Robert Elz.
 1.8 19-Aug-2002  wiz Sort supported languages, and sync them with reality, as suggested by
Julio Merino in bin/17993, with a minor correction.
 1.7 16-Nov-2001  wiz Whitespace nits
 1.6 03-Oct-2000  bjh21 Put the sections in the canonical order.
Fix formatting of '=' and '+='.
File names are .Pa, not .Ar.
 1.5 12-Sep-1999  kleink Use full month names with .Dd, as per mdoc.samples(7).
 1.4 28-Jun-1999  agc Flesh out the manual page, add an examples section, and correct some of the
English.
 1.3 03-Feb-1999  augustss Xref wscons wsconscfg wsfontload
 1.2 30-Dec-1998  augustss Remove a slight ambiguity in the flag description.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.11.4.1 13-May-2005  riz Pull up revision 1.17 (requested by augustss in ticket #1490):
Change the default controlling devices to /dev/wskbd and /dev/wsmouse
(instead wskbd0 and wsmouse0), this way changes will affect all devices
instead of just the first one.
 1.15.2.1 01-May-2005  tron Pull up revision 1.17 (requested by augustss in ticket #220):
Change the default controlling devices to /dev/wskbd and /dev/wsmouse
(instead wskbd0 and wsmouse0), this way changes will affect all devices
instead of just the first one.
 1.24.20.1 18-May-2008  yamt sync with head.
 1.24.18.2 17-Jan-2009  mjf Sync with HEAD.
 1.24.18.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.14.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by dholland in ticket #1345):
sbin/wsconsctl/wsconsctl.8: revision 1.26
PR/40059 - Bug Hunting -- add Xref to wscons.conf(5)
 1.24.2.1 18-Aug-2009  bouyer Pull up following revision(s) (requested by dholland in ticket #1345):
sbin/wsconsctl/wsconsctl.8: revision 1.26
PR/40059 - Bug Hunting -- add Xref to wscons.conf(5)
 1.25.6.1 26-Jul-2009  snj branches: 1.25.6.1.2;
Pull up following revision(s) (requested by dholland in ticket #873):
sbin/wsconsctl/wsconsctl.8: revision 1.26
PR/40059 - Bug Hunting -- add Xref to wscons.conf(5)
 1.25.6.1.2.1 21-Apr-2010  matt sync to netbsd-5
 1.25.4.1 26-Jul-2009  snj Pull up following revision(s) (requested by dholland in ticket #873):
sbin/wsconsctl/wsconsctl.8: revision 1.26
PR/40059 - Bug Hunting -- add Xref to wscons.conf(5)
 1.27.6.1 17-Apr-2012  yamt sync with head
 1.28.42.2 18-Jul-2020  martin Fix editor mishap during processing of ticket #1002
 1.28.42.1 13-Jul-2020  martin Pull up following revision(s) (requested by nia in ticket #1002):

sys/dev/wscons/wsksymdef.h: revision 1.68
sys/dev/wscons/wsksymdef.h: revision 1.69
sys/dev/pckbport/wskbdmap_mfii.c: revision 1.28
sys/dev/pckbport/wskbdmap_mfii.c: revision 1.29
sys/dev/hid/hidkbdmap.c: revision 1.10
share/man/man4/pckbd.4: revision 1.23
share/man/man4/wskbd.4: revision 1.18
share/man/man4/wskbd.4: revision 1.19
share/man/man4/pckbd.4: revision 1.25
sys/dev/wscons/wsksymdef.h: revision 1.70
sys/dev/wscons/wsksymdef.h: revision 1.71
sys/dev/pckbport/wskbdmap_mfii.c: revision 1.30
sys/dev/wscons/wsksymdef.h: revision 1.72
sys/dev/pckbport/wskbdmap_mfii.c: revision 1.31
sys/dev/wscons/wsksymdef.h: revision 1.73
sys/dev/pckbport/wskbdmap_mfii.c: revision 1.32
sys/dev/pckbport/wskbdmap_mfii.c: revision 1.33
sys/dev/hid/hidkbdmap.c: revision 1.4
sbin/wsconsctl/wsconsctl.8: revision 1.30
sys/dev/hid/hidkbdmap.c: revision 1.5
etc/wscons.conf: revision 1.20
sys/dev/hid/hidkbdmap.c: revision 1.6
etc/wscons.conf: revision 1.21
sys/dev/hid/hidkbdmap.c: revision 1.7
sys/dev/hid/hidkbdmap.c: revision 1.8
sys/dev/hid/hidkbdmap.c: revision 1.9

Add support for the Brazilian keyboard layout to pckbd and ukbd.

This is significantly different from the European Portugese layout,
and was pieced together from Wikipedia, X11 layout files, and to
some extent with trial and error.

Thanks to lun-4 for helping test this.

PR kern/44570
Update lists of keyboard layouts to add Turkish and Brazilian

Bring br.nodead closer to X11

Add Estonian layout as a variation of Swedish for ukbd and pckbd

Add KB_TR for uhid keyboards (it was PS/2 only, this seems wrong)

Add Icelandic keyboard layout to ukbd/pckbd.

Add keyboard layout for Latin American Spanish to ukbd/pckbd

Canadian French keyboard layout for ukbd/pckbd

Clarify that KB_TR is the "Q" layout - there's two standards for Turkish.

Move description of keyboard layouts to wskbd.4, add newer layouts

Previously, the best reference was pckbd.4. This does not make much
sense to read if you are on, say, an evbarm device with only USB.
wsconsctl.8 contained a vaguer description of supported language names,
which isn't very useful because you can't pass full language names
to the command. Point readers to wskbd.4 instead.

Note in the wskbd.4 page that while all layouts are generally supported
by pckbd(4) and ukbd(4), older keyboard interfaces might only support
a subset.

wskbd.4: Add KB_LA

Point readers at wskbd.4
 1.19 23-Nov-2018  mlelstv When merging entries with the keyboard map, print only the resulting changes.

While here, replace bcopy with standad memcpy.
 1.18 25-Aug-2008  dholland branches: 1.18.58; 1.18.60;
Clarify message that says the map isn't shown when -a is given.
Resolves PR 32436 from Igor Sobrado based on a suggestion by
Dieter Roelants, except I expanded the message further.
 1.17 28-Apr-2008  martin branches: 1.17.2;
Remove clause 3 and 4 from TNF licenses
 1.16 15-Dec-2007  perry branches: 1.16.4; 1.16.6;
convert __attribute__s to applicable cdefs.h macros
 1.15 15-Dec-2007  perry include sys/cdefs.h so that __attribute__ can be fixed later
 1.14 05-Feb-2006  jmmv branches: 1.14.10; 1.14.12;
Style fixes:
- Use EXIT_SUCCESS/EXIT_FAILURE where appropriate.
- Cut long lines.
- Properly indent continuation of lines.
- Sort includes.
- Replace u_int with unsigned int.
- Remove parenthesis around return values.
- Add blank line at the beginning of functions without local parameters.
- Cast *printf calls to void.
 1.13 26-Jun-2005  christos constify.
 1.12 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.11 29-Apr-2005  augustss Change the default controlling devices to /dev/wskbd and /dev/wsmouse
(instead wskbd0 and wsmouse0), this way changes will affect all devices
instead of just the first one.
 1.10 19-Jan-2005  xtraeme branches: 1.10.2;
Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.9 30-Jul-2004  jmmv Add 2004 to copyright notice as these has been significantly modified recently.
 1.8 30-Jul-2004  jmmv Do not show several variables when they are not available.

At the moment this only affects the display part, hiding console colors,
border color and/or console scrollback if their respective ioctls are
not supported by the running kernel.

Trying to write to these variables will still fail with the correct ioctl
error message.
 1.7 25-Jun-2004  wiz Sync usage with man page (add -w name+=value).
Closes PR 25876 by Kouichirou Hiratsuka.
 1.6 04-May-2003  jmmv branches: 1.6.2;
Explicitly close open file descriptor before exiting.
 1.5 18-Feb-2002  yamt s/read only/write only/ for FLG_WRONLY.
 1.4 19-Feb-2001  cgd convert to use getprogname()
 1.3 03-Jul-2000  matt More include fixups and GCC 2.96 nonsense
 1.2 29-Dec-1998  hannken Display usage information if called without arguments.
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.6.2.1 22-Aug-2004  tron branches: 1.6.2.1.2;
Sync usage with man page (add -w name+=value).
Closes PR 25876 by Kouichirou Hiratsuka.
 1.6.2.1.2.1 13-May-2005  riz Pull up revision 1.11 (requested by augustss in ticket #1490):
Change the default controlling devices to /dev/wskbd and /dev/wsmouse
(instead wskbd0 and wsmouse0), this way changes will affect all devices
instead of just the first one.
 1.10.2.1 01-May-2005  tron Pull up revision 1.11 (requested by augustss in ticket #220):
Change the default controlling devices to /dev/wskbd and /dev/wsmouse
(instead wskbd0 and wsmouse0), this way changes will affect all devices
instead of just the first one.
 1.14.12.1 27-Dec-2007  mjf Sync with HEAD.
 1.14.10.1 09-Jan-2008  matt sync with HEAD
 1.16.6.1 18-May-2008  yamt sync with head.
 1.16.4.2 28-Sep-2008  mjf Sync with HEAD.
 1.16.4.1 02-Jun-2008  mjf Sync with HEAD.
 1.17.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.18.60.1 10-Jun-2019  christos Sync with HEAD
 1.18.58.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.14 25-Dec-2021  mlelstv Add support for a read-only edid attribute that shows the result of
WSDISPLAYIO_GET_EDID.

Uses code from sys/dev/videomode to parse and print the edid data.
 1.13 23-Nov-2018  mlelstv When merging entries with the keyboard map, print only the resulting changes.

While here, replace bcopy with standad memcpy.
 1.12 24-Dec-2012  khorben branches: 1.12.28; 1.12.30;
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).

Reviewed by uwe@ (thank you!)
 1.11 27-Aug-2011  joerg branches: 1.11.2; 1.11.4; 1.11.8;
Mark yyerror as static and dead.
 1.10 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9 05-Feb-2006  jmmv branches: 1.9.20; 1.9.22;
Add support to automatically repeat mouse button events in wsmouse(4) and
change wsconsctl(4) so that this is configurable.

This is specially useful for mice that provide page up/down buttons instead
of a real wheel and that do not send events repeatedly from the hardware.
(E.g.: Logitech Marble Mouse.)

No objections in tech-kern@.
 1.8 26-Jun-2005  christos constify.
 1.7 19-Jan-2005  xtraeme Kill __P(), ANSIfy, remove main() prototype; WARNS=2
 1.6 30-Jul-2004  jmmv Add 2004 to copyright notice as these has been significantly modified recently.
 1.5 30-Jul-2004  jmmv Do not show several variables when they are not available.

At the moment this only affects the display part, hiding console colors,
border color and/or console scrollback if their respective ioctls are
not supported by the running kernel.

Trying to write to these variables will still fail with the correct ioctl
error message.
 1.4 28-Jul-2004  jmmv Implement support to dynamically change wscons console and kernel colors.

Two new ioctls are added to the wsdisplay device, named WSDISPLAY_GMSGATTRS
and WSDISPLAY_SMSGATTRS, used to retrieve the actual values and set them,
respectively (the name, if you are wondering, comes from "message attributes").

A new emulop is added to the underlying display driver (only vga, for now)
which sets the new attribute for the whole screen, without having to clear
it. This is optional, which means that this also works with other drivers
that don't have this new operation.

Five new kernel options have been added, although only documented in
i386 kernels (for now):
- WSDISPLAY_CUSTOM_OUTPUT, which enables the ioctls described above to
change the colors dynamically from userland. This is enabled by default
in the GENERIC kernel (as well as others) but disabled on all INSTALL*
kernels (as this feature is useless there).
- WS_DEFAULT_COLATTR, WS_DEFAULT_MONOATTR, WS_DEFAULT_BG and WS_DEFAULT_FG,
which specify the default colors for the console at boot time. These have
the same meaning as the (already existing) WS_KERNEL_* variables.

wsconsctl is modified to add msg.default.{attrs,bg,fg} and
msg.kernel.{attrs,bg,fg} to the display part, so that colors can be changed
after boot.

Tested on NetBSD/i386 with vga (and vga in mono mode), and on NetBSD/mac68k.
No objections in tech-kern@.
 1.3 07-Apr-2002  hannken Allow setting display's font.
 1.2 04-Feb-2001  christos avoid redundant declaration
 1.1 28-Dec-1998  hannken wsconsctl(8) - a program to manipulate wscons devices.

- lacks wsdisplay support (driver needs work on ioctls).
- man page needs work.
 1.9.22.1 18-May-2008  yamt sync with head.
 1.9.20.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.8.1 25-Feb-2013  tls resync with head
 1.11.4.1 11-Feb-2013  riz Pull up following revision(s) (requested by khorben in ticket #814):
sbin/wsconsctl/wsconsctl.h: revision 1.12
sbin/wsconsctl/mouse.c: revision 1.9
sbin/wsconsctl/mouse.c: revision 1.10
sbin/wsconsctl/util.c: revision 1.31
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).
Reviewed by uwe@ (thank you!)
Added a field type for signed integers. This is required when handling
touchscreen calibration values, which is about to be implemented in
wsconsctl (see PR kern/45872).
Reviewed by uwe@ (thank you!)
Added read-only support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.
Reviewed by uwe@ (thank you!)
Added complete support for touchscreen calibration (see PR kern/45872).
Tested with the uts(4) driver, as well as with mice without calibration
support.
Reviewed by uwe@ (thank you!)
 1.11.2.1 23-Jan-2013  yamt sync with head
 1.12.30.1 10-Jun-2019  christos Sync with HEAD
 1.12.28.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts

RSS XML Feed