- 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:
Hartmut Birr 2005-07-29 21:59:06 +00:00
parent ade86ba7d7
commit 7006f75f63

View file

@ -250,6 +250,8 @@ FindFirstFileA (
&FileNameU,
FALSE);
}
memcpy(lpFindFileData, &FindFileData, offsetof(WIN32_FIND_DATAA, cFileName));
}
@ -347,20 +349,19 @@ FindFirstFileExW (
DWORD dwAdditionalFlags
)
{
OBJECT_ATTRIBUTES ObjectAttributes;
PKERNEL32_FIND_FILE_DATA IData;
IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING NtPathU;
UNICODE_STRING PatternStr;
NTSTATUS Status;
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING DosFilePath;
UNICODE_STRING NtName;
UNICODE_STRING FileNameU;
UNICODE_STRING NtFilePath;
PWSTR e1, e2;
WCHAR CurrentDir[256];
PWCHAR SlashlessFileName;
PWSTR SearchPath;
PWCHAR SearchPattern;
ULONG Length;
BOOLEAN bResult;
/*
.....
@ -375,16 +376,17 @@ FindFirstFileExW (
lpSearchFilter,
dwAdditionalFlags);
RtlInitUnicodeString(&FileNameU, lpFileName);
Length = wcslen(lpFileName);
if (L'\\' == lpFileName[Length - 1])
{
SlashlessFileName = RtlAllocateHeap(hProcessHeap, 0, Length * sizeof(WCHAR));
SlashlessFileName = RtlAllocateHeap(hProcessHeap,
0,
Length * sizeof(WCHAR));
if (NULL == SlashlessFileName)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return (INVALID_HANDLE_VALUE);
return INVALID_HANDLE_VALUE;
}
memcpy(SlashlessFileName, lpFileName, (Length - 1) * sizeof(WCHAR));
SlashlessFileName[Length - 1] = L'\0';
@ -407,21 +409,29 @@ FindFirstFileExW (
Length = GetCurrentDirectoryW(sizeof(CurrentDir) / sizeof(WCHAR), SearchPath);
if (0 == Length)
{
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
return (INVALID_HANDLE_VALUE);
return INVALID_HANDLE_VALUE;
}
if (Length > sizeof(CurrentDir) / sizeof(WCHAR))
{
SearchPath = RtlAllocateHeap(hProcessHeap, HEAP_ZERO_MEMORY, Length * sizeof(WCHAR));
SearchPath = RtlAllocateHeap(hProcessHeap,
HEAP_ZERO_MEMORY,
Length * sizeof(WCHAR));
if (NULL == SearchPath)
{
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return (INVALID_HANDLE_VALUE);
return INVALID_HANDLE_VALUE;
}
GetCurrentDirectoryW(Length, SearchPath);
}
@ -433,112 +443,113 @@ FindFirstFileExW (
Length = SearchPattern - lpFileName;
if (Length + 1 > sizeof(CurrentDir) / sizeof(WCHAR))
{
SearchPath = RtlAllocateHeap(hProcessHeap, HEAP_ZERO_MEMORY, (Length + 1) * sizeof(WCHAR));
if (NULL == SearchPath) {
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
SearchPath = RtlAllocateHeap(hProcessHeap,
HEAP_ZERO_MEMORY,
(Length + 1) * sizeof(WCHAR));
if (NULL == SearchPath)
{
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return (INVALID_HANDLE_VALUE);
return INVALID_HANDLE_VALUE;
}
}
memcpy(SearchPath, lpFileName, Length * sizeof(WCHAR));
SearchPath[Length] = 0;
}
if( FALSE == RtlDosPathNameToNtPathName_U(
(PWSTR)SearchPath,
&NtName,
&DosFilePath.Buffer,
(PCURDIR)&NtFilePath
) )
bResult = RtlDosPathNameToNtPathName_U ((LPWSTR)SearchPath,
&NtPathU,
NULL,
NULL);
if (SearchPath != CurrentDir)
{
RtlFreeHeap(hProcessHeap, 0, SearchPath);
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
RtlFreeHeap(hProcessHeap,
0,
SearchPath);
}
SetLastError(ERROR_PATH_NOT_FOUND);
return (INVALID_HANDLE_VALUE);
if (FALSE == bResult)
{
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
return INVALID_HANDLE_VALUE;
}
if (SearchPath != CurrentDir) {
RtlFreeHeap(hProcessHeap, 0, SearchPath);
}
DPRINT("NtName \'%S\'\n", NtName.Buffer);
DPRINT("NtPathU \'%S\'\n", NtPathU.Buffer);
IData = RtlAllocateHeap (hProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE);
if (NULL == IData)
{
RtlFreeHeap (hProcessHeap, 0, NtName.Buffer);
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
RtlFreeHeap (hProcessHeap,
0,
NtPathU.Buffer);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return (INVALID_HANDLE_VALUE);
return INVALID_HANDLE_VALUE;
}
/* change pattern: "*.*" --> "*" */
if (!wcscmp (SearchPattern, L"*.*")) {
RtlInitUnicodeString(&DosFilePath, L"*");
} else {
RtlInitUnicodeString(&DosFilePath, SearchPattern);
if (!wcscmp (SearchPattern, L"*.*"))
{
RtlInitUnicodeString(&PatternStr, L"*");
}
else
{
RtlInitUnicodeString(&PatternStr, SearchPattern);
}
DPRINT("NtName \'%S\' DosFilePath \'%S\'\n",
NtName.Buffer, DosFilePath.Buffer);
DPRINT("NtPathU \'%S\' Pattern \'%S\'\n",
NtPathU.Buffer, PatternStr.Buffer);
InitializeObjectAttributes( &ObjectAttributes,
&NtName,
dwAdditionalFlags,
NtFilePath.Buffer,
NULL );
InitializeObjectAttributes (&ObjectAttributes,
&NtPathU,
0,
NULL,
NULL);
Status =
NtOpenFile(
&IData->DirectoryHandle,
SYNCHRONIZE | FILE_LIST_DIRECTORY,
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
);
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT);
if( !NT_SUCCESS(Status) )
{
DPRINT1("NtOpenFile() - failed (Status %lx)\n", Status);
SetLastError( Status );
return (INVALID_HANDLE_VALUE);
}
RtlFreeHeap(hProcessHeap, 0, NtName.Buffer);
RtlFreeHeap (hProcessHeap,
0,
NtPathU.Buffer);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap (hProcessHeap, 0, IData);
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
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->FileIndex = 0;
Status =
NtQueryDirectoryFile(
IData->DirectoryHandle,
Status = NtQueryDirectoryFile (IData->DirectoryHandle,
NULL,
NULL,
NULL,
@ -547,22 +558,22 @@ FindFirstFileExW (
FIND_DATA_SIZE,
FileBothDirectoryInformation,
TRUE,
&DosFilePath,
FALSE
);
if (NULL != SlashlessFileName) {
RtlFreeHeap(hProcessHeap, 0, SlashlessFileName);
&PatternStr,
TRUE);
if (NULL != SlashlessFileName)
{
RtlFreeHeap(hProcessHeap,
0,
SlashlessFileName);
}
if( !NT_SUCCESS(Status) ) {
DPRINT1("NtQueryDirectoryFile() - failed (Status %lx)\n", Status);
RtlFreeHeap(hProcessHeap, 0, IData);
NtClose(IData->DirectoryHandle);
SetLastError(Status);
return (INVALID_HANDLE_VALUE);
if (!NT_SUCCESS(Status))
{
DPRINT("Status %lx\n", Status);
CloseHandle (IData->DirectoryHandle);
RtlFreeHeap (hProcessHeap, 0, IData);
SetLastErrorByStatus (Status);
return INVALID_HANDLE_VALUE;
}
DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength/sizeof(WCHAR), IData->pFileInfo->FileName);
/* copy data into WIN32_FIND_DATA structure */