1
2 The Second Extended Filesystem
3 ==============================
4
5 ext2 was originally released in January 1993. Written by R\'emy Card,
6 Theodore Ts'o and Stephen Tweedie, it was a major rewrite of the
7 Extended Filesystem. It is currently (February 1999) the predominant
8 filesystem in use by Linux. There are also implementations available
9 for NetBSD, FreeBSD, the GNU HURD, Windows 95/98/NT, OS/2 and RISC OS.
10
11 Options
12 =======
13
14 When mounting an ext2 filesystem, the following options are accepted.
15 Defaults are marked with (*).
16
17 bsddf (*) Makes `df' act like BSD.
18 minixdf Makes `df' act like Minix.
19
20 check=none, nocheck Perform no checks upon the filesystem.
21 check=normal (*) Perform normal checks on the filesystem.
22 check=strict Perform extra checks on the filesystem.
23
24 debug For developers only.
25
26 errors=continue (*) Keep going on a filesystem error.
27 errors=remount-ro Remount the filesystem read-only on an error.
28 errors=panic Panic and halt the machine if an error occurs.
29
30 grpid, bsdgroups Give objects the same group ID as their parent.
31 nogrpid, sysvgroups (*) New objects have the group ID of their creator.
32
33 resuid=n The user which may use the reserved blocks.
34 resgid=n The group which may use the reserved blocks.
35
36 sb=n Use alternate superblock at this location.
37
38 grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
39
40
41 Specification
42 =============
43
44 ext2 shares many properties with traditional Unix filesystems. It has
45 the concepts of blocks, inodes and directories. It has space in the
46 specification for Access Control Lists (ACLs), fragments, undeletion and
47 compression though these are not yet implemented (some are available as
48 separate patches). There is also a versioning mechanism to allow new
49 features (such as journalling) to be added in a maximally compatible
50 manner.
51
52 Blocks
53 ------
54
55 The space in the device or file is split up into blocks. These are
56 a fixed size, of 1024, 2048 or 4096 bytes, which is decided when the
57 filesystem is created. Smaller blocks mean less wasted space per file,
58 but require slightly more accounting overhead.
59
60 Blocks are clustered into block groups in order to reduce fragmentation
61 and minimise the amount of head seeking when reading a large amount of
62 consecutive data. Each block group has a descriptor and the array of
63 descriptors is stored immediately after the superblock. Two blocks at
64 the start of each group are reserved for the block usage bitmap and
65 the inode usage bitmap which show which blocks and inodes are used.
66 Since each bitmap fits in a block, this means that the maximum size of
67 a block group is 8 times the size of a block.
68
69 The first (non-reserved) blocks in the block group are designated as
70 the inode table for the block and the remainder are the data blocks.
71 The block allocation algorithm attempts to allocate data blocks in the
72 same block group as the inode which contains them.
73
74 The Superblock
75 --------------
76
77 The superblock contains all the information about the configuration of
78 the filing system. It is stored in block 1 of the filesystem (numbering
79 from 0) and it is essential to mounting it. Since it is so important,
80 backup copies of the superblock are stored in block groups throughout
81 the filesystem. The first revision of ext2 stores a copy at the start
82 of every block group. Later revisions can store a copy in only some
83 block groups to reduce the amount of redundancy on large filesystems.
84 The groups chosen are 0, 1 and powers of 3, 5 and 7.
85
86 The information in the superblock contains fields such as how many
87 inodes and blocks are in the filesystem and how many are unused, how
88 many inodes and blocks are in a block group, when the filesystem was
89 mounted, when it was modified, what version of the filesystem it is
90 (see the Revisions section below) and which OS created it.
91
92 If the revision of the filesystem is recent enough then there are extra
93 fields, such as a volume name, a unique identifier, the inode size,
94 support for compression, block preallocation and creating fewer backup
95 superblocks.
96
97 All fields in the superblock (as in all other ext2 structures) are stored
98 on the disc in little endian format, so a filesystem is portable between
99 machines without having to know what machine it was created on.
100
101 Inodes
102 ------
103
104 The inode (index node) is the fundamental concept in the ext2 filesystem.
105 Each object in the filesystem is represented by an inode. The inode
106 structure contains pointers to the filesystem blocks which contain the
107 data held in the object and all of the metadata about an object except
108 its name. The metadata about an object includes the permissions, owner,
109 group, flags, size, number of blocks used, access time, change time,
110 modification time, deletion time, number of links, fragments, version
111 (for NFS) and ACLs.
112
113 There are several reserved fields which are currently unused in the inode
114 structure and several which are overloaded. One field is used for the
115 directory ACL if the inode is a directory and for the top 32 bits of
116 the file size if the inode is a regular file. The translator field is
117 unused under Linux, but is used by the HURD to reference the inode of
118 a program which will be used to interpret this object. The HURD also
119 has larger permissions, owner and group fields, so it uses some of the
120 other unused by Linux fields to store the extra bits.
121
122 There are pointers to the first 12 blocks which contain the file's data
123 in the inode. There is a pointer to an indirect block (which contains
124 pointers to the next set of blocks), a pointer to a doubly-indirect
125 block (which contains pointers to indirect blocks) and a pointer to a
126 trebly-indirect block (which contains pointers to doubly-indirect blocks).
127
128 The flags field contains some ext2-specific flags which aren't catered
129 for by the standard chmod flags. These flags can be listed with
130 lsattr and changed with the chattr command. There are flags for secure
131 deletion, undeletable, compression, synchronous updates, immutability,
132 append-only, dumpable, no-atime, and btree directories. Not all of
133 these are supported yet.
134
135 Directories
136 -----------
137
138 A directory is a filesystem object and has an inode just like a file.
139 It is a specially formatted file containing records which associate
140 each name with an inode number. Later revisions of the filesystem also
141 encode the type of the object (file, directory, symlink, device, fifo,
142 socket) in the directory entry for speed. The current implementation
143 of ext2 uses a linked list in directories; a planned enhancement will
144 use btrees instead. The current implementation also never shrinks
145 directories once they have grown to accommodate more files.
146
147 Special files
148 -------------
149
150 Symbolic links are also filesystem objects with inodes. They deserve
151 special mention because the data for them is stored within the inode
152 itself if the symlink is less than 60 bytes long. It uses the fields
153 which would normally be used to store the pointers to blocks to store
154 the data. This is a worthwhile optimisation to make as it does not then
155 take up a block, and most symlinks are less than 60 characters long.
156
157 Character and block special devices never have data blocks assigned to
158 them. Instead, their device number is stored in the inode, again reusing
159 the fields which would be used to point to the blocks.
160
161 Revisions
162 ---------
163
164 The revisioning mechanism used in ext2 is sophisticated. The revisioning
165 mechanism is not supported by version 0 (EXT2_GOOD_OLD_REV) of ext2 but
166 was introduced in version 1. There are three 32-bit fields, one for
167 compatible features, one for read-only compatible features and one for
168 incompatible features.
169
170 Reserved Space
171 --------------
172
173 In ext2, there is a mechanism for reserving a certain number of blocks
174 for a particular user (normally the super-user). This is intended to
175 allow for the system to continue functioning even if a user fills up
176 all the available space. It also keeps the filesystem from filling up
177 entirely which helps combat fragmentation.
178
179 Filesystem check
180 ----------------
181
182 At boot time, most systems run a consistency check (e2fsck) on their
183 filesystems. The superblock of the ext2 filesystem contains several
184 fields which indicate whether fsck should actually run (since checking
185 the filesystem at boot can take a long time if it is large). fsck will
186 run if the filesystem was not unmounted without errors, if the maximum
187 mount count has been exceeded or if the maximum time between checks has
188 been exceeded.
189
190 Metadata
191 --------
192
193 It is frequently claimed that the ext2 implementation of writing
194 asynchronous metadata is faster than the ffs synchronous metadata
195 scheme but less reliable. Both methods are equally resolvable by their
196 respective fsck programs.
197
198 If you're exceptionally paranoid, there are 3 ways of making metadata
199 writes synchronous:
200
201 per-file if you have the source: use the O_SYNC argument to open()
202 per-file if you don't have the source: use chattr +S
203 per-filesystem: mount -o sync
204
205 the first and last are not ext2 specific but do force the metadata to
206 be written synchronously.
207
208 References
209 ==========
210
211 The kernel source file:/usr/src/linux/fs/ext2/
212 Design & Implementation http://khg.redhat.com/HyperNews/get/fs/ext2intro.html
213 Compression http://debs.fuller.edu/e2compr/
214 ACL support ftp://tsx-11.mit.edu/pub/linux/ALPHA/ext2fs
215 updated ACL work http://aerobee.informatik.uni-bremen.de/acl_eng.html
216 e2fsprogs ftp://tsx-11.mit.edu/pub/linux/packages/ext2fs
217
218 Implementations for:
219 OS/2 http://perso.wanadoo.fr/matthieu.willm/ext2-os2/
220 Windows 95 http://www.yipton.demon.co.uk/
221 Windows NT http://www.cyco.nl/~andreys/ext2fsnt/
222 http://uranus.it.swin.edu.au/~jn/linux/Explore2fs.htm
223 DOS client ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
224 RISC OS client ftp://ftp.barnet.ac.uk/pub/acorn/armlinux/iscafs/
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.