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

commit 37c49decc835f65af570a45fc6b8b4f9d9b05ba2
Author: Takashi Yano <takashi.y...@nifty.ne.jp>
Date:   Mon Apr 14 20:49:29 2025 +0200

    Cygwin: open: only fix up cached DOS file attributes for on-disk files
    
    Don't try to change the file attributes for devices, e.g. /dev/null,
    this can lead to confusion later.
    
    Addresse: https://cygwin.com/pipermail/cygwin/2025-April/257940.html
    Fixes: 2d81f6ebe3dc ("Cygwin: open: always fix up cached DOS file 
attributes after NtCreateFile")
    Reported-by: Bruno Haible <br...@clisp.org>
    Signed-off-by: Takashi Yano <takashi.y...@nifty.ne.jp>

Diff:
---
 winsup/cygwin/fhandler/base.cc | 49 ++++++++++++++++++++++--------------------
 winsup/cygwin/release/3.6.2    |  3 +++
 2 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc
index 32aca2c51..6c95e2b60 100644
--- a/winsup/cygwin/fhandler/base.cc
+++ b/winsup/cygwin/fhandler/base.cc
@@ -720,29 +720,32 @@ fhandler_base::open (int flags, mode_t mode)
        goto done;
    }
 
-  /* Fix up file attributes, they are desperately needed later.
-
-     Originally we only did that in the FILE_CREATED case below, but that's
-     insufficient:
-
-     If two threads try to create the same file at the same time, it's
-     possible that path_conv::check returns the file as non-existant, i. e.,
-     pc.file_attributes () returns INVALID_FILE_ATTRIBUTES, 0xffffffff.
-     However, one of the NtCreateFile will beat the other, so only one of
-     them returns with FILE_CREATED.
-
-     The other fhandler_base::open() will instead run into the O_TRUNC
-     conditional (further below), blindly check for the SPARSE attribute
-     and remove that bit.  The result is that the attributes will be
-     0xfffffdff, i.e., everything but SPARSE.  Most annoying is that
-     pc.isdir() will return TRUE.  Hilarity ensues.
-
-     Note that we use a different IO_STATUS_BLOCK, so as not to overwrite
-     io.Information... */
-  if (!NT_SUCCESS (NtQueryInformationFile (fh, &io_bi, &fbi, sizeof fbi,
-                                          FileBasicInformation)))
-    fbi.FileAttributes = file_attributes | FILE_ATTRIBUTE_ARCHIVE;
-  pc.file_attributes (fbi.FileAttributes);
+  if (get_device () == FH_FS)
+    {
+      /* Fix up file attributes, they are desperately needed later.
+
+        Originally we only did that in the FILE_CREATED case below, but that's
+        insufficient:
+
+        If two threads try to create the same file at the same time, it's
+        possible that path_conv::check returns the file as non-existant, i. e.,
+        pc.file_attributes () returns INVALID_FILE_ATTRIBUTES, 0xffffffff.
+        However, one of the NtCreateFile will beat the other, so only one of
+        them returns with FILE_CREATED.
+
+        The other fhandler_base::open() will instead run into the O_TRUNC
+        conditional (further below), blindly check for the SPARSE attribute
+        and remove that bit.  The result is that the attributes will be
+        0xfffffdff, i.e., everything but SPARSE.  Most annoying is that
+        pc.isdir() will return TRUE.  Hilarity ensues.
+
+        Note that we use a different IO_STATUS_BLOCK, so as not to overwrite
+        io.Information... */
+      if (!NT_SUCCESS (NtQueryInformationFile (fh, &io_bi, &fbi, sizeof fbi,
+                                              FileBasicInformation)))
+       fbi.FileAttributes = file_attributes | FILE_ATTRIBUTE_ARCHIVE;
+      pc.file_attributes (fbi.FileAttributes);
+    }
 
   if (io.Information == FILE_CREATED)
     {
diff --git a/winsup/cygwin/release/3.6.2 b/winsup/cygwin/release/3.6.2
index f10a947cd..bceabcab3 100644
--- a/winsup/cygwin/release/3.6.2
+++ b/winsup/cygwin/release/3.6.2
@@ -10,3 +10,6 @@ Fixes:
 
 - Fix the console states after the console is closed.
   Addresses: https://cygwin.com/pipermail/cygwin/2025-April/257909.html
+
+- Fix setting DOS attributes on devices.
+  Addresse: https://cygwin.com/pipermail/cygwin/2025-April/257940.html

Reply via email to