Skip to content

Commit

Permalink
Add lookup() and forget()
Browse files Browse the repository at this point in the history
Just as notifications to the filesystem implementation; no return value.

Fixes #20
  • Loading branch information
wfraser committed Oct 20, 2017
1 parent 92131b0 commit f58ef44
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions example/src/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ impl FilesystemMT for PassthroughFS {
debug!("destroy");
}

fn lookup(&self, _req: RequestInfo, path: &Path) {
debug!("lookup: {:?}", path);
}

fn forget(&self, _req: RequestInfo, path: &Path) {
debug!("forget: {:?}", path);
}

fn getattr(&self, _req: RequestInfo, path: &Path, fh: Option<u64>) -> ResultEntry {
debug!("getattr: {:?}", path);

Expand Down
4 changes: 3 additions & 1 deletion src/fusemt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl<T: FilesystemMT + Sync + Send + 'static> fuse::Filesystem for FuseMT<T> {
let parent_path = get_path!(self, parent, reply);
debug!("lookup: {:?}, {:?}", parent_path, name);
let path = Arc::new((*parent_path).clone().join(name));
self.target.lookup(req.info(), &path);
match self.target.getattr(req.info(), &path, None) {
Ok((ttl, attr)) => {
let (ino, generation) = self.inodes.add_or_get(path.clone());
Expand All @@ -120,10 +121,11 @@ impl<T: FilesystemMT + Sync + Send + 'static> fuse::Filesystem for FuseMT<T> {
}
}

fn forget(&mut self, _req: &fuse::Request, ino: u64, nlookup: u64) {
fn forget(&mut self, req: &fuse::Request, ino: u64, nlookup: u64) {
let path = self.inodes.get_path(ino).unwrap_or_else(|| {
Arc::new(PathBuf::from("[unknown]"))
});
self.target.forget(req.info(), &path);
let lookups = self.inodes.forget(ino, nlookup);
debug!("forget: inode {} ({:?}) now at {} lookups", ino, path, lookups);
}
Expand Down
12 changes: 12 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ pub trait FilesystemMT {
// Nothing.
}

/// Called when a path is looked up for the first time. This call will be immediately followed
/// by a call to `getattr` with the same path.
fn lookup(&self, _req: RequestInfo, _path: &Path) {
// Nothing.
}

/// Called when the kernel is removing an inode from its internal caches. Filesystems can use
/// this to clean up their own caches.
fn forget(&self, _req: RequestInfo, _path: &Path) {
// Nothing.
}

/// Get the attributes of a filesystem entry.
///
/// * `fh`: a file handle if this is called on an open file.
Expand Down

0 comments on commit f58ef44

Please sign in to comment.