EXT2/3 Structures, Records
The SUPER_BLOCK structure contains information needed to parse EXT2/3 filesystem.
The SUPER_BLOCK can (must) be found at offset 1024bytes from the begining of LINUX_NATIVE partition.
It length's 1024 bytes.
SUPER BLOCK
[DATA TYPE]Field nameAbout it ...
[DWORD]s_inodes_countInodes count
[DWORD]s_blocks_countBlocks count
[DWORD]s_r_blocks_countReserved blocks count
[DWORD]s_free_blocks_countFree blocks count
[DWORD]s_free_inodes_countFree inodes count
[DWORD]s_first_data_blockFirst Data Block
[DWORD]s_log_block_sizeBlock size
[DWORD]s_log_frag_sizeFragment size
[DWORD]s_blocks_per_group# Blocks per group
[DWORD]s_frags_per_group# Fragments per group
[DWORD]s_inodes_per_group# Inodes per group
[DWORD]s_mtimeMount time
[DWORD]s_wtimeWrite time
[WORD]s_mnt_countMount count
[WORD]s_max_mnt_countMaximal mount count
[WORD]s_magicMagic signature
[WORD]s_stateFile system state
[WORD]s_errorsBehaviour when detecting errors
[WORD]s_minor_rev_levelMinor revision level
[DWORD]s_lastchecktime of last check (*)
[DWORD]s_checkintervalmax. time between checks
[DWORD]s_creator_osOS
[DWORD]s_rev_levelRevision level
[WORD]s_def_resuidDefault uid for reserved blocks
[WORD]s_def_resgidDefault gid for reserved blocks
The next fields are for EXT2_DYNAMIC_REV superblocks only(newer)
[DWORD]s_first_inoFirst non-reserved inode
[WORD]s_inode_sizesize of inode structure
[WORD]s_block_group_nrblock group # of this superblock
[DWORD]s_feature_compatcompatible feature set
[DWORD]s_feature_incompatincompatible feature set
[DWORD]s_feature_ro_compatreadonly-compatible feature set
[DWORD]s_pad[229]Padding to the end of the block
(*)All time records in this structures/recors/types are in seconds. The amount of seconds
passed from 0:00:00 1/january/1970


GROUP DESCRIPTOR
[DATA TYPE]Field nameAbout it ...
[DWORD]bg_block_bitmapBlocks bitmap block
[DWORD]bg_inode_bitmapInodes bitmap block
[DWORD]bg_inode_tableInodes table block
[WORD]bg_free_blocks_countFree blocks count
[WORD]bg_free_inodes_countFree inodes count
[WORD]bg_used_dirs_countDirectories count
[WORD]bg_pad
[DWORD]bg_reserved[2]


INODE
[DATA TYPE]Field nameAbout it ...
[WORD]i_modeFile mode
[WORD]i_uidOwner Uid
[DWORD]i_sizeSize in bytes
[DWORD]i_atimeAccess time
[DWORD]i_ctimeCreation time
[DWORD]i_mtimeModification time
[DWORD]i_dtimeDeletion Time
[WORD]i_gidGroup Id
[WORD]i_links_countLinks count
[DWORD]i_blocksBlocks count
[DWORD]i_flagsFile flags
[DWORD]i_reserved1Reserved 1
[DWORD]i_block[15]Pointers to blocks
[DWORD]i_versionFile version (for NFS)
[DWORD]i_file_aclFile ACL
[DWORD]i_dir_aclDirectory ACL
[DWORD]i_faddrFragment address
[BYTE]i_fragFragment number
[BYTE]i_fsizeFragment size
[WORD]i_pad1
[WORD]i_uid_highhigh bits of uid
[WORD]i_gid_highhigh bits of gid
[DWORD]i_reserved2


WARNING ! EXT2_DIRECTOY structure it is NOT in the same sector/block with the inode !!!
The inode occupies some space (128/256 bytes) just after -INODE BITMAP which is after -BLOCK BITMAP which is after GROUP DESCRIPTOR - which group desciptor is sometimes after SUPER_BLOCK.
. But the EXT2_DIRECTORY structures are store separatlly in a special file.
Directories are normal linked list. Each entry in the directory points to an inode - the inode
contains information about the entry - block(s) used, size, attributes, time(s), creator ... etc.

The inode size on disk can be found in SUPER_BLOCK.s_inode_size (which is 128 or 256 or 512 ...)
So when reading inodes from disk you must take care ! You must not use a predefined constat for inode length (128) but
use the information given by SUPER_BLOCK.s_inode_size.


EXT2 DIRETORY
[DATA TYPE]Field nameAbout it ...
[DWORD]inode_numThe inode containing information about this entry
[WORD]rec_lenLength of this record
[BYTE]name_lenLength of string [filename]
[BYTE]file_typeFile type (2 is for dir)
[BYTE]name[((((neme_len-1) >> 2)+1) << 2)]String containing filename + padding (4 byte allignament)
(*)The last entry -name = filename - contains the filename + padding bytes(dword allignament) !
That means:
name : autoconf.sh
len : 11
So because lenght of filename is 11 which is not DWORD alligned you substract 1,shift right length by 2,then add 1, the shift left by 2. That is : 0b1011 - 1 = 0b1010 ; 0b1010 >> 2 = 0b10 ; 0b10 + 1 = 0b11 ; 0b11 << 2 = 0b1100 (which is 12 and 12 is divisible by 4 !)



Not all directories just EXT2_DIRECTORY record ! There is also hashing (for directories with many files !).
Also there exist HASHING for big directories, backword compatibility must always be kept !
So even if a directory is HASHED it also contains normal EXT2_DIRECTORY fields !
The whole standard is : -- page under development---