1*0a6a1f1dSLionel Sambuc$NetBSD: README,v 1.7 2015/01/12 19:50:47 christos Exp $ 29f988b79SJean-Baptiste Boric 39f988b79SJean-Baptiste Boricmakefs - build a file system image from a directory tree 49f988b79SJean-Baptiste Boric 59f988b79SJean-Baptiste BoricNOTES: 69f988b79SJean-Baptiste Boric 79f988b79SJean-Baptiste Boric * This tool uses modified local copies of source found in other 89f988b79SJean-Baptiste Boric parts of the tree. This is intentional. 99f988b79SJean-Baptiste Boric 109f988b79SJean-Baptiste Boric * makefs is a work in progress, and subject to change. 119f988b79SJean-Baptiste Boric 129f988b79SJean-Baptiste Boric 139f988b79SJean-Baptiste Boricuser overview: 149f988b79SJean-Baptiste Boric-------------- 159f988b79SJean-Baptiste Boric 169f988b79SJean-Baptiste Boricmakefs creates a file system image from a given directory tree. 179f988b79SJean-Baptiste Boricthe following file system types can be built: 18*0a6a1f1dSLionel Sambuc 199f988b79SJean-Baptiste Boric cd9660 ISO 9660 file system 20*0a6a1f1dSLionel Sambuc chfs "Chip" file system, for flash devices 21*0a6a1f1dSLionel Sambuc ffs BSD fast file system 22*0a6a1f1dSLionel Sambuc msdos MS-DOS `FAT' file system (FAT12, FAT16, FAT32) 23*0a6a1f1dSLionel Sambuc udf Universal Disk Format file system 249f988b79SJean-Baptiste Boric v7fs 7th edition(V7) file system 259f988b79SJean-Baptiste Boric 269f988b79SJean-Baptiste BoricSupport for the following file systems maybe be added in the future 27*0a6a1f1dSLionel Sambuc 289f988b79SJean-Baptiste Boric ext2fs Linux EXT2 file system 299f988b79SJean-Baptiste Boric 309f988b79SJean-Baptiste BoricVarious file system independent parameters and contraints can be 319f988b79SJean-Baptiste Boricspecified, such as: 32*0a6a1f1dSLionel Sambuc 339f988b79SJean-Baptiste Boric - minimum file system size (in KB) 349f988b79SJean-Baptiste Boric - maximum file system size (in KB) 359f988b79SJean-Baptiste Boric - free inodes 369f988b79SJean-Baptiste Boric - free blocks (in KB) 379f988b79SJean-Baptiste Boric - mtree(8) specification file containing permissions and ownership 389f988b79SJean-Baptiste Boric to use in image, overridding the settings in the directory tree 399f988b79SJean-Baptiste Boric - file containing list of files to specifically exclude or include 409f988b79SJean-Baptiste Boric - fnmatch(3) pattern of filenames to exclude or include 419f988b79SJean-Baptiste Boric - endianness of target file system 429f988b79SJean-Baptiste Boric 439f988b79SJean-Baptiste BoricFile system specific parameters can be given as well, with a command 449f988b79SJean-Baptiste Boricline option such as "-o fsspeccific-options,comma-separated". 459f988b79SJean-Baptiste BoricFor example, ffs would allow tuning of: 46*0a6a1f1dSLionel Sambuc 479f988b79SJean-Baptiste Boric - block & fragment size 489f988b79SJean-Baptiste Boric - cylinder groups 499f988b79SJean-Baptiste Boric - number of blocks per inode 509f988b79SJean-Baptiste Boric - minimum free space 519f988b79SJean-Baptiste Boric 529f988b79SJean-Baptiste BoricOther file systems might have controls on how to "munge" file names to 539f988b79SJean-Baptiste Boricfit within the constraints of the target file system. 549f988b79SJean-Baptiste Boric 559f988b79SJean-Baptiste BoricExit codes: 569f988b79SJean-Baptiste Boric 0 all ok 579f988b79SJean-Baptiste Boric 1 fatal error 589f988b79SJean-Baptiste Boric 2 some files couldn't be added during image creation 599f988b79SJean-Baptiste Boric (bad perms, missing file, etc). image will continue 609f988b79SJean-Baptiste Boric to be made 619f988b79SJean-Baptiste Boric 629f988b79SJean-Baptiste Boric 639f988b79SJean-Baptiste BoricImplementation overview: 649f988b79SJean-Baptiste Boric------------------------ 659f988b79SJean-Baptiste Boric 669f988b79SJean-Baptiste BoricThe implementation must allow for easy addition of extra file systems 679f988b79SJean-Baptiste Boricwith minimal changes to the file system independent sections. 689f988b79SJean-Baptiste Boric 699f988b79SJean-Baptiste BoricThe main program will: 709f988b79SJean-Baptiste Boric - parse the options, including calling fs-specific routines to 719f988b79SJean-Baptiste Boric validate fs-specific options 729f988b79SJean-Baptiste Boric - walk the tree, building up a data structure which represents 739f988b79SJean-Baptiste Boric the tree to stuff into the image. The structure will 749f988b79SJean-Baptiste Boric probably be a similar tree to what mtree(8) uses internally; 759f988b79SJean-Baptiste Boric a linked list of entries per directory with a child pointer 769f988b79SJean-Baptiste Boric to children of directories. ".." won't be stored in the list; 779f988b79SJean-Baptiste Boric the fs-specific tree walker should add this if required by the fs. 789f988b79SJean-Baptiste Boric this builder have the smarts to handle hard links correctly. 799f988b79SJean-Baptiste Boric - (optionally) Change the permissions in the tree according to 809f988b79SJean-Baptiste Boric the mtree(8) specfile 819f988b79SJean-Baptiste Boric - Call an fs-specific routine to build the image based on the 829f988b79SJean-Baptiste Boric data structures. 839f988b79SJean-Baptiste Boric 849f988b79SJean-Baptiste BoricEach fs-specific module should have the following external interfaces: 859f988b79SJean-Baptiste Boric 869f988b79SJean-Baptiste Boric prepare_options optional file system specific defaults that need to be 879f988b79SJean-Baptiste Boric setup before parsing fs-specific options. 889f988b79SJean-Baptiste Boric 899f988b79SJean-Baptiste Boric parse_options parse the string for fs-specific options, feeding 909f988b79SJean-Baptiste Boric errors back to the user as appropriate 919f988b79SJean-Baptiste Boric 929f988b79SJean-Baptiste Boric cleanup_options optional file system specific data that need to be 939f988b79SJean-Baptiste Boric cleaned up when done with this filesystem. 949f988b79SJean-Baptiste Boric 959f988b79SJean-Baptiste Boric make_fs take the data structures representing the 969f988b79SJean-Baptiste Boric directory tree and fs parameters, 979f988b79SJean-Baptiste Boric validate that the parameters are valid 989f988b79SJean-Baptiste Boric (e.g, the requested image will be large enough), 999f988b79SJean-Baptiste Boric create the image, and 1009f988b79SJean-Baptiste Boric populate the image 1019f988b79SJean-Baptiste Boric 1029f988b79SJean-Baptiste Boricprepare_options and cleanup_options are optional and can be NULL. 1039f988b79SJean-Baptiste Boric 1049f988b79SJean-Baptiste BoricNOTE: All file system specific options are referenced via the fs_specific 1059f988b79SJean-Baptiste Boricpointer from the fsinfo_t strucutre. It is up to the filesystem to allocate 1069f988b79SJean-Baptiste Boricand free any data needed for this via the prepare and cleanup callbacks. 1079f988b79SJean-Baptiste Boric 108*0a6a1f1dSLionel SambucEach fs-specific module will need to add its routines to the dispatch array 1099f988b79SJean-Baptiste Boricin makefs.c and add prototypes for these to makefs.h 1109f988b79SJean-Baptiste Boric 1119f988b79SJean-Baptiste BoricAll other implementation details should not need to change any of the 1129f988b79SJean-Baptiste Boricgeneric code. 1139f988b79SJean-Baptiste Boric 1149f988b79SJean-Baptiste Boricffs implementation 1159f988b79SJean-Baptiste Boric------------------ 1169f988b79SJean-Baptiste Boric 1179f988b79SJean-Baptiste BoricIn the ffs case, we can leverage off sbin/newfs/mkfs.c to actually build 1189f988b79SJean-Baptiste Boricthe image. When building and populating the image, the implementation 1199f988b79SJean-Baptiste Boriccan be greatly simplified if some assumptions are made: 1209f988b79SJean-Baptiste Boric - the total required size (in blocks and inodes) is determined 1219f988b79SJean-Baptiste Boric as part of the validation phase 1229f988b79SJean-Baptiste Boric - a "file" (including a directory) has a known size, so 1239f988b79SJean-Baptiste Boric support for growing a file is not necessary 1249f988b79SJean-Baptiste Boric 1259f988b79SJean-Baptiste BoricTwo underlying primitives are provided: 1269f988b79SJean-Baptiste Boric make_inode create an inode, returning the inode number 1279f988b79SJean-Baptiste Boric 1289f988b79SJean-Baptiste Boric write_file write file (from memory if DIR, file descriptor 1299f988b79SJean-Baptiste Boric if FILE or SYMLINK), referencing given inode. 1309f988b79SJean-Baptiste Boric it is smart enough to know if a short symlink 1319f988b79SJean-Baptiste Boric can be stuffed into the inode, etc. 1329f988b79SJean-Baptiste Boric 1339f988b79SJean-Baptiste BoricWhen creating a directory, the directory entries in the previously 1349f988b79SJean-Baptiste Boricbuilt tree data structure is scanned and built in memory so it can 1359f988b79SJean-Baptiste Boricbe written entirely as a single write_file() operation. 136