Skip to content

Commit

Permalink
Use ensure_last_os_error() with libfuse2
Browse files Browse the repository at this point in the history
Under some conditions, `fuse_mount_compat25` may return -1 to indicate
an error but does not set errno. `io::Error::last_os_error()` will then
be equivalent to `Err(Success)` which is somewhat surprising.

In particular, if the mount options `auto_unmount,allow_{root,other}`
are set but the user does not have `user_allow_other` set in their
`fuse.conf`, the `fusermount` binary will print an error message to
stderr but not set errno.

`fusermount3` has the same behaviour, but this issue was mitigated for
the libfuse3 binding in #178 by mapping `Err(Success)` to
the slightly more useful `Error(Other, "Unspecified Error")`. This
commit applies the same fix to the libfuse2 binding.
  • Loading branch information
str4d authored and cberner committed Aug 24, 2022
1 parent 5d54545 commit 48783dc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/mnt/fuse2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{fuse2_sys::*, with_fuse_args, MountOption};
use super::{ensure_last_os_error, fuse2_sys::*, with_fuse_args, MountOption};
use log::warn;
use std::{
ffi::CString,
Expand All @@ -19,7 +19,7 @@ impl Mount {
with_fuse_args(options, |args| {
let fd = unsafe { fuse_mount_compat25(mountpoint.as_ptr(), args) };
if fd < 0 {
Err(io::Error::last_os_error())
Err(ensure_last_os_error())
} else {
let file = unsafe { File::from_raw_fd(fd) };
Ok((Arc::new(file), Mount { mountpoint }))
Expand Down
1 change: 0 additions & 1 deletion src/mnt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ fn is_mounted(fuse_device: &File) -> bool {
}

/// Ensures that an os error is never 0/Success
#[cfg(feature = "libfuse3")]
fn ensure_last_os_error() -> io::Error {
let err = io::Error::last_os_error();
match err.raw_os_error() {
Expand Down

0 comments on commit 48783dc

Please sign in to comment.