mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 18:42:56 +00:00
[RTL]
- Use correct checks for illegal chars - Build context and 8.3 name on the basis of it (context can be already presented) * Fixes 34 tests for ntdll:RtlGenerate8dot3Name (remained 16 tests will be fixed after correction of a problem with NLS files) svn path=/trunk/; revision=72668
This commit is contained in:
parent
f693e1e83a
commit
a4cd19ec42
1 changed files with 120 additions and 194 deletions
|
@ -13,81 +13,66 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
extern PUSHORT NlsUnicodeToMbOemTable;
|
||||||
|
|
||||||
/* CONSTANTS *****************************************************************/
|
/* CONSTANTS *****************************************************************/
|
||||||
|
|
||||||
const PCHAR RtlpShortIllegals = ";+=[],\"*\\<>/?:|";
|
const ULONG RtlpShortIllegals[] = { 0xFFFFFFFF, 0xFC009C04, 0x38000000, 0x10000000 };
|
||||||
|
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
NTAPI
|
||||||
|
RtlIsValidOemCharacter(IN PWCHAR Char);
|
||||||
|
|
||||||
static BOOLEAN
|
static BOOLEAN
|
||||||
RtlpIsShortIllegal(CHAR Char)
|
RtlpIsShortIllegal(const WCHAR Char)
|
||||||
{
|
{
|
||||||
return strchr(RtlpShortIllegals, Char) ? TRUE : FALSE;
|
return (Char < 128 && (RtlpShortIllegals[Char / 32] & (1 << (Char % 32))));
|
||||||
}
|
}
|
||||||
|
|
||||||
static USHORT
|
static USHORT
|
||||||
RtlpGetCheckSum(PUNICODE_STRING Name)
|
RtlpGetCheckSum(PUNICODE_STRING Name)
|
||||||
{
|
{
|
||||||
USHORT Hash, Saved;
|
PWCHAR CurrentChar;
|
||||||
WCHAR* CurChar;
|
USHORT Hash;
|
||||||
USHORT Len;
|
USHORT Saved;
|
||||||
|
USHORT Length;
|
||||||
|
|
||||||
if (Name->Length == 0)
|
if (!Name->Length)
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (Name->Length == sizeof(WCHAR))
|
if (Name->Length == sizeof(WCHAR))
|
||||||
{
|
|
||||||
return Name->Buffer[0];
|
return Name->Buffer[0];
|
||||||
}
|
|
||||||
|
|
||||||
CurChar = Name->Buffer;
|
CurrentChar = Name->Buffer;
|
||||||
Hash = (*CurChar << 8) + *(CurChar + 1);
|
Hash = (*CurrentChar << 8) + *(CurrentChar + 1);
|
||||||
|
|
||||||
if (Name->Length == 2 * sizeof(WCHAR))
|
if (Name->Length == 2 * sizeof(WCHAR))
|
||||||
{
|
|
||||||
return Hash;
|
return Hash;
|
||||||
}
|
|
||||||
|
|
||||||
Saved = Hash;
|
Saved = Hash;
|
||||||
Len = 2;
|
Length = 2;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
CurChar = CurChar + 2;
|
CurrentChar += 2;
|
||||||
Hash = (Hash << 7) + *CurChar;
|
Hash = (Hash << 7) + *CurrentChar;
|
||||||
Hash = (Saved >> 1) + (Hash << 8);
|
Hash = (Saved >> 1) + (Hash << 8);
|
||||||
|
|
||||||
if (Len + 1 < Name->Length / sizeof(WCHAR))
|
if (Length + 1 < Name->Length / sizeof(WCHAR))
|
||||||
{
|
{
|
||||||
Hash += *(CurChar + 1);
|
Hash += *(CurrentChar + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Saved = Hash;
|
Saved = Hash;
|
||||||
Len += 2;
|
Length += 2;
|
||||||
} while (Len < Name->Length / sizeof(WCHAR));
|
}
|
||||||
|
while (Length < Name->Length / sizeof(WCHAR));
|
||||||
|
|
||||||
return Hash;
|
return Hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ULONG
|
|
||||||
RtlpGetIndexLength(ULONG Index)
|
|
||||||
{
|
|
||||||
ULONG Length = 0;
|
|
||||||
|
|
||||||
while (Index)
|
|
||||||
{
|
|
||||||
Index /= 10;
|
|
||||||
Length++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Length ? Length : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
|
@ -98,205 +83,146 @@ RtlGenerate8dot3Name(IN PUNICODE_STRING Name,
|
||||||
IN OUT PGENERATE_NAME_CONTEXT Context,
|
IN OUT PGENERATE_NAME_CONTEXT Context,
|
||||||
OUT PUNICODE_STRING Name8dot3)
|
OUT PUNICODE_STRING Name8dot3)
|
||||||
{
|
{
|
||||||
ULONG Count;
|
ULONG Length = Name->Length / sizeof(WCHAR);
|
||||||
WCHAR NameBuffer[8];
|
|
||||||
WCHAR ExtBuffer[4];
|
|
||||||
ULONG StrLength;
|
|
||||||
ULONG NameLength;
|
|
||||||
ULONG ExtLength;
|
|
||||||
ULONG CopyLength;
|
|
||||||
ULONG DotPos;
|
|
||||||
ULONG i, j;
|
|
||||||
ULONG IndexLength;
|
ULONG IndexLength;
|
||||||
ULONG CurrentIndex;
|
ULONG Index;
|
||||||
|
ULONG DotPos;
|
||||||
|
WCHAR IndexBuffer[8];
|
||||||
|
WCHAR Char;
|
||||||
USHORT Checksum;
|
USHORT Checksum;
|
||||||
WCHAR c;
|
|
||||||
|
|
||||||
StrLength = Name->Length / sizeof(WCHAR);
|
if (!Context->NameLength)
|
||||||
|
|
||||||
DPRINT("StrLength: %lu\n", StrLength);
|
|
||||||
|
|
||||||
/* Find last dot in Name */
|
|
||||||
DotPos = StrLength;
|
|
||||||
for (i = 0; i < StrLength; i++)
|
|
||||||
{
|
{
|
||||||
if (Name->Buffer[i] == L'.')
|
DotPos = Length;
|
||||||
{
|
|
||||||
DotPos = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("DotPos: %lu\n", DotPos);
|
/* Find last dot in Name */
|
||||||
|
for (Index = 0; Index < Length; Index++)
|
||||||
/* Copy name (6 valid characters max) */
|
|
||||||
for (i = 0, NameLength = 0; NameLength < 6 && i < DotPos; i++)
|
|
||||||
{
|
|
||||||
c = UNICODE_NULL;
|
|
||||||
if (AllowExtendedCharacters)
|
|
||||||
{
|
{
|
||||||
c = RtlUpcaseUnicodeChar(Name->Buffer[i]);
|
if (Name->Buffer[Index] == L'.')
|
||||||
Count = 1;
|
DotPos = Index;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RtlUpcaseUnicodeToOemN((CHAR *)&c, sizeof(CHAR), &Count, &Name->Buffer[i], sizeof(WCHAR));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Count != 1 || c == UNICODE_NULL || RtlpIsShortIllegal(c))
|
/* Copy name (6 valid characters max) */
|
||||||
|
for (Index = 0; Index < DotPos && Context->NameLength < 6; Index++)
|
||||||
{
|
{
|
||||||
NameBuffer[NameLength++] = L'_';
|
Char = Name->Buffer[Index];
|
||||||
}
|
|
||||||
else if (c != L'.' && c != L' ')
|
if ((Char > L' ') && (Char != L'.') &&
|
||||||
{
|
((Char < 127) || (AllowExtendedCharacters && RtlIsValidOemCharacter(&Char))))
|
||||||
if (isgraph(c) || (AllowExtendedCharacters && iswgraph(c)))
|
|
||||||
{
|
{
|
||||||
NameBuffer[NameLength++] = c;
|
if (RtlpIsShortIllegal(Char))
|
||||||
|
Char = L'_';
|
||||||
|
else if (Char >= L'a' && Char <= L'z')
|
||||||
|
Char = RtlUpcaseUnicodeChar(Char);
|
||||||
|
|
||||||
|
Context->NameBuffer[Context->NameLength] = Char;
|
||||||
|
++Context->NameLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("NameBuffer: '%.08S'\n", NameBuffer);
|
/* Copy extension (4 valid characters max) */
|
||||||
DPRINT("NameLength: %lu\n", NameLength);
|
Context->ExtensionLength = 0;
|
||||||
|
if (DotPos < Length)
|
||||||
/* Copy extension (4 valid characters max) */
|
|
||||||
if (DotPos < StrLength)
|
|
||||||
{
|
|
||||||
for (i = DotPos, ExtLength = 0; ExtLength < 4 && i < StrLength; i++)
|
|
||||||
{
|
{
|
||||||
c = UNICODE_NULL;
|
Context->ExtensionBuffer[0] = L'.';
|
||||||
|
Context->ExtensionLength = 1;
|
||||||
|
|
||||||
if (AllowExtendedCharacters)
|
while (DotPos < Length && Context->ExtensionLength < 4)
|
||||||
{
|
{
|
||||||
c = RtlUpcaseUnicodeChar(Name->Buffer[i]);
|
Char = Name->Buffer[DotPos];
|
||||||
Count = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RtlUpcaseUnicodeToOemN((CHAR *)&c, sizeof(CHAR), &Count, &Name->Buffer[i], sizeof(WCHAR));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Count != 1 || c == UNICODE_NULL || RtlpIsShortIllegal(c))
|
if ((Char > L' ') && (Char != L'.') &&
|
||||||
{
|
((Char < 127) || (AllowExtendedCharacters && RtlIsValidOemCharacter(&Char))))
|
||||||
ExtBuffer[ExtLength++] = L'_';
|
|
||||||
}
|
|
||||||
else if (c != L' ')
|
|
||||||
{
|
|
||||||
if (isgraph(c) || c == L'.' || (AllowExtendedCharacters && iswgraph(c)))
|
|
||||||
{
|
{
|
||||||
ExtBuffer[ExtLength++] = c;
|
if (RtlpIsShortIllegal(Char))
|
||||||
|
Char = L'_';
|
||||||
|
else if (Char >= L'a' && Char <= L'z')
|
||||||
|
Char = RtlUpcaseUnicodeChar(Char);
|
||||||
|
|
||||||
|
Context->ExtensionBuffer[Context->ExtensionLength++] = Char;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Char = UNICODE_NULL;
|
||||||
|
++DotPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Char != UNICODE_NULL)
|
||||||
|
Context->ExtensionBuffer[Context->ExtensionLength - 1] = L'~';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ExtLength = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("ExtBuffer: '%.04S'\n", ExtBuffer);
|
if (Context->NameLength <= 2)
|
||||||
DPRINT("ExtLength: %lu\n", ExtLength);
|
|
||||||
|
|
||||||
/* Determine next index */
|
|
||||||
IndexLength = RtlpGetIndexLength(Context->LastIndexValue);
|
|
||||||
if (Context->CheckSumInserted)
|
|
||||||
{
|
|
||||||
CopyLength = min(NameLength, 8 - 4 - 1 - IndexLength);
|
|
||||||
Checksum = RtlpGetCheckSum(Name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CopyLength = min(NameLength, 8 - 1 - IndexLength);
|
|
||||||
Checksum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("CopyLength: %lu\n", CopyLength);
|
|
||||||
|
|
||||||
if ((Context->NameLength == CopyLength) &&
|
|
||||||
(wcsncmp(Context->NameBuffer, NameBuffer, CopyLength) == 0) &&
|
|
||||||
(Context->ExtensionLength == ExtLength) &&
|
|
||||||
(wcsncmp(Context->ExtensionBuffer, ExtBuffer, ExtLength) == 0) &&
|
|
||||||
(Checksum == Context->Checksum) &&
|
|
||||||
(Context->LastIndexValue < 999))
|
|
||||||
{
|
|
||||||
Context->LastIndexValue++;
|
|
||||||
|
|
||||||
if (Context->CheckSumInserted == FALSE &&
|
|
||||||
Context->LastIndexValue > 9)
|
|
||||||
{
|
{
|
||||||
|
Checksum = Context->Checksum = RtlpGetCheckSum(Name);
|
||||||
|
|
||||||
|
for (Index = 0; Index < 4; Index++)
|
||||||
|
{
|
||||||
|
Context->NameBuffer[Context->NameLength + Index] =
|
||||||
|
(Checksum & 0xF) > 9 ? (Checksum & 0xF) + L'A' - 10 : (Checksum & 0xF) + L'0';
|
||||||
|
Checksum >>= 4;
|
||||||
|
}
|
||||||
|
|
||||||
Context->CheckSumInserted = TRUE;
|
Context->CheckSumInserted = TRUE;
|
||||||
Context->LastIndexValue = 1;
|
Context->NameLength += 4;
|
||||||
Context->Checksum = RtlpGetCheckSum(Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Context->LastIndexValue = 1;
|
|
||||||
|
|
||||||
if (NameLength == 0)
|
|
||||||
{
|
|
||||||
Context->CheckSumInserted = TRUE;
|
|
||||||
Context->Checksum = RtlpGetCheckSum(Name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Context->CheckSumInserted = FALSE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexLength = RtlpGetIndexLength(Context->LastIndexValue);
|
++Context->LastIndexValue;
|
||||||
|
|
||||||
DPRINT("CurrentIndex: %lu, IndexLength %lu\n", Context->LastIndexValue, IndexLength);
|
if (Context->LastIndexValue > 4 && !Context->CheckSumInserted)
|
||||||
|
|
||||||
if (Context->CheckSumInserted)
|
|
||||||
{
|
{
|
||||||
CopyLength = min(NameLength, 8 - 4 - 1 - IndexLength);
|
Checksum = Context->Checksum = RtlpGetCheckSum(Name);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CopyLength = min(NameLength, 8 - 1 - IndexLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Build the short name */
|
for (Index = 2; Index < 6; Index++)
|
||||||
memcpy(Name8dot3->Buffer, NameBuffer, CopyLength * sizeof(WCHAR));
|
|
||||||
|
|
||||||
j = CopyLength;
|
|
||||||
|
|
||||||
if (Context->CheckSumInserted)
|
|
||||||
{
|
|
||||||
Checksum = Context->Checksum;
|
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
{
|
{
|
||||||
Name8dot3->Buffer[j++] = (Checksum & 0xF) > 9 ? (Checksum & 0xF) + L'A' - 10 : (Checksum & 0xF) + L'0';
|
Context->NameBuffer[Index] =
|
||||||
|
(Checksum & 0xF) > 9 ? (Checksum & 0xF) + L'A' - 10 : (Checksum & 0xF) + L'0';
|
||||||
Checksum >>= 4;
|
Checksum >>= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
j = CopyLength + 4;
|
Context->CheckSumInserted = TRUE;
|
||||||
|
Context->NameLength = 6;
|
||||||
|
Context->LastIndexValue = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Name8dot3->Buffer[j++] = L'~';
|
/* Calculate index length and index buffer */
|
||||||
j += IndexLength - 1;
|
Index = Context->LastIndexValue;
|
||||||
CurrentIndex = Context->LastIndexValue;
|
for (IndexLength = 1; IndexLength <= 7 && Index > 0; IndexLength++)
|
||||||
|
|
||||||
for (i = 0; i < IndexLength; i++)
|
|
||||||
{
|
{
|
||||||
Name8dot3->Buffer[j--] = (CurrentIndex % 10) + L'0';
|
IndexBuffer[8 - IndexLength] = L'0' + (Index % 10);
|
||||||
CurrentIndex /= 10;
|
Index /= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
j += IndexLength + 1;
|
IndexBuffer[8 - IndexLength] = L'~';
|
||||||
|
|
||||||
memcpy(Name8dot3->Buffer + j, ExtBuffer, ExtLength * sizeof(WCHAR));
|
/* Reset name length */
|
||||||
Name8dot3->Length = (USHORT)(j + ExtLength) * sizeof(WCHAR);
|
Name8dot3->Length = 0;
|
||||||
|
|
||||||
DPRINT("Name8dot3: '%wZ'\n", Name8dot3);
|
/* If name present */
|
||||||
|
if (Context->NameLength)
|
||||||
|
{
|
||||||
|
/* Copy name buffer */
|
||||||
|
Length = Context->NameLength * sizeof(WCHAR);
|
||||||
|
RtlCopyMemory(Name8dot3->Buffer, Context->NameBuffer, Length);
|
||||||
|
Name8dot3->Length = Length;
|
||||||
|
}
|
||||||
|
|
||||||
/* Update context */
|
/* Copy index buffer */
|
||||||
Context->NameLength = (UCHAR)CopyLength;
|
Length = IndexLength * sizeof(WCHAR);
|
||||||
Context->ExtensionLength = ExtLength;
|
RtlCopyMemory(Name8dot3->Buffer + (Name8dot3->Length / sizeof(WCHAR)),
|
||||||
|
IndexBuffer + (8 - IndexLength),
|
||||||
|
Length);
|
||||||
|
Name8dot3->Length += Length;
|
||||||
|
|
||||||
memcpy(Context->NameBuffer, NameBuffer, CopyLength * sizeof(WCHAR));
|
/* If extension present */
|
||||||
memcpy(Context->ExtensionBuffer, ExtBuffer, ExtLength * sizeof(WCHAR));
|
if (Context->ExtensionLength)
|
||||||
|
{
|
||||||
|
/* Copy extension buffer */
|
||||||
|
Length = Context->ExtensionLength * sizeof(WCHAR);
|
||||||
|
RtlCopyMemory(Name8dot3->Buffer + (Name8dot3->Length / sizeof(WCHAR)),
|
||||||
|
Context->ExtensionBuffer,
|
||||||
|
Length);
|
||||||
|
Name8dot3->Length += Length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue