Index: sys/compat/freebsd32/freebsd32_misc.c =================================================================== --- sys/compat/freebsd32/freebsd32_misc.c +++ sys/compat/freebsd32/freebsd32_misc.c @@ -2965,21 +2965,22 @@ freebsd32_posix_fallocate(struct thread *td, struct freebsd32_posix_fallocate_args *uap) { + int error; - td->td_retval[0] = kern_posix_fallocate(td, uap->fd, + error = kern_posix_fallocate(td, uap->fd, PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len)); - return (0); + return (posix_ret_error(td, error)); } int freebsd32_posix_fadvise(struct thread *td, struct freebsd32_posix_fadvise_args *uap) { + int error; - td->td_retval[0] = kern_posix_fadvise(td, uap->fd, - PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len), - uap->advice); - return (0); + error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset), + PAIR32TO64(off_t, uap->len), uap->advice); + return (posix_ret_error(td, error)); } int Index: sys/kern/kern_syscalls.c =================================================================== --- sys/kern/kern_syscalls.c +++ sys/kern/kern_syscalls.c @@ -229,3 +229,15 @@ } return (0); } + +int +posix_ret_error(struct thread *td, int error) +{ + + if (error <= 0) + return (error); + td->td_errno = error; + td->td_pflags |= TDP_NERRNO; + td->td_retval[0] = error; + return (0); +} Index: sys/kern/vfs_syscalls.c =================================================================== --- sys/kern/vfs_syscalls.c +++ sys/kern/vfs_syscalls.c @@ -4533,10 +4533,10 @@ int sys_posix_fallocate(struct thread *td, struct posix_fallocate_args *uap) { + int error; - td->td_retval[0] = kern_posix_fallocate(td, uap->fd, uap->offset, - uap->len); - return (0); + error = kern_posix_fallocate(td, uap->fd, uap->offset, uap->len); + return (posix_ret_error(td, error)); } /* @@ -4668,8 +4668,9 @@ int sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap) { + int error; - td->td_retval[0] = kern_posix_fadvise(td, uap->fd, uap->offset, - uap->len, uap->advice); - return (0); + error = kern_posix_fadvise(td, uap->fd, uap->offset, uap->len, + uap->advice); + return (posix_ret_error(td, error)); } Index: sys/sys/sysent.h =================================================================== --- sys/sys/sysent.h +++ sys/sys/sysent.h @@ -270,6 +270,8 @@ void exec_sysvec_init(void *param); void exec_inittk(void); +int posix_ret_error(struct thread *, int); + #define INIT_SYSENTVEC(name, sv) \ SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY, \ (sysinit_cfunc_t)exec_sysvec_init, sv);