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

14
Cargo.lock generated
View File

@@ -92,7 +92,7 @@ dependencies = [
[[package]]
name = "ext4-view"
version = "0.9.3"
source = "git+https://github.com/arihant2math/ext4-view-rs.git?branch=main#adb7c88dd8acba198f8c701e664b2a03ca9df339"
source = "git+https://github.com/arihant2math/ext4-view-rs.git?branch=main#6408b7de5947ac04cfce03579b586ec8b5fa0d6d"
dependencies = [
"async-trait",
"bitflags",
@@ -430,9 +430,9 @@ dependencies = [
[[package]]
name = "rand_core"
version = "0.9.3"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
dependencies = [
"getrandom",
]
@@ -606,9 +606,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
version = "1.0.2+wasi-0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
dependencies = [
"wit-bindgen",
]
@@ -704,9 +704,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
[[package]]
name = "wit-bindgen"
version = "0.46.0"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
[[package]]
name = "zerocopy"

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> {