16e29ad2eSMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
26e29ad2eSMauro Carvalho Chehab
36e29ad2eSMauro Carvalho Chehab
42356eb80SJonathan Neuschäfer==============================
56e29ad2eSMauro Carvalho ChehabThe Second Extended Filesystem
66e29ad2eSMauro Carvalho Chehab==============================
76e29ad2eSMauro Carvalho Chehab
86e29ad2eSMauro Carvalho Chehabext2 was originally released in January 1993.  Written by R\'emy Card,
96e29ad2eSMauro Carvalho ChehabTheodore Ts'o and Stephen Tweedie, it was a major rewrite of the
106e29ad2eSMauro Carvalho ChehabExtended Filesystem.  It is currently still (April 2001) the predominant
116e29ad2eSMauro Carvalho Chehabfilesystem in use by Linux.  There are also implementations available
126e29ad2eSMauro Carvalho Chehabfor NetBSD, FreeBSD, the GNU HURD, Windows 95/98/NT, OS/2 and RISC OS.
136e29ad2eSMauro Carvalho Chehab
146e29ad2eSMauro Carvalho ChehabOptions
156e29ad2eSMauro Carvalho Chehab=======
166e29ad2eSMauro Carvalho Chehab
176e29ad2eSMauro Carvalho ChehabMost defaults are determined by the filesystem superblock, and can be
186e29ad2eSMauro Carvalho Chehabset using tune2fs(8). Kernel-determined defaults are indicated by (*).
196e29ad2eSMauro Carvalho Chehab
206e29ad2eSMauro Carvalho Chehab====================    ===     ================================================
216e29ad2eSMauro Carvalho Chehabbsddf			(*)	Makes ``df`` act like BSD.
226e29ad2eSMauro Carvalho Chehabminixdf				Makes ``df`` act like Minix.
236e29ad2eSMauro Carvalho Chehab
246e29ad2eSMauro Carvalho Chehabcheck=none, nocheck	(*)	Don't do extra checking of bitmaps on mount
256e29ad2eSMauro Carvalho Chehab				(check=normal and check=strict options removed)
266e29ad2eSMauro Carvalho Chehab
276e29ad2eSMauro Carvalho Chehabdax				Use direct access (no page cache).  See
28*a9edc03fSKir Kolyshkin				Documentation/filesystems/dax.rst.
296e29ad2eSMauro Carvalho Chehab
306e29ad2eSMauro Carvalho Chehabdebug				Extra debugging information is sent to the
316e29ad2eSMauro Carvalho Chehab				kernel syslog.  Useful for developers.
326e29ad2eSMauro Carvalho Chehab
336e29ad2eSMauro Carvalho Chehaberrors=continue			Keep going on a filesystem error.
346e29ad2eSMauro Carvalho Chehaberrors=remount-ro		Remount the filesystem read-only on an error.
356e29ad2eSMauro Carvalho Chehaberrors=panic			Panic and halt the machine if an error occurs.
366e29ad2eSMauro Carvalho Chehab
376e29ad2eSMauro Carvalho Chehabgrpid, bsdgroups		Give objects the same group ID as their parent.
386e29ad2eSMauro Carvalho Chehabnogrpid, sysvgroups		New objects have the group ID of their creator.
396e29ad2eSMauro Carvalho Chehab
406e29ad2eSMauro Carvalho Chehabnouid32				Use 16-bit UIDs and GIDs.
416e29ad2eSMauro Carvalho Chehab
426e29ad2eSMauro Carvalho Chehaboldalloc			Enable the old block allocator. Orlov should
436e29ad2eSMauro Carvalho Chehab				have better performance, we'd like to get some
446e29ad2eSMauro Carvalho Chehab				feedback if it's the contrary for you.
456e29ad2eSMauro Carvalho Chehaborlov			(*)	Use the Orlov block allocator.
466e29ad2eSMauro Carvalho Chehab				(See http://lwn.net/Articles/14633/ and
476e29ad2eSMauro Carvalho Chehab				http://lwn.net/Articles/14446/.)
486e29ad2eSMauro Carvalho Chehab
496e29ad2eSMauro Carvalho Chehabresuid=n			The user ID which may use the reserved blocks.
506e29ad2eSMauro Carvalho Chehabresgid=n			The group ID which may use the reserved blocks.
516e29ad2eSMauro Carvalho Chehab
526e29ad2eSMauro Carvalho Chehabsb=n				Use alternate superblock at this location.
536e29ad2eSMauro Carvalho Chehab
546e29ad2eSMauro Carvalho Chehabuser_xattr			Enable "user." POSIX Extended Attributes
556e29ad2eSMauro Carvalho Chehab				(requires CONFIG_EXT2_FS_XATTR).
566e29ad2eSMauro Carvalho Chehabnouser_xattr			Don't support "user." extended attributes.
576e29ad2eSMauro Carvalho Chehab
586e29ad2eSMauro Carvalho Chehabacl				Enable POSIX Access Control Lists support
596e29ad2eSMauro Carvalho Chehab				(requires CONFIG_EXT2_FS_POSIX_ACL).
606e29ad2eSMauro Carvalho Chehabnoacl				Don't support POSIX ACLs.
616e29ad2eSMauro Carvalho Chehab
626e29ad2eSMauro Carvalho Chehabquota, usrquota			Enable user disk quota support
636e29ad2eSMauro Carvalho Chehab				(requires CONFIG_QUOTA).
646e29ad2eSMauro Carvalho Chehab
656e29ad2eSMauro Carvalho Chehabgrpquota			Enable group disk quota support
666e29ad2eSMauro Carvalho Chehab				(requires CONFIG_QUOTA).
676e29ad2eSMauro Carvalho Chehab====================    ===     ================================================
686e29ad2eSMauro Carvalho Chehab
696e29ad2eSMauro Carvalho Chehabnoquota option ls silently ignored by ext2.
706e29ad2eSMauro Carvalho Chehab
716e29ad2eSMauro Carvalho Chehab
726e29ad2eSMauro Carvalho ChehabSpecification
736e29ad2eSMauro Carvalho Chehab=============
746e29ad2eSMauro Carvalho Chehab
756e29ad2eSMauro Carvalho Chehabext2 shares many properties with traditional Unix filesystems.  It has
766e29ad2eSMauro Carvalho Chehabthe concepts of blocks, inodes and directories.  It has space in the
776e29ad2eSMauro Carvalho Chehabspecification for Access Control Lists (ACLs), fragments, undeletion and
786e29ad2eSMauro Carvalho Chehabcompression though these are not yet implemented (some are available as
796e29ad2eSMauro Carvalho Chehabseparate patches).  There is also a versioning mechanism to allow new
806e29ad2eSMauro Carvalho Chehabfeatures (such as journalling) to be added in a maximally compatible
816e29ad2eSMauro Carvalho Chehabmanner.
826e29ad2eSMauro Carvalho Chehab
836e29ad2eSMauro Carvalho ChehabBlocks
846e29ad2eSMauro Carvalho Chehab------
856e29ad2eSMauro Carvalho Chehab
866e29ad2eSMauro Carvalho ChehabThe space in the device or file is split up into blocks.  These are
876e29ad2eSMauro Carvalho Chehaba fixed size, of 1024, 2048 or 4096 bytes (8192 bytes on Alpha systems),
886e29ad2eSMauro Carvalho Chehabwhich is decided when the filesystem is created.  Smaller blocks mean
896e29ad2eSMauro Carvalho Chehabless wasted space per file, but require slightly more accounting overhead,
906e29ad2eSMauro Carvalho Chehaband also impose other limits on the size of files and the filesystem.
916e29ad2eSMauro Carvalho Chehab
926e29ad2eSMauro Carvalho ChehabBlock Groups
936e29ad2eSMauro Carvalho Chehab------------
946e29ad2eSMauro Carvalho Chehab
956e29ad2eSMauro Carvalho ChehabBlocks are clustered into block groups in order to reduce fragmentation
966e29ad2eSMauro Carvalho Chehaband minimise the amount of head seeking when reading a large amount
976e29ad2eSMauro Carvalho Chehabof consecutive data.  Information about each block group is kept in a
986e29ad2eSMauro Carvalho Chehabdescriptor table stored in the block(s) immediately after the superblock.
996e29ad2eSMauro Carvalho ChehabTwo blocks near the start of each group are reserved for the block usage
1006e29ad2eSMauro Carvalho Chehabbitmap and the inode usage bitmap which show which blocks and inodes
1016e29ad2eSMauro Carvalho Chehabare in use.  Since each bitmap is limited to a single block, this means
1026e29ad2eSMauro Carvalho Chehabthat the maximum size of a block group is 8 times the size of a block.
1036e29ad2eSMauro Carvalho Chehab
1046e29ad2eSMauro Carvalho ChehabThe block(s) following the bitmaps in each block group are designated
1056e29ad2eSMauro Carvalho Chehabas the inode table for that block group and the remainder are the data
1066e29ad2eSMauro Carvalho Chehabblocks.  The block allocation algorithm attempts to allocate data blocks
1076e29ad2eSMauro Carvalho Chehabin the same block group as the inode which contains them.
1086e29ad2eSMauro Carvalho Chehab
1096e29ad2eSMauro Carvalho ChehabThe Superblock
1106e29ad2eSMauro Carvalho Chehab--------------
1116e29ad2eSMauro Carvalho Chehab
1126e29ad2eSMauro Carvalho ChehabThe superblock contains all the information about the configuration of
1136e29ad2eSMauro Carvalho Chehabthe filing system.  The primary copy of the superblock is stored at an
1146e29ad2eSMauro Carvalho Chehaboffset of 1024 bytes from the start of the device, and it is essential
1156e29ad2eSMauro Carvalho Chehabto mounting the filesystem.  Since it is so important, backup copies of
1166e29ad2eSMauro Carvalho Chehabthe superblock are stored in block groups throughout the filesystem.
1176e29ad2eSMauro Carvalho ChehabThe first version of ext2 (revision 0) stores a copy at the start of
1186e29ad2eSMauro Carvalho Chehabevery block group, along with backups of the group descriptor block(s).
1196e29ad2eSMauro Carvalho ChehabBecause this can consume a considerable amount of space for large
1206e29ad2eSMauro Carvalho Chehabfilesystems, later revisions can optionally reduce the number of backup
1216e29ad2eSMauro Carvalho Chehabcopies by only putting backups in specific groups (this is the sparse
1226e29ad2eSMauro Carvalho Chehabsuperblock feature).  The groups chosen are 0, 1 and powers of 3, 5 and 7.
1236e29ad2eSMauro Carvalho Chehab
1246e29ad2eSMauro Carvalho ChehabThe information in the superblock contains fields such as the total
1256e29ad2eSMauro Carvalho Chehabnumber of inodes and blocks in the filesystem and how many are free,
1266e29ad2eSMauro Carvalho Chehabhow many inodes and blocks are in each block group, when the filesystem
1276e29ad2eSMauro Carvalho Chehabwas mounted (and if it was cleanly unmounted), when it was modified,
1286e29ad2eSMauro Carvalho Chehabwhat version of the filesystem it is (see the Revisions section below)
1296e29ad2eSMauro Carvalho Chehaband which OS created it.
1306e29ad2eSMauro Carvalho Chehab
1316e29ad2eSMauro Carvalho ChehabIf the filesystem is revision 1 or higher, then there are extra fields,
1326e29ad2eSMauro Carvalho Chehabsuch as a volume name, a unique identification number, the inode size,
1336e29ad2eSMauro Carvalho Chehaband space for optional filesystem features to store configuration info.
1346e29ad2eSMauro Carvalho Chehab
1356e29ad2eSMauro Carvalho ChehabAll fields in the superblock (as in all other ext2 structures) are stored
1366e29ad2eSMauro Carvalho Chehabon the disc in little endian format, so a filesystem is portable between
1376e29ad2eSMauro Carvalho Chehabmachines without having to know what machine it was created on.
1386e29ad2eSMauro Carvalho Chehab
1396e29ad2eSMauro Carvalho ChehabInodes
1406e29ad2eSMauro Carvalho Chehab------
1416e29ad2eSMauro Carvalho Chehab
1426e29ad2eSMauro Carvalho ChehabThe inode (index node) is a fundamental concept in the ext2 filesystem.
1436e29ad2eSMauro Carvalho ChehabEach object in the filesystem is represented by an inode.  The inode
1446e29ad2eSMauro Carvalho Chehabstructure contains pointers to the filesystem blocks which contain the
1456e29ad2eSMauro Carvalho Chehabdata held in the object and all of the metadata about an object except
1466e29ad2eSMauro Carvalho Chehabits name.  The metadata about an object includes the permissions, owner,
1476e29ad2eSMauro Carvalho Chehabgroup, flags, size, number of blocks used, access time, change time,
1486e29ad2eSMauro Carvalho Chehabmodification time, deletion time, number of links, fragments, version
1496e29ad2eSMauro Carvalho Chehab(for NFS) and extended attributes (EAs) and/or Access Control Lists (ACLs).
1506e29ad2eSMauro Carvalho Chehab
1516e29ad2eSMauro Carvalho ChehabThere are some reserved fields which are currently unused in the inode
1526e29ad2eSMauro Carvalho Chehabstructure and several which are overloaded.  One field is reserved for the
1536e29ad2eSMauro Carvalho Chehabdirectory ACL if the inode is a directory and alternately for the top 32
1546e29ad2eSMauro Carvalho Chehabbits of the file size if the inode is a regular file (allowing file sizes
1556e29ad2eSMauro Carvalho Chehablarger than 2GB).  The translator field is unused under Linux, but is used
1566e29ad2eSMauro Carvalho Chehabby the HURD to reference the inode of a program which will be used to
1576e29ad2eSMauro Carvalho Chehabinterpret this object.  Most of the remaining reserved fields have been
1586e29ad2eSMauro Carvalho Chehabused up for both Linux and the HURD for larger owner and group fields,
1596e29ad2eSMauro Carvalho ChehabThe HURD also has a larger mode field so it uses another of the remaining
1606e29ad2eSMauro Carvalho Chehabfields to store the extra more bits.
1616e29ad2eSMauro Carvalho Chehab
1626e29ad2eSMauro Carvalho ChehabThere are pointers to the first 12 blocks which contain the file's data
1636e29ad2eSMauro Carvalho Chehabin the inode.  There is a pointer to an indirect block (which contains
1646e29ad2eSMauro Carvalho Chehabpointers to the next set of blocks), a pointer to a doubly-indirect
1656e29ad2eSMauro Carvalho Chehabblock (which contains pointers to indirect blocks) and a pointer to a
1666e29ad2eSMauro Carvalho Chehabtrebly-indirect block (which contains pointers to doubly-indirect blocks).
1676e29ad2eSMauro Carvalho Chehab
1686e29ad2eSMauro Carvalho ChehabThe flags field contains some ext2-specific flags which aren't catered
1696e29ad2eSMauro Carvalho Chehabfor by the standard chmod flags.  These flags can be listed with lsattr
1706e29ad2eSMauro Carvalho Chehaband changed with the chattr command, and allow specific filesystem
1716e29ad2eSMauro Carvalho Chehabbehaviour on a per-file basis.  There are flags for secure deletion,
1726e29ad2eSMauro Carvalho Chehabundeletable, compression, synchronous updates, immutability, append-only,
1736e29ad2eSMauro Carvalho Chehabdumpable, no-atime, indexed directories, and data-journaling.  Not all
1746e29ad2eSMauro Carvalho Chehabof these are supported yet.
1756e29ad2eSMauro Carvalho Chehab
1766e29ad2eSMauro Carvalho ChehabDirectories
1776e29ad2eSMauro Carvalho Chehab-----------
1786e29ad2eSMauro Carvalho Chehab
1796e29ad2eSMauro Carvalho ChehabA directory is a filesystem object and has an inode just like a file.
1806e29ad2eSMauro Carvalho ChehabIt is a specially formatted file containing records which associate
1816e29ad2eSMauro Carvalho Chehabeach name with an inode number.  Later revisions of the filesystem also
1826e29ad2eSMauro Carvalho Chehabencode the type of the object (file, directory, symlink, device, fifo,
1836e29ad2eSMauro Carvalho Chehabsocket) to avoid the need to check the inode itself for this information
1846e29ad2eSMauro Carvalho Chehab(support for taking advantage of this feature does not yet exist in
1856e29ad2eSMauro Carvalho ChehabGlibc 2.2).
1866e29ad2eSMauro Carvalho Chehab
1876e29ad2eSMauro Carvalho ChehabThe inode allocation code tries to assign inodes which are in the same
1886e29ad2eSMauro Carvalho Chehabblock group as the directory in which they are first created.
1896e29ad2eSMauro Carvalho Chehab
1906e29ad2eSMauro Carvalho ChehabThe current implementation of ext2 uses a singly-linked list to store
1916e29ad2eSMauro Carvalho Chehabthe filenames in the directory; a pending enhancement uses hashing of the
1926e29ad2eSMauro Carvalho Chehabfilenames to allow lookup without the need to scan the entire directory.
1936e29ad2eSMauro Carvalho Chehab
1946e29ad2eSMauro Carvalho ChehabThe current implementation never removes empty directory blocks once they
1956e29ad2eSMauro Carvalho Chehabhave been allocated to hold more files.
1966e29ad2eSMauro Carvalho Chehab
1976e29ad2eSMauro Carvalho ChehabSpecial files
1986e29ad2eSMauro Carvalho Chehab-------------
1996e29ad2eSMauro Carvalho Chehab
2006e29ad2eSMauro Carvalho ChehabSymbolic links are also filesystem objects with inodes.  They deserve
2016e29ad2eSMauro Carvalho Chehabspecial mention because the data for them is stored within the inode
2026e29ad2eSMauro Carvalho Chehabitself if the symlink is less than 60 bytes long.  It uses the fields
2036e29ad2eSMauro Carvalho Chehabwhich would normally be used to store the pointers to data blocks.
2046e29ad2eSMauro Carvalho ChehabThis is a worthwhile optimisation as it we avoid allocating a full
2056e29ad2eSMauro Carvalho Chehabblock for the symlink, and most symlinks are less than 60 characters long.
2066e29ad2eSMauro Carvalho Chehab
2076e29ad2eSMauro Carvalho ChehabCharacter and block special devices never have data blocks assigned to
2086e29ad2eSMauro Carvalho Chehabthem.  Instead, their device number is stored in the inode, again reusing
2096e29ad2eSMauro Carvalho Chehabthe fields which would be used to point to the data blocks.
2106e29ad2eSMauro Carvalho Chehab
2116e29ad2eSMauro Carvalho ChehabReserved Space
2126e29ad2eSMauro Carvalho Chehab--------------
2136e29ad2eSMauro Carvalho Chehab
2146e29ad2eSMauro Carvalho ChehabIn ext2, there is a mechanism for reserving a certain number of blocks
2156e29ad2eSMauro Carvalho Chehabfor a particular user (normally the super-user).  This is intended to
2166e29ad2eSMauro Carvalho Chehaballow for the system to continue functioning even if non-privileged users
2176e29ad2eSMauro Carvalho Chehabfill up all the space available to them (this is independent of filesystem
2186e29ad2eSMauro Carvalho Chehabquotas).  It also keeps the filesystem from filling up entirely which
2196e29ad2eSMauro Carvalho Chehabhelps combat fragmentation.
2206e29ad2eSMauro Carvalho Chehab
2216e29ad2eSMauro Carvalho ChehabFilesystem check
2226e29ad2eSMauro Carvalho Chehab----------------
2236e29ad2eSMauro Carvalho Chehab
2246e29ad2eSMauro Carvalho ChehabAt boot time, most systems run a consistency check (e2fsck) on their
2256e29ad2eSMauro Carvalho Chehabfilesystems.  The superblock of the ext2 filesystem contains several
2266e29ad2eSMauro Carvalho Chehabfields which indicate whether fsck should actually run (since checking
2276e29ad2eSMauro Carvalho Chehabthe filesystem at boot can take a long time if it is large).  fsck will
2286e29ad2eSMauro Carvalho Chehabrun if the filesystem was not cleanly unmounted, if the maximum mount
2296e29ad2eSMauro Carvalho Chehabcount has been exceeded or if the maximum time between checks has been
2306e29ad2eSMauro Carvalho Chehabexceeded.
2316e29ad2eSMauro Carvalho Chehab
2326e29ad2eSMauro Carvalho ChehabFeature Compatibility
2336e29ad2eSMauro Carvalho Chehab---------------------
2346e29ad2eSMauro Carvalho Chehab
2356e29ad2eSMauro Carvalho ChehabThe compatibility feature mechanism used in ext2 is sophisticated.
2366e29ad2eSMauro Carvalho ChehabIt safely allows features to be added to the filesystem, without
2376e29ad2eSMauro Carvalho Chehabunnecessarily sacrificing compatibility with older versions of the
2386e29ad2eSMauro Carvalho Chehabfilesystem code.  The feature compatibility mechanism is not supported by
2396e29ad2eSMauro Carvalho Chehabthe original revision 0 (EXT2_GOOD_OLD_REV) of ext2, but was introduced in
2406e29ad2eSMauro Carvalho Chehabrevision 1.  There are three 32-bit fields, one for compatible features
2416e29ad2eSMauro Carvalho Chehab(COMPAT), one for read-only compatible (RO_COMPAT) features and one for
2426e29ad2eSMauro Carvalho Chehabincompatible (INCOMPAT) features.
2436e29ad2eSMauro Carvalho Chehab
2446e29ad2eSMauro Carvalho ChehabThese feature flags have specific meanings for the kernel as follows:
2456e29ad2eSMauro Carvalho Chehab
2466e29ad2eSMauro Carvalho ChehabA COMPAT flag indicates that a feature is present in the filesystem,
2476e29ad2eSMauro Carvalho Chehabbut the on-disk format is 100% compatible with older on-disk formats, so
2486e29ad2eSMauro Carvalho Chehaba kernel which didn't know anything about this feature could read/write
2496e29ad2eSMauro Carvalho Chehabthe filesystem without any chance of corrupting the filesystem (or even
2506e29ad2eSMauro Carvalho Chehabmaking it inconsistent).  This is essentially just a flag which says
2516e29ad2eSMauro Carvalho Chehab"this filesystem has a (hidden) feature" that the kernel or e2fsck may
2526e29ad2eSMauro Carvalho Chehabwant to be aware of (more on e2fsck and feature flags later).  The ext3
2536e29ad2eSMauro Carvalho ChehabHAS_JOURNAL feature is a COMPAT flag because the ext3 journal is simply
2546e29ad2eSMauro Carvalho Chehaba regular file with data blocks in it so the kernel does not need to
2556e29ad2eSMauro Carvalho Chehabtake any special notice of it if it doesn't understand ext3 journaling.
2566e29ad2eSMauro Carvalho Chehab
2576e29ad2eSMauro Carvalho ChehabAn RO_COMPAT flag indicates that the on-disk format is 100% compatible
2586e29ad2eSMauro Carvalho Chehabwith older on-disk formats for reading (i.e. the feature does not change
2596e29ad2eSMauro Carvalho Chehabthe visible on-disk format).  However, an old kernel writing to such a
2606e29ad2eSMauro Carvalho Chehabfilesystem would/could corrupt the filesystem, so this is prevented. The
2616e29ad2eSMauro Carvalho Chehabmost common such feature, SPARSE_SUPER, is an RO_COMPAT feature because
2626e29ad2eSMauro Carvalho Chehabsparse groups allow file data blocks where superblock/group descriptor
2636e29ad2eSMauro Carvalho Chehabbackups used to live, and ext2_free_blocks() refuses to free these blocks,
2646e29ad2eSMauro Carvalho Chehabwhich would leading to inconsistent bitmaps.  An old kernel would also
2656e29ad2eSMauro Carvalho Chehabget an error if it tried to free a series of blocks which crossed a group
2666e29ad2eSMauro Carvalho Chehabboundary, but this is a legitimate layout in a SPARSE_SUPER filesystem.
2676e29ad2eSMauro Carvalho Chehab
2686e29ad2eSMauro Carvalho ChehabAn INCOMPAT flag indicates the on-disk format has changed in some
2696e29ad2eSMauro Carvalho Chehabway that makes it unreadable by older kernels, or would otherwise
2706e29ad2eSMauro Carvalho Chehabcause a problem if an old kernel tried to mount it.  FILETYPE is an
2716e29ad2eSMauro Carvalho ChehabINCOMPAT flag because older kernels would think a filename was longer
2726e29ad2eSMauro Carvalho Chehabthan 256 characters, which would lead to corrupt directory listings.
2736e29ad2eSMauro Carvalho ChehabThe COMPRESSION flag is an obvious INCOMPAT flag - if the kernel
2746e29ad2eSMauro Carvalho Chehabdoesn't understand compression, you would just get garbage back from
2756e29ad2eSMauro Carvalho Chehabread() instead of it automatically decompressing your data.  The ext3
2766e29ad2eSMauro Carvalho ChehabRECOVER flag is needed to prevent a kernel which does not understand the
2776e29ad2eSMauro Carvalho Chehabext3 journal from mounting the filesystem without replaying the journal.
2786e29ad2eSMauro Carvalho Chehab
2796e29ad2eSMauro Carvalho ChehabFor e2fsck, it needs to be more strict with the handling of these
2806e29ad2eSMauro Carvalho Chehabflags than the kernel.  If it doesn't understand ANY of the COMPAT,
2816e29ad2eSMauro Carvalho ChehabRO_COMPAT, or INCOMPAT flags it will refuse to check the filesystem,
2826e29ad2eSMauro Carvalho Chehabbecause it has no way of verifying whether a given feature is valid
2836e29ad2eSMauro Carvalho Chehabor not.  Allowing e2fsck to succeed on a filesystem with an unknown
2846e29ad2eSMauro Carvalho Chehabfeature is a false sense of security for the user.  Refusing to check
2856e29ad2eSMauro Carvalho Chehaba filesystem with unknown features is a good incentive for the user to
2866e29ad2eSMauro Carvalho Chehabupdate to the latest e2fsck.  This also means that anyone adding feature
2876e29ad2eSMauro Carvalho Chehabflags to ext2 also needs to update e2fsck to verify these features.
2886e29ad2eSMauro Carvalho Chehab
2896e29ad2eSMauro Carvalho ChehabMetadata
2906e29ad2eSMauro Carvalho Chehab--------
2916e29ad2eSMauro Carvalho Chehab
2926e29ad2eSMauro Carvalho ChehabIt is frequently claimed that the ext2 implementation of writing
2936e29ad2eSMauro Carvalho Chehabasynchronous metadata is faster than the ffs synchronous metadata
2946e29ad2eSMauro Carvalho Chehabscheme but less reliable.  Both methods are equally resolvable by their
2956e29ad2eSMauro Carvalho Chehabrespective fsck programs.
2966e29ad2eSMauro Carvalho Chehab
2976e29ad2eSMauro Carvalho ChehabIf you're exceptionally paranoid, there are 3 ways of making metadata
2986e29ad2eSMauro Carvalho Chehabwrites synchronous on ext2:
2996e29ad2eSMauro Carvalho Chehab
3006e29ad2eSMauro Carvalho Chehab- per-file if you have the program source: use the O_SYNC flag to open()
3016e29ad2eSMauro Carvalho Chehab- per-file if you don't have the source: use "chattr +S" on the file
3026e29ad2eSMauro Carvalho Chehab- per-filesystem: add the "sync" option to mount (or in /etc/fstab)
3036e29ad2eSMauro Carvalho Chehab
3046e29ad2eSMauro Carvalho Chehabthe first and last are not ext2 specific but do force the metadata to
3056e29ad2eSMauro Carvalho Chehabbe written synchronously.  See also Journaling below.
3066e29ad2eSMauro Carvalho Chehab
3076e29ad2eSMauro Carvalho ChehabLimitations
3086e29ad2eSMauro Carvalho Chehab-----------
3096e29ad2eSMauro Carvalho Chehab
3106e29ad2eSMauro Carvalho ChehabThere are various limits imposed by the on-disk layout of ext2.  Other
3116e29ad2eSMauro Carvalho Chehablimits are imposed by the current implementation of the kernel code.
3126e29ad2eSMauro Carvalho ChehabMany of the limits are determined at the time the filesystem is first
3136e29ad2eSMauro Carvalho Chehabcreated, and depend upon the block size chosen.  The ratio of inodes to
3146e29ad2eSMauro Carvalho Chehabdata blocks is fixed at filesystem creation time, so the only way to
3156e29ad2eSMauro Carvalho Chehabincrease the number of inodes is to increase the size of the filesystem.
3166e29ad2eSMauro Carvalho ChehabNo tools currently exist which can change the ratio of inodes to blocks.
3176e29ad2eSMauro Carvalho Chehab
3186e29ad2eSMauro Carvalho ChehabMost of these limits could be overcome with slight changes in the on-disk
3196e29ad2eSMauro Carvalho Chehabformat and using a compatibility flag to signal the format change (at
3206e29ad2eSMauro Carvalho Chehabthe expense of some compatibility).
3216e29ad2eSMauro Carvalho Chehab
3226e29ad2eSMauro Carvalho Chehab=====================  =======    =======    =======   ========
3236e29ad2eSMauro Carvalho ChehabFilesystem block size      1kB        2kB        4kB        8kB
3246e29ad2eSMauro Carvalho Chehab=====================  =======    =======    =======   ========
3256e29ad2eSMauro Carvalho ChehabFile size limit           16GB      256GB     2048GB     2048GB
3266e29ad2eSMauro Carvalho ChehabFilesystem size limit   2047GB     8192GB    16384GB    32768GB
3276e29ad2eSMauro Carvalho Chehab=====================  =======    =======    =======   ========
3286e29ad2eSMauro Carvalho Chehab
3296e29ad2eSMauro Carvalho ChehabThere is a 2.4 kernel limit of 2048GB for a single block device, so no
3306e29ad2eSMauro Carvalho Chehabfilesystem larger than that can be created at this time.  There is also
3316e29ad2eSMauro Carvalho Chehaban upper limit on the block size imposed by the page size of the kernel,
3326e29ad2eSMauro Carvalho Chehabso 8kB blocks are only allowed on Alpha systems (and other architectures
3336e29ad2eSMauro Carvalho Chehabwhich support larger pages).
3346e29ad2eSMauro Carvalho Chehab
3356e29ad2eSMauro Carvalho ChehabThere is an upper limit of 32000 subdirectories in a single directory.
3366e29ad2eSMauro Carvalho Chehab
3376e29ad2eSMauro Carvalho ChehabThere is a "soft" upper limit of about 10-15k files in a single directory
3386e29ad2eSMauro Carvalho Chehabwith the current linear linked-list directory implementation.  This limit
3396e29ad2eSMauro Carvalho Chehabstems from performance problems when creating and deleting (and also
3406e29ad2eSMauro Carvalho Chehabfinding) files in such large directories.  Using a hashed directory index
3416e29ad2eSMauro Carvalho Chehab(under development) allows 100k-1M+ files in a single directory without
3426e29ad2eSMauro Carvalho Chehabperformance problems (although RAM size becomes an issue at this point).
3436e29ad2eSMauro Carvalho Chehab
3446e29ad2eSMauro Carvalho ChehabThe (meaningless) absolute upper limit of files in a single directory
3456e29ad2eSMauro Carvalho Chehab(imposed by the file size, the realistic limit is obviously much less)
3466e29ad2eSMauro Carvalho Chehabis over 130 trillion files.  It would be higher except there are not
3476e29ad2eSMauro Carvalho Chehabenough 4-character names to make up unique directory entries, so they
3486e29ad2eSMauro Carvalho Chehabhave to be 8 character filenames, even then we are fairly close to
3496e29ad2eSMauro Carvalho Chehabrunning out of unique filenames.
3506e29ad2eSMauro Carvalho Chehab
3516e29ad2eSMauro Carvalho ChehabJournaling
3526e29ad2eSMauro Carvalho Chehab----------
3536e29ad2eSMauro Carvalho Chehab
3546e29ad2eSMauro Carvalho ChehabA journaling extension to the ext2 code has been developed by Stephen
3556e29ad2eSMauro Carvalho ChehabTweedie.  It avoids the risks of metadata corruption and the need to
3566e29ad2eSMauro Carvalho Chehabwait for e2fsck to complete after a crash, without requiring a change
3576e29ad2eSMauro Carvalho Chehabto the on-disk ext2 layout.  In a nutshell, the journal is a regular
3586e29ad2eSMauro Carvalho Chehabfile which stores whole metadata (and optionally data) blocks that have
3596e29ad2eSMauro Carvalho Chehabbeen modified, prior to writing them into the filesystem.  This means
3606e29ad2eSMauro Carvalho Chehabit is possible to add a journal to an existing ext2 filesystem without
3616e29ad2eSMauro Carvalho Chehabthe need for data conversion.
3626e29ad2eSMauro Carvalho Chehab
3636e29ad2eSMauro Carvalho ChehabWhen changes to the filesystem (e.g. a file is renamed) they are stored in
3646e29ad2eSMauro Carvalho Chehaba transaction in the journal and can either be complete or incomplete at
3656e29ad2eSMauro Carvalho Chehabthe time of a crash.  If a transaction is complete at the time of a crash
3666e29ad2eSMauro Carvalho Chehab(or in the normal case where the system does not crash), then any blocks
3676e29ad2eSMauro Carvalho Chehabin that transaction are guaranteed to represent a valid filesystem state,
3686e29ad2eSMauro Carvalho Chehaband are copied into the filesystem.  If a transaction is incomplete at
3696e29ad2eSMauro Carvalho Chehabthe time of the crash, then there is no guarantee of consistency for
3706e29ad2eSMauro Carvalho Chehabthe blocks in that transaction so they are discarded (which means any
3716e29ad2eSMauro Carvalho Chehabfilesystem changes they represent are also lost).
3726e29ad2eSMauro Carvalho ChehabCheck Documentation/filesystems/ext4/ if you want to read more about
3736e29ad2eSMauro Carvalho Chehabext4 and journaling.
3746e29ad2eSMauro Carvalho Chehab
3756e29ad2eSMauro Carvalho ChehabReferences
3766e29ad2eSMauro Carvalho Chehab==========
3776e29ad2eSMauro Carvalho Chehab
3786e29ad2eSMauro Carvalho Chehab=======================	===============================================
3796e29ad2eSMauro Carvalho ChehabThe kernel source	file:/usr/src/linux/fs/ext2/
3806e29ad2eSMauro Carvalho Chehabe2fsprogs (e2fsck)	http://e2fsprogs.sourceforge.net/
3816e29ad2eSMauro Carvalho ChehabDesign & Implementation	http://e2fsprogs.sourceforge.net/ext2intro.html
3826e29ad2eSMauro Carvalho ChehabJournaling (ext3)	ftp://ftp.uk.linux.org/pub/linux/sct/fs/jfs/
3836e29ad2eSMauro Carvalho ChehabFilesystem Resizing	http://ext2resize.sourceforge.net/
3846e29ad2eSMauro Carvalho ChehabCompression [1]_	http://e2compr.sourceforge.net/
3856e29ad2eSMauro Carvalho Chehab=======================	===============================================
3866e29ad2eSMauro Carvalho Chehab
3876e29ad2eSMauro Carvalho ChehabImplementations for:
3886e29ad2eSMauro Carvalho Chehab
3896e29ad2eSMauro Carvalho Chehab=======================	===========================================================
3906e29ad2eSMauro Carvalho ChehabWindows 95/98/NT/2000	http://www.chrysocome.net/explore2fs
3916e29ad2eSMauro Carvalho ChehabWindows 95 [1]_		http://www.yipton.net/content.html#FSDEXT2
3926e29ad2eSMauro Carvalho ChehabDOS client [1]_		ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
3936e29ad2eSMauro Carvalho ChehabOS/2 [2]_		ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
3946e29ad2eSMauro Carvalho ChehabRISC OS client		http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/IscaFS/
3956e29ad2eSMauro Carvalho Chehab=======================	===========================================================
3966e29ad2eSMauro Carvalho Chehab
3976e29ad2eSMauro Carvalho Chehab.. [1] no longer actively developed/supported (as of Apr 2001)
3986e29ad2eSMauro Carvalho Chehab.. [2] no longer actively developed/supported (as of Mar 2009)
399