Skip to content

Commit 2d529bc

Browse files
committed
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: 2d81f6e ("Cygwin: open: always fix up cached DOS file attributes after NtCreateFile") Reported-by: Bruno Haible <[email protected]> Signed-off-by: Takashi Yano <[email protected]> (cherry picked from commit 37c49de)
1 parent 191bb5f commit 2d529bc

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

winsup/cygwin/fhandler/base.cc

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -720,29 +720,32 @@ fhandler_base::open (int flags, mode_t mode)
720720
goto done;
721721
}
722722

723-
/* Fix up file attributes, they are desperately needed later.
724-
725-
Originally we only did that in the FILE_CREATED case below, but that's
726-
insufficient:
727-
728-
If two threads try to create the same file at the same time, it's
729-
possible that path_conv::check returns the file as non-existant, i. e.,
730-
pc.file_attributes () returns INVALID_FILE_ATTRIBUTES, 0xffffffff.
731-
However, one of the NtCreateFile will beat the other, so only one of
732-
them returns with FILE_CREATED.
733-
734-
The other fhandler_base::open() will instead run into the O_TRUNC
735-
conditional (further below), blindly check for the SPARSE attribute
736-
and remove that bit. The result is that the attributes will be
737-
0xfffffdff, i.e., everything but SPARSE. Most annoying is that
738-
pc.isdir() will return TRUE. Hilarity ensues.
739-
740-
Note that we use a different IO_STATUS_BLOCK, so as not to overwrite
741-
io.Information... */
742-
if (!NT_SUCCESS (NtQueryInformationFile (fh, &io_bi, &fbi, sizeof fbi,
743-
FileBasicInformation)))
744-
fbi.FileAttributes = file_attributes | FILE_ATTRIBUTE_ARCHIVE;
745-
pc.file_attributes (fbi.FileAttributes);
723+
if (get_device () == FH_FS)
724+
{
725+
/* Fix up file attributes, they are desperately needed later.
726+
727+
Originally we only did that in the FILE_CREATED case below, but that's
728+
insufficient:
729+
730+
If two threads try to create the same file at the same time, it's
731+
possible that path_conv::check returns the file as non-existant, i. e.,
732+
pc.file_attributes () returns INVALID_FILE_ATTRIBUTES, 0xffffffff.
733+
However, one of the NtCreateFile will beat the other, so only one of
734+
them returns with FILE_CREATED.
735+
736+
The other fhandler_base::open() will instead run into the O_TRUNC
737+
conditional (further below), blindly check for the SPARSE attribute
738+
and remove that bit. The result is that the attributes will be
739+
0xfffffdff, i.e., everything but SPARSE. Most annoying is that
740+
pc.isdir() will return TRUE. Hilarity ensues.
741+
742+
Note that we use a different IO_STATUS_BLOCK, so as not to overwrite
743+
io.Information... */
744+
if (!NT_SUCCESS (NtQueryInformationFile (fh, &io_bi, &fbi, sizeof fbi,
745+
FileBasicInformation)))
746+
fbi.FileAttributes = file_attributes | FILE_ATTRIBUTE_ARCHIVE;
747+
pc.file_attributes (fbi.FileAttributes);
748+
}
746749

747750
if (io.Information == FILE_CREATED)
748751
{

winsup/cygwin/release/3.6.2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ Fixes:
1010

1111
- Fix the console states after the console is closed.
1212
Addresses: https://cygwin.com/pipermail/cygwin/2025-April/257909.html
13+
14+
- Fix setting DOS attributes on devices.
15+
Addresse: https://cygwin.com/pipermail/cygwin/2025-April/257940.html

0 commit comments

Comments
 (0)