Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 
0004 ==============================
0005 The Second Extended Filesystem
0006 ==============================
0007 
0008 ext2 was originally released in January 1993.  Written by R\'emy Card,
0009 Theodore Ts'o and Stephen Tweedie, it was a major rewrite of the
0010 Extended Filesystem.  It is currently still (April 2001) the predominant
0011 filesystem in use by Linux.  There are also implementations available
0012 for NetBSD, FreeBSD, the GNU HURD, Windows 95/98/NT, OS/2 and RISC OS.
0013 
0014 Options
0015 =======
0016 
0017 Most defaults are determined by the filesystem superblock, and can be
0018 set using tune2fs(8). Kernel-determined defaults are indicated by (*).
0019 
0020 ====================    ===     ================================================
0021 bsddf                   (*)     Makes ``df`` act like BSD.
0022 minixdf                         Makes ``df`` act like Minix.
0023 
0024 check=none, nocheck     (*)     Don't do extra checking of bitmaps on mount
0025                                 (check=normal and check=strict options removed)
0026 
0027 dax                             Use direct access (no page cache).  See
0028                                 Documentation/filesystems/dax.rst.
0029 
0030 debug                           Extra debugging information is sent to the
0031                                 kernel syslog.  Useful for developers.
0032 
0033 errors=continue                 Keep going on a filesystem error.
0034 errors=remount-ro               Remount the filesystem read-only on an error.
0035 errors=panic                    Panic and halt the machine if an error occurs.
0036 
0037 grpid, bsdgroups                Give objects the same group ID as their parent.
0038 nogrpid, sysvgroups             New objects have the group ID of their creator.
0039 
0040 nouid32                         Use 16-bit UIDs and GIDs.
0041 
0042 oldalloc                        Enable the old block allocator. Orlov should
0043                                 have better performance, we'd like to get some
0044                                 feedback if it's the contrary for you.
0045 orlov                   (*)     Use the Orlov block allocator.
0046                                 (See http://lwn.net/Articles/14633/ and
0047                                 http://lwn.net/Articles/14446/.)
0048 
0049 resuid=n                        The user ID which may use the reserved blocks.
0050 resgid=n                        The group ID which may use the reserved blocks.
0051 
0052 sb=n                            Use alternate superblock at this location.
0053 
0054 user_xattr                      Enable "user." POSIX Extended Attributes
0055                                 (requires CONFIG_EXT2_FS_XATTR).
0056 nouser_xattr                    Don't support "user." extended attributes.
0057 
0058 acl                             Enable POSIX Access Control Lists support
0059                                 (requires CONFIG_EXT2_FS_POSIX_ACL).
0060 noacl                           Don't support POSIX ACLs.
0061 
0062 quota, usrquota                 Enable user disk quota support
0063                                 (requires CONFIG_QUOTA).
0064 
0065 grpquota                        Enable group disk quota support
0066                                 (requires CONFIG_QUOTA).
0067 ====================    ===     ================================================
0068 
0069 noquota option ls silently ignored by ext2.
0070 
0071 
0072 Specification
0073 =============
0074 
0075 ext2 shares many properties with traditional Unix filesystems.  It has
0076 the concepts of blocks, inodes and directories.  It has space in the
0077 specification for Access Control Lists (ACLs), fragments, undeletion and
0078 compression though these are not yet implemented (some are available as
0079 separate patches).  There is also a versioning mechanism to allow new
0080 features (such as journalling) to be added in a maximally compatible
0081 manner.
0082 
0083 Blocks
0084 ------
0085 
0086 The space in the device or file is split up into blocks.  These are
0087 a fixed size, of 1024, 2048 or 4096 bytes (8192 bytes on Alpha systems),
0088 which is decided when the filesystem is created.  Smaller blocks mean
0089 less wasted space per file, but require slightly more accounting overhead,
0090 and also impose other limits on the size of files and the filesystem.
0091 
0092 Block Groups
0093 ------------
0094 
0095 Blocks are clustered into block groups in order to reduce fragmentation
0096 and minimise the amount of head seeking when reading a large amount
0097 of consecutive data.  Information about each block group is kept in a
0098 descriptor table stored in the block(s) immediately after the superblock.
0099 Two blocks near the start of each group are reserved for the block usage
0100 bitmap and the inode usage bitmap which show which blocks and inodes
0101 are in use.  Since each bitmap is limited to a single block, this means
0102 that the maximum size of a block group is 8 times the size of a block.
0103 
0104 The block(s) following the bitmaps in each block group are designated
0105 as the inode table for that block group and the remainder are the data
0106 blocks.  The block allocation algorithm attempts to allocate data blocks
0107 in the same block group as the inode which contains them.
0108 
0109 The Superblock
0110 --------------
0111 
0112 The superblock contains all the information about the configuration of
0113 the filing system.  The primary copy of the superblock is stored at an
0114 offset of 1024 bytes from the start of the device, and it is essential
0115 to mounting the filesystem.  Since it is so important, backup copies of
0116 the superblock are stored in block groups throughout the filesystem.
0117 The first version of ext2 (revision 0) stores a copy at the start of
0118 every block group, along with backups of the group descriptor block(s).
0119 Because this can consume a considerable amount of space for large
0120 filesystems, later revisions can optionally reduce the number of backup
0121 copies by only putting backups in specific groups (this is the sparse
0122 superblock feature).  The groups chosen are 0, 1 and powers of 3, 5 and 7.
0123 
0124 The information in the superblock contains fields such as the total
0125 number of inodes and blocks in the filesystem and how many are free,
0126 how many inodes and blocks are in each block group, when the filesystem
0127 was mounted (and if it was cleanly unmounted), when it was modified,
0128 what version of the filesystem it is (see the Revisions section below)
0129 and which OS created it.
0130 
0131 If the filesystem is revision 1 or higher, then there are extra fields,
0132 such as a volume name, a unique identification number, the inode size,
0133 and space for optional filesystem features to store configuration info.
0134 
0135 All fields in the superblock (as in all other ext2 structures) are stored
0136 on the disc in little endian format, so a filesystem is portable between
0137 machines without having to know what machine it was created on.
0138 
0139 Inodes
0140 ------
0141 
0142 The inode (index node) is a fundamental concept in the ext2 filesystem.
0143 Each object in the filesystem is represented by an inode.  The inode
0144 structure contains pointers to the filesystem blocks which contain the
0145 data held in the object and all of the metadata about an object except
0146 its name.  The metadata about an object includes the permissions, owner,
0147 group, flags, size, number of blocks used, access time, change time,
0148 modification time, deletion time, number of links, fragments, version
0149 (for NFS) and extended attributes (EAs) and/or Access Control Lists (ACLs).
0150 
0151 There are some reserved fields which are currently unused in the inode
0152 structure and several which are overloaded.  One field is reserved for the
0153 directory ACL if the inode is a directory and alternately for the top 32
0154 bits of the file size if the inode is a regular file (allowing file sizes
0155 larger than 2GB).  The translator field is unused under Linux, but is used
0156 by the HURD to reference the inode of a program which will be used to
0157 interpret this object.  Most of the remaining reserved fields have been
0158 used up for both Linux and the HURD for larger owner and group fields,
0159 The HURD also has a larger mode field so it uses another of the remaining
0160 fields to store the extra more bits.
0161 
0162 There are pointers to the first 12 blocks which contain the file's data
0163 in the inode.  There is a pointer to an indirect block (which contains
0164 pointers to the next set of blocks), a pointer to a doubly-indirect
0165 block (which contains pointers to indirect blocks) and a pointer to a
0166 trebly-indirect block (which contains pointers to doubly-indirect blocks).
0167 
0168 The flags field contains some ext2-specific flags which aren't catered
0169 for by the standard chmod flags.  These flags can be listed with lsattr
0170 and changed with the chattr command, and allow specific filesystem
0171 behaviour on a per-file basis.  There are flags for secure deletion,
0172 undeletable, compression, synchronous updates, immutability, append-only,
0173 dumpable, no-atime, indexed directories, and data-journaling.  Not all
0174 of these are supported yet.
0175 
0176 Directories
0177 -----------
0178 
0179 A directory is a filesystem object and has an inode just like a file.
0180 It is a specially formatted file containing records which associate
0181 each name with an inode number.  Later revisions of the filesystem also
0182 encode the type of the object (file, directory, symlink, device, fifo,
0183 socket) to avoid the need to check the inode itself for this information
0184 (support for taking advantage of this feature does not yet exist in
0185 Glibc 2.2).
0186 
0187 The inode allocation code tries to assign inodes which are in the same
0188 block group as the directory in which they are first created.
0189 
0190 The current implementation of ext2 uses a singly-linked list to store
0191 the filenames in the directory; a pending enhancement uses hashing of the
0192 filenames to allow lookup without the need to scan the entire directory.
0193 
0194 The current implementation never removes empty directory blocks once they
0195 have been allocated to hold more files.
0196 
0197 Special files
0198 -------------
0199 
0200 Symbolic links are also filesystem objects with inodes.  They deserve
0201 special mention because the data for them is stored within the inode
0202 itself if the symlink is less than 60 bytes long.  It uses the fields
0203 which would normally be used to store the pointers to data blocks.
0204 This is a worthwhile optimisation as it we avoid allocating a full
0205 block for the symlink, and most symlinks are less than 60 characters long.
0206 
0207 Character and block special devices never have data blocks assigned to
0208 them.  Instead, their device number is stored in the inode, again reusing
0209 the fields which would be used to point to the data blocks.
0210 
0211 Reserved Space
0212 --------------
0213 
0214 In ext2, there is a mechanism for reserving a certain number of blocks
0215 for a particular user (normally the super-user).  This is intended to
0216 allow for the system to continue functioning even if non-privileged users
0217 fill up all the space available to them (this is independent of filesystem
0218 quotas).  It also keeps the filesystem from filling up entirely which
0219 helps combat fragmentation.
0220 
0221 Filesystem check
0222 ----------------
0223 
0224 At boot time, most systems run a consistency check (e2fsck) on their
0225 filesystems.  The superblock of the ext2 filesystem contains several
0226 fields which indicate whether fsck should actually run (since checking
0227 the filesystem at boot can take a long time if it is large).  fsck will
0228 run if the filesystem was not cleanly unmounted, if the maximum mount
0229 count has been exceeded or if the maximum time between checks has been
0230 exceeded.
0231 
0232 Feature Compatibility
0233 ---------------------
0234 
0235 The compatibility feature mechanism used in ext2 is sophisticated.
0236 It safely allows features to be added to the filesystem, without
0237 unnecessarily sacrificing compatibility with older versions of the
0238 filesystem code.  The feature compatibility mechanism is not supported by
0239 the original revision 0 (EXT2_GOOD_OLD_REV) of ext2, but was introduced in
0240 revision 1.  There are three 32-bit fields, one for compatible features
0241 (COMPAT), one for read-only compatible (RO_COMPAT) features and one for
0242 incompatible (INCOMPAT) features.
0243 
0244 These feature flags have specific meanings for the kernel as follows:
0245 
0246 A COMPAT flag indicates that a feature is present in the filesystem,
0247 but the on-disk format is 100% compatible with older on-disk formats, so
0248 a kernel which didn't know anything about this feature could read/write
0249 the filesystem without any chance of corrupting the filesystem (or even
0250 making it inconsistent).  This is essentially just a flag which says
0251 "this filesystem has a (hidden) feature" that the kernel or e2fsck may
0252 want to be aware of (more on e2fsck and feature flags later).  The ext3
0253 HAS_JOURNAL feature is a COMPAT flag because the ext3 journal is simply
0254 a regular file with data blocks in it so the kernel does not need to
0255 take any special notice of it if it doesn't understand ext3 journaling.
0256 
0257 An RO_COMPAT flag indicates that the on-disk format is 100% compatible
0258 with older on-disk formats for reading (i.e. the feature does not change
0259 the visible on-disk format).  However, an old kernel writing to such a
0260 filesystem would/could corrupt the filesystem, so this is prevented. The
0261 most common such feature, SPARSE_SUPER, is an RO_COMPAT feature because
0262 sparse groups allow file data blocks where superblock/group descriptor
0263 backups used to live, and ext2_free_blocks() refuses to free these blocks,
0264 which would leading to inconsistent bitmaps.  An old kernel would also
0265 get an error if it tried to free a series of blocks which crossed a group
0266 boundary, but this is a legitimate layout in a SPARSE_SUPER filesystem.
0267 
0268 An INCOMPAT flag indicates the on-disk format has changed in some
0269 way that makes it unreadable by older kernels, or would otherwise
0270 cause a problem if an old kernel tried to mount it.  FILETYPE is an
0271 INCOMPAT flag because older kernels would think a filename was longer
0272 than 256 characters, which would lead to corrupt directory listings.
0273 The COMPRESSION flag is an obvious INCOMPAT flag - if the kernel
0274 doesn't understand compression, you would just get garbage back from
0275 read() instead of it automatically decompressing your data.  The ext3
0276 RECOVER flag is needed to prevent a kernel which does not understand the
0277 ext3 journal from mounting the filesystem without replaying the journal.
0278 
0279 For e2fsck, it needs to be more strict with the handling of these
0280 flags than the kernel.  If it doesn't understand ANY of the COMPAT,
0281 RO_COMPAT, or INCOMPAT flags it will refuse to check the filesystem,
0282 because it has no way of verifying whether a given feature is valid
0283 or not.  Allowing e2fsck to succeed on a filesystem with an unknown
0284 feature is a false sense of security for the user.  Refusing to check
0285 a filesystem with unknown features is a good incentive for the user to
0286 update to the latest e2fsck.  This also means that anyone adding feature
0287 flags to ext2 also needs to update e2fsck to verify these features.
0288 
0289 Metadata
0290 --------
0291 
0292 It is frequently claimed that the ext2 implementation of writing
0293 asynchronous metadata is faster than the ffs synchronous metadata
0294 scheme but less reliable.  Both methods are equally resolvable by their
0295 respective fsck programs.
0296 
0297 If you're exceptionally paranoid, there are 3 ways of making metadata
0298 writes synchronous on ext2:
0299 
0300 - per-file if you have the program source: use the O_SYNC flag to open()
0301 - per-file if you don't have the source: use "chattr +S" on the file
0302 - per-filesystem: add the "sync" option to mount (or in /etc/fstab)
0303 
0304 the first and last are not ext2 specific but do force the metadata to
0305 be written synchronously.  See also Journaling below.
0306 
0307 Limitations
0308 -----------
0309 
0310 There are various limits imposed by the on-disk layout of ext2.  Other
0311 limits are imposed by the current implementation of the kernel code.
0312 Many of the limits are determined at the time the filesystem is first
0313 created, and depend upon the block size chosen.  The ratio of inodes to
0314 data blocks is fixed at filesystem creation time, so the only way to
0315 increase the number of inodes is to increase the size of the filesystem.
0316 No tools currently exist which can change the ratio of inodes to blocks.
0317 
0318 Most of these limits could be overcome with slight changes in the on-disk
0319 format and using a compatibility flag to signal the format change (at
0320 the expense of some compatibility).
0321 
0322 =====================  =======    =======    =======   ========
0323 Filesystem block size      1kB        2kB        4kB        8kB
0324 =====================  =======    =======    =======   ========
0325 File size limit           16GB      256GB     2048GB     2048GB
0326 Filesystem size limit   2047GB     8192GB    16384GB    32768GB
0327 =====================  =======    =======    =======   ========
0328 
0329 There is a 2.4 kernel limit of 2048GB for a single block device, so no
0330 filesystem larger than that can be created at this time.  There is also
0331 an upper limit on the block size imposed by the page size of the kernel,
0332 so 8kB blocks are only allowed on Alpha systems (and other architectures
0333 which support larger pages).
0334 
0335 There is an upper limit of 32000 subdirectories in a single directory.
0336 
0337 There is a "soft" upper limit of about 10-15k files in a single directory
0338 with the current linear linked-list directory implementation.  This limit
0339 stems from performance problems when creating and deleting (and also
0340 finding) files in such large directories.  Using a hashed directory index
0341 (under development) allows 100k-1M+ files in a single directory without
0342 performance problems (although RAM size becomes an issue at this point).
0343 
0344 The (meaningless) absolute upper limit of files in a single directory
0345 (imposed by the file size, the realistic limit is obviously much less)
0346 is over 130 trillion files.  It would be higher except there are not
0347 enough 4-character names to make up unique directory entries, so they
0348 have to be 8 character filenames, even then we are fairly close to
0349 running out of unique filenames.
0350 
0351 Journaling
0352 ----------
0353 
0354 A journaling extension to the ext2 code has been developed by Stephen
0355 Tweedie.  It avoids the risks of metadata corruption and the need to
0356 wait for e2fsck to complete after a crash, without requiring a change
0357 to the on-disk ext2 layout.  In a nutshell, the journal is a regular
0358 file which stores whole metadata (and optionally data) blocks that have
0359 been modified, prior to writing them into the filesystem.  This means
0360 it is possible to add a journal to an existing ext2 filesystem without
0361 the need for data conversion.
0362 
0363 When changes to the filesystem (e.g. a file is renamed) they are stored in
0364 a transaction in the journal and can either be complete or incomplete at
0365 the time of a crash.  If a transaction is complete at the time of a crash
0366 (or in the normal case where the system does not crash), then any blocks
0367 in that transaction are guaranteed to represent a valid filesystem state,
0368 and are copied into the filesystem.  If a transaction is incomplete at
0369 the time of the crash, then there is no guarantee of consistency for
0370 the blocks in that transaction so they are discarded (which means any
0371 filesystem changes they represent are also lost).
0372 Check Documentation/filesystems/ext4/ if you want to read more about
0373 ext4 and journaling.
0374 
0375 References
0376 ==========
0377 
0378 ======================= ===============================================
0379 The kernel source       file:/usr/src/linux/fs/ext2/
0380 e2fsprogs (e2fsck)      http://e2fsprogs.sourceforge.net/
0381 Design & Implementation http://e2fsprogs.sourceforge.net/ext2intro.html
0382 Journaling (ext3)       ftp://ftp.uk.linux.org/pub/linux/sct/fs/jfs/
0383 Filesystem Resizing     http://ext2resize.sourceforge.net/
0384 Compression [1]_        http://e2compr.sourceforge.net/
0385 ======================= ===============================================
0386 
0387 Implementations for:
0388 
0389 ======================= ===========================================================
0390 Windows 95/98/NT/2000   http://www.chrysocome.net/explore2fs
0391 Windows 95 [1]_         http://www.yipton.net/content.html#FSDEXT2
0392 DOS client [1]_         ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
0393 OS/2 [2]_               ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
0394 RISC OS client          http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/IscaFS/
0395 ======================= ===========================================================
0396 
0397 .. [1] no longer actively developed/supported (as of Apr 2001)
0398 .. [2] no longer actively developed/supported (as of Mar 2009)