xref: /OK3568_Linux_fs/kernel/Documentation/filesystems/romfs.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun=======================
4*4882a593SmuzhiyunROMFS - ROM File System
5*4882a593Smuzhiyun=======================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThis is a quite dumb, read only filesystem, mainly for initial RAM
8*4882a593Smuzhiyundisks of installation disks.  It has grown up by the need of having
9*4882a593Smuzhiyunmodules linked at boot time.  Using this filesystem, you get a very
10*4882a593Smuzhiyunsimilar feature, and even the possibility of a small kernel, with a
11*4882a593Smuzhiyunfile system which doesn't take up useful memory from the router
12*4882a593Smuzhiyunfunctions in the basement of your office.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunFor comparison, both the older minix and xiafs (the latter is now
15*4882a593Smuzhiyundefunct) filesystems, compiled as module need more than 20000 bytes,
16*4882a593Smuzhiyunwhile romfs is less than a page, about 4000 bytes (assuming i586
17*4882a593Smuzhiyuncode).  Under the same conditions, the msdos filesystem would need
18*4882a593Smuzhiyunabout 30K (and does not support device nodes or symlinks), while the
19*4882a593Smuzhiyunnfs module with nfsroot is about 57K.  Furthermore, as a bit unfair
20*4882a593Smuzhiyuncomparison, an actual rescue disk used up 3202 blocks with ext2, while
21*4882a593Smuzhiyunwith romfs, it needed 3079 blocks.
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunTo create such a file system, you'll need a user program named
24*4882a593Smuzhiyungenromfs. It is available on http://romfs.sourceforge.net/
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunAs the name suggests, romfs could be also used (space-efficiently) on
27*4882a593Smuzhiyunvarious read-only media, like (E)EPROM disks if someone will have the
28*4882a593Smuzhiyunmotivation.. :)
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunHowever, the main purpose of romfs is to have a very small kernel,
31*4882a593Smuzhiyunwhich has only this filesystem linked in, and then can load any module
32*4882a593Smuzhiyunlater, with the current module utilities.  It can also be used to run
33*4882a593Smuzhiyunsome program to decide if you need SCSI devices, and even IDE or
34*4882a593Smuzhiyunfloppy drives can be loaded later if you use the "initrd"--initial
35*4882a593SmuzhiyunRAM disk--feature of the kernel.  This would not be really news
36*4882a593Smuzhiyunflash, but with romfs, you can even spare off your ext2 or minix or
37*4882a593Smuzhiyunmaybe even affs filesystem until you really know that you need it.
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunFor example, a distribution boot disk can contain only the cd disk
40*4882a593Smuzhiyundrivers (and possibly the SCSI drivers), and the ISO 9660 filesystem
41*4882a593Smuzhiyunmodule.  The kernel can be small enough, since it doesn't have other
42*4882a593Smuzhiyunfilesystems, like the quite large ext2fs module, which can then be
43*4882a593Smuzhiyunloaded off the CD at a later stage of the installation.  Another use
44*4882a593Smuzhiyunwould be for a recovery disk, when you are reinstalling a workstation
45*4882a593Smuzhiyunfrom the network, and you will have all the tools/modules available
46*4882a593Smuzhiyunfrom a nearby server, so you don't want to carry two disks for this
47*4882a593Smuzhiyunpurpose, just because it won't fit into ext2.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyunromfs operates on block devices as you can expect, and the underlying
50*4882a593Smuzhiyunstructure is very simple.  Every accessible structure begins on 16
51*4882a593Smuzhiyunbyte boundaries for fast access.  The minimum space a file will take
52*4882a593Smuzhiyunis 32 bytes (this is an empty file, with a less than 16 character
53*4882a593Smuzhiyunname).  The maximum overhead for any non-empty file is the header, and
54*4882a593Smuzhiyunthe 16 byte padding for the name and the contents, also 16+14+15 = 45
55*4882a593Smuzhiyunbytes.  This is quite rare however, since most file names are longer
56*4882a593Smuzhiyunthan 3 bytes, and shorter than 15 bytes.
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunThe layout of the filesystem is the following::
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun offset	    content
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun	+---+---+---+---+
63*4882a593Smuzhiyun  0	| - | r | o | m |  \
64*4882a593Smuzhiyun	+---+---+---+---+	The ASCII representation of those bytes
65*4882a593Smuzhiyun  4	| 1 | f | s | - |  /	(i.e. "-rom1fs-")
66*4882a593Smuzhiyun	+---+---+---+---+
67*4882a593Smuzhiyun  8	|   full size	|	The number of accessible bytes in this fs.
68*4882a593Smuzhiyun	+---+---+---+---+
69*4882a593Smuzhiyun 12	|    checksum	|	The checksum of the FIRST 512 BYTES.
70*4882a593Smuzhiyun	+---+---+---+---+
71*4882a593Smuzhiyun 16	| volume name	|	The zero terminated name of the volume,
72*4882a593Smuzhiyun	:               :	padded to 16 byte boundary.
73*4882a593Smuzhiyun	+---+---+---+---+
74*4882a593Smuzhiyun xx	|     file	|
75*4882a593Smuzhiyun	:    headers	:
76*4882a593Smuzhiyun
77*4882a593SmuzhiyunEvery multi byte value (32 bit words, I'll use the longwords term from
78*4882a593Smuzhiyunnow on) must be in big endian order.
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunThe first eight bytes identify the filesystem, even for the casual
81*4882a593Smuzhiyuninspector.  After that, in the 3rd longword, it contains the number of
82*4882a593Smuzhiyunbytes accessible from the start of this filesystem.  The 4th longword
83*4882a593Smuzhiyunis the checksum of the first 512 bytes (or the number of bytes
84*4882a593Smuzhiyunaccessible, whichever is smaller).  The applied algorithm is the same
85*4882a593Smuzhiyunas in the AFFS filesystem, namely a simple sum of the longwords
86*4882a593Smuzhiyun(assuming bigendian quantities again).  For details, please consult
87*4882a593Smuzhiyunthe source.  This algorithm was chosen because although it's not quite
88*4882a593Smuzhiyunreliable, it does not require any tables, and it is very simple.
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunThe following bytes are now part of the file system; each file header
91*4882a593Smuzhiyunmust begin on a 16 byte boundary::
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun offset	    content
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun     	+---+---+---+---+
96*4882a593Smuzhiyun  0	| next filehdr|X|	The offset of the next file header
97*4882a593Smuzhiyun	+---+---+---+---+	  (zero if no more files)
98*4882a593Smuzhiyun  4	|   spec.info	|	Info for directories/hard links/devices
99*4882a593Smuzhiyun	+---+---+---+---+
100*4882a593Smuzhiyun  8	|     size      |	The size of this file in bytes
101*4882a593Smuzhiyun	+---+---+---+---+
102*4882a593Smuzhiyun 12	|   checksum	|	Covering the meta data, including the file
103*4882a593Smuzhiyun	+---+---+---+---+	  name, and padding
104*4882a593Smuzhiyun 16	| file name     |	The zero terminated name of the file,
105*4882a593Smuzhiyun	:               :	padded to 16 byte boundary
106*4882a593Smuzhiyun	+---+---+---+---+
107*4882a593Smuzhiyun xx	| file data	|
108*4882a593Smuzhiyun	:		:
109*4882a593Smuzhiyun
110*4882a593SmuzhiyunSince the file headers begin always at a 16 byte boundary, the lowest
111*4882a593Smuzhiyun4 bits would be always zero in the next filehdr pointer.  These four
112*4882a593Smuzhiyunbits are used for the mode information.  Bits 0..2 specify the type of
113*4882a593Smuzhiyunthe file; while bit 4 shows if the file is executable or not.  The
114*4882a593Smuzhiyunpermissions are assumed to be world readable, if this bit is not set,
115*4882a593Smuzhiyunand world executable if it is; except the character and block devices,
116*4882a593Smuzhiyunthey are never accessible for other than owner.  The owner of every
117*4882a593Smuzhiyunfile is user and group 0, this should never be a problem for the
118*4882a593Smuzhiyunintended use.  The mapping of the 8 possible values to file types is
119*4882a593Smuzhiyunthe following:
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun==	=============== ============================================
122*4882a593Smuzhiyun	  mapping		spec.info means
123*4882a593Smuzhiyun==	=============== ============================================
124*4882a593Smuzhiyun 0	hard link	link destination [file header]
125*4882a593Smuzhiyun 1	directory	first file's header
126*4882a593Smuzhiyun 2	regular file	unused, must be zero [MBZ]
127*4882a593Smuzhiyun 3	symbolic link	unused, MBZ (file data is the link content)
128*4882a593Smuzhiyun 4	block device	16/16 bits major/minor number
129*4882a593Smuzhiyun 5	char device		    - " -
130*4882a593Smuzhiyun 6	socket		unused, MBZ
131*4882a593Smuzhiyun 7	fifo		unused, MBZ
132*4882a593Smuzhiyun==	=============== ============================================
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunNote that hard links are specifically marked in this filesystem, but
135*4882a593Smuzhiyunthey will behave as you can expect (i.e. share the inode number).
136*4882a593SmuzhiyunNote also that it is your responsibility to not create hard link
137*4882a593Smuzhiyunloops, and creating all the . and .. links for directories.  This is
138*4882a593Smuzhiyunnormally done correctly by the genromfs program.  Please refrain from
139*4882a593Smuzhiyunusing the executable bits for special purposes on the socket and fifo
140*4882a593Smuzhiyunspecial files, they may have other uses in the future.  Additionally,
141*4882a593Smuzhiyunplease remember that only regular files, and symlinks are supposed to
142*4882a593Smuzhiyunhave a nonzero size field; they contain the number of bytes available
143*4882a593Smuzhiyundirectly after the (padded) file name.
144*4882a593Smuzhiyun
145*4882a593SmuzhiyunAnother thing to note is that romfs works on file headers and data
146*4882a593Smuzhiyunaligned to 16 byte boundaries, but most hardware devices and the block
147*4882a593Smuzhiyundevice drivers are unable to cope with smaller than block-sized data.
148*4882a593SmuzhiyunTo overcome this limitation, the whole size of the file system must be
149*4882a593Smuzhiyunpadded to an 1024 byte boundary.
150*4882a593Smuzhiyun
151*4882a593SmuzhiyunIf you have any problems or suggestions concerning this file system,
152*4882a593Smuzhiyunplease contact me.  However, think twice before wanting me to add
153*4882a593Smuzhiyunfeatures and code, because the primary and most important advantage of
154*4882a593Smuzhiyunthis file system is the small code.  On the other hand, don't be
155*4882a593Smuzhiyunalarmed, I'm not getting that much romfs related mail.  Now I can
156*4882a593Smuzhiyununderstand why Avery wrote poems in the ARCnet docs to get some more
157*4882a593Smuzhiyunfeedback. :)
158*4882a593Smuzhiyun
159*4882a593Smuzhiyunromfs has also a mailing list, and to date, it hasn't received any
160*4882a593Smuzhiyuntraffic, so you are welcome to join it to discuss your ideas. :)
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunIt's run by ezmlm, so you can subscribe to it by sending a message
163*4882a593Smuzhiyunto romfs-subscribe@shadow.banki.hu, the content is irrelevant.
164*4882a593Smuzhiyun
165*4882a593SmuzhiyunPending issues:
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun- Permissions and owner information are pretty essential features of a
168*4882a593Smuzhiyun  Un*x like system, but romfs does not provide the full possibilities.
169*4882a593Smuzhiyun  I have never found this limiting, but others might.
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun- The file system is read only, so it can be very small, but in case
172*4882a593Smuzhiyun  one would want to write _anything_ to a file system, he still needs
173*4882a593Smuzhiyun  a writable file system, thus negating the size advantages.  Possible
174*4882a593Smuzhiyun  solutions: implement write access as a compile-time option, or a new,
175*4882a593Smuzhiyun  similarly small writable filesystem for RAM disks.
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun- Since the files are only required to have alignment on a 16 byte
178*4882a593Smuzhiyun  boundary, it is currently possibly suboptimal to read or execute files
179*4882a593Smuzhiyun  from the filesystem.  It might be resolved by reordering file data to
180*4882a593Smuzhiyun  have most of it (i.e. except the start and the end) laying at "natural"
181*4882a593Smuzhiyun  boundaries, thus it would be possible to directly map a big portion of
182*4882a593Smuzhiyun  the file contents to the mm subsystem.
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun- Compression might be an useful feature, but memory is quite a
185*4882a593Smuzhiyun  limiting factor in my eyes.
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun- Where it is used?
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun- Does it work on other architectures than intel and motorola?
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun
192*4882a593SmuzhiyunHave fun,
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunJanos Farkas <chexum@shadow.banki.hu>
195