1e66d8631SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0 2e66d8631SMauro Carvalho Chehab 3e66d8631SMauro Carvalho Chehab====================================== 46e95d0a0SGao XiangEROFS - Enhanced Read-Only File System 5e66d8631SMauro Carvalho Chehab====================================== 6e66d8631SMauro Carvalho Chehab 7e66d8631SMauro Carvalho ChehabOverview 8e66d8631SMauro Carvalho Chehab======== 9e66d8631SMauro Carvalho Chehab 106e95d0a0SGao XiangEROFS filesystem stands for Enhanced Read-Only File System. It aims to form a 116e95d0a0SGao Xianggeneric read-only filesystem solution for various read-only use cases instead 126e95d0a0SGao Xiangof just focusing on storage space saving without considering any side effects 136e95d0a0SGao Xiangof runtime performance. 14e66d8631SMauro Carvalho Chehab 156e95d0a0SGao XiangIt is designed to meet the needs of flexibility, feature extendability and user 166e95d0a0SGao Xiangpayload friendly, etc. Apart from those, it is still kept as a simple 176e95d0a0SGao Xiangrandom-access friendly high-performance filesystem to get rid of unneeded I/O 186e95d0a0SGao Xiangamplification and memory-resident overhead compared to similar approaches. 196e95d0a0SGao Xiang 206e95d0a0SGao XiangIt is implemented to be a better choice for the following scenarios: 21e66d8631SMauro Carvalho Chehab 22e66d8631SMauro Carvalho Chehab - read-only storage media or 23e66d8631SMauro Carvalho Chehab 24e66d8631SMauro Carvalho Chehab - part of a fully trusted read-only solution, which means it needs to be 25e66d8631SMauro Carvalho Chehab immutable and bit-for-bit identical to the official golden image for 266e95d0a0SGao Xiang their releases due to security or other considerations and 27e66d8631SMauro Carvalho Chehab 28dfeab2e9SGao Xiang - hope to minimize extra storage space with guaranteed end-to-end performance 29dfeab2e9SGao Xiang by using compact layout, transparent file compression and direct access, 30dfeab2e9SGao Xiang especially for those embedded devices with limited memory and high-density 316e95d0a0SGao Xiang hosts with numerous containers. 32e66d8631SMauro Carvalho Chehab 33*2109901dSGao XiangHere are the main features of EROFS: 34e66d8631SMauro Carvalho Chehab 35e66d8631SMauro Carvalho Chehab - Little endian on-disk design; 36e66d8631SMauro Carvalho Chehab 37*2109901dSGao Xiang - Block-based distribution and file-based distribution over fscache are 38*2109901dSGao Xiang supported; 39*2109901dSGao Xiang 40*2109901dSGao Xiang - Support multiple devices to refer to external blobs, which can be used 41*2109901dSGao Xiang for container images; 42*2109901dSGao Xiang 43*2109901dSGao Xiang - 4KiB block size and 32-bit block addresses for each device, therefore 44*2109901dSGao Xiang 16TiB address space at most for now; 45e66d8631SMauro Carvalho Chehab 466e95d0a0SGao Xiang - Two inode layouts for different requirements: 47e66d8631SMauro Carvalho Chehab 486e95d0a0SGao Xiang ===================== ============ ====================================== 49e66d8631SMauro Carvalho Chehab compact (v1) extended (v2) 506e95d0a0SGao Xiang ===================== ============ ====================================== 51e66d8631SMauro Carvalho Chehab Inode metadata size 32 bytes 64 bytes 526e95d0a0SGao Xiang Max file size 4 GiB 16 EiB (also limited by max. vol size) 53e66d8631SMauro Carvalho Chehab Max uids/gids 65536 4294967296 54a1108dcdSDavid Anderson Per-inode timestamp no yes (64 + 32-bit timestamp) 55e66d8631SMauro Carvalho Chehab Max hardlinks 65536 4294967296 566e95d0a0SGao Xiang Metadata reserved 8 bytes 18 bytes 576e95d0a0SGao Xiang ===================== ============ ====================================== 586e95d0a0SGao Xiang 59*2109901dSGao Xiang - Support extended attributes as an option; 60e66d8631SMauro Carvalho Chehab 61*2109901dSGao Xiang - Support POSIX.1e ACLs by using extended attributes; 62e66d8631SMauro Carvalho Chehab 6346f2e044SGao Xiang - Support transparent data compression as an option: 646e95d0a0SGao Xiang LZ4 and MicroLZMA algorithms can be used on a per-file basis; In addition, 656e95d0a0SGao Xiang inplace decompression is also supported to avoid bounce compressed buffers 666e95d0a0SGao Xiang and page cache thrashing. 67dfeab2e9SGao Xiang 68*2109901dSGao Xiang - Support chunk-based data deduplication and rolling-hash compressed data 69*2109901dSGao Xiang deduplication; 70*2109901dSGao Xiang 71*2109901dSGao Xiang - Support tailpacking inline compared to byte-addressed unaligned metadata 72*2109901dSGao Xiang or smaller block size alternatives; 73*2109901dSGao Xiang 74*2109901dSGao Xiang - Support merging tail-end data into a special inode as fragments. 75*2109901dSGao Xiang 766e95d0a0SGao Xiang - Support direct I/O on uncompressed files to avoid double caching for loop 776e95d0a0SGao Xiang devices; 786e95d0a0SGao Xiang 796e95d0a0SGao Xiang - Support FSDAX on uncompressed images for secure containers and ramdisks in 806e95d0a0SGao Xiang order to get rid of unnecessary page cache. 816e95d0a0SGao Xiang 826e95d0a0SGao Xiang - Support file-based on-demand loading with the Fscache infrastructure. 83e66d8631SMauro Carvalho Chehab 84e66d8631SMauro Carvalho ChehabThe following git tree provides the file system user-space tools under 856e95d0a0SGao Xiangdevelopment, such as a formatting tool (mkfs.erofs), an on-disk consistency & 866e95d0a0SGao Xiangcompatibility checking tool (fsck.erofs), and a debugging tool (dump.erofs): 87e66d8631SMauro Carvalho Chehab 88e66d8631SMauro Carvalho Chehab- git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git 89e66d8631SMauro Carvalho Chehab 90e66d8631SMauro Carvalho ChehabBugs and patches are welcome, please kindly help us and send to the following 91e66d8631SMauro Carvalho Chehablinux-erofs mailing list: 92e66d8631SMauro Carvalho Chehab 93e66d8631SMauro Carvalho Chehab- linux-erofs mailing list <linux-erofs@lists.ozlabs.org> 94e66d8631SMauro Carvalho Chehab 95e66d8631SMauro Carvalho ChehabMount options 96e66d8631SMauro Carvalho Chehab============= 97e66d8631SMauro Carvalho Chehab 98e66d8631SMauro Carvalho Chehab=================== ========================================================= 99e66d8631SMauro Carvalho Chehab(no)user_xattr Setup Extended User Attributes. Note: xattr is enabled 100e66d8631SMauro Carvalho Chehab by default if CONFIG_EROFS_FS_XATTR is selected. 101e66d8631SMauro Carvalho Chehab(no)acl Setup POSIX Access Control List. Note: acl is enabled 102e66d8631SMauro Carvalho Chehab by default if CONFIG_EROFS_FS_POSIX_ACL is selected. 103e66d8631SMauro Carvalho Chehabcache_strategy=%s Select a strategy for cached decompression from now on: 104e66d8631SMauro Carvalho Chehab 105e66d8631SMauro Carvalho Chehab ========== ============================================= 106e66d8631SMauro Carvalho Chehab disabled In-place I/O decompression only; 107e66d8631SMauro Carvalho Chehab readahead Cache the last incomplete compressed physical 108e66d8631SMauro Carvalho Chehab cluster for further reading. It still does 109e66d8631SMauro Carvalho Chehab in-place I/O decompression for the rest 110e66d8631SMauro Carvalho Chehab compressed physical clusters; 111e66d8631SMauro Carvalho Chehab readaround Cache the both ends of incomplete compressed 112e66d8631SMauro Carvalho Chehab physical clusters for further reading. 113e66d8631SMauro Carvalho Chehab It still does in-place I/O decompression 114e66d8631SMauro Carvalho Chehab for the rest compressed physical clusters. 115e66d8631SMauro Carvalho Chehab ========== ============================================= 11606252e9cSGao Xiangdax={always,never} Use direct access (no page cache). See 11706252e9cSGao Xiang Documentation/filesystems/dax.rst. 11806252e9cSGao Xiangdax A legacy option which is an alias for ``dax=always``. 119dfeab2e9SGao Xiangdevice=%s Specify a path to an extra device to be used together. 1206e95d0a0SGao Xiangfsid=%s Specify a filesystem image ID for Fscache back-end. 121e66d8631SMauro Carvalho Chehab=================== ========================================================= 122e66d8631SMauro Carvalho Chehab 123168e9a76SHuang JiananSysfs Entries 124168e9a76SHuang Jianan============= 125168e9a76SHuang Jianan 126168e9a76SHuang JiananInformation about mounted erofs file systems can be found in /sys/fs/erofs. 127168e9a76SHuang JiananEach mounted filesystem will have a directory in /sys/fs/erofs based on its 128168e9a76SHuang Jianandevice name (i.e., /sys/fs/erofs/sda). 129168e9a76SHuang Jianan(see also Documentation/ABI/testing/sysfs-fs-erofs) 130168e9a76SHuang Jianan 131e66d8631SMauro Carvalho ChehabOn-disk details 132e66d8631SMauro Carvalho Chehab=============== 133e66d8631SMauro Carvalho Chehab 134e66d8631SMauro Carvalho ChehabSummary 135e66d8631SMauro Carvalho Chehab------- 136e66d8631SMauro Carvalho ChehabDifferent from other read-only file systems, an EROFS volume is designed 137e66d8631SMauro Carvalho Chehabto be as simple as possible:: 138e66d8631SMauro Carvalho Chehab 139e66d8631SMauro Carvalho Chehab |-> aligned with the block size 140e66d8631SMauro Carvalho Chehab ____________________________________________________________ 141e66d8631SMauro Carvalho Chehab | |SB| | ... | Metadata | ... | Data | Metadata | ... | Data | 142e66d8631SMauro Carvalho Chehab |_|__|_|_____|__________|_____|______|__________|_____|______| 143e66d8631SMauro Carvalho Chehab 0 +1K 144e66d8631SMauro Carvalho Chehab 145e66d8631SMauro Carvalho ChehabAll data areas should be aligned with the block size, but metadata areas 146e66d8631SMauro Carvalho Chehabmay not. All metadatas can be now observed in two different spaces (views): 147e66d8631SMauro Carvalho Chehab 148e66d8631SMauro Carvalho Chehab 1. Inode metadata space 149e66d8631SMauro Carvalho Chehab 150e66d8631SMauro Carvalho Chehab Each valid inode should be aligned with an inode slot, which is a fixed 151e66d8631SMauro Carvalho Chehab value (32 bytes) and designed to be kept in line with compact inode size. 152e66d8631SMauro Carvalho Chehab 153e66d8631SMauro Carvalho Chehab Each inode can be directly found with the following formula: 154e66d8631SMauro Carvalho Chehab inode offset = meta_blkaddr * block_size + 32 * nid 155e66d8631SMauro Carvalho Chehab 156e66d8631SMauro Carvalho Chehab :: 157e66d8631SMauro Carvalho Chehab 158e66d8631SMauro Carvalho Chehab |-> aligned with 8B 159e66d8631SMauro Carvalho Chehab |-> followed closely 160e66d8631SMauro Carvalho Chehab + meta_blkaddr blocks |-> another slot 161e66d8631SMauro Carvalho Chehab _____________________________________________________________________ 162e66d8631SMauro Carvalho Chehab | ... | inode | xattrs | extents | data inline | ... | inode ... 163e66d8631SMauro Carvalho Chehab |________|_______|(optional)|(optional)|__(optional)_|_____|__________ 164e66d8631SMauro Carvalho Chehab |-> aligned with the inode slot size 165e66d8631SMauro Carvalho Chehab . . 166e66d8631SMauro Carvalho Chehab . . 167e66d8631SMauro Carvalho Chehab . . 168e66d8631SMauro Carvalho Chehab . . 169e66d8631SMauro Carvalho Chehab . . 170e66d8631SMauro Carvalho Chehab . . 171e66d8631SMauro Carvalho Chehab .____________________________________________________|-> aligned with 4B 172e66d8631SMauro Carvalho Chehab | xattr_ibody_header | shared xattrs | inline xattrs | 173e66d8631SMauro Carvalho Chehab |____________________|_______________|_______________| 174e66d8631SMauro Carvalho Chehab |-> 12 bytes <-|->x * 4 bytes<-| . 175e66d8631SMauro Carvalho Chehab . . . 176e66d8631SMauro Carvalho Chehab . . . 177e66d8631SMauro Carvalho Chehab . . . 178e66d8631SMauro Carvalho Chehab ._______________________________.______________________. 179e66d8631SMauro Carvalho Chehab | id | id | id | id | ... | id | ent | ... | ent| ... | 180e66d8631SMauro Carvalho Chehab |____|____|____|____|______|____|_____|_____|____|_____| 181e66d8631SMauro Carvalho Chehab |-> aligned with 4B 182e66d8631SMauro Carvalho Chehab |-> aligned with 4B 183e66d8631SMauro Carvalho Chehab 184e66d8631SMauro Carvalho Chehab Inode could be 32 or 64 bytes, which can be distinguished from a common 185e66d8631SMauro Carvalho Chehab field which all inode versions have -- i_format:: 186e66d8631SMauro Carvalho Chehab 187e66d8631SMauro Carvalho Chehab __________________ __________________ 188e66d8631SMauro Carvalho Chehab | i_format | | i_format | 189e66d8631SMauro Carvalho Chehab |__________________| |__________________| 190e66d8631SMauro Carvalho Chehab | ... | | ... | 191e66d8631SMauro Carvalho Chehab | | | | 192e66d8631SMauro Carvalho Chehab |__________________| 32 bytes | | 193e66d8631SMauro Carvalho Chehab | | 194e66d8631SMauro Carvalho Chehab |__________________| 64 bytes 195e66d8631SMauro Carvalho Chehab 196e66d8631SMauro Carvalho Chehab Xattrs, extents, data inline are followed by the corresponding inode with 197e66d8631SMauro Carvalho Chehab proper alignment, and they could be optional for different data mappings. 1982a9dc7a8SGao Xiang _currently_ total 5 data layouts are supported: 199e66d8631SMauro Carvalho Chehab 200e66d8631SMauro Carvalho Chehab == ==================================================================== 201e66d8631SMauro Carvalho Chehab 0 flat file data without data inline (no extent); 202e66d8631SMauro Carvalho Chehab 1 fixed-sized output data compression (with non-compacted indexes); 203e66d8631SMauro Carvalho Chehab 2 flat file data with tail packing data inline (no extent); 2042a9dc7a8SGao Xiang 3 fixed-sized output data compression (with compacted indexes, v5.3+); 2052a9dc7a8SGao Xiang 4 chunk-based file (v5.15+). 206e66d8631SMauro Carvalho Chehab == ==================================================================== 207e66d8631SMauro Carvalho Chehab 208e66d8631SMauro Carvalho Chehab The size of the optional xattrs is indicated by i_xattr_count in inode 209e66d8631SMauro Carvalho Chehab header. Large xattrs or xattrs shared by many different files can be 210e66d8631SMauro Carvalho Chehab stored in shared xattrs metadata rather than inlined right after inode. 211e66d8631SMauro Carvalho Chehab 212e66d8631SMauro Carvalho Chehab 2. Shared xattrs metadata space 213e66d8631SMauro Carvalho Chehab 214e66d8631SMauro Carvalho Chehab Shared xattrs space is similar to the above inode space, started with 215e66d8631SMauro Carvalho Chehab a specific block indicated by xattr_blkaddr, organized one by one with 216e66d8631SMauro Carvalho Chehab proper align. 217e66d8631SMauro Carvalho Chehab 218e66d8631SMauro Carvalho Chehab Each share xattr can also be directly found by the following formula: 219e66d8631SMauro Carvalho Chehab xattr offset = xattr_blkaddr * block_size + 4 * xattr_id 220e66d8631SMauro Carvalho Chehab 221e66d8631SMauro Carvalho Chehab:: 222e66d8631SMauro Carvalho Chehab 223e66d8631SMauro Carvalho Chehab |-> aligned by 4 bytes 224e66d8631SMauro Carvalho Chehab + xattr_blkaddr blocks |-> aligned with 4 bytes 225e66d8631SMauro Carvalho Chehab _________________________________________________________________________ 226e66d8631SMauro Carvalho Chehab | ... | xattr_entry | xattr data | ... | xattr_entry | xattr data ... 227e66d8631SMauro Carvalho Chehab |________|_____________|_____________|_____|______________|_______________ 228e66d8631SMauro Carvalho Chehab 229e66d8631SMauro Carvalho ChehabDirectories 230e66d8631SMauro Carvalho Chehab----------- 231e66d8631SMauro Carvalho ChehabAll directories are now organized in a compact on-disk format. Note that 232e66d8631SMauro Carvalho Chehabeach directory block is divided into index and name areas in order to support 233e66d8631SMauro Carvalho Chehabrandom file lookup, and all directory entries are _strictly_ recorded in 234e66d8631SMauro Carvalho Chehabalphabetical order in order to support improved prefix binary search 235e66d8631SMauro Carvalho Chehabalgorithm (could refer to the related source code). 236e66d8631SMauro Carvalho Chehab 237e66d8631SMauro Carvalho Chehab:: 238e66d8631SMauro Carvalho Chehab 239e66d8631SMauro Carvalho Chehab ___________________________ 240e66d8631SMauro Carvalho Chehab / | 241e66d8631SMauro Carvalho Chehab / ______________|________________ 242e66d8631SMauro Carvalho Chehab / / | nameoff1 | nameoffN-1 243e66d8631SMauro Carvalho Chehab ____________.______________._______________v________________v__________ 244e66d8631SMauro Carvalho Chehab | dirent | dirent | ... | dirent | filename | filename | ... | filename | 245e66d8631SMauro Carvalho Chehab |___.0___|____1___|_____|___N-1__|____0_____|____1_____|_____|___N-1____| 246e66d8631SMauro Carvalho Chehab \ ^ 247e66d8631SMauro Carvalho Chehab \ | * could have 248e66d8631SMauro Carvalho Chehab \ | trailing '\0' 249e66d8631SMauro Carvalho Chehab \________________________| nameoff0 250e66d8631SMauro Carvalho Chehab Directory block 251e66d8631SMauro Carvalho Chehab 252e66d8631SMauro Carvalho ChehabNote that apart from the offset of the first filename, nameoff0 also indicates 253e66d8631SMauro Carvalho Chehabthe total number of directory entries in this block since it is no need to 254e66d8631SMauro Carvalho Chehabintroduce another on-disk field at all. 255e66d8631SMauro Carvalho Chehab 2566e95d0a0SGao XiangChunk-based files 2576e95d0a0SGao Xiang----------------- 2582a9dc7a8SGao XiangIn order to support chunk-based data deduplication, a new inode data layout has 2592a9dc7a8SGao Xiangbeen supported since Linux v5.15: Files are split in equal-sized data chunks 2602a9dc7a8SGao Xiangwith ``extents`` area of the inode metadata indicating how to get the chunk 2612a9dc7a8SGao Xiangdata: these can be simply as a 4-byte block address array or in the 8-byte 2622a9dc7a8SGao Xiangchunk index form (see struct erofs_inode_chunk_index in erofs_fs.h for more 2632a9dc7a8SGao Xiangdetails.) 2642a9dc7a8SGao Xiang 2652a9dc7a8SGao XiangBy the way, chunk-based files are all uncompressed for now. 2662a9dc7a8SGao Xiang 26746f2e044SGao XiangData compression 26846f2e044SGao Xiang---------------- 269*2109901dSGao XiangEROFS implements fixed-sized output compression which generates fixed-sized 27046f2e044SGao Xiangcompressed data blocks from variable-sized input in contrast to other existing 27146f2e044SGao Xiangfixed-sized input solutions. Relatively higher compression ratios can be gotten 27246f2e044SGao Xiangby using fixed-sized output compression since nowadays popular data compression 27346f2e044SGao Xiangalgorithms are mostly LZ77-based and such fixed-sized output approach can be 27446f2e044SGao Xiangbenefited from the historical dictionary (aka. sliding window). 27546f2e044SGao Xiang 27646f2e044SGao XiangIn details, original (uncompressed) data is turned into several variable-sized 27746f2e044SGao Xiangextents and in the meanwhile, compressed into physical clusters (pclusters). 27846f2e044SGao XiangIn order to record each variable-sized extent, logical clusters (lclusters) are 27946f2e044SGao Xiangintroduced as the basic unit of compress indexes to indicate whether a new 28046f2e044SGao Xiangextent is generated within the range (HEAD) or not (NONHEAD). Lclusters are now 28146f2e044SGao Xiangfixed in block size, as illustrated below:: 282e66d8631SMauro Carvalho Chehab 2831b55767dSGao Xiang |<- variable-sized extent ->|<- VLE ->| 284e66d8631SMauro Carvalho Chehab clusterofs clusterofs clusterofs 2851b55767dSGao Xiang | | | 2861b55767dSGao Xiang _________v_________________________________v_______________________v________ 2871b55767dSGao Xiang ... | . | | . | | . ... 2881b55767dSGao Xiang ____|____._________|______________|________.___ _|______________|__.________ 2891b55767dSGao Xiang |-> lcluster <-|-> lcluster <-|-> lcluster <-|-> lcluster <-| 29046f2e044SGao Xiang (HEAD) (NONHEAD) (HEAD) (NONHEAD) . 29146f2e044SGao Xiang . CBLKCNT . . 29246f2e044SGao Xiang . . . 29346f2e044SGao Xiang . . . 29446f2e044SGao Xiang _______._____________________________.______________._________________ 2951b55767dSGao Xiang ... | | | | ... 2961b55767dSGao Xiang _______|______________|______________|______________|_________________ 29746f2e044SGao Xiang |-> big pcluster <-|-> pcluster <-| 298e66d8631SMauro Carvalho Chehab 29946f2e044SGao XiangA physical cluster can be seen as a container of physical compressed blocks 30046f2e044SGao Xiangwhich contains compressed data. Previously, only lcluster-sized (4KB) pclusters 30146f2e044SGao Xiangwere supported. After big pcluster feature is introduced (available since 30246f2e044SGao XiangLinux v5.13), pcluster can be a multiple of lcluster size. 303e66d8631SMauro Carvalho Chehab 30446f2e044SGao XiangFor each HEAD lcluster, clusterofs is recorded to indicate where a new extent 30546f2e044SGao Xiangstarts and blkaddr is used to seek the compressed data. For each NONHEAD 30646f2e044SGao Xianglcluster, delta0 and delta1 are available instead of blkaddr to indicate the 30746f2e044SGao Xiangdistance to its HEAD lcluster and the next HEAD lcluster. A PLAIN lcluster is 30846f2e044SGao Xiangalso a HEAD lcluster except that its data is uncompressed. See the comments 30946f2e044SGao Xiangaround "struct z_erofs_vle_decompressed_index" in erofs_fs.h for more details. 31046f2e044SGao Xiang 31146f2e044SGao XiangIf big pcluster is enabled, pcluster size in lclusters needs to be recorded as 31246f2e044SGao Xiangwell. Let the delta0 of the first NONHEAD lcluster store the compressed block 31346f2e044SGao Xiangcount with a special flag as a new called CBLKCNT NONHEAD lcluster. It's easy 31446f2e044SGao Xiangto understand its delta0 is constantly 1, as illustrated below:: 31546f2e044SGao Xiang 31646f2e044SGao Xiang __________________________________________________________ 31746f2e044SGao Xiang | HEAD | NONHEAD | NONHEAD | ... | NONHEAD | HEAD | HEAD | 31846f2e044SGao Xiang |__:___|_(CBLKCNT)_|_________|_____|_________|__:___|____:_| 31946f2e044SGao Xiang |<----- a big pcluster (with CBLKCNT) ------>|<-- -->| 32046f2e044SGao Xiang a lcluster-sized pcluster (without CBLKCNT) ^ 32146f2e044SGao Xiang 32246f2e044SGao XiangIf another HEAD follows a HEAD lcluster, there is no room to record CBLKCNT, 32346f2e044SGao Xiangbut it's easy to know the size of such pcluster is 1 lcluster as well. 324*2109901dSGao Xiang 325*2109901dSGao XiangSince Linux v6.1, each pcluster can be used for multiple variable-sized extents, 326*2109901dSGao Xiangtherefore it can be used for compressed data deduplication. 327