Linux Audio

Check our new training course

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