18a98ec7cSDarrick J. Wong.. SPDX-License-Identifier: GPL-2.0
28a98ec7cSDarrick J. Wong
38a98ec7cSDarrick J. WongIndex Nodes
48a98ec7cSDarrick J. Wong-----------
58a98ec7cSDarrick J. Wong
68a98ec7cSDarrick J. WongIn a regular UNIX filesystem, the inode stores all the metadata
78a98ec7cSDarrick J. Wongpertaining to the file (time stamps, block maps, extended attributes,
88a98ec7cSDarrick J. Wongetc), not the directory entry. To find the information associated with a
98a98ec7cSDarrick J. Wongfile, one must traverse the directory files to find the directory entry
108a98ec7cSDarrick J. Wongassociated with a file, then load the inode to find the metadata for
118a98ec7cSDarrick J. Wongthat file. ext4 appears to cheat (for performance reasons) a little bit
128a98ec7cSDarrick J. Wongby storing a copy of the file type (normally stored in the inode) in the
138a98ec7cSDarrick J. Wongdirectory entry. (Compare all this to FAT, which stores all the file
148a98ec7cSDarrick J. Wonginformation directly in the directory entry, but does not support hard
158a98ec7cSDarrick J. Wonglinks and is in general more seek-happy than ext4 due to its simpler
168a98ec7cSDarrick J. Wongblock allocator and extensive use of linked lists.)
178a98ec7cSDarrick J. Wong
188a98ec7cSDarrick J. WongThe inode table is a linear array of ``struct ext4_inode``. The table is
198a98ec7cSDarrick J. Wongsized to have enough blocks to store at least
208a98ec7cSDarrick J. Wong``sb.s_inode_size * sb.s_inodes_per_group`` bytes. The number of the
218a98ec7cSDarrick J. Wongblock group containing an inode can be calculated as
228a98ec7cSDarrick J. Wong``(inode_number - 1) / sb.s_inodes_per_group``, and the offset into the
238a98ec7cSDarrick J. Wonggroup's table is ``(inode_number - 1) % sb.s_inodes_per_group``. There
248a98ec7cSDarrick J. Wongis no inode 0.
258a98ec7cSDarrick J. Wong
268a98ec7cSDarrick J. WongThe inode checksum is calculated against the FS UUID, the inode number,
278a98ec7cSDarrick J. Wongand the inode structure itself.
288a98ec7cSDarrick J. Wong
298a98ec7cSDarrick J. WongThe inode table entry is laid out in ``struct ext4_inode``.
308a98ec7cSDarrick J. Wong
318a98ec7cSDarrick J. Wong.. list-table::
328a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
338a98ec7cSDarrick J. Wong   :header-rows: 1
348a98ec7cSDarrick J. Wong   :class: longtable
358a98ec7cSDarrick J. Wong
368a98ec7cSDarrick J. Wong   * - Offset
378a98ec7cSDarrick J. Wong     - Size
388a98ec7cSDarrick J. Wong     - Name
398a98ec7cSDarrick J. Wong     - Description
408a98ec7cSDarrick J. Wong   * - 0x0
41*3103084aSWang Jianjian     - __le16
42*3103084aSWang Jianjian     - i_mode
438a98ec7cSDarrick J. Wong     - File mode. See the table i_mode_ below.
448a98ec7cSDarrick J. Wong   * - 0x2
45*3103084aSWang Jianjian     - __le16
46*3103084aSWang Jianjian     - i_uid
478a98ec7cSDarrick J. Wong     - Lower 16-bits of Owner UID.
488a98ec7cSDarrick J. Wong   * - 0x4
49*3103084aSWang Jianjian     - __le32
50*3103084aSWang Jianjian     - i_size_lo
518a98ec7cSDarrick J. Wong     - Lower 32-bits of size in bytes.
528a98ec7cSDarrick J. Wong   * - 0x8
53*3103084aSWang Jianjian     - __le32
54*3103084aSWang Jianjian     - i_atime
55*3103084aSWang Jianjian     - Last access time, in seconds since the epoch. However, if the EA_INODE
568a98ec7cSDarrick J. Wong       inode flag is set, this inode stores an extended attribute value and
578a98ec7cSDarrick J. Wong       this field contains the checksum of the value.
588a98ec7cSDarrick J. Wong   * - 0xC
59*3103084aSWang Jianjian     - __le32
60*3103084aSWang Jianjian     - i_ctime
618a98ec7cSDarrick J. Wong     - Last inode change time, in seconds since the epoch. However, if the
62*3103084aSWang Jianjian       EA_INODE inode flag is set, this inode stores an extended attribute
638a98ec7cSDarrick J. Wong       value and this field contains the lower 32 bits of the attribute value's
648a98ec7cSDarrick J. Wong       reference count.
658a98ec7cSDarrick J. Wong   * - 0x10
66*3103084aSWang Jianjian     - __le32
67*3103084aSWang Jianjian     - i_mtime
688a98ec7cSDarrick J. Wong     - Last data modification time, in seconds since the epoch. However, if the
69*3103084aSWang Jianjian       EA_INODE inode flag is set, this inode stores an extended attribute
708a98ec7cSDarrick J. Wong       value and this field contains the number of the inode that owns the
718a98ec7cSDarrick J. Wong       extended attribute.
728a98ec7cSDarrick J. Wong   * - 0x14
73*3103084aSWang Jianjian     - __le32
74*3103084aSWang Jianjian     - i_dtime
758a98ec7cSDarrick J. Wong     - Deletion Time, in seconds since the epoch.
768a98ec7cSDarrick J. Wong   * - 0x18
77*3103084aSWang Jianjian     - __le16
78*3103084aSWang Jianjian     - i_gid
798a98ec7cSDarrick J. Wong     - Lower 16-bits of GID.
808a98ec7cSDarrick J. Wong   * - 0x1A
81*3103084aSWang Jianjian     - __le16
82*3103084aSWang Jianjian     - i_links_count
838a98ec7cSDarrick J. Wong     - Hard link count. Normally, ext4 does not permit an inode to have more
848a98ec7cSDarrick J. Wong       than 65,000 hard links. This applies to files as well as directories,
858a98ec7cSDarrick J. Wong       which means that there cannot be more than 64,998 subdirectories in a
868a98ec7cSDarrick J. Wong       directory (each subdirectory's '..' entry counts as a hard link, as does
87*3103084aSWang Jianjian       the '.' entry in the directory itself). With the DIR_NLINK feature
888a98ec7cSDarrick J. Wong       enabled, ext4 supports more than 64,998 subdirectories by setting this
898a98ec7cSDarrick J. Wong       field to 1 to indicate that the number of hard links is not known.
908a98ec7cSDarrick J. Wong   * - 0x1C
91*3103084aSWang Jianjian     - __le32
92*3103084aSWang Jianjian     - i_blocks_lo
93*3103084aSWang Jianjian     - Lower 32-bits of “block” count. If the huge_file feature flag is not
948a98ec7cSDarrick J. Wong       set on the filesystem, the file consumes ``i_blocks_lo`` 512-byte blocks
95*3103084aSWang Jianjian       on disk. If huge_file is set and EXT4_HUGE_FILE_FL is NOT set in
968a98ec7cSDarrick J. Wong       ``inode.i_flags``, then the file consumes ``i_blocks_lo + (i_blocks_hi
97*3103084aSWang Jianjian       << 32)`` 512-byte blocks on disk. If huge_file is set and
98*3103084aSWang Jianjian       EXT4_HUGE_FILE_FL IS set in ``inode.i_flags``, then this file
998a98ec7cSDarrick J. Wong       consumes (``i_blocks_lo + i_blocks_hi`` << 32) filesystem blocks on
1008a98ec7cSDarrick J. Wong       disk.
1018a98ec7cSDarrick J. Wong   * - 0x20
102*3103084aSWang Jianjian     - __le32
103*3103084aSWang Jianjian     - i_flags
1048a98ec7cSDarrick J. Wong     - Inode flags. See the table i_flags_ below.
1058a98ec7cSDarrick J. Wong   * - 0x24
1068a98ec7cSDarrick J. Wong     - 4 bytes
107*3103084aSWang Jianjian     - i_osd1
1088a98ec7cSDarrick J. Wong     - See the table i_osd1_ for more details.
1098a98ec7cSDarrick J. Wong   * - 0x28
1108a98ec7cSDarrick J. Wong     - 60 bytes
111*3103084aSWang Jianjian     - i_block[EXT4_N_BLOCKS=15]
112*3103084aSWang Jianjian     - Block map or extent tree. See the section “The Contents of inode.i_block”.
1138a98ec7cSDarrick J. Wong   * - 0x64
114*3103084aSWang Jianjian     - __le32
115*3103084aSWang Jianjian     - i_generation
1168a98ec7cSDarrick J. Wong     - File version (for NFS).
1178a98ec7cSDarrick J. Wong   * - 0x68
118*3103084aSWang Jianjian     - __le32
119*3103084aSWang Jianjian     - i_file_acl_lo
1208a98ec7cSDarrick J. Wong     - Lower 32-bits of extended attribute block. ACLs are of course one of
1218a98ec7cSDarrick J. Wong       many possible extended attributes; I think the name of this field is a
1228a98ec7cSDarrick J. Wong       result of the first use of extended attributes being for ACLs.
1238a98ec7cSDarrick J. Wong   * - 0x6C
124*3103084aSWang Jianjian     - __le32
125*3103084aSWang Jianjian     - i_size_high / i_dir_acl
1268a98ec7cSDarrick J. Wong     - Upper 32-bits of file/directory size. In ext2/3 this field was named
127*3103084aSWang Jianjian       i_dir_acl, though it was usually set to zero and never used.
1288a98ec7cSDarrick J. Wong   * - 0x70
129*3103084aSWang Jianjian     - __le32
130*3103084aSWang Jianjian     - i_obso_faddr
1318a98ec7cSDarrick J. Wong     - (Obsolete) fragment address.
1328a98ec7cSDarrick J. Wong   * - 0x74
1338a98ec7cSDarrick J. Wong     - 12 bytes
134*3103084aSWang Jianjian     - i_osd2
1358a98ec7cSDarrick J. Wong     - See the table i_osd2_ for more details.
1368a98ec7cSDarrick J. Wong   * - 0x80
137*3103084aSWang Jianjian     - __le16
138*3103084aSWang Jianjian     - i_extra_isize
1398a98ec7cSDarrick J. Wong     - Size of this inode - 128. Alternately, the size of the extended inode
1408a98ec7cSDarrick J. Wong       fields beyond the original ext2 inode, including this field.
1418a98ec7cSDarrick J. Wong   * - 0x82
142*3103084aSWang Jianjian     - __le16
143*3103084aSWang Jianjian     - i_checksum_hi
1448a98ec7cSDarrick J. Wong     - Upper 16-bits of the inode checksum.
1458a98ec7cSDarrick J. Wong   * - 0x84
146*3103084aSWang Jianjian     - __le32
147*3103084aSWang Jianjian     - i_ctime_extra
1488a98ec7cSDarrick J. Wong     - Extra change time bits. This provides sub-second precision. See Inode
1498a98ec7cSDarrick J. Wong       Timestamps section.
1508a98ec7cSDarrick J. Wong   * - 0x88
151*3103084aSWang Jianjian     - __le32
152*3103084aSWang Jianjian     - i_mtime_extra
1538a98ec7cSDarrick J. Wong     - Extra modification time bits. This provides sub-second precision.
1548a98ec7cSDarrick J. Wong   * - 0x8C
155*3103084aSWang Jianjian     - __le32
156*3103084aSWang Jianjian     - i_atime_extra
1578a98ec7cSDarrick J. Wong     - Extra access time bits. This provides sub-second precision.
1588a98ec7cSDarrick J. Wong   * - 0x90
159*3103084aSWang Jianjian     - __le32
160*3103084aSWang Jianjian     - i_crtime
1618a98ec7cSDarrick J. Wong     - File creation time, in seconds since the epoch.
1628a98ec7cSDarrick J. Wong   * - 0x94
163*3103084aSWang Jianjian     - __le32
164*3103084aSWang Jianjian     - i_crtime_extra
1658a98ec7cSDarrick J. Wong     - Extra file creation time bits. This provides sub-second precision.
1668a98ec7cSDarrick J. Wong   * - 0x98
167*3103084aSWang Jianjian     - __le32
168*3103084aSWang Jianjian     - i_version_hi
1698a98ec7cSDarrick J. Wong     - Upper 32-bits for version number.
1708a98ec7cSDarrick J. Wong   * - 0x9C
171*3103084aSWang Jianjian     - __le32
172*3103084aSWang Jianjian     - i_projid
1738a98ec7cSDarrick J. Wong     - Project ID.
1748a98ec7cSDarrick J. Wong
1758a98ec7cSDarrick J. Wong.. _i_mode:
1768a98ec7cSDarrick J. Wong
1778a98ec7cSDarrick J. WongThe ``i_mode`` value is a combination of the following flags:
1788a98ec7cSDarrick J. Wong
1798a98ec7cSDarrick J. Wong.. list-table::
1808a98ec7cSDarrick J. Wong   :widths: 16 64
1818a98ec7cSDarrick J. Wong   :header-rows: 1
1828a98ec7cSDarrick J. Wong
1838a98ec7cSDarrick J. Wong   * - Value
1848a98ec7cSDarrick J. Wong     - Description
1858a98ec7cSDarrick J. Wong   * - 0x1
186*3103084aSWang Jianjian     - S_IXOTH (Others may execute)
1878a98ec7cSDarrick J. Wong   * - 0x2
188*3103084aSWang Jianjian     - S_IWOTH (Others may write)
1898a98ec7cSDarrick J. Wong   * - 0x4
190*3103084aSWang Jianjian     - S_IROTH (Others may read)
1918a98ec7cSDarrick J. Wong   * - 0x8
192*3103084aSWang Jianjian     - S_IXGRP (Group members may execute)
1938a98ec7cSDarrick J. Wong   * - 0x10
194*3103084aSWang Jianjian     - S_IWGRP (Group members may write)
1958a98ec7cSDarrick J. Wong   * - 0x20
196*3103084aSWang Jianjian     - S_IRGRP (Group members may read)
1978a98ec7cSDarrick J. Wong   * - 0x40
198*3103084aSWang Jianjian     - S_IXUSR (Owner may execute)
1998a98ec7cSDarrick J. Wong   * - 0x80
200*3103084aSWang Jianjian     - S_IWUSR (Owner may write)
2018a98ec7cSDarrick J. Wong   * - 0x100
202*3103084aSWang Jianjian     - S_IRUSR (Owner may read)
2038a98ec7cSDarrick J. Wong   * - 0x200
204*3103084aSWang Jianjian     - S_ISVTX (Sticky bit)
2058a98ec7cSDarrick J. Wong   * - 0x400
206*3103084aSWang Jianjian     - S_ISGID (Set GID)
2078a98ec7cSDarrick J. Wong   * - 0x800
208*3103084aSWang Jianjian     - S_ISUID (Set UID)
2098a98ec7cSDarrick J. Wong   * -
2108a98ec7cSDarrick J. Wong     - These are mutually-exclusive file types:
2118a98ec7cSDarrick J. Wong   * - 0x1000
212*3103084aSWang Jianjian     - S_IFIFO (FIFO)
2138a98ec7cSDarrick J. Wong   * - 0x2000
214*3103084aSWang Jianjian     - S_IFCHR (Character device)
2158a98ec7cSDarrick J. Wong   * - 0x4000
216*3103084aSWang Jianjian     - S_IFDIR (Directory)
2178a98ec7cSDarrick J. Wong   * - 0x6000
218*3103084aSWang Jianjian     - S_IFBLK (Block device)
2198a98ec7cSDarrick J. Wong   * - 0x8000
220*3103084aSWang Jianjian     - S_IFREG (Regular file)
2218a98ec7cSDarrick J. Wong   * - 0xA000
222*3103084aSWang Jianjian     - S_IFLNK (Symbolic link)
2238a98ec7cSDarrick J. Wong   * - 0xC000
224*3103084aSWang Jianjian     - S_IFSOCK (Socket)
2258a98ec7cSDarrick J. Wong
2268a98ec7cSDarrick J. Wong.. _i_flags:
2278a98ec7cSDarrick J. Wong
2288a98ec7cSDarrick J. WongThe ``i_flags`` field is a combination of these values:
2298a98ec7cSDarrick J. Wong
2308a98ec7cSDarrick J. Wong.. list-table::
2318a98ec7cSDarrick J. Wong   :widths: 16 64
2328a98ec7cSDarrick J. Wong   :header-rows: 1
2338a98ec7cSDarrick J. Wong
2348a98ec7cSDarrick J. Wong   * - Value
2358a98ec7cSDarrick J. Wong     - Description
2368a98ec7cSDarrick J. Wong   * - 0x1
237*3103084aSWang Jianjian     - This file requires secure deletion (EXT4_SECRM_FL). (not implemented)
2388a98ec7cSDarrick J. Wong   * - 0x2
2398a98ec7cSDarrick J. Wong     - This file should be preserved, should undeletion be desired
240*3103084aSWang Jianjian       (EXT4_UNRM_FL). (not implemented)
2418a98ec7cSDarrick J. Wong   * - 0x4
242*3103084aSWang Jianjian     - File is compressed (EXT4_COMPR_FL). (not really implemented)
2438a98ec7cSDarrick J. Wong   * - 0x8
244*3103084aSWang Jianjian     - All writes to the file must be synchronous (EXT4_SYNC_FL).
2458a98ec7cSDarrick J. Wong   * - 0x10
246*3103084aSWang Jianjian     - File is immutable (EXT4_IMMUTABLE_FL).
2478a98ec7cSDarrick J. Wong   * - 0x20
248*3103084aSWang Jianjian     - File can only be appended (EXT4_APPEND_FL).
2498a98ec7cSDarrick J. Wong   * - 0x40
250*3103084aSWang Jianjian     - The dump(1) utility should not dump this file (EXT4_NODUMP_FL).
2518a98ec7cSDarrick J. Wong   * - 0x80
252*3103084aSWang Jianjian     - Do not update access time (EXT4_NOATIME_FL).
2538a98ec7cSDarrick J. Wong   * - 0x100
254*3103084aSWang Jianjian     - Dirty compressed file (EXT4_DIRTY_FL). (not used)
2558a98ec7cSDarrick J. Wong   * - 0x200
256*3103084aSWang Jianjian     - File has one or more compressed clusters (EXT4_COMPRBLK_FL). (not used)
2578a98ec7cSDarrick J. Wong   * - 0x400
258*3103084aSWang Jianjian     - Do not compress file (EXT4_NOCOMPR_FL). (not used)
2598a98ec7cSDarrick J. Wong   * - 0x800
260*3103084aSWang Jianjian     - Encrypted inode (EXT4_ENCRYPT_FL). This bit value previously was
261*3103084aSWang Jianjian       EXT4_ECOMPR_FL (compression error), which was never used.
2628a98ec7cSDarrick J. Wong   * - 0x1000
263*3103084aSWang Jianjian     - Directory has hashed indexes (EXT4_INDEX_FL).
2648a98ec7cSDarrick J. Wong   * - 0x2000
265*3103084aSWang Jianjian     - AFS magic directory (EXT4_IMAGIC_FL).
2668a98ec7cSDarrick J. Wong   * - 0x4000
2678a98ec7cSDarrick J. Wong     - File data must always be written through the journal
268*3103084aSWang Jianjian       (EXT4_JOURNAL_DATA_FL).
2698a98ec7cSDarrick J. Wong   * - 0x8000
270*3103084aSWang Jianjian     - File tail should not be merged (EXT4_NOTAIL_FL). (not used by ext4)
2718a98ec7cSDarrick J. Wong   * - 0x10000
2728a98ec7cSDarrick J. Wong     - All directory entry data should be written synchronously (see
273*3103084aSWang Jianjian       ``dirsync``) (EXT4_DIRSYNC_FL).
2748a98ec7cSDarrick J. Wong   * - 0x20000
275*3103084aSWang Jianjian     - Top of directory hierarchy (EXT4_TOPDIR_FL).
2768a98ec7cSDarrick J. Wong   * - 0x40000
277*3103084aSWang Jianjian     - This is a huge file (EXT4_HUGE_FILE_FL).
2788a98ec7cSDarrick J. Wong   * - 0x80000
279*3103084aSWang Jianjian     - Inode uses extents (EXT4_EXTENTS_FL).
28084fb7ca4SEric Biggers   * - 0x100000
281*3103084aSWang Jianjian     - Verity protected file (EXT4_VERITY_FL).
2828a98ec7cSDarrick J. Wong   * - 0x200000
2838a98ec7cSDarrick J. Wong     - Inode stores a large extended attribute value in its data blocks
284*3103084aSWang Jianjian       (EXT4_EA_INODE_FL).
2858a98ec7cSDarrick J. Wong   * - 0x400000
286*3103084aSWang Jianjian     - This file has blocks allocated past EOF (EXT4_EOFBLOCKS_FL).
2878a98ec7cSDarrick J. Wong       (deprecated)
2888a98ec7cSDarrick J. Wong   * - 0x01000000
2898a98ec7cSDarrick J. Wong     - Inode is a snapshot (``EXT4_SNAPFILE_FL``). (not in mainline)
2908a98ec7cSDarrick J. Wong   * - 0x04000000
2918a98ec7cSDarrick J. Wong     - Snapshot is being deleted (``EXT4_SNAPFILE_DELETED_FL``). (not in
2928a98ec7cSDarrick J. Wong       mainline)
2938a98ec7cSDarrick J. Wong   * - 0x08000000
2948a98ec7cSDarrick J. Wong     - Snapshot shrink has completed (``EXT4_SNAPFILE_SHRUNK_FL``). (not in
2958a98ec7cSDarrick J. Wong       mainline)
2968a98ec7cSDarrick J. Wong   * - 0x10000000
297*3103084aSWang Jianjian     - Inode has inline data (EXT4_INLINE_DATA_FL).
2988a98ec7cSDarrick J. Wong   * - 0x20000000
299*3103084aSWang Jianjian     - Create children with the same project ID (EXT4_PROJINHERIT_FL).
3008a98ec7cSDarrick J. Wong   * - 0x80000000
301*3103084aSWang Jianjian     - Reserved for ext4 library (EXT4_RESERVED_FL).
3028a98ec7cSDarrick J. Wong   * -
3038a98ec7cSDarrick J. Wong     - Aggregate flags:
30484fb7ca4SEric Biggers   * - 0x705BDFFF
3058a98ec7cSDarrick J. Wong     - User-visible flags.
30684fb7ca4SEric Biggers   * - 0x604BC0FF
307*3103084aSWang Jianjian     - User-modifiable flags. Note that while EXT4_JOURNAL_DATA_FL and
308*3103084aSWang Jianjian       EXT4_EXTENTS_FL can be set with setattr, they are not in the kernel's
309*3103084aSWang Jianjian       EXT4_FL_USER_MODIFIABLE mask, since it needs to handle the setting of
3108a98ec7cSDarrick J. Wong       these flags in a special manner and they are masked out of the set of
311*3103084aSWang Jianjian       flags that are saved directly to i_flags.
3128a98ec7cSDarrick J. Wong
3138a98ec7cSDarrick J. Wong.. _i_osd1:
3148a98ec7cSDarrick J. Wong
3158a98ec7cSDarrick J. WongThe ``osd1`` field has multiple meanings depending on the creator:
3168a98ec7cSDarrick J. Wong
3178a98ec7cSDarrick J. WongLinux:
3188a98ec7cSDarrick J. Wong
3198a98ec7cSDarrick J. Wong.. list-table::
3208a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
3218a98ec7cSDarrick J. Wong   :header-rows: 1
3228a98ec7cSDarrick J. Wong
3238a98ec7cSDarrick J. Wong   * - Offset
3248a98ec7cSDarrick J. Wong     - Size
3258a98ec7cSDarrick J. Wong     - Name
3268a98ec7cSDarrick J. Wong     - Description
3278a98ec7cSDarrick J. Wong   * - 0x0
328*3103084aSWang Jianjian     - __le32
329*3103084aSWang Jianjian     - l_i_version
330*3103084aSWang Jianjian     - Inode version. However, if the EA_INODE inode flag is set, this inode
3318a98ec7cSDarrick J. Wong       stores an extended attribute value and this field contains the upper 32
3328a98ec7cSDarrick J. Wong       bits of the attribute value's reference count.
3338a98ec7cSDarrick J. Wong
3348a98ec7cSDarrick J. WongHurd:
3358a98ec7cSDarrick J. Wong
3368a98ec7cSDarrick J. Wong.. list-table::
3378a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
3388a98ec7cSDarrick J. Wong   :header-rows: 1
3398a98ec7cSDarrick J. Wong
3408a98ec7cSDarrick J. Wong   * - Offset
3418a98ec7cSDarrick J. Wong     - Size
3428a98ec7cSDarrick J. Wong     - Name
3438a98ec7cSDarrick J. Wong     - Description
3448a98ec7cSDarrick J. Wong   * - 0x0
345*3103084aSWang Jianjian     - __le32
346*3103084aSWang Jianjian     - h_i_translator
3478a98ec7cSDarrick J. Wong     - ??
3488a98ec7cSDarrick J. Wong
3498a98ec7cSDarrick J. WongMasix:
3508a98ec7cSDarrick J. Wong
3518a98ec7cSDarrick J. Wong.. list-table::
3528a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
3538a98ec7cSDarrick J. Wong   :header-rows: 1
3548a98ec7cSDarrick J. Wong
3558a98ec7cSDarrick J. Wong   * - Offset
3568a98ec7cSDarrick J. Wong     - Size
3578a98ec7cSDarrick J. Wong     - Name
3588a98ec7cSDarrick J. Wong     - Description
3598a98ec7cSDarrick J. Wong   * - 0x0
360*3103084aSWang Jianjian     - __le32
361*3103084aSWang Jianjian     - m_i_reserved
3628a98ec7cSDarrick J. Wong     - ??
3638a98ec7cSDarrick J. Wong
3648a98ec7cSDarrick J. Wong.. _i_osd2:
3658a98ec7cSDarrick J. Wong
3668a98ec7cSDarrick J. WongThe ``osd2`` field has multiple meanings depending on the filesystem creator:
3678a98ec7cSDarrick J. Wong
3688a98ec7cSDarrick J. WongLinux:
3698a98ec7cSDarrick J. Wong
3708a98ec7cSDarrick J. Wong.. list-table::
3718a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
3728a98ec7cSDarrick J. Wong   :header-rows: 1
3738a98ec7cSDarrick J. Wong
3748a98ec7cSDarrick J. Wong   * - Offset
3758a98ec7cSDarrick J. Wong     - Size
3768a98ec7cSDarrick J. Wong     - Name
3778a98ec7cSDarrick J. Wong     - Description
3788a98ec7cSDarrick J. Wong   * - 0x0
379*3103084aSWang Jianjian     - __le16
380*3103084aSWang Jianjian     - l_i_blocks_high
3818a98ec7cSDarrick J. Wong     - Upper 16-bits of the block count. Please see the note attached to
382*3103084aSWang Jianjian       i_blocks_lo.
3838a98ec7cSDarrick J. Wong   * - 0x2
384*3103084aSWang Jianjian     - __le16
385*3103084aSWang Jianjian     - l_i_file_acl_high
3868a98ec7cSDarrick J. Wong     - Upper 16-bits of the extended attribute block (historically, the file
3878a98ec7cSDarrick J. Wong       ACL location). See the Extended Attributes section below.
3888a98ec7cSDarrick J. Wong   * - 0x4
389*3103084aSWang Jianjian     - __le16
390*3103084aSWang Jianjian     - l_i_uid_high
3918a98ec7cSDarrick J. Wong     - Upper 16-bits of the Owner UID.
3928a98ec7cSDarrick J. Wong   * - 0x6
393*3103084aSWang Jianjian     - __le16
394*3103084aSWang Jianjian     - l_i_gid_high
3958a98ec7cSDarrick J. Wong     - Upper 16-bits of the GID.
3968a98ec7cSDarrick J. Wong   * - 0x8
397*3103084aSWang Jianjian     - __le16
398*3103084aSWang Jianjian     - l_i_checksum_lo
3998a98ec7cSDarrick J. Wong     - Lower 16-bits of the inode checksum.
4008a98ec7cSDarrick J. Wong   * - 0xA
401*3103084aSWang Jianjian     - __le16
402*3103084aSWang Jianjian     - l_i_reserved
4038a98ec7cSDarrick J. Wong     - Unused.
4048a98ec7cSDarrick J. Wong
4058a98ec7cSDarrick J. WongHurd:
4068a98ec7cSDarrick J. Wong
4078a98ec7cSDarrick J. Wong.. list-table::
4088a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
4098a98ec7cSDarrick J. Wong   :header-rows: 1
4108a98ec7cSDarrick J. Wong
4118a98ec7cSDarrick J. Wong   * - Offset
4128a98ec7cSDarrick J. Wong     - Size
4138a98ec7cSDarrick J. Wong     - Name
4148a98ec7cSDarrick J. Wong     - Description
4158a98ec7cSDarrick J. Wong   * - 0x0
416*3103084aSWang Jianjian     - __le16
417*3103084aSWang Jianjian     - h_i_reserved1
4188a98ec7cSDarrick J. Wong     - ??
4198a98ec7cSDarrick J. Wong   * - 0x2
420*3103084aSWang Jianjian     - __u16
421*3103084aSWang Jianjian     - h_i_mode_high
4228a98ec7cSDarrick J. Wong     - Upper 16-bits of the file mode.
4238a98ec7cSDarrick J. Wong   * - 0x4
424*3103084aSWang Jianjian     - __le16
425*3103084aSWang Jianjian     - h_i_uid_high
4268a98ec7cSDarrick J. Wong     - Upper 16-bits of the Owner UID.
4278a98ec7cSDarrick J. Wong   * - 0x6
428*3103084aSWang Jianjian     - __le16
429*3103084aSWang Jianjian     - h_i_gid_high
4308a98ec7cSDarrick J. Wong     - Upper 16-bits of the GID.
4318a98ec7cSDarrick J. Wong   * - 0x8
432*3103084aSWang Jianjian     - __u32
433*3103084aSWang Jianjian     - h_i_author
4348a98ec7cSDarrick J. Wong     - Author code?
4358a98ec7cSDarrick J. Wong
4368a98ec7cSDarrick J. WongMasix:
4378a98ec7cSDarrick J. Wong
4388a98ec7cSDarrick J. Wong.. list-table::
4398a98ec7cSDarrick J. Wong   :widths: 8 8 24 40
4408a98ec7cSDarrick J. Wong   :header-rows: 1
4418a98ec7cSDarrick J. Wong
4428a98ec7cSDarrick J. Wong   * - Offset
4438a98ec7cSDarrick J. Wong     - Size
4448a98ec7cSDarrick J. Wong     - Name
4458a98ec7cSDarrick J. Wong     - Description
4468a98ec7cSDarrick J. Wong   * - 0x0
447*3103084aSWang Jianjian     - __le16
448*3103084aSWang Jianjian     - h_i_reserved1
4498a98ec7cSDarrick J. Wong     - ??
4508a98ec7cSDarrick J. Wong   * - 0x2
451*3103084aSWang Jianjian     - __u16
452*3103084aSWang Jianjian     - m_i_file_acl_high
4538a98ec7cSDarrick J. Wong     - Upper 16-bits of the extended attribute block (historically, the file
4548a98ec7cSDarrick J. Wong       ACL location).
4558a98ec7cSDarrick J. Wong   * - 0x4
456*3103084aSWang Jianjian     - __u32
457*3103084aSWang Jianjian     - m_i_reserved2[2]
4588a98ec7cSDarrick J. Wong     - ??
4598a98ec7cSDarrick J. Wong
4608a98ec7cSDarrick J. WongInode Size
4618a98ec7cSDarrick J. Wong~~~~~~~~~~
4628a98ec7cSDarrick J. Wong
4638a98ec7cSDarrick J. WongIn ext2 and ext3, the inode structure size was fixed at 128 bytes
4648a98ec7cSDarrick J. Wong(``EXT2_GOOD_OLD_INODE_SIZE``) and each inode had a disk record size of
4658a98ec7cSDarrick J. Wong128 bytes. Starting with ext4, it is possible to allocate a larger
4668a98ec7cSDarrick J. Wongon-disk inode at format time for all inodes in the filesystem to provide
4678a98ec7cSDarrick J. Wongspace beyond the end of the original ext2 inode. The on-disk inode
4688a98ec7cSDarrick J. Wongrecord size is recorded in the superblock as ``s_inode_size``. The
469*3103084aSWang Jianjiannumber of bytes actually used by struct ext4_inode beyond the original
4708a98ec7cSDarrick J. Wong128-byte ext2 inode is recorded in the ``i_extra_isize`` field for each
471*3103084aSWang Jianjianinode, which allows struct ext4_inode to grow for a new kernel without
4728a98ec7cSDarrick J. Wonghaving to upgrade all of the on-disk inodes. Access to fields beyond
473*3103084aSWang JianjianEXT2_GOOD_OLD_INODE_SIZE should be verified to be within
4748a98ec7cSDarrick J. Wong``i_extra_isize``. By default, ext4 inode records are 256 bytes, and (as
475219db95bSAyush Ranjanof August 2019) the inode structure is 160 bytes
476219db95bSAyush Ranjan(``i_extra_isize = 32``). The extra space between the end of the inode
4778a98ec7cSDarrick J. Wongstructure and the end of the inode record can be used to store extended
4788a98ec7cSDarrick J. Wongattributes. Each inode record can be as large as the filesystem block
4798a98ec7cSDarrick J. Wongsize, though this is not terribly efficient.
4808a98ec7cSDarrick J. Wong
4818a98ec7cSDarrick J. WongFinding an Inode
4828a98ec7cSDarrick J. Wong~~~~~~~~~~~~~~~~
4838a98ec7cSDarrick J. Wong
4848a98ec7cSDarrick J. WongEach block group contains ``sb->s_inodes_per_group`` inodes. Because
4858a98ec7cSDarrick J. Wonginode 0 is defined not to exist, this formula can be used to find the
4868a98ec7cSDarrick J. Wongblock group that an inode lives in:
4878a98ec7cSDarrick J. Wong``bg = (inode_num - 1) / sb->s_inodes_per_group``. The particular inode
4888a98ec7cSDarrick J. Wongcan be found within the block group's inode table at
4898a98ec7cSDarrick J. Wong``index = (inode_num - 1) % sb->s_inodes_per_group``. To get the byte
4908a98ec7cSDarrick J. Wongaddress within the inode table, use
4918a98ec7cSDarrick J. Wong``offset = index * sb->s_inode_size``.
4928a98ec7cSDarrick J. Wong
4938a98ec7cSDarrick J. WongInode Timestamps
4948a98ec7cSDarrick J. Wong~~~~~~~~~~~~~~~~
4958a98ec7cSDarrick J. Wong
4968a98ec7cSDarrick J. WongFour timestamps are recorded in the lower 128 bytes of the inode
4978a98ec7cSDarrick J. Wongstructure -- inode change time (ctime), access time (atime), data
4988a98ec7cSDarrick J. Wongmodification time (mtime), and deletion time (dtime). The four fields
4998a98ec7cSDarrick J. Wongare 32-bit signed integers that represent seconds since the Unix epoch
5008a98ec7cSDarrick J. Wong(1970-01-01 00:00:00 GMT), which means that the fields will overflow in
5013a6541e9SJan KaraJanuary 2038. If the filesystem does not have orphan_file feature, inodes
5023a6541e9SJan Karathat are not linked from any directory but are still open (orphan inodes) have
5033a6541e9SJan Karathe dtime field overloaded for use with the orphan list. The superblock field
5043a6541e9SJan Kara``s_last_orphan`` points to the first inode in the orphan list; dtime is then
5053a6541e9SJan Karathe number of the next orphaned inode, or zero if there are no more orphans.
5068a98ec7cSDarrick J. Wong
5078a98ec7cSDarrick J. WongIf the inode structure size ``sb->s_inode_size`` is larger than 128
5088a98ec7cSDarrick J. Wongbytes and the ``i_inode_extra`` field is large enough to encompass the
5098a98ec7cSDarrick J. Wongrespective ``i_[cma]time_extra`` field, the ctime, atime, and mtime
5108a98ec7cSDarrick J. Wonginode fields are widened to 64 bits. Within this “extra” 32-bit field,
5118a98ec7cSDarrick J. Wongthe lower two bits are used to extend the 32-bit seconds field to be 34
5128a98ec7cSDarrick J. Wongbit wide; the upper 30 bits are used to provide nanosecond timestamp
5138a98ec7cSDarrick J. Wongaccuracy. Therefore, timestamps should not overflow until May 2446.
5148a98ec7cSDarrick J. Wongdtime was not widened. There is also a fifth timestamp to record inode
5158a98ec7cSDarrick J. Wongcreation time (crtime); this field is 64-bits wide and decoded in the
5168a98ec7cSDarrick J. Wongsame manner as 64-bit [cma]time. Neither crtime nor dtime are accessible
5178a98ec7cSDarrick J. Wongthrough the regular stat() interface, though debugfs will report them.
5188a98ec7cSDarrick J. Wong
519*3103084aSWang JianjianWe use the 32-bit signed time value plus (2^32 * (extra epoch bits)).
5208a98ec7cSDarrick J. WongIn other words:
5218a98ec7cSDarrick J. Wong
5228a98ec7cSDarrick J. Wong.. list-table::
5238a98ec7cSDarrick J. Wong   :widths: 20 20 20 20 20
5248a98ec7cSDarrick J. Wong   :header-rows: 1
5258a98ec7cSDarrick J. Wong
5268a98ec7cSDarrick J. Wong   * - Extra epoch bits
5278a98ec7cSDarrick J. Wong     - MSB of 32-bit time
528*3103084aSWang Jianjian     - Adjustment for signed 32-bit to 64-bit tv_sec
529*3103084aSWang Jianjian     - Decoded 64-bit tv_sec
5308a98ec7cSDarrick J. Wong     - valid time range
5318a98ec7cSDarrick J. Wong   * - 0 0
5328a98ec7cSDarrick J. Wong     - 1
5338a98ec7cSDarrick J. Wong     - 0
5348a98ec7cSDarrick J. Wong     - ``-0x80000000 - -0x00000001``
5358a98ec7cSDarrick J. Wong     - 1901-12-13 to 1969-12-31
5368a98ec7cSDarrick J. Wong   * - 0 0
5378a98ec7cSDarrick J. Wong     - 0
5388a98ec7cSDarrick J. Wong     - 0
5398a98ec7cSDarrick J. Wong     - ``0x000000000 - 0x07fffffff``
5408a98ec7cSDarrick J. Wong     - 1970-01-01 to 2038-01-19
5418a98ec7cSDarrick J. Wong   * - 0 1
5428a98ec7cSDarrick J. Wong     - 1
5438a98ec7cSDarrick J. Wong     - 0x100000000
5448a98ec7cSDarrick J. Wong     - ``0x080000000 - 0x0ffffffff``
5458a98ec7cSDarrick J. Wong     - 2038-01-19 to 2106-02-07
5468a98ec7cSDarrick J. Wong   * - 0 1
5478a98ec7cSDarrick J. Wong     - 0
5488a98ec7cSDarrick J. Wong     - 0x100000000
5498a98ec7cSDarrick J. Wong     - ``0x100000000 - 0x17fffffff``
5508a98ec7cSDarrick J. Wong     - 2106-02-07 to 2174-02-25
5518a98ec7cSDarrick J. Wong   * - 1 0
5528a98ec7cSDarrick J. Wong     - 1
5538a98ec7cSDarrick J. Wong     - 0x200000000
5548a98ec7cSDarrick J. Wong     - ``0x180000000 - 0x1ffffffff``
5558a98ec7cSDarrick J. Wong     - 2174-02-25 to 2242-03-16
5568a98ec7cSDarrick J. Wong   * - 1 0
5578a98ec7cSDarrick J. Wong     - 0
5588a98ec7cSDarrick J. Wong     - 0x200000000
5598a98ec7cSDarrick J. Wong     - ``0x200000000 - 0x27fffffff``
5608a98ec7cSDarrick J. Wong     - 2242-03-16 to 2310-04-04
5618a98ec7cSDarrick J. Wong   * - 1 1
5628a98ec7cSDarrick J. Wong     - 1
5638a98ec7cSDarrick J. Wong     - 0x300000000
5648a98ec7cSDarrick J. Wong     - ``0x280000000 - 0x2ffffffff``
5658a98ec7cSDarrick J. Wong     - 2310-04-04 to 2378-04-22
5668a98ec7cSDarrick J. Wong   * - 1 1
5678a98ec7cSDarrick J. Wong     - 0
5688a98ec7cSDarrick J. Wong     - 0x300000000
5698a98ec7cSDarrick J. Wong     - ``0x300000000 - 0x37fffffff``
5708a98ec7cSDarrick J. Wong     - 2378-04-22 to 2446-05-10
5718a98ec7cSDarrick J. Wong
5728a98ec7cSDarrick J. WongThis is a somewhat odd encoding since there are effectively seven times
5738a98ec7cSDarrick J. Wongas many positive values as negative values. There have also been
5748a98ec7cSDarrick J. Wonglong-standing bugs decoding and encoding dates beyond 2038, which don't
5758a98ec7cSDarrick J. Wongseem to be fixed as of kernel 3.12 and e2fsprogs 1.42.8. 64-bit kernels
5768a98ec7cSDarrick J. Wongincorrectly use the extra epoch bits 1,1 for dates between 1901 and
5778a98ec7cSDarrick J. Wong1970. At some point the kernel will be fixed and e2fsck will fix this
5788a98ec7cSDarrick J. Wongsituation, assuming that it is run before 2310.
579