Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) The Second Extended Filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) ==============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) ext2 was originally released in January 1993.  Written by R\'emy Card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) Theodore Ts'o and Stephen Tweedie, it was a major rewrite of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) Extended Filesystem.  It is currently still (April 2001) the predominant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) filesystem in use by Linux.  There are also implementations available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) for NetBSD, FreeBSD, the GNU HURD, Windows 95/98/NT, OS/2 and RISC OS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) Options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) Most defaults are determined by the filesystem superblock, and can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) set using tune2fs(8). Kernel-determined defaults are indicated by (*).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) ====================    ===     ================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) bsddf			(*)	Makes ``df`` act like BSD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) minixdf				Makes ``df`` act like Minix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) check=none, nocheck	(*)	Don't do extra checking of bitmaps on mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 				(check=normal and check=strict options removed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) dax				Use direct access (no page cache).  See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 				Documentation/filesystems/dax.txt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) debug				Extra debugging information is sent to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 				kernel syslog.  Useful for developers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) errors=continue			Keep going on a filesystem error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) errors=remount-ro		Remount the filesystem read-only on an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) errors=panic			Panic and halt the machine if an error occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) grpid, bsdgroups		Give objects the same group ID as their parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) nogrpid, sysvgroups		New objects have the group ID of their creator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) nouid32				Use 16-bit UIDs and GIDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) oldalloc			Enable the old block allocator. Orlov should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 				have better performance, we'd like to get some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 				feedback if it's the contrary for you.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) orlov			(*)	Use the Orlov block allocator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				(See http://lwn.net/Articles/14633/ and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 				http://lwn.net/Articles/14446/.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) resuid=n			The user ID which may use the reserved blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) resgid=n			The group ID which may use the reserved blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) sb=n				Use alternate superblock at this location.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) user_xattr			Enable "user." POSIX Extended Attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				(requires CONFIG_EXT2_FS_XATTR).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) nouser_xattr			Don't support "user." extended attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) acl				Enable POSIX Access Control Lists support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				(requires CONFIG_EXT2_FS_POSIX_ACL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) noacl				Don't support POSIX ACLs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) nobh				Do not attach buffer_heads to file pagecache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) quota, usrquota			Enable user disk quota support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				(requires CONFIG_QUOTA).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) grpquota			Enable group disk quota support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				(requires CONFIG_QUOTA).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) ====================    ===     ================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) noquota option ls silently ignored by ext2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) Specification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) ext2 shares many properties with traditional Unix filesystems.  It has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) the concepts of blocks, inodes and directories.  It has space in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) specification for Access Control Lists (ACLs), fragments, undeletion and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) compression though these are not yet implemented (some are available as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) separate patches).  There is also a versioning mechanism to allow new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) features (such as journalling) to be added in a maximally compatible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) manner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) Blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) ------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) The space in the device or file is split up into blocks.  These are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) a fixed size, of 1024, 2048 or 4096 bytes (8192 bytes on Alpha systems),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) which is decided when the filesystem is created.  Smaller blocks mean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) less wasted space per file, but require slightly more accounting overhead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) and also impose other limits on the size of files and the filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) Block Groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) Blocks are clustered into block groups in order to reduce fragmentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) and minimise the amount of head seeking when reading a large amount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) of consecutive data.  Information about each block group is kept in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) descriptor table stored in the block(s) immediately after the superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) Two blocks near the start of each group are reserved for the block usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) bitmap and the inode usage bitmap which show which blocks and inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) are in use.  Since each bitmap is limited to a single block, this means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) that the maximum size of a block group is 8 times the size of a block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) The block(s) following the bitmaps in each block group are designated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) as the inode table for that block group and the remainder are the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) blocks.  The block allocation algorithm attempts to allocate data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) in the same block group as the inode which contains them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) The Superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) The superblock contains all the information about the configuration of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) the filing system.  The primary copy of the superblock is stored at an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) offset of 1024 bytes from the start of the device, and it is essential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) to mounting the filesystem.  Since it is so important, backup copies of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) the superblock are stored in block groups throughout the filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) The first version of ext2 (revision 0) stores a copy at the start of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) every block group, along with backups of the group descriptor block(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) Because this can consume a considerable amount of space for large
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) filesystems, later revisions can optionally reduce the number of backup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) copies by only putting backups in specific groups (this is the sparse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) superblock feature).  The groups chosen are 0, 1 and powers of 3, 5 and 7.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) The information in the superblock contains fields such as the total
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) number of inodes and blocks in the filesystem and how many are free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) how many inodes and blocks are in each block group, when the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) was mounted (and if it was cleanly unmounted), when it was modified,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) what version of the filesystem it is (see the Revisions section below)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) and which OS created it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) If the filesystem is revision 1 or higher, then there are extra fields,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) such as a volume name, a unique identification number, the inode size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) and space for optional filesystem features to store configuration info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) All fields in the superblock (as in all other ext2 structures) are stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) on the disc in little endian format, so a filesystem is portable between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) machines without having to know what machine it was created on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) Inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) The inode (index node) is a fundamental concept in the ext2 filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) Each object in the filesystem is represented by an inode.  The inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) structure contains pointers to the filesystem blocks which contain the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) data held in the object and all of the metadata about an object except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) its name.  The metadata about an object includes the permissions, owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) group, flags, size, number of blocks used, access time, change time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) modification time, deletion time, number of links, fragments, version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) (for NFS) and extended attributes (EAs) and/or Access Control Lists (ACLs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) There are some reserved fields which are currently unused in the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) structure and several which are overloaded.  One field is reserved for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) directory ACL if the inode is a directory and alternately for the top 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) bits of the file size if the inode is a regular file (allowing file sizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) larger than 2GB).  The translator field is unused under Linux, but is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) by the HURD to reference the inode of a program which will be used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) interpret this object.  Most of the remaining reserved fields have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) used up for both Linux and the HURD for larger owner and group fields,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) The HURD also has a larger mode field so it uses another of the remaining
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) fields to store the extra more bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) There are pointers to the first 12 blocks which contain the file's data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) in the inode.  There is a pointer to an indirect block (which contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) pointers to the next set of blocks), a pointer to a doubly-indirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) block (which contains pointers to indirect blocks) and a pointer to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) trebly-indirect block (which contains pointers to doubly-indirect blocks).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) The flags field contains some ext2-specific flags which aren't catered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) for by the standard chmod flags.  These flags can be listed with lsattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) and changed with the chattr command, and allow specific filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) behaviour on a per-file basis.  There are flags for secure deletion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) undeletable, compression, synchronous updates, immutability, append-only,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) dumpable, no-atime, indexed directories, and data-journaling.  Not all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) of these are supported yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) Directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) A directory is a filesystem object and has an inode just like a file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) It is a specially formatted file containing records which associate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) each name with an inode number.  Later revisions of the filesystem also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) encode the type of the object (file, directory, symlink, device, fifo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) socket) to avoid the need to check the inode itself for this information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) (support for taking advantage of this feature does not yet exist in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) Glibc 2.2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) The inode allocation code tries to assign inodes which are in the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) block group as the directory in which they are first created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) The current implementation of ext2 uses a singly-linked list to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) the filenames in the directory; a pending enhancement uses hashing of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) filenames to allow lookup without the need to scan the entire directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) The current implementation never removes empty directory blocks once they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) have been allocated to hold more files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) Special files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) -------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) Symbolic links are also filesystem objects with inodes.  They deserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) special mention because the data for them is stored within the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) itself if the symlink is less than 60 bytes long.  It uses the fields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) which would normally be used to store the pointers to data blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) This is a worthwhile optimisation as it we avoid allocating a full
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) block for the symlink, and most symlinks are less than 60 characters long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) Character and block special devices never have data blocks assigned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) them.  Instead, their device number is stored in the inode, again reusing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) the fields which would be used to point to the data blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) Reserved Space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) In ext2, there is a mechanism for reserving a certain number of blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) for a particular user (normally the super-user).  This is intended to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) allow for the system to continue functioning even if non-privileged users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) fill up all the space available to them (this is independent of filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) quotas).  It also keeps the filesystem from filling up entirely which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) helps combat fragmentation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) Filesystem check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) At boot time, most systems run a consistency check (e2fsck) on their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) filesystems.  The superblock of the ext2 filesystem contains several
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) fields which indicate whether fsck should actually run (since checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) the filesystem at boot can take a long time if it is large).  fsck will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) run if the filesystem was not cleanly unmounted, if the maximum mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) count has been exceeded or if the maximum time between checks has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) exceeded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) Feature Compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) The compatibility feature mechanism used in ext2 is sophisticated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) It safely allows features to be added to the filesystem, without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) unnecessarily sacrificing compatibility with older versions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) filesystem code.  The feature compatibility mechanism is not supported by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) the original revision 0 (EXT2_GOOD_OLD_REV) of ext2, but was introduced in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) revision 1.  There are three 32-bit fields, one for compatible features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) (COMPAT), one for read-only compatible (RO_COMPAT) features and one for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) incompatible (INCOMPAT) features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) These feature flags have specific meanings for the kernel as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) A COMPAT flag indicates that a feature is present in the filesystem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) but the on-disk format is 100% compatible with older on-disk formats, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) a kernel which didn't know anything about this feature could read/write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) the filesystem without any chance of corrupting the filesystem (or even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) making it inconsistent).  This is essentially just a flag which says
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) "this filesystem has a (hidden) feature" that the kernel or e2fsck may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) want to be aware of (more on e2fsck and feature flags later).  The ext3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) HAS_JOURNAL feature is a COMPAT flag because the ext3 journal is simply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) a regular file with data blocks in it so the kernel does not need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) take any special notice of it if it doesn't understand ext3 journaling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) An RO_COMPAT flag indicates that the on-disk format is 100% compatible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) with older on-disk formats for reading (i.e. the feature does not change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) the visible on-disk format).  However, an old kernel writing to such a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) filesystem would/could corrupt the filesystem, so this is prevented. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) most common such feature, SPARSE_SUPER, is an RO_COMPAT feature because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) sparse groups allow file data blocks where superblock/group descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) backups used to live, and ext2_free_blocks() refuses to free these blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) which would leading to inconsistent bitmaps.  An old kernel would also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) get an error if it tried to free a series of blocks which crossed a group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) boundary, but this is a legitimate layout in a SPARSE_SUPER filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) An INCOMPAT flag indicates the on-disk format has changed in some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) way that makes it unreadable by older kernels, or would otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) cause a problem if an old kernel tried to mount it.  FILETYPE is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) INCOMPAT flag because older kernels would think a filename was longer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) than 256 characters, which would lead to corrupt directory listings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) The COMPRESSION flag is an obvious INCOMPAT flag - if the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) doesn't understand compression, you would just get garbage back from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) read() instead of it automatically decompressing your data.  The ext3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) RECOVER flag is needed to prevent a kernel which does not understand the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) ext3 journal from mounting the filesystem without replaying the journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) For e2fsck, it needs to be more strict with the handling of these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) flags than the kernel.  If it doesn't understand ANY of the COMPAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) RO_COMPAT, or INCOMPAT flags it will refuse to check the filesystem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) because it has no way of verifying whether a given feature is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) or not.  Allowing e2fsck to succeed on a filesystem with an unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) feature is a false sense of security for the user.  Refusing to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) a filesystem with unknown features is a good incentive for the user to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) update to the latest e2fsck.  This also means that anyone adding feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) flags to ext2 also needs to update e2fsck to verify these features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) Metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) --------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) It is frequently claimed that the ext2 implementation of writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) asynchronous metadata is faster than the ffs synchronous metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) scheme but less reliable.  Both methods are equally resolvable by their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) respective fsck programs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) If you're exceptionally paranoid, there are 3 ways of making metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) writes synchronous on ext2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) - per-file if you have the program source: use the O_SYNC flag to open()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) - per-file if you don't have the source: use "chattr +S" on the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) - per-filesystem: add the "sync" option to mount (or in /etc/fstab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) the first and last are not ext2 specific but do force the metadata to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) be written synchronously.  See also Journaling below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) Limitations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) There are various limits imposed by the on-disk layout of ext2.  Other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) limits are imposed by the current implementation of the kernel code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) Many of the limits are determined at the time the filesystem is first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) created, and depend upon the block size chosen.  The ratio of inodes to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) data blocks is fixed at filesystem creation time, so the only way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) increase the number of inodes is to increase the size of the filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) No tools currently exist which can change the ratio of inodes to blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) Most of these limits could be overcome with slight changes in the on-disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) format and using a compatibility flag to signal the format change (at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) the expense of some compatibility).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) =====================  =======    =======    =======   ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) Filesystem block size      1kB        2kB        4kB        8kB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) =====================  =======    =======    =======   ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) File size limit           16GB      256GB     2048GB     2048GB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) Filesystem size limit   2047GB     8192GB    16384GB    32768GB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) =====================  =======    =======    =======   ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) There is a 2.4 kernel limit of 2048GB for a single block device, so no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) filesystem larger than that can be created at this time.  There is also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) an upper limit on the block size imposed by the page size of the kernel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) so 8kB blocks are only allowed on Alpha systems (and other architectures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) which support larger pages).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) There is an upper limit of 32000 subdirectories in a single directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) There is a "soft" upper limit of about 10-15k files in a single directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) with the current linear linked-list directory implementation.  This limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) stems from performance problems when creating and deleting (and also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) finding) files in such large directories.  Using a hashed directory index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) (under development) allows 100k-1M+ files in a single directory without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) performance problems (although RAM size becomes an issue at this point).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) The (meaningless) absolute upper limit of files in a single directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) (imposed by the file size, the realistic limit is obviously much less)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) is over 130 trillion files.  It would be higher except there are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) enough 4-character names to make up unique directory entries, so they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) have to be 8 character filenames, even then we are fairly close to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) running out of unique filenames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) Journaling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) ----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) A journaling extension to the ext2 code has been developed by Stephen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) Tweedie.  It avoids the risks of metadata corruption and the need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) wait for e2fsck to complete after a crash, without requiring a change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) to the on-disk ext2 layout.  In a nutshell, the journal is a regular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) file which stores whole metadata (and optionally data) blocks that have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) been modified, prior to writing them into the filesystem.  This means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) it is possible to add a journal to an existing ext2 filesystem without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) the need for data conversion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) When changes to the filesystem (e.g. a file is renamed) they are stored in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) a transaction in the journal and can either be complete or incomplete at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) the time of a crash.  If a transaction is complete at the time of a crash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) (or in the normal case where the system does not crash), then any blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) in that transaction are guaranteed to represent a valid filesystem state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) and are copied into the filesystem.  If a transaction is incomplete at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) the time of the crash, then there is no guarantee of consistency for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) the blocks in that transaction so they are discarded (which means any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) filesystem changes they represent are also lost).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) Check Documentation/filesystems/ext4/ if you want to read more about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ext4 and journaling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) References
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ==========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) =======================	===============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) The kernel source	file:/usr/src/linux/fs/ext2/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) e2fsprogs (e2fsck)	http://e2fsprogs.sourceforge.net/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) Design & Implementation	http://e2fsprogs.sourceforge.net/ext2intro.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) Journaling (ext3)	ftp://ftp.uk.linux.org/pub/linux/sct/fs/jfs/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) Filesystem Resizing	http://ext2resize.sourceforge.net/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) Compression [1]_	http://e2compr.sourceforge.net/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) =======================	===============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) Implementations for:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) =======================	===========================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) Windows 95/98/NT/2000	http://www.chrysocome.net/explore2fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) Windows 95 [1]_		http://www.yipton.net/content.html#FSDEXT2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) DOS client [1]_		ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) OS/2 [2]_		ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) RISC OS client		http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/IscaFS/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) =======================	===========================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .. [1] no longer actively developed/supported (as of Apr 2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .. [2] no longer actively developed/supported (as of Mar 2009)