195 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3=======================4ROMFS - ROM File System5=======================6 7This is a quite dumb, read only filesystem, mainly for initial RAM8disks of installation disks. It has grown up by the need of having9modules linked at boot time. Using this filesystem, you get a very10similar feature, and even the possibility of a small kernel, with a11file system which doesn't take up useful memory from the router12functions in the basement of your office.13 14For comparison, both the older minix and xiafs (the latter is now15defunct) filesystems, compiled as module need more than 20000 bytes,16while romfs is less than a page, about 4000 bytes (assuming i58617code). Under the same conditions, the msdos filesystem would need18about 30K (and does not support device nodes or symlinks), while the19nfs module with nfsroot is about 57K. Furthermore, as a bit unfair20comparison, an actual rescue disk used up 3202 blocks with ext2, while21with romfs, it needed 3079 blocks.22 23To create such a file system, you'll need a user program named24genromfs. It is available on http://romfs.sourceforge.net/25 26As the name suggests, romfs could be also used (space-efficiently) on27various read-only media, like (E)EPROM disks if someone will have the28motivation.. :)29 30However, the main purpose of romfs is to have a very small kernel,31which has only this filesystem linked in, and then can load any module32later, with the current module utilities. It can also be used to run33some program to decide if you need SCSI devices, and even IDE or34floppy drives can be loaded later if you use the "initrd"--initial35RAM disk--feature of the kernel. This would not be really news36flash, but with romfs, you can even spare off your ext2 or minix or37maybe even affs filesystem until you really know that you need it.38 39For example, a distribution boot disk can contain only the cd disk40drivers (and possibly the SCSI drivers), and the ISO 9660 filesystem41module. The kernel can be small enough, since it doesn't have other42filesystems, like the quite large ext2fs module, which can then be43loaded off the CD at a later stage of the installation. Another use44would be for a recovery disk, when you are reinstalling a workstation45from the network, and you will have all the tools/modules available46from a nearby server, so you don't want to carry two disks for this47purpose, just because it won't fit into ext2.48 49romfs operates on block devices as you can expect, and the underlying50structure is very simple. Every accessible structure begins on 1651byte boundaries for fast access. The minimum space a file will take52is 32 bytes (this is an empty file, with a less than 16 character53name). The maximum overhead for any non-empty file is the header, and54the 16 byte padding for the name and the contents, also 16+14+15 = 4555bytes. This is quite rare however, since most file names are longer56than 3 bytes, and shorter than 15 bytes.57 58The layout of the filesystem is the following::59 60 offset content61 62 +---+---+---+---+63 0 | - | r | o | m | \64 +---+---+---+---+ The ASCII representation of those bytes65 4 | 1 | f | s | - | / (i.e. "-rom1fs-")66 +---+---+---+---+67 8 | full size | The number of accessible bytes in this fs.68 +---+---+---+---+69 12 | checksum | The checksum of the FIRST 512 BYTES.70 +---+---+---+---+71 16 | volume name | The zero terminated name of the volume,72 : : padded to 16 byte boundary.73 +---+---+---+---+74 xx | file |75 : headers :76 77Every multi byte value (32 bit words, I'll use the longwords term from78now on) must be in big endian order.79 80The first eight bytes identify the filesystem, even for the casual81inspector. After that, in the 3rd longword, it contains the number of82bytes accessible from the start of this filesystem. The 4th longword83is the checksum of the first 512 bytes (or the number of bytes84accessible, whichever is smaller). The applied algorithm is the same85as in the AFFS filesystem, namely a simple sum of the longwords86(assuming bigendian quantities again). For details, please consult87the source. This algorithm was chosen because although it's not quite88reliable, it does not require any tables, and it is very simple.89 90The following bytes are now part of the file system; each file header91must begin on a 16 byte boundary::92 93 offset content94 95 +---+---+---+---+96 0 | next filehdr|X| The offset of the next file header97 +---+---+---+---+ (zero if no more files)98 4 | spec.info | Info for directories/hard links/devices99 +---+---+---+---+100 8 | size | The size of this file in bytes101 +---+---+---+---+102 12 | checksum | Covering the meta data, including the file103 +---+---+---+---+ name, and padding104 16 | file name | The zero terminated name of the file,105 : : padded to 16 byte boundary106 +---+---+---+---+107 xx | file data |108 : :109 110Since the file headers begin always at a 16 byte boundary, the lowest1114 bits would be always zero in the next filehdr pointer. These four112bits are used for the mode information. Bits 0..2 specify the type of113the file; while bit 4 shows if the file is executable or not. The114permissions are assumed to be world readable, if this bit is not set,115and world executable if it is; except the character and block devices,116they are never accessible for other than owner. The owner of every117file is user and group 0, this should never be a problem for the118intended use. The mapping of the 8 possible values to file types is119the following:120 121== =============== ============================================122 mapping spec.info means123== =============== ============================================124 0 hard link link destination [file header]125 1 directory first file's header126 2 regular file unused, must be zero [MBZ]127 3 symbolic link unused, MBZ (file data is the link content)128 4 block device 16/16 bits major/minor number129 5 char device - " -130 6 socket unused, MBZ131 7 fifo unused, MBZ132== =============== ============================================133 134Note that hard links are specifically marked in this filesystem, but135they will behave as you can expect (i.e. share the inode number).136Note also that it is your responsibility to not create hard link137loops, and creating all the . and .. links for directories. This is138normally done correctly by the genromfs program. Please refrain from139using the executable bits for special purposes on the socket and fifo140special files, they may have other uses in the future. Additionally,141please remember that only regular files, and symlinks are supposed to142have a nonzero size field; they contain the number of bytes available143directly after the (padded) file name.144 145Another thing to note is that romfs works on file headers and data146aligned to 16 byte boundaries, but most hardware devices and the block147device drivers are unable to cope with smaller than block-sized data.148To overcome this limitation, the whole size of the file system must be149padded to an 1024 byte boundary.150 151If you have any problems or suggestions concerning this file system,152please contact me. However, think twice before wanting me to add153features and code, because the primary and most important advantage of154this file system is the small code. On the other hand, don't be155alarmed, I'm not getting that much romfs related mail. Now I can156understand why Avery wrote poems in the ARCnet docs to get some more157feedback. :)158 159romfs has also a mailing list, and to date, it hasn't received any160traffic, so you are welcome to join it to discuss your ideas. :)161 162It's run by ezmlm, so you can subscribe to it by sending a message163to romfs-subscribe@shadow.banki.hu, the content is irrelevant.164 165Pending issues:166 167- Permissions and owner information are pretty essential features of a168 Un*x like system, but romfs does not provide the full possibilities.169 I have never found this limiting, but others might.170 171- The file system is read only, so it can be very small, but in case172 one would want to write _anything_ to a file system, he still needs173 a writable file system, thus negating the size advantages. Possible174 solutions: implement write access as a compile-time option, or a new,175 similarly small writable filesystem for RAM disks.176 177- Since the files are only required to have alignment on a 16 byte178 boundary, it is currently possibly suboptimal to read or execute files179 from the filesystem. It might be resolved by reordering file data to180 have most of it (i.e. except the start and the end) laying at "natural"181 boundaries, thus it would be possible to directly map a big portion of182 the file contents to the mm subsystem.183 184- Compression might be an useful feature, but memory is quite a185 limiting factor in my eyes.186 187- Where it is used?188 189- Does it work on other architectures than intel and motorola?190 191 192Have fun,193 194Janos Farkas <chexum@shadow.banki.hu>195