Ext2: Difference between revisions

2,772 bytes added ,  1 year ago
→‎Base Superblock Fields: clarify the superblock block number field is also the starting block number
[unchecked revision][unchecked revision]
No edit summary
(→‎Base Superblock Fields: clarify the superblock block number field is also the starting block number)
 
(18 intermediate revisions by 9 users not shown)
Line 2:
The '''Second Extended Filesystem''' ('''ext2fs''') is a rewrite of the original ''Extended Filesystem'' and as such, is also based around the concept of "inodes." Ext2 served as the de facto filesystem of Linux for nearly a decade from the early 1990s to the early 2000s when it was superseded by the journaling file systems [[Ext3|ext3]] and [[ReiserFS]]. It has native support for UNIX ownership / access rights, symbolic- and hard-links, and other properties that are common among UNIX-like operating systems. Organizationally, it divides disk space up into groups called "block groups." Having these groups results in distribution of data across the disk which helps to minimize head movement as well as the impact of fragmentation. Further, some (if not all) groups are required to contain backups of important data that can be used to rebuild the file system in the event of disaster.
 
''Note: Most of the information here is based off of work done by Dave Poirier on the ext2-doc project (see the [[#Links|links section]]) which is graciously released under the [http://www.fsf.org/licenses/fdl.html GNU Free Documentation License]. Be sure to buy him a beer the next time you see him.''
'''Important Note: All values are little-endian unless otherwise specified'''
 
 
== Basic Concepts ==
'''Important Note: All values are little-endian unless otherwise specified'''
 
=== What is a Block? ===
Line 11:
 
=== What is a Block Group? ===
Blocks, along with inodes, are divvieddivided up into "block groups." These are nothing more than contiguous groups of blocks.
 
Each block group reserves a few of its blocks for special purposes such as:
Line 55:
| 16 || 19 || 4 || Total number of unallocated inodes
|-
| 20 || 23 || 4 || Block number of the block containing the superblock (also the starting block number, NOT always zero.)
|-
| 24 || 27 || 4 || ''log''<sub>2</sub> (block size) - 10. (In other words, the number to shift 1,024 to the left by to obtain the block size)
Line 132:
 
=== Extended Superblock Fields ===
These fields are only present if Major version (specified in the base superblock fields), is greater than or equal to 1.
{| {{Wikitable}}
! Starting
Line 209:
| 0x0002 || Directory entries contain a type field
|-
| 0x0004 || File system needs recoveryto replay its journal
|-
| 0x0008 || File system uses a journal device
Line 263:
Like blocks, each inode has a numerical address. It is extremely important to note that unlike block addresses, '''inode addresses start at 1'''.
 
With Ext2 versions prior to Major version 1, inodes 1 to 10 are reserved and should be in an allocated state. Starting with version 1, the first non-reserved inode is indicated via a field in the Superblock. Of the reserved inodes, number 2 has subjectively has the most significance as it is used for the root directory.
 
Inodes have a fixed size of either 128 for version 0 Ext2 file systems, or as dictated by the field in the Superblock for version 1 file systems. All inodes reside in inode tables that belong to block groups. Therefore, looking up an inode is simply a matter of determining which block group it belongs to and indexing that block group's inode table.
Line 300:
'''Triply Indirect Block Pointer''': Lastly, if a file needs still more space, it can use a triple indirect block. Again, this is an extension of the double indirect block. So, a triple indirect block contains addresses of double indirect blocks, which contain addresses of single indirect blocks, which contain address of data blocks. The inode structure has a "Triply Indirect Block Pointer" field that points to this block if present.
 
[http://en.wikipedia.org/wiki/File:Ext2-inode.gif This image from Wikipedia] illustrates what is described above pretty well.
 
=== Inode Data Structure ===
Line 321:
| 8 || 11 || 4 || Last Access Time (in [http://en.wikipedia.org/wiki/Unix_time POSIX time])
|-
| 12 || 15 || 4 || Last ChangeCreation Time (in [http://en.wikipedia.org/wiki/Unix_time POSIX time])
|-
| 16 || 19 || 4 || Last Modification time (in [http://en.wikipedia.org/wiki/Unix_time POSIX time])
Line 335:
| 32 || 35 || 4 || Flags ([[#Inode_Flags|see below]])
|-
| 36 || 39 || 4 || (Unused)[[#OS_Specific_Value_1|Operating System Specific value #1]]
|-
| 40 || 43 || 4 || Direct Block Pointer 0
Line 365:
| 92 || 95 || 4 || Doubly Indirect Block Pointer (Points to a block that is a list of block pointers to Singly Indirect Blocks)
|-
| 96 || 99 || 4 || Triply Indirect Block Pointer (Points to a block that is a list of block poitnerspointers to Doubly Indirect Blocks)
|-
| 100 || 103 || 4 || Generation number (Primarily used for NFS)
|-
| 104 || 107 || 4 || In Ext2 version 0, this field is reserved. In version >= 1, Extended attribute block (File ACL).
|-
| 108 || 111 || 4 || In Ext2 version 0, this field is reserved. In version >= 1, Upper 32 bits of file size /(if feature bit set) if it's a file, Directory ACL Yesif it's a /directory
|-
| 112 || 115 || 4 || Block address of fragment
|-
| 116 || 116127 || 112 || Fragment[[#OS_Specific_Value_2|Operating System indexSpecific inValue block#2]]
|-
| 117 || 117 || 1 || Fragment size
|-
| 118 || 119 || 2 || (Unused)
|-
| 120 || 121 || 2 || Upper 16 bits of user ID
|-
| 122 || 123 || 2 || Upper 16 bits of group ID
|-
| 124 || 127 || 4 || (Unused)
|}
 
Line 435 ⟶ 425:
| 0x100 || 00400 || [http://en.wikipedia.org/wiki/Filesystem_permissions#Traditional_Unix_permissions User—read permission]
|-
| 0x200 || 01000 || [http://en.wikipedia.org/wiki/Sticky_bit StickSticky Bit]
|-
| 0x400 || 02000 || Set group ID
Line 441 ⟶ 431:
| 0x800 || 04000 || Set user ID
|}
 
==== Inode Flags ====
{| {{Wikitable}}
Line 471 ⟶ 462:
| 0x00040000 || Journal file data
|}
==== OS Specific Value 1 ====
{| {{Wikitable}}
! Operating
System
! How they use this field
|-
| Linux || (reserved)
|-
| HURD || "translator"?
|-
| MASIX || (reserved)
|}
==== OS Specific Value 2 ====
{| {{Wikitable}}
! Operating
System
! How they use this field
|-
| Linux ||
{| {{Wikitable}}
! Starting
Byte
! Ending
Byte
! Size
in Bytes
! Field Description
|-
| 116 || 116 || 1 || Fragment number
|-
| 117 || 117 || 1 || Fragment size
|-
| 118 || 119 || 2 || (reserved)
|-
| 120 || 121 || 2 || High 16 bits of 32-bit User ID
|-
| 122 || 123 || 2 || High 16 bits of 32-bit Group ID
|-
| 124 || 127 || 4 || (reserved)
|}
|-
| HURD ||
{| {{Wikitable}}
! Starting
Byte
! Ending
Byte
! Size
in Bytes
! Field Description
|-
| 116 || 116 || 1 || Fragment number
|-
| 117 || 117 || 1 || Fragment size
|-
| 118 || 119 || 2 || High 16 bits of 32-bit "Type and Permissions" field
|-
| 120 || 121 || 2 || High 16 bits of 32-bit User ID
|-
| 122 || 123 || 2 || High 16 bits of 32-bit Group ID
|-
| 124 || 127 || 4 || User ID of author (if == 0xFFFFFFFF, the normal User ID will be used)
|}
|-
| MASIX ||
{| {{Wikitable}}
! Starting
Byte
! Ending
Byte
! Size
in Bytes
! Field Description
|-
| 116 || 116 || 1 || Fragment number
|-
| 117 || 117 || 1 || Fragment size
|-
| 118 || 127 || X || (reserved)
|}
|}
 
=== Directories ===
Directories are inodes which contain some number of "entries" as their contents. These entries are nothing more than a name/inode pair. For instance the inode corresponding to the root directory might have an entry with the name of "etc" and an inode value of 50. A directory inode stores these entries in a linked-list fashion in its contents blocks.
 
The root directory is Inode 2.
 
The total size of a directory entry may be longer then the length of the name would imply (The name may not span to the end of the record), and records have to be aligned to 4-byte boundaries. Directory entries are also not allowed to span multiple blocks on the file-system, so there may be empty space in-between directory entries. Empty space is however not allowed in-between directory entries, so any possible empty space will be used as part of the preceding record by increasing its record length to include the empty space. Empty space may also be equivalently marked by a separate directory entry with an inode number of zero, indicating that directory entry should be skipped.
 
=== Directory Entry ===
 
Line 488 ⟶ 564:
| 0 || 3 || 4 || Inode
|-
| 4 || 5 || 2 || RecordTotal Lengthsize (Willof getthis youentry to the(Including nextall recordsubfields)
|-
| 6 || 6 || 1 || Name Length least-significant 8 bits
|-
| 7 || 7 || 1 || [[#Directory_Entry_Type_Indicators|Type indicator]] (only if the feature bit for "directory entries have file type byte" is set, else this is the most-significant 8 bits of the Name Length)
|-
| 8 || 8+N-1 || N || Name characters
Line 498 ⟶ 574:
 
 
==== FiletypesDirectory Entry Type Indicators ====
 
{| {{Wikitable}}
|-
! Description
! Value
! Type Description
|-
| 0 || Unknown type
|EXT2_FT_UNKNOWN || 0
|-
|EXT2_FT_REG_FILE || 1
|-
| 1 || Regular file
|EXT2_FT_DIR || 2
|-
| 2 || Directory
|EXT2_FT_CHRDEV ||3
|-
| 3 || Character device
|EXT2_FT_BLKDEV ||4
|-
| 4 || Block device
|EXT2_FT_FIFO ||5
|-
|EXT2_FT_SOCK 5 ||6 FIFO
|-
| 6 || Socket
|EXT2_FT_SYMLINK ||7
|-
| 7 || Symbolic link (soft link)
|EXT2_FT_MAX ||8
|}
 
Line 536 ⟶ 610:
 
=== How To Read the Root Directory ===
The root directory's inode is defined to always be 2. Read/parse the contents of inode 2.
 
==See Links Also==
===External Links===
* [http://www.nongnu.org/ext2-doc/ ext2-doc project: Second Extended File System] - implementation-oriented documentation, describes internal structure in human language.
* [http://web.mit.edu/tytso/www/linux/ext2intro.html Design and Implementation of the Second Extended Filesystem] (overview)
* [http://ext2.sourceforge.net/2005-ols/paper-html/ State of the Art: Where we are with the Ext3 filesystem] - Paper by Mingming Cao, Theodore Y. Ts'o, Badari Pulavarty, and Suparna Bhattacharya describing extended features for ext2
 
[[Category:Filesystems]]
[[de:Ext2]]
Anonymous user