18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci======================= 48c2ecf20Sopenharmony_ciROMFS - ROM File System 58c2ecf20Sopenharmony_ci======================= 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciThis is a quite dumb, read only filesystem, mainly for initial RAM 88c2ecf20Sopenharmony_cidisks of installation disks. It has grown up by the need of having 98c2ecf20Sopenharmony_cimodules linked at boot time. Using this filesystem, you get a very 108c2ecf20Sopenharmony_cisimilar feature, and even the possibility of a small kernel, with a 118c2ecf20Sopenharmony_cifile system which doesn't take up useful memory from the router 128c2ecf20Sopenharmony_cifunctions in the basement of your office. 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciFor comparison, both the older minix and xiafs (the latter is now 158c2ecf20Sopenharmony_cidefunct) filesystems, compiled as module need more than 20000 bytes, 168c2ecf20Sopenharmony_ciwhile romfs is less than a page, about 4000 bytes (assuming i586 178c2ecf20Sopenharmony_cicode). Under the same conditions, the msdos filesystem would need 188c2ecf20Sopenharmony_ciabout 30K (and does not support device nodes or symlinks), while the 198c2ecf20Sopenharmony_cinfs module with nfsroot is about 57K. Furthermore, as a bit unfair 208c2ecf20Sopenharmony_cicomparison, an actual rescue disk used up 3202 blocks with ext2, while 218c2ecf20Sopenharmony_ciwith romfs, it needed 3079 blocks. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciTo create such a file system, you'll need a user program named 248c2ecf20Sopenharmony_cigenromfs. It is available on http://romfs.sourceforge.net/ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciAs the name suggests, romfs could be also used (space-efficiently) on 278c2ecf20Sopenharmony_civarious read-only media, like (E)EPROM disks if someone will have the 288c2ecf20Sopenharmony_cimotivation.. :) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ciHowever, the main purpose of romfs is to have a very small kernel, 318c2ecf20Sopenharmony_ciwhich has only this filesystem linked in, and then can load any module 328c2ecf20Sopenharmony_cilater, with the current module utilities. It can also be used to run 338c2ecf20Sopenharmony_cisome program to decide if you need SCSI devices, and even IDE or 348c2ecf20Sopenharmony_cifloppy drives can be loaded later if you use the "initrd"--initial 358c2ecf20Sopenharmony_ciRAM disk--feature of the kernel. This would not be really news 368c2ecf20Sopenharmony_ciflash, but with romfs, you can even spare off your ext2 or minix or 378c2ecf20Sopenharmony_cimaybe even affs filesystem until you really know that you need it. 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciFor example, a distribution boot disk can contain only the cd disk 408c2ecf20Sopenharmony_cidrivers (and possibly the SCSI drivers), and the ISO 9660 filesystem 418c2ecf20Sopenharmony_cimodule. The kernel can be small enough, since it doesn't have other 428c2ecf20Sopenharmony_cifilesystems, like the quite large ext2fs module, which can then be 438c2ecf20Sopenharmony_ciloaded off the CD at a later stage of the installation. Another use 448c2ecf20Sopenharmony_ciwould be for a recovery disk, when you are reinstalling a workstation 458c2ecf20Sopenharmony_cifrom the network, and you will have all the tools/modules available 468c2ecf20Sopenharmony_cifrom a nearby server, so you don't want to carry two disks for this 478c2ecf20Sopenharmony_cipurpose, just because it won't fit into ext2. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciromfs operates on block devices as you can expect, and the underlying 508c2ecf20Sopenharmony_cistructure is very simple. Every accessible structure begins on 16 518c2ecf20Sopenharmony_cibyte boundaries for fast access. The minimum space a file will take 528c2ecf20Sopenharmony_ciis 32 bytes (this is an empty file, with a less than 16 character 538c2ecf20Sopenharmony_ciname). The maximum overhead for any non-empty file is the header, and 548c2ecf20Sopenharmony_cithe 16 byte padding for the name and the contents, also 16+14+15 = 45 558c2ecf20Sopenharmony_cibytes. This is quite rare however, since most file names are longer 568c2ecf20Sopenharmony_cithan 3 bytes, and shorter than 15 bytes. 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciThe layout of the filesystem is the following:: 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci offset content 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci +---+---+---+---+ 638c2ecf20Sopenharmony_ci 0 | - | r | o | m | \ 648c2ecf20Sopenharmony_ci +---+---+---+---+ The ASCII representation of those bytes 658c2ecf20Sopenharmony_ci 4 | 1 | f | s | - | / (i.e. "-rom1fs-") 668c2ecf20Sopenharmony_ci +---+---+---+---+ 678c2ecf20Sopenharmony_ci 8 | full size | The number of accessible bytes in this fs. 688c2ecf20Sopenharmony_ci +---+---+---+---+ 698c2ecf20Sopenharmony_ci 12 | checksum | The checksum of the FIRST 512 BYTES. 708c2ecf20Sopenharmony_ci +---+---+---+---+ 718c2ecf20Sopenharmony_ci 16 | volume name | The zero terminated name of the volume, 728c2ecf20Sopenharmony_ci : : padded to 16 byte boundary. 738c2ecf20Sopenharmony_ci +---+---+---+---+ 748c2ecf20Sopenharmony_ci xx | file | 758c2ecf20Sopenharmony_ci : headers : 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciEvery multi byte value (32 bit words, I'll use the longwords term from 788c2ecf20Sopenharmony_cinow on) must be in big endian order. 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciThe first eight bytes identify the filesystem, even for the casual 818c2ecf20Sopenharmony_ciinspector. After that, in the 3rd longword, it contains the number of 828c2ecf20Sopenharmony_cibytes accessible from the start of this filesystem. The 4th longword 838c2ecf20Sopenharmony_ciis the checksum of the first 512 bytes (or the number of bytes 848c2ecf20Sopenharmony_ciaccessible, whichever is smaller). The applied algorithm is the same 858c2ecf20Sopenharmony_cias in the AFFS filesystem, namely a simple sum of the longwords 868c2ecf20Sopenharmony_ci(assuming bigendian quantities again). For details, please consult 878c2ecf20Sopenharmony_cithe source. This algorithm was chosen because although it's not quite 888c2ecf20Sopenharmony_cireliable, it does not require any tables, and it is very simple. 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ciThe following bytes are now part of the file system; each file header 918c2ecf20Sopenharmony_cimust begin on a 16 byte boundary:: 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci offset content 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci +---+---+---+---+ 968c2ecf20Sopenharmony_ci 0 | next filehdr|X| The offset of the next file header 978c2ecf20Sopenharmony_ci +---+---+---+---+ (zero if no more files) 988c2ecf20Sopenharmony_ci 4 | spec.info | Info for directories/hard links/devices 998c2ecf20Sopenharmony_ci +---+---+---+---+ 1008c2ecf20Sopenharmony_ci 8 | size | The size of this file in bytes 1018c2ecf20Sopenharmony_ci +---+---+---+---+ 1028c2ecf20Sopenharmony_ci 12 | checksum | Covering the meta data, including the file 1038c2ecf20Sopenharmony_ci +---+---+---+---+ name, and padding 1048c2ecf20Sopenharmony_ci 16 | file name | The zero terminated name of the file, 1058c2ecf20Sopenharmony_ci : : padded to 16 byte boundary 1068c2ecf20Sopenharmony_ci +---+---+---+---+ 1078c2ecf20Sopenharmony_ci xx | file data | 1088c2ecf20Sopenharmony_ci : : 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciSince the file headers begin always at a 16 byte boundary, the lowest 1118c2ecf20Sopenharmony_ci4 bits would be always zero in the next filehdr pointer. These four 1128c2ecf20Sopenharmony_cibits are used for the mode information. Bits 0..2 specify the type of 1138c2ecf20Sopenharmony_cithe file; while bit 4 shows if the file is executable or not. The 1148c2ecf20Sopenharmony_cipermissions are assumed to be world readable, if this bit is not set, 1158c2ecf20Sopenharmony_ciand world executable if it is; except the character and block devices, 1168c2ecf20Sopenharmony_cithey are never accessible for other than owner. The owner of every 1178c2ecf20Sopenharmony_cifile is user and group 0, this should never be a problem for the 1188c2ecf20Sopenharmony_ciintended use. The mapping of the 8 possible values to file types is 1198c2ecf20Sopenharmony_cithe following: 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci== =============== ============================================ 1228c2ecf20Sopenharmony_ci mapping spec.info means 1238c2ecf20Sopenharmony_ci== =============== ============================================ 1248c2ecf20Sopenharmony_ci 0 hard link link destination [file header] 1258c2ecf20Sopenharmony_ci 1 directory first file's header 1268c2ecf20Sopenharmony_ci 2 regular file unused, must be zero [MBZ] 1278c2ecf20Sopenharmony_ci 3 symbolic link unused, MBZ (file data is the link content) 1288c2ecf20Sopenharmony_ci 4 block device 16/16 bits major/minor number 1298c2ecf20Sopenharmony_ci 5 char device - " - 1308c2ecf20Sopenharmony_ci 6 socket unused, MBZ 1318c2ecf20Sopenharmony_ci 7 fifo unused, MBZ 1328c2ecf20Sopenharmony_ci== =============== ============================================ 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciNote that hard links are specifically marked in this filesystem, but 1358c2ecf20Sopenharmony_cithey will behave as you can expect (i.e. share the inode number). 1368c2ecf20Sopenharmony_ciNote also that it is your responsibility to not create hard link 1378c2ecf20Sopenharmony_ciloops, and creating all the . and .. links for directories. This is 1388c2ecf20Sopenharmony_cinormally done correctly by the genromfs program. Please refrain from 1398c2ecf20Sopenharmony_ciusing the executable bits for special purposes on the socket and fifo 1408c2ecf20Sopenharmony_cispecial files, they may have other uses in the future. Additionally, 1418c2ecf20Sopenharmony_ciplease remember that only regular files, and symlinks are supposed to 1428c2ecf20Sopenharmony_cihave a nonzero size field; they contain the number of bytes available 1438c2ecf20Sopenharmony_cidirectly after the (padded) file name. 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ciAnother thing to note is that romfs works on file headers and data 1468c2ecf20Sopenharmony_cialigned to 16 byte boundaries, but most hardware devices and the block 1478c2ecf20Sopenharmony_cidevice drivers are unable to cope with smaller than block-sized data. 1488c2ecf20Sopenharmony_ciTo overcome this limitation, the whole size of the file system must be 1498c2ecf20Sopenharmony_cipadded to an 1024 byte boundary. 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ciIf you have any problems or suggestions concerning this file system, 1528c2ecf20Sopenharmony_ciplease contact me. However, think twice before wanting me to add 1538c2ecf20Sopenharmony_cifeatures and code, because the primary and most important advantage of 1548c2ecf20Sopenharmony_cithis file system is the small code. On the other hand, don't be 1558c2ecf20Sopenharmony_cialarmed, I'm not getting that much romfs related mail. Now I can 1568c2ecf20Sopenharmony_ciunderstand why Avery wrote poems in the ARCnet docs to get some more 1578c2ecf20Sopenharmony_cifeedback. :) 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciromfs has also a mailing list, and to date, it hasn't received any 1608c2ecf20Sopenharmony_citraffic, so you are welcome to join it to discuss your ideas. :) 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ciIt's run by ezmlm, so you can subscribe to it by sending a message 1638c2ecf20Sopenharmony_cito romfs-subscribe@shadow.banki.hu, the content is irrelevant. 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ciPending issues: 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci- Permissions and owner information are pretty essential features of a 1688c2ecf20Sopenharmony_ci Un*x like system, but romfs does not provide the full possibilities. 1698c2ecf20Sopenharmony_ci I have never found this limiting, but others might. 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci- The file system is read only, so it can be very small, but in case 1728c2ecf20Sopenharmony_ci one would want to write _anything_ to a file system, he still needs 1738c2ecf20Sopenharmony_ci a writable file system, thus negating the size advantages. Possible 1748c2ecf20Sopenharmony_ci solutions: implement write access as a compile-time option, or a new, 1758c2ecf20Sopenharmony_ci similarly small writable filesystem for RAM disks. 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci- Since the files are only required to have alignment on a 16 byte 1788c2ecf20Sopenharmony_ci boundary, it is currently possibly suboptimal to read or execute files 1798c2ecf20Sopenharmony_ci from the filesystem. It might be resolved by reordering file data to 1808c2ecf20Sopenharmony_ci have most of it (i.e. except the start and the end) laying at "natural" 1818c2ecf20Sopenharmony_ci boundaries, thus it would be possible to directly map a big portion of 1828c2ecf20Sopenharmony_ci the file contents to the mm subsystem. 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci- Compression might be an useful feature, but memory is quite a 1858c2ecf20Sopenharmony_ci limiting factor in my eyes. 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci- Where it is used? 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci- Does it work on other architectures than intel and motorola? 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ciHave fun, 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ciJanos Farkas <chexum@shadow.banki.hu> 195