|
@@ -5,7 +5,7 @@ mod private {
|
|
|
use fuse_backend_rs::{
|
|
|
abi::fuse_abi::{stat64, statvfs64, CreateIn},
|
|
|
api::filesystem::{
|
|
|
- Context, DirEntry as FuseDirEntry, Entry, FileSystem, FsOptions, OpenOptions,
|
|
|
+ Context, DirEntry as FuseDirEntry, Entry, FileSystem, FsOptions, OpenOptions, SetattrValid,
|
|
|
},
|
|
|
};
|
|
|
use log::{debug, error, warn};
|
|
@@ -439,9 +439,9 @@ mod private {
|
|
|
write_to(&sb, &mut sb_block)?;
|
|
|
sb_block.mut_meta_body().access_secrets(|secrets| {
|
|
|
secrets.inode = SpecInodes::Sb.into();
|
|
|
- secrets.mode = Self::default_file_mode();
|
|
|
- secrets.uid = Self::uid();
|
|
|
- secrets.gid = Self::gid();
|
|
|
+ secrets.mode = FileType::Reg.value() | 0o666;
|
|
|
+ secrets.uid = 0;
|
|
|
+ secrets.gid = 0;
|
|
|
secrets.nlink = 1;
|
|
|
Ok(())
|
|
|
})?;
|
|
@@ -457,9 +457,9 @@ mod private {
|
|
|
write_to(&Directory::new(), &mut root_block)?;
|
|
|
root_block.mut_meta_body().access_secrets(|secrets| {
|
|
|
secrets.inode = SpecInodes::RootDir.into();
|
|
|
- secrets.mode = Self::default_dir_mode();
|
|
|
- secrets.uid = Self::uid();
|
|
|
- secrets.gid = Self::gid();
|
|
|
+ secrets.mode = FileType::Dir.value() | 0o777;
|
|
|
+ secrets.uid = 0;
|
|
|
+ secrets.gid = 0;
|
|
|
secrets.nlink = 1;
|
|
|
Ok(())
|
|
|
})?;
|
|
@@ -559,22 +559,6 @@ mod private {
|
|
|
.open()
|
|
|
}
|
|
|
|
|
|
- fn default_dir_mode() -> u32 {
|
|
|
- FileType::Dir.value() | 0o755
|
|
|
- }
|
|
|
-
|
|
|
- fn default_file_mode() -> u32 {
|
|
|
- FileType::Reg.value() | 0o644
|
|
|
- }
|
|
|
-
|
|
|
- fn uid() -> u32 {
|
|
|
- unsafe { libc::getuid() }
|
|
|
- }
|
|
|
-
|
|
|
- fn gid() -> u32 {
|
|
|
- unsafe { libc::getgid() }
|
|
|
- }
|
|
|
-
|
|
|
/// Returns the [Err] variant containing the [io::Error] corresponding to [libc::ENOSYS].
|
|
|
fn not_supported<T>() -> io::Result<T> {
|
|
|
let err = io::Error::from_raw_os_error(libc::ENOSYS);
|
|
@@ -1279,6 +1263,64 @@ mod private {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ fn setattr(
|
|
|
+ &self,
|
|
|
+ ctx: &Context,
|
|
|
+ inode: Self::Inode,
|
|
|
+ attr: stat64,
|
|
|
+ _handle: Option<Self::Handle>,
|
|
|
+ valid: SetattrValid,
|
|
|
+ ) -> io::Result<(stat64, Duration)> {
|
|
|
+ debug!("Blocktree::setattr called for inode {inode}");
|
|
|
+ let stat = self.borrow_block(inode, |block| {
|
|
|
+ let ctx = AuthzContext::new(ctx, block.meta());
|
|
|
+ self.authorizer.can_write(&ctx)?;
|
|
|
+
|
|
|
+ let stat = block.mut_meta_body().access_secrets(|secrets| {
|
|
|
+ if valid.intersects(SetattrValid::MODE) {
|
|
|
+ secrets.mode = attr.st_mode;
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::UID) {
|
|
|
+ secrets.uid = attr.st_uid;
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::GID) {
|
|
|
+ secrets.gid = attr.st_gid;
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::SIZE) {
|
|
|
+ warn!("modifying file size with setattr is not supported");
|
|
|
+ return Err(io::Error::from_raw_os_error(libc::EINVAL).into());
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::ATIME) {
|
|
|
+ secrets.atime = (attr.st_atime as u64).into();
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::MTIME) {
|
|
|
+ secrets.mtime = (attr.st_mtime as u64).into();
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::CTIME) {
|
|
|
+ secrets.ctime = (attr.st_ctime as u64).into();
|
|
|
+ }
|
|
|
+ let atime_now = valid.intersects(SetattrValid::ATIME_NOW);
|
|
|
+ let mtime_now = valid.intersects(SetattrValid::MTIME_NOW);
|
|
|
+ if atime_now || mtime_now {
|
|
|
+ let now = Epoch::now();
|
|
|
+ if atime_now {
|
|
|
+ secrets.atime = now;
|
|
|
+ }
|
|
|
+ if mtime_now {
|
|
|
+ secrets.mtime = now;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if valid.intersects(SetattrValid::KILL_SUIDGID) {
|
|
|
+ secrets.mode &= !(libc::S_ISUID | libc::S_ISGID)
|
|
|
+ }
|
|
|
+ Ok(secrets.stat())
|
|
|
+ })?;
|
|
|
+ block.flush_meta()?;
|
|
|
+ Ok(stat)
|
|
|
+ })?;
|
|
|
+ Ok((stat, self.attr_timeout()))
|
|
|
+ }
|
|
|
+
|
|
|
//////////////////////////////////
|
|
|
// METHODS WHICH ARE NOT SUPPORTED
|
|
|
//////////////////////////////////
|
|
@@ -1474,18 +1516,6 @@ mod private {
|
|
|
Self::not_supported()
|
|
|
}
|
|
|
|
|
|
- fn setattr(
|
|
|
- &self,
|
|
|
- _ctx: &Context,
|
|
|
- inode: Self::Inode,
|
|
|
- _attr: stat64,
|
|
|
- _handle: Option<Self::Handle>,
|
|
|
- _valid: fuse_backend_rs::api::filesystem::SetattrValid,
|
|
|
- ) -> io::Result<(stat64, Duration)> {
|
|
|
- debug!("Blocktree::setattr called for inode {inode}");
|
|
|
- Self::not_supported()
|
|
|
- }
|
|
|
-
|
|
|
fn setlk(
|
|
|
&self,
|
|
|
_ctx: &Context,
|