From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 6B20C385800B; Tue, 28 Nov 2023 10:02:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B20C385800B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1701165760; bh=i8bX4JPys5L6tWgl8rPmngNRTe1mOyR3TRe3EQZOqys=; h=From:To:Subject:Date:From; b=DX+mhImoCTUE+om1xM3A3IQ7qJo/5MhVFbUnVGqyja2edv8MDoS/Pb0yuHHV4Cbvp RIdVOmwVy9OkFM4zXRvK4ZhG74pFAvAFtniAHt4hMo2IpREZe90suCJ35kYcttjJJA 21rFiVoC2hSk0mIFzJW7O/PSAud1xupZDdztmBto= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: posix_fallocate: return ENODEV X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: 4a7cc5af01e438b33f6544d99548fe5f4d2cb776 X-Git-Newrev: 8e009dce7c82538119766cc0e3a6c91f3248ea5a Message-Id: <20231128100240.6B20C385800B@sourceware.org> Date: Tue, 28 Nov 2023 10:02:40 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D8e009dce7c8= 2538119766cc0e3a6c91f3248ea5a commit 8e009dce7c82538119766cc0e3a6c91f3248ea5a Author: Corinna Vinschen AuthorDate: Sat Nov 25 20:56:52 2023 +0100 Commit: Corinna Vinschen CommitDate: Tue Nov 28 10:55:52 2023 +0100 Cygwin: posix_fallocate: return ENODEV =20 The fhandler method ftruncate returns either EISDIR if it has been called on directories, or EINVAL if called on files other than regular files. This matches what ftruncate(2) is supposed to return, but it doesn't match posix_fallocate(3), which is supposed to return ENODEV in both cases. =20 To accomplish that, return ENODEV from fhandler_base::ftruncate() and convert it to EINVAL in ftruncate(2). In posix_fallocate(3), convert EISDIR to ENODEV. =20 Fixes: 7636b58590621 ("* autoload.cc (NtSetInformationFile): Define.") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/fhandler/base.cc | 2 +- winsup/cygwin/release/3.4.10 | 3 +++ winsup/cygwin/syscalls.cc | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc index 9b49ec7b9ede..58b63da8de88 100644 --- a/winsup/cygwin/fhandler/base.cc +++ b/winsup/cygwin/fhandler/base.cc @@ -1705,7 +1705,7 @@ fhandler_base::fadvise (off_t offset, off_t length, i= nt advice) int fhandler_base::ftruncate (off_t length, bool allow_truncate) { - return EINVAL; + return ENODEV; } =20 int diff --git a/winsup/cygwin/release/3.4.10 b/winsup/cygwin/release/3.4.10 index 758a6e071c59..02f6885837b4 100644 --- a/winsup/cygwin/release/3.4.10 +++ b/winsup/cygwin/release/3.4.10 @@ -18,3 +18,6 @@ Bug Fixes =20 - Align behaviour of rand(3) to ISO C. Adresses: https://cygwin.com/pipermail/cygwin/2023-November/254735.html + +- Fix posix_fallocate(3) return value in case of being called on + other than regular files. diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index ba0cd05b270a..bc323235a791 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2998,6 +2998,8 @@ posix_fallocate (int fd, off_t offset, off_t len) res =3D cfd->ftruncate (offset + len, false); else res =3D EBADF; + if (res =3D=3D EISDIR) + res =3D ENODEV; } syscall_printf ("%R =3D posix_fallocate(%d, %D, %D)", res, fd, offset, l= en); return res; @@ -3013,6 +3015,8 @@ ftruncate (int fd, off_t length) res =3D cfd->ftruncate (length, true); if (res) { + if (res =3D=3D ENODEV) + res =3D EINVAL; set_errno (res); res =3D -1; }