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