NetBSD/usr.sbin/makefs
riastradh d1579b2d70 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!)
2018-09-03 16:29:22 +00:00
..
cd9660 Correctly mark the last El Torito section header. 2018-03-28 06:48:55 +00:00
chfs Include missing header <unistd.h> for write(2) read(2) close(2) 2017-01-10 04:27:02 +00:00
ffs Rename min/max -> uimin/uimax for better honesty. 2018-09-03 16:29:22 +00:00
msdos Need strings.h for ffs() 2018-01-27 02:07:33 +00:00
udf Disable a couple of warnings until further investigation. 2017-01-11 12:19:43 +00:00
v7fs
Makefile
README
TODO
cd9660.c Change duplicate 'D' option to 'm'. From Ed Maste @ FreeBSD 2017-03-15 15:33:54 +00:00
cd9660.h little size_t/ssize_t... 2015-12-24 15:52:37 +00:00
chfs.c
chfs_makefs.h
ffs.c PR/52828: Mark Johnston: makefs UFS2 lazy inode initialization is buggy 2017-12-16 23:08:40 +00:00
ffs.h
makefs.8 Whitespace fixes. 2017-04-14 07:09:43 +00:00
makefs.c Don't pass garbage to parsedate, but do use the return value. 2015-11-27 15:10:32 +00:00
makefs.h
msdos.c leave the size alone and set the create_size to include the offset. It 2017-04-14 15:40:35 +00:00
msdos.h
udf.c If we are using a timestamp from the command line, don't pay attention to 2017-02-08 21:33:12 +00:00
v7fs.c
v7fs_makefs.h
walk.c

README

$NetBSD: README,v 1.7 2015/01/12 19:50:47 christos Exp $

makefs - build a file system image from a directory tree

NOTES:

    *   This tool uses modified local copies of source found in other
	parts of the tree.  This is intentional.

    *	makefs is a work in progress, and subject to change.


user overview:
--------------

makefs creates a file system image from a given directory tree.
the following file system types can be built:

	cd9660	ISO 9660 file system
	chfs	"Chip" file system, for flash devices
	ffs	BSD fast file system
	msdos	MS-DOS `FAT' file system (FAT12, FAT16, FAT32)
	udf	Universal Disk Format file system
	v7fs	7th edition(V7) file system

Support for the following file systems maybe be added in the future

	ext2fs	Linux EXT2 file system

Various file system independent parameters and contraints can be
specified, such as:

	- minimum file system size (in KB)
	- maximum file system size (in KB)
	- free inodes
	- free blocks (in KB)
	- mtree(8) specification file containing permissions and ownership
	  to use in image, overridding the settings in the directory tree
	- file containing list of files to specifically exclude or include
	- fnmatch(3) pattern of filenames to exclude or include
	- endianness of target file system

File system specific parameters can be given as well, with a command
line option such as "-o fsspeccific-options,comma-separated".
For example, ffs would allow tuning of:

	- block & fragment size
	- cylinder groups
	- number of blocks per inode
	- minimum free space

Other file systems might have controls on how to "munge" file names to
fit within the constraints of the target file system.

Exit codes:
	0	all ok
	1	fatal error
	2	some files couldn't be added during image creation
		(bad perms, missing file, etc). image will continue
		to be made


Implementation overview:
------------------------

The implementation must allow for easy addition of extra file systems
with minimal changes to the file system independent sections.

The main program will:
	- parse the options, including calling fs-specific routines to
	  validate fs-specific options
	- walk the tree, building up a data structure which represents
	  the tree to stuff into the image. The structure will
	  probably be a similar tree to what mtree(8) uses internally;
	  a linked list of entries per directory with a child pointer
	  to children of directories. ".." won't be stored in the list;
	  the fs-specific tree walker should add this if required by the fs. 
	  this builder have the smarts to handle hard links correctly.
	- (optionally) Change the permissions in the tree according to
	  the mtree(8) specfile
	- Call an fs-specific routine to build the image based on the
	  data structures.

Each fs-specific module should have the following external interfaces:

    prepare_options	optional file system specific defaults that need to be
			setup before parsing fs-specific options.

    parse_options	parse the string for fs-specific options, feeding
			errors back to the user as appropriate

    cleanup_options	optional file system specific data that need to be
			cleaned up when done with this filesystem.

    make_fs		take the data structures representing the
			directory tree and fs parameters,
			validate that the parameters are valid
			(e.g, the requested image will be large enough), 
			create the image, and
			populate the image

prepare_options and cleanup_options are optional and can be NULL.

NOTE: All file system specific options are referenced via the fs_specific
pointer from the fsinfo_t strucutre. It is up to the filesystem to allocate
and free any data needed for this via the prepare and cleanup callbacks.

Each fs-specific module will need to add its routines to the dispatch array
in makefs.c and add prototypes for these to makefs.h

All other implementation details should not need to change any of the
generic code.

ffs implementation
------------------

In the ffs case, we can leverage off sbin/newfs/mkfs.c to actually build
the image. When building and populating the image, the implementation
can be greatly simplified if some assumptions are made:
	- the total required size (in blocks and inodes) is determined
	  as part of the validation phase
	- a "file" (including a directory) has a known size, so
	  support for growing a file is not necessary

Two underlying primitives are provided:
	make_inode	create an inode, returning the inode number

	write_file	write file (from memory if DIR, file descriptor
			if FILE or SYMLINK), referencing given inode.
			it is smart enough to know if a short symlink
			can be stuffed into the inode, etc.

When creating a directory, the directory entries in the previously
built tree data structure is scanned and built in memory so it can
be written entirely as a single write_file() operation.