• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. SPDX-License-Identifier: GPL-2.0
2
3======================================
4EROFS - Enhanced Read-Only File System
5======================================
6
7Overview
8========
9
10EROFS filesystem stands for Enhanced Read-Only File System.  It aims to form a
11generic read-only filesystem solution for various read-only use cases instead
12of just focusing on storage space saving without considering any side effects
13of runtime performance.
14
15It is designed to meet the needs of flexibility, feature extendability and user
16payload friendly, etc.  Apart from those, it is still kept as a simple
17random-access friendly high-performance filesystem to get rid of unneeded I/O
18amplification and memory-resident overhead compared to similar approaches.
19
20It is implemented to be a better choice for the following scenarios:
21
22 - read-only storage media or
23
24 - part of a fully trusted read-only solution, which means it needs to be
25   immutable and bit-for-bit identical to the official golden image for
26   their releases due to security or other considerations and
27
28 - hope to minimize extra storage space with guaranteed end-to-end performance
29   by using compact layout, transparent file compression and direct access,
30   especially for those embedded devices with limited memory and high-density
31   hosts with numerous containers.
32
33Here is the main features of EROFS:
34
35 - Little endian on-disk design;
36
37 - Block-based distribution and file-based distribution over fscache are
38   supported;
39
40 - Support multiple devices to refer to external blobs, which can be used
41   for container images;
42
43 - 32-bit block addresses for each device, therefore 16TiB address space at
44   most with 4KiB block size for now;
45
46 - Two inode layouts for different requirements:
47
48   =====================  ============  ======================================
49                          compact (v1)  extended (v2)
50   =====================  ============  ======================================
51   Inode metadata size    32 bytes      64 bytes
52   Max file size          4 GiB         16 EiB (also limited by max. vol size)
53   Max uids/gids          65536         4294967296
54   Per-inode timestamp    no            yes (64 + 32-bit timestamp)
55   Max hardlinks          65536         4294967296
56   Metadata reserved      8 bytes       18 bytes
57   =====================  ============  ======================================
58
59 - Metadata and data could be mixed as an option;
60
61 - Support extended attributes (xattrs) as an option;
62
63 - Support tailpacking data and xattr inline compared to byte-addressed
64   unaligned metadata or smaller block size alternatives;
65
66 - Support POSIX.1e ACLs by using xattrs;
67
68 - Support transparent data compression as an option:
69   LZ4 and MicroLZMA algorithms can be used on a per-file basis; In addition,
70   inplace decompression is also supported to avoid bounce compressed buffers
71   and page cache thrashing.
72
73 - Support direct I/O on uncompressed files to avoid double caching for loop
74   devices;
75
76 - Support FSDAX on uncompressed images for secure containers and ramdisks in
77   order to get rid of unnecessary page cache.
78
79 - Support multiple devices for multi blob container images;
80
81 - Support file-based on-demand loading with the Fscache infrastructure.
82
83The following git tree provides the file system user-space tools under
84development, such as a formatting tool (mkfs.erofs), an on-disk consistency &
85compatibility checking tool (fsck.erofs), and a debugging tool (dump.erofs):
86
87- git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git
88
89Bugs and patches are welcome, please kindly help us and send to the following
90linux-erofs mailing list:
91
92- linux-erofs mailing list   <linux-erofs@lists.ozlabs.org>
93
94Mount options
95=============
96
97===================    =========================================================
98(no)user_xattr         Setup Extended User Attributes. Note: xattr is enabled
99                       by default if CONFIG_EROFS_FS_XATTR is selected.
100(no)acl                Setup POSIX Access Control List. Note: acl is enabled
101                       by default if CONFIG_EROFS_FS_POSIX_ACL is selected.
102cache_strategy=%s      Select a strategy for cached decompression from now on:
103
104		       ==========  =============================================
105                         disabled  In-place I/O decompression only;
106                        readahead  Cache the last incomplete compressed physical
107                                   cluster for further reading. It still does
108                                   in-place I/O decompression for the rest
109                                   compressed physical clusters;
110                       readaround  Cache the both ends of incomplete compressed
111                                   physical clusters for further reading.
112                                   It still does in-place I/O decompression
113                                   for the rest compressed physical clusters.
114		       ==========  =============================================
115dax={always,never}     Use direct access (no page cache).  See
116                       Documentation/filesystems/dax.rst.
117dax                    A legacy option which is an alias for ``dax=always``.
118device=%s              Specify a path to an extra device to be used together.
119fsid=%s                Specify a filesystem image ID for Fscache back-end.
120===================    =========================================================
121
122Sysfs Entries
123=============
124
125Information about mounted erofs file systems can be found in /sys/fs/erofs.
126Each mounted filesystem will have a directory in /sys/fs/erofs based on its
127device name (i.e., /sys/fs/erofs/sda).
128(see also Documentation/ABI/testing/sysfs-fs-erofs)
129
130On-disk details
131===============
132
133Summary
134-------
135Different from other read-only file systems, an EROFS volume is designed
136to be as simple as possible::
137
138                                |-> aligned with the block size
139   ____________________________________________________________
140  | |SB| | ... | Metadata | ... | Data | Metadata | ... | Data |
141  |_|__|_|_____|__________|_____|______|__________|_____|______|
142  0 +1K
143
144All data areas should be aligned with the block size, but metadata areas
145may not. All metadatas can be now observed in two different spaces (views):
146
147 1. Inode metadata space
148
149    Each valid inode should be aligned with an inode slot, which is a fixed
150    value (32 bytes) and designed to be kept in line with compact inode size.
151
152    Each inode can be directly found with the following formula:
153         inode offset = meta_blkaddr * block_size + 32 * nid
154
155    ::
156
157                                 |-> aligned with 8B
158                                            |-> followed closely
159     + meta_blkaddr blocks                                      |-> another slot
160       _____________________________________________________________________
161     |  ...   | inode |  xattrs  | extents  | data inline | ... | inode ...
162     |________|_______|(optional)|(optional)|__(optional)_|_____|__________
163              |-> aligned with the inode slot size
164                   .                   .
165                 .                         .
166               .                              .
167             .                                    .
168           .                                         .
169         .                                              .
170       .____________________________________________________|-> aligned with 4B
171       | xattr_ibody_header | shared xattrs | inline xattrs |
172       |____________________|_______________|_______________|
173       |->    12 bytes    <-|->x * 4 bytes<-|               .
174                           .                .                 .
175                     .                      .                   .
176                .                           .                     .
177            ._______________________________.______________________.
178            | id | id | id | id |  ... | id | ent | ... | ent| ... |
179            |____|____|____|____|______|____|_____|_____|____|_____|
180                                            |-> aligned with 4B
181                                                        |-> aligned with 4B
182
183    Inode could be 32 or 64 bytes, which can be distinguished from a common
184    field which all inode versions have -- i_format::
185
186        __________________               __________________
187       |     i_format     |             |     i_format     |
188       |__________________|             |__________________|
189       |        ...       |             |        ...       |
190       |                  |             |                  |
191       |__________________| 32 bytes    |                  |
192                                        |                  |
193                                        |__________________| 64 bytes
194
195    Xattrs, extents, data inline are followed by the corresponding inode with
196    proper alignment, and they could be optional for different data mappings.
197    _currently_ total 5 data layouts are supported:
198
199    ==  ====================================================================
200     0  flat file data without data inline (no extent);
201     1  fixed-sized output data compression (with non-compacted indexes);
202     2  flat file data with tail packing data inline (no extent);
203     3  fixed-sized output data compression (with compacted indexes, v5.3+);
204     4  chunk-based file (v5.15+).
205    ==  ====================================================================
206
207    The size of the optional xattrs is indicated by i_xattr_count in inode
208    header. Large xattrs or xattrs shared by many different files can be
209    stored in shared xattrs metadata rather than inlined right after inode.
210
211 2. Shared xattrs metadata space
212
213    Shared xattrs space is similar to the above inode space, started with
214    a specific block indicated by xattr_blkaddr, organized one by one with
215    proper align.
216
217    Each share xattr can also be directly found by the following formula:
218         xattr offset = xattr_blkaddr * block_size + 4 * xattr_id
219
220::
221
222                           |-> aligned by  4 bytes
223    + xattr_blkaddr blocks                     |-> aligned with 4 bytes
224     _________________________________________________________________________
225    |  ...   | xattr_entry |  xattr data | ... |  xattr_entry | xattr data  ...
226    |________|_____________|_____________|_____|______________|_______________
227
228Directories
229-----------
230All directories are now organized in a compact on-disk format. Note that
231each directory block is divided into index and name areas in order to support
232random file lookup, and all directory entries are _strictly_ recorded in
233alphabetical order in order to support improved prefix binary search
234algorithm (could refer to the related source code).
235
236::
237
238                  ___________________________
239                 /                           |
240                /              ______________|________________
241               /              /              | nameoff1       | nameoffN-1
242  ____________.______________._______________v________________v__________
243 | dirent | dirent | ... | dirent | filename | filename | ... | filename |
244 |___.0___|____1___|_____|___N-1__|____0_____|____1_____|_____|___N-1____|
245      \                           ^
246       \                          |                           * could have
247        \                         |                             trailing '\0'
248         \________________________| nameoff0
249                             Directory block
250
251Note that apart from the offset of the first filename, nameoff0 also indicates
252the total number of directory entries in this block since it is no need to
253introduce another on-disk field at all.
254
255Chunk-based files
256-----------------
257In order to support chunk-based data deduplication, a new inode data layout has
258been supported since Linux v5.15: Files are split in equal-sized data chunks
259with ``extents`` area of the inode metadata indicating how to get the chunk
260data: these can be simply as a 4-byte block address array or in the 8-byte
261chunk index form (see struct erofs_inode_chunk_index in erofs_fs.h for more
262details.)
263
264By the way, chunk-based files are all uncompressed for now.
265
266Data compression
267----------------
268EROFS implements LZ4 fixed-sized output compression which generates fixed-sized
269compressed data blocks from variable-sized input in contrast to other existing
270fixed-sized input solutions. Relatively higher compression ratios can be gotten
271by using fixed-sized output compression since nowadays popular data compression
272algorithms are mostly LZ77-based and such fixed-sized output approach can be
273benefited from the historical dictionary (aka. sliding window).
274
275In details, original (uncompressed) data is turned into several variable-sized
276extents and in the meanwhile, compressed into physical clusters (pclusters).
277In order to record each variable-sized extent, logical clusters (lclusters) are
278introduced as the basic unit of compress indexes to indicate whether a new
279extent is generated within the range (HEAD) or not (NONHEAD). Lclusters are now
280fixed in block size, as illustrated below::
281
282          |<-    variable-sized extent    ->|<-       VLE         ->|
283        clusterofs                        clusterofs              clusterofs
284          |                                 |                       |
285 _________v_________________________________v_______________________v________
286 ... |    .         |              |        .     |              |  .   ...
287 ____|____._________|______________|________.___ _|______________|__.________
288     |-> lcluster <-|-> lcluster <-|-> lcluster <-|-> lcluster <-|
289          (HEAD)        (NONHEAD)       (HEAD)        (NONHEAD)    .
290           .             CBLKCNT            .                    .
291            .                               .                  .
292             .                              .                .
293       _______._____________________________.______________._________________
294          ... |              |              |              | ...
295       _______|______________|______________|______________|_________________
296              |->      big pcluster       <-|-> pcluster <-|
297
298A physical cluster can be seen as a container of physical compressed blocks
299which contains compressed data. Previously, only lcluster-sized (4KB) pclusters
300were supported. After big pcluster feature is introduced (available since
301Linux v5.13), pcluster can be a multiple of lcluster size.
302
303For each HEAD lcluster, clusterofs is recorded to indicate where a new extent
304starts and blkaddr is used to seek the compressed data. For each NONHEAD
305lcluster, delta0 and delta1 are available instead of blkaddr to indicate the
306distance to its HEAD lcluster and the next HEAD lcluster. A PLAIN lcluster is
307also a HEAD lcluster except that its data is uncompressed. See the comments
308around "struct z_erofs_vle_decompressed_index" in erofs_fs.h for more details.
309
310If big pcluster is enabled, pcluster size in lclusters needs to be recorded as
311well. Let the delta0 of the first NONHEAD lcluster store the compressed block
312count with a special flag as a new called CBLKCNT NONHEAD lcluster. It's easy
313to understand its delta0 is constantly 1, as illustrated below::
314
315   __________________________________________________________
316  | HEAD |  NONHEAD  | NONHEAD | ... | NONHEAD | HEAD | HEAD |
317  |__:___|_(CBLKCNT)_|_________|_____|_________|__:___|____:_|
318     |<----- a big pcluster (with CBLKCNT) ------>|<--  -->|
319           a lcluster-sized pcluster (without CBLKCNT) ^
320
321If another HEAD follows a HEAD lcluster, there is no room to record CBLKCNT,
322but it's easy to know the size of such pcluster is 1 lcluster as well.
323