Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
freebsd_instance:
image_family: freebsd-14-3

task:
name: FreeBSD
setup_script:
- pkg install -y pkgconf fusefs-libs fusefs-libs3 rust
build_script:
- cargo build --features "parallel libfuse"
test_script:
- cargo test --features "parallel libfuse"
33 changes: 33 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI MacOS

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main, devel, macos_workflow ]

jobs:
build:
name: "Main tests"
runs-on: macos-latest
strategy:
matrix:
toolchain:
- stable
feature:
- serial
- parallel

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: brew install macfuse
- name: Set PKG_CONFIG_PATH
run: echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV
- name: Setup Rust
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- name: Build
run: cargo build --verbose --features "${{ matrix.feature }} libfuse"
- name: Run tests
run: cargo test --verbose --features "${{ matrix.feature }} libfuse"
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ serial = []
parallel = ["dep:threadpool"]
async = ["dep:async-trait", "dep:tokio"]
deadlock_detection = ["parallel", "dep:parking_lot"]

libfuse = ["fuser/libfuse"]

[dependencies]
# Core dependencies
fuser = { version = "0.16.0" }
log = "0.4"
libc = "0.2"
fuser = "0.16"
bitflags = "2.10"

# Parallel dependencies
Expand Down
70 changes: 56 additions & 14 deletions src/unix_fs/bsd_fs.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,68 @@
pub use super::bsd_like_fs::*;
use std::os::fd::*;
use std::path::Path;
use std::ffi::{CStr, CString};
use crate::PosixError;

use std::ffi::c_void;

use libc::{self, c_char, c_int, size_t, ssize_t};
use libc::{self, c_char, c_int, size_t, ssize_t, off_t, c_void};

use super::{StatFs, cstring_from_path};

pub(super) unsafe fn fallocate(fd: c_int, _mode: c_int, offset: off_t, len: off_t) -> c_int {
libc::posix_fallocate(fd, offset, len)
unsafe { libc::posix_fallocate(fd, offset, len) }
}

/// Warning: untested function
pub(super) unsafe fn setxattr(
path: *const c_char,
name: *const c_char,
value: *const c_void,
_size: size_t,
_flags: c_int,
size: libc::size_t,
position: u32,
_flags: c_int, // ignored on FreeBSD
) -> c_int {
libc::extattr_set_file(path, libc::EXTATTR_NAMESPACE_USER, name, value, size)
.try_into()
.unwrap()
unsafe {
if position != 0 {
return -libc::EOPNOTSUPP;
}

// Convert C strings → Rust &str (safe failure → EINVAL)
let name_str = match CStr::from_ptr(name).to_str() {
Ok(s) => s,
Err(_) => return -libc::EINVAL,
};

// Map common prefixed names → FreeBSD namespace
let (ns, attr_name): (c_int, &str) = if name_str.starts_with("user.") {
(libc::EXTATTR_NAMESPACE_USER, &name_str[5..])
} else if name_str.starts_with("system.") {
(libc::EXTATTR_NAMESPACE_SYSTEM, &name_str[7..])
} else if name_str.starts_with("trusted.") {
(libc::EXTATTR_NAMESPACE_SYSTEM, &name_str[8..])
} else if name_str.starts_with("security.") {
(libc::EXTATTR_NAMESPACE_SYSTEM, &name_str[9..])
} else {
(libc::EXTATTR_NAMESPACE_USER, name_str)
};

let attr_name_c: CString = match CString::new(attr_name) {
Ok(c) => c,
Err(_) => return -libc::EINVAL,
};

let ret = libc::extattr_set_file(
path,
ns,
attr_name_c.as_ptr(),
value as *mut c_void, // FreeBSD wants mutable pointer
size,
);

if ret >= 0 {
0
} else {
-(*libc::__error()) // correct FreeBSD way to read errno
}
}
}

pub(super) unsafe fn getxattr(
Expand All @@ -29,20 +71,20 @@ pub(super) unsafe fn getxattr(
value: *mut c_void,
size: size_t,
) -> ssize_t {
libc::extattr_get_file(path, libc::EXTATTR_NAMESPACE_USER, name, value, size)
unsafe { libc::extattr_get_file(path, libc::EXTATTR_NAMESPACE_USER, name, value, size) }
}

pub(super) unsafe fn listxattr(path: *const c_char, list: *mut c_char, size: size_t) -> ssize_t {
libc::extattr_list_file(
unsafe { libc::extattr_list_file(
path,
libc::EXTATTR_NAMESPACE_USER,
list as *mut c_void,
size,
)
) }
}

pub(super) unsafe fn removexattr(path: *const c_char, name: *const c_char) -> c_int {
libc::extattr_delete_file(path, libc::EXTATTR_NAMESPACE_USER, name)
unsafe { libc::extattr_delete_file(path, libc::EXTATTR_NAMESPACE_USER, name) }
}

/// Retrieves file system statistics for the specified path.
Expand Down
4 changes: 2 additions & 2 deletions src/unix_fs/bsd_like_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub(super) unsafe fn renameat2(
newpath: *const c_char,
_flags: c_uint,
) -> c_int {
libc::renameat(olddirfd, oldpath, newdirfd, newpath)
unsafe { libc::renameat(olddirfd, oldpath, newdirfd, newpath) }
}

pub(super) unsafe fn fdatasync(fd: c_int) -> c_int {
libc::fsync(fd)
unsafe { libc::fsync(fd) }
}

/// Copies a range of data from one file to another.
Expand Down
22 changes: 17 additions & 5 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::os::unix::fs::PermissionsExt;
use std::time::Duration;
use tempfile::TempDir;

#[cfg(not(target_os = "macos"))]
#[test]
fn test_mirror_fs_operations() {
// Create temporary directories for mount point and source
Expand Down Expand Up @@ -97,9 +98,20 @@ fn test_mirror_fs_operations() {
}

eprintln!("Unmounting filesystem...");
let _ = std::process::Command::new("fusermount")
.arg("-u")
.arg(&mntpoint)
.status();
handle.join().unwrap();
#[cfg(not(target_os = "freebsd"))]
{
let _ = std::process::Command::new("fusermount")
.arg("-u")
.arg(&mntpoint)
.status();
handle.join().unwrap();
}
#[cfg(target_os = "freebsd")] // TODO: explore why error: no such file or directory happens there
{
let _ = std::process::Command::new("umount")
.arg(&mntpoint)
.status();
let _ = handle.join();
}
drop(mntpoint);
}
2 changes: 2 additions & 0 deletions tests/mount_mirror_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ fn mount_fs<FS: MirrorFsTrait>() {
println!("Exiting debug mount.");
}

#[cfg(not(target_os = "macos"))]
#[test]
#[ignore]
fn mount_mirror_fs() {
mount_fs::<MirrorFs>();
}

#[cfg(not(target_os = "macos"))]
#[test]
#[ignore]
fn mount_mirror_fs_read_only() {
Expand Down
22 changes: 17 additions & 5 deletions tests/offset_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::time::Duration;

use tempfile::TempDir;

#[cfg(not(target_os = "macos"))]
#[test]
fn test_mirror_fs_file_offsets() {
// Create temporary directories for mount point and source
Expand Down Expand Up @@ -95,9 +96,20 @@ fn test_mirror_fs_file_offsets() {
}

eprintln!("Unmounting filesystem...");
let _ = std::process::Command::new("fusermount")
.arg("-u")
.arg(&mntpoint)
.status();
handle.join().unwrap();
#[cfg(not(target_os = "freebsd"))]
{
let _ = std::process::Command::new("fusermount")
.arg("-u")
.arg(&mntpoint)
.status();
handle.join().unwrap();
}
#[cfg(target_os = "freebsd")] // TODO: explore why error: no such file or directory happens there
{
let _ = std::process::Command::new("umount")
.arg(&mntpoint)
.status();
let _ = handle.join();
}
drop(mntpoint);
}
23 changes: 18 additions & 5 deletions tests/test_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::time::{Duration, Instant};
///
/// However, when trying this kind of mount in a terminal, it hangs

#[cfg(not(target_os = "macos"))]
#[test]
fn test_mirror_fs_recursion() {
// Create source and mount directories
Expand Down Expand Up @@ -75,9 +76,21 @@ fn test_mirror_fs_recursion() {
println!("Test passed: No infinite recursion detected.");

eprintln!("Unmounting filesystem...");
let _ = std::process::Command::new("fusermount")
.arg("-u")
.arg(&mntpoint)
.status();
handle.join().unwrap();
#[cfg(not(target_os = "freebsd"))]
{
let _ = std::process::Command::new("fusermount")
.arg("-u")
.arg(&mntpoint)
.status();
handle.join().unwrap();
}
#[cfg(target_os = "freebsd")] // TODO: explore why error: no such file or directory happens there
{
let _ = std::process::Command::new("umount")
.arg(&mntpoint)
.status();
let _ = handle.join();
}
drop(mntpoint);

}