18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciIndex Nodes 48c2ecf20Sopenharmony_ci----------- 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ciIn a regular UNIX filesystem, the inode stores all the metadata 78c2ecf20Sopenharmony_cipertaining to the file (time stamps, block maps, extended attributes, 88c2ecf20Sopenharmony_cietc), not the directory entry. To find the information associated with a 98c2ecf20Sopenharmony_cifile, one must traverse the directory files to find the directory entry 108c2ecf20Sopenharmony_ciassociated with a file, then load the inode to find the metadata for 118c2ecf20Sopenharmony_cithat file. ext4 appears to cheat (for performance reasons) a little bit 128c2ecf20Sopenharmony_ciby storing a copy of the file type (normally stored in the inode) in the 138c2ecf20Sopenharmony_cidirectory entry. (Compare all this to FAT, which stores all the file 148c2ecf20Sopenharmony_ciinformation directly in the directory entry, but does not support hard 158c2ecf20Sopenharmony_cilinks and is in general more seek-happy than ext4 due to its simpler 168c2ecf20Sopenharmony_ciblock allocator and extensive use of linked lists.) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciThe inode table is a linear array of ``struct ext4_inode``. The table is 198c2ecf20Sopenharmony_cisized to have enough blocks to store at least 208c2ecf20Sopenharmony_ci``sb.s_inode_size * sb.s_inodes_per_group`` bytes. The number of the 218c2ecf20Sopenharmony_ciblock group containing an inode can be calculated as 228c2ecf20Sopenharmony_ci``(inode_number - 1) / sb.s_inodes_per_group``, and the offset into the 238c2ecf20Sopenharmony_cigroup's table is ``(inode_number - 1) % sb.s_inodes_per_group``. There 248c2ecf20Sopenharmony_ciis no inode 0. 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciThe inode checksum is calculated against the FS UUID, the inode number, 278c2ecf20Sopenharmony_ciand the inode structure itself. 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciThe inode table entry is laid out in ``struct ext4_inode``. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci.. list-table:: 328c2ecf20Sopenharmony_ci :widths: 8 8 24 40 338c2ecf20Sopenharmony_ci :header-rows: 1 348c2ecf20Sopenharmony_ci :class: longtable 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci * - Offset 378c2ecf20Sopenharmony_ci - Size 388c2ecf20Sopenharmony_ci - Name 398c2ecf20Sopenharmony_ci - Description 408c2ecf20Sopenharmony_ci * - 0x0 418c2ecf20Sopenharmony_ci - \_\_le16 428c2ecf20Sopenharmony_ci - i\_mode 438c2ecf20Sopenharmony_ci - File mode. See the table i_mode_ below. 448c2ecf20Sopenharmony_ci * - 0x2 458c2ecf20Sopenharmony_ci - \_\_le16 468c2ecf20Sopenharmony_ci - i\_uid 478c2ecf20Sopenharmony_ci - Lower 16-bits of Owner UID. 488c2ecf20Sopenharmony_ci * - 0x4 498c2ecf20Sopenharmony_ci - \_\_le32 508c2ecf20Sopenharmony_ci - i\_size\_lo 518c2ecf20Sopenharmony_ci - Lower 32-bits of size in bytes. 528c2ecf20Sopenharmony_ci * - 0x8 538c2ecf20Sopenharmony_ci - \_\_le32 548c2ecf20Sopenharmony_ci - i\_atime 558c2ecf20Sopenharmony_ci - Last access time, in seconds since the epoch. However, if the EA\_INODE 568c2ecf20Sopenharmony_ci inode flag is set, this inode stores an extended attribute value and 578c2ecf20Sopenharmony_ci this field contains the checksum of the value. 588c2ecf20Sopenharmony_ci * - 0xC 598c2ecf20Sopenharmony_ci - \_\_le32 608c2ecf20Sopenharmony_ci - i\_ctime 618c2ecf20Sopenharmony_ci - Last inode change time, in seconds since the epoch. However, if the 628c2ecf20Sopenharmony_ci EA\_INODE inode flag is set, this inode stores an extended attribute 638c2ecf20Sopenharmony_ci value and this field contains the lower 32 bits of the attribute value's 648c2ecf20Sopenharmony_ci reference count. 658c2ecf20Sopenharmony_ci * - 0x10 668c2ecf20Sopenharmony_ci - \_\_le32 678c2ecf20Sopenharmony_ci - i\_mtime 688c2ecf20Sopenharmony_ci - Last data modification time, in seconds since the epoch. However, if the 698c2ecf20Sopenharmony_ci EA\_INODE inode flag is set, this inode stores an extended attribute 708c2ecf20Sopenharmony_ci value and this field contains the number of the inode that owns the 718c2ecf20Sopenharmony_ci extended attribute. 728c2ecf20Sopenharmony_ci * - 0x14 738c2ecf20Sopenharmony_ci - \_\_le32 748c2ecf20Sopenharmony_ci - i\_dtime 758c2ecf20Sopenharmony_ci - Deletion Time, in seconds since the epoch. 768c2ecf20Sopenharmony_ci * - 0x18 778c2ecf20Sopenharmony_ci - \_\_le16 788c2ecf20Sopenharmony_ci - i\_gid 798c2ecf20Sopenharmony_ci - Lower 16-bits of GID. 808c2ecf20Sopenharmony_ci * - 0x1A 818c2ecf20Sopenharmony_ci - \_\_le16 828c2ecf20Sopenharmony_ci - i\_links\_count 838c2ecf20Sopenharmony_ci - Hard link count. Normally, ext4 does not permit an inode to have more 848c2ecf20Sopenharmony_ci than 65,000 hard links. This applies to files as well as directories, 858c2ecf20Sopenharmony_ci which means that there cannot be more than 64,998 subdirectories in a 868c2ecf20Sopenharmony_ci directory (each subdirectory's '..' entry counts as a hard link, as does 878c2ecf20Sopenharmony_ci the '.' entry in the directory itself). With the DIR\_NLINK feature 888c2ecf20Sopenharmony_ci enabled, ext4 supports more than 64,998 subdirectories by setting this 898c2ecf20Sopenharmony_ci field to 1 to indicate that the number of hard links is not known. 908c2ecf20Sopenharmony_ci * - 0x1C 918c2ecf20Sopenharmony_ci - \_\_le32 928c2ecf20Sopenharmony_ci - i\_blocks\_lo 938c2ecf20Sopenharmony_ci - Lower 32-bits of “block” count. If the huge\_file feature flag is not 948c2ecf20Sopenharmony_ci set on the filesystem, the file consumes ``i_blocks_lo`` 512-byte blocks 958c2ecf20Sopenharmony_ci on disk. If huge\_file is set and EXT4\_HUGE\_FILE\_FL is NOT set in 968c2ecf20Sopenharmony_ci ``inode.i_flags``, then the file consumes ``i_blocks_lo + (i_blocks_hi 978c2ecf20Sopenharmony_ci << 32)`` 512-byte blocks on disk. If huge\_file is set and 988c2ecf20Sopenharmony_ci EXT4\_HUGE\_FILE\_FL IS set in ``inode.i_flags``, then this file 998c2ecf20Sopenharmony_ci consumes (``i_blocks_lo + i_blocks_hi`` << 32) filesystem blocks on 1008c2ecf20Sopenharmony_ci disk. 1018c2ecf20Sopenharmony_ci * - 0x20 1028c2ecf20Sopenharmony_ci - \_\_le32 1038c2ecf20Sopenharmony_ci - i\_flags 1048c2ecf20Sopenharmony_ci - Inode flags. See the table i_flags_ below. 1058c2ecf20Sopenharmony_ci * - 0x24 1068c2ecf20Sopenharmony_ci - 4 bytes 1078c2ecf20Sopenharmony_ci - i\_osd1 1088c2ecf20Sopenharmony_ci - See the table i_osd1_ for more details. 1098c2ecf20Sopenharmony_ci * - 0x28 1108c2ecf20Sopenharmony_ci - 60 bytes 1118c2ecf20Sopenharmony_ci - i\_block[EXT4\_N\_BLOCKS=15] 1128c2ecf20Sopenharmony_ci - Block map or extent tree. See the section “The Contents of inode.i\_block”. 1138c2ecf20Sopenharmony_ci * - 0x64 1148c2ecf20Sopenharmony_ci - \_\_le32 1158c2ecf20Sopenharmony_ci - i\_generation 1168c2ecf20Sopenharmony_ci - File version (for NFS). 1178c2ecf20Sopenharmony_ci * - 0x68 1188c2ecf20Sopenharmony_ci - \_\_le32 1198c2ecf20Sopenharmony_ci - i\_file\_acl\_lo 1208c2ecf20Sopenharmony_ci - Lower 32-bits of extended attribute block. ACLs are of course one of 1218c2ecf20Sopenharmony_ci many possible extended attributes; I think the name of this field is a 1228c2ecf20Sopenharmony_ci result of the first use of extended attributes being for ACLs. 1238c2ecf20Sopenharmony_ci * - 0x6C 1248c2ecf20Sopenharmony_ci - \_\_le32 1258c2ecf20Sopenharmony_ci - i\_size\_high / i\_dir\_acl 1268c2ecf20Sopenharmony_ci - Upper 32-bits of file/directory size. In ext2/3 this field was named 1278c2ecf20Sopenharmony_ci i\_dir\_acl, though it was usually set to zero and never used. 1288c2ecf20Sopenharmony_ci * - 0x70 1298c2ecf20Sopenharmony_ci - \_\_le32 1308c2ecf20Sopenharmony_ci - i\_obso\_faddr 1318c2ecf20Sopenharmony_ci - (Obsolete) fragment address. 1328c2ecf20Sopenharmony_ci * - 0x74 1338c2ecf20Sopenharmony_ci - 12 bytes 1348c2ecf20Sopenharmony_ci - i\_osd2 1358c2ecf20Sopenharmony_ci - See the table i_osd2_ for more details. 1368c2ecf20Sopenharmony_ci * - 0x80 1378c2ecf20Sopenharmony_ci - \_\_le16 1388c2ecf20Sopenharmony_ci - i\_extra\_isize 1398c2ecf20Sopenharmony_ci - Size of this inode - 128. Alternately, the size of the extended inode 1408c2ecf20Sopenharmony_ci fields beyond the original ext2 inode, including this field. 1418c2ecf20Sopenharmony_ci * - 0x82 1428c2ecf20Sopenharmony_ci - \_\_le16 1438c2ecf20Sopenharmony_ci - i\_checksum\_hi 1448c2ecf20Sopenharmony_ci - Upper 16-bits of the inode checksum. 1458c2ecf20Sopenharmony_ci * - 0x84 1468c2ecf20Sopenharmony_ci - \_\_le32 1478c2ecf20Sopenharmony_ci - i\_ctime\_extra 1488c2ecf20Sopenharmony_ci - Extra change time bits. This provides sub-second precision. See Inode 1498c2ecf20Sopenharmony_ci Timestamps section. 1508c2ecf20Sopenharmony_ci * - 0x88 1518c2ecf20Sopenharmony_ci - \_\_le32 1528c2ecf20Sopenharmony_ci - i\_mtime\_extra 1538c2ecf20Sopenharmony_ci - Extra modification time bits. This provides sub-second precision. 1548c2ecf20Sopenharmony_ci * - 0x8C 1558c2ecf20Sopenharmony_ci - \_\_le32 1568c2ecf20Sopenharmony_ci - i\_atime\_extra 1578c2ecf20Sopenharmony_ci - Extra access time bits. This provides sub-second precision. 1588c2ecf20Sopenharmony_ci * - 0x90 1598c2ecf20Sopenharmony_ci - \_\_le32 1608c2ecf20Sopenharmony_ci - i\_crtime 1618c2ecf20Sopenharmony_ci - File creation time, in seconds since the epoch. 1628c2ecf20Sopenharmony_ci * - 0x94 1638c2ecf20Sopenharmony_ci - \_\_le32 1648c2ecf20Sopenharmony_ci - i\_crtime\_extra 1658c2ecf20Sopenharmony_ci - Extra file creation time bits. This provides sub-second precision. 1668c2ecf20Sopenharmony_ci * - 0x98 1678c2ecf20Sopenharmony_ci - \_\_le32 1688c2ecf20Sopenharmony_ci - i\_version\_hi 1698c2ecf20Sopenharmony_ci - Upper 32-bits for version number. 1708c2ecf20Sopenharmony_ci * - 0x9C 1718c2ecf20Sopenharmony_ci - \_\_le32 1728c2ecf20Sopenharmony_ci - i\_projid 1738c2ecf20Sopenharmony_ci - Project ID. 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci.. _i_mode: 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ciThe ``i_mode`` value is a combination of the following flags: 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci.. list-table:: 1808c2ecf20Sopenharmony_ci :widths: 16 64 1818c2ecf20Sopenharmony_ci :header-rows: 1 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci * - Value 1848c2ecf20Sopenharmony_ci - Description 1858c2ecf20Sopenharmony_ci * - 0x1 1868c2ecf20Sopenharmony_ci - S\_IXOTH (Others may execute) 1878c2ecf20Sopenharmony_ci * - 0x2 1888c2ecf20Sopenharmony_ci - S\_IWOTH (Others may write) 1898c2ecf20Sopenharmony_ci * - 0x4 1908c2ecf20Sopenharmony_ci - S\_IROTH (Others may read) 1918c2ecf20Sopenharmony_ci * - 0x8 1928c2ecf20Sopenharmony_ci - S\_IXGRP (Group members may execute) 1938c2ecf20Sopenharmony_ci * - 0x10 1948c2ecf20Sopenharmony_ci - S\_IWGRP (Group members may write) 1958c2ecf20Sopenharmony_ci * - 0x20 1968c2ecf20Sopenharmony_ci - S\_IRGRP (Group members may read) 1978c2ecf20Sopenharmony_ci * - 0x40 1988c2ecf20Sopenharmony_ci - S\_IXUSR (Owner may execute) 1998c2ecf20Sopenharmony_ci * - 0x80 2008c2ecf20Sopenharmony_ci - S\_IWUSR (Owner may write) 2018c2ecf20Sopenharmony_ci * - 0x100 2028c2ecf20Sopenharmony_ci - S\_IRUSR (Owner may read) 2038c2ecf20Sopenharmony_ci * - 0x200 2048c2ecf20Sopenharmony_ci - S\_ISVTX (Sticky bit) 2058c2ecf20Sopenharmony_ci * - 0x400 2068c2ecf20Sopenharmony_ci - S\_ISGID (Set GID) 2078c2ecf20Sopenharmony_ci * - 0x800 2088c2ecf20Sopenharmony_ci - S\_ISUID (Set UID) 2098c2ecf20Sopenharmony_ci * - 2108c2ecf20Sopenharmony_ci - These are mutually-exclusive file types: 2118c2ecf20Sopenharmony_ci * - 0x1000 2128c2ecf20Sopenharmony_ci - S\_IFIFO (FIFO) 2138c2ecf20Sopenharmony_ci * - 0x2000 2148c2ecf20Sopenharmony_ci - S\_IFCHR (Character device) 2158c2ecf20Sopenharmony_ci * - 0x4000 2168c2ecf20Sopenharmony_ci - S\_IFDIR (Directory) 2178c2ecf20Sopenharmony_ci * - 0x6000 2188c2ecf20Sopenharmony_ci - S\_IFBLK (Block device) 2198c2ecf20Sopenharmony_ci * - 0x8000 2208c2ecf20Sopenharmony_ci - S\_IFREG (Regular file) 2218c2ecf20Sopenharmony_ci * - 0xA000 2228c2ecf20Sopenharmony_ci - S\_IFLNK (Symbolic link) 2238c2ecf20Sopenharmony_ci * - 0xC000 2248c2ecf20Sopenharmony_ci - S\_IFSOCK (Socket) 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci.. _i_flags: 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ciThe ``i_flags`` field is a combination of these values: 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci.. list-table:: 2318c2ecf20Sopenharmony_ci :widths: 16 64 2328c2ecf20Sopenharmony_ci :header-rows: 1 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci * - Value 2358c2ecf20Sopenharmony_ci - Description 2368c2ecf20Sopenharmony_ci * - 0x1 2378c2ecf20Sopenharmony_ci - This file requires secure deletion (EXT4\_SECRM\_FL). (not implemented) 2388c2ecf20Sopenharmony_ci * - 0x2 2398c2ecf20Sopenharmony_ci - This file should be preserved, should undeletion be desired 2408c2ecf20Sopenharmony_ci (EXT4\_UNRM\_FL). (not implemented) 2418c2ecf20Sopenharmony_ci * - 0x4 2428c2ecf20Sopenharmony_ci - File is compressed (EXT4\_COMPR\_FL). (not really implemented) 2438c2ecf20Sopenharmony_ci * - 0x8 2448c2ecf20Sopenharmony_ci - All writes to the file must be synchronous (EXT4\_SYNC\_FL). 2458c2ecf20Sopenharmony_ci * - 0x10 2468c2ecf20Sopenharmony_ci - File is immutable (EXT4\_IMMUTABLE\_FL). 2478c2ecf20Sopenharmony_ci * - 0x20 2488c2ecf20Sopenharmony_ci - File can only be appended (EXT4\_APPEND\_FL). 2498c2ecf20Sopenharmony_ci * - 0x40 2508c2ecf20Sopenharmony_ci - The dump(1) utility should not dump this file (EXT4\_NODUMP\_FL). 2518c2ecf20Sopenharmony_ci * - 0x80 2528c2ecf20Sopenharmony_ci - Do not update access time (EXT4\_NOATIME\_FL). 2538c2ecf20Sopenharmony_ci * - 0x100 2548c2ecf20Sopenharmony_ci - Dirty compressed file (EXT4\_DIRTY\_FL). (not used) 2558c2ecf20Sopenharmony_ci * - 0x200 2568c2ecf20Sopenharmony_ci - File has one or more compressed clusters (EXT4\_COMPRBLK\_FL). (not used) 2578c2ecf20Sopenharmony_ci * - 0x400 2588c2ecf20Sopenharmony_ci - Do not compress file (EXT4\_NOCOMPR\_FL). (not used) 2598c2ecf20Sopenharmony_ci * - 0x800 2608c2ecf20Sopenharmony_ci - Encrypted inode (EXT4\_ENCRYPT\_FL). This bit value previously was 2618c2ecf20Sopenharmony_ci EXT4\_ECOMPR\_FL (compression error), which was never used. 2628c2ecf20Sopenharmony_ci * - 0x1000 2638c2ecf20Sopenharmony_ci - Directory has hashed indexes (EXT4\_INDEX\_FL). 2648c2ecf20Sopenharmony_ci * - 0x2000 2658c2ecf20Sopenharmony_ci - AFS magic directory (EXT4\_IMAGIC\_FL). 2668c2ecf20Sopenharmony_ci * - 0x4000 2678c2ecf20Sopenharmony_ci - File data must always be written through the journal 2688c2ecf20Sopenharmony_ci (EXT4\_JOURNAL\_DATA\_FL). 2698c2ecf20Sopenharmony_ci * - 0x8000 2708c2ecf20Sopenharmony_ci - File tail should not be merged (EXT4\_NOTAIL\_FL). (not used by ext4) 2718c2ecf20Sopenharmony_ci * - 0x10000 2728c2ecf20Sopenharmony_ci - All directory entry data should be written synchronously (see 2738c2ecf20Sopenharmony_ci ``dirsync``) (EXT4\_DIRSYNC\_FL). 2748c2ecf20Sopenharmony_ci * - 0x20000 2758c2ecf20Sopenharmony_ci - Top of directory hierarchy (EXT4\_TOPDIR\_FL). 2768c2ecf20Sopenharmony_ci * - 0x40000 2778c2ecf20Sopenharmony_ci - This is a huge file (EXT4\_HUGE\_FILE\_FL). 2788c2ecf20Sopenharmony_ci * - 0x80000 2798c2ecf20Sopenharmony_ci - Inode uses extents (EXT4\_EXTENTS\_FL). 2808c2ecf20Sopenharmony_ci * - 0x100000 2818c2ecf20Sopenharmony_ci - Verity protected file (EXT4\_VERITY\_FL). 2828c2ecf20Sopenharmony_ci * - 0x200000 2838c2ecf20Sopenharmony_ci - Inode stores a large extended attribute value in its data blocks 2848c2ecf20Sopenharmony_ci (EXT4\_EA\_INODE\_FL). 2858c2ecf20Sopenharmony_ci * - 0x400000 2868c2ecf20Sopenharmony_ci - This file has blocks allocated past EOF (EXT4\_EOFBLOCKS\_FL). 2878c2ecf20Sopenharmony_ci (deprecated) 2888c2ecf20Sopenharmony_ci * - 0x01000000 2898c2ecf20Sopenharmony_ci - Inode is a snapshot (``EXT4_SNAPFILE_FL``). (not in mainline) 2908c2ecf20Sopenharmony_ci * - 0x04000000 2918c2ecf20Sopenharmony_ci - Snapshot is being deleted (``EXT4_SNAPFILE_DELETED_FL``). (not in 2928c2ecf20Sopenharmony_ci mainline) 2938c2ecf20Sopenharmony_ci * - 0x08000000 2948c2ecf20Sopenharmony_ci - Snapshot shrink has completed (``EXT4_SNAPFILE_SHRUNK_FL``). (not in 2958c2ecf20Sopenharmony_ci mainline) 2968c2ecf20Sopenharmony_ci * - 0x10000000 2978c2ecf20Sopenharmony_ci - Inode has inline data (EXT4\_INLINE\_DATA\_FL). 2988c2ecf20Sopenharmony_ci * - 0x20000000 2998c2ecf20Sopenharmony_ci - Create children with the same project ID (EXT4\_PROJINHERIT\_FL). 3008c2ecf20Sopenharmony_ci * - 0x80000000 3018c2ecf20Sopenharmony_ci - Reserved for ext4 library (EXT4\_RESERVED\_FL). 3028c2ecf20Sopenharmony_ci * - 3038c2ecf20Sopenharmony_ci - Aggregate flags: 3048c2ecf20Sopenharmony_ci * - 0x705BDFFF 3058c2ecf20Sopenharmony_ci - User-visible flags. 3068c2ecf20Sopenharmony_ci * - 0x604BC0FF 3078c2ecf20Sopenharmony_ci - User-modifiable flags. Note that while EXT4\_JOURNAL\_DATA\_FL and 3088c2ecf20Sopenharmony_ci EXT4\_EXTENTS\_FL can be set with setattr, they are not in the kernel's 3098c2ecf20Sopenharmony_ci EXT4\_FL\_USER\_MODIFIABLE mask, since it needs to handle the setting of 3108c2ecf20Sopenharmony_ci these flags in a special manner and they are masked out of the set of 3118c2ecf20Sopenharmony_ci flags that are saved directly to i\_flags. 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci.. _i_osd1: 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ciThe ``osd1`` field has multiple meanings depending on the creator: 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ciLinux: 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci.. list-table:: 3208c2ecf20Sopenharmony_ci :widths: 8 8 24 40 3218c2ecf20Sopenharmony_ci :header-rows: 1 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci * - Offset 3248c2ecf20Sopenharmony_ci - Size 3258c2ecf20Sopenharmony_ci - Name 3268c2ecf20Sopenharmony_ci - Description 3278c2ecf20Sopenharmony_ci * - 0x0 3288c2ecf20Sopenharmony_ci - \_\_le32 3298c2ecf20Sopenharmony_ci - l\_i\_version 3308c2ecf20Sopenharmony_ci - Inode version. However, if the EA\_INODE inode flag is set, this inode 3318c2ecf20Sopenharmony_ci stores an extended attribute value and this field contains the upper 32 3328c2ecf20Sopenharmony_ci bits of the attribute value's reference count. 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ciHurd: 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci.. list-table:: 3378c2ecf20Sopenharmony_ci :widths: 8 8 24 40 3388c2ecf20Sopenharmony_ci :header-rows: 1 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci * - Offset 3418c2ecf20Sopenharmony_ci - Size 3428c2ecf20Sopenharmony_ci - Name 3438c2ecf20Sopenharmony_ci - Description 3448c2ecf20Sopenharmony_ci * - 0x0 3458c2ecf20Sopenharmony_ci - \_\_le32 3468c2ecf20Sopenharmony_ci - h\_i\_translator 3478c2ecf20Sopenharmony_ci - ?? 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ciMasix: 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci.. list-table:: 3528c2ecf20Sopenharmony_ci :widths: 8 8 24 40 3538c2ecf20Sopenharmony_ci :header-rows: 1 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci * - Offset 3568c2ecf20Sopenharmony_ci - Size 3578c2ecf20Sopenharmony_ci - Name 3588c2ecf20Sopenharmony_ci - Description 3598c2ecf20Sopenharmony_ci * - 0x0 3608c2ecf20Sopenharmony_ci - \_\_le32 3618c2ecf20Sopenharmony_ci - m\_i\_reserved 3628c2ecf20Sopenharmony_ci - ?? 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci.. _i_osd2: 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ciThe ``osd2`` field has multiple meanings depending on the filesystem creator: 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ciLinux: 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci.. list-table:: 3718c2ecf20Sopenharmony_ci :widths: 8 8 24 40 3728c2ecf20Sopenharmony_ci :header-rows: 1 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci * - Offset 3758c2ecf20Sopenharmony_ci - Size 3768c2ecf20Sopenharmony_ci - Name 3778c2ecf20Sopenharmony_ci - Description 3788c2ecf20Sopenharmony_ci * - 0x0 3798c2ecf20Sopenharmony_ci - \_\_le16 3808c2ecf20Sopenharmony_ci - l\_i\_blocks\_high 3818c2ecf20Sopenharmony_ci - Upper 16-bits of the block count. Please see the note attached to 3828c2ecf20Sopenharmony_ci i\_blocks\_lo. 3838c2ecf20Sopenharmony_ci * - 0x2 3848c2ecf20Sopenharmony_ci - \_\_le16 3858c2ecf20Sopenharmony_ci - l\_i\_file\_acl\_high 3868c2ecf20Sopenharmony_ci - Upper 16-bits of the extended attribute block (historically, the file 3878c2ecf20Sopenharmony_ci ACL location). See the Extended Attributes section below. 3888c2ecf20Sopenharmony_ci * - 0x4 3898c2ecf20Sopenharmony_ci - \_\_le16 3908c2ecf20Sopenharmony_ci - l\_i\_uid\_high 3918c2ecf20Sopenharmony_ci - Upper 16-bits of the Owner UID. 3928c2ecf20Sopenharmony_ci * - 0x6 3938c2ecf20Sopenharmony_ci - \_\_le16 3948c2ecf20Sopenharmony_ci - l\_i\_gid\_high 3958c2ecf20Sopenharmony_ci - Upper 16-bits of the GID. 3968c2ecf20Sopenharmony_ci * - 0x8 3978c2ecf20Sopenharmony_ci - \_\_le16 3988c2ecf20Sopenharmony_ci - l\_i\_checksum\_lo 3998c2ecf20Sopenharmony_ci - Lower 16-bits of the inode checksum. 4008c2ecf20Sopenharmony_ci * - 0xA 4018c2ecf20Sopenharmony_ci - \_\_le16 4028c2ecf20Sopenharmony_ci - l\_i\_reserved 4038c2ecf20Sopenharmony_ci - Unused. 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ciHurd: 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci.. list-table:: 4088c2ecf20Sopenharmony_ci :widths: 8 8 24 40 4098c2ecf20Sopenharmony_ci :header-rows: 1 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci * - Offset 4128c2ecf20Sopenharmony_ci - Size 4138c2ecf20Sopenharmony_ci - Name 4148c2ecf20Sopenharmony_ci - Description 4158c2ecf20Sopenharmony_ci * - 0x0 4168c2ecf20Sopenharmony_ci - \_\_le16 4178c2ecf20Sopenharmony_ci - h\_i\_reserved1 4188c2ecf20Sopenharmony_ci - ?? 4198c2ecf20Sopenharmony_ci * - 0x2 4208c2ecf20Sopenharmony_ci - \_\_u16 4218c2ecf20Sopenharmony_ci - h\_i\_mode\_high 4228c2ecf20Sopenharmony_ci - Upper 16-bits of the file mode. 4238c2ecf20Sopenharmony_ci * - 0x4 4248c2ecf20Sopenharmony_ci - \_\_le16 4258c2ecf20Sopenharmony_ci - h\_i\_uid\_high 4268c2ecf20Sopenharmony_ci - Upper 16-bits of the Owner UID. 4278c2ecf20Sopenharmony_ci * - 0x6 4288c2ecf20Sopenharmony_ci - \_\_le16 4298c2ecf20Sopenharmony_ci - h\_i\_gid\_high 4308c2ecf20Sopenharmony_ci - Upper 16-bits of the GID. 4318c2ecf20Sopenharmony_ci * - 0x8 4328c2ecf20Sopenharmony_ci - \_\_u32 4338c2ecf20Sopenharmony_ci - h\_i\_author 4348c2ecf20Sopenharmony_ci - Author code? 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ciMasix: 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci.. list-table:: 4398c2ecf20Sopenharmony_ci :widths: 8 8 24 40 4408c2ecf20Sopenharmony_ci :header-rows: 1 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci * - Offset 4438c2ecf20Sopenharmony_ci - Size 4448c2ecf20Sopenharmony_ci - Name 4458c2ecf20Sopenharmony_ci - Description 4468c2ecf20Sopenharmony_ci * - 0x0 4478c2ecf20Sopenharmony_ci - \_\_le16 4488c2ecf20Sopenharmony_ci - h\_i\_reserved1 4498c2ecf20Sopenharmony_ci - ?? 4508c2ecf20Sopenharmony_ci * - 0x2 4518c2ecf20Sopenharmony_ci - \_\_u16 4528c2ecf20Sopenharmony_ci - m\_i\_file\_acl\_high 4538c2ecf20Sopenharmony_ci - Upper 16-bits of the extended attribute block (historically, the file 4548c2ecf20Sopenharmony_ci ACL location). 4558c2ecf20Sopenharmony_ci * - 0x4 4568c2ecf20Sopenharmony_ci - \_\_u32 4578c2ecf20Sopenharmony_ci - m\_i\_reserved2[2] 4588c2ecf20Sopenharmony_ci - ?? 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ciInode Size 4618c2ecf20Sopenharmony_ci~~~~~~~~~~ 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ciIn ext2 and ext3, the inode structure size was fixed at 128 bytes 4648c2ecf20Sopenharmony_ci(``EXT2_GOOD_OLD_INODE_SIZE``) and each inode had a disk record size of 4658c2ecf20Sopenharmony_ci128 bytes. Starting with ext4, it is possible to allocate a larger 4668c2ecf20Sopenharmony_cion-disk inode at format time for all inodes in the filesystem to provide 4678c2ecf20Sopenharmony_cispace beyond the end of the original ext2 inode. The on-disk inode 4688c2ecf20Sopenharmony_cirecord size is recorded in the superblock as ``s_inode_size``. The 4698c2ecf20Sopenharmony_cinumber of bytes actually used by struct ext4\_inode beyond the original 4708c2ecf20Sopenharmony_ci128-byte ext2 inode is recorded in the ``i_extra_isize`` field for each 4718c2ecf20Sopenharmony_ciinode, which allows struct ext4\_inode to grow for a new kernel without 4728c2ecf20Sopenharmony_cihaving to upgrade all of the on-disk inodes. Access to fields beyond 4738c2ecf20Sopenharmony_ciEXT2\_GOOD\_OLD\_INODE\_SIZE should be verified to be within 4748c2ecf20Sopenharmony_ci``i_extra_isize``. By default, ext4 inode records are 256 bytes, and (as 4758c2ecf20Sopenharmony_ciof August 2019) the inode structure is 160 bytes 4768c2ecf20Sopenharmony_ci(``i_extra_isize = 32``). The extra space between the end of the inode 4778c2ecf20Sopenharmony_cistructure and the end of the inode record can be used to store extended 4788c2ecf20Sopenharmony_ciattributes. Each inode record can be as large as the filesystem block 4798c2ecf20Sopenharmony_cisize, though this is not terribly efficient. 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ciFinding an Inode 4828c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ciEach block group contains ``sb->s_inodes_per_group`` inodes. Because 4858c2ecf20Sopenharmony_ciinode 0 is defined not to exist, this formula can be used to find the 4868c2ecf20Sopenharmony_ciblock group that an inode lives in: 4878c2ecf20Sopenharmony_ci``bg = (inode_num - 1) / sb->s_inodes_per_group``. The particular inode 4888c2ecf20Sopenharmony_cican be found within the block group's inode table at 4898c2ecf20Sopenharmony_ci``index = (inode_num - 1) % sb->s_inodes_per_group``. To get the byte 4908c2ecf20Sopenharmony_ciaddress within the inode table, use 4918c2ecf20Sopenharmony_ci``offset = index * sb->s_inode_size``. 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ciInode Timestamps 4948c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ciFour timestamps are recorded in the lower 128 bytes of the inode 4978c2ecf20Sopenharmony_cistructure -- inode change time (ctime), access time (atime), data 4988c2ecf20Sopenharmony_cimodification time (mtime), and deletion time (dtime). The four fields 4998c2ecf20Sopenharmony_ciare 32-bit signed integers that represent seconds since the Unix epoch 5008c2ecf20Sopenharmony_ci(1970-01-01 00:00:00 GMT), which means that the fields will overflow in 5018c2ecf20Sopenharmony_ciJanuary 2038. For inodes that are not linked from any directory but are 5028c2ecf20Sopenharmony_cistill open (orphan inodes), the dtime field is overloaded for use with 5038c2ecf20Sopenharmony_cithe orphan list. The superblock field ``s_last_orphan`` points to the 5048c2ecf20Sopenharmony_cifirst inode in the orphan list; dtime is then the number of the next 5058c2ecf20Sopenharmony_ciorphaned inode, or zero if there are no more orphans. 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ciIf the inode structure size ``sb->s_inode_size`` is larger than 128 5088c2ecf20Sopenharmony_cibytes and the ``i_inode_extra`` field is large enough to encompass the 5098c2ecf20Sopenharmony_cirespective ``i_[cma]time_extra`` field, the ctime, atime, and mtime 5108c2ecf20Sopenharmony_ciinode fields are widened to 64 bits. Within this “extra” 32-bit field, 5118c2ecf20Sopenharmony_cithe lower two bits are used to extend the 32-bit seconds field to be 34 5128c2ecf20Sopenharmony_cibit wide; the upper 30 bits are used to provide nanosecond timestamp 5138c2ecf20Sopenharmony_ciaccuracy. Therefore, timestamps should not overflow until May 2446. 5148c2ecf20Sopenharmony_cidtime was not widened. There is also a fifth timestamp to record inode 5158c2ecf20Sopenharmony_cicreation time (crtime); this field is 64-bits wide and decoded in the 5168c2ecf20Sopenharmony_cisame manner as 64-bit [cma]time. Neither crtime nor dtime are accessible 5178c2ecf20Sopenharmony_cithrough the regular stat() interface, though debugfs will report them. 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ciWe use the 32-bit signed time value plus (2^32 \* (extra epoch bits)). 5208c2ecf20Sopenharmony_ciIn other words: 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci.. list-table:: 5238c2ecf20Sopenharmony_ci :widths: 20 20 20 20 20 5248c2ecf20Sopenharmony_ci :header-rows: 1 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci * - Extra epoch bits 5278c2ecf20Sopenharmony_ci - MSB of 32-bit time 5288c2ecf20Sopenharmony_ci - Adjustment for signed 32-bit to 64-bit tv\_sec 5298c2ecf20Sopenharmony_ci - Decoded 64-bit tv\_sec 5308c2ecf20Sopenharmony_ci - valid time range 5318c2ecf20Sopenharmony_ci * - 0 0 5328c2ecf20Sopenharmony_ci - 1 5338c2ecf20Sopenharmony_ci - 0 5348c2ecf20Sopenharmony_ci - ``-0x80000000 - -0x00000001`` 5358c2ecf20Sopenharmony_ci - 1901-12-13 to 1969-12-31 5368c2ecf20Sopenharmony_ci * - 0 0 5378c2ecf20Sopenharmony_ci - 0 5388c2ecf20Sopenharmony_ci - 0 5398c2ecf20Sopenharmony_ci - ``0x000000000 - 0x07fffffff`` 5408c2ecf20Sopenharmony_ci - 1970-01-01 to 2038-01-19 5418c2ecf20Sopenharmony_ci * - 0 1 5428c2ecf20Sopenharmony_ci - 1 5438c2ecf20Sopenharmony_ci - 0x100000000 5448c2ecf20Sopenharmony_ci - ``0x080000000 - 0x0ffffffff`` 5458c2ecf20Sopenharmony_ci - 2038-01-19 to 2106-02-07 5468c2ecf20Sopenharmony_ci * - 0 1 5478c2ecf20Sopenharmony_ci - 0 5488c2ecf20Sopenharmony_ci - 0x100000000 5498c2ecf20Sopenharmony_ci - ``0x100000000 - 0x17fffffff`` 5508c2ecf20Sopenharmony_ci - 2106-02-07 to 2174-02-25 5518c2ecf20Sopenharmony_ci * - 1 0 5528c2ecf20Sopenharmony_ci - 1 5538c2ecf20Sopenharmony_ci - 0x200000000 5548c2ecf20Sopenharmony_ci - ``0x180000000 - 0x1ffffffff`` 5558c2ecf20Sopenharmony_ci - 2174-02-25 to 2242-03-16 5568c2ecf20Sopenharmony_ci * - 1 0 5578c2ecf20Sopenharmony_ci - 0 5588c2ecf20Sopenharmony_ci - 0x200000000 5598c2ecf20Sopenharmony_ci - ``0x200000000 - 0x27fffffff`` 5608c2ecf20Sopenharmony_ci - 2242-03-16 to 2310-04-04 5618c2ecf20Sopenharmony_ci * - 1 1 5628c2ecf20Sopenharmony_ci - 1 5638c2ecf20Sopenharmony_ci - 0x300000000 5648c2ecf20Sopenharmony_ci - ``0x280000000 - 0x2ffffffff`` 5658c2ecf20Sopenharmony_ci - 2310-04-04 to 2378-04-22 5668c2ecf20Sopenharmony_ci * - 1 1 5678c2ecf20Sopenharmony_ci - 0 5688c2ecf20Sopenharmony_ci - 0x300000000 5698c2ecf20Sopenharmony_ci - ``0x300000000 - 0x37fffffff`` 5708c2ecf20Sopenharmony_ci - 2378-04-22 to 2446-05-10 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ciThis is a somewhat odd encoding since there are effectively seven times 5738c2ecf20Sopenharmony_cias many positive values as negative values. There have also been 5748c2ecf20Sopenharmony_cilong-standing bugs decoding and encoding dates beyond 2038, which don't 5758c2ecf20Sopenharmony_ciseem to be fixed as of kernel 3.12 and e2fsprogs 1.42.8. 64-bit kernels 5768c2ecf20Sopenharmony_ciincorrectly use the extra epoch bits 1,1 for dates between 1901 and 5778c2ecf20Sopenharmony_ci1970. At some point the kernel will be fixed and e2fsck will fix this 5788c2ecf20Sopenharmony_cisituation, assuming that it is run before 2310. 579