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