Skip to content

Commit

Permalink
fix: fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Feb 19, 2024
1 parent 1758719 commit c54c446
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/api/filesystem/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
use std::ffi::{CStr, CString};
use std::io::{Error, ErrorKind, Result};

use super::{Context, Entry, FileSystem, GetxattrReply};
#[cfg(target_os = "linux")]
use super::GetxattrReply;
use super::{Context, Entry, FileSystem};
use crate::abi::fuse_abi::stat64;

#[cfg(target_os = "linux")]
pub const OPAQUE_XATTR_LEN: u32 = 16;
pub const OPAQUE_XATTR: &str = "user.fuseoverlayfs.opaque";
#[cfg(target_os = "linux")]
pub const UNPRIVILEGED_OPAQUE_XATTR: &str = "user.overlay.opaque";
#[cfg(target_os = "linux")]
pub const PRIVILEGED_OPAQUE_XATTR: &str = "trusted.overlay.opaque";

/// A filesystem must implement Layer trait, or it cannot be used as an OverlayFS layer.
Expand Down Expand Up @@ -53,9 +57,15 @@ pub trait Layer: FileSystem {
}

// Try to create whiteout char device with 0/0 device number.
#[cfg(target_os = "linux")]
let dev = libc::makedev(0, 0);
#[cfg(target_os = "macos")]
let dev = unsafe { libc::makedev(0, 0) };
let mode = libc::S_IFCHR | 0o777;
self.mknod(ctx, ino.into(), name, mode as u32, dev as u32, 0)
#[cfg(target_os = "macos")]
return self.mknod(ctx, ino.into(), name, mode as u32, dev as u32, 0);
#[cfg(target_os = "linux")]
return self.mknod(ctx, ino.into(), name, mode, dev as u32, 0);
}

/// Delete whiteout file with name <name>.
Expand Down Expand Up @@ -122,10 +132,14 @@ pub trait Layer: FileSystem {
)
}

#[cfg(target_os = "macos")]
fn is_opaque(&self, _ctx: &Context, _inode: Self::Inode) -> Result<bool> {
Ok(false)
}

/// Check if the directory is opaque.
#[cfg(target_os = "linux")]
fn is_opaque(&self, ctx: &Context, inode: Self::Inode) -> Result<bool> {
#[cfg(target_os = "macos")]
return Ok(false);
// Use temp value to avoid moved 'parent'.
let ino: u64 = inode.into();

Expand Down
8 changes: 7 additions & 1 deletion src/overlayfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,10 @@ impl OverlayInode {
Some((mode, umask)) => {
parent_ri.mkdir(ctx, self.name.as_str(), mode, umask)?
}
#[cfg(target_os = "macos")]
None => parent_ri.mkdir(ctx, self.name.as_str(), st.st_mode.into(), 0)?,
#[cfg(target_os = "linux")]
None => parent_ri.mkdir(ctx, self.name.as_str(), st.st_mode, 0)?,
};
// create directory here
child.replace(ri);
Expand Down Expand Up @@ -1752,7 +1755,10 @@ impl OverlayFs {
// create the file in upper layer using information from lower layer
let args = CreateIn {
flags: libc::O_WRONLY as u32,
#[cfg(target_os = "macos")]
mode: st.st_mode.into(),
#[cfg(target_os = "linux")]
mode: st.st_mode,
umask: 0,
fuse_flags: 0,
};
Expand Down Expand Up @@ -2187,7 +2193,7 @@ impl ZeroCopyWriter for File {
let mut buf = vec![0_u8; count];
let slice = unsafe { FileVolatileSlice::from_raw_ptr(buf.as_mut_ptr(), count) };
// Read from f at offset off to slice.
let ret = f.read_vectored_at_volatile(&vec![slice], off)?;
let ret = f.read_vectored_at_volatile(&[slice], off)?;

if ret > 0 {
let slice = unsafe { FileVolatileSlice::from_raw_ptr(buf.as_mut_ptr(), ret) };
Expand Down
4 changes: 4 additions & 0 deletions src/overlayfs/sync_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ impl FileSystem for OverlayFs {
if self.no_opendir.load(Ordering::Relaxed) {
#[cfg(target_os = "macos")]
return Ok((None, OpenOptions::KEEP_CACHE));
#[cfg(target_os = "linux")]
info!("fuse: opendir is not supported.");
#[cfg(target_os = "linux")]
return Err(Error::from_raw_os_error(libc::ENOSYS));
}

Expand Down Expand Up @@ -289,7 +291,9 @@ impl FileSystem for OverlayFs {
if self.no_open.load(Ordering::Relaxed) {
#[cfg(target_os = "macos")]
return Ok((None, OpenOptions::KEEP_CACHE, None));
#[cfg(target_os = "linux")]
info!("fuse: open is not supported.");
#[cfg(target_os = "linux")]
return Err(Error::from_raw_os_error(libc::ENOSYS));
}

Expand Down

0 comments on commit c54c446

Please sign in to comment.