From af02ecfb3fb0da641ebe07c37af094c42dd60c2e Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 8 Mar 2019 15:50:55 +0800 Subject: [PATCH] fix sfs: auto resize when writing to end --- rcore-fs-fuse/src/fuse.rs | 5 ----- rcore-fs-sefs/Cargo.toml | 2 -- rcore-fs-sfs/src/lib.rs | 12 ++++++++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/rcore-fs-fuse/src/fuse.rs b/rcore-fs-fuse/src/fuse.rs index 165dfad..f21ad79 100644 --- a/rcore-fs-fuse/src/fuse.rs +++ b/rcore-fs-fuse/src/fuse.rs @@ -175,11 +175,6 @@ impl Filesystem for VfsFuse { fn write(&mut self, _req: &Request, ino: u64, _fh: u64, offset: i64, data: &[u8], _flags: u32, reply: ReplyWrite) { let inode = try_vfs!(reply, self.get_inode(ino)); - let info = try_vfs!(reply, inode.metadata()); - let end = offset as usize + data.len(); - if end > info.size { - try_vfs!(reply, inode.resize(end)); - } let len = try_vfs!(reply, inode.write_at(offset as usize, data)); reply.written(len as u32); } diff --git a/rcore-fs-sefs/Cargo.toml b/rcore-fs-sefs/Cargo.toml index 4f8ae75..e5d74c8 100644 --- a/rcore-fs-sefs/Cargo.toml +++ b/rcore-fs-sefs/Cargo.toml @@ -9,7 +9,6 @@ rcore-fs = { path = "../rcore-fs" } static_assertions = "0.3" spin = "0.4" log = "0.4" -sgx_tstd = { path = "../../rust-sgx-sdk/sgx_tstd", optional = true } [dependencies.bitvec] version = "0.9" @@ -18,4 +17,3 @@ features = ["alloc"] [features] std = ["rcore-fs/std"] -sgx = ["sgx_tstd"] diff --git a/rcore-fs-sfs/src/lib.rs b/rcore-fs-sfs/src/lib.rs index 786ad92..822c811 100644 --- a/rcore-fs-sfs/src/lib.rs +++ b/rcore-fs-sfs/src/lib.rs @@ -1,7 +1,10 @@ +#![no_std] #![feature(alloc)] #![feature(const_str_len)] extern crate alloc; +#[macro_use] +extern crate log; use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::{Arc, Weak}, vec::Vec}; use core::any::Any; @@ -9,7 +12,6 @@ use core::fmt::{Debug, Error, Formatter}; use core::mem::uninitialized; use bitvec::BitVec; -use log::*; use spin::RwLock; use rcore_fs::dev::Device; @@ -269,9 +271,15 @@ impl vfs::INode for INodeImpl { self._read_at(offset, buf) } fn write_at(&self, offset: usize, buf: &[u8]) -> vfs::Result { - if self.disk_inode.read().type_!=FileType::File { + let DiskINode { type_, size, .. } = **self.disk_inode.read(); + if type_ != FileType::File { return Err(FsError::NotFile); } + // resize if not large enough + let end_offset = offset + buf.len(); + if (size as usize) < end_offset { + self._resize(end_offset)?; + } self._write_at(offset, buf) } /// the size returned here is logical size(entry num for directory), not the disk space used.