A filesystem is defined foremost by it's blocksize. Then, it consists of one blockgroup after another. Each block group has as many blocks in it as there are bits in a single block.

A useful tool for filesystem exploration is lde. It lets you inspect inodes, follow directory tree structure, and view the raw contents of the block device. If you are stupid, the hexedit package is the only hex editor I have found that has both large file support and a tolerable UI. It supports seeking around arbitrarily, so it works well for manually inspecting a block device with a filesystem on it.

superblock

422 /*
423  * Structure of the super block
424  */
425 struct ext3_super_block {
426 /*00*/  __le32  s_inodes_count;         /* Inodes count */
427         __le32  s_blocks_count;         /* Blocks count */
428         __le32  s_r_blocks_count;       /* Reserved blocks count */
429         __le32  s_free_blocks_count;    /* Free blocks count */
430 /*10*/  __le32  s_free_inodes_count;    /* Free inodes count */
431         __le32  s_first_data_block;     /* First Data Block */
432         __le32  s_log_block_size;       /* Block size */
433         __le32  s_log_frag_size;        /* Fragment size */
434 /*20*/  __le32  s_blocks_per_group;     /* # Blocks per group */
435         __le32  s_frags_per_group;      /* # Fragments per group */
436         __le32  s_inodes_per_group;     /* # Inodes per group */
437         __le32  s_mtime;                /* Mount time */
438 /*30*/  __le32  s_wtime;                /* Write time */
439         __le16  s_mnt_count;            /* Mount count */
440         __le16  s_max_mnt_count;        /* Maximal mount count */
441         __le16  s_magic;                /* Magic signature */
442         __le16  s_state;                /* File system state */
443         __le16  s_errors;               /* Behaviour when detecting errors */
444         __le16  s_minor_rev_level;      /* minor revision level */
445 /*40*/  __le32  s_lastcheck;            /* time of last check */
446         __le32  s_checkinterval;        /* max. time between checks */
447         __le32  s_creator_os;           /* OS */
448         __le32  s_rev_level;            /* Revision level */
449 /*50*/  __le16  s_def_resuid;           /* Default uid for reserved blocks */
450         __le16  s_def_resgid;           /* Default gid for reserved blocks */
451         /*
452          * These fields are for EXT3_DYNAMIC_REV superblocks only.
453          *
454          * Note: the difference between the compatible feature set and
455          * the incompatible feature set is that if there is a bit set
456          * in the incompatible feature set that the kernel doesn't
457          * know about, it should refuse to mount the filesystem.
458          *
459          * e2fsck's requirements are more strict; if it doesn't know
460          * about a feature in either the compatible or incompatible
461          * feature set, it must abort and not try to meddle with
462          * things it doesn't understand...
463          */
464         __le32  s_first_ino;            /* First non-reserved inode */
465         __le16   s_inode_size;          /* size of inode structure */
466         __le16  s_block_group_nr;       /* block group # of this superblock */
467         __le32  s_feature_compat;       /* compatible feature set */
468 /*60*/  __le32  s_feature_incompat;     /* incompatible feature set */
469         __le32  s_feature_ro_compat;    /* readonly-compatible feature set */
470 /*68*/  __u8    s_uuid[16];             /* 128-bit uuid for volume */
471 /*78*/  char    s_volume_name[16];      /* volume name */
472 /*88*/  char    s_last_mounted[64];     /* directory where last mounted */
473 /*C8*/  __le32  s_algorithm_usage_bitmap; /* For compression */
474         /*
475          * Performance hints.  Directory preallocation should only
476          * happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on.
477          */
478         __u8    s_prealloc_blocks;      /* Nr of blocks to try to preallocate*/
479         __u8    s_prealloc_dir_blocks;  /* Nr to preallocate for dirs */
480         __le16  s_reserved_gdt_blocks;  /* Per group desc for online growth */
481         /*
482          * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
483          */
484 /*D0*/  __u8    s_journal_uuid[16];     /* uuid of journal superblock */
485 /*E0*/  __le32  s_journal_inum;         /* inode number of journal file */
486         __le32  s_journal_dev;          /* device number of journal file */
487         __le32  s_last_orphan;          /* start of list of inodes to delete */
488         __le32  s_hash_seed[4];         /* HTREE hash seed */
489         __u8    s_def_hash_version;     /* Default hash version to use */
490         __u8    s_reserved_char_pad;
491         __u16   s_reserved_word_pad;
492         __le32  s_default_mount_opts;
493         __le32  s_first_meta_bg;        /* First metablock block group */
494         __u32   s_reserved[190];        /* Padding to the end of the block */
495 };

inode

264 /*
265  * Structure of an inode on the disk
266  */
267 struct ext3_inode {
268         __le16  i_mode;         /* File mode */
269         __le16  i_uid;          /* Low 16 bits of Owner Uid */
270         __le32  i_size;         /* Size in bytes */
271         __le32  i_atime;        /* Access time */
272         __le32  i_ctime;        /* Creation time */
273         __le32  i_mtime;        /* Modification time */
274         __le32  i_dtime;        /* Deletion Time */
275         __le16  i_gid;          /* Low 16 bits of Group Id */
276         __le16  i_links_count;  /* Links count */
277         __le32  i_blocks;       /* Blocks count */
278         __le32  i_flags;        /* File flags */
279         union {
280                 struct {
281                         __u32  l_i_reserved1;
282                 } linux1;
283                 struct {
284                         __u32  h_i_translator;
285                 } hurd1;
286                 struct {
287                         __u32  m_i_reserved1;
288                 } masix1;
289         } osd1;                         /* OS dependent 1 */
290         __le32  i_block[EXT3_N_BLOCKS];/* Pointers to blocks */
291         __le32  i_generation;   /* File version (for NFS) */
292         __le32  i_file_acl;     /* File ACL */
293         __le32  i_dir_acl;      /* Directory ACL */
294         __le32  i_faddr;        /* Fragment address */
295         union {
296                 struct {
297                         __u8    l_i_frag;       /* Fragment number */
298                         __u8    l_i_fsize;      /* Fragment size */
299                         __u16   i_pad1;
300                         __le16  l_i_uid_high;   /* these 2 fields    */
301                         __le16  l_i_gid_high;   /* were reserved2[0] */
302                         __u32   l_i_reserved2;
303                 } linux2;
304                 struct {
305                         __u8    h_i_frag;       /* Fragment number */
306                         __u8    h_i_fsize;      /* Fragment size */
307                         __u16   h_i_mode_high;
308                         __u16   h_i_uid_high;
309                         __u16   h_i_gid_high;
310                         __u32   h_i_author;
311                 } hurd2;
312                 struct {
313                         __u8    m_i_frag;       /* Fragment number */
314                         __u8    m_i_fsize;      /* Fragment size */
315                         __u16   m_pad1;
316                         __u32   m_i_reserved2[2];
317                 } masix2;
318         } osd2;                         /* OS dependent 2 */
319         __le16  i_extra_isize;
320         __le16  i_pad1;
321 };

Directory Entry Layout

bits

type

name

613 /*
614  * Structure of a directory entry
615  */
616 #define EXT3_NAME_LEN 255
617 
618 struct ext3_dir_entry {
619         __le32  inode;                  /* Inode number */
620         __le16  rec_len;                /* Directory entry length */
621         __le16  name_len;               /* Name length */
622         char    name[EXT3_NAME_LEN];    /* File name */

refs

Hints for fixing it

Ext2Filesystem (last edited 2009-12-16 21:22:16 by RichardDarst)