https://bugs.winehq.org/show_bug.cgi?id=50771
--- Comment #1 from Joel Holdsworth joel@airwebreathe.org.uk --- Created attachment 72998 --> https://bugs.winehq.org/attachment.cgi?id=72998 Test case for FILE_WRITE_ATTRIBUTES on a read-only file
I stumbled into the same issue with Msys2's implementation of the unlink() syscall when applied to read-only files. I suspect this also affect Cygwin.
It's the same issue, except that they call into the underlying NtCreateFile API.
Here is a test case for the Wine test suite that shows the issue.
The issue seems to be related to the open_fd function in server/fd.c . If the access flags are in the set defined by FILE_UNIX_WRITE_ACCESS (FILE_WRITE_DATA, FILE_APPEND_DATA, FILE_WRITE_ATTRIBUTES, FILE_WRITE_EA), then the function attempts to open the file with O_RDWR or O_WRONLY - which is going to fail on a read-only file.
So we need to open the file to get an fd, which later gets passed into fchmod if the application decides to modify the file permissions.
Is it possible to open() a file with neither read or write access?