Compare commits
No commits in common. "2e4934e986130839a5a2ce58620679404b3389ea" and "5bd839e0229b174a2ac0810c2473522a3b1de405" have entirely different histories.
2e4934e986
...
5bd839e022
53
src/fs.rs
53
src/fs.rs
@ -1,18 +1,11 @@
|
||||
use std::{
|
||||
cmp::min,
|
||||
collections::HashMap,
|
||||
ffi::{OsStr, OsString},
|
||||
iter::repeat,
|
||||
time::{Duration, SystemTime},
|
||||
cmp::min, collections::HashMap, ffi::{OsStr, OsString}, iter::repeat, time::{Duration, SystemTime}
|
||||
};
|
||||
|
||||
use fuser::{
|
||||
consts::{FOPEN_DIRECT_IO, FOPEN_KEEP_CACHE, FUSE_WRITEBACK_CACHE},
|
||||
FileAttr, FileType, Filesystem, TimeOrNow,
|
||||
};
|
||||
use fuser::{consts::{FOPEN_DIRECT_IO, FOPEN_KEEP_CACHE, FUSE_WRITEBACK_CACHE}, FileAttr, FileType, Filesystem, TimeOrNow};
|
||||
use nix::{
|
||||
libc::{
|
||||
EBADF, EBUSY, EEXIST, EINVAL, EISDIR, ENOENT, ENOTDIR, EPERM, O_DIRECT, O_RDONLY, SEEK_SET,
|
||||
EBADF, EBUSY, EEXIST, EINVAL, EISDIR, ENOENT, ENOTDIR, EPERM, O_DIRECT, O_RDONLY, SEEK_SET
|
||||
},
|
||||
unistd::{getgid, getuid},
|
||||
};
|
||||
@ -151,11 +144,7 @@ impl CorruptFs {
|
||||
}
|
||||
|
||||
impl Filesystem for CorruptFs {
|
||||
fn init(
|
||||
&mut self,
|
||||
_req: &fuser::Request<'_>,
|
||||
config: &mut fuser::KernelConfig,
|
||||
) -> Result<(), nix::libc::c_int> {
|
||||
fn init(&mut self, _req: &fuser::Request<'_>, config: &mut fuser::KernelConfig) -> Result<(), nix::libc::c_int> {
|
||||
if let Err(unsup) = config.add_capabilities(FUSE_WRITEBACK_CACHE) {
|
||||
warn!("Unsupported kernel caps: 0x{:08x}", unsup);
|
||||
}
|
||||
@ -238,13 +227,9 @@ impl Filesystem for CorruptFs {
|
||||
if req.uid() != getuid().as_raw() {
|
||||
reply.error(EPERM);
|
||||
} else if let Some((file, _)) = fh.and_then(|fh| self.open_file_with_file_mut(fh)) {
|
||||
do_setattr(
|
||||
file, mode, uid, gid, size, atime, mtime, ctime, crtime, reply,
|
||||
);
|
||||
do_setattr(file, mode, uid, gid, size, atime, mtime, ctime, crtime, reply);
|
||||
} else if let Some(file) = self.files.get_mut(&ino) {
|
||||
do_setattr(
|
||||
file, mode, uid, gid, size, atime, mtime, ctime, crtime, reply,
|
||||
);
|
||||
do_setattr(file, mode, uid, gid, size, atime, mtime, ctime, crtime, reply);
|
||||
} else {
|
||||
reply.error(ENOENT);
|
||||
}
|
||||
@ -260,11 +245,12 @@ impl Filesystem for CorruptFs {
|
||||
let open_file = OpenFile { ino, flags };
|
||||
self.open_fds.insert(fh, OpenFd::File(open_file));
|
||||
|
||||
let o_flags = if (flags & O_DIRECT) != 0 {
|
||||
FOPEN_DIRECT_IO
|
||||
} else {
|
||||
FOPEN_KEEP_CACHE
|
||||
};
|
||||
let o_flags =
|
||||
if (flags & O_DIRECT) != 0 {
|
||||
FOPEN_DIRECT_IO
|
||||
} else {
|
||||
FOPEN_KEEP_CACHE
|
||||
};
|
||||
reply.opened(fh, o_flags);
|
||||
} else {
|
||||
reply.error(ENOENT);
|
||||
@ -311,11 +297,12 @@ impl Filesystem for CorruptFs {
|
||||
};
|
||||
self.open_fds.insert(fh, OpenFd::File(open_file));
|
||||
|
||||
let cr_flags = if (flags & O_DIRECT) != 0 {
|
||||
FOPEN_DIRECT_IO
|
||||
} else {
|
||||
FOPEN_KEEP_CACHE
|
||||
};
|
||||
let cr_flags =
|
||||
if (flags & O_DIRECT) != 0 {
|
||||
FOPEN_DIRECT_IO
|
||||
} else {
|
||||
FOPEN_KEEP_CACHE
|
||||
};
|
||||
reply.created(&TTL, &attr, 0, fh, cr_flags);
|
||||
}
|
||||
}
|
||||
@ -657,9 +644,7 @@ fn do_setattr(
|
||||
crtime: Option<SystemTime>,
|
||||
reply: fuser::ReplyAttr,
|
||||
) {
|
||||
if uid.filter(|uid| *uid != getuid().as_raw()).is_some()
|
||||
|| gid.filter(|gid| *gid != getgid().as_raw()).is_some()
|
||||
{
|
||||
if uid.filter(|uid| *uid != getuid().as_raw()).is_some() || gid.filter(|gid| *gid != getgid().as_raw()).is_some() {
|
||||
reply.error(EPERM);
|
||||
} else {
|
||||
if let Some(mode) = mode {
|
||||
|
@ -41,10 +41,5 @@ fn main() {
|
||||
.map(|opt| MountOption::CUSTOM(opt.clone())),
|
||||
);
|
||||
|
||||
fuser::mount2(
|
||||
fs::CorruptFs::new(args.allow_direct_io),
|
||||
args.mount_point,
|
||||
&options,
|
||||
)
|
||||
.unwrap();
|
||||
fuser::mount2(fs::CorruptFs::new(args.allow_direct_io), args.mount_point, &options).unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user