From 2dd8613adcac695468937156f6e13dc5a4828e4c Mon Sep 17 00:00:00 2001 From: Joran Dirk Greef Date: Sun, 1 Nov 2020 11:49:08 +0200 Subject: [PATCH] "The Traveling Wilburys' - Handle With Care" Both `offset` and `len` are `off_t`. Like the rest of the std lib we assume that `_FILE_OFFSET_BITS == 64` is always true, so that `off_t` is a `u64`. When passing to 32-bit kernels, we split these into two `u32` parameters. --- lib/std/os/linux.zig | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 0af646780..82b146f04 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -121,14 +121,26 @@ pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, fl return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); } -pub fn fallocate(fd: i32, mode: i32, offset: usize, len: usize) usize { - return syscall4( - .fallocate, - @bitCast(usize, @as(isize, fd)), - @bitCast(usize, @as(isize, mode)), - offset, - len, - ); +pub fn fallocate(fd: i32, mode: i32, offset: u64, len: u64) usize { + if (@sizeOf(usize) == 4) { + return syscall6( + .fallocate, + @bitCast(usize, @as(isize, fd)), + @bitCast(usize, @as(isize, mode)), + @truncate(usize, offset >> 32), + @truncate(usize, offset), + @truncate(usize, len >> 32), + @truncate(usize, len), + ); + } else { + return syscall4( + .fallocate, + @bitCast(usize, @as(isize, fd)), + @bitCast(usize, @as(isize, mode)), + offset, + len, + ); + } } pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {