1*6da2a6edSmsaitoh$NetBSD: README,v 1.9 2024/02/07 04:00:10 msaitoh Exp $ 2de8b3ad2Slukem 3de8b3ad2Slukemmakefs - build a file system image from a directory tree 4de8b3ad2Slukem 5de8b3ad2SlukemNOTES: 6de8b3ad2Slukem 7de8b3ad2Slukem * This tool uses modified local copies of source found in other 8de8b3ad2Slukem parts of the tree. This is intentional. 9de8b3ad2Slukem 10de8b3ad2Slukem * makefs is a work in progress, and subject to change. 11de8b3ad2Slukem 12de8b3ad2Slukem 13de8b3ad2Slukemuser overview: 14de8b3ad2Slukem-------------- 15de8b3ad2Slukem 16de8b3ad2Slukemmakefs creates a file system image from a given directory tree. 17de8b3ad2Slukemthe following file system types can be built: 18e701837bSchristos 19f9dee387Slukem cd9660 ISO 9660 file system 20e701837bSchristos chfs "Chip" file system, for flash devices 21e701837bSchristos ffs BSD fast file system 22e701837bSchristos msdos MS-DOS `FAT' file system (FAT12, FAT16, FAT32) 23e701837bSchristos udf Universal Disk Format file system 24dd9e8309Such v7fs 7th edition(V7) file system 25de8b3ad2Slukem 26de8b3ad2SlukemSupport for the following file systems maybe be added in the future 27e701837bSchristos 28de8b3ad2Slukem ext2fs Linux EXT2 file system 29de8b3ad2Slukem 3049811c99SandvarVarious file system independent parameters and constraints can be 31de8b3ad2Slukemspecified, such as: 32e701837bSchristos 33de8b3ad2Slukem - minimum file system size (in KB) 34de8b3ad2Slukem - maximum file system size (in KB) 35de8b3ad2Slukem - free inodes 36de8b3ad2Slukem - free blocks (in KB) 37de8b3ad2Slukem - mtree(8) specification file containing permissions and ownership 3849811c99Sandvar to use in image, overriding the settings in the directory tree 39de8b3ad2Slukem - file containing list of files to specifically exclude or include 40de8b3ad2Slukem - fnmatch(3) pattern of filenames to exclude or include 41de8b3ad2Slukem - endianness of target file system 42de8b3ad2Slukem 43de8b3ad2SlukemFile system specific parameters can be given as well, with a command 44de8b3ad2Slukemline option such as "-o fsspeccific-options,comma-separated". 45de8b3ad2SlukemFor example, ffs would allow tuning of: 46e701837bSchristos 47bb07f837Slukem - block & fragment size 48de8b3ad2Slukem - cylinder groups 49de8b3ad2Slukem - number of blocks per inode 50de8b3ad2Slukem - minimum free space 51de8b3ad2Slukem 52de8b3ad2SlukemOther file systems might have controls on how to "munge" file names to 53de8b3ad2Slukemfit within the constraints of the target file system. 54de8b3ad2Slukem 55de8b3ad2SlukemExit codes: 56de8b3ad2Slukem 0 all ok 57de8b3ad2Slukem 1 fatal error 58de8b3ad2Slukem 2 some files couldn't be added during image creation 59de8b3ad2Slukem (bad perms, missing file, etc). image will continue 60de8b3ad2Slukem to be made 61de8b3ad2Slukem 62de8b3ad2Slukem 63de8b3ad2SlukemImplementation overview: 64de8b3ad2Slukem------------------------ 65de8b3ad2Slukem 66de8b3ad2SlukemThe implementation must allow for easy addition of extra file systems 67de8b3ad2Slukemwith minimal changes to the file system independent sections. 68de8b3ad2Slukem 69de8b3ad2SlukemThe main program will: 70de8b3ad2Slukem - parse the options, including calling fs-specific routines to 71de8b3ad2Slukem validate fs-specific options 72de8b3ad2Slukem - walk the tree, building up a data structure which represents 73de8b3ad2Slukem the tree to stuff into the image. The structure will 74de8b3ad2Slukem probably be a similar tree to what mtree(8) uses internally; 75de8b3ad2Slukem a linked list of entries per directory with a child pointer 76de8b3ad2Slukem to children of directories. ".." won't be stored in the list; 77de8b3ad2Slukem the fs-specific tree walker should add this if required by the fs. 78de8b3ad2Slukem this builder have the smarts to handle hard links correctly. 79de8b3ad2Slukem - (optionally) Change the permissions in the tree according to 80de8b3ad2Slukem the mtree(8) specfile 81de8b3ad2Slukem - Call an fs-specific routine to build the image based on the 82de8b3ad2Slukem data structures. 83de8b3ad2Slukem 84de8b3ad2SlukemEach fs-specific module should have the following external interfaces: 85de8b3ad2Slukem 862406596eSjmc prepare_options optional file system specific defaults that need to be 872406596eSjmc setup before parsing fs-specific options. 882406596eSjmc 89de8b3ad2Slukem parse_options parse the string for fs-specific options, feeding 90de8b3ad2Slukem errors back to the user as appropriate 91de8b3ad2Slukem 922406596eSjmc cleanup_options optional file system specific data that need to be 932406596eSjmc cleaned up when done with this filesystem. 942406596eSjmc 95de8b3ad2Slukem make_fs take the data structures representing the 96de8b3ad2Slukem directory tree and fs parameters, 97de8b3ad2Slukem validate that the parameters are valid 98de8b3ad2Slukem (e.g, the requested image will be large enough), 99de8b3ad2Slukem create the image, and 100de8b3ad2Slukem populate the image 101de8b3ad2Slukem 1022406596eSjmcprepare_options and cleanup_options are optional and can be NULL. 1032406596eSjmc 1042406596eSjmcNOTE: All file system specific options are referenced via the fs_specific 105*6da2a6edSmsaitohpointer from the fsinfo_t structure. It is up to the filesystem to allocate 1062406596eSjmcand free any data needed for this via the prepare and cleanup callbacks. 1072406596eSjmc 108f0a7346dSsnjEach fs-specific module will need to add its routines to the dispatch array 1092406596eSjmcin makefs.c and add prototypes for these to makefs.h 1102406596eSjmc 1112406596eSjmcAll other implementation details should not need to change any of the 1122406596eSjmcgeneric code. 113de8b3ad2Slukem 114de8b3ad2Slukemffs implementation 115de8b3ad2Slukem------------------ 116de8b3ad2Slukem 117de8b3ad2SlukemIn the ffs case, we can leverage off sbin/newfs/mkfs.c to actually build 118de8b3ad2Slukemthe image. When building and populating the image, the implementation 119de8b3ad2Slukemcan be greatly simplified if some assumptions are made: 120de8b3ad2Slukem - the total required size (in blocks and inodes) is determined 121de8b3ad2Slukem as part of the validation phase 122de8b3ad2Slukem - a "file" (including a directory) has a known size, so 123de8b3ad2Slukem support for growing a file is not necessary 124de8b3ad2Slukem 125de8b3ad2SlukemTwo underlying primitives are provided: 126de8b3ad2Slukem make_inode create an inode, returning the inode number 127de8b3ad2Slukem 128de8b3ad2Slukem write_file write file (from memory if DIR, file descriptor 129de8b3ad2Slukem if FILE or SYMLINK), referencing given inode. 130de8b3ad2Slukem it is smart enough to know if a short symlink 131de8b3ad2Slukem can be stuffed into the inode, etc. 132de8b3ad2Slukem 133de8b3ad2SlukemWhen creating a directory, the directory entries in the previously 134de8b3ad2Slukembuilt tree data structure is scanned and built in memory so it can 135de8b3ad2Slukembe written entirely as a single write_file() operation. 136