Skip to content

Commit

Permalink
⚡ Implement lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Jan 25, 2024
1 parent d705464 commit 35a9690
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
clap = { version = "4.4.18", features = ["derive"] }
fuser = "0.14.0"
id_tree = "1.8.0"
libc = "0.2.152"
log = "0.4.20"
pna = "0.6.0"
simple_logger = "4.3.3"
23 changes: 21 additions & 2 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::file_manager::FileManager;
use fuser::{Filesystem, ReplyAttr, ReplyDirectory, Request};
use fuser::{Filesystem, ReplyAttr, ReplyDirectory, ReplyEntry, Request};
use libc::ENOENT;
use log::info;
use std::ffi::OsStr;
use std::path::PathBuf;
use std::time::Duration;

const TTL: Duration = Duration::from_secs(1);

pub(crate) struct PnaFS {
manager: FileManager,
}
Expand All @@ -17,6 +21,21 @@ impl PnaFS {
}

impl Filesystem for PnaFS {
fn lookup(&mut self, _req: &Request<'_>, parent: u64, name: &OsStr, reply: ReplyEntry) {
info!(
"[Implemented] lookup(parent: {:#x?}, name {:?})",
parent, name
);
let name = name.to_string_lossy().to_string();
let children = self.manager.get_children(parent).unwrap();
let entry = children.iter().find(|it| it.name == name);
if let Some(entry) = entry {
reply.entry(&TTL, &entry.attr, 0);
} else {
reply.error(ENOENT);
}
}

fn getattr(&mut self, _req: &Request<'_>, ino: u64, reply: ReplyAttr) {
info!("[Implemented] getattr(ino: {:#x?})", ino);
let ttl = Duration::from_secs(1);
Expand All @@ -36,7 +55,7 @@ impl Filesystem for PnaFS {
"[Implemented] readdir(ino: {:#x?}, fh: {}, offset: {})",
ino, fh, offset
);
let mut children = self.manager.get_children(ino).unwrap();
let children = self.manager.get_children(ino).unwrap();

let mut current_offset = offset + 1;
for entry in children.into_iter().skip(offset as usize) {
Expand Down

0 comments on commit 35a9690

Please sign in to comment.