Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jan 2014 11:40:17 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Gennady Proskurin <gpr@mail.ru>
Cc:        mdf@freebsd.org, standards@FreeBSD.org
Subject:   Re: standards/186028: incorrect return values for posix_fallocate()
Message-ID:  <20140123094017.GH24664@kib.kiev.ua>
In-Reply-To: <201401230858.s0N8wwQB039907@oldred.freebsd.org>
References:  <201401230858.s0N8wwQB039907@oldred.freebsd.org>

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

--wayzTnRSUXKNfBqd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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+743a=
a78(svn_head): Fri Jan 10 05:28:05 MSK 2014     gpr@gpr.nnz-home.ru:/usr/ob=
j/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.
>=20
> Quote from standard:
> http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.=
html
> RETURN VALUE
>     Upon successful completion, posix_fallocate() shall return zero; othe=
rwise, 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 fai=
lure,
>      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

Indeed.  Linux also seems to have the conforming behaviour, according
to their man page, which also explicitely states that errno is not set.

Try this.

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/f=
reebsd32_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
 /*

--wayzTnRSUXKNfBqd
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (FreeBSD)

iQIcBAEBAgAGBQJS4OOAAAoJEJDCuSvBvK1BlUMP/1Uf92S2nvI0nhGf7AzT230Z
ZcfI7jZ0XoKP3hCySgYBJOarhfNpYjNtBX4k8IAb50XRw/+r3RHhLDGXXvPFwt3H
L1EMLQhipDpSErXUHp0ndsURCRH3DayaAPY7i7nwf0GqGCFgmbY6U1pMfzpgTfDc
MrQNFVH3lwXM0hDHihzZqFxFYoB1XULbUB+GGS3b2waYBvRfuzYUswYSr18JNrrj
VPTv5br7rwjUxqO+Jqr4vn39B22UsHRVp9Z4y2c03/I1+RlXoN7NcpgS1yKLwtr0
StQ3yn46IcvkWsaqSXm8amZ7c+dWQB5y/DZt24gWqPtfDylO+o3XEbr+RYFpTGyo
sawuL2xaVwPLMYiIB24DJo8ajs6ePmQyHYr/2R0Gsac+D7774k61Z5IAuefBXw8I
qGqMID+rsFiIbC6Amdbu1UV94MSj2vshQtNcnO2IsJk/XpYMR8QpLdXreDFPVN1B
pkmuBhS4yUEPhOmsx33kvzOVOZ1Tkx9V3VLyR+LWd5kD/c3eWiVClV760/Vxyi9k
tjEZjytKdobKo7scGwkpusqWaAloo57J1+rD61Wqgjb1ggeCtR1/igXzkVkAVKoS
1LKNRr90pRfxariyHqMrJp8Fvx6lKmlMe++ExAgYumWzV6tpVAZ+pCyeSwGNZPne
lEYSHiB9lLSn8569fKpb
=5ox1
-----END PGP SIGNATURE-----

--wayzTnRSUXKNfBqd--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140123094017.GH24664>