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