Skip to content

Commit

Permalink
Add missing FUSE operations
Browse files Browse the repository at this point in the history
Remove usages of 'folder' instead of 'directory'
  • Loading branch information
cout970 committed Sep 1, 2024
1 parent 3bc1205 commit 3900ef1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ primary:
# Gzip compression, values from 0 to 9, where 0 is no compression and 1 (fastest) to 9 (slowest) are the compression levels
# Automatically disabled if [encryption_key] is set, not recommended for backends that already compress data, like RocksBD or S3
compression_level: 0
# If set to true, the blobs will be stored on a single folder with a hash as filename
# If set to true, the blobs will be stored on a single directory with a hash as filename
# otherwise, the original full path will be preserved
# It is recommended to set this to true if using encryption, otherwise the directory structure
# and filenames will be visible
Expand Down
65 changes: 63 additions & 2 deletions src/fuse_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::ffi::OsStr;
use std::path::Path;
use std::time::{Duration, SystemTime};
use cntr_fuse::{FileAttr, FileType, Filesystem, ReplyAttr, ReplyBmap, ReplyCreate, ReplyData, ReplyDirectory, ReplyEmpty, ReplyEntry, ReplyLock, ReplyOpen, ReplyRead, ReplyStatfs, ReplyWrite, Request, UtimeSpec};
use cntr_fuse::{fuse_forget_one, FileAttr, FileType, Filesystem, ReplyAttr, ReplyBmap, ReplyCreate, ReplyData, ReplyDirectory, ReplyDirectoryPlus, ReplyEmpty, ReplyEntry, ReplyIoctl, ReplyLock, ReplyLseek, ReplyOpen, ReplyRead, ReplyStatfs, ReplyWrite, Request, UtimeSpec};
use libc::{c_int, ENOENT, ENOSYS, O_APPEND, O_CREAT, O_DSYNC, O_EXCL, O_NOATIME, O_NOCTTY, O_NONBLOCK, O_PATH, O_RDONLY, O_RDWR, O_SYNC, O_TMPFILE, O_TRUNC, O_WRONLY};
use log::{error, trace, warn};

Expand Down Expand Up @@ -129,6 +129,18 @@ impl Filesystem for FuseFileSystem {
}
}

fn forget(&mut self, _req: &Request<'_>, ino: u64, nlookup: u64) {
if FINE_LOGGING {
trace!("FS forget(ino: {}, nlookup: {})", ino, nlookup);
}
}

fn forget_multi(&mut self, _req: &Request<'_>, forget_data: &[fuse_forget_one]) {
if FINE_LOGGING {
trace!("FS forget_multi({:?})", forget_data);
}
}

fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) {
if FINE_LOGGING {
trace!("FS getattr(ino: {})", ino);
Expand Down Expand Up @@ -307,6 +319,10 @@ impl Filesystem for FuseFileSystem {
}
}

fn rename2(&mut self, _req: &Request<'_>, parent: u64, name: &OsStr, newparent: u64, newname: &OsStr, _flags: u32, reply: ReplyEmpty) {
self.rename(_req, parent, name, newparent, newname, reply);
}

fn link(&mut self, _req: &Request, _ino: u64, _newparent: u64, _newname: &OsStr, reply: ReplyEntry) {
trace!("FS link(ino: {}, newparent: {}, newname: {:?})", _ino, _newparent, _newname);
warn!("Link not implemented");
Expand Down Expand Up @@ -342,7 +358,7 @@ impl Filesystem for FuseFileSystem {
reply.data(&data);
}
Err(e) => {
error!("Error reading file: {:?}", e.error);
error!("Error reading file: {:?}", e.error);
reply.error(e.code);
}
}
Expand Down Expand Up @@ -427,6 +443,33 @@ impl Filesystem for FuseFileSystem {
}
}

fn readdirplus(&mut self, _req: &Request<'_>, ino: u64, fh: u64, offset: u64, mut reply: ReplyDirectoryPlus) {
if FINE_LOGGING {
trace!("FS readdirplus(ino: {}, file_handle: {}, offset: {})", ino, fh, offset);
}

match self.fs.readdir(ino as i64, offset as i64) {
Ok(entries) => {
let mut index = offset + 1;
for e in entries {
let ino = e.entry_file_id as u64;
let file = self.fs.get_file_or_err(e.entry_file_id).unwrap();
let attr = FileAttr::from(&file);

if reply.add(ino, index as i64, e.name, &self.get_ttl(), &attr, 0) {
break;
}
index += 1;
}
reply.ok();
}
Err(e) => {
error!("Error reading directory: {:?}", e.error);
reply.error(e.code);
}
}
}

fn releasedir(&mut self, _req: &Request, _ino: u64, _fh: u64, _flags: u32, reply: ReplyEmpty) {
if FINE_LOGGING {
trace!("FS releasedir(ino: {}, file_handle: {}, flags: {})", _ino, _fh, _flags);
Expand Down Expand Up @@ -525,6 +568,24 @@ impl Filesystem for FuseFileSystem {
warn!("Bmap not implemented");
reply.error(ENOSYS);
}

fn ioctl(&mut self, _req: &Request<'_>, _ino: u64, _fh: u64, _flags: u32, _cmd: u32, _in_data: Option<&[u8]>, _out_size: u32, reply: ReplyIoctl) {
trace!("FS ioctl(ino: {}, file_handle: {}, flags: {}, cmd: {}, in_data: {:?}, out_size: {})", _ino, _fh, _flags, _cmd, _in_data, _out_size);
warn!("Operation ioctl not implemented");
reply.error(ENOSYS);
}

fn fallocate(&mut self, _req: &Request<'_>, _ino: u64, _fh: u64, _offset: u64, _length: u64, _mode: u32, reply: ReplyEmpty) {
trace!("FS fallocate(ino: {})", _ino);
warn!("Operation fallocate not implemented");
reply.error(ENOSYS);
}

fn lseek(&mut self, _req: &Request<'_>, _ino: u64, _fh: u64, _offset: i64, _whence: u32, reply: ReplyLseek) {
trace!("FS lseek(ino: {}, file_handle: {}, offset: {}, whence: {})", _ino, _fh, _offset, _whence);
warn!("Operation lseek not implemented");
reply.error(ENOSYS);
}
}

impl From<&FileRow> for FileAttr {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn mount(fs: SqlFileSystem) -> Result<(), AnyError> {
}
}

info!("Folder was unmounted successfully, exiting");
info!("Directory was unmounted successfully, exiting");
Ok(())
}

Expand Down

0 comments on commit 3900ef1

Please sign in to comment.