|
| 1 | +#include </usr/include/linux/types.h> |
| 2 | + |
| 3 | +#define FILE_MODE 33188 |
| 4 | +#define EXT4_NDIR_BLOCKS 12 |
| 5 | +#define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS |
| 6 | +#define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1) |
| 7 | +#define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1) |
| 8 | +#define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1) |
| 9 | +#define EXT4_GOOD_OLD_INODE_SIZE 128 |
| 10 | + |
| 11 | +/* ext4 superblock */ |
| 12 | +struct ext4_super_block |
| 13 | +{ |
| 14 | + /*00*/ __le32 s_inodes_count; /* Inodes count */ |
| 15 | + __le32 s_blocks_count_lo; /* Blocks count */ |
| 16 | + __le32 s_r_blocks_count_lo; /* Reserved blocks count */ |
| 17 | + __le32 s_free_blocks_count_lo; /* Free blocks count */ |
| 18 | + /*10*/ __le32 s_free_inodes_count; /* Free inodes count */ |
| 19 | + __le32 s_first_data_block; /* First Data Block */ |
| 20 | + __le32 s_log_block_size; /* Block size */ |
| 21 | + __le32 s_log_cluster_size; /* Allocation cluster size */ |
| 22 | + /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */ |
| 23 | + __le32 s_clusters_per_group; /* # Clusters per group */ |
| 24 | + __le32 s_inodes_per_group; /* # Inodes per group */ |
| 25 | + __le32 s_mtime; /* Mount time */ |
| 26 | + /*30*/ __le32 s_wtime; /* Write time */ |
| 27 | + __le16 s_mnt_count; /* Mount count */ |
| 28 | + __le16 s_max_mnt_count; /* Maximal mount count */ |
| 29 | + __le16 s_magic; /* Magic signature */ |
| 30 | + __le16 s_state; /* File system state */ |
| 31 | + __le16 s_errors; /* Behaviour when detecting errors */ |
| 32 | + __le16 s_minor_rev_level; /* minor revision level */ |
| 33 | + /*40*/ __le32 s_lastcheck; /* time of last check */ |
| 34 | + __le32 s_checkinterval; /* max. time between checks */ |
| 35 | + __le32 s_creator_os; /* OS */ |
| 36 | + __le32 s_rev_level; /* Revision level */ |
| 37 | + /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */ |
| 38 | + __le16 s_def_resgid; /* Default gid for reserved blocks */ |
| 39 | + /* |
| 40 | + * These fields are for EXT4_DYNAMIC_REV superblocks only. |
| 41 | + * |
| 42 | + * Note: the difference between the compatible feature set and |
| 43 | + * the incompatible feature set is that if there is a bit set |
| 44 | + * in the incompatible feature set that the kernel doesn't |
| 45 | + * know about, it should refuse to mount the filesystem. |
| 46 | + * |
| 47 | + * e2fsck's requirements are more strict; if it doesn't know |
| 48 | + * about a feature in either the compatible or incompatible |
| 49 | + * feature set, it must abort and not try to meddle with |
| 50 | + * things it doesn't understand... |
| 51 | + */ |
| 52 | + __le32 s_first_ino; /* First non-reserved inode */ |
| 53 | + __le16 s_inode_size; /* size of inode structure */ |
| 54 | + __le16 s_block_group_nr; /* block group # of this superblock */ |
| 55 | + __le32 s_feature_compat; /* compatible feature set */ |
| 56 | + /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ |
| 57 | + __le32 s_feature_ro_compat; /* readonly-compatible feature set */ |
| 58 | + /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ |
| 59 | + /*78*/ char s_volume_name[16]; /* volume name */ |
| 60 | + /*88*/ char s_last_mounted[64]; /* directory where last mounted */ |
| 61 | + /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ |
| 62 | + /* |
| 63 | + * Performance hints. Directory preallocation should only |
| 64 | + * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on. |
| 65 | + */ |
| 66 | + __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ |
| 67 | + __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ |
| 68 | + __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */ |
| 69 | + /* |
| 70 | +* Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set. |
| 71 | +*/ |
| 72 | + /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */ |
| 73 | + /*E0*/ __le32 s_journal_inum; /* inode number of journal file */ |
| 74 | + __le32 s_journal_dev; /* device number of journal file */ |
| 75 | + __le32 s_last_orphan; /* start of list of inodes to delete */ |
| 76 | + __le32 s_hash_seed[4]; /* HTREE hash seed */ |
| 77 | + __u8 s_def_hash_version; /* Default hash version to use */ |
| 78 | + __u8 s_jnl_backup_type; |
| 79 | + __le16 s_desc_size; /* size of group descriptor */ |
| 80 | + /*100*/ __le32 s_default_mount_opts; |
| 81 | + __le32 s_first_meta_bg; /* First metablock block group */ |
| 82 | + __le32 s_mkfs_time; /* When the filesystem was created */ |
| 83 | + __le32 s_jnl_blocks[17]; /* Backup of the journal inode */ |
| 84 | + /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */ |
| 85 | + /*150*/ __le32 s_blocks_count_hi; /* Blocks count */ |
| 86 | + __le32 s_r_blocks_count_hi; /* Reserved blocks count */ |
| 87 | + __le32 s_free_blocks_count_hi; /* Free blocks count */ |
| 88 | + __le16 s_min_extra_isize; /* All inodes have at least # bytes */ |
| 89 | + __le16 s_want_extra_isize; /* New inodes should reserve # bytes */ |
| 90 | + __le32 s_flags; /* Miscellaneous flags */ |
| 91 | + __le16 s_raid_stride; /* RAID stride */ |
| 92 | + __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ |
| 93 | + __le64 s_mmp_block; /* Block for multi-mount protection */ |
| 94 | + __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ |
| 95 | + __u8 s_log_groups_per_flex; /* FLEX_BG group size */ |
| 96 | + __u8 s_checksum_type; /* metadata checksum algorithm used */ |
| 97 | + __le16 s_reserved_pad; |
| 98 | + __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ |
| 99 | + __le32 s_snapshot_inum; /* Inode number of active snapshot */ |
| 100 | + __le32 s_snapshot_id; /* sequential ID of active snapshot */ |
| 101 | + __le64 s_snapshot_r_blocks_count; /* reserved blocks for active |
| 102 | + snapshot's future use */ |
| 103 | + __le32 s_snapshot_list; /* inode number of the head of the |
| 104 | + on-disk snapshot list */ |
| 105 | +#define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count) |
| 106 | + __le32 s_error_count; /* number of fs errors */ |
| 107 | + __le32 s_first_error_time; /* first time an error happened */ |
| 108 | + __le32 s_first_error_ino; /* inode involved in first error */ |
| 109 | + __le64 s_first_error_block; /* block involved of first error */ |
| 110 | + __u8 s_first_error_func[32]; /* function where the error happened */ |
| 111 | + __le32 s_first_error_line; /* line number where error happened */ |
| 112 | + __le32 s_last_error_time; /* most recent time of an error */ |
| 113 | + __le32 s_last_error_ino; /* inode involved in last error */ |
| 114 | + __le32 s_last_error_line; /* line number where error happened */ |
| 115 | + __le64 s_last_error_block; /* block involved of last error */ |
| 116 | + __u8 s_last_error_func[32]; /* function where the error happened */ |
| 117 | +#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts) |
| 118 | + __u8 s_mount_opts[64]; |
| 119 | + __le32 s_usr_quota_inum; /* inode for tracking user quota */ |
| 120 | + __le32 s_grp_quota_inum; /* inode for tracking group quota */ |
| 121 | + __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */ |
| 122 | + __le32 s_reserved[108]; /* Padding to the end of the block */ |
| 123 | + __le32 s_checksum; /* crc32c(superblock) */ |
| 124 | +}; |
| 125 | + |
| 126 | +/* ext4 Group Descriptor Table*/ |
| 127 | +struct ext4_group_desc |
| 128 | +{ |
| 129 | + __u32 bg_block_bitmap; /* Blocks bitmap block */ |
| 130 | + __u32 bg_inode_bitmap; /* Inodes bitmap block */ |
| 131 | + __u32 bg_inode_table; /* Inodes table block */ |
| 132 | + __u16 bg_free_blocks_count; /* Free blocks count */ |
| 133 | + __u16 bg_free_inodes_count; /* Free inodes count */ |
| 134 | + __u16 bg_used_dirs_count; /* Directories count */ |
| 135 | + __u16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ |
| 136 | + __u32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ |
| 137 | + __u16 bg_block_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+bitmap) LSB */ |
| 138 | + __u16 bg_inode_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+bitmap) LSB */ |
| 139 | + __u16 bg_itable_unused; /* Unused inodes count */ |
| 140 | + __u16 bg_checksum; /* crc16(sb_uuid+group+desc) */ |
| 141 | +}; |
| 142 | + |
| 143 | +/* ext4 inode */ |
| 144 | +struct inode |
| 145 | +{ |
| 146 | + __le16 i_mode; /* File mode */ |
| 147 | + __le16 i_uid; /* Low 16 bits of Owner Uid */ |
| 148 | + __le32 i_size_lo; /* Size in bytes */ |
| 149 | + __le32 i_atime; /* Access time */ |
| 150 | + __le32 i_ctime; /* Inode Change time */ |
| 151 | + __le32 i_mtime; /* Modification time */ |
| 152 | + __le32 i_dtime; /* Deletion Time */ |
| 153 | + __le16 i_gid; /* Low 16 bits of Group Id */ |
| 154 | + __le16 i_links_count; /* Links count */ |
| 155 | + __le32 i_blocks_lo; /* Blocks count */ |
| 156 | + __le32 i_flags; /* File flags */ |
| 157 | + union |
| 158 | + { |
| 159 | + struct |
| 160 | + { |
| 161 | + __le32 l_i_version; |
| 162 | + } linux1; |
| 163 | + struct |
| 164 | + { |
| 165 | + __u32 h_i_translator; |
| 166 | + } hurd1; |
| 167 | + struct |
| 168 | + { |
| 169 | + __u32 m_i_reserved1; |
| 170 | + } masix1; |
| 171 | + } osd1; /* OS dependent 1 */ |
| 172 | + __le32 i_block[EXT4_N_BLOCKS]; /* Pointers to blocks */ |
| 173 | + __le32 i_generation; /* File version (for NFS) */ |
| 174 | + __le32 i_file_acl_lo; /* File ACL */ |
| 175 | + __le32 i_size_high; |
| 176 | + __le32 i_obso_faddr; /* Obsoleted fragment address */ |
| 177 | + union |
| 178 | + { |
| 179 | + struct |
| 180 | + { |
| 181 | + __le16 l_i_blocks_high; /* were l_i_reserved1 */ |
| 182 | + __le16 l_i_file_acl_high; |
| 183 | + __le16 l_i_uid_high; /* these 2 fields */ |
| 184 | + __le16 l_i_gid_high; /* were reserved2[0] */ |
| 185 | + __le16 l_i_checksum_lo; /* crc32c(uuid+inum+inode) LE */ |
| 186 | + __le16 l_i_reserved; |
| 187 | + } linux2; |
| 188 | + struct |
| 189 | + { |
| 190 | + __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ |
| 191 | + __u16 h_i_mode_high; |
| 192 | + __u16 h_i_uid_high; |
| 193 | + __u16 h_i_gid_high; |
| 194 | + __u32 h_i_author; |
| 195 | + } hurd2; |
| 196 | + struct |
| 197 | + { |
| 198 | + __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ |
| 199 | + __le16 m_i_file_acl_high; |
| 200 | + __u32 m_i_reserved2[2]; |
| 201 | + } masix2; |
| 202 | + } osd2; /* OS dependent 2 */ |
| 203 | + __le16 i_extra_isize; |
| 204 | + __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */ |
| 205 | + __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ |
| 206 | + __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ |
| 207 | + __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ |
| 208 | + __le32 i_crtime; /* File Creation time */ |
| 209 | + __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ |
| 210 | + __le32 i_version_hi; /* high 32 bits for 64-bit version */ |
| 211 | +}; |
0 commit comments