mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
- Copy all data in FindFirstFileA.
- Changed back to the old code in FindFirstFileExW, because too many things are broken or useless. svn path=/trunk/; revision=16882
This commit is contained in:
parent
ade86ba7d7
commit
7006f75f63
1 changed files with 144 additions and 133 deletions
|
@ -250,6 +250,8 @@ FindFirstFileA (
|
||||||
&FileNameU,
|
&FileNameU,
|
||||||
FALSE);
|
FALSE);
|
||||||
}
|
}
|
||||||
|
memcpy(lpFindFileData, &FindFileData, offsetof(WIN32_FIND_DATAA, cFileName));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -347,20 +349,19 @@ FindFirstFileExW (
|
||||||
DWORD dwAdditionalFlags
|
DWORD dwAdditionalFlags
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
PKERNEL32_FIND_FILE_DATA IData;
|
PKERNEL32_FIND_FILE_DATA IData;
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
NTSTATUS Status;
|
UNICODE_STRING NtPathU;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
UNICODE_STRING PatternStr;
|
||||||
UNICODE_STRING DosFilePath;
|
NTSTATUS Status;
|
||||||
UNICODE_STRING NtName;
|
|
||||||
UNICODE_STRING FileNameU;
|
|
||||||
UNICODE_STRING NtFilePath;
|
|
||||||
PWSTR e1, e2;
|
PWSTR e1, e2;
|
||||||
WCHAR CurrentDir[256];
|
WCHAR CurrentDir[256];
|
||||||
PWCHAR SlashlessFileName;
|
PWCHAR SlashlessFileName;
|
||||||
PWSTR SearchPath;
|
PWSTR SearchPath;
|
||||||
PWCHAR SearchPattern;
|
PWCHAR SearchPattern;
|
||||||
ULONG Length;
|
ULONG Length;
|
||||||
|
BOOLEAN bResult;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
.....
|
.....
|
||||||
|
@ -375,16 +376,17 @@ FindFirstFileExW (
|
||||||
lpSearchFilter,
|
lpSearchFilter,
|
||||||
dwAdditionalFlags);
|
dwAdditionalFlags);
|
||||||
|
|
||||||
RtlInitUnicodeString(&FileNameU, lpFileName);
|
|
||||||
|
|
||||||
Length = wcslen(lpFileName);
|
Length = wcslen(lpFileName);
|
||||||
if (L'\\' == lpFileName[Length - 1])
|
if (L'\\' == lpFileName[Length - 1])
|
||||||
{
|
{
|
||||||
SlashlessFileName = RtlAllocateHeap(hProcessHeap, 0, Length * sizeof(WCHAR));
|
SlashlessFileName = RtlAllocateHeap(hProcessHeap,
|
||||||
|
0,
|
||||||
|
Length * sizeof(WCHAR));
|
||||||
if (NULL == SlashlessFileName)
|
if (NULL == SlashlessFileName)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
return (INVALID_HANDLE_VALUE);
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
memcpy(SlashlessFileName, lpFileName, (Length - 1) * sizeof(WCHAR));
|
memcpy(SlashlessFileName, lpFileName, (Length - 1) * sizeof(WCHAR));
|
||||||
SlashlessFileName[Length - 1] = L'\0';
|
SlashlessFileName[Length - 1] = L'\0';
|
||||||
|
@ -402,167 +404,176 @@ FindFirstFileExW (
|
||||||
|
|
||||||
if (NULL == SearchPattern)
|
if (NULL == SearchPattern)
|
||||||
{
|
{
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
SearchPattern = (PWCHAR)lpFileName;
|
SearchPattern = (PWCHAR)lpFileName;
|
||||||
Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath);
|
Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath);
|
||||||
if (0 == Length)
|
if (0 == Length)
|
||||||
{
|
{
|
||||||
if (NULL != SlashlessFileName) {
|
if (NULL != SlashlessFileName)
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
{
|
||||||
}
|
RtlFreeHeap(hProcessHeap,
|
||||||
return (INVALID_HANDLE_VALUE);
|
0,
|
||||||
|
SlashlessFileName);
|
||||||
|
}
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
if (Length > sizeof(CurrentDir) / sizeof(WCHAR))
|
if (Length > sizeof(CurrentDir) / sizeof(WCHAR))
|
||||||
{
|
{
|
||||||
SearchPath = RtlAllocateHeap(hProcessHeap, HEAP_ZERO_MEMORY, Length * sizeof(WCHAR));
|
SearchPath = RtlAllocateHeap(hProcessHeap,
|
||||||
if (NULL == SearchPath)
|
HEAP_ZERO_MEMORY,
|
||||||
{
|
Length * sizeof(WCHAR));
|
||||||
if (NULL != SlashlessFileName) {
|
if (NULL == SearchPath)
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
{
|
||||||
}
|
if (NULL != SlashlessFileName)
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
{
|
||||||
return (INVALID_HANDLE_VALUE);
|
RtlFreeHeap(hProcessHeap,
|
||||||
|
0,
|
||||||
|
SlashlessFileName);
|
||||||
|
}
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
GetCurrentDirectoryW(Length, SearchPath);
|
GetCurrentDirectoryW(Length, SearchPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
SearchPattern++;
|
SearchPattern++;
|
||||||
Length = SearchPattern - lpFileName;
|
Length = SearchPattern - lpFileName;
|
||||||
if (Length + 1 > sizeof(CurrentDir) / sizeof(WCHAR))
|
if (Length + 1 > sizeof(CurrentDir) / sizeof(WCHAR))
|
||||||
{
|
{
|
||||||
SearchPath = RtlAllocateHeap(hProcessHeap, HEAP_ZERO_MEMORY, (Length + 1) * sizeof(WCHAR));
|
SearchPath = RtlAllocateHeap(hProcessHeap,
|
||||||
if (NULL == SearchPath) {
|
HEAP_ZERO_MEMORY,
|
||||||
if (NULL != SlashlessFileName) {
|
(Length + 1) * sizeof(WCHAR));
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
if (NULL == SearchPath)
|
||||||
}
|
{
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
if (NULL != SlashlessFileName)
|
||||||
return (INVALID_HANDLE_VALUE);
|
{
|
||||||
}
|
RtlFreeHeap(hProcessHeap,
|
||||||
}
|
0,
|
||||||
memcpy(SearchPath, lpFileName, Length * sizeof(WCHAR));
|
SlashlessFileName);
|
||||||
SearchPath[Length] = 0;
|
}
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(SearchPath, lpFileName, Length * sizeof(WCHAR));
|
||||||
|
SearchPath[Length] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( FALSE == RtlDosPathNameToNtPathName_U(
|
bResult = RtlDosPathNameToNtPathName_U ((LPWSTR)SearchPath,
|
||||||
(PWSTR)SearchPath,
|
&NtPathU,
|
||||||
&NtName,
|
NULL,
|
||||||
&DosFilePath.Buffer,
|
NULL);
|
||||||
(PCURDIR)&NtFilePath
|
if (SearchPath != CurrentDir)
|
||||||
) )
|
|
||||||
{
|
{
|
||||||
RtlFreeHeap(hProcessHeap, 0, SearchPath);
|
RtlFreeHeap(hProcessHeap,
|
||||||
if (NULL != SlashlessFileName) {
|
0,
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
SearchPath);
|
||||||
}
|
}
|
||||||
SetLastError(ERROR_PATH_NOT_FOUND);
|
if (FALSE == bResult)
|
||||||
return (INVALID_HANDLE_VALUE);
|
{
|
||||||
|
if (NULL != SlashlessFileName)
|
||||||
|
{
|
||||||
|
RtlFreeHeap(hProcessHeap,
|
||||||
|
0,
|
||||||
|
SlashlessFileName);
|
||||||
|
}
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DPRINT("NtPathU \'%S\'\n", NtPathU.Buffer);
|
||||||
if (SearchPath != CurrentDir) {
|
|
||||||
RtlFreeHeap(hProcessHeap, 0, SearchPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("NtName \'%S\'\n", NtName.Buffer);
|
|
||||||
|
|
||||||
IData = RtlAllocateHeap (hProcessHeap,
|
IData = RtlAllocateHeap (hProcessHeap,
|
||||||
HEAP_ZERO_MEMORY,
|
HEAP_ZERO_MEMORY,
|
||||||
sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE);
|
sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE);
|
||||||
if (NULL == IData)
|
if (NULL == IData)
|
||||||
{
|
{
|
||||||
RtlFreeHeap (hProcessHeap, 0, NtName.Buffer);
|
RtlFreeHeap (hProcessHeap,
|
||||||
if (NULL != SlashlessFileName) {
|
0,
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
NtPathU.Buffer);
|
||||||
|
if (NULL != SlashlessFileName)
|
||||||
|
{
|
||||||
|
RtlFreeHeap(hProcessHeap,
|
||||||
|
0,
|
||||||
|
SlashlessFileName);
|
||||||
}
|
}
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
return (INVALID_HANDLE_VALUE);
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* change pattern: "*.*" --> "*" */
|
/* change pattern: "*.*" --> "*" */
|
||||||
if (!wcscmp (SearchPattern, L"*.*")) {
|
if (!wcscmp (SearchPattern, L"*.*"))
|
||||||
RtlInitUnicodeString(&DosFilePath, L"*");
|
|
||||||
} else {
|
|
||||||
RtlInitUnicodeString(&DosFilePath, SearchPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINT("NtName \'%S\' DosFilePath \'%S\'\n",
|
|
||||||
NtName.Buffer, DosFilePath.Buffer);
|
|
||||||
|
|
||||||
InitializeObjectAttributes( &ObjectAttributes,
|
|
||||||
&NtName,
|
|
||||||
dwAdditionalFlags,
|
|
||||||
NtFilePath.Buffer,
|
|
||||||
NULL );
|
|
||||||
|
|
||||||
Status =
|
|
||||||
NtOpenFile(
|
|
||||||
&IData->DirectoryHandle,
|
|
||||||
SYNCHRONIZE | FILE_LIST_DIRECTORY,
|
|
||||||
&ObjectAttributes,
|
|
||||||
&IoStatusBlock,
|
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
||||||
FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT
|
|
||||||
);
|
|
||||||
|
|
||||||
if( !NT_SUCCESS(Status) )
|
|
||||||
{
|
{
|
||||||
DPRINT1("NtOpenFile() - failed (Status %lx)\n", Status);
|
RtlInitUnicodeString(&PatternStr, L"*");
|
||||||
SetLastError( Status );
|
}
|
||||||
return (INVALID_HANDLE_VALUE);
|
else
|
||||||
|
{
|
||||||
|
RtlInitUnicodeString(&PatternStr, SearchPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlFreeHeap(hProcessHeap, 0, NtName.Buffer);
|
DPRINT("NtPathU \'%S\' Pattern \'%S\'\n",
|
||||||
|
NtPathU.Buffer, PatternStr.Buffer);
|
||||||
|
|
||||||
|
InitializeObjectAttributes (&ObjectAttributes,
|
||||||
|
&NtPathU,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
Status = NtOpenFile (&IData->DirectoryHandle,
|
||||||
|
SYNCHRONIZE|FILE_LIST_DIRECTORY,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
|
FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT);
|
||||||
|
|
||||||
|
RtlFreeHeap (hProcessHeap,
|
||||||
|
0,
|
||||||
|
NtPathU.Buffer);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
RtlFreeHeap (hProcessHeap, 0, IData);
|
RtlFreeHeap (hProcessHeap, 0, IData);
|
||||||
if (NULL != SlashlessFileName) {
|
if (NULL != SlashlessFileName)
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
{
|
||||||
}
|
RtlFreeHeap(hProcessHeap,
|
||||||
SetLastErrorByStatus (Status);
|
0,
|
||||||
return (INVALID_HANDLE_VALUE);
|
SlashlessFileName);
|
||||||
|
}
|
||||||
|
SetLastErrorByStatus (Status);
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 0 == DosFilePath.Length ) {
|
|
||||||
DPRINT1("0 == DosFilePath.Length\n");
|
|
||||||
NtClose(IData->DirectoryHandle);
|
|
||||||
SetLastError(ERROR_FILE_NOT_FOUND);
|
|
||||||
return INVALID_HANDLE_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
IData->pFileInfo = (PVOID)((ULONG_PTR)IData + sizeof(KERNEL32_FIND_FILE_DATA));
|
IData->pFileInfo = (PVOID)((ULONG_PTR)IData + sizeof(KERNEL32_FIND_FILE_DATA));
|
||||||
|
|
||||||
IData->pFileInfo->FileIndex = 0;
|
IData->pFileInfo->FileIndex = 0;
|
||||||
|
|
||||||
Status =
|
Status = NtQueryDirectoryFile (IData->DirectoryHandle,
|
||||||
NtQueryDirectoryFile(
|
NULL,
|
||||||
IData->DirectoryHandle,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
&IoStatusBlock,
|
||||||
NULL,
|
(PVOID)IData->pFileInfo,
|
||||||
&IoStatusBlock,
|
FIND_DATA_SIZE,
|
||||||
(PVOID)IData->pFileInfo,
|
FileBothDirectoryInformation,
|
||||||
FIND_DATA_SIZE,
|
TRUE,
|
||||||
FileBothDirectoryInformation,
|
&PatternStr,
|
||||||
TRUE,
|
TRUE);
|
||||||
&DosFilePath,
|
if (NULL != SlashlessFileName)
|
||||||
FALSE
|
{
|
||||||
);
|
RtlFreeHeap(hProcessHeap,
|
||||||
|
0,
|
||||||
if (NULL != SlashlessFileName) {
|
SlashlessFileName);
|
||||||
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
|
|
||||||
}
|
}
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
if( !NT_SUCCESS(Status) ) {
|
{
|
||||||
DPRINT1("NtQueryDirectoryFile() - failed (Status %lx)\n", Status);
|
DPRINT("Status %lx\n", Status);
|
||||||
RtlFreeHeap(hProcessHeap, 0, IData);
|
CloseHandle (IData->DirectoryHandle);
|
||||||
NtClose(IData->DirectoryHandle);
|
RtlFreeHeap (hProcessHeap, 0, IData);
|
||||||
SetLastError(Status);
|
SetLastErrorByStatus (Status);
|
||||||
return (INVALID_HANDLE_VALUE);
|
return INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength/sizeof(WCHAR), IData->pFileInfo->FileName);
|
DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength/sizeof(WCHAR), IData->pFileInfo->FileName);
|
||||||
|
|
||||||
/* copy data into WIN32_FIND_DATA structure */
|
/* copy data into WIN32_FIND_DATA structure */
|
||||||
|
|
Loading…
Reference in a new issue