[PATCH v7 4/4] ntdll: Allow renaming a file/directory to a different casing of itself.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon Apr 26 11:37:14 CDT 2021


On 26/04/2021 17:03, Rémi Bernon wrote:
> On 4/23/21 5:52 PM, Gabriel Ivăncescu wrote:
>> +/***********************************************************************
>> + *           nt_to_unix_file_name_with_casing
>> + *
>> + * Same as nt_to_unix_file_name, but additionally return unix file name
>> + * without path, with the original casing from the NT file name.
>> + */
>> +static NTSTATUS nt_to_unix_file_name_with_casing( const 
>> OBJECT_ATTRIBUTES *attr, char **name_ret,
>> +                                                  char **casing_ret, 
>> UINT disposition )
>> +{
>> +    int len = attr->ObjectName->Length / sizeof(WCHAR);
>> +    const WCHAR *nt_filename;
>> +    NTSTATUS status;
>> +    char *casing;
>> +
>> +    /* NT name may not be NUL terminated; look for last \ character */
>> +    for (nt_filename = attr->ObjectName->Buffer + len; nt_filename != 
>> attr->ObjectName->Buffer; nt_filename--)
>> +        if (nt_filename[-1] == '\\')
>> +            break;
>> +    len = attr->ObjectName->Buffer + len - nt_filename;
>> +
> I was about to sign it off as it looks good to me, but then I wondered 
> what would happen if there's a trailing '\\' in the name buffer. I don't 
> think there's any guarantee the input is sane.
> 
> I quickly checked what the new tests do in such case, and on Windows the 
> ntdll link tests seems to be happily doing something with such trailing 
> backslash (haven't tried the other). I don't know if it treats the path 
> as a folder or something else.
> 
> It also looks like nt_to_unix_file_name is already handling the case 
> somehow, as it strips the trailing backslash from the unix_name (while 
> keeping it in the nt_name buffer). I don't know if that's on purpose or 
> not.
> 
> Maybe it could return the proper casing for the last path component too 
> as it has more knowledge of what is been done?

I can just strip the trailing '\\'. Even if it's a directory, it's still 
necessary, directories have case differences too. What we're interested 
in isn't whether it's a directory or a file, rather the last component.

Personally I'd rather not change nt_to_unix_file_name since it is used 
in many other places and files, it would complicate things in my 
opinion. This new helper is defined in the same file so it makes sense 
to also have knowledge of such things.



More information about the wine-devel mailing list