Skip to content

Commit

Permalink
feat(ofs): introduce ofs macos support (apache#5136)
Browse files Browse the repository at this point in the history
* feat(ofs): introduce ofs macos stpport

* feat: fix code
  • Loading branch information
oowl authored Sep 27, 2024
1 parent d479ac3 commit 43e4d7d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 48 deletions.
41 changes: 6 additions & 35 deletions bin/ofs/Cargo.lock

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

4 changes: 2 additions & 2 deletions bin/ofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ tokio = { version = "1.37.0", features = [
] }
url = "2.5.0"

[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
fuse3 = { "version" = "0.7.2", "features" = ["tokio-runtime", "unprivileged"] }
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))'.dependencies]
fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] }
fuse3_opendal = { version = "0.0.7", path = "../../integrations/fuse3" }
libc = "0.2.154"
nix = { version = "0.29.0", features = ["user"] }
Expand Down
12 changes: 2 additions & 10 deletions bin/ofs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() -> Result<()> {
execute(cfg).await
}

#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
async fn execute(cfg: Config) -> Result<()> {
use std::env;
use std::str::FromStr;
Expand Down Expand Up @@ -71,7 +71,7 @@ async fn execute(cfg: Config) -> Result<()> {
let mut uid = nix::unistd::getuid().into();
mount_options.uid(uid);

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
let mut mount_handle = if nix::unistd::getuid().is_root() {
if let Some(sudo_gid) = env::var("SUDO_GID")
.ok()
Expand Down Expand Up @@ -100,9 +100,6 @@ async fn execute(cfg: Config) -> Result<()> {
.await?
};

#[cfg(target_os = "freebsd")]
let mut mount_handle = Fuse::new().mount(cfg.mount_path, backend).await?;

let handle = &mut mount_handle;
tokio::select! {
res = handle => res?,
Expand Down Expand Up @@ -190,8 +187,3 @@ async fn execute(cfg: Config) -> Result<()> {

Ok(())
}

#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "windows")))]
async fn execute(_cfg: Config) -> Result<()> {
Err(anyhow!("platform not supported"))
}
2 changes: 1 addition & 1 deletion integrations/fuse3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ version = "0.0.7"

[dependencies]
bytes = "1.6.0"
fuse3 = { version = "0.7.2", "features" = ["tokio-runtime", "unprivileged"] }
fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] }
futures-util = "0.3.30"
libc = "0.2.155"
log = "0.4.21"
Expand Down
23 changes: 23 additions & 0 deletions integrations/fuse3/src/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ impl PathFilesystem for Filesystem {
Err(libc::EOPNOTSUPP.into())
}

async fn opendir(&self, _req: Request, path: &OsStr, flags: u32) -> Result<ReplyOpen> {
log::debug!("opendir(path={:?}, flags=0x{:x})", path, flags);
Ok(ReplyOpen { fh: 0, flags })
}

async fn open(&self, _req: Request, path: &OsStr, flags: u32) -> Result<ReplyOpen> {
log::debug!("open(path={:?}, flags=0x{:x})", path, flags);

Expand Down Expand Up @@ -821,6 +826,20 @@ impl PathFilesystem for Filesystem {
copied: u64::from(written),
})
}

async fn statfs(&self, _req: Request, path: &OsStr) -> Result<ReplyStatFs> {
log::debug!("statfs(path={:?})", path);
Ok(ReplyStatFs {
blocks: 1,
bfree: 0,
bavail: 0,
files: 1,
ffree: 0,
bsize: 4096,
namelen: u32::MAX,
frsize: 0,
})
}
}

const fn entry_mode2file_type(mode: EntryMode) -> FileType {
Expand Down Expand Up @@ -855,6 +874,10 @@ const fn dummy_file_attr(kind: FileType, now: SystemTime, uid: u32, gid: u32) ->
gid,
rdev: 0,
blksize: 4096,
#[cfg(target_os = "macos")]
crtime: now,
#[cfg(target_os = "macos")]
flags: 0,
}
}

Expand Down

0 comments on commit 43e4d7d

Please sign in to comment.