Store number of blocks actually used

This commit is contained in:
Jeremy Soller
2025-08-01 11:51:37 -06:00
parent f30b363ce1
commit a1c94311db
8 changed files with 110 additions and 52 deletions
+27 -7
View File
@@ -107,17 +107,25 @@ pub struct Node {
/// The length of this file, in bytes
pub size: Le<u64>,
/// The disk usage of this file, in blocks
pub blocks: Le<u64>,
/// Creation time
pub ctime: Le<u64>,
pub ctime_nsec: Le<u32>,
/// Modification time
pub mtime: Le<u64>,
pub mtime_nsec: Le<u32>,
/// Access time
pub atime: Le<u64>,
pub atime_nsec: Le<u32>,
/// Record level
pub record_level: Le<u32>,
pub padding: [u8; BLOCK_SIZE as usize - 4094],
pub padding: [u8; BLOCK_SIZE as usize - 4038],
/// The first 128 blocks of this file.
///
@@ -143,11 +151,11 @@ pub struct Node {
/// Total size: 16 * 256 * 256 * 256 * RECORD_SIZE (32 TiB, 2 TiB each)
pub level3: [BlockPtr<BlockListL3>; 16],
/// The next 12 * 256 * 256 * 256 * 256 blocks of this file,
/// stored behind 12 level four tables.
/// The next 8 * 256 * 256 * 256 * 256 blocks of this file,
/// stored behind 8 level four tables.
///
/// Total size: 12 * 256 * 256 * 256 * 256 * RECORD_SIZE (6 PiB, 512 TiB each)
pub level4: [BlockPtr<BlockListL4>; 12],
/// Total size: 8 * 256 * 256 * 256 * 256 * RECORD_SIZE (4 PiB, 512 TiB each)
pub level4: [BlockPtr<BlockListL4>; 8],
}
unsafe impl BlockTrait for Node {
@@ -168,6 +176,9 @@ impl Default for Node {
gid: 0.into(),
links: 0.into(),
size: 0.into(),
// Node counts as a block.
//TODO: track all the blocks in indirect levels
blocks: 1.into(),
ctime: 0.into(),
ctime_nsec: 0.into(),
mtime: 0.into(),
@@ -175,12 +186,12 @@ impl Default for Node {
atime: 0.into(),
atime_nsec: 0.into(),
record_level: 0.into(),
padding: [0; BLOCK_SIZE as usize - 4094],
padding: [0; BLOCK_SIZE as usize - 4038],
level0: [BlockPtr::default(); 128],
level1: [BlockPtr::default(); 64],
level2: [BlockPtr::default(); 32],
level3: [BlockPtr::default(); 16],
level4: [BlockPtr::default(); 12],
level4: [BlockPtr::default(); 8],
}
}
}
@@ -253,6 +264,11 @@ impl Node {
self.size.to_ne()
}
/// The disk usage of this file, in blocks.
pub fn blocks(&self) -> u64 {
self.blocks.to_ne()
}
pub fn ctime(&self) -> (u64, u32) {
(self.ctime.to_ne(), self.ctime_nsec.to_ne())
}
@@ -289,6 +305,10 @@ impl Node {
self.size = size.into();
}
pub fn set_blocks(&mut self, blocks: u64) {
self.blocks = blocks.into();
}
pub fn set_mtime(&mut self, mtime: u64, mtime_nsec: u32) {
self.mtime = mtime.into();
self.mtime_nsec = mtime_nsec.into();