pub struct Inode {
pub header: InodeHeader,
pub extra: Option<InodeExtraAttr>,
pub inline_data: Option<Box<[u8]>>,
pub footer: InodeFooter,
pub xattr: Vec<XattrEntry>,
pub context: Option<Context>,
pub block_addrs: Vec<u32>,
/* private fields */
}Expand description
Inode represents a file or directory and consumes one 4kB block in the metadata region.
An Inode’s basic layout is as follows: +–––––––+ | InodeHeader | +–––––––+ | i_addrs[923] | +–––––––+ | nids[5] | +–––––––+ | InodeFooter | +–––––––+
The i_addrs region consists of 32-bit block addresses to data associated with the inode. Some or all of this may be repurposed for optional structures based on header flags:
- extra: Contains additional metadata. Consumes the first 9 entries of i_addrs.
- xattr: Extended attributes. Consumes the last 50 entries of i_addrs.
- inline_data: Consumes all remaining i_addrs. If used, no external data blocks are used.
- inline_dentry: Consumes all remaining i_addrs. If used, no external data blocks are used.
For inodes that do not contain inline data or inline dentry, the remaining i_addrs[] list the block offsets for data blocks that contain the contents of the inode. A value of NULL_ADDR indicates a zero page. A value of NEW_ADDR indicates a page that has not yet been allocated and should be treated the same as a zero page for our purposes.
If a file contains more data than available i_addrs[], nids[] will be used.
nids[0] and nids[1] are what F2fs called “direct node” blocks. These contain nids (i.e. NAT translated block addresses) to RawAddrBlock. Each RawAddrBlock contains up to 1018 block offsets to data blocks.
If that is insufficient, nids[2] and nids[3] contain what F2fs calls “indirect node” blocks. This is the same format as RawAddrBlock but each entry contains the nid of another RawAddrBlock, providing another layer of indirection and thus the ability to reference 1018^2 further blocks.
Finally, nids[4] may point at a “double indirect node” block. This adds one more layer of indirection, allowing for a further 1018^3 blocks.
For sparse files, any individual blocks or pages of blocks (at any indirection level) may be replaced with NULL_ADDR.
Block addressing starts at i_addrs and flows through each of nids[0..5] in order.
Fields§
§header: InodeHeader§extra: Option<InodeExtraAttr>§inline_data: Option<Box<[u8]>>§xattr: Vec<XattrEntry>§context: Option<Context>§block_addrs: Vec<u32>Implementations§
Source§impl Inode
impl Inode
Sourcepub fn data_blocks(&self) -> DataBlocksIter<'_>
pub fn data_blocks(&self) -> DataBlocksIter<'_>
Walks through the data blocks of the file in order, handling sparse regions. Emits extents of (logical_block_num, physical_block_num, length).
Sourcepub fn data_block_addr(&self, block_num: u32) -> u32
pub fn data_block_addr(&self, block_num: u32) -> u32
Get the address of a specific logical data block. NULL_ADDR and NEW_ADDR should be considered sparse (unallocated) zero blocks.