Implement posix_fallocate
`posix_fallocate` ensures that a byte range in a file is allocated so that subsequent writes don't fail. Unlike ftruncate, posix_fallocate does not shrink files. The Linux syscall fallocate is similar to posix_fallocate except with far more control over how byte ranges are allocated (e.g. it supports file holes and other features). This MR doesn't implement fallocate as it requires syscall and redoxfs support. Finally, I changed the flags for flock from usize to c_int. That matches what we have in libc and also avoids some silly, needless type casting.
This commit is contained in:
committed by
Josh Megnauth
parent
27355b953b
commit
8e5937ca25
@@ -1,4 +1,4 @@
|
||||
use core::{arch::asm, ptr};
|
||||
use core::{arch::asm, num::NonZeroU64, ptr};
|
||||
|
||||
use super::{ERRNO, Pal, types::*};
|
||||
use crate::{
|
||||
@@ -560,6 +560,11 @@ impl Pal for Sys {
|
||||
e_raw(unsafe { syscall!(PIPE2, fildes.as_mut_ptr(), flags) }).map(|_| ())
|
||||
}
|
||||
|
||||
fn posix_fallocate(fd: c_int, offset: u64, length: NonZeroU64) -> Result<()> {
|
||||
let length = length.get();
|
||||
e_raw(unsafe { syscall!(FALLOCATE, fd, 0, offset, length) }).map(|_| ())
|
||||
}
|
||||
|
||||
fn posix_getdents(fildes: c_int, buf: &mut [u8]) -> Result<usize> {
|
||||
let current_offset = Self::lseek(fildes, 0, SEEK_CUR)? as u64;
|
||||
let bytes_read = Self::getdents(fildes, buf, current_offset)?;
|
||||
|
||||
Reference in New Issue
Block a user