- Change RtlIsDosDeviceName_U() implementation to a better Wine implementation

- Winesync RtlIsNameLegalDOS8Dot3()
- "ntdll_winetest.exe path" reduced to 3 failures (which happen on XP too), so considering "path" done 100% now.

svn path=/trunk/; revision=29084
This commit is contained in:
Aleksey Bragin 2007-09-17 19:51:32 +00:00
parent 4ee3207955
commit c466246f9e
2 changed files with 118 additions and 150 deletions

View file

@ -238,79 +238,64 @@ RtlIsNameLegalDOS8Dot3(IN PCUNICODE_STRING UnicodeName,
IN OUT POEM_STRING AnsiName OPTIONAL, IN OUT POEM_STRING AnsiName OPTIONAL,
IN OUT PBOOLEAN SpacesFound OPTIONAL) IN OUT PBOOLEAN SpacesFound OPTIONAL)
{ {
PANSI_STRING name = AnsiName; static const char Illegal[] = "*?<>|\"+=,;[]:/\\\345";
ANSI_STRING DummyString; int Dot = -1;
CHAR Buffer[12]; int i;
char *str; char Buffer[12];
ULONG Length; OEM_STRING OemString;
ULONG i; BOOLEAN GotSpace = FALSE;
NTSTATUS Status;
BOOLEAN HasSpace = FALSE;
BOOLEAN HasDot = FALSE;
if (UnicodeName->Length > 24) if (!AnsiName)
{ {
return(FALSE); /* name too long */ OemString.Length = sizeof(Buffer);
OemString.MaximumLength = sizeof(Buffer);
OemString.Buffer = Buffer;
AnsiName = &OemString;
}
if (RtlUpcaseUnicodeStringToCountedOemString( AnsiName, UnicodeName, FALSE ) != STATUS_SUCCESS)
return FALSE;
if (AnsiName->Length > 12) return FALSE;
/* a starting . is invalid, except for . and .. */
if (AnsiName->Buffer[0] == '.')
{
if (AnsiName->Length != 1 && (AnsiName->Length != 2 || AnsiName->Buffer[1] != '.')) return FALSE;
if (SpacesFound) *SpacesFound = FALSE;
return TRUE;
} }
if (!name) for (i = 0; i < AnsiName->Length; i++)
{ {
name = &DummyString; switch (AnsiName->Buffer[i])
name->Length = 0;
name->MaximumLength = 12;
name->Buffer = Buffer;
}
Status = RtlUpcaseUnicodeStringToCountedOemString(name,
UnicodeName,
FALSE);
if (!NT_SUCCESS(Status))
{
return(FALSE);
}
Length = name->Length;
str = name->Buffer;
if (!(Length == 1 && *str == '.') &&
!(Length == 2 && *str == '.' && *(str + 1) == '.'))
{
for (i = 0; i < Length; i++, str++)
{
switch (*str)
{ {
case ' ': case ' ':
HasSpace = TRUE; /* leading/trailing spaces not allowed */
if (!i || i == AnsiName->Length-1 || AnsiName->Buffer[i+1] == '.') return FALSE;
GotSpace = TRUE;
break; break;
case '.': case '.':
if ((HasDot) || /* two or more dots */ if (Dot != -1) return FALSE;
(i == 0) || /* dot is first char */ Dot = i;
(i + 1 == Length) || /* dot is last char */
(Length - i > 4) || /* more than 3 chars of extension */
(HasDot == FALSE && i > 8)) /* name is longer than 8 chars */
return(FALSE);
HasDot = TRUE;
break; break;
default: default:
if (RtlpIsShortIllegal(*str)) if (strchr(Illegal, AnsiName->Buffer[i])) return FALSE;
break;
}
}
/* check file part is shorter than 8, extension shorter than 3
* dot cannot be last in string
*/
if (Dot == -1)
{ {
return(FALSE); if (AnsiName->Length > 8) return FALSE;
} }
} else
}
}
/* Name is longer than 8 chars and does not have an extension */
if (Length > 8 && HasDot == FALSE)
{ {
return(FALSE); if (Dot > 8 || (AnsiName->Length - Dot > 4) || Dot == AnsiName->Length - 1) return FALSE;
} }
if (SpacesFound) *SpacesFound = GotSpace;
if (SpacesFound) return TRUE;
*SpacesFound = HasSpace;
return(TRUE);
} }
/* /*

View file

@ -91,91 +91,68 @@ RtlDetermineDosPathNameType_U(PCWSTR Path)
* @implemented * @implemented
*/ */
ULONG NTAPI ULONG NTAPI
RtlIsDosDeviceName_U(PWSTR DeviceName) RtlIsDosDeviceName_U(PWSTR dos_name)
{ {
ULONG Type; static const WCHAR consoleW[] = {'\\','\\','.','\\','C','O','N',0};
ULONG Length = 0; static const WCHAR auxW[3] = {'A','U','X'};
ULONG Offset; static const WCHAR comW[3] = {'C','O','M'};
PWCHAR wc; static const WCHAR conW[3] = {'C','O','N'};
UNICODE_STRING DeviceNameU; static const WCHAR lptW[3] = {'L','P','T'};
static const WCHAR nulW[3] = {'N','U','L'};
static const WCHAR prnW[3] = {'P','R','N'};
if (DeviceName == NULL) const WCHAR *start, *end, *p;
switch(RtlDetermineDosPathNameType_U( dos_name ))
{ {
case RtlPathTypeUnknown:
case RtlPathTypeUncAbsolute:
return 0; return 0;
} case RtlPathTypeLocalDevice:
if (!_wcsicmp( dos_name, consoleW ))
while (DeviceName[Length]) return MAKELONG( sizeof(conW), 4 * sizeof(WCHAR) ); /* 4 is length of \\.\ prefix */
{
Length++;
}
Type = RtlDetermineDosPathNameType_U(DeviceName);
if (Type <= 1)
{
return 0; return 0;
default:
break;
} }
if (Type == 6) end = dos_name + wcslen(dos_name) - 1;
{ while (end >= dos_name && *end == ':') end--; /* remove all trailing ':' */
DeviceNameU.Length = DeviceNameU.MaximumLength = Length * sizeof(WCHAR);
DeviceNameU.Buffer = DeviceName;
if (Length == 7 &&
RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_condev, TRUE))
return 0x00080006;
return 0;
}
/* name can end with ':' */ /* find start of file name */
if (Length && DeviceName[Length - 1 ] == L':') for (start = end; start >= dos_name; start--)
{ {
Length--; if (IS_PATH_SEPARATOR(start[0])) break;
/* check for ':' but ignore if before extension (for things like NUL:.txt) */
if (start[0] == ':' && start[1] != '.') break;
} }
start++;
/* there can be spaces or points at the end of name */ /* remove extension */
wc = DeviceName + Length - 1; if ((p = wcschr( start, '.' )))
while (Length && (*wc == L'.' || *wc == L' '))
{ {
Length--; end = p - 1;
wc--; if (end >= dos_name && *end == ':') end--; /* remove trailing ':' before extension */
} }
/* remove trailing spaces */
while (end >= dos_name && *end == ' ') end--;
/* let's find a beginning of name */ /* now we have a potential device name between start and end, check it */
wc = DeviceName + Length - 1; switch(end - start + 1)
while (wc > DeviceName && !IS_PATH_SEPARATOR(*(wc - 1)))
{ {
wc--; case 3:
if (_wcsnicmp( start, auxW, 3 ) &&
_wcsnicmp( start, conW, 3 ) &&
_wcsnicmp( start, nulW, 3 ) &&
_wcsnicmp( start, prnW, 3 )) break;
return MAKELONG( 3 * sizeof(WCHAR), (start - dos_name) * sizeof(WCHAR) );
case 4:
if (_wcsnicmp( start, comW, 3 ) && _wcsnicmp( start, lptW, 3 )) break;
if (*end <= '0' || *end > '9') break;
return MAKELONG( 4 * sizeof(WCHAR), (start - dos_name) * sizeof(WCHAR) );
default: /* can't match anything */
break;
} }
Offset = wc - DeviceName;
Length -= Offset;
DeviceNameU.Length = DeviceNameU.MaximumLength = 3 * sizeof(WCHAR);
DeviceNameU.Buffer = wc;
/* check for LPTx or COMx */
if (Length == 4 && wc[3] >= L'0' && wc[3] <= L'9')
{
if (wc[3] == L'0')
{
return 0;
}
if (RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_lpt, TRUE) ||
RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_com, TRUE))
{
return ((Offset * 2) << 16 ) | 8;
}
return 0;
}
/* check for PRN,AUX,NUL or CON */
if (Length == 3 &&
(RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_prn, TRUE) ||
RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_aux, TRUE) ||
RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_nul, TRUE) ||
RtlEqualUnicodeString(&DeviceNameU, (PUNICODE_STRING)&_con, TRUE)))
{
return ((Offset * 2) << 16) | 6;
}
return 0; return 0;
} }
@ -389,7 +366,12 @@ static __inline void collapse_path( WCHAR *path, UINT mark )
} }
/* skip to the next component */ /* skip to the next component */
while (*p && *p != '\\') p++; while (*p && *p != '\\') p++;
if (*p == '\\') p++; if (*p == '\\')
{
/* remove last dot in previous dir name */
if (p > path + mark && p[-1] == '.') memmove( p-1, p, (wcslen(p) + 1) * sizeof(WCHAR) );
else p++;
}
} }
/* remove trailing spaces and dots (yes, Windows really does that, don't ask) */ /* remove trailing spaces and dots (yes, Windows really does that, don't ask) */
@ -439,7 +421,8 @@ static ULONG get_full_path_helper(
RtlAcquirePebLock(); RtlAcquirePebLock();
cd = &((PCURDIR)&NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->CurrentDirectory.DosPath)->DosPath; //cd = &((PCURDIR)&NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->CurrentDirectory.DosPath)->DosPath;
cd = &NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->CurrentDirectory.DosPath;
switch (type = RtlDetermineDosPathNameType_U(name)) switch (type = RtlDetermineDosPathNameType_U(name))
{ {