From owner-freebsd-standards@FreeBSD.ORG Thu Jan 23 21:20:28 2014 Return-Path: Delivered-To: standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 561FEAA9; Thu, 23 Jan 2014 21:20:28 +0000 (UTC) Received: from mx0.gid.co.uk (mx0.gid.co.uk [194.32.164.250]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0C6F61D3A; Thu, 23 Jan 2014 21:20:27 +0000 (UTC) Received: from [194.32.164.24] (80-46-130-69.static.dsl.as9105.com [80.46.130.69]) by mx0.gid.co.uk (8.14.2/8.14.2) with ESMTP id s0NLKHPk011304; Thu, 23 Jan 2014 21:20:17 GMT (envelope-from rb@gid.co.uk) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) Subject: Re: standards/186028: incorrect return values for posix_fallocate() From: Bob Bishop In-Reply-To: <20140123094017.GH24664@kib.kiev.ua> Date: Thu, 23 Jan 2014 21:20:11 +0000 Content-Transfer-Encoding: quoted-printable Message-Id: References: <201401230858.s0N8wwQB039907@oldred.freebsd.org> <20140123094017.GH24664@kib.kiev.ua> To: Konstantin Belousov X-Mailer: Apple Mail (2.1827) Cc: Gennady Proskurin , mdf@freebsd.org, standards@freebsd.org X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jan 2014 21:20:28 -0000 Hi, On 23 Jan 2014, at 09:40, Konstantin Belousov = 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 >> #include >> #include >> #include >>=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