Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2014 21:20:11 +0000
From:      Bob Bishop <rb@gid.co.uk>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Gennady Proskurin <gpr@mail.ru>, mdf@freebsd.org, standards@freebsd.org
Subject:   Re: standards/186028: incorrect return values for posix_fallocate()
Message-ID:  <F5BBA557-7ACA-4A7A-9245-165CF962922D@gid.co.uk>
In-Reply-To: <20140123094017.GH24664@kib.kiev.ua>
References:  <201401230858.s0N8wwQB039907@oldred.freebsd.org> <20140123094017.GH24664@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

On 23 Jan 2014, at 09:40, Konstantin Belousov <kostikbel@gmail.com> =
wrote:

> On Thu, Jan 23, 2014 at 08:58:58AM +0000, Gennady Proskurin wrote:
>>=20
>>> Number:         186028
>>> Category:       standards
>>> Synopsis:       incorrect return values for posix_fallocate()
>>> Confidential:   no
>>> Severity:       non-critical
>>> Priority:       low
>>> Responsible:    freebsd-standards
>>> State:          open
>>> Quarter:       =20
>>> Keywords:      =20
>>> Date-Required:
>>> Class:          sw-bug
>>> Submitter-Id:   current-users
>>> Arrival-Date:   Thu Jan 23 09:00:00 UTC 2014
>>> Closed-Date:
>>> Last-Modified:
>>> Originator:     Gennady Proskurin
>>> Release:        FreeBSD 11.0-CURRENT
>>> Organization:
>>> Environment:
>> FreeBSD gpr.nnz-home.ru 11.0-CURRENT FreeBSD 11.0-CURRENT #0 =
r260472+743aa78(svn_head): Fri Jan 10 05:28:05 MSK 2014     =
gpr@gpr.nnz-home.ru:/usr/obj/usr/src/freebsd-head/sys/GPR  amd64
>>> Description:
>> In case of error, posix_fallocate() should return error code itself, =
but in FreeBSD it returns -1 and sets errno.

FWIW at least posix_madvise() and posix_fadvise() have the same problem.

>> Quote from standard:
>> =
http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.h=
tml
>> RETURN VALUE
>>    Upon successful completion, posix_fallocate() shall return zero; =
otherwise, an error number shall be returned to indicate the error.
>>=20
>>=20
>> Quote from freebsd man:
>> RETURN VALUES
>>     If successful, posix_fallocate() returns zero.  It returns -1 on =
failure,
>>     and sets errno to indicate the error.
>>=20
>>> How-To-Repeat:
>> test program attached
>>> Fix:
>>=20
>>=20
>> Patch attached with submission follows:
>>=20
>> #include <fcntl.h>
>> #include <errno.h>
>> #include <string.h>
>> #include <stdio.h>
>>=20
>> int main()
>> {
>> 	int ret;
>> 	int err;
>>=20
>> 	errno =3D 0;
>> 	ret =3D posix_fallocate(-1 /* emulate EBADF error */, 0, 1);
>> 	err =3D errno;
>> 	printf("return value : %i   strerror: %s\n", ret, =
strerror(ret));
>> 	printf("errno        : %i   strerror: %s\n", err, =
strerror(err));
>> }
>>=20
>=20
> Indeed.  Linux also seems to have the conforming behaviour, according
> to their man page, which also explicitely states that errno is not =
set.
>=20
> Try this.
>=20
> diff --git a/lib/libc/sys/posix_fallocate.2 =
b/lib/libc/sys/posix_fallocate.2
> index 087c68c..ee6fcc4 100644
> --- a/lib/libc/sys/posix_fallocate.2
> +++ b/lib/libc/sys/posix_fallocate.2
> @@ -83,9 +83,9 @@ that reduces the file size to a size smaller than
> If successful,
> .Fn posix_fallocate
> returns zero.
> -It returns -1 on failure, and sets
> +It returns error on failure, without setting
> .Va errno
> -to indicate the error.
> +variable.
> .Sh ERRORS
> Possible failure conditions:
> .Bl -tag -width Er
> diff --git a/sys/compat/freebsd32/freebsd32_misc.c =
b/sys/compat/freebsd32/freebsd32_misc.c
> index 719a057..e4ffbe4 100644
> --- a/sys/compat/freebsd32/freebsd32_misc.c
> +++ b/sys/compat/freebsd32/freebsd32_misc.c
> @@ -2995,8 +2995,9 @@ freebsd32_posix_fallocate(struct thread *td,
>     struct freebsd32_posix_fallocate_args *uap)
> {
>=20
> -	return (kern_posix_fallocate(td, uap->fd,
> -	    PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, =
uap->len)));
> +	td->td_retval[0] =3D kern_posix_fallocate(td, uap->fd,
> +	    PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, =
uap->len));
> +	return (0);
> }
>=20
> int
> diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
> index dbad1ae..b864c90 100644
> --- a/sys/kern/vfs_syscalls.c
> +++ b/sys/kern/vfs_syscalls.c
> @@ -4584,7 +4584,9 @@ int
> sys_posix_fallocate(struct thread *td, struct posix_fallocate_args =
*uap)
> {
>=20
> -	return (kern_posix_fallocate(td, uap->fd, uap->offset, =
uap->len));
> +	td->td_retval[0] =3D kern_posix_fallocate(td, uap->fd, =
uap->offset,
> +	    uap->len);
> +	return (0);
> }
>=20
> /*


--
Bob Bishop          +44 (0)118 940 1243
rb@gid.co.uk    fax +44 (0)118 940 1295
             mobile +44 (0)783 626 4518








Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F5BBA557-7ACA-4A7A-9245-165CF962922D>