public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: posix_fallocate: return ENODEV
Date: Tue, 28 Nov 2023 10:02:50 +0000 (GMT)	[thread overview]
Message-ID: <20231128100250.7D84E384CBBB@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fedd7fae77303ee3caf7c87510a03a9157deb06f

commit fedd7fae77303ee3caf7c87510a03a9157deb06f
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sat Nov 25 20:56:52 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Tue Nov 28 10:51:47 2023 +0100

    Cygwin: posix_fallocate: return ENODEV
    
    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.
    
    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.
    
    Fixes: 7636b58590621 ("* autoload.cc (NtSetInformationFile): Define.")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

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 a57ffcb86429..3f0dc5f69847 100644
--- a/winsup/cygwin/fhandler/base.cc
+++ b/winsup/cygwin/fhandler/base.cc
@@ -1797,7 +1797,7 @@ fhandler_base::fadvise (off_t offset, off_t length, int advice)
 int
 fhandler_base::ftruncate (off_t length, bool allow_truncate)
 {
-  return EINVAL;
+  return ENODEV;
 }
 
 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
 
 - 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 e4b3dd2f3c62..c3c17d604af3 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3000,6 +3000,8 @@ posix_fallocate (int fd, off_t offset, off_t len)
 	res = cfd->ftruncate (offset + len, false);
       else
 	res = EBADF;
+      if (res == EISDIR)
+	res = ENODEV;
     }
   syscall_printf ("%R = posix_fallocate(%d, %D, %D)", res, fd, offset, len);
   return res;
@@ -3015,6 +3017,8 @@ ftruncate (int fd, off_t length)
       res = cfd->ftruncate (length, true);
       if (res)
 	{
+	  if (res == ENODEV)
+	    res = EINVAL;
 	  set_errno (res);
 	  res = -1;
 	}

                 reply	other threads:[~2023-11-28 10:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231128100250.7D84E384CBBB@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).