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