Skip to main content

Superblock

Struct Superblock 

Source
pub struct Superblock {
Show 40 fields pub inodes_count: u32, pub blocks_count: u64, pub free_blocks_count: u64, pub free_inodes_count: u32, pub r_blocks_count: u64, pub first_data_block: u32, pub log_block_size: u32, pub blocks_per_group: u32, pub inodes_per_group: u32, pub magic: u16, pub state: u16, pub errors_behavior: u16, pub minor_rev_level: u16, pub rev_level: u32, pub inode_size: u16, pub first_inode: u32, pub feature_compat: u32, pub feature_incompat: u32, pub feature_ro_compat: u32, pub uuid: [u8; 16], pub volume_name: String, pub last_mounted: String, pub desc_size: u16, pub reserved_gdt_blocks: u16, pub backup_bgs: [u32; 2], pub hash_seed: [u32; 4], pub default_hash_version: u8, pub checksum_seed: u32, pub journal_inode: u32, pub last_orphan: u32, pub mtime: u32, pub wtime: u32, pub mnt_count: u16, pub max_mnt_count: u16, pub lastcheck: u32, pub checkinterval: u32, pub creator_os: u32, pub def_resuid: u16, pub def_resgid: u16, pub raw: Vec<u8>,
}
Expand description

Parsed in-memory representation of the ext4 superblock. Field names mirror the kernel’s struct ext4_super_block (s_ prefix dropped).

Fields§

§inodes_count: u32§blocks_count: u64§free_blocks_count: u64§free_inodes_count: u32§r_blocks_count: u64

s_r_blocks_count (lo at 0x08, hi at 0x154 — 64-bit on INCOMPAT_64BIT volumes). Blocks reserved for the superuser — explains the gap between free_blocks and what df reports as available to a normal user.

§first_data_block: u32§log_block_size: u32§blocks_per_group: u32§inodes_per_group: u32§magic: u16§state: u16

s_state (0x3A). EXT4_VALID_FS = cleanly unmounted. Any other value means the FS was mounted and not cleanly unmounted (dirty) or that the kernel marked the FS as having errors.

§errors_behavior: u16

s_errors (0x3C). Kernel error policy: 1=continue, 2=remount-ro, 3=panic. Informational from a Swift host’s POV but useful in diagnostics output.

§minor_rev_level: u16

s_minor_rev_level (0x3E). Bumped by filesystem admin tools for minor format tweaks within a major rev_level.

§rev_level: u32§inode_size: u16§first_inode: u32

s_first_ino (0x54, dynamic-rev only). First non-reserved inode number; defaults to 11 on rev_level=1+ filesystems.

§feature_compat: u32§feature_incompat: u32§feature_ro_compat: u32§uuid: [u8; 16]§volume_name: String§last_mounted: String

s_last_mounted (0x88, 64 bytes). Last directory the FS was mounted at — handy for diagnostics (“when was this disk last in another machine?”).

§desc_size: u16§reserved_gdt_blocks: u16

s_reserved_gdt_blocks — blocks held back after the group descriptor table so the filesystem can be grown online.

They sit between the GDT and the block bitmap in every group that carries a superblock backup, and they are not free space: anything that rebuilds a block bitmap has to mark them used or the next allocation writes over the filesystem’s own room to expand.

§backup_bgs: [u32; 2]

s_backup_bgs — the only two groups carrying backups when SPARSE_SUPER2 is set. Meaningless without that feature.

§hash_seed: [u32; 4]§default_hash_version: u8§checksum_seed: u32§journal_inode: u32§last_orphan: u32

s_last_orphan (0xE8). Head of the orphan-inode list — inodes whose link count reached zero while still open. The kernel inserts unlink-while-open targets here so that, on the next mount, recovery can reclaim them. Each inode’s i_dtime field is overloaded to point at the next orphan in the chain; the chain terminates with a zero dtime.

§mtime: u32

s_mtime (0x2C). Timestamp the FS was last mounted.

§wtime: u32

s_wtime (0x30). Timestamp the FS was last written to.

§mnt_count: u16

s_mnt_count (0x34). Mounts since last fsck.

§max_mnt_count: u16

s_max_mnt_count (0x36). Forced fsck after this many mounts; 0 disables.

§lastcheck: u32

s_lastcheck (0x40). Timestamp of the last fsck pass.

§checkinterval: u32

s_checkinterval (0x44). Seconds between forced fscks; 0 disables time-based forced fsck.

§creator_os: u32

s_creator_os (0x48). 0=Linux, 1=Hurd, 2=Masix, 3=FreeBSD, 4=Lites.

§def_resuid: u16

s_def_resuid (0x50). UID with access to reserved blocks.

§def_resgid: u16

s_def_resgid (0x52). GID with access to reserved blocks.

§raw: Vec<u8>

Implementations§

Source§

impl Superblock

Source

pub fn read<D: BlockDevice + ?Sized>(dev: &D) -> Result<Self>

Read and parse the superblock from a block device.

Source

pub fn parse(raw: Vec<u8>) -> Result<Self>

Source

pub fn is_clean(&self) -> bool

Whether the filesystem was cleanly unmounted. false here means the FS was not cleanly unmounted and a journal replay (or fsck) is required before writes are safe. Read-only consumers can still mount a dirty FS; callers that intend to write should surface this to the user and either run fsck or refuse to mount read-write.

Source

pub fn group_has_super(&self, g: u64) -> bool

Whether block group g carries a superblock and group-descriptor backup.

Three layouts, and the filesystem’s own flags decide which:

  • SPARSE_SUPER2: group 0, and the two groups named by s_backup_bgs. Nothing else.
  • SPARSE_SUPER clear: every group. This is the old ext2 layout, and the one that costs most to get wrong — assuming the sparse rule leaves real backups looking like free space.
  • otherwise: the classic sparse rule — groups 0 and 1, and every power of 3, 5 or 7.

Answering unconditionally with the classic rule is wrong in both of the first two cases, and wrong in the direction that matters: on a filesystem without SPARSE_SUPER it reports “no backup here” for groups that have one, so a rebuilt bitmap offers the backup superblock and its descriptor table as free blocks.

Source

pub fn block_size(&self) -> u32

Block size in bytes: 1024 << log_block_size.

Source

pub fn block_group_count(&self) -> u64

Number of block groups.

Source

pub fn is_64bit(&self) -> bool

Whether the 64BIT incompat feature is enabled.

Trait Implementations§

Source§

impl Clone for Superblock

Source§

fn clone(&self) -> Superblock

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Superblock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.