-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
posix_fallocate fails on ZFS+FreeBSD #25
Comments
@P-E-Meunier by "emulate," do you mean a call that avoids unnecessary truncating? i.e. something like this? #[cfg(target_os = "freebsd")]
pub fn allocate(file: &File, len: u64) -> Result<()> {
let fd = file.as_raw_fd();
let len = len.try_into().unwrap();
let ret = unsafe {
let mut stat: libc::stat = mem::zeroed();
let len_new = if libc::fstat(fd, std::ptr::addr_of_mut!(stat)) == 0 {
stat.st_size.max(len)
} else {
len
};
libc::ftruncate(file.as_raw_fd(), len_new)
};
if ret == 0 { Ok(()) } else { Err(Error::last_os_error()) }
} |
I believe so, but it was quite some time ago, I don't remember exactly what the issue was. It was also reported to me indirectly. |
I have a current version of FreeBSD and ZFS running with this crate. diff --git a/src/unix.rs b/src/unix.rs
index 5c2f4f2..79f7595 100644
--- a/src/unix.rs
+++ b/src/unix.rs
@@ -96,7 +96,6 @@ pub fn allocated_size(file: &File) -> Result<u64> {
}
#[cfg(any(target_os = "linux",
- target_os = "freebsd",
target_os = "android",
target_os = "emscripten",
target_os = "nacl"))]
@@ -138,6 +137,7 @@ pub fn allocate(file: &File, len: u64) -> Result<()> {
#[cfg(any(target_os = "openbsd",
target_os = "netbsd",
+ target_os = "freebsd",
target_os = "dragonfly",
target_os = "solaris",
target_os = "haiku"))] A suitable workaround seems to be to make FreeBSD use the same I tested another approach which would use I am not sure whether @danburkert has any preference to the approach taken here. |
@rtyler I'm not sure if fs2 is maintained any more, the last commit was >5 years ago and several important PR's have been left open for nearly as long. You may consider fs4 as an alternative. It is a fork of fs2 that is now actively maintained, and they accepted my PR to fix the FreeBSD+ZFS issue you are describing. |
@ryanavella fs4 does bubble up the |
I think the reason FreeBSD returns My workaround is to match on |
This error never shows up on Linux because glibc tries to emulate
fallocate
. However, it seems this call could be emulated withtruncate
on FreeBSD.The text was updated successfully, but these errors were encountered: