README revision 1.4
11.4Slukem$NetBSD: README,v 1.4 2009/01/03 08:25:35 lukem 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.1Slukem ffs BSD fast file system 191.4Slukem cd9660 ISO 9660 file system 201.1Slukem 211.1SlukemSupport for the following file systems maybe be added in the future 221.1Slukem ext2fs Linux EXT2 file system 231.1Slukem fat MS-DOS `FAT' file system (FAT12, FAT16, FAT32) 241.1Slukem 251.1SlukemVarious file system independent parameters and contraints can be 261.1Slukemspecified, such as: 271.1Slukem - minimum file system size (in KB) 281.1Slukem - maximum file system size (in KB) 291.1Slukem - free inodes 301.1Slukem - free blocks (in KB) 311.1Slukem - mtree(8) specification file containing permissions and ownership 321.1Slukem to use in image, overridding the settings in the directory tree 331.1Slukem - file containing list of files to specifically exclude or include 341.1Slukem - fnmatch(3) pattern of filenames to exclude or include 351.1Slukem - endianness of target file system 361.1Slukem 371.1SlukemFile system specific parameters can be given as well, with a command 381.1Slukemline option such as "-o fsspeccific-options,comma-separated". 391.1SlukemFor example, ffs would allow tuning of: 401.2Slukem - block & fragment size 411.1Slukem - cylinder groups 421.1Slukem - number of blocks per inode 431.1Slukem - minimum free space 441.1Slukem 451.1SlukemOther file systems might have controls on how to "munge" file names to 461.1Slukemfit within the constraints of the target file system. 471.1Slukem 481.1SlukemExit codes: 491.1Slukem 0 all ok 501.1Slukem 1 fatal error 511.1Slukem 2 some files couldn't be added during image creation 521.1Slukem (bad perms, missing file, etc). image will continue 531.1Slukem to be made 541.1Slukem 551.1Slukem 561.1SlukemImplementation overview: 571.1Slukem------------------------ 581.1Slukem 591.1SlukemThe implementation must allow for easy addition of extra file systems 601.1Slukemwith minimal changes to the file system independent sections. 611.1Slukem 621.1SlukemThe main program will: 631.1Slukem - parse the options, including calling fs-specific routines to 641.1Slukem validate fs-specific options 651.1Slukem - walk the tree, building up a data structure which represents 661.1Slukem the tree to stuff into the image. The structure will 671.1Slukem probably be a similar tree to what mtree(8) uses internally; 681.1Slukem a linked list of entries per directory with a child pointer 691.1Slukem to children of directories. ".." won't be stored in the list; 701.1Slukem the fs-specific tree walker should add this if required by the fs. 711.1Slukem this builder have the smarts to handle hard links correctly. 721.1Slukem - (optionally) Change the permissions in the tree according to 731.1Slukem the mtree(8) specfile 741.1Slukem - Call an fs-specific routine to build the image based on the 751.1Slukem data structures. 761.1Slukem 771.1SlukemEach fs-specific module should have the following external interfaces: 781.1Slukem 791.3Sjmc prepare_options optional file system specific defaults that need to be 801.3Sjmc setup before parsing fs-specific options. 811.3Sjmc 821.1Slukem parse_options parse the string for fs-specific options, feeding 831.1Slukem errors back to the user as appropriate 841.1Slukem 851.3Sjmc cleanup_options optional file system specific data that need to be 861.3Sjmc cleaned up when done with this filesystem. 871.3Sjmc 881.1Slukem make_fs take the data structures representing the 891.1Slukem directory tree and fs parameters, 901.1Slukem validate that the parameters are valid 911.1Slukem (e.g, the requested image will be large enough), 921.1Slukem create the image, and 931.1Slukem populate the image 941.1Slukem 951.3Sjmcprepare_options and cleanup_options are optional and can be NULL. 961.3Sjmc 971.3SjmcNOTE: All file system specific options are referenced via the fs_specific 981.3Sjmcpointer from the fsinfo_t strucutre. It is up to the filesystem to allocate 991.3Sjmcand free any data needed for this via the prepare and cleanup callbacks. 1001.3Sjmc 1011.3SjmcEach fs-specific module will need to add it's routines to the dispatch array 1021.3Sjmcin makefs.c and add prototypes for these to makefs.h 1031.3Sjmc 1041.3SjmcAll other implementation details should not need to change any of the 1051.3Sjmcgeneric code. 1061.1Slukem 1071.1Slukemffs implementation 1081.1Slukem------------------ 1091.1Slukem 1101.1SlukemIn the ffs case, we can leverage off sbin/newfs/mkfs.c to actually build 1111.1Slukemthe image. When building and populating the image, the implementation 1121.1Slukemcan be greatly simplified if some assumptions are made: 1131.1Slukem - the total required size (in blocks and inodes) is determined 1141.1Slukem as part of the validation phase 1151.1Slukem - a "file" (including a directory) has a known size, so 1161.1Slukem support for growing a file is not necessary 1171.1Slukem 1181.1SlukemTwo underlying primitives are provided: 1191.1Slukem make_inode create an inode, returning the inode number 1201.1Slukem 1211.1Slukem write_file write file (from memory if DIR, file descriptor 1221.1Slukem if FILE or SYMLINK), referencing given inode. 1231.1Slukem it is smart enough to know if a short symlink 1241.1Slukem can be stuffed into the inode, etc. 1251.1Slukem 1261.1SlukemWhen creating a directory, the directory entries in the previously 1271.1Slukembuilt tree data structure is scanned and built in memory so it can 1281.1Slukembe written entirely as a single write_file() operation. 129