replace chmod by set_metadata in INode

master
WangRunji 6 years ago
parent c611248f80
commit 05a4df20bf

@ -28,6 +28,12 @@ impl VfsFuse {
nsec: time.nsec,
}
}
fn trans_time_r(time: Timespec) -> vfs::Timespec {
vfs::Timespec {
sec: time.sec,
nsec: time.nsec,
}
}
fn trans_attr(info: vfs::Metadata) -> FileAttr {
FileAttr {
ino: info.inode as u64,
@ -40,8 +46,8 @@ impl VfsFuse {
kind: Self::trans_type(info.type_),
perm: info.mode,
nlink: info.nlinks as u32,
uid: info.uid as u32,
gid: info.gid as u32,
uid: 501, // info.uid as u32,
gid: 20, // info.gid as u32,
rdev: 0,
flags: 0,
}
@ -59,20 +65,19 @@ impl VfsFuse {
}
fn trans_error(err: vfs::FsError) -> i32 {
use libc::*;
use vfs::FsError::*;
match err {
NotSupported => ENOSYS,
EntryNotFound => ENOENT,
EntryExist => EEXIST,
IsDir => EISDIR,
NotFile => EISDIR,
NotDir => ENOTDIR,
NotSameFs => EXDEV,
InvalidParam => EINVAL,
NoDeviceSpace => ENOSPC,
DirRemoved => ENOENT,
DirNotEmpty => ENOTEMPTY,
WrongFs => EINVAL,
vfs::FsError::NotSupported => ENOSYS,
vfs::FsError::EntryNotFound => ENOENT,
vfs::FsError::EntryExist => EEXIST,
vfs::FsError::IsDir => EISDIR,
vfs::FsError::NotFile => EISDIR,
vfs::FsError::NotDir => ENOTDIR,
vfs::FsError::NotSameFs => EXDEV,
vfs::FsError::InvalidParam => EINVAL,
vfs::FsError::NoDeviceSpace => ENOSPC,
vfs::FsError::DirRemoved => ENOENT,
vfs::FsError::DirNotEmpty => ENOTEMPTY,
vfs::FsError::WrongFs => EINVAL,
_ => EINVAL,
}
}
@ -118,6 +123,45 @@ impl Filesystem for VfsFuse {
reply.attr(&TTL, &attr);
}
fn setattr(
&mut self,
_req: &Request,
ino: u64,
mode: Option<u32>,
uid: Option<u32>,
gid: Option<u32>,
_size: Option<u64>,
atime: Option<Timespec>,
mtime: Option<Timespec>,
_fh: Option<u64>,
_crtime: Option<Timespec>,
_chgtime: Option<Timespec>,
_bkuptime: Option<Timespec>,
_flags: Option<u32>,
reply: ReplyAttr,
) {
let inode = try_vfs!(reply, self.get_inode(ino));
let mut info = try_vfs!(reply, inode.metadata());
if let Some(mode) = mode {
info.mode = mode as u16;
}
if let Some(uid) = uid {
info.uid = uid as usize;
}
if let Some(gid) = gid {
info.gid = gid as usize;
}
if let Some(atime) = atime {
info.atime = Self::trans_time_r(atime);
}
if let Some(mtime) = mtime {
info.mtime = Self::trans_time_r(mtime);
}
try_vfs!(reply, inode.set_metadata(&info));
let attr = Self::trans_attr(info);
reply.attr(&TTL, &attr);
}
fn mknod(
&mut self,
_req: &Request,
@ -141,6 +185,7 @@ impl Filesystem for VfsFuse {
let inode = try_vfs!(reply, self.get_inode(parent));
let target = try_vfs!(reply, inode.create(name, vfs::FileType::Dir, mode));
let info = try_vfs!(reply, target.metadata());
self.inodes.insert(info.inode, target);
let attr = Self::trans_attr(info);
reply.entry(&TTL, &attr, 0);
}

@ -2,9 +2,6 @@
#![feature(alloc)]
extern crate alloc;
#[cfg(feature = "sgx")]
#[macro_use]
extern crate sgx_tstd as std;
use alloc::{
boxed::Box,
@ -191,13 +188,16 @@ impl vfs::INode for INodeImpl {
blk_size: 0x1000,
})
}
fn chmod(&self, mode: u16) -> vfs::Result<()> {
fn set_metadata(&self, metadata: &vfs::Metadata) -> vfs::Result<()> {
let mut disk_inode = self.disk_inode.write();
disk_inode.mode = mode;
disk_inode.mode = metadata.mode;
disk_inode.uid = metadata.uid as u16;
disk_inode.gid = metadata.gid as u8;
disk_inode.atime = metadata.atime.sec as u32;
disk_inode.mtime = metadata.mtime.sec as u32;
disk_inode.ctime = metadata.ctime.sec as u32;
Ok(())
}
fn sync_all(&self) -> vfs::Result<()> {
let mut disk_inode = self.disk_inode.write();
if disk_inode.dirty() {
@ -206,10 +206,12 @@ impl vfs::INode for INodeImpl {
.write_block(self.id, disk_inode.as_buf())?;
disk_inode.sync();
}
self.sync_data()?;
Ok(())
}
fn sync_data(&self) -> vfs::Result<()> {
self.sync_all()
self.file.flush()?;
Ok(())
}
fn resize(&self, len: usize) -> vfs::Result<()> {
if self.disk_inode.read().type_ != FileType::File {

@ -421,12 +421,10 @@ impl vfs::INode for INodeImpl {
blk_size: BLKSIZE,
})
}
fn chmod(&self, _mode: u16) -> vfs::Result<()> {
fn set_metadata(&self, _metadata: &vfs::Metadata) -> vfs::Result<()> {
// No-op for sfs
Ok(())
}
fn sync_all(&self) -> vfs::Result<()> {
let mut disk_inode = self.disk_inode.write();
if disk_inode.dirty() {

@ -9,7 +9,7 @@ pub trait INode: Any + Sync + Send {
fn read_at(&self, offset: usize, buf: &mut [u8]) -> Result<usize>;
fn write_at(&self, offset: usize, buf: &[u8]) -> Result<usize>;
fn metadata(&self) -> Result<Metadata>;
fn chmod(&self, mode: u16) -> Result<()>;
fn set_metadata(&self, metadata: &Metadata) -> Result<()>;
/// Sync all data and metadata
fn sync_all(&self) -> Result<()>;
/// Sync data (not include metadata)

Loading…
Cancel
Save