Home | History | Annotate | only in /src/usr.sbin/makefs
History log of /src/usr.sbin/makefs
RevisionDateAuthorComments
 1.43 25-Sep-2025  mrg remove the recently added -O0 for vax & gcc 14, the compiler bug is fixed.

thanks to Kalvis.
 1.42 24-Sep-2025  mrg vax-gcc14 triggers an ICE here, same one as most new ones, ending in:

in extract_insn, at recog.cc:2818
 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 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.39 09-Apr-2022  riastradh branches: 1.39.2;
makefs(8): Needs -lm for ceil in udf as a host tool too.
 1.38 06-Apr-2022  hauke udf.c uses math library functions.
 1.37 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.36 05-Aug-2013  reinoud branches: 1.36.26;
Implement `makefs -t udf'.

Formatting options may be enhanced to make it more in line with newfs_udf on
say labeling.
 1.35 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.34 26-Jan-2013  christos add debugging, fix warnings.
 1.33 23-Jan-2013  christos ok, we can create the filesystem now.
 1.32 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.31 19-Apr-2012  christos branches: 1.31.2;
WARNS=5
 1.30 19-Apr-2012  ttoth added chfs support for makefs
 1.29 18-Jul-2011  tron branches: 1.29.2;
Re-enable v7fs support in the tools version of "makefs" after the
issues have been fixed by Alan Barrett. Tested under Mac OS X.
 1.28 18-Jul-2011  tron Define "USE_V7FS" in the makefile of the directory with the actual source.
 1.27 18-Jul-2011  tron Don't include v7fs support into tool version of "makefs" because it
breaks the build.
 1.26 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.25 22-Apr-2009  lukem Enable WARNS=4 by default, except for:
cpuctl dumplfs hprop ipf iprop-log kadmin kcm kdc kdigest
kimpersonate kstash ktutil makefs ndbootd ntp pppd quot
racoon racoonctl rtadvd sntp sup tcpdchk tcpdmatch tcpdump
traceroute traceroute6 user veriexecgen wsmoused zic
(Mostly third-party applications)
 1.24 16-Jan-2009  pooka branches: 1.24.2;
Move fs-specific stuff in Makefile to fs/Makefile.inc to clarify
top-level Makefile.
 1.23 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.22 29-Aug-2008  gmcgarry Wrap compiler-specific flags with HAVE_GCC and HAVE_PCC as necessary. Add a few flags for PCC.
 1.21 16-Dec-2006  bouyer branches: 1.21.12;
Don't depend on lubutil if we're building host tools. Fix tools build on
non-NetBSD hosts.
 1.20 14-Dec-2006  he Complete the move of string_to_flags() and flags_to_string() from the
bin/ls sources to libutil:
o Bump libutil minor version number
o Fix uses to include <util.h> to pick up the function definitions
o Fix most uses of flags_to_string() to release the now-malloc()ed result
 1.19 12-May-2006  mrg don't do the -Wno-pointer-sign dance for host programs.
 1.18 11-May-2006  mrg sprinkle some -fno-strict-aliasing and -Wno-pointer-sign with GCC4.
 1.17 19-Aug-2005  dyoung Remove extraneous #PKG_DEVELOPER=1 line that snuck in with the last
commit. (Thanks Masao Uebayashi.)
 1.16 19-Aug-2005  dyoung Cosmetic: alphabetize SRCS. Start a new line on each change of
leading letter.
 1.15 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.14 18-May-2003  lukem Now that <bsd.prog.mk> DTRT if HOSTPROG is defined (i.e, it is a no-op),
there's no need to special-case .include-ing it.
 1.13 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.12 30-Nov-2002  lukem oops; libutil is (currently) needed by ../mtree/spec.c for fparseln
 1.11 30-Nov-2002  lukem - remove -lutil; nothing here needs it
- no need to reference ../../bin/dd now that strsuftoll(3) is in libc
 1.10 29-Nov-2002  lukem convert from strsuftoull() (from ../../bin/dd) to strsuftoll(3) in libc
 1.9 18-Sep-2002  lukem use NETBSDSRCDIR as appropriate
 1.8 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.7 24-Jan-2002  lukem Add '-N dbdir', to specify that user & group lookups (via pwcache(3)) are to
be done from dbdir/master.passwd and dbdir/group, using simple text file
parsing routines from ../mtree/getid.c
 1.6 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.5 05-Jan-2002  mrg build this as a host tool.
 1.4 25-Nov-2001  lukem - Use strsuftoull() from dd(1) to parse numbers, rather than home grown
version. The new version supports products, 'g' (GB) and 't' (TB)
suffices, and `b' now means `blocks' instead of `bytes'.
Functionality requested by perry.
- debug is now a u_int instead of an int.
- Ensure that various numbers have sane upper limits (e.g, 99 for %, etc)
 1.3 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.2 26-Oct-2001  lukem fix manual page building
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.21.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.24.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.29.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.29.2.1 23-May-2012  yamt sync with head.
 1.31.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.31.2.1 25-Feb-2013  tls resync with head
 1.36.26.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.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.9 07-Feb-2024  msaitoh s/strucutre/structure/ in comment.
 1.8 26-Oct-2022  andvar fix various typos in comments and makefs README file.
 1.7 12-Jan-2015  christos reflect reality about filesystems supported.
 1.6 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.5 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.4 03-Jan-2009  lukem cd9660 support has been present for a while
 1.3 20-Dec-2004  jmc Refactor the filesystem specific portions out of makefs.c/makefs.h completely.
Instead of extending fsinfo_t it now holds a void * to file system specific
data. This is then setup/cleaned up by the additional of 2 additional
callbacks. Makes adding new filesystems simpler as almost no code has
to be updated in the generic makefs code now.
 1.2 31-May-2004  lukem minor typo
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.7 10-Dec-2007  dyoung Add a todo item: read files from multiple directories.
 1.6 06-Feb-2002  lukem branches: 1.6.24;
- clean up some debugging and verbose output
- use fs_cstotal.cs_nifree rather than fs->fs_ncg * fs->fs_ipg to
determine the number of free inodes available in the file system
- don't count '.' (the root node for a level) in inode sizing, since
the parent has already been counted
- some more todo items
 1.5 24-Jan-2002  lukem -N dbdir allows reading user & group info from a different source
 1.4 23-Jan-2002  lukem more stuff
 1.3 29-Oct-2001  lukem typographical cleanups
 1.2 28-Oct-2001  lukem a possible feature...
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.6.24.1 09-Jan-2008  matt sync with HEAD
 1.60 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.59 18-Apr-2023  christos Move date setting into cd9660_populate_iso_dir_record so there is no
path that leaves it unset.

From FreeBSD https://reviews.freebsd.org/D39258
 1.58 21-Dec-2021  andvar s/filname/filename/
 1.57 10-Nov-2020  reinoud rock_ridge_move_count is only incremented and can never be negative so change
%08i to %08u.
This removes a warning when compiling with tools outside ./build.sh
 1.56 18-Oct-2019  msaitoh s/initalize/initialize/ in comment or printf message.
 1.55 15-Mar-2017  christos branches: 1.55.12;
Change duplicate 'D' option to 'm'. From Ed Maste @ FreeBSD
 1.54 24-Jan-2017  nonaka makefs(8): add cd9660 eltorito-alt-boot option for EFI boot.
 1.53 25-Nov-2016  christos branches: 1.53.2;
PR/51652: Sevan Janiyan: makefs dies due to segmentation fault
Don't dereference NULL when running out of nodes during rename.
 1.52 24-Dec-2015  christos branches: 1.52.2;
little size_t/ssize_t...
 1.51 21-Dec-2015  christos Fix some more MKREPRO issues in cdrom creation. Now amd64 passes MKREPRO.
 1.50 25-Nov-2015  christos Provide a -T option to set timestamps to a consistent value for MKREPRO
 1.49 17-Jun-2015  christos more error normalization
 1.48 16-Jun-2015  christos improve error messages (remove \n, use __func__, etc)
 1.47 24-Oct-2013  apb Now that tools/compat/compat_defs.h defones __USE, there's no
need to treat the tools build as a special case.
 1.46 19-Oct-2013  mrg avoid using __USE() in the tools version of this.
 1.45 19-Oct-2013  christos fix unused variable warnings.
 1.44 30-Jul-2013  reinoud `makefs -t cd9660' fix from FreeBSD:
Submitted by: Thomas Schmitt via marius@freebsd.org
Obtained from: FreeBSD r253707

- Correctly set the Expiration Time in the Primary Volume Descriptor;
according to ISO 9660 8.4.26.1 unspecified date and time are denoted by the
digit 0 in RBP 1 to 16 but the number 0 in RBP 17.

- Rock Ridge TF entries should use a length of 5, because after the 4 bytes of
generic SUSP header there is one byte of flags. See typedef of ISO_RRIP_TF
in iso9660_rrip.h.
 1.43 31-Jan-2013  christos macroize to make it more type-safe.
 1.42 31-Jan-2013  christos the allow options are 8 bits wide.
 1.41 29-Jan-2013  christos make everything use the generic options parser.
 1.40 29-Jan-2013  christos handle some of the options by the generic parser.
 1.39 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.38 24-Jan-2013  christos - Fix single letter option parsing.
- Instead of returning 1 << index and 0 on error,
return just index and -1 on error for the set_option*() routines.
 1.37 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.36 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.35 28-Jan-2012  christos branches: 1.35.6;
Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.34 23-Aug-2011  christos branches: 1.34.2;
more fixes from martin
 1.33 23-Aug-2011  christos remove stray brace, minor knf
 1.32 23-Aug-2011  christos PR/45285: Martin Matuska: makefs does not properly convert ISO level 1 and 2
filenames (buffer overflow)

makefs does not properly verify the maximum filename length in the
special "." case for both ISO level 1 and ISO level 2 filename
conversion. This creates broken images or causes a buffer overflow
(ISO level 2).

ISO level 1:
If a filename contains only dots or up to 8 characters followed by
dots the 8+3 limit check doesn't work.

ISO level 2:
If a filename contains a dot in the first 30 characters and a dot
on the 30th character, the length limit check doesn't work and the
buffer is overflowed.

$ mkdir level1
$ touch level1/12345............
$ makefs -t cd9660 -o isolevel=1 test.iso level1

$ mkdir level2
$ touch level2/1234567890.2345678901234567.....34567890123456789012345
$ makefs -t cd9660 -o isolevel=2 test.iso level2
 1.31 06-Aug-2011  christos PR/45217: Martin Matuska: Use proper lengths to space pad fields and don't
overwrite them according to the spec.
 1.30 29-May-2011  tsutsui Apply fixes for PR bin/44114 (makefs(8) -t cd9660 -o rockridge creates
corrupted cd9660fs):
- makefs/cd9660.c:
- cd9660_rrip_move_directory() should also update lenght[0] and
name_len[0] in dir->isoDirRecord
- makefs/cd9660/iso9660_rrip.c:
- cd9660_rrip_finalize_node() should check rr_real_parent in node->parent,
not in node itself in RRIP_PL case
- cd9660_rrip_initialize_node() should update only node passed as arg
so handle RRIP_PL in DOTDOT case

Fixes malformed dotdot entries in deep (more than 8 level) directories
moved into .rr_moved dir.

Should be pulled up to netbsd-5.
(no official ISO has such deep dirs, but cobalt restorecd is affected)
 1.29 22-May-2011  christos From Nathan Whitehorn (nwhitehorn at freebsd dot org):
Add code to generate bootable ISOs on Powermac and CHRP systems.
Synthesize some partition maps (APM and MBR, respectively) pointing
to (a) the whole disk, and (b) relevant El Torito boot images that
have been added by other code. These partition maps are a little
bit funny looking, but they seem to work. FreeBSD has been using
this successfully in their release generation on powerpc, as well
as generating all non-SPARC install media. SPARC support could
probably be added as an extension of this patch.
 1.28 19-Nov-2010  tsutsui cd9960 -> cd9660
 1.27 27-Oct-2010  christos Handle > 2GB images. Thanks to Greg Troxel for testing!
 1.26 16-Jan-2009  pooka remove fsopts asserts - the parameter is unused, so we don't care here
 1.25 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.24 08-Jan-2009  bjh21 If the user specifies a cd9660-specific option that needs an integer value
without supplying a value, complain at them instead of segfaulting.
Or, to put it another way, check that the value is non-NULL before calling
set_option().
 1.23 21-Nov-2008  ad Make the allow-multidot option useful.
 1.22 30-Oct-2008  ahoka branches: 1.22.2;
Import changes from the MirBSD Project:

Initialise memory before writing to only part of it,
making sure that the string is NUL-terminated

Allocate the maximum allowed length (including the
terminating NUL byte) for the temporary name string, make sure
the final output is NUL terminated, and copy back the NUL when
overwriting the previously created name (since maxlen is always
at least 1 less than ISO_FILENAME_MAXLENGTH_WITH_PADDING, this
is no problem)

Patches from Thorsten Glaser through freenode.net.
 1.21 27-Jul-2008  reinoud Fix typo in cd9660 functionname cd9660_setup_boot_volume_descritpor ->
cd9660_setup_boot_volume_descriptor.

Interestingly the same typo was used in 3 files!
 1.20 10-May-2008  skrll Add an option to load a generic boot image into the first 32K of the
cd9660 image.
 1.19 07-Apr-2007  christos branches: 1.19.10; 1.19.12;
Fix deep directory move rock-ridge extension. Code was there, but it had
bit-rotted.
 1.18 16-Jan-2007  hubertf * Don't include headers twice
* Remove a few trailing whitespaces
* Rearrange and join to one #if for some headers

Patch contributed by Slava Semushin <slava.semushin@gmail.com>
in private mail.
 1.17 18-Dec-2006  christos from Anon Ymous: compile with -Wextra
 1.16 22-Oct-2006  christos branches: 1.16.2; 1.16.4;
use c99 initializers
 1.15 10-Oct-2006  dbj implement -x by pruning fsnodes tree before building filesystem rather
than by skipping nodes while building filesystem
 1.14 08-Oct-2006  dbj make -t cd9660 obey -x option similarly to ffs
 1.13 01-Jun-2006  hubertf Fix fix for Coverity CID 2751:

Move an error check to the right place, and instead of blindly insisting on
an argument for all of "no-emul-boot", "no-boot", "hard-disk-boot" and
"boot-load-segment", only require it for the last one, which is the only
one that requires/uses it.

OK'd by Christos
 1.12 25-May-2006  christos Coverity CID 2751: Avoid NULL deref.
 1.11 30-Nov-2005  dyoung Fix a bug in cd9660_sort_nodes, which tried to insert `next' before
`node' on a tail-queue, when `node' wasn't on the tail-queue.
Sometimes this led to a segfault. Insert before `cn', since that
is the intention. Closes PR 32194. Thanks, Jeff Rizzo, for reporting
this bug.
 1.10 31-Oct-2005  dyoung Change cd9660's default verbosity level to 0, quieting it down
considerably.
 1.9 31-Oct-2005  dyoung Remove the cd9660_inode hashtable for hard-links support, and re-use
the fsinode for the same purpose, per Luke Mewburn's suggestion on
source-changes@.
 1.8 30-Oct-2005  dyoung Add hard-link support: keep a hashtable that maps inodes for
regular files on the source filesystem to the offset of the first
data block on the target filesystem. Don't allocate blocks for a
file a second time (i.e., if it is already present in the hashtable).
Avoid writing the blocks of a file twice (use the FS_WRITTEN flag
in fsinode->flags for this purpose).
 1.7 30-Oct-2005  dyoung Bug fix: record the actual number number of 512-byte "virtual"
sectors in the Sector Count field of the Initial/Default Entry in
the "El Torito" Boot Catalog, instead of blithely writing 1 (!!)
into the Sector Count field. Ditto the Section Entries.

Remove last remnants of cd9660's unsupported boot-load-size option.

Really use cd9660's boot-load-segment argument.

Change the boot images list from a LIST to a TAILQ.

Re-implement CD9660_BLOCKS() with howmany().

Introduce ELTORITO_DPRINTF and some debug messages.

Zero memory malloc'd in the El Torito code.

Revise some debugging outputs.

Insert a new boot-image on the boot-images list after the last
boot-image for the same architecture. It makes a (trivial) functional
difference.

Miscellaneous cosmetic changes. Remove useless variable-assignment.
 1.6 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.5 25-Oct-2005  dyoung Overhaul makefs -t cd9660.

Functional: Do not add a missing period or a version number to
directories, since that doesn't fit the standard (thanks
Daniel Watt).

Add RRIP PX records (POSIX meta-information) to '.'
and '..' entries. Quiets kernel complaint, when we
mount a cd9660 filesystem, that there is a missing PX
entry.

Cosmetic: Reduce height of staircases. Remove an unused member
from struct _cd9660node. Extract a subroutine. KNF.

Use a TAILQ macros for lists of both SUSP/RRIP attributes
and directory entries.

XXX
XXX The new RRIP PX entries are not quite right.
XXX
 1.4 11-Sep-2005  dyoung Cosmetic: change to a standard idiom, *(x++) --> *x++. Flag some
places needing bounds-checking with XXX. Fix indendation.
 1.3 11-Sep-2005  dyoung By default, do not omit the trailing period from ISO9660 filenames
unless given the option '-o omit-trailing-period'. Also, fix a
logic error so that makefs obeys option '-o omit-trailing-period'
when it is given.
 1.2 15-Aug-2005  he Move local variable declaration to start of block (also start of function).
Fixes build problem for vax.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.16.4.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.16.2.1 31-Aug-2007  pavel Pull up following revision(s) (requested by christos in ticket #757):
usr.sbin/makefs/cd9660.c: revision 1.19
Fix deep directory move rock-ridge extension. Code was there, but it had
bit-rotted.
 1.19.12.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.19.12.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.19.10.1 18-May-2008  yamt sync with head.
 1.22.2.3 15-Jul-2011  riz Pull up following revision(s) (requested by tsutsui in ticket #1638):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.9
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.10
usr.sbin/makefs/cd9660.c: revision 1.30
- remove unnecessary (pasto?) line on RRIP PL handling for moved dir
- RRIP RE length should be 4, not 0
Apply fixes for PR bin/44114 (makefs(8) -t cd9660 -o rockridge creates
corrupted cd9660fs):
- makefs/cd9660.c:
- cd9660_rrip_move_directory() should also update lenght[0] and
name_len[0] in dir->isoDirRecord
- makefs/cd9660/iso9660_rrip.c:
- cd9660_rrip_finalize_node() should check rr_real_parent in node->parent,
not in node itself in RRIP_PL case
- cd9660_rrip_initialize_node() should update only node passed as arg
so handle RRIP_PL in DOTDOT case
Fixes malformed dotdot entries in deep (more than 8 level) directories
moved into .rr_moved dir.
Should be pulled up to netbsd-5.
(no official ISO has such deep dirs, but cobalt restorecd is affected)
 1.22.2.2 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.22.2.1 02-Feb-2009  snj branches: 1.22.2.1.2; 1.22.2.1.4;
Pull up following revision(s) (requested by ad in ticket #347):
usr.sbin/makefs/cd9660.c: revision 1.23
Make the allow-multidot option useful.
 1.22.2.1.4.1 21-Apr-2010  matt sync to netbsd-5
 1.22.2.1.2.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 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 17-Apr-2012  yamt sync with head
 1.35.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.35.6.1 25-Feb-2013  tls resync with head
 1.52.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.52.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.53.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.55.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.21 24-Dec-2015  christos little size_t/ssize_t...
 1.20 29-Jan-2013  christos make everything use the generic options parser.
 1.19 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.18 28-Jan-2012  christos branches: 1.18.6;
Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.17 23-Jun-2011  enami branches: 1.17.2;
Move inclusion of sys/endian.h from cd9660_eltorito.c to cd9660.h
since actual user is not cd9660_eltorito.c but iso.h and
cd9660_eltorito.h.

Actually, include order/place of sys/endian.h doesn't matter on
netbsd since it is always included by sys/types.h but it's not
true on other system. This should fix cross build breakage on
freebsd introduced by rev. 1.16 of cd9660_eltorito.c.
Problem reported and fix suggested on twitter.
 1.16 22-May-2011  christos From Nathan Whitehorn (nwhitehorn at freebsd dot org):
Add code to generate bootable ISOs on Powermac and CHRP systems.
Synthesize some partition maps (APM and MBR, respectively) pointing
to (a) the whole disk, and (b) relevant El Torito boot images that
have been added by other code. These partition maps are a little
bit funny looking, but they seem to work. FreeBSD has been using
this successfully in their release generation on powerpc, as well
as generating all non-SPARC install media. SPARC support could
probably be added as an extension of this patch.
 1.15 27-Oct-2010  christos Handle > 2GB images. Thanks to Greg Troxel for testing!
 1.14 22-Oct-2010  christos - simple fseek->fseeko conversion. probably needs more work.
- use a constant instead of sprinkling 2048 everywhere.
 1.13 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.12 27-Jul-2008  reinoud branches: 1.12.4; 1.12.6; 1.12.8;
Fix typo in cd9660 functionname cd9660_setup_boot_volume_descritpor ->
cd9660_setup_boot_volume_descriptor.

Interestingly the same typo was used in 3 files!
 1.11 10-May-2008  skrll Add an option to load a generic boot image into the first 32K of the
cd9660 image.
 1.10 01-Feb-2006  dyoung branches: 1.10.18; 1.10.20;
Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.9 31-Oct-2005  dyoung Remove the cd9660_inode hashtable for hard-links support, and re-use
the fsinode for the same purpose, per Luke Mewburn's suggestion on
source-changes@.
 1.8 30-Oct-2005  dyoung Add hard-link support: keep a hashtable that maps inodes for
regular files on the source filesystem to the offset of the first
data block on the target filesystem. Don't allocate blocks for a
file a second time (i.e., if it is already present in the hashtable).
Avoid writing the blocks of a file twice (use the FS_WRITTEN flag
in fsinode->flags for this purpose).
 1.7 30-Oct-2005  dyoung Now that I understand what order boot-images and boot-entries are
intended to be kept on the boot-images and -entries lists, keep
them in that order: images grouped and entries grouped by system,
with later images nearer the front of the list.

*Really* apply boot options to the last boot-image specified.
 1.6 30-Oct-2005  dyoung Bug fix: record the actual number number of 512-byte "virtual"
sectors in the Sector Count field of the Initial/Default Entry in
the "El Torito" Boot Catalog, instead of blithely writing 1 (!!)
into the Sector Count field. Ditto the Section Entries.

Remove last remnants of cd9660's unsupported boot-load-size option.

Really use cd9660's boot-load-segment argument.

Change the boot images list from a LIST to a TAILQ.

Re-implement CD9660_BLOCKS() with howmany().

Introduce ELTORITO_DPRINTF and some debug messages.

Zero memory malloc'd in the El Torito code.

Revise some debugging outputs.

Insert a new boot-image on the boot-images list after the last
boot-image for the same architecture. It makes a (trivial) functional
difference.

Miscellaneous cosmetic changes. Remove useless variable-assignment.
 1.5 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.4 25-Oct-2005  dyoung Overhaul makefs -t cd9660.

Functional: Do not add a missing period or a version number to
directories, since that doesn't fit the standard (thanks
Daniel Watt).

Add RRIP PX records (POSIX meta-information) to '.'
and '..' entries. Quiets kernel complaint, when we
mount a cd9660 filesystem, that there is a missing PX
entry.

Cosmetic: Reduce height of staircases. Remove an unused member
from struct _cd9660node. Extract a subroutine. KNF.

Use a TAILQ macros for lists of both SUSP/RRIP attributes
and directory entries.

XXX
XXX The new RRIP PX entries are not quite right.
XXX
 1.3 13-Aug-2005  fvdl Fix some wrapping lines.
 1.2 13-Aug-2005  fvdl Add nbtool_config.h include, fixing the tool compile on some platforms.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.10.20.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.20.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.10.18.1 18-May-2008  yamt sync with head.
 1.12.8.1 21-Apr-2010  matt sync to netbsd-5
 1.12.6.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.12.4.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.17.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.17.2.1 17-Apr-2012  yamt sync with head
 1.18.6.1 25-Feb-2013  tls resync with head
 1.9 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.8 29-Jan-2013  christos make everything use the generic options parser.
 1.7 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.6 24-Jan-2013  christos - Fix single letter option parsing.
- Instead of returning 1 << index and 0 on error,
return just index and -1 on error for the set_option*() routines.
 1.5 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.4 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.3 19-Apr-2012  christos branches: 1.3.2; 1.3.4;
WARNS=5
 1.2 19-Apr-2012  christos - fix compilation isses
- add some error checking
- avoid alloca
- add missing frees
 1.1 19-Apr-2012  ttoth added chfs support for makefs
 1.3.4.1 25-Feb-2013  tls resync with head
 1.3.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.3.2.2 23-May-2012  yamt sync with head.
 1.3.2.1 19-Apr-2012  yamt file chfs.c was added on branch yamt-pagecache on 2012-05-23 10:08:28 +0000
 1.2 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.1 19-Apr-2012  ttoth branches: 1.1.2; 1.1.4;
added chfs support for makefs
 1.1.4.1 25-Feb-2013  tls resync with head
 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-May-2012  yamt sync with head.
 1.1.2.1 19-Apr-2012  yamt file chfs_makefs.h was added on branch yamt-pagecache on 2012-05-23 10:08:28 +0000
 1.77 30-Apr-2025  christos From FreeBSD D50078 by jrtc27:

Linux's struct stat does not have an st_flags member, but we still want
to be able to create FreeBSD disk images with non-zero st_flags. Add a
replacement member to struct fsinode to store it on Linux.
 1.76 17-Jun-2024  riastradh branches: 1.76.2;
makefs(8): Fix format string for newly 64-bit target inode numbers.
 1.75 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.74 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.73 17-Nov-2022  chs branches: 1.73.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.72 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.71 06-Apr-2022  wiz makefs: fix some typos
 1.70 16-Dec-2017  christos PR/52828: Mark Johnston: makefs UFS2 lazy inode initialization is buggy

makefs(8) emulates UFS2 in performing lazy initialization of inode
blocks when allocating and writing inodes. However, it only ever
initializes one inode block at a time, which may be insufficient.
If so, a later initialization may clobber an inode, resulting in
an inconsistent filesystem.

I committed a minimal fix for the problem to FreeBSD:
https://svnweb.freebsd.org/changeset/base/326912
 1.69 08-Feb-2017  christos branches: 1.69.4;
stampst.st_ion consistent treatment (non-zero vs zero instead of testing == 1)
 1.68 08-Feb-2017  christos no, this is wrong.
 1.67 08-Feb-2017  christos zero out the superblock so that it does not contain random stuff in the
spare fields.
 1.66 21-Dec-2015  christos branches: 1.66.2; 1.66.4;
more deterministic ffs for reproducible builds.
 1.65 20-Dec-2015  christos Add timestamp support to the ffs image creation; needed for in kernel memory
images MKREPRO.
 1.64 12-Jan-2015  christos PR/49559: Christian Brueffer: Fix typo maxbpf instead of maxbpg.
 1.63 23-Jun-2013  dholland branches: 1.63.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.62 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.61 09-Jun-2013  dholland Stick UFS_ in front of these symbols:
DIRBLKSIZ
DIRECTSIZ
DIRSIZ
OLDDIRFMT
NEWDIRFMT

Part of PR 47909.
 1.60 03-Feb-2013  christos - more changes to make -O work
- fix err* calls.
 1.59 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.58 30-Jan-2013  christos gc global sectorsize.
 1.57 29-Jan-2013  christos make everything use the generic options parser.
 1.56 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.55 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.54 26-Jan-2013  christos make the buffer functions look exactly like the kernel ones and add other
cruft to make the kernel files compile.
 1.53 24-Jan-2013  christos - Fix single letter option parsing.
- Instead of returning 1 << index and 0 on error,
return just index and -1 on error for the set_option*() routines.
 1.52 23-Jan-2013  christos return the bit of the option set, so that others can act on it.
 1.51 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.50 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 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 22-Jun-2012  sjg branches: 1.48.2;
Add -Z to enable sparse files - for ffs at least.
Based on a patch from shesha at juniper.
 1.47 19-Apr-2012  christos WARNS=5
 1.46 28-Jan-2012  christos Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.45 09-Oct-2011  christos branches: 1.45.2;
add support for setting the ufs label. (Nathan Whitehorn)
 1.44 28-Apr-2009  joerg Create images with 0666 - umask, not 0777 - umask (e.g. without x bits).
 1.43 16-Apr-2009  dyoung Distinguish read(2) failure due to a short read from other causes, and
suggest in the error message a possible cause: the size= attribute in
the metalog (if one is given) may be different from the source file's
actual size.
 1.42 18-Dec-2006  christos branches: 1.42.20;
from Anon Ymous: compile with -Wextra
 1.41 22-Oct-2006  christos use c99 initializers
 1.40 10-Oct-2006  dbj implement -x by pruning fsnodes tree before building filesystem rather
than by skipping nodes while building filesystem
 1.39 22-Apr-2006  christos Coverity CID 174: Add extra NULL test to appease coverity.
 1.38 18-Mar-2006  rtr free buf on error path
coverity 190 / run 5
 1.37 23-Oct-2005  thorpej Use the real field name (d_fileno instead of d_ino).
 1.36 20-Aug-2005  kent fix compilatio problems on LP64
 1.35 13-Aug-2005  fvdl Fix a sign warning for WARNS=3.
 1.34 02-Jun-2005  lukem appease gcc -Wuninitialized
 1.33 20-Dec-2004  jmc Refactor the filesystem specific portions out of makefs.c/makefs.h completely.
Instead of extending fsinfo_t it now holds a void * to file system specific
data. This is then setup/cleaned up by the additional of 2 additional
callbacks. Makes adding new filesystems simpler as almost no code has
to be updated in the generic makefs code now.
 1.32 12-Oct-2004  jmc Check for fstatvfs and provide/use it only if the host system has it.
Fixes PR#27221
 1.31 24-Jul-2004  dbj include <sys/statvfs.h> if HAVE_STRUCT_STATVFS_F_IOSIZE
addresses part of PR toolchain/26415
 1.30 24-Jun-2004  lukem Define FFS_MAXBSIZE to 65536 and use instead of MAXBSIZE.
Deprecate unused MAXINOPB.
Should fix PR [toolchain/25603].
 1.29 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.28 26-Apr-2004  dsl Allow for ROOTINO when deciding whether their are enough inodes in the
created filesystem. Otherwise this fails when asked for 63 inodes for
i386 ramdisk-big.
This code really needs to use the current version of newfs/mkfs.c where
the actual inode count can be passed in (instead of the density).
Fixes a build problem when I add /mountroot to mtree.common for sysinst.
 1.27 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.26 02-Apr-2004  lukem After populating the file system, update superblock->fs_old_cstotal from
superblock->fs_cstotal. Fixes inconsistencies found by FreeBSD's fsck.
Problem noted by Luigi Rizzo <luigi@FreeBSD.org> via Colin Percival.
 1.25 26-Oct-2003  mycroft branches: 1.25.2;
Mention that we should be adding space for bitmaps.
 1.24 26-Oct-2003  mycroft Remove a strange multiplication which appears to be incorrect.
 1.23 19-Sep-2003  itojun realloc pedant
 1.22 07-Sep-2003  fvdl Revert arc4random usage. makefs is only used for install images,
filehandle randomization is not an issue there, and using arc4random
broke building makefs as a host tool.
 1.21 06-Sep-2003  itojun use arc4random
 1.20 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.19 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.18 30-Mar-2003  lukem Tweak Jason's -x support to pass its state around as part of fsinf_t,
just like all the other "global" options.
Update the usage for -x.
Crank date on man page.

(Thanks to Jason for adding -x; I've been meaning to add that
functionality for a while :-)
 1.17 29-Mar-2003  thorpej Add a -x option which causes makefs(8) to exclude any file system node
not explicitly listed in the specfile.
 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 30-May-2002  thorpej d_namlen is a uint8_t, and thus will always be < MAXMANLEN + 1 (256),
so there is no need to assert it.
 1.14 15-Feb-2002  lukem branches: 1.14.2;
- Clear fs_fmod in superblock before final write. Noted by Erik Anggard.
- Explicitly close the image file descriptor at the end of ffs_makefs().
 1.13 06-Feb-2002  lukem - clean up some debugging and verbose output
- use fs_cstotal.cs_nifree rather than fs->fs_ncg * fs->fs_ipg to
determine the number of free inodes available in the file system
- don't count '.' (the root node for a level) in inode sizing, since
the parent has already been counted
- some more todo items
 1.12 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.11 26-Jan-2002  lukem be a little bit more verbose
 1.10 26-Jan-2002  lukem - crank default cpg from 16 to 65536, and let the auto-sizing code in
mkfs() do its job
- pass cpgflg=1 to mkfs() if the user provided cpg, =0 otherwise
- improve error reporting in ffs_write_file()
- only add superblock & block map slop for one cylinder group.
trying to calculate the number of required cylinder groups caused
too many problems when tweaking parameters for small file systems.
rely upon slop from minfree, and upon ffs_write_file() to complain
if the user is too aggressive about tweaking the parameters
 1.9 18-Jan-2002  lukem use -1 instead of 0 as the value to indicate if a numeric parameter
hasn't been set and thus needs a default override.
allows minfree and rotdelay to take a value of 0.
 1.8 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.7 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.6 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.5 05-Dec-2001  lukem rework `fsnode' into two components; `fsnode' contains the name and tree
information and a link to the appropriate fsinode, and `fsinode' contains
the inode information and a reference count. multiple fsnodes may point
to the same fsinode. this replaces the 'dup' pointer in the previous code.
 1.4 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.3 02-Nov-2001  lukem tweak copyright
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.14.2.1 30-May-2002  tv Pull up revision 1.15 (requested by thorpej in ticket #87):
d_namlen is a uint8_t, and thus will always be < MAXMANLEN + 1 (256),
so there is no need to assert it.
 1.25.2.3 25-Jun-2004  jmc Pullup rev 1.30 (requested by lukem in ticket #549)

Define FFS_MAXBSIZE to 65536 and use instead of MAXBSIZE.
Deprecate unused MAXINOPB. PR#25603 fixed.
 1.25.2.2 22-Jun-2004  tron Pull up revision 1.29 (requested by jmc in ticket #527):
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.25.2.1 28-Apr-2004  jmc Pullup rev 1.28 (requested by dsl in ticket #200)

Allow for ROOTINO when deciding whether their are enough inodes in the
created filesystem. Otherwise this fails when asked for 63 inodes for
i386 ramdisk-big.
 1.42.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.45.2.5 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.4 23-Jan-2013  yamt sync with head
 1.45.2.3 30-Oct-2012  yamt sync with head
 1.45.2.2 23-May-2012  yamt sync with head.
 1.45.2.1 17-Apr-2012  yamt sync with head
 1.48.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.48.2.2 23-Jun-2013  tls resync from head
 1.48.2.1 25-Feb-2013  tls resync with head
 1.63.6.2 06-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1615):

usr.sbin/makefs/ffs.c: revision 1.70

PR/52828: Mark Johnston: makefs UFS2 lazy inode initialization is buggy
makefs(8) emulates UFS2 in performing lazy initialization of inode
blocks when allocating and writing inodes. However, it only ever
initializes one inode block at a time, which may be insufficient.

If so, a later initialization may clobber an inode, resulting in
an inconsistent filesystem.

I committed a minimal fix for the problem to FreeBSD:
https://svnweb.freebsd.org/changeset/base/326912
 1.63.6.1 14-Apr-2015  snj branches: 1.63.6.1.2; 1.63.6.1.6;
Pull up following revision(s) (requested by christos in ticket #684):
usr.sbin/makefs/ffs.c: revision 1.64
PR/49559: Christian Brueffer: Fix typo maxbpf instead of maxbpg.
 1.63.6.1.6.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1615):

usr.sbin/makefs/ffs.c: revision 1.70

PR/52828: Mark Johnston: makefs UFS2 lazy inode initialization is buggy
makefs(8) emulates UFS2 in performing lazy initialization of inode
blocks when allocating and writing inodes. However, it only ever
initializes one inode block at a time, which may be insufficient.

If so, a later initialization may clobber an inode, resulting in
an inconsistent filesystem.

I committed a minimal fix for the problem to FreeBSD:
https://svnweb.freebsd.org/changeset/base/326912
 1.63.6.1.2.1 14-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #1615):

usr.sbin/makefs/ffs.c: revision 1.70

PR/52828: Mark Johnston: makefs UFS2 lazy inode initialization is buggy
makefs(8) emulates UFS2 in performing lazy initialization of inode
blocks when allocating and writing inodes. However, it only ever
initializes one inode block at a time, which may be insufficient.

If so, a later initialization may clobber an inode, resulting in
an inconsistent filesystem.

I committed a minimal fix for the problem to FreeBSD:
https://svnweb.freebsd.org/changeset/base/326912
 1.66.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.66.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.69.4.1 09-Jun-2018  martin Pull up following revision(s) (requested by maya in ticket #858):

usr.sbin/makefs/ffs.c: revision 1.70

PR/52828: Mark Johnston: makefs UFS2 lazy inode initialization is buggy
makefs(8) emulates UFS2 in performing lazy initialization of inode
blocks when allocating and writing inodes. However, it only ever
initializes one inode block at a time, which may be insufficient.

If so, a later initialization may clobber an inode, resulting in
an inconsistent filesystem.

I committed a minimal fix for the problem to FreeBSD:
https://svnweb.freebsd.org/changeset/base/326912
 1.73.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.76.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 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.2 09-Oct-2011  christos add support for setting the ufs label. (Nathan Whitehorn)
 1.1 20-Dec-2004  jmc Refactor the filesystem specific portions out of makefs.c/makefs.h completely.
Instead of extending fsinfo_t it now holds a void * to file system specific
data. This is then setup/cleaned up by the additional of 2 additional
callbacks. Makes adding new filesystems simpler as almost no code has
to be updated in the generic makefs code now.
 1.73 27-Oct-2024  christos Document debugging options and allow specifying them by name.
 1.72 08-May-2024  christos branches: 1.72.2;
Add an option to warn and error out for mtree missing entries.
 1.71 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.70 06-Apr-2022  wiz new sentence, new line
 1.69 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.68 12-Nov-2021  reinoud Explain cd9660 and udf exceptions on the rule that the default sectorsize is
512.
 1.67 03-Apr-2021  simonb Add a -L option to follow all symbolic links. Useful if you have symlinks
in a makefs directory tree but want to refer to the actual file.
 1.66 15-Nov-2020  jmcneill Add "efi" as a supported boot image type and derive the platform ID for
the validation entry from the default boot image instead of hard-coding
X86.
 1.65 04-Apr-2020  reinoud Indent the makefs(8) options for UDF like the other filesystems described.
 1.64 06-Nov-2019  christos Correct documentation of -m and -M.
From Ed Maste @ FreeBSD
 1.63 14-Apr-2017  wiz branches: 1.63.12;
Whitespace fixes.
 1.62 13-Apr-2017  christos Explain the 's' image size better.
 1.61 12-Feb-2017  wiz file system police.
 1.60 11-Feb-2017  christos untorture language.
 1.59 11-Feb-2017  christos mention timezone change for -T timestamp
 1.58 24-Jan-2017  nonaka makefs(8): add cd9660 eltorito-alt-boot option for EFI boot.
 1.57 11-Jan-2017  wiz branches: 1.57.2;
Document msdos-specific options directly.

From jmc@OpenBSD.

Bump date.
 1.56 11-Jan-2017  wiz Some changes and sorting based on diff sent from jmc@OpenBSD.
 1.55 25-Nov-2015  wiz branches: 1.55.2;
"file system" as two words.
 1.54 25-Nov-2015  christos Provide a -T option to set timestamps to a consistent value for MKREPRO
 1.53 06-Aug-2013  wiz New sentence, new line.
Use one list instead of two consecutive ones.
Add .El to end list.
 1.52 06-Aug-2013  reinoud Add minimum UDF version specification to makefs(8) -t udf.
 1.51 06-Aug-2013  reinoud Allow for the logical volume label to be specified as well as the physical
volume label. Also allow the volumeset name to be specified if desired. The
syntax follows the newfs_udf(8) syntax.
 1.50 06-Aug-2013  wiz New sentence, new line.
 1.49 06-Aug-2013  reinoud Update makefs(8) man page to reflect the selection of default sector and disc
sizes based on the disc type.
 1.48 05-Aug-2013  reinoud Note that i added the UDF support to makefs(8) and bump data
 1.47 05-Aug-2013  wiz Sort. Improve table formatting.
 1.46 05-Aug-2013  reinoud Implement `makefs -t udf'.

Formatting options may be enhanced to make it more in line with newfs_udf on
say labeling.
 1.45 03-Feb-2013  christos add a replace flag so we can overlay exiting files when we merge directories.
 1.44 02-Feb-2013  christos add and document offset.
 1.43 29-Jan-2013  christos mention me
 1.42 28-Jan-2013  christos now that msdos works, document it.
 1.41 22-Jun-2012  sjg branches: 1.41.2;
Add -Z to enable sparse files - for ffs at least.
Based on a patch from shesha at juniper.
 1.40 19-Apr-2012  wiz New sentence, new line.
 1.39 19-Apr-2012  ttoth added chfs support for makefs
 1.38 28-Jan-2012  christos Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.37 09-Oct-2011  christos branches: 1.37.2;
add support for setting the ufs label. (Nathan Whitehorn)
 1.36 15-Aug-2011  wiz Re-order `usage' alphabetically;
rename option arguments in the manpage's `SYNOPSIS' section to
match those from `usage' (not the other way around; the `usage'-line
(and other parts of makefs.c) contain the correct names);
minor punctuation improvements.

From Snader_LB.
 1.35 22-Jul-2011  wiz Bump date for previous, fix typo.
 1.34 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.33 22-May-2011  christos From Nathan Whitehorn (nwhitehorn at freebsd dot org):
Add code to generate bootable ISOs on Powermac and CHRP systems.
Synthesize some partition maps (APM and MBR, respectively) pointing
to (a) the whole disk, and (b) relevant El Torito boot images that
have been added by other code. These partition maps are a little
bit funny looking, but they seem to work. FreeBSD has been using
this successfully in their release generation on powerpc, as well
as generating all non-SPARC install media. SPARC support could
probably be added as an extension of this patch.
 1.32 20-Jan-2009  bjh21 Bump date for last change.
 1.31 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.30 10-May-2008  skrll Add an option to load a generic boot image into the first 32K of the
cd9660 image.
 1.29 02-Dec-2007  wiz branches: 1.29.6; 1.29.8;
Fix Xref.
 1.28 13-Apr-2007  lukem branches: 1.28.4;
Use IEC 60027-2 prefixes for 2^n based prefixes.
 1.27 01-Feb-2007  uebayasi Use periods in tables consistently.
 1.26 01-Feb-2007  uebayasi New sentence new line.
 1.25 12-Mar-2006  rpaulo bump date
 1.24 11-Mar-2006  jschauma fix typo: explcitly -> explicitly
 1.23 04-Feb-2006  wiz Sort SEE ALSO.
 1.22 26-Jan-2006  martin Add reference to installboot(8), as suggested by Patrick Welche.
 1.21 31-Oct-2005  wiz Bump date for previous.
 1.20 30-Oct-2005  dyoung boot-load-size, the number of load sectors for the boot image, is
not yet, and will not be, supported.
 1.19 28-Oct-2005  dyoung The system type mac68k is also allowed.

XXX Is that correct?
 1.18 28-Oct-2005  dyoung Synchronize documentation with utility.
 1.17 09-Sep-2005  wiz Remove unnecessary keeps (Bk/Ek). Sort options. Various minor fixes.
Bump date.
 1.16 13-Aug-2005  fvdl Comment out some currently unimplemented options, and add a few descriptions
for others (from Daniel Watt).
 1.15 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.14 11-Jul-2005  lukem Fix a typo in the description of -f. Noted by Jukka Salmi in PR 30713.
Add some missing punctuation.
 1.13 13-Feb-2004  wiz Spell the plural of suffix "suffixes", not "suffices".
Inspired by PR 24400 by Todd Vierling.
 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 30-Mar-2003  lukem Tweak Jason's -x support to pass its state around as part of fsinf_t,
just like all the other "global" options.
Update the usage for -x.
Crank date on man page.

(Thanks to Jason for adding -x; I've been meaning to add that
functionality for a while :-)
 1.10 29-Mar-2003  thorpej Add a -x option which causes makefs(8) to exclude any file system node
not explicitly listed in the specfile.
 1.9 10-Mar-2003  lukem support 1234 and 4321 as valid byte-order arguments for -B
 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 14-Feb-2003  grant The correct capitalisation of 'NetBSD.org' is (you
guessed it) 'NetBSD.org'.

some mdoc fixes.
 1.6 08-Feb-2002  lukem If an entry is in the specfile but not in the underlying file system, and it's
marked "optional", don't add it. (e.g, don't create a zero-length file).
 1.5 24-Jan-2002  lukem Add '-N dbdir', to specify that user & group lookups (via pwcache(3)) are to
be done from dbdir/master.passwd and dbdir/group, using simple text file
parsing routines from ../mtree/getid.c
 1.4 25-Nov-2001  wiz Drop an unnecessary .Pp, fix a typo, use standard headers, sort sections,
mark up author name.
 1.3 25-Nov-2001  lukem - Use strsuftoull() from dd(1) to parse numbers, rather than home grown
version. The new version supports products, 'g' (GB) and 't' (TB)
suffices, and `b' now means `blocks' instead of `bytes'.
Functionality requested by perry.
- debug is now a u_int instead of an int.
- Ensure that various numbers have sane upper limits (e.g, 99 for %, etc)
 1.2 02-Nov-2001  lukem tweak copyright
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.28.4.1 09-Jan-2008  matt sync with HEAD
 1.29.8.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.29.6.1 18-May-2008  yamt sync with head.
 1.37.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.37.2.3 30-Oct-2012  yamt sync with head
 1.37.2.2 23-May-2012  yamt sync with head.
 1.37.2.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.55.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.55.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.57.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.63.12.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.63.12.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.72.2.1 02-Aug-2025  perseant Sync with HEAD
 1.59 27-Oct-2024  christos Document debugging options and allow specifying them by name.
 1.58 08-May-2024  christos branches: 1.58.2;
Add an option to warn and error out for mtree missing entries.
 1.57 18-Feb-2024  christos Add an options pretty-printer, pass some lint.
 1.56 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.55 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.54 03-Apr-2021  simonb Add a -L option to follow all symbolic links. Useful if you have symlinks
in a makefs directory tree but want to refer to the actual file.
 1.53 27-Nov-2015  joerg Don't pass garbage to parsedate, but do use the return value.
 1.52 25-Nov-2015  wiz Sort options in usage to match man page order.
 1.51 25-Nov-2015  christos Provide a -T option to set timestamps to a consistent value for MKREPRO
 1.50 05-Aug-2013  reinoud Implement `makefs -t udf'.

Formatting options may be enhanced to make it more in line with newfs_udf on
say labeling.
 1.49 03-Feb-2013  christos add a replace flag so we can overlay exiting files when we merge directories.
 1.48 02-Feb-2013  christos add and document offset.
 1.47 01-Feb-2013  christos remove bogus err.
 1.46 01-Feb-2013  christos while it is studly to play with token pasting, passing directly the type
is a lot more readable.
 1.45 30-Jan-2013  christos use "val" not "var"
 1.44 29-Jan-2013  christos make everything use the generic options parser.
 1.43 29-Jan-2013  christos Allow options without values meaning the empty string for string options
and = 1 to numerics.
 1.42 29-Jan-2013  christos deal with options that don't have a single letter argument.
 1.41 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.40 27-Jan-2013  christos fix single letter parsing.
 1.39 24-Jan-2013  christos - Fix single letter option parsing.
- Instead of returning 1 << index and 0 on error,
return just index and -1 on error for the set_option*() routines.
 1.38 23-Jan-2013  christos return the bit of the option set, so that others can act on it.
 1.37 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.36 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.35 22-Jun-2012  sjg branches: 1.35.2;
Add -Z to enable sparse files - for ffs at least.
Based on a patch from shesha at juniper.
 1.34 29-Apr-2012  joerg usage is dead. name_len should be read as unsigned byte.
 1.33 19-Apr-2012  christos - fix compilation isses
- add some error checking
- avoid alloca
- add missing frees
 1.32 19-Apr-2012  ttoth added chfs support for makefs
 1.31 28-Jan-2012  christos Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.30 15-Aug-2011  wiz branches: 1.30.2;
Re-order `usage' alphabetically;
rename option arguments in the manpage's `SYNOPSIS' section to
match those from `usage' (not the other way around; the `usage'-line
(and other parts of makefs.c) contain the correct names);
minor punctuation improvements.

From Snader_LB.
 1.29 18-Jul-2011  tron Re-enable v7fs support in the tools version of "makefs" after the
issues have been fixed by Alan Barrett. Tested under Mac OS X.
 1.28 18-Jul-2011  tron Don't include v7fs support into tool version of "makefs" because it
breaks the build.
 1.27 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.26 22-Oct-2006  christos use c99 initializers
 1.25 10-Oct-2006  dbj implement -x by pruning fsnodes tree before building filesystem rather
than by skipping nodes while building filesystem
 1.24 10-Oct-2006  dbj add implementation of free_fsnodes() which unlinks a node
from the hierarchy and frees it and any of its children
use it to free memory before a normal exit, which helps diagnostics
 1.23 10-Oct-2006  dbj use strtoll instead of strsuftoll to parse -d so it can be specified
in hex with a 0x prefix
 1.22 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.21 20-Dec-2004  jmc Refactor the filesystem specific portions out of makefs.c/makefs.h completely.
Instead of extending fsinfo_t it now holds a void * to file system specific
data. This is then setup/cleaned up by the additional of 2 additional
callbacks. Makes adding new filesystems simpler as almost no code has
to be updated in the generic makefs code now.
 1.20 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.19 05-Jan-2004  jmmv branches: 1.19.2;
Homogenize usage messages: make the 'usage' word all lowercase, as this seems
to be the most common practice in our tree.
 1.18 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.17 30-Mar-2003  lukem Tweak Jason's -x support to pass its state around as part of fsinf_t,
just like all the other "global" options.
Update the usage for -x.
Crank date on man page.

(Thanks to Jason for adding -x; I've been meaning to add that
functionality for a while :-)
 1.16 29-Mar-2003  thorpej Add a -x option which causes makefs(8) to exclude any file system node
not explicitly listed in the specfile.
 1.15 10-Mar-2003  lukem support 1234 and 4321 as valid byte-order arguments for -B
 1.14 29-Nov-2002  lukem convert from strsuftoull() (from ../../bin/dd) to strsuftoll(3) in libc
 1.13 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.12 26-Jan-2002  lukem - crank default cpg from 16 to 65536, and let the auto-sizing code in
mkfs() do its job
- pass cpgflg=1 to mkfs() if the user provided cpg, =0 otherwise
- improve error reporting in ffs_write_file()
- only add superblock & block map slop for one cylinder group.
trying to calculate the number of required cylinder groups caused
too many problems when tweaking parameters for small file systems.
rely upon slop from minfree, and upon ffs_write_file() to complain
if the user is too aggressive about tweaking the parameters
 1.11 24-Jan-2002  lukem Add '-N dbdir', to specify that user & group lookups (via pwcache(3)) are to
be done from dbdir/master.passwd and dbdir/group, using simple text file
parsing routines from ../mtree/getid.c
 1.10 22-Jan-2002  is add config.h when compiled as host tool.
 1.9 18-Jan-2002  lukem use -1 instead of 0 as the value to indicate if a numeric parameter
hasn't been set and thus needs a default override.
allows minfree and rotdelay to take a value of 0.
 1.8 10-Jan-2002  lukem setprogname(argv[0])
 1.7 05-Dec-2001  lukem rework `fsnode' into two components; `fsnode' contains the name and tree
information and a link to the appropriate fsinode, and `fsinode' contains
the inode information and a reference count. multiple fsnodes may point
to the same fsinode. this replaces the 'dup' pointer in the previous code.
 1.6 25-Nov-2001  lukem - Use strsuftoull() from dd(1) to parse numbers, rather than home grown
version. The new version supports products, 'g' (GB) and 't' (TB)
suffices, and `b' now means `blocks' instead of `bytes'.
Functionality requested by perry.
- debug is now a u_int instead of an int.
- Ensure that various numbers have sane upper limits (e.g, 99 for %, etc)
 1.5 08-Nov-2001  simonb Include <limits.h> to get LLONG_{MIN,MAX}.
 1.4 02-Nov-2001  lukem tweak copyright
 1.3 29-Oct-2001  lukem cast time_t values to long if printing as %ld to appease the sparc64 port
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.19.2.1 22-Jun-2004  tron Pull up revision 1.20 (requested by jmc in ticket #527):
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.30.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.30.2.3 30-Oct-2012  yamt sync with head
 1.30.2.2 23-May-2012  yamt sync with head.
 1.30.2.1 17-Apr-2012  yamt sync with head
 1.35.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.35.2.1 25-Feb-2013  tls resync with head
 1.58.2.1 02-Aug-2025  perseant Sync with HEAD
 1.44 30-Apr-2025  christos From FreeBSD D50078 by jrtc27:

Linux's struct stat does not have an st_flags member, but we still want
to be able to create FreeBSD disk images with non-zero st_flags. Add a
replacement member to struct fsinode to store it on Linux.
 1.43 27-Oct-2024  christos Document debugging options and allow specifying them by name.
 1.42 17-Jun-2024  reinoud branches: 1.42.2;
Bump inode number on target FS from 32 bits to 64 bits
 1.41 18-Feb-2024  christos Add an options pretty-printer, pass some lint.
 1.40 08-May-2022  reinoud Revert, sorry this was not intended to be committed.
 1.39 07-May-2022  reinoud When creating disc images, keep the proposed size a multiple of the blockingnr
for good measure; this prevents possible burning/copying issues on packet
media.
 1.38 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.37 03-Apr-2021  simonb Add a -L option to follow all symbolic links. Useful if you have symlinks
in a makefs directory tree but want to refer to the actual file.
 1.36 25-Nov-2015  christos Provide a -T option to set timestamps to a consistent value for MKREPRO
 1.35 05-Aug-2013  reinoud Implement `makefs -t udf'.

Formatting options may be enhanced to make it more in line with newfs_udf on
say labeling.
 1.34 03-Feb-2013  christos add a replace flag so we can overlay exiting files when we merge directories.
 1.33 02-Feb-2013  christos add and document offset.
 1.32 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.31 29-Jan-2013  christos make everything use the generic options parser.
 1.30 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.29 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.28 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.27 22-Jun-2012  sjg branches: 1.27.2;
Add -Z to enable sparse files - for ffs at least.
Based on a patch from shesha at juniper.
 1.26 19-Apr-2012  christos - fix compilation isses
- add some error checking
- avoid alloca
- add missing frees
 1.25 19-Apr-2012  ttoth added chfs support for makefs
 1.24 28-Jan-2012  christos Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.23 18-Jul-2011  tron branches: 1.23.2;
Re-enable v7fs support in the tools version of "makefs" after the
issues have been fixed by Alan Barrett. Tested under Mac OS X.
 1.22 18-Jul-2011  tron Don't include v7fs support into tool version of "makefs" because it
breaks the build.
 1.21 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.20 28-Dec-2008  christos fix for 64 bit time_t and dev_t.
 1.19 10-Oct-2006  dbj implement -x by pruning fsnodes tree before building filesystem rather
than by skipping nodes while building filesystem
 1.18 10-Oct-2006  dbj add implementation of free_fsnodes() which unlinks a node
from the hierarchy and frees it and any of its children
use it to free memory before a normal exit, which helps diagnostics
 1.17 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.16 20-Dec-2004  jmc Refactor the filesystem specific portions out of makefs.c/makefs.h completely.
Instead of extending fsinfo_t it now holds a void * to file system specific
data. This is then setup/cleaned up by the additional of 2 additional
callbacks. Makes adding new filesystems simpler as almost no code has
to be updated in the generic makefs code now.
 1.15 12-Oct-2004  jmc Check for fstatvfs and provide/use it only if the host system has it.
Fixes PR#27221
 1.14 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.13 21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.12 27-Oct-2003  lukem branches: 1.12.2;
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.11 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.10 30-Mar-2003  lukem Tweak Jason's -x support to pass its state around as part of fsinf_t,
just like all the other "global" options.
Update the usage for -x.
Crank date on man page.

(Thanks to Jason for adding -x; I've been meaning to add that
functionality for a while :-)
 1.9 29-Mar-2003  thorpej Add a -x option which causes makefs(8) to exclude any file system node
not explicitly listed in the specfile.
 1.8 14-Feb-2002  lukem remove (now) incorrect comment
 1.7 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.6 26-Jan-2002  lukem - crank default cpg from 16 to 65536, and let the auto-sizing code in
mkfs() do its job
- pass cpgflg=1 to mkfs() if the user provided cpg, =0 otherwise
- improve error reporting in ffs_write_file()
- only add superblock & block map slop for one cylinder group.
trying to calculate the number of required cylinder groups caused
too many problems when tweaking parameters for small file systems.
rely upon slop from minfree, and upon ffs_write_file() to complain
if the user is too aggressive about tweaking the parameters
 1.5 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.4 05-Dec-2001  lukem rework `fsnode' into two components; `fsnode' contains the name and tree
information and a link to the appropriate fsinode, and `fsinode' contains
the inode information and a reference count. multiple fsnodes may point
to the same fsinode. this replaces the 'dup' pointer in the previous code.
 1.3 25-Nov-2001  lukem - Use strsuftoull() from dd(1) to parse numbers, rather than home grown
version. The new version supports products, 'g' (GB) and 't' (TB)
suffices, and `b' now means `blocks' instead of `bytes'.
Functionality requested by perry.
- debug is now a u_int instead of an int.
- Ensure that various numbers have sane upper limits (e.g, 99 for %, etc)
 1.2 02-Nov-2001  lukem tweak copyright
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.12.2.1 22-Jun-2004  tron Pull up revision 1.14 (requested by jmc in ticket #527):
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.23.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.23.2.3 30-Oct-2012  yamt sync with head
 1.23.2.2 23-May-2012  yamt sync with head.
 1.23.2.1 17-Apr-2012  yamt sync with head
 1.27.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.27.2.1 25-Feb-2013  tls resync with head
 1.42.2.1 02-Aug-2025  perseant Sync with HEAD
 1.25 29-Feb-2024  tkusumi makefs/msdos: Fix broken [extra-directory ...] case

"path + cur->name" is not same as "cur->root + cur->path + cur->name"
for extra-directory files, as extra-directory files are
in different location. Do what makefs ffs code does.
 1.24 18-Feb-2024  christos PR/57945: Jan-Benedict Glaw: makefs: msdos filesystems with label not
reproducible.
When we specify a label, the volume label is used to create the root dir
and it gets stamped by the timestamp. We were trying to set the timestamp
in the fs-specific part of the options parsing which did not work since
the method was called only for fs_specific options. Move setting of the
timestamp just before we create the fs, where we reconcile the rest of
the options.
 1.23 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.22 20-Dec-2023  tsutsui Return a proper exit status on failure on creating msdosfs.

No particular comment in PR bin/57752.
Should be pulled up to netbsd-10 and netbsd-9.
 1.21 09-Apr-2022  riastradh branches: 1.21.2;
makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.20 14-Apr-2017  christos branches: 1.20.14;
leave the size alone and set the create_size to include the offset. It
does not matter anyway, but it makes more sense this way.
 1.19 13-Apr-2017  christos for consistency with ffs, don't count the offset into the size.
 1.18 16-Feb-2017  christos allow 0 timestamp
 1.17 16-Feb-2017  christos start fixing msdosfs for reproducible builds; does not work yet.
 1.16 30-Jan-2016  mlelstv branches: 1.16.2; 1.16.4;
Add support to msdosfs and makefs to generate correct Unicode (UCS-2) directory
entries from UTF8 encoded file names.
 1.15 16-Oct-2015  christos remove clause 3.
 1.14 03-Feb-2013  christos branches: 1.14.4; 1.14.10;
- more changes to make -O work
- fix err* calls.
 1.13 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.12 30-Jan-2013  christos gc global sectorsize.
 1.11 29-Jan-2013  christos add missing arguments.
 1.10 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.9 27-Jan-2013  christos fix recursion error handling. top level directory works.
 1.8 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.7 27-Jan-2013  christos fixed directory entry allocation. Now the file data remains and is currently
broken.
 1.6 26-Jan-2013  christos add more msdos stuff.
 1.5 24-Jan-2013  christos - Fix single letter option parsing.
- Instead of returning 1 << index and 0 on error,
return just index and -1 on error for the set_option*() routines.
 1.4 23-Jan-2013  christos ok, we can create the filesystem now.
 1.3 23-Jan-2013  christos return the bit of the option set, so that others can act on it.
 1.2 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.1 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.14.10.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.10.1 03-Feb-2013  yamt file msdos.c was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.14.4.2 25-Feb-2013  tls resync with head
 1.14.4.1 03-Feb-2013  tls file msdos.c was added on branch tls-maxphys on 2013-02-25 00:30:44 +0000
 1.16.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.16.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.16.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.20.14.1 30-Dec-2023  martin Pull up following revision(s) (requested by tsutsui in ticket #1783):

usr.sbin/makefs/msdos.c: revision 1.22

Return a proper exit status on failure on creating msdosfs.

No particular comment in PR bin/57752.
 1.21.2.1 30-Dec-2023  martin Pull up following revision(s) (requested by tsutsui in ticket #522):

usr.sbin/makefs/msdos.c: revision 1.22

Return a proper exit status on failure on creating msdosfs.

No particular comment in PR bin/57752.
 1.3 16-Oct-2015  christos remove clause 3.
 1.2 26-Jan-2013  christos branches: 1.2.4; 1.2.10;
add debugging, fix warnings.
 1.1 26-Jan-2013  christos add more msdos stuff.
 1.2.10.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.10.1 26-Jan-2013  yamt file msdos.h was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.2.4.2 25-Feb-2013  tls resync with head
 1.2.4.1 26-Jan-2013  tls file msdos.h was added on branch tls-maxphys on 2013-02-25 00:30:44 +0000
 1.31 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.30 07-May-2022  reinoud When creating disc images, keep the proposed size a multiple of the blockingnr
for good measure; this prevents possible burning/copying issues on packet
media.
 1.29 26-Apr-2022  reinoud Avoid warning by clang of unused variable

While here, use the computated obj_size even though it's always the same as
its information length since we don't use extended attribute files or
stream directories.
 1.28 26-Apr-2022  reinoud Fix endian bug that resulted in UniqueIDs of 0 in file identifiers; note that
the the unique ID in a longad stored in a FID is 32 bit where in the file
descriptor (fe/efe) its 64 bits long.
 1.27 26-Apr-2022  reinoud No need to use ceilf() when ceil() is already used
 1.26 26-Apr-2022  reinoud Fix endian bug in makefs for udf
 1.25 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.24 06-Apr-2022  wiz makefs: fix some typos
 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 21-Aug-2021  andvar s/helt/held+s/eroneously/erroneously/+s/splitted/split/+s/recommented/recommended/
 1.21 18-Apr-2020  martin Remove unused variable (to fix the build)
 1.20 18-Apr-2020  reinoud Believe the datablocks predictor when determining if data on a node gets
stored internal or not. Also make a note that the datablocks predictor takes
NO extended attributes stored in the node into account

In rare cases it could lead to confusion where the predictor would say it
wouldn't fit internally when it could just have fitted. This would trigger the
assertion. Now it will on rare accasions create a datablock even though it
might have fitted.
 1.19 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.18 08-Feb-2017  christos branches: 1.18.12;
If we are using a timestamp from the command line, don't pay attention to
the user timezone, use UTC instead (for reproducible builds).
 1.17 16-Jun-2015  christos branches: 1.17.2; 1.17.4;
improve error messages (remove \n, use __func__, etc)
 1.16 19-Dec-2013  joerg branches: 1.16.4; 1.16.8;
long_ad is a mix of struct and union, so use memset to initialise in the
one place it is used.
 1.15 19-Dec-2013  christos initialize dummy_ref
 1.14 19-Oct-2013  christos fix unused variable warnings.
 1.13 14-Aug-2013  jmcneill when building as a tool, only use struct tm tm_gmtoff if HAVE_STRUCT_TM_TM_GMTOFF is defined -- fixes cygwin build
 1.12 09-Aug-2013  reinoud Fix possible 32 bit issues. In practice hard to reach but better be safe than
sorry.
 1.11 09-Aug-2013  reinoud Oops, used size_t when off_t was meant. This results in the 4G file size
modulation seen on 32 bit machines due to size_t being 32 bit there.

While here, also fix compilation errors he@ discovered while compiling on
NetBSD/vax.
 1.10 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.9 06-Aug-2013  reinoud Add minimum UDF version specification to makefs(8) -t udf.
 1.8 06-Aug-2013  reinoud Allow for the logical volume label to be specified as well as the physical
volume label. Also allow the volumeset name to be specified if desired. The
syntax follows the newfs_udf(8) syntax.
 1.7 06-Aug-2013  reinoud Implement auto-setting of sector size and disc size when specifying
-oT=<devtype> to one of the supported disk types.

While here, also fix where the -s size argument would be overriden by the
calculated size.
 1.6 06-Aug-2013  reinoud Fix assert() on allocation type by masking it with the flag allocation bit
mask. Fixes internal allocation writing in nodes with suid/sgid/sticky
accessnode.
 1.5 06-Aug-2013  reinoud Fix memory leaks found by Coverity and fix memoryleaks in the new code
 1.4 05-Aug-2013  reinoud Revert joergs patch and make it compile in both the normal as in the tools
environment by providing the MMC datastructures separately for compat.
 1.3 05-Aug-2013  joerg Allow building UDF parts of makefs on !NetBSD.
 1.2 05-Aug-2013  reinoud Make memset() usage consequent in using the right types
 1.1 05-Aug-2013  reinoud Implement `makefs -t udf'.

Formatting options may be enhanced to make it more in line with newfs_udf on
say labeling.
 1.16.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.8.1 19-Dec-2013  tls file udf.c was added on branch tls-maxphys on 2014-08-20 00:05:09 +0000
 1.16.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.16.4.1 19-Dec-2013  yamt file udf.c was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.17.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.17.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.18.12.2 21-Apr-2020  martin Sync with HEAD
 1.18.12.1 10-Jun-2019  christos Sync with HEAD
 1.8 29-Jan-2013  christos make everything use the generic options parser.
 1.7 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.6 24-Jan-2013  christos - Fix single letter option parsing.
- Instead of returning 1 << index and 0 on error,
return just index and -1 on error for the set_option*() routines.
 1.5 23-Jan-2013  christos remove duplicated code, and try to cleanup parsing by using the shared code.
cd9660 needs a lot of work.
 1.4 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.3 10-Aug-2011  uch branches: 1.3.2; 1.3.8;
newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.2 19-Jul-2011  joerg Allow cross-compiling from Linux
 1.1 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.3.8.1 25-Feb-2013  tls resync with head
 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.2 10-Aug-2011  uch newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.1 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.43 01-May-2025  andvar s/sollowed/followed/ in comment.
 1.42 30-Apr-2025  christos From FreeBSD D50078 by jrtc27:

Linux's struct stat does not have an st_flags member, but we still want
to be able to create FreeBSD disk images with non-zero st_flags. Add a
replacement member to struct fsinode to store it on Linux.
 1.41 18-Oct-2024  christos PR/58759: Kenichi Hashimoto: failed merge with extra-directory using -r option
 1.40 08-May-2024  christos branches: 1.40.2;
Add an option to warn and error out for mtree missing entries.
 1.39 24-Apr-2024  rillig makefs: fix out-of-bounds fsnode count in fsnode_sort

Found by running './makefs img.dat cd9660'.

While here, apply more KNF.
 1.38 24-Apr-2024  christos use __func__
 1.37 24-Apr-2024  christos make a separate sorting function and KNF (thanks rillig)
 1.36 23-Apr-2024  christos pass lint, simplify
 1.35 23-Apr-2024  christos makefs: Fix symlink permission bits

Permission bits for symlinks are taken straight from `lstat()`. However, the
actual bits presented to the user are filesystem/kernel specific. For example,
Linux with ext2/3/4 will use 0777 for symlinks, whereas NetBSD/FFS will
show 0755. As far as `makefs` is in the loop, the target filesystem will likely
be FFS, so use 0755.
 1.34 23-Apr-2024  christos makefs: Sort directory contents by name (Jan-Benedict Glaw)

`makefs` inserts nodes into its internal data structures in the order as
returned by `readdir()` calls. As this is unpredictable, sort entries by
name before creating the target filesystem.

This is done by first converting the (per-directory) linked list into
a plain array, sort it, finally re-link the list. Special case for the
sorting function: The "." directory entry seems to be ment to be always
at the front, so always check that first.
 1.33 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.32 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.31 06-Apr-2022  wiz makefs: fix some typos
 1.30 03-Apr-2021  simonb Add a -L option to follow all symbolic links. Useful if you have symlinks
in a makefs directory tree but want to refer to the actual file.
 1.29 25-Nov-2015  christos Provide a -T option to set timestamps to a consistent value for MKREPRO
 1.28 03-Feb-2013  christos add a replace flag so we can overlay exiting files when we merge directories.
 1.27 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.26 19-Apr-2012  christos branches: 1.26.2;
WARNS=5
 1.25 28-Jan-2012  christos Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.24 28-Dec-2008  christos branches: 1.24.8;
fix for 64 bit time_t and dev_t.
 1.23 10-Oct-2006  dbj implement -x by pruning fsnodes tree before building filesystem rather
than by skipping nodes while building filesystem
 1.22 10-Oct-2006  dbj add implementation of free_fsnodes() which unlinks a node
from the hierarchy and frees it and any of its children
use it to free memory before a normal exit, which helps diagnostics
 1.21 10-Oct-2006  dbj free specfile structure once it has been applied
 1.20 10-Oct-2006  dbj use new implementation of link_check which i
implemented for du.c revision 1.25 :

Use open address hashtable with multiplicative double hash probing
and exponential hashtable growth for tracking previously seen inodes.
This replaces the O(n^2) behavior of linkchk() with an implementation
that should be O(n*logn)
 1.19 01-Feb-2006  dyoung Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.18 19-Aug-2005  christos 64 bit inode changes
 1.17 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.16 31-May-2004  lukem Use uint64_t instead of uint32_t to store a host inode when checking
for duplicate inodes, as Cygwin's stat(2) has a 64 bit st_ino.
Fix from Ian Lance Taylor in private email.
 1.15 19-Sep-2003  itojun branches: 1.15.2;
realloc pedant
 1.14 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.13 09-May-2003  itojun just for safety - use sizeof
 1.12 29-Mar-2003  thorpej Add a -x option which causes makefs(8) to exclude any file system node
not explicitly listed in the specfile.
 1.11 27-Jan-2003  uwe s/ulong/unsigned long/. ulong is for SysV compatibility, there's no
point in using it in our code. This change makes makefs(8) compile on
host systems without ulong.
 1.10 19-Oct-2002  provos use readlink with bufsize - 1; approved thorpej.
 1.9 08-Feb-2002  lukem branches: 1.9.2;
If an entry is in the specfile but not in the underlying file system, and it's
marked "optional", don't add it. (e.g, don't create a zero-length file).
 1.8 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.7 23-Jan-2002  lukem Merge create_fsinode() into create_fsnode(), so that a newly created
fsnode always has a valid inode member. Problem noted by Artem Belevich.
 1.6 05-Dec-2001  lukem rework `fsnode' into two components; `fsnode' contains the name and tree
information and a link to the appropriate fsinode, and `fsinode' contains
the inode information and a reference count. multiple fsnodes may point
to the same fsinode. this replaces the 'dup' pointer in the previous code.
 1.5 02-Nov-2001  lukem tweak copyright
 1.4 29-Oct-2001  lukem cast time_t values to long if printing as %ld to appease the sparc64 port
 1.3 29-Oct-2001  lukem - apply_specdir(): when adding a new symlink from the specfile, do the assert
check on the correct node
- apply_specentry(): if this node is a duplicate of another, apply the
changes to the `master' entry instead of this one.
- fix inotype() to DTRT
- comment out some debugging info that is too verbose
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.9.2.1 23-Jul-2004  tron Apply patch (request by dbj in ticket 1723):
Fix building the netbsd-1-6 branch under Darwin/MacOS.
 1.15.2.1 22-Jun-2004  tron Pull up revision 1.17 (requested by jmc in ticket #527):
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.24.8.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.24.8.2 23-May-2012  yamt sync with head.
 1.24.8.1 17-Apr-2012  yamt sync with head
 1.26.2.1 25-Feb-2013  tls resync with head
 1.40.2.1 02-Aug-2025  perseant Sync with HEAD
 1.3 10-Aug-2012  joerg Remove many HAVE_GCC || HAVE_PCC conditionals as the options also apply
to Clang. Add a few cases of HAVE_LLVM for -fno-strict-aliasing.
 1.2 20-Jun-2011  mrg branches: 1.2.2;
remove most of the remaining HAVE_GCC tests that are always true in
the modern world.
 1.1 16-Jan-2009  pooka branches: 1.1.6;
Move fs-specific stuff in Makefile to fs/Makefile.inc to clarify
top-level Makefile.
 1.1.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.2.2.1 30-Oct-2012  yamt sync with head
 1.3 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.2 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.1 10-Jan-2009  bjh21 branches: 1.1.8; 1.1.14;
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.1.14.1 25-Feb-2013  tls resync with head
 1.1.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.2 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.1 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.6 17-Jun-2024  reinoud We know the target string buffer only needs 18 but gcc can't figure this out.
Fixes compiling with -Werror=format-truncation
 1.5 08-Feb-2017  christos If we are using a timestamp from the command line, don't pay attention to
the user timezone, use UTC instead (for reproducible builds).
 1.4 14-Mar-2007  christos branches: 1.4.58; 1.4.62;
PR/36006: Takahiro Kambe: makefs(8) create cd9660 file system with wrong time
stamp because localtime(3) and gmtime(3) share the same buffer. Fixed by using
the _r functions.
 1.3 24-Dec-2005  perry branches: 1.3.4;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.3.4.1 31-Mar-2007  bouyer Pull up following revision(s) (requested by taca in ticket #539):
usr.sbin/makefs/cd9660/cd9660_conversion.c: revision 1.4
PR/36006: Takahiro Kambe: makefs(8) create cd9660 file system with wrong time
stamp because localtime(3) and gmtime(3) share the same buffer. Fixed by using
the _r functions.
 1.4.62.1 21-Apr-2017  bouyer Sync with HEAD
 1.4.58.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.13 19-Oct-2013  christos fix unused variable warnings.
 1.12 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.11 27-Oct-2010  christos branches: 1.11.6; 1.11.12;
Handle > 2GB images. Thanks to Greg Troxel for testing!
 1.10 22-Oct-2010  christos - simple fseek->fseeko conversion. probably needs more work.
- use a constant instead of sprinkling 2048 everywhere.
 1.9 08-Jan-2009  bjh21 Typo: debuging -> debugging.
 1.8 30-Jan-2007  dogcow emasculate debugging mode for the hosttool version of makefs, to avoid various
hairy endian-decoding macros/inlined functions/etc.
 1.7 28-Jan-2007  dogcow revert this change, too.
 1.6 28-Jan-2007  dogcow Due to recent changes in the cd9660 code, crosscompilation of tools/makefs
now fails due to the use of [be]e{16,32}dec. Add a compat header, and force
the inclusion of <sys/endian.h>.
 1.5 18-Dec-2006  christos from Anon Ymous: compile with -Wextra
 1.4 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.2 25-Oct-2005  dyoung Overhaul makefs -t cd9660.

Functional: Do not add a missing period or a version number to
directories, since that doesn't fit the standard (thanks
Daniel Watt).

Add RRIP PX records (POSIX meta-information) to '.'
and '..' entries. Quiets kernel complaint, when we
mount a cd9660 filesystem, that there is a missing PX
entry.

Cosmetic: Reduce height of staircases. Remove an unused member
from struct _cd9660node. Extract a subroutine. KNF.

Use a TAILQ macros for lists of both SUSP/RRIP attributes
and directory entries.

XXX
XXX The new RRIP PX entries are not quite right.
XXX
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.11.12.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.12.1 25-Feb-2013  tls resync with 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.27 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.26 18-Apr-2023  christos The boot catalog pointer is a DWord, but we previously populated it via
cd9660_bothendian_dword which overwrote four unused bytes following it.
See El Torito 1.0 (1995) Figure 7 for details.

Found by Coverity on FreeBSD
 1.25 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.24 15-Nov-2020  jmcneill Add "efi" as a supported boot image type and derive the platform ID for
the validation entry from the default boot image instead of hard-coding
X86.
 1.23 28-Mar-2018  nonaka Correctly mark the last El Torito section header.

Pointed out by Benno Rice via DM.
 1.22 09-Nov-2017  nonaka branches: 1.22.2;
Initialize boot_catalog_entry's entry_type properly.

This had been missing but the type was used in cd9660_setup_boot().

From OpenBSD usr.sbin/makefs/cd9660/cd9660_eltorito.c r1.10.
 1.21 24-Jan-2017  nonaka branches: 1.21.4;
makefs(8): add cd9660 eltorito-alt-boot option for EFI boot.
 1.20 28-Jan-2013  christos branches: 1.20.12; 1.20.16;
- use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.19 19-Apr-2012  christos branches: 1.19.2;
WARNS=5
 1.18 02-Apr-2012  christos Pull FreeBSD fix from Andreas Tobbler:

- Write the ISO9660 descriptor after the apm partition entries.
- Fill the needed pmPartStatus flags. At least the OpenBIOS
implementation relies on these flags.

This commit fixes the panic seen on OS-X when inserting a FreeBSD/ppc disc.
Additionally OpenBIOS recognizes the partition where the boot code is located.
This lets us load a FreeBSD/ppc PowerMac kernel inside qemu.
 1.17 23-Jun-2011  enami branches: 1.17.2;
Move inclusion of sys/endian.h from cd9660_eltorito.c to cd9660.h
since actual user is not cd9660_eltorito.c but iso.h and
cd9660_eltorito.h.

Actually, include order/place of sys/endian.h doesn't matter on
netbsd since it is always included by sys/types.h but it's not
true on other system. This should fix cross build breakage on
freebsd introduced by rev. 1.16 of cd9660_eltorito.c.
Problem reported and fix suggested on twitter.
 1.16 23-May-2011  christos include system headers after config.h
 1.15 22-May-2011  christos From Nathan Whitehorn (nwhitehorn at freebsd dot org):
Add code to generate bootable ISOs on Powermac and CHRP systems.
Synthesize some partition maps (APM and MBR, respectively) pointing
to (a) the whole disk, and (b) relevant El Torito boot images that
have been added by other code. These partition maps are a little
bit funny looking, but they seem to work. FreeBSD has been using
this successfully in their release generation on powerpc, as well
as generating all non-SPARC install media. SPARC support could
probably be added as an extension of this patch.
 1.14 27-Oct-2010  christos Handle > 2GB images. Thanks to Greg Troxel for testing!
 1.13 22-Oct-2010  christos - simple fseek->fseeko conversion. probably needs more work.
- use a constant instead of sprinkling 2048 everywhere.
 1.12 27-Jul-2008  reinoud Fix typo in cd9660 functionname cd9660_setup_boot_volume_descritpor ->
cd9660_setup_boot_volume_descriptor.

Interestingly the same typo was used in 3 files!
 1.11 22-Apr-2006  christos branches: 1.11.20;
Coverity CID 548: Fix resource leak.
 1.10 31-Oct-2005  dyoung Oops, condition another printf on verbose_level > 0.
 1.9 31-Oct-2005  dyoung Condition several cd9660 printfs on verbose_level > 0. Silences
makefs -t cd9660.
 1.8 30-Oct-2005  dyoung Now that I understand what order boot-images and boot-entries are
intended to be kept on the boot-images and -entries lists, keep
them in that order: images grouped and entries grouped by system,
with later images nearer the front of the list.

*Really* apply boot options to the last boot-image specified.
 1.7 30-Oct-2005  dyoung Bug fix: record the actual number number of 512-byte "virtual"
sectors in the Sector Count field of the Initial/Default Entry in
the "El Torito" Boot Catalog, instead of blithely writing 1 (!!)
into the Sector Count field. Ditto the Section Entries.

Remove last remnants of cd9660's unsupported boot-load-size option.

Really use cd9660's boot-load-segment argument.

Change the boot images list from a LIST to a TAILQ.

Re-implement CD9660_BLOCKS() with howmany().

Introduce ELTORITO_DPRINTF and some debug messages.

Zero memory malloc'd in the El Torito code.

Revise some debugging outputs.

Insert a new boot-image on the boot-images list after the last
boot-image for the same architecture. It makes a (trivial) functional
difference.

Miscellaneous cosmetic changes. Remove useless variable-assignment.
 1.6 30-Oct-2005  dyoung Cosmetic: add temporary variables for lengthy, repeated clauses
like 'default_entry->entry_data.IE'. KNF.
 1.5 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.4 28-Oct-2005  dyoung Correct strcmp(3) usage (expect equal -> 0).
 1.3 28-Oct-2005  dyoung Use LIST_ macros instead of accessing list structure members lh_first
and le_next directly.
 1.2 19-Aug-2005  dyoung Change from malloc/strcpy idiom to strdup.

Revamp err, errx, warn, warnx usage.

Misc. cosmetic tweaks.

Make -o bootimage=sysname;filename expect NetBSD architecture names
(x86 -> i386; mac -> {macppc, mac68k}; ppc -> powerpc) for sysname.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.11.20.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.17.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.17.2.2 23-May-2012  yamt sync with head.
 1.17.2.1 17-Apr-2012  yamt sync with head
 1.19.2.1 25-Feb-2013  tls resync with head
 1.20.16.1 21-Apr-2017  bouyer Sync with HEAD
 1.20.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.21.4.1 30-Mar-2018  martin Pull up following revision(s) (requested by nonaka in ticket #660):
usr.sbin/makefs/cd9660/cd9660_eltorito.c: revision 1.22
usr.sbin/makefs/cd9660/cd9660_eltorito.c: revision 1.23

Initialize boot_catalog_entry's entry_type properly.

This had been missing but the type was used in cd9660_setup_boot().
From OpenBSD usr.sbin/makefs/cd9660/cd9660_eltorito.c r1.10.

Correctly mark the last El Torito section header.
Pointed out by Benno Rice via DM.
 1.22.2.1 30-Mar-2018  pgoyette Resolve conflicts between branch and HEAD
 1.6 24-Jan-2017  nonaka makefs(8): add cd9660 eltorito-alt-boot option for EFI boot.
 1.5 04-Jul-2009  ahoka branches: 1.5.28; 1.5.32;
Get rid of the DOS line endings in the file.
No change of the code intended.
 1.4 30-Oct-2005  dyoung Now that I understand what order boot-images and boot-entries are
intended to be kept on the boot-images and -entries lists, keep
them in that order: images grouped and entries grouped by system,
with later images nearer the front of the list.

*Really* apply boot options to the last boot-image specified.
 1.3 30-Oct-2005  dyoung Bug fix: record the actual number number of 512-byte "virtual"
sectors in the Sector Count field of the Initial/Default Entry in
the "El Torito" Boot Catalog, instead of blithely writing 1 (!!)
into the Sector Count field. Ditto the Section Entries.

Remove last remnants of cd9660's unsupported boot-load-size option.

Really use cd9660's boot-load-segment argument.

Change the boot images list from a LIST to a TAILQ.

Re-implement CD9660_BLOCKS() with howmany().

Introduce ELTORITO_DPRINTF and some debug messages.

Zero memory malloc'd in the El Torito code.

Revise some debugging outputs.

Insert a new boot-image on the boot-images list after the last
boot-image for the same architecture. It makes a (trivial) functional
difference.

Miscellaneous cosmetic changes. Remove useless variable-assignment.
 1.2 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.5.32.1 21-Apr-2017  bouyer Sync with HEAD
 1.5.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3 01-Feb-2006  dyoung Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.2 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.2 01-Feb-2006  dyoung Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.6 24-Dec-2015  christos little size_t/ssize_t...
 1.5 23-Mar-2011  christos Fix typos in character ranges from: Baptiste Daroussin bapt at freebsd dot org
 1.4 16-Jan-2007  hubertf * Don't include headers twice
* Remove a few trailing whitespaces
* Rearrange and join to one #if for some headers

Patch contributed by Slava Semushin <slava.semushin@gmail.com>
in private mail.
 1.3 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.3 01-Feb-2006  dyoung Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.2 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.18 28-Dec-2023  tsutsui Use EXIT_SUCCESS and EXIT_FAILURE where appropriate per style guide.
 1.17 19-Oct-2013  christos fix unused variable warnings.
 1.16 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.15 28-Jan-2012  christos branches: 1.15.6;
Patch from Jung-uk Kim (jkim at FreeBSD dot org) to allow contents of multiple
directories to be merged to the current image.
 1.14 04-Jan-2011  wiz branches: 1.14.6;
Fix fd leaks in error cases. Found by cppcheck.
 1.13 22-Oct-2010  christos - simple fseek->fseeko conversion. probably needs more work.
- use a constant instead of sprinkling 2048 everywhere.
 1.12 22-Nov-2009  mbalmer make sense
 1.11 22-Nov-2009  mbalmer s/the the/the/
 1.10 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.9 10-May-2008  skrll branches: 1.9.4; 1.9.6; 1.9.8;
Add an option to load a generic boot image into the first 32K of the
cd9660 image.
 1.8 22-Apr-2006  christos branches: 1.8.18; 1.8.20;
Coverity CID 550: Resource leak.
 1.7 23-Mar-2006  riz Coverity CID 2757: Don't leak memory in error conditions.
 1.6 31-Oct-2005  dyoung Remove the cd9660_inode hashtable for hard-links support, and re-use
the fsinode for the same purpose, per Luke Mewburn's suggestion on
source-changes@.
 1.5 30-Oct-2005  dyoung Add hard-link support: keep a hashtable that maps inodes for
regular files on the source filesystem to the offset of the first
data block on the target filesystem. Don't allocate blocks for a
file a second time (i.e., if it is already present in the hashtable).
Avoid writing the blocks of a file twice (use the FS_WRITTEN flag
in fsinode->flags for this purpose).
 1.4 30-Oct-2005  dyoung Normalize {err,warn}{,x} uses.
 1.3 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.2 25-Oct-2005  dyoung Overhaul makefs -t cd9660.

Functional: Do not add a missing period or a version number to
directories, since that doesn't fit the standard (thanks
Daniel Watt).

Add RRIP PX records (POSIX meta-information) to '.'
and '..' entries. Quiets kernel complaint, when we
mount a cd9660 filesystem, that there is a missing PX
entry.

Cosmetic: Reduce height of staircases. Remove an unused member
from struct _cd9660node. Extract a subroutine. KNF.

Use a TAILQ macros for lists of both SUSP/RRIP attributes
and directory entries.

XXX
XXX The new RRIP PX entries are not quite right.
XXX
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.8.20.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.18.1 18-May-2008  yamt sync with head.
 1.9.8.1 21-Apr-2010  matt sync to netbsd-5
 1.9.6.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.9.4.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 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 17-Apr-2012  yamt sync with head
 1.15.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.6.1 25-Feb-2013  tls resync with head
 1.3 01-Feb-2006  dyoung Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.2 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.17 17-Feb-2025  andvar s/bye/byte/ in comments.
 1.16 18-Apr-2023  christos branches: 1.16.2;
We previously attempted to emit Rock Ridge NM records only when the name
represented by the Rock Ridge extensions would actually differ. We would
omit the record for an all-upper-case directory name, however Linux (and
perhaps other operating systems) map names with no NM record to
lowercase.

This affected only directories, as file names have an implicit ";1"
version number appended and thus always differ. To solve, just emit NM
records for all entries other than DOT and DOTDOT .

We could continue to omit the NM record for directories that would avoid
mapping (for example, one named 1234.567) but this does not seem worth
the complexity.

From FreeBSD https://reviews.freebsd.org/D39258
 1.15 18-Apr-2023  christos The bit definitions for the TF_* timestamp bits (TF_MODIFY, etc.) were
incorrect, and timestamps were written in the wrong order.

See RRIP 4.1.6 Description of the "TF" System Use Entry for details.

From: https://reviews.freebsd.org/D39221
 1.14 30-May-2014  martin PR kern/48852 (which should have been bin/ in retrospect): apply patch
from Thomas Schmitt to fix rockridge encoding of device nodes.
 1.13 30-Jul-2013  reinoud branches: 1.13.2;
`makefs -t cd9660' fix from FreeBSD:
Submitted by: Thomas Schmitt via marius@freebsd.org
Obtained from: FreeBSD r253707

- Correctly set the Expiration Time in the Primary Volume Descriptor;
according to ISO 9660 8.4.26.1 unspecified date and time are denoted by the
digit 0 in RBP 1 to 16 but the number 0 in RBP 17.

- Rock Ridge TF entries should use a length of 5, because after the 4 bytes of
generic SUSP header there is one byte of flags. See typedef of ISO_RRIP_TF
in iso9660_rrip.h.
 1.12 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.11 29-Apr-2012  joerg branches: 1.11.2;
usage is dead. name_len should be read as unsigned byte.
 1.10 29-May-2011  tsutsui branches: 1.10.4;
Apply fixes for PR bin/44114 (makefs(8) -t cd9660 -o rockridge creates
corrupted cd9660fs):
- makefs/cd9660.c:
- cd9660_rrip_move_directory() should also update lenght[0] and
name_len[0] in dir->isoDirRecord
- makefs/cd9660/iso9660_rrip.c:
- cd9660_rrip_finalize_node() should check rr_real_parent in node->parent,
not in node itself in RRIP_PL case
- cd9660_rrip_initialize_node() should update only node passed as arg
so handle RRIP_PL in DOTDOT case

Fixes malformed dotdot entries in deep (more than 8 level) directories
moved into .rr_moved dir.

Should be pulled up to netbsd-5.
(no official ISO has such deep dirs, but cobalt restorecd is affected)
 1.9 28-May-2011  tsutsui - remove unnecessary (pasto?) line on RRIP PL handling for moved dir
- RRIP RE length should be 4, not 0
 1.8 10-Jan-2009  bjh21 Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.7 10-Jan-2009  he Initialize a local variable to get rid of a "may be used uninitialized"
warning (turned into error by -Werror).
 1.6 09-Jan-2009  bjh21 Fix another bug in SUSP "CE" handling: when the SUSP records fit into
the System Use field with fewer then 28 bytes to spare, we were
remembering the wrong length for the System Use field and hence
emitting a corrupt directory entry. This could be triggered by trying
to build a filesystem containing a regular file with a 120-byte name.
Now we're a little more careful.
 1.5 08-Jan-2009  bjh21 When splitting a System Use Area between a System Use field and a
Continuation Area, be sure to insert the "CE" record at the correct
point in the chain of SUSP records. Without this, makefs emits
an invalid image if any file needs a Continuation Area. The bug
seems to have been introduced with the conversion to TAILQs.
 1.4 18-Dec-2006  christos branches: 1.4.18; 1.4.20; 1.4.22;
from Anon Ymous: compile with -Wextra
 1.3 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.2 25-Oct-2005  dyoung Overhaul makefs -t cd9660.

Functional: Do not add a missing period or a version number to
directories, since that doesn't fit the standard (thanks
Daniel Watt).

Add RRIP PX records (POSIX meta-information) to '.'
and '..' entries. Quiets kernel complaint, when we
mount a cd9660 filesystem, that there is a missing PX
entry.

Cosmetic: Reduce height of staircases. Remove an unused member
from struct _cd9660node. Extract a subroutine. KNF.

Use a TAILQ macros for lists of both SUSP/RRIP attributes
and directory entries.

XXX
XXX The new RRIP PX entries are not quite right.
XXX
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.4.22.1 21-Apr-2010  matt sync to netbsd-5
 1.4.20.4 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.4.20.3 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.7
Initialize a local variable to get rid of a "may be used uninitialized"
warning (turned into error by -Werror).
 1.4.20.2 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.6
Fix another bug in SUSP "CE" handling: when the SUSP records fit into
the System Use field with fewer then 28 bytes to spare, we were
remembering the wrong length for the System Use field and hence
emitting a corrupt directory entry. This could be triggered by trying
to build a filesystem containing a regular file with a 120-byte name.
Now we're a little more careful.
 1.4.20.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.5
When splitting a System Use Area between a System Use field and a
Continuation Area, be sure to insert the "CE" record at the correct
point in the chain of SUSP records. Without this, makefs emits
an invalid image if any file needs a Continuation Area. The bug
seems to have been introduced with the conversion to TAILQs.
 1.4.18.5 15-Jul-2011  riz Pull up following revision(s) (requested by tsutsui in ticket #1638):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.9
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.10
usr.sbin/makefs/cd9660.c: revision 1.30
- remove unnecessary (pasto?) line on RRIP PL handling for moved dir
- RRIP RE length should be 4, not 0
Apply fixes for PR bin/44114 (makefs(8) -t cd9660 -o rockridge creates
corrupted cd9660fs):
- makefs/cd9660.c:
- cd9660_rrip_move_directory() should also update lenght[0] and
name_len[0] in dir->isoDirRecord
- makefs/cd9660/iso9660_rrip.c:
- cd9660_rrip_finalize_node() should check rr_real_parent in node->parent,
not in node itself in RRIP_PL case
- cd9660_rrip_initialize_node() should update only node passed as arg
so handle RRIP_PL in DOTDOT case
Fixes malformed dotdot entries in deep (more than 8 level) directories
moved into .rr_moved dir.
Should be pulled up to netbsd-5.
(no official ISO has such deep dirs, but cobalt restorecd is affected)
 1.4.18.4 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.4.18.3 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.7
Initialize a local variable to get rid of a "may be used uninitialized"
warning (turned into error by -Werror).
 1.4.18.2 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.6
Fix another bug in SUSP "CE" handling: when the SUSP records fit into
the System Use field with fewer then 28 bytes to spare, we were
remembering the wrong length for the System Use field and hence
emitting a corrupt directory entry. This could be triggered by trying
to build a filesystem containing a regular file with a 120-byte name.
Now we're a little more careful.
 1.4.18.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.5
When splitting a System Use Area between a System Use field and a
Continuation Area, be sure to insert the "CE" record at the correct
point in the chain of SUSP records. Without this, makefs emits
an invalid image if any file needs a Continuation Area. The bug
seems to have been introduced with the conversion to TAILQs.
 1.10.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.10.4.1 23-May-2012  yamt sync with head.
 1.11.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11.2.1 25-Feb-2013  tls resync with head
 1.13.2.1 10-Aug-2014  tls Rebase.
 1.16.2.1 02-Aug-2025  perseant Sync with HEAD
 1.8 18-Apr-2023  christos See RRIP 4.1.4 Description of the "NM" System Use Entry for details.

From FreeBSD
 1.7 18-Apr-2023  christos The bit definitions for the TF_* timestamp bits (TF_MODIFY, etc.) were
incorrect, and timestamps were written in the wrong order.

See RRIP 4.1.6 Description of the "TF" System Use Entry for details.

From: https://reviews.freebsd.org/D39221
 1.6 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.5 10-Jan-2009  bjh21 branches: 1.5.8; 1.5.14;
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.

Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.4 01-Feb-2006  dyoung branches: 1.4.26; 1.4.28; 1.4.30;
Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.3 30-Oct-2005  dyoung Remove invisible whitespace at ends of lines that disrupted my
speedy cursor-movement habits in vi.
 1.2 25-Oct-2005  dyoung Overhaul makefs -t cd9660.

Functional: Do not add a missing period or a version number to
directories, since that doesn't fit the standard (thanks
Daniel Watt).

Add RRIP PX records (POSIX meta-information) to '.'
and '..' entries. Quiets kernel complaint, when we
mount a cd9660 filesystem, that there is a missing PX
entry.

Cosmetic: Reduce height of staircases. Remove an unused member
from struct _cd9660node. Extract a subroutine. KNF.

Use a TAILQ macros for lists of both SUSP/RRIP attributes
and directory entries.

XXX
XXX The new RRIP PX entries are not quite right.
XXX
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.4.30.1 21-Apr-2010  matt sync to netbsd-5
 1.4.28.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.4.26.1 02-Jan-2010  snj Pull up following revision(s) (requested by tsutsui in ticket #1198):
usr.sbin/makefs/cd9660.c: revision 1.25 via patch
usr.sbin/makefs/cd9660.h: revision 1.13 via patch
usr.sbin/makefs/cd9660/cd9660_write.c: revision 1.10
usr.sbin/makefs/cd9660/iso9660_rrip.c: revision 1.8
usr.sbin/makefs/cd9660/iso9660_rrip.h: revision 1.5
Add support for encoding RISC OS metadata into ISO 9660 filesystems.
This is done by adding the general ability to stuff non-SUSP data into
the end of the System Use field of a Directory Record, which required
some amount of rewriting of the SUSP support. I think the result is
at least as good as what came before, and I've fixed at least one bug
along the way. Tested against RISC OS 3.70 on my Risc PC.
Oh, why do we want it? It should allow us to make acorn{26,32} CDs that
can be booted directly from RISC OS without mucking around copying the
bootloader to a native filing system.
 1.5.14.1 25-Feb-2013  tls resync with head
 1.5.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.2 01-Feb-2006  dyoung Stop duplicating the ISO9660 sources in sys/fs/cd9660/ for makefs(8).
 1.1 13-Aug-2005  fvdl cd9660 support. Written by Daniel Watt, Walter Deignan, Ryan Gabrys,
Alan Perez-Rathke and Ram Vedam.

Prototyping, KNF, WARNS=3 by me.

Note that this is marked experimental for now. It works well enough to
make NetBSD/i386 bootable images, but does need more work.
 1.2 20-Apr-2012  adam branches: 1.2.2;
Fix building tools
 1.1 19-Apr-2012  ttoth added chfs support for makefs
 1.2.2.2 23-May-2012  yamt sync with head.
 1.2.2.1 20-Apr-2012  yamt file Makefile.inc was added on branch yamt-pagecache on 2012-05-23 10:08:29 +0000
 1.9 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.8 10-Jan-2017  kamil Include missing header <unistd.h> for write(2) read(2) close(2)

These functions are undefined after switch to new zlib.
 1.7 07-Mar-2016  christos branches: 1.7.2;
PR/50911: David Binderman: Optimize memset
 1.6 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.5 27-Apr-2012  dogcow branches: 1.5.2; 1.5.4;
As this code is used by tools, and thus needs to be portable,
eliminate all the mucking around for an undocumented, seemingly
unused field and use 0.
 1.4 20-Apr-2012  adam Fix building tools
 1.3 19-Apr-2012  christos WARNS=5
 1.2 19-Apr-2012  christos - fix compilation isses
- add some error checking
- avoid alloca
- add missing frees
 1.1 19-Apr-2012  ttoth added chfs support for makefs
 1.5.4.1 25-Feb-2013  tls resync with head
 1.5.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.5.2.2 23-May-2012  yamt sync with head.
 1.5.2.1 27-Apr-2012  yamt file chfs_mkfs.c was added on branch yamt-pagecache on 2012-05-23 10:08:29 +0000
 1.7.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 19-Apr-2012  ttoth branches: 1.1.2;
added chfs support for makefs
 1.1.2.2 23-May-2012  yamt sync with head.
 1.1.2.1 19-Apr-2012  yamt file chfs_mkfs.h was added on branch yamt-pagecache on 2012-05-23 10:08:29 +0000
 1.1 16-Jan-2009  pooka Move fs-specific stuff in Makefile to fs/Makefile.inc to clarify
top-level Makefile.
 1.28 14-Mar-2023  kre In bwrite() if the write() returned -1, the associated errno was
being used after a (possible) call to printf (only happens when
debugging) and a certain call to free() (via brelse()).
Make a copy, and use that instead.
 1.27 14-Mar-2023  kre Use %zd to print ssize_t (%z[uxo] for size_t), rather than %jd
(just like the other adjacent printfs do)

Should fix i386 build.
 1.26 13-Mar-2023  christos modernize; release bpp and set it to NULL as the kernel does even if we
never return here.
 1.25 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.24 24-Jun-2016  christos tidy up error messages
 1.23 24-Dec-2015  christos little size_t/ssize_t...
 1.22 29-Mar-2015  agc Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.21 03-Feb-2013  christos - more changes to make -O work
- fix err* calls.
 1.20 02-Feb-2013  christos add and document offset.
 1.19 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.18 30-Jan-2013  christos buf is generic; it has nothing to do with ffs and will eventually be moved.
gc sectorize.
 1.17 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.16 28-Jan-2013  mlelstv Do not use *bp after freeing it in brelse.
 1.15 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.14 27-Jan-2013  christos Don't print the pointers in debugging, it is not useful.
zero all memory
 1.13 26-Jan-2013  christos make the buffer functions look exactly like the kernel ones and add other
cruft to make the kernel files compile.
 1.12 20-Jun-2004  jmc branches: 1.12.48; 1.12.54;
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.11 16-Oct-2003  itojun branches: 1.11.2;
safer use of realloc
 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 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.8 08-Jan-2002  lukem need ufs/ufs/dinode.h for ufs/ffs/fs.h
 1.7 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.6 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.5 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.4 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.3 02-Nov-2001  lukem tweak copyright
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.11.2.1 22-Jun-2004  tron Pull up revision 1.12 (requested by jmc in ticket #527):
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.12.54.1 25-Feb-2013  tls resync with head
 1.12.48.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 06-Mar-2022  hgutch Make sure daddr_t is a 64 bit type when building tools.
(see also PR sw-bug/56742 ).
 1.13 03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.12 16-Feb-2017  christos branches: 1.12.10; 1.12.12;
need <sys/stat.h>
 1.11 16-Feb-2017  christos fix msdos reproducible builds!
 1.10 29-Mar-2015  agc branches: 1.10.2; 1.10.4;
Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.9 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.8 30-Jan-2013  christos buf is generic; it has nothing to do with ffs and will eventually be moved.
gc sectorize.
 1.7 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.6 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.5 27-Jan-2013  christos zero memory
 1.4 26-Jan-2013  christos make this cross-compile friendly.
 1.3 26-Jan-2013  christos make the buffer functions look exactly like the kernel ones and add other
cruft to make the kernel files compile.
 1.2 02-Nov-2001  lukem branches: 1.2.56; 1.2.62;
tweak copyright
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.2.62.1 25-Feb-2013  tls resync with head
 1.2.56.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.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.10.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.12.12.1 10-Jun-2019  christos Sync with HEAD
 1.12.10.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.33 27-Jun-2025  andvar s/quadradically/quadratically/ in comments.
 1.32 13-Mar-2023  christos branches: 1.32.2;
Don't brelse() if bread() fails. The kernel does this for us. Our bread()
implementation just exits on failure, but if it didn't we would double-free.
From Ed Maste (https://reviews.freebsd.org/D39069)
 1.31 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.30 09-Apr-2022  riastradh branches: 1.30.2;
makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.29 24-Jun-2016  christos tidy up error messages
 1.28 29-Mar-2015  agc Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.27 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.26 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.25 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.24 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.23 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.22 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.21 26-Jan-2013  christos make the buffer functions look exactly like the kernel ones and add other
cruft to make the kernel files compile.
 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 19-Apr-2012  christos branches: 1.19.2;
WARNS=5
 1.18 06-Mar-2011  bouyer branches: 1.18.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.17 18-Dec-2006  christos branches: 1.17.30;
from Anon Ymous: compile with -Wextra
 1.16 19-Aug-2005  christos 64 bit inode changes
 1.15 23-Jun-2005  fvdl Pull in DIP_ADD from sys/ufs/ufs/inode.h and use it, to prevent bad lvalue
assignment warnings/errors from gcc4.
 1.14 20-Jun-2004  jmc branches: 1.14.2; 1.14.4;
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.13 07-Aug-2003  agc branches: 1.13.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, 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 20-Jul-2002  grant sweep of errx/warnx, remove unnecessary trailing \n
 1.9 06-Feb-2002  lukem use (size / DEV_BSIZE) instead of btodb(size). fixes cross build issue.
 1.8 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.7 08-Jan-2002  lukem need ufs/ufs/dinode.h for ufs/ffs/fs.h
 1.6 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.5 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.4 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.3 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.13.2.1 22-Jun-2004  tron Pull up revision 1.14 (requested by jmc in ticket #527):
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.14.4.1 12-Oct-2006  ghen Apply patch (requested by skrll in ticket #1529):
PR toolchain/34258: Fix cross-building NetBSD 3.x binutils with GCC 4.x.
 1.14.2.1 06-Oct-2006  ghen Apply patch (requested by skrll in ticket #1529):
PR toolchain/34258: Fix cross-building NetBSD 3.x binutils with GCC 4.x.
 1.17.30.1 08-Feb-2011  bouyer ffs_clusteracct() moved to ffs_subr.c, so remove it from this copy of
ffs_alloc.c (otherwise we have duplicate symbols at link time).
Always use UFS_FSNEEDSWAP(fs) even if !KERNEL; so we can use for makefs too.
other !KERNEL consumers will have UFS_FSNEEDSWAP(fs) == 0 anyway.
 1.18.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.18.4.2 23-Jan-2013  yamt sync with head
 1.18.4.1 23-May-2012  yamt sync with head.
 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.30.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.32.2.1 02-Aug-2025  perseant Sync with HEAD
 1.23 13-Mar-2023  christos Don't brelse() if bread() fails. The kernel does this for us. Our bread()
implementation just exits on failure, but if it didn't we would double-free.
From Ed Maste (https://reviews.freebsd.org/D39069)
 1.22 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.21 29-Mar-2015  agc Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.20 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.19 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.18 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.17 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.16 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.15 26-Jan-2013  christos make the buffer functions look exactly like the kernel ones and add other
cruft to make the kernel files compile.
 1.14 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.13 20-Jun-2004  jmc branches: 1.13.48; 1.13.54;
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.12 07-Aug-2003  agc branches: 1.12.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.11 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.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 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.8 08-Jan-2002  lukem need ufs/ufs/dinode.h for ufs/ffs/fs.h
 1.7 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.6 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.5 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.4 31-Dec-2001  thorpej Need <stdlib.h> for abort() prototype (noticed by gcc 3.1).
 1.3 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.12.2.1 22-Jun-2004  tron Pull up revision 1.13 (requested by jmc in ticket #527):
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.13.54.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.13.54.2 23-Jun-2013  tls resync from head
 1.13.54.1 25-Feb-2013  tls resync with head
 1.13.48.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.48.1 23-Jan-2013  yamt sync with head
 1.9 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.8 09-Apr-2022  riastradh branches: 1.8.2;
makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.7 09-Feb-2017  kre Revert the part of mkfs.c 1.36 that "gutted the const" (while
retaining the part that added a different one).

That is, re-constipate makefs (well, just a bit, no real pain here.)
 1.6 07-Aug-2003  agc branches: 1.6.78; 1.6.82;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.5 15-Jun-2003  tsutsui Fix function declaration mismatch with src/sys/ufs/ffs/ffs_extern.h which
causes makefs(8) failure on big endian machines. Pointed out by tsubai.

XXX The real problem is that some sources include {.CURDIR}/ffs/ffs_extern.h
XXX but others include /usr/include/ufs/ffs/ffs_extern.h .
 1.4 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.3 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.2 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.6.82.1 21-Apr-2017  bouyer Sync with HEAD
 1.6.78.1 20-Mar-2017  pgoyette Sync with HEAD
 1.8.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.42 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.41 17-Nov-2022  chs branches: 1.41.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.40 02-Apr-2022  mlelstv Avoid integer overflow on systems with 32bit disk addresses.
 1.39 26-Mar-2020  kre Fix the build, use %jd and (intmax_t) cast for big numbers, off_t
and ptrdiff_t aren't always the same size.
 1.38 25-Mar-2020  christos improve error messages.
 1.37 09-Feb-2017  kre branches: 1.37.12;

Revert the part of mkfs.c 1.36 that "gutted the const" (while
retaining the part that added a different one).

That is, re-constipate makefs (well, just a bit, no real pain here.)
 1.36 08-Feb-2017  christos gut const for now.
 1.35 08-Feb-2017  christos Don't store random (from ASLR) pointers into the superblock. Should be the
last (famous last words) problem with reproducible builds!
 1.34 24-Jun-2016  christos branches: 1.34.2; 1.34.4;
tidy up error messages
 1.33 21-Dec-2015  christos more deterministic ffs for reproducible builds.
 1.32 19-Oct-2013  christos fix unused variable warnings.
 1.31 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.30 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.29 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.28 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.27 03-Feb-2013  christos - more changes to make -O work
- fix err* calls.
 1.26 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 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 19-Apr-2012  dholland branches: 1.24.2;
Fix build failure reported by bracket.

(shouldn't this size_t be ino_t?)
 1.23 19-Apr-2012  christos WARNS=5
 1.22 09-Oct-2011  christos branches: 1.22.2;
add support for setting the ufs label. (Nathan Whitehorn)
 1.21 20-Dec-2004  jmc Refactor the filesystem specific portions out of makefs.c/makefs.h completely.
Instead of extending fsinfo_t it now holds a void * to file system specific
data. This is then setup/cleaned up by the additional of 2 additional
callbacks. Makes adding new filesystems simpler as almost no code has
to be updated in the generic makefs code now.
 1.20 24-Jun-2004  lukem Define FFS_MAXBSIZE to 65536 and use instead of MAXBSIZE.
Deprecate unused MAXINOPB.
Should fix PR [toolchain/25603].
 1.19 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.18 07-Sep-2003  fvdl branches: 1.18.2;
Revert arc4random usage. makefs is only used for install images,
filehandle randomization is not an issue there, and using arc4random
broke building makefs as a host tool.
 1.17 06-Sep-2003  itojun use arc4random
 1.16 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 1.15 16-Apr-2003  briggs Protect use of __RCSID() with a check to ensure that it's defined.
Suggested by Ian Lance Taylor on tech-userlevel@ to help cross-compilation
on Red Hat 7.3.
 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 28-Jan-2003  mrg make this build on alpha after daddr_t->64bit
 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 08-Aug-2002  soren Remove extraneous \n's in {err,warn}{,x} that used to be printfs.
 1.10 06-Feb-2002  lukem don't need <ufs/ufs/dir.h> here
 1.9 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.8 26-Jan-2002  lukem - crank default cpg from 16 to 65536, and let the auto-sizing code in
mkfs() do its job
- pass cpgflg=1 to mkfs() if the user provided cpg, =0 otherwise
- improve error reporting in ffs_write_file()
- only add superblock & block map slop for one cylinder group.
trying to calculate the number of required cylinder groups caused
too many problems when tweaking parameters for small file systems.
rely upon slop from minfree, and upon ffs_write_file() to complain
if the user is too aggressive about tweaking the parameters
 1.7 18-Jan-2002  lukem apply changes from revs 1.56-1.59 of newfs/mkfs.c:
* revision 1.56
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]
[ this fixes a problem in makefs(8) that matt green reported ]

* revision 1.58
clamp bsize to MAXBSIZE

* revision 1.59
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.

XXX: I must rework newfs/mkfs.c to make it easier to just .PATH into makefs(8)
 1.6 08-Jan-2002  lukem need ufs/ufs/dinode.h for ufs/ffs/fs.h
 1.5 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.4 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.3 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.2 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.18.2.2 25-Jun-2004  jmc Pullup rev 1.20 (requested by lukem in ticket #549)

Define FFS_MAXBSIZE to 65536 and use instead of MAXBSIZE.
Deprecate unused MAXINOPB. PR#25603 fixed.
 1.18.2.1 22-Jun-2004  tron Pull up revision 1.19 (requested by jmc in ticket #527):
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.22.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.22.2.2 23-Jan-2013  yamt sync with head
 1.22.2.1 23-May-2012  yamt sync with head.
 1.24.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.24.2.2 23-Jun-2013  tls resync from head
 1.24.2.1 25-Feb-2013  tls resync with head
 1.34.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.34.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.37.12.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.41.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.1 06-Mar-2022  hgutch Make sure daddr_t is a 64 bit type when building tools.
(see also PR sw-bug/56742 ).
 1.5 06-Mar-2022  hgutch Make sure daddr_t is a 64 bit type when building tools.
(see also PR sw-bug/56742 ).
 1.4 21-Dec-2015  christos more deterministic ffs for reproducible builds.
 1.3 21-Oct-2009  snj Remove 3rd and 4th clauses in christos' license. OK christos.
 1.2 24-Jun-2004  lukem Define FFS_MAXBSIZE to 65536 and use instead of MAXBSIZE.
Deprecate unused MAXINOPB.
Should fix PR [toolchain/25603].
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem branches: 1.1.1.1.4;
makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.1.1.1.4.1 25-Jun-2004  jmc Pullup rev 1.2 (requested by lukem in ticket #549)

Define FFS_MAXBSIZE to 65536 and use instead of MAXBSIZE.
Deprecate unused MAXINOPB. PR#25603 fixed.
 1.19 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.18 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.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 08-Oct-2005  chs branches: 1.16.42; 1.16.48;
avoid the need for a bogus initializer.
 1.15 07-Jun-2005  he Initialize a local variable in ufs_getlbns() to appease -Wuninitialized.
Marked with XXXGCC for sparc64 (found while compiling for it).

Reviewed by lukem.
 1.14 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.13 07-Aug-2003  agc branches: 1.13.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 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 31-Jan-2002  tv Protect __RCSID and __COPYRIGHT from being invoked if not defined.
 1.10 18-Jan-2002  lukem don't need ffs/buf.h here
 1.9 08-Jan-2002  lukem need ufs/ufs/dinode.h for ufs/ffs/fs.h
 1.8 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.7 07-Jan-2002  lukem - pull in <ufs/ufs/dinode.h> before <ufs/ffs/fs.h>
- #include <ufs/[uf]fs/*.h> instead of "ufs/[uf]fs/*.h", and don't bother
with -I../../sys; we'll solve the hostprog problem another way and
unconditionally pulling in NetBSD-current's usr/src/sys on a host system
could be a Bad Thing.
 1.6 07-Jan-2002  lukem fix bugs reported by matt green:
- when calculating file size, round up to frag size not block size
- #define FFS_EI in makefs.h, and include that before [uf]fs/*.h

other stuff:
- round up final size to next block (instead of next sector)
- protect makefs.h from multiple inclusion
 1.5 31-Dec-2001  thorpej Need <strings.h> for ffs() prototype (noticed by gcc 3.1).
 1.4 22-Nov-2001  lukem reference the ufs/[uf]fs headers in ../../sys rather than using those
in /usr/include. this should make it easier to make this a host tool
 1.3 08-Nov-2001  lukem sync with ufs/ufs/ufs_bmap.c rev 1.14:
- assert that ufs_getlbns() is only called for blocks which involve indirects
- use a shift instead of a multiply in one place
 1.2 28-Oct-2001  lukem add __RCSID()
 1.1 26-Oct-2001  lukem branches: 1.1.1;
Initial revision
 1.1.1.1 26-Oct-2001  lukem makefs - create a file system image from a directory tree.
It doesn't need any special privileges or kernel devices.

Only ffs image creation is supported at this time, although makefs has been
designed to allow the addition of other file system formats by writing new
back-ends.

This program was designed & implemented by Luke Mewburn of Wasabi Systems.
 1.13.2.1 22-Jun-2004  tron Pull up revision 1.14 (requested by jmc in ticket #527):
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.16.48.2 23-Jun-2013  tls resync from head
 1.16.48.1 25-Feb-2013  tls resync with head
 1.16.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.16.42.1 23-Jan-2013  yamt sync with head
 1.5 30-Jan-2013  christos - don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.4 23-Jun-2005  fvdl branches: 1.4.42; 1.4.48;
Pull in DIP_ADD from sys/ufs/ufs/inode.h and use it, to prevent bad lvalue
assignment warnings/errors from gcc4.
 1.3 07-Aug-2003  agc branches: 1.3.6; 1.3.10;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22366, verified by myself.
 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 07-Jan-2002  lukem add "ffs/ufs_inode.h" with a minimal struct inode, to replace
<ufs/ufs/inode.h>, since the latter has a lot of cruft we don't need
and it #include's way more stuff in <sys/*> (etc) than is needed here.
yet another nail in the "let's make makefs a proper host tool" coffin.
 1.3.10.1 12-Oct-2006  ghen Apply patch (requested by skrll in ticket #1529):
PR toolchain/34258: Fix cross-building NetBSD 3.x binutils with GCC 4.x.
 1.3.6.1 06-Oct-2006  ghen Apply patch (requested by skrll in ticket #1529):
PR toolchain/34258: Fix cross-building NetBSD 3.x binutils with GCC 4.x.
 1.4.48.1 25-Feb-2013  tls resync with head
 1.4.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.7 06-Feb-2016  mlelstv Split case folding table into separate source file and add full
copyright and permission notice from http://www.unicode.org/copyright.html
 1.6 01-Sep-2014  martin Make msdosfs time conversion use the y/m/d/h/m/s conversion functions
from clock_subr.c and compile that into the userland (and tools)
makefs as well.
 1.5 26-Jan-2013  christos branches: 1.5.4; 1.5.10; 1.5.12;
make this cross-compile friendly.
 1.4 26-Jan-2013  christos add more msdos stuff.
 1.3 23-Jan-2013  christos ok, we can create the filesystem now.
 1.2 23-Jan-2013  christos don't reuse the same variables
 1.1 23-Jan-2013  christos - add support for parsing different types; not just int.
- add beginning of msdos support.
 1.5.12.1 12-Nov-2014  snj Pull up following revision(s) (requested by martin in ticket #216):
share/man/man9/todr.9: revision 1.17
sys/arch/sh3/dev/rtc.c: revision 1.9
sys/dev/clock_subr.c: revision 1.17-1.22
sys/dev/clock_subr.h: revision 1.22
sys/fs/msdosfs/msdosfs_conv.c: revision 1.10
tools/compat/compat_defs.h: revision 1.98
tools/compat/dev/clock_subr.h: revision 1.1-1.2
usr.sbin/makefs/msdos/Makefile.inc: revision 1.6
clock_secs_to_ymdhms(9) takes seconds as a time_t, not int.
--
Make this compile- and usable from userland as well.
--
Add a slightly stripped down version of sys/dev/clock/clock_subr.h to make
this code available for tools.
--
Reformulate an overflow test so it can be used in tool builds (i.e. does
not depend on netbsd specific macros).
--
Make msdosfs time conversion use the y/m/d/h/m/s conversion functions
from clock_subr.c and compile that into the userland (and tools)
makefs as well.
--
Copy definitions of __type_min(t), __type_max(t), and some related macros,
from <sys/cdefs.h>, for use when building tools.
--
Revert previous; test secs > __type_max(time_t) again, now
that __type_max is available in tools/compat/compat_defs.h.
--
If HAVE_NBTOOL_CONFIG_H is set, then include "nbtool_config.h",
because this file is compiled as part of tools/makefs.
--
Counting leap years was fine while we had 32bit time_t - but now it
is not a good idea for dates far away in the future.
For dates in the year 2000 or later, use arithmetic instead (since the
repeating periods are well aligned). Should fix PR 49144.
--
Avoid overflowing the "year" value by making the field uint64_t. Adapt
arguments and local variables accordingly.
This now fixes PR 49144 for real.
--
Adapt formats for debug printfs to clock_subr type changes.
 1.5.10.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.10.1 26-Jan-2013  yamt file Makefile.inc was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.5.4.2 25-Feb-2013  tls resync with head
 1.5.4.1 26-Jan-2013  tls file Makefile.inc was added on branch tls-maxphys on 2013-02-25 00:30:45 +0000
 1.8 23-Oct-2021  thorpej Sanitize the symbol namespace. NFC.
 1.7 29-Mar-2015  agc Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.6 19-Oct-2013  christos branches: 1.6.4;
fix unused variable warnings.
 1.5 28-Jan-2013  christos branches: 1.5.4;
- use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.4 28-Jan-2013  christos don't forget to initialize the cache.
 1.3 27-Jan-2013  christos fix root detection (although the code is a noop)
 1.2 26-Jan-2013  christos make this cross-compile friendly.
 1.1 26-Jan-2013  christos add more msdos stuff.
 1.5.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.4.2 25-Feb-2013  tls resync with head
 1.5.4.1 28-Jan-2013  tls file msdosfs_denode.c was added on branch tls-maxphys on 2013-02-25 00:30:45 +0000
 1.6.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.6.4.1 19-Oct-2013  yamt file msdosfs_denode.c was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.13 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.12 23-Oct-2021  thorpej Sanitize the symbol namespace. NFC.
 1.11 27-Jan-2018  sevan Need strings.h for ffs()
 1.10 30-Jan-2016  mlelstv branches: 1.10.8;
Add support to msdosfs and makefs to generate correct Unicode (UCS-2) directory
entries from UTF8 encoded file names.
 1.9 29-Mar-2015  agc Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.8 09-Jul-2014  maxv branches: 1.8.2;
What a terrible use-after-free
 1.7 30-Jan-2013  christos branches: 1.7.4; 1.7.8; 1.7.10;
- don't abuse vp->fs to mean struct fs for ffs and struct msdos_opts;
make it always fsinfo_t and change void * to that.
- kill unused structure members.
 1.6 28-Jan-2013  christos - use emalloc and friends
- kill a bunch of global variables, more work to be done here
- homogenize option parsing. more work for cd9660
- use the new options parsing code to print an fs-specific usage
 1.5 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.4 27-Jan-2013  christos fixed directory entry allocation. Now the file data remains and is currently
broken.
 1.3 26-Jan-2013  christos make this cross-compile friendly.
 1.2 26-Jan-2013  christos add debugging, fix warnings.
 1.1 26-Jan-2013  christos add more msdos stuff.
 1.7.10.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.10.1 30-Jan-2013  yamt file msdosfs_vfsops.c was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.7.8.1 10-Aug-2014  tls Rebase.
 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 30-Jan-2013  tls file msdosfs_vfsops.c was added on branch tls-maxphys on 2013-02-25 00:30:45 +0000
 1.8.2.1 19-Feb-2018  snj Pull up following revision(s) (requested by sevan in ticket #1558):
sys/fs/msdosfs/msdosfs_fat.c: 1.32
usr.sbin/makefs/msdos/msdosfs_vfsops.c: 1.11
Need strings.h for ffs()
--
Need strings.h for ffs()
Resolves implict declaration warning of ffs() when building tools via
build.sh
 1.10.8.1 04-Feb-2018  martin Pull up following revision(s) (requested by sevan in ticket #518):
sys/fs/msdosfs/msdosfs_fat.c: revision 1.32
usr.sbin/makefs/msdos/msdosfs_vfsops.c: revision 1.11
Need strings.h for ffs()
Need strings.h for ffs()
Resolves implict declaration warning of ffs() when building tools via
build.sh
 1.22 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.21 23-Oct-2021  thorpej Sanitize the symbol namespace. NFC.
 1.20 23-Oct-2021  hannken Factor out the lookup results from struct denode.

No functional change.
 1.19 13-Apr-2017  christos Fix error handling; msdosfs_wfile is supposed to return errno.
 1.18 16-Feb-2017  christos start fixing msdosfs for reproducible builds; does not work yet.
 1.17 30-Jan-2016  mlelstv branches: 1.17.2; 1.17.4;
Add support to msdosfs and makefs to generate correct Unicode (UCS-2) directory
entries from UTF8 encoded file names.
 1.16 29-Mar-2015  agc Make the userland signature and uses of bread() match the kernel ones,
after the removal of the cred argument.
 1.15 19-Oct-2013  christos branches: 1.15.4;
fix unused variable warnings.
 1.14 29-Jan-2013  christos branches: 1.14.4;
workaround for gcc/vax
 1.13 28-Jan-2013  christos use pcbmap instead of the open coded hack now the pcbmap works.
 1.12 27-Jan-2013  christos - don't forget to set de_pmp
- unexpand inserted tabs to the "." and ".." strings!
 1.11 27-Jan-2013  christos undo c99
 1.10 27-Jan-2013  christos - some more debugging
- use msdosfs_update() -- should not be needed.
- remove <sys/mount.h>
 1.9 27-Jan-2013  christos This works well enough to populate plain files in the root dir. creating
directories fails.
 1.8 27-Jan-2013  christos the max msdos file size is less than size_t so don't bother checking against it.
 1.7 27-Jan-2013  christos fixed directory entry allocation. Now the file data remains and is currently
broken.
 1.6 27-Jan-2013  martin Make it compile on 32bit AND 64bit archs.
 1.5 27-Jan-2013  mbalmer Allow this to compile on 32bit architectures.
 1.4 26-Jan-2013  christos depend on TOOLS instead of __NetBSD__ for extra functionality
 1.3 26-Jan-2013  christos make this cross-compile friendly.
 1.2 26-Jan-2013  christos add debugging, fix warnings.
 1.1 26-Jan-2013  christos add more msdos stuff.
 1.14.4.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.4.2 25-Feb-2013  tls resync with head
 1.14.4.1 29-Jan-2013  tls file msdosfs_vnops.c was added on branch tls-maxphys on 2013-02-25 00:30:45 +0000
 1.15.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.15.4.1 19-Oct-2013  yamt file msdosfs_vnops.c was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.17.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.17.2.2 26-Apr-2017  pgoyette Sync with HEAD
 1.17.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.8 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.7 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.6 10-Apr-2022  riastradh makefs(8): Fix tool build -- no libutil DPADD if HOSTPROG.
 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 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.3 11-Jan-2017  joerg Disable a couple of warnings until further investigation.
 1.2 05-Aug-2013  reinoud branches: 1.2.4; 1.2.8; 1.2.12;
Cleanup makefile for makefs
 1.1 05-Aug-2013  reinoud Implement `makefs -t udf'.

Formatting options may be enhanced to make it more in line with newfs_udf on
say labeling.
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.8.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.8.1 05-Aug-2013  tls file Makefile.inc was added on branch tls-maxphys on 2014-08-20 00:05:09 +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 05-Aug-2013  yamt file Makefile.inc was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.2 09-Apr-2022  riastradh makefs(8): Nix trailing whitespace.

Computed by machine, eyeballed by hand, so to speak.
 1.1 05-Aug-2013  reinoud branches: 1.1.4; 1.1.8;
Revert joergs patch and make it compile in both the normal as in the tools
environment by providing the MMC datastructures separately for compat.
 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 cdio_mmc_structs.h was added on branch tls-maxphys on 2014-08-20 00:05:09 +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 cdio_mmc_structs.h was added on branch yamt-pagecache on 2014-05-22 11:43:05 +0000
 1.5 23-Jan-2013  christos don't reuse the same variables
 1.4 19-Jul-2011  joerg branches: 1.4.2; 1.4.8;
Allow cross-compiling from Linux
 1.3 18-Jul-2011  tron Define "USE_V7FS" in the makefile of the directory with the actual source.
 1.2 18-Jul-2011  tron Don't include v7fs support into tool version of makefs because it
breaks the build.
 1.1 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.4.8.1 25-Feb-2013  tls resync with head
 1.4.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 19-Apr-2012  christos WARNS=5
 1.2 10-Aug-2011  uch branches: 1.2.2;
newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.1 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.
 1.2.2.1 23-May-2012  yamt sync with head.
 1.4 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.3 10-Aug-2011  uch newfs_v7fs(8)'s -v and -P options are obsolete. changed to newfs(8) compatible -V option.
 1.2 18-Jul-2011  tron Fix broken error check found by GCC 4.5.
 1.1 18-Jul-2011  uch v7fs(7th edition(V7) file system) support.

RSS XML Feed