written idea for storage of "infinite" indirects

This commit is contained in:
husky 2023-08-15 00:27:40 -07:00
parent a6c4812797
commit ca82cdb4d4
No known key found for this signature in database
GPG key ID: 6B3D8CB511646891

View file

@ -198,8 +198,29 @@ pub struct Inode {
/// Flags field, see `InodeFlags`
pub flags: u32,
/// Direct-Block-Addresses, last three are indirect if `InodeFlags::INDIRECT` is set
/// Indirect blocks are Indexes to other blocks, their contents are a u64 count "N" followed by N u64 indexes
/// both are pointers to data blocks, starting from data block 0
/// Indirect blocks are Indexes to other blocks, their contents are a u64 count "N" followed by
/// for each entry...
/// is_data: bool (true if data block, false if another indirect block)
/// depth: u56 (in total, how many indirect blocks are pointed to if this isn't data, and how many indirect blocks do they point to if they have indirect blocks)
/// ptr: u64 (if is_data, then this is a data block, otherwise it is an indirect block)
/// both direct and indirect are pointers to data blocks, starting from data block 0
/// ====
/// these pointers can be addressed via a u64 in the following way:
/// if i < 12, then it refers to a direct block in this array (undefined behaviour if indirect is set and i > 9)
/// if i == 12, then it refers to the first index found by going to the first indirect block, and recursing through each found indirect block until the first data block is found.
/// if i == 13, then it refers to the second index found by going to the first indirect block, and recursing through each found indirect block until the second data block is found.
/// ==
/// the algorithm for finding the nth data block is as follows:
/// if n < 12, then it is the nth direct block
/// if n >= 12...
/// let mut n = n - 12;
/// let mut block_i = n / (block_size - 8);
/// // block_i is how many indirect blocks we need to traverse to get to the indirect block that contains the nth data block
/// let mut current_block = self.direct_block_addresses[12];
/// while not found...
/// // read block, if not data then check depth,
/// // if depth implies that this indirect block could contain the nth data block, then recurse
/// // otherwise, subtract the depth from n, and continue
pub direct_block_addresses: [Index; 12],
/// CRC32 checksum of this inode
pub checksum: u32,