romfs.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ROMFS - ROM FILE SYSTEM
  2. This is a quite dumb, read only filesystem, mainly for initial RAM
  3. disks of installation disks. It has grown up by the need of having
  4. modules linked at boot time. Using this filesystem, you get a very
  5. similar feature, and even the possibility of a small kernel, with a
  6. file system which doesn't take up useful memory from the router
  7. functions in the basement of your office.
  8. For comparison, both the older minix and xiafs (the latter is now
  9. defunct) filesystems, compiled as module need more than 20000 bytes,
  10. while romfs is less than a page, about 4000 bytes (assuming i586
  11. code). Under the same conditions, the msdos filesystem would need
  12. about 30K (and does not support device nodes or symlinks), while the
  13. nfs module with nfsroot is about 57K. Furthermore, as a bit unfair
  14. comparison, an actual rescue disk used up 3202 blocks with ext2, while
  15. with romfs, it needed 3079 blocks.
  16. To create such a file system, you'll need a user program named
  17. genromfs. It is available on http://romfs.sourceforge.net/
  18. As the name suggests, romfs could be also used (space-efficiently) on
  19. various read-only media, like (E)EPROM disks if someone will have the
  20. motivation.. :)
  21. However, the main purpose of romfs is to have a very small kernel,
  22. which has only this filesystem linked in, and then can load any module
  23. later, with the current module utilities. It can also be used to run
  24. some program to decide if you need SCSI devices, and even IDE or
  25. floppy drives can be loaded later if you use the "initrd"--initial
  26. RAM disk--feature of the kernel. This would not be really news
  27. flash, but with romfs, you can even spare off your ext2 or minix or
  28. maybe even affs filesystem until you really know that you need it.
  29. For example, a distribution boot disk can contain only the cd disk
  30. drivers (and possibly the SCSI drivers), and the ISO 9660 filesystem
  31. module. The kernel can be small enough, since it doesn't have other
  32. filesystems, like the quite large ext2fs module, which can then be
  33. loaded off the CD at a later stage of the installation. Another use
  34. would be for a recovery disk, when you are reinstalling a workstation
  35. from the network, and you will have all the tools/modules available
  36. from a nearby server, so you don't want to carry two disks for this
  37. purpose, just because it won't fit into ext2.
  38. romfs operates on block devices as you can expect, and the underlying
  39. structure is very simple. Every accessible structure begins on 16
  40. byte boundaries for fast access. The minimum space a file will take
  41. is 32 bytes (this is an empty file, with a less than 16 character
  42. name). The maximum overhead for any non-empty file is the header, and
  43. the 16 byte padding for the name and the contents, also 16+14+15 = 45
  44. bytes. This is quite rare however, since most file names are longer
  45. than 3 bytes, and shorter than 15 bytes.
  46. The layout of the filesystem is the following:
  47. offset content
  48. +---+---+---+---+
  49. 0 | - | r | o | m | \
  50. +---+---+---+---+ The ASCII representation of those bytes
  51. 4 | 1 | f | s | - | / (i.e. "-rom1fs-")
  52. +---+---+---+---+
  53. 8 | full size | The number of accessible bytes in this fs.
  54. +---+---+---+---+
  55. 12 | checksum | The checksum of the FIRST 512 BYTES.
  56. +---+---+---+---+
  57. 16 | volume name | The zero terminated name of the volume,
  58. : : padded to 16 byte boundary.
  59. +---+---+---+---+
  60. xx | file |
  61. : headers :
  62. Every multi byte value (32 bit words, I'll use the longwords term from
  63. now on) must be in big endian order.
  64. The first eight bytes identify the filesystem, even for the casual
  65. inspector. After that, in the 3rd longword, it contains the number of
  66. bytes accessible from the start of this filesystem. The 4th longword
  67. is the checksum of the first 512 bytes (or the number of bytes
  68. accessible, whichever is smaller). The applied algorithm is the same
  69. as in the AFFS filesystem, namely a simple sum of the longwords
  70. (assuming bigendian quantities again). For details, please consult
  71. the source. This algorithm was chosen because although it's not quite
  72. reliable, it does not require any tables, and it is very simple.
  73. The following bytes are now part of the file system; each file header
  74. must begin on a 16 byte boundary.
  75. offset content
  76. +---+---+---+---+
  77. 0 | next filehdr|X| The offset of the next file header
  78. +---+---+---+---+ (zero if no more files)
  79. 4 | spec.info | Info for directories/hard links/devices
  80. +---+---+---+---+
  81. 8 | size | The size of this file in bytes
  82. +---+---+---+---+
  83. 12 | checksum | Covering the meta data, including the file
  84. +---+---+---+---+ name, and padding
  85. 16 | file name | The zero terminated name of the file,
  86. : : padded to 16 byte boundary
  87. +---+---+---+---+
  88. xx | file data |
  89. : :
  90. Since the file headers begin always at a 16 byte boundary, the lowest
  91. 4 bits would be always zero in the next filehdr pointer. These four
  92. bits are used for the mode information. Bits 0..2 specify the type of
  93. the file; while bit 4 shows if the file is executable or not. The
  94. permissions are assumed to be world readable, if this bit is not set,
  95. and world executable if it is; except the character and block devices,
  96. they are never accessible for other than owner. The owner of every
  97. file is user and group 0, this should never be a problem for the
  98. intended use. The mapping of the 8 possible values to file types is
  99. the following:
  100. mapping spec.info means
  101. 0 hard link link destination [file header]
  102. 1 directory first file's header
  103. 2 regular file unused, must be zero [MBZ]
  104. 3 symbolic link unused, MBZ (file data is the link content)
  105. 4 block device 16/16 bits major/minor number
  106. 5 char device - " -
  107. 6 socket unused, MBZ
  108. 7 fifo unused, MBZ
  109. Note that hard links are specifically marked in this filesystem, but
  110. they will behave as you can expect (i.e. share the inode number).
  111. Note also that it is your responsibility to not create hard link
  112. loops, and creating all the . and .. links for directories. This is
  113. normally done correctly by the genromfs program. Please refrain from
  114. using the executable bits for special purposes on the socket and fifo
  115. special files, they may have other uses in the future. Additionally,
  116. please remember that only regular files, and symlinks are supposed to
  117. have a nonzero size field; they contain the number of bytes available
  118. directly after the (padded) file name.
  119. Another thing to note is that romfs works on file headers and data
  120. aligned to 16 byte boundaries, but most hardware devices and the block
  121. device drivers are unable to cope with smaller than block-sized data.
  122. To overcome this limitation, the whole size of the file system must be
  123. padded to an 1024 byte boundary.
  124. If you have any problems or suggestions concerning this file system,
  125. please contact me. However, think twice before wanting me to add
  126. features and code, because the primary and most important advantage of
  127. this file system is the small code. On the other hand, don't be
  128. alarmed, I'm not getting that much romfs related mail. Now I can
  129. understand why Avery wrote poems in the ARCnet docs to get some more
  130. feedback. :)
  131. romfs has also a mailing list, and to date, it hasn't received any
  132. traffic, so you are welcome to join it to discuss your ideas. :)
  133. It's run by ezmlm, so you can subscribe to it by sending a message
  134. to romfs-subscribe@shadow.banki.hu, the content is irrelevant.
  135. Pending issues:
  136. - Permissions and owner information are pretty essential features of a
  137. Un*x like system, but romfs does not provide the full possibilities.
  138. I have never found this limiting, but others might.
  139. - The file system is read only, so it can be very small, but in case
  140. one would want to write _anything_ to a file system, he still needs
  141. a writable file system, thus negating the size advantages. Possible
  142. solutions: implement write access as a compile-time option, or a new,
  143. similarly small writable filesystem for RAM disks.
  144. - Since the files are only required to have alignment on a 16 byte
  145. boundary, it is currently possibly suboptimal to read or execute files
  146. from the filesystem. It might be resolved by reordering file data to
  147. have most of it (i.e. except the start and the end) laying at "natural"
  148. boundaries, thus it would be possible to directly map a big portion of
  149. the file contents to the mm subsystem.
  150. - Compression might be an useful feature, but memory is quite a
  151. limiting factor in my eyes.
  152. - Where it is used?
  153. - Does it work on other architectures than intel and motorola?
  154. Have fun,
  155. Janos Farkas <chexum@shadow.banki.hu>