From 7eb9848ba7085dbb615b3bda508abab9d1874476 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Mon, 9 Sep 2019 18:27:29 +0200 Subject: [PATCH] src/pxar/fuse.rs: impl opendir callback for fuse Signed-off-by: Christian Ebner --- src/pxar/fuse.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pxar/fuse.rs b/src/pxar/fuse.rs index 8cbe7a99..43e0fe3f 100644 --- a/src/pxar/fuse.rs +++ b/src/pxar/fuse.rs @@ -453,11 +453,19 @@ extern "C" fn read(req: Request, inode: u64, size: size_t, offset: c_int, _filei }); } -extern "C" fn opendir(req: Request, inode: u64, _fileinfo: MutPtr) { - run_in_context(req, inode, |_decoder, _ino_offset| { - // code goes here +/// Open the directory referenced by the given inode for reading. +/// +/// This simply checks if the inode references a valid directory, no internal +/// state identifies the directory as opened. +extern "C" fn opendir(req: Request, inode: u64, fileinfo: MutPtr) { + run_in_context(req, inode, |mut decoder, ino_offset| { + let (attr, _) = stat(&mut decoder, ino_offset).map_err(|_| libc::ENOENT)?; + if attr.st_mode & libc::S_IFMT != libc::S_IFDIR { + return Err(libc::ENOENT); + } + let _ret = unsafe { fuse_reply_open(req, fileinfo) }; - Err(libc::ENOENT) + Ok(()) }); }