[PATCH 0/1] MR9861: ntdll/unix/file.c: added new xattr for marking directories as readonly
On Windows, directories marked as readonly do not behave as readonly directories on linux. Readonly has no effect on windows but on querying for attributes, windows shows the directory to be readonly. To simulate this behaviour, an xattribute is being used to mark a directory as readonly. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50772 -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861
From: Rayan Halder <rayanhldr@gmail.com> On Windows, directories marked as readonly do not behave as readonly directories on linux. Readonly has no effect on windows but on querying for attributes, windows shows the directory to be readonly. To simulate this behaviour, an xattribute is being used to mark a directory as readonly. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50772 --- dlls/ntdll/unix/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/unix/file.c b/dlls/ntdll/unix/file.c index 42c82531051..61ae66fdcd6 100644 --- a/dlls/ntdll/unix/file.c +++ b/dlls/ntdll/unix/file.c @@ -183,6 +183,7 @@ typedef struct #define XATTR_ATTRIBS_MASK (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM) #define XATTR_REPARSE XATTR_USER_PREFIX "WINEREPARSE" +#define XATTR_WIN_DIR_READONLY XATTR_USER_PREFIX "WINREADONLY" struct file_identity { @@ -1746,7 +1747,10 @@ static NTSTATUS fd_set_file_info( int fd, UINT attr, BOOL force_set_xattr ) if (attr & FILE_ATTRIBUTE_READONLY) { if (S_ISDIR( st.st_mode)) - WARN("FILE_ATTRIBUTE_READONLY ignored for directory.\n"); + { + int status = xattr_fset(fd, XATTR_WIN_DIR_READONLY, "1", 1); + if (status) WARN("Failed to set extended attribute %s. errno: %d (%s)\n", XATTR_WIN_DIR_READONLY, errno, strerror(errno)); + } else st.st_mode &= ~0222; /* clear write permission bits */ } @@ -1754,6 +1758,8 @@ static NTSTATUS fd_set_file_info( int fd, UINT attr, BOOL force_set_xattr ) { /* add write permission only where we already have read permission */ st.st_mode |= (0600 | ((st.st_mode & 044) >> 1)) & (~start_umask); + + if (S_ISDIR(st.st_mode)) xattr_fremove(fd, XATTR_WIN_DIR_READONLY); } if (fchmod( fd, st.st_mode ) == -1) return errno_to_status( errno ); @@ -1777,6 +1783,8 @@ static int get_file_info( const char *path, struct stat *st, ULONG *attr, ULONG char *parent_path; char attr_data[65]; int attr_len, ret; + char ro_buffer[3]; + int ro_buf_len; *attr = 0; ret = lstat( path, st ); @@ -1810,6 +1818,12 @@ static int get_file_info( const char *path, struct stat *st, ULONG *attr, ULONG } *attr |= get_file_attributes( st ); + ro_buf_len = xattr_get(path, XATTR_WIN_DIR_READONLY, &ro_buffer, 3); + if (ro_buf_len != -1) + { + *attr |= FILE_ATTRIBUTE_READONLY; + } + attr_len = xattr_get( path, XATTR_REPARSE, buffer, sizeof(buffer) ); if (attr_len >= 0 && attr_len >= sizeof(ULONG)) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9861
Is there an application that actually cares about this? If not, I don't think it's worth fixing. If we do, why not use the existing DOSATTRIBS attribute? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861#note_126503
I personally do not know of any application requiring this. I went for the fix as I am currently new to the codebase and assumed parity with windows on small things could be a start. I didn't know about DOSATTRIBS, I will look into it. Thank you. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861#note_126511
I personally do not know of any application requiring this. I went for the fix as I am currently new to the codebase and assumed parity with windows on small things could be a start.
Would that it were so, but unfortunately we resist pretty heavily making changes that nothing needs.
I didn't know about DOSATTRIBS, I will look into it. Thank you.
It should be a simple matter of tweaking XATTR_ATTRIBS_MASK to include the new flag. The problem is that doing this isn't exactly free. The reason we don't store all attributes already is because the xattrs take up extra space in the file system, and we only want to store attributes for files where they're actually necessary. If no application cares then we don't want to do anything. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861#note_126512
Okay, thank you for your time. Will look for something else to work on. Should I close the merge request? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861#note_126528
Should I close the merge request?
Yes, this can be closed. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861#note_126572
This merge request was closed by Rayan Halder. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9861
participants (3)
-
Elizabeth Figura (@zfigura) -
Rayan Halder -
Rayan Halder (@rayanh)