implement truncation

This commit is contained in:
Ashwin Naren
2026-01-18 01:17:19 -08:00
parent 782bef29e6
commit 8df12a027c
2 changed files with 16 additions and 9 deletions

View File

@@ -220,8 +220,15 @@ where
Ok(total_written)
}
async fn truncate(&self, _size: u64) -> Result<()> {
Err(KernelError::NotSupported)
async fn truncate(&self, size: u64) -> Result<()> {
let inner = self.inner.lock().await;
if inner.metadata.file_type != ext4_view::FileType::Regular {
return Err(KernelError::NotSupported);
}
let fs = self.fs_ref.upgrade().unwrap();
let mut file = File::open_inode(&fs.inner, inner.clone())?;
file.truncate(size).await?;
Ok(())
}
async fn getattr(&self) -> Result<FileAttr> {