You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, this is because in fs2, if the contiguous allocation fails, then try non-contiguous allocation. rustix does not provide the same functionality (fcntl_preallocate) as libc
I review the source code of rustix's fallocate, it already tries to allocate non-contiguous when contiguous allocation fails, so it is weird.
The fallocate source code in rustix is the same as what fs2's allocate does.
#[cfg(apple)]pub(crate)fnfallocate(fd:BorrowedFd<'_>,mode:FallocateFlags,offset:u64,len:u64,) -> io::Result<()>{let offset:i64 = offset.try_into().map_err(|_e| io::Errno::INVAL)?;let len = len asi64;assert!(mode.is_empty());let new_len = offset.checked_add(len).ok_or(io::Errno::FBIG)?;letmut store = c::fstore_t{fst_flags: c::F_ALLOCATECONTIG,fst_posmode: c::F_PEOFPOSMODE,fst_offset:0,fst_length: new_len,fst_bytesalloc:0,};unsafe{if c::fcntl(borrowed_fd(fd), c::F_PREALLOCATE,&store) == -1{// Unable to allocate contiguous disk space; attempt to allocate// non-contiguously.
store.fst_flags = c::F_ALLOCATEALL;let _ = ret_c_int(c::fcntl(borrowed_fd(fd), c::F_PREALLOCATE,&store))?;}ret(c::ftruncate(borrowed_fd(fd), new_len))}}
I just replaced some of fs2 usage with fs4 and got following error when calling
file.allocate()
on macOS from multiple users:In one example it happened with ~750GB file and then
file.allocate()
was called with the same file size again, which failed with ^ error.Here is what implementation looks in fs2, it is much more verbose than in fs4:
https://github.com/danburkert/fs2-rs/blob/9a340454a8292df025de368fc4b310bb736f382f/src/unix.rs#L108-L137
I'll be switching to fs2 for that use case for now.
The text was updated successfully, but these errors were encountered: