README revision 1.9
11.9Smsaitoh$NetBSD: README,v 1.9 2024/02/07 04:00:10 msaitoh Exp $
21.1Slukem
31.1Slukemmakefs - build a file system image from a directory tree
41.1Slukem
51.1SlukemNOTES:
61.1Slukem
71.1Slukem    *   This tool uses modified local copies of source found in other
81.1Slukem	parts of the tree.  This is intentional.
91.1Slukem
101.1Slukem    *	makefs is a work in progress, and subject to change.
111.1Slukem
121.1Slukem
131.1Slukemuser overview:
141.1Slukem--------------
151.1Slukem
161.1Slukemmakefs creates a file system image from a given directory tree.
171.1Slukemthe following file system types can be built:
181.7Schristos
191.7Schristos	cd9660	ISO 9660 file system
201.7Schristos	chfs	"Chip" file system, for flash devices
211.1Slukem	ffs	BSD fast file system
221.7Schristos	msdos	MS-DOS `FAT' file system (FAT12, FAT16, FAT32)
231.7Schristos	udf	Universal Disk Format file system
241.5Such	v7fs	7th edition(V7) file system
251.1Slukem
261.1SlukemSupport for the following file systems maybe be added in the future
271.7Schristos
281.1Slukem	ext2fs	Linux EXT2 file system
291.1Slukem
301.8SandvarVarious file system independent parameters and constraints can be
311.1Slukemspecified, such as:
321.7Schristos
331.1Slukem	- minimum file system size (in KB)
341.1Slukem	- maximum file system size (in KB)
351.1Slukem	- free inodes
361.1Slukem	- free blocks (in KB)
371.1Slukem	- mtree(8) specification file containing permissions and ownership
381.8Sandvar	  to use in image, overriding the settings in the directory tree
391.1Slukem	- file containing list of files to specifically exclude or include
401.1Slukem	- fnmatch(3) pattern of filenames to exclude or include
411.1Slukem	- endianness of target file system
421.1Slukem
431.1SlukemFile system specific parameters can be given as well, with a command
441.1Slukemline option such as "-o fsspeccific-options,comma-separated".
451.1SlukemFor example, ffs would allow tuning of:
461.7Schristos
471.2Slukem	- block & fragment size
481.1Slukem	- cylinder groups
491.1Slukem	- number of blocks per inode
501.1Slukem	- minimum free space
511.1Slukem
521.1SlukemOther file systems might have controls on how to "munge" file names to
531.1Slukemfit within the constraints of the target file system.
541.1Slukem
551.1SlukemExit codes:
561.1Slukem	0	all ok
571.1Slukem	1	fatal error
581.1Slukem	2	some files couldn't be added during image creation
591.1Slukem		(bad perms, missing file, etc). image will continue
601.1Slukem		to be made
611.1Slukem
621.1Slukem
631.1SlukemImplementation overview:
641.1Slukem------------------------
651.1Slukem
661.1SlukemThe implementation must allow for easy addition of extra file systems
671.1Slukemwith minimal changes to the file system independent sections.
681.1Slukem
691.1SlukemThe main program will:
701.1Slukem	- parse the options, including calling fs-specific routines to
711.1Slukem	  validate fs-specific options
721.1Slukem	- walk the tree, building up a data structure which represents
731.1Slukem	  the tree to stuff into the image. The structure will
741.1Slukem	  probably be a similar tree to what mtree(8) uses internally;
751.1Slukem	  a linked list of entries per directory with a child pointer
761.1Slukem	  to children of directories. ".." won't be stored in the list;
771.1Slukem	  the fs-specific tree walker should add this if required by the fs. 
781.1Slukem	  this builder have the smarts to handle hard links correctly.
791.1Slukem	- (optionally) Change the permissions in the tree according to
801.1Slukem	  the mtree(8) specfile
811.1Slukem	- Call an fs-specific routine to build the image based on the
821.1Slukem	  data structures.
831.1Slukem
841.1SlukemEach fs-specific module should have the following external interfaces:
851.1Slukem
861.3Sjmc    prepare_options	optional file system specific defaults that need to be
871.3Sjmc			setup before parsing fs-specific options.
881.3Sjmc
891.1Slukem    parse_options	parse the string for fs-specific options, feeding
901.1Slukem			errors back to the user as appropriate
911.1Slukem
921.3Sjmc    cleanup_options	optional file system specific data that need to be
931.3Sjmc			cleaned up when done with this filesystem.
941.3Sjmc
951.1Slukem    make_fs		take the data structures representing the
961.1Slukem			directory tree and fs parameters,
971.1Slukem			validate that the parameters are valid
981.1Slukem			(e.g, the requested image will be large enough), 
991.1Slukem			create the image, and
1001.1Slukem			populate the image
1011.1Slukem
1021.3Sjmcprepare_options and cleanup_options are optional and can be NULL.
1031.3Sjmc
1041.3SjmcNOTE: All file system specific options are referenced via the fs_specific
1051.9Smsaitohpointer from the fsinfo_t structure. It is up to the filesystem to allocate
1061.3Sjmcand free any data needed for this via the prepare and cleanup callbacks.
1071.3Sjmc
1081.6SsnjEach fs-specific module will need to add its routines to the dispatch array
1091.3Sjmcin makefs.c and add prototypes for these to makefs.h
1101.3Sjmc
1111.3SjmcAll other implementation details should not need to change any of the
1121.3Sjmcgeneric code.
1131.1Slukem
1141.1Slukemffs implementation
1151.1Slukem------------------
1161.1Slukem
1171.1SlukemIn the ffs case, we can leverage off sbin/newfs/mkfs.c to actually build
1181.1Slukemthe image. When building and populating the image, the implementation
1191.1Slukemcan be greatly simplified if some assumptions are made:
1201.1Slukem	- the total required size (in blocks and inodes) is determined
1211.1Slukem	  as part of the validation phase
1221.1Slukem	- a "file" (including a directory) has a known size, so
1231.1Slukem	  support for growing a file is not necessary
1241.1Slukem
1251.1SlukemTwo underlying primitives are provided:
1261.1Slukem	make_inode	create an inode, returning the inode number
1271.1Slukem
1281.1Slukem	write_file	write file (from memory if DIR, file descriptor
1291.1Slukem			if FILE or SYMLINK), referencing given inode.
1301.1Slukem			it is smart enough to know if a short symlink
1311.1Slukem			can be stuffed into the inode, etc.
1321.1Slukem
1331.1SlukemWhen creating a directory, the directory entries in the previously
1341.1Slukembuilt tree data structure is scanned and built in memory so it can
1351.1Slukembe written entirely as a single write_file() operation.
136