Increased the search buffer for InternalFindFirstFile/InternalFindNextFile.

Changed from single entry to multiple entries in InternalFindNextFile.

svn path=/trunk/; revision=3497
This commit is contained in:
Hartmut Birr 2002-09-13 19:03:40 +00:00
parent 5d53de65e2
commit 8b3648cad0

View file

@ -1,4 +1,4 @@
/* $Id: find.c,v 1.32 2002/09/08 10:22:42 chorns Exp $ /* $Id: find.c,v 1.33 2002/09/13 19:03:40 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -22,12 +22,16 @@
/* TYPES ********************************************************************/ /* TYPES ********************************************************************/
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &( ((TYPE *) 0)->MEMBER ))
#endif
#define FIND_DATA_SIZE (16*1024)
typedef struct _KERNEL32_FIND_FILE_DATA typedef struct _KERNEL32_FIND_FILE_DATA
{ {
HANDLE DirectoryHandle; HANDLE DirectoryHandle;
FILE_BOTH_DIRECTORY_INFORMATION FileInfo; PFILE_BOTH_DIRECTORY_INFORMATION pFileInfo;
WCHAR FileNameExtra[MAX_PATH];
UNICODE_STRING PatternStr;
} KERNEL32_FIND_FILE_DATA, *PKERNEL32_FIND_FILE_DATA; } KERNEL32_FIND_FILE_DATA, *PKERNEL32_FIND_FILE_DATA;
@ -46,25 +50,31 @@ InternalFindNextFile (
IData = (PKERNEL32_FIND_FILE_DATA)hFindFile; IData = (PKERNEL32_FIND_FILE_DATA)hFindFile;
if (IData->pFileInfo->NextEntryOffset != 0)
{
IData->pFileInfo = (PVOID)IData->pFileInfo + IData->pFileInfo->NextEntryOffset;
DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength, IData->pFileInfo->FileName);
return TRUE;
}
IData->pFileInfo = (PVOID)IData + sizeof(KERNEL32_FIND_FILE_DATA);
IData->pFileInfo->FileIndex = 0;
Status = NtQueryDirectoryFile (IData->DirectoryHandle, Status = NtQueryDirectoryFile (IData->DirectoryHandle,
NULL, NULL,
NULL, NULL,
NULL, NULL,
&IoStatusBlock, &IoStatusBlock,
(PVOID)&IData->FileInfo, (PVOID)IData->pFileInfo,
sizeof(IData->FileInfo) + FIND_DATA_SIZE,
sizeof(IData->FileNameExtra),
FileBothDirectoryInformation, FileBothDirectoryInformation,
TRUE, FALSE,
&(IData->PatternStr), NULL,
FALSE); FALSE);
DPRINT("Found %S\n",IData->FileInfo.FileName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return FALSE; return FALSE;
} }
DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength, IData->pFileInfo->FileName);
return TRUE; return TRUE;
} }
@ -79,11 +89,12 @@ InternalFindFirstFile (
PKERNEL32_FIND_FILE_DATA IData; PKERNEL32_FIND_FILE_DATA IData;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
UNICODE_STRING NtPathU; UNICODE_STRING NtPathU;
UNICODE_STRING PatternStr;
NTSTATUS Status; NTSTATUS Status;
PWSTR End; PWSTR End;
DPRINT("FindFirstFileW(lpFileName %S, lpFindFileData %x)\n", DPRINT("FindFirstFileW(lpFileName %S)\n",
lpFileName, lpFindFileData); lpFileName);
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName, if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName,
&NtPathU, &NtPathU,
@ -93,25 +104,25 @@ InternalFindFirstFile (
DPRINT("NtPathU \'%S\' End \'%S\'\n", NtPathU.Buffer, End); DPRINT("NtPathU \'%S\' End \'%S\'\n", NtPathU.Buffer, End);
IData = RtlAllocateHeap (RtlGetProcessHeap (), IData = RtlAllocateHeap (hProcessHeap,
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(KERNEL32_FIND_FILE_DATA)); sizeof(KERNEL32_FIND_FILE_DATA) + FIND_DATA_SIZE);
/* move seach pattern to separate string */ /* move seach pattern to separate string */
RtlCreateUnicodeString (&IData->PatternStr, RtlCreateUnicodeString (&PatternStr,
End); End);
*End = 0; *End = 0;
NtPathU.Length = wcslen(NtPathU.Buffer)*sizeof(WCHAR); NtPathU.Length = wcslen(NtPathU.Buffer)*sizeof(WCHAR);
/* change pattern: "*.*" --> "*" */ /* change pattern: "*.*" --> "*" */
if (!wcscmp (IData->PatternStr.Buffer, L"*.*")) if (!wcscmp (PatternStr.Buffer, L"*.*"))
{ {
IData->PatternStr.Buffer[1] = 0; PatternStr.Buffer[1] = 0;
IData->PatternStr.Length = sizeof(WCHAR); PatternStr.Length = sizeof(WCHAR);
} }
DPRINT("NtPathU \'%S\' Pattern \'%S\'\n", DPRINT("NtPathU \'%S\' Pattern \'%S\'\n",
NtPathU.Buffer, IData->PatternStr.Buffer); NtPathU.Buffer, PatternStr.Buffer);
InitializeObjectAttributes (&ObjectAttributes, InitializeObjectAttributes (&ObjectAttributes,
&NtPathU, &NtPathU,
@ -126,39 +137,40 @@ InternalFindFirstFile (
FILE_OPEN_IF, FILE_OPEN_IF,
OPEN_EXISTING); OPEN_EXISTING);
RtlFreeHeap (RtlGetProcessHeap (), RtlFreeHeap (hProcessHeap,
0, 0,
NtPathU.Buffer); NtPathU.Buffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
RtlFreeHeap (RtlGetProcessHeap (), 0, IData->PatternStr.Buffer); RtlFreeHeap (hProcessHeap, 0, PatternStr.Buffer);
RtlFreeHeap (RtlGetProcessHeap (), 0, IData); RtlFreeHeap (hProcessHeap, 0, IData);
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return(NULL); return(NULL);
} }
IData->pFileInfo = (PVOID)IData + sizeof(KERNEL32_FIND_FILE_DATA);
IData->pFileInfo->FileIndex = 0;
Status = NtQueryDirectoryFile (IData->DirectoryHandle, Status = NtQueryDirectoryFile (IData->DirectoryHandle,
NULL, NULL,
NULL, NULL,
NULL, NULL,
&IoStatusBlock, &IoStatusBlock,
(PVOID)&IData->FileInfo, (PVOID)IData->pFileInfo,
sizeof(IData->FileInfo) + FIND_DATA_SIZE,
sizeof(IData->FileNameExtra),
FileBothDirectoryInformation, FileBothDirectoryInformation,
TRUE, TRUE,
&(IData->PatternStr), &PatternStr,
FALSE); TRUE);
RtlFreeHeap (hProcessHeap, 0, PatternStr.Buffer);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Status %lx\n", Status); DPRINT("Status %lx\n", Status);
RtlFreeHeap (RtlGetProcessHeap (), 0, IData->PatternStr.Buffer); RtlFreeHeap (hProcessHeap, 0, IData);
RtlFreeHeap (RtlGetProcessHeap (), 0, IData);
SetLastErrorByStatus (Status); SetLastErrorByStatus (Status);
return NULL; return NULL;
} }
DPRINT("Found %S\n",IData->FileInfo.FileName); DPRINT("Found %.*S\n",IData->pFileInfo->FileNameLength, IData->pFileInfo->FileName);
return IData; return IData;
} }
@ -198,26 +210,26 @@ FindFirstFileA (
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
DPRINT("IData->FileInfo.FileNameLength %d\n", DPRINT("IData->pFileInfo->FileNameLength %d\n",
IData->FileInfo.FileNameLength); IData->pFileInfo->FileNameLength);
/* copy data into WIN32_FIND_DATA structure */ /* copy data into WIN32_FIND_DATA structure */
lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; lpFindFileData->dwFileAttributes = IData->pFileInfo->FileAttributes;
memcpy (&lpFindFileData->ftCreationTime, memcpy (&lpFindFileData->ftCreationTime,
&IData->FileInfo.CreationTime, &IData->pFileInfo->CreationTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastAccessTime, memcpy (&lpFindFileData->ftLastAccessTime,
&IData->FileInfo.LastAccessTime, &IData->pFileInfo->LastAccessTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastWriteTime, memcpy (&lpFindFileData->ftLastWriteTime,
&IData->FileInfo.LastWriteTime, &IData->pFileInfo->LastWriteTime,
sizeof(FILETIME)); sizeof(FILETIME));
lpFindFileData->nFileSizeHigh = IData->FileInfo.EndOfFile.u.HighPart; lpFindFileData->nFileSizeHigh = IData->pFileInfo->EndOfFile.u.HighPart;
lpFindFileData->nFileSizeLow = IData->FileInfo.EndOfFile.u.LowPart; lpFindFileData->nFileSizeLow = IData->pFileInfo->EndOfFile.u.LowPart;
FileNameU.Length = IData->FileInfo.FileNameLength; FileNameU.Length = IData->pFileInfo->FileNameLength;
FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR); FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR);
FileNameU.Buffer = IData->FileInfo.FileName; FileNameU.Buffer = IData->pFileInfo->FileName;
FileName.Length = 0; FileName.Length = 0;
FileName.MaximumLength = MAX_PATH; FileName.MaximumLength = MAX_PATH;
@ -233,12 +245,12 @@ FindFirstFileA (
&FileNameU, &FileNameU,
FALSE); FALSE);
DPRINT("IData->FileInfo.ShortNameLength %d\n", DPRINT("IData->pFileInfo->ShortNameLength %d\n",
IData->FileInfo.ShortNameLength); IData->pFileInfo->ShortNameLength);
FileNameU.Length = IData->FileInfo.ShortNameLength; FileNameU.Length = IData->pFileInfo->ShortNameLength;
FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR); FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR);
FileNameU.Buffer = IData->FileInfo.ShortName; FileNameU.Buffer = IData->pFileInfo->ShortName;
FileName.Length = 0; FileName.Length = 0;
FileName.MaximumLength = 14; FileName.MaximumLength = 14;
@ -280,26 +292,26 @@ FindNextFileA (
return FALSE; return FALSE;
} }
DPRINT("IData->FileInfo.FileNameLength %d\n", DPRINT("IData->pFileInfo->FileNameLength %d\n",
IData->FileInfo.FileNameLength); IData->pFileInfo->FileNameLength);
/* copy data into WIN32_FIND_DATA structure */ /* copy data into WIN32_FIND_DATA structure */
lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; lpFindFileData->dwFileAttributes = IData->pFileInfo->FileAttributes;
memcpy (&lpFindFileData->ftCreationTime, memcpy (&lpFindFileData->ftCreationTime,
&IData->FileInfo.CreationTime, &IData->pFileInfo->CreationTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastAccessTime, memcpy (&lpFindFileData->ftLastAccessTime,
&IData->FileInfo.LastAccessTime, &IData->pFileInfo->LastAccessTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastWriteTime, memcpy (&lpFindFileData->ftLastWriteTime,
&IData->FileInfo.LastWriteTime, &IData->pFileInfo->LastWriteTime,
sizeof(FILETIME)); sizeof(FILETIME));
lpFindFileData->nFileSizeHigh = IData->FileInfo.EndOfFile.u.HighPart; lpFindFileData->nFileSizeHigh = IData->pFileInfo->EndOfFile.u.HighPart;
lpFindFileData->nFileSizeLow = IData->FileInfo.EndOfFile.u.LowPart; lpFindFileData->nFileSizeLow = IData->pFileInfo->EndOfFile.u.LowPart;
FileNameU.Length = IData->FileInfo.FileNameLength; FileNameU.Length = IData->pFileInfo->FileNameLength;
FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR); FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR);
FileNameU.Buffer = IData->FileInfo.FileName; FileNameU.Buffer = IData->pFileInfo->FileName;
FileName.Length = 0; FileName.Length = 0;
FileName.MaximumLength = MAX_PATH; FileName.MaximumLength = MAX_PATH;
@ -315,12 +327,12 @@ FindNextFileA (
&FileNameU, &FileNameU,
FALSE); FALSE);
DPRINT("IData->FileInfo.ShortNameLength %d\n", DPRINT("IData->pFileInfo->ShortNameLength %d\n",
IData->FileInfo.ShortNameLength); IData->pFileInfo->ShortNameLength);
FileNameU.Length = IData->FileInfo.ShortNameLength; FileNameU.Length = IData->pFileInfo->ShortNameLength;
FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR); FileNameU.MaximumLength = FileNameU.Length + sizeof(WCHAR);
FileNameU.Buffer = IData->FileInfo.ShortName; FileNameU.Buffer = IData->pFileInfo->ShortName;
FileName.Length = 0; FileName.Length = 0;
FileName.MaximumLength = 14; FileName.MaximumLength = 14;
@ -359,9 +371,7 @@ FindClose (
IData = (PKERNEL32_FIND_FILE_DATA)hFindFile; IData = (PKERNEL32_FIND_FILE_DATA)hFindFile;
CloseHandle (IData->DirectoryHandle); CloseHandle (IData->DirectoryHandle);
if (IData->PatternStr.Buffer) RtlFreeHeap (hProcessHeap, 0, IData);
RtlFreeHeap (RtlGetProcessHeap (), 0, IData->PatternStr.Buffer);
RtlFreeHeap (RtlGetProcessHeap (), 0, IData);
return TRUE; return TRUE;
} }
@ -384,26 +394,26 @@ FindFirstFileW (
} }
/* copy data into WIN32_FIND_DATA structure */ /* copy data into WIN32_FIND_DATA structure */
lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; lpFindFileData->dwFileAttributes = IData->pFileInfo->FileAttributes;
memcpy (&lpFindFileData->ftCreationTime, memcpy (&lpFindFileData->ftCreationTime,
&IData->FileInfo.CreationTime, &IData->pFileInfo->CreationTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastAccessTime, memcpy (&lpFindFileData->ftLastAccessTime,
&IData->FileInfo.LastAccessTime, &IData->pFileInfo->LastAccessTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastWriteTime, memcpy (&lpFindFileData->ftLastWriteTime,
&IData->FileInfo.LastWriteTime, &IData->pFileInfo->LastWriteTime,
sizeof(FILETIME)); sizeof(FILETIME));
lpFindFileData->nFileSizeHigh = IData->FileInfo.EndOfFile.u.HighPart; lpFindFileData->nFileSizeHigh = IData->pFileInfo->EndOfFile.u.HighPart;
lpFindFileData->nFileSizeLow = IData->FileInfo.EndOfFile.u.LowPart; lpFindFileData->nFileSizeLow = IData->pFileInfo->EndOfFile.u.LowPart;
memcpy (lpFindFileData->cFileName, memcpy (lpFindFileData->cFileName,
IData->FileInfo.FileName, IData->pFileInfo->FileName,
IData->FileInfo.FileNameLength); IData->pFileInfo->FileNameLength);
lpFindFileData->cFileName[IData->FileInfo.FileNameLength] = 0; lpFindFileData->cFileName[IData->pFileInfo->FileNameLength] = 0;
memcpy (lpFindFileData->cAlternateFileName, memcpy (lpFindFileData->cAlternateFileName,
IData->FileInfo.ShortName, IData->pFileInfo->ShortName,
IData->FileInfo.ShortNameLength); IData->pFileInfo->ShortNameLength);
lpFindFileData->cAlternateFileName[IData->FileInfo.ShortNameLength] = 0; lpFindFileData->cAlternateFileName[IData->pFileInfo->ShortNameLength] = 0;
return IData; return IData;
} }
@ -425,26 +435,26 @@ FindNextFileW (
} }
/* copy data into WIN32_FIND_DATA structure */ /* copy data into WIN32_FIND_DATA structure */
lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; lpFindFileData->dwFileAttributes = IData->pFileInfo->FileAttributes;
memcpy (&lpFindFileData->ftCreationTime, memcpy (&lpFindFileData->ftCreationTime,
&IData->FileInfo.CreationTime, &IData->pFileInfo->CreationTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastAccessTime, memcpy (&lpFindFileData->ftLastAccessTime,
&IData->FileInfo.LastAccessTime, &IData->pFileInfo->LastAccessTime,
sizeof(FILETIME)); sizeof(FILETIME));
memcpy (&lpFindFileData->ftLastWriteTime, memcpy (&lpFindFileData->ftLastWriteTime,
&IData->FileInfo.LastWriteTime, &IData->pFileInfo->LastWriteTime,
sizeof(FILETIME)); sizeof(FILETIME));
lpFindFileData->nFileSizeHigh = IData->FileInfo.EndOfFile.u.HighPart; lpFindFileData->nFileSizeHigh = IData->pFileInfo->EndOfFile.u.HighPart;
lpFindFileData->nFileSizeLow = IData->FileInfo.EndOfFile.u.LowPart; lpFindFileData->nFileSizeLow = IData->pFileInfo->EndOfFile.u.LowPart;
memcpy (lpFindFileData->cFileName, memcpy (lpFindFileData->cFileName,
IData->FileInfo.FileName, IData->pFileInfo->FileName,
IData->FileInfo.FileNameLength); IData->pFileInfo->FileNameLength);
lpFindFileData->cFileName[IData->FileInfo.FileNameLength] = 0; lpFindFileData->cFileName[IData->pFileInfo->FileNameLength] = 0;
memcpy (lpFindFileData->cAlternateFileName, memcpy (lpFindFileData->cAlternateFileName,
IData->FileInfo.ShortName, IData->pFileInfo->ShortName,
IData->FileInfo.ShortNameLength); IData->pFileInfo->ShortNameLength);
lpFindFileData->cAlternateFileName[IData->FileInfo.ShortNameLength] = 0; lpFindFileData->cAlternateFileName[IData->pFileInfo->ShortNameLength] = 0;
return TRUE; return TRUE;
} }