I'm not sure that it makes sense to use multiple approaches. Consider ntfs in particular, which IIRC has a dedicated DOS attribute field for all files, but also supports extended attributes. We probably don't want to store extended attributes as that'd be redundant. Same with Apple, whatever file system that is.
Yes - ideally every file would only ever have the single most optimal form of attribute marking. However, it seems to me that it's going to be difficult to ensure this without doing a lot of probing. This will involve a lot more OS-specific code, and I'm not thrilled about the possibility of TOCTOU issues.
It seems more elegant to simply try various methods, and see what works. You are correct to say that on NTFS on Linux, every file will be labbelled by both a user extended attribute, and a system DOS attribute extended attrbite. But aside from being slightly inelegant, is this really a problem?
Well, it'd take up more space, presumably, whereas we get the system DOS attribute for free.
It would mean that the file would retain its attribute if it were moved to another filesystem.
Hmm, that's a fair point, though...
I think chmod is definitely the wrong approach. I don't understand why we'd need to remove the READONLY attribute in order to open a file without any access bits, though?
This is my partially updated version of the patch from staging: https://gitlab.winehq.org/jhol/wine/-/commit/2d980a3c45b12d707b1a21f30e7af47...
Just looking at the logic, the only scenario that could trigger the chmod behaviour is `FILE_WRITE_ATTRIBUTES` on a read-only file.
Does that actually matter in practice? I.e. are there cases where a Windows program sets FILE_WRITE_ATTRIBUTES access but not FILE_WRITE_DATA access?
If it's just FILE_ATTRIBUTE_READONLY that's stripping Unix write access, I would agree that the better thing to do there is just to use the DOS attributes to store it, instead of translating it to Unix ~write access.
I think `O_PATH` should work in this scenario? But we would need a fallback path for the other UNIXs.
Ugh, I'm surprised this isn't a more standardized feature, it's missing from basically everything but Linux and FreeBSD. Maybe we just leave it as unimplemented; it wouldn't be a regression in that case. Or maybe we just implement a fallback based on storing path names and hang the TOCTOU issues.