2005-08-24 18:29:45 +00:00
|
|
|
/*
|
2001-07-05 01:51:53 +00:00
|
|
|
* FILE: DirEntry.c
|
|
|
|
* PURPOSE: Routines to manipulate directory entries.
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
|
|
|
|
* Rex Jolliff (rex@lvcablemodem.com)
|
2004-12-05 16:31:51 +00:00
|
|
|
* Herve Poussineau (reactos@poussine.freesurf.fr)
|
2001-07-05 01:51:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------- INCLUDES */
|
|
|
|
|
|
|
|
#include "vfat.h"
|
|
|
|
|
2013-12-19 16:20:28 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
ULONG
|
2013-12-09 18:48:13 +00:00
|
|
|
vfatDirEntryGetFirstCluster(
|
|
|
|
PDEVICE_EXTENSION pDeviceExt,
|
|
|
|
PDIR_ENTRY pFatDirEntry)
|
2001-07-05 01:51:53 +00:00
|
|
|
{
|
2008-11-30 20:12:04 +00:00
|
|
|
ULONG cluster;
|
|
|
|
|
|
|
|
if (pDeviceExt->FatInfo.FatType == FAT32)
|
|
|
|
{
|
|
|
|
cluster = pFatDirEntry->Fat.FirstCluster |
|
|
|
|
(pFatDirEntry->Fat.FirstClusterHigh << 16);
|
|
|
|
}
|
2017-02-17 21:24:12 +00:00
|
|
|
else if (vfatVolumeIsFatX(pDeviceExt))
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
|
|
|
cluster = pFatDirEntry->FatX.FirstCluster;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cluster = pFatDirEntry->Fat.FirstCluster;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cluster;
|
2001-07-05 01:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
BOOLEAN
|
2013-12-09 18:48:13 +00:00
|
|
|
FATIsDirectoryEmpty(
|
2018-05-18 12:03:20 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
2013-12-09 18:48:13 +00:00
|
|
|
PVFATFCB Fcb)
|
2001-07-05 01:51:53 +00:00
|
|
|
{
|
2008-11-30 20:12:04 +00:00
|
|
|
LARGE_INTEGER FileOffset;
|
|
|
|
PVOID Context = NULL;
|
|
|
|
PFAT_DIR_ENTRY FatDirEntry;
|
|
|
|
ULONG Index, MaxIndex;
|
2018-05-18 12:03:20 +00:00
|
|
|
NTSTATUS Status;
|
2008-11-30 20:12:04 +00:00
|
|
|
|
|
|
|
if (vfatFCBIsRoot(Fcb))
|
|
|
|
{
|
|
|
|
Index = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Index = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileOffset.QuadPart = 0;
|
|
|
|
MaxIndex = Fcb->RFCB.FileSize.u.LowPart / sizeof(FAT_DIR_ENTRY);
|
|
|
|
|
2018-05-18 12:03:20 +00:00
|
|
|
Status = vfatFCBInitializeCacheFromVolume(DeviceExt, Fcb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
while (Index < MaxIndex)
|
|
|
|
{
|
|
|
|
if (Context == NULL || (Index % FAT_ENTRIES_PER_PAGE) == 0)
|
|
|
|
{
|
|
|
|
if (Context != NULL)
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(Fcb->FileObject, &FileOffset, sizeof(FAT_DIR_ENTRY), MAP_WAIT, &Context, (PVOID*)&FatDirEntry);
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
_SEH2_YIELD(return TRUE);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2008-11-30 20:12:04 +00:00
|
|
|
|
|
|
|
FatDirEntry += Index % FAT_ENTRIES_PER_PAGE;
|
2009-03-06 17:23:29 +00:00
|
|
|
FileOffset.QuadPart += PAGE_SIZE;
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FAT_ENTRY_END(FatDirEntry))
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FAT_ENTRY_DELETED(FatDirEntry))
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Index++;
|
|
|
|
FatDirEntry++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Context)
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-07-05 01:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
BOOLEAN
|
2013-12-09 18:48:13 +00:00
|
|
|
FATXIsDirectoryEmpty(
|
2018-05-18 12:03:20 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt,
|
2013-12-09 18:48:13 +00:00
|
|
|
PVFATFCB Fcb)
|
2004-12-05 16:31:51 +00:00
|
|
|
{
|
2008-11-30 20:12:04 +00:00
|
|
|
LARGE_INTEGER FileOffset;
|
|
|
|
PVOID Context = NULL;
|
|
|
|
PFATX_DIR_ENTRY FatXDirEntry;
|
|
|
|
ULONG Index = 0, MaxIndex;
|
2018-05-18 12:03:20 +00:00
|
|
|
NTSTATUS Status;
|
2004-12-05 16:31:51 +00:00
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
FileOffset.QuadPart = 0;
|
|
|
|
MaxIndex = Fcb->RFCB.FileSize.u.LowPart / sizeof(FATX_DIR_ENTRY);
|
2004-12-05 16:31:51 +00:00
|
|
|
|
2018-05-18 12:03:20 +00:00
|
|
|
Status = vfatFCBInitializeCacheFromVolume(DeviceExt, Fcb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
while (Index < MaxIndex)
|
|
|
|
{
|
|
|
|
if (Context == NULL || (Index % FATX_ENTRIES_PER_PAGE) == 0)
|
|
|
|
{
|
|
|
|
if (Context != NULL)
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(Fcb->FileObject, &FileOffset, sizeof(FATX_DIR_ENTRY), MAP_WAIT, &Context, (PVOID*)&FatXDirEntry);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_YIELD(return TRUE);
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_END;
|
2008-11-30 20:12:04 +00:00
|
|
|
|
|
|
|
FatXDirEntry += Index % FATX_ENTRIES_PER_PAGE;
|
2009-03-06 17:23:29 +00:00
|
|
|
FileOffset.QuadPart += PAGE_SIZE;
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FATX_ENTRY_END(FatXDirEntry))
|
|
|
|
{
|
2004-12-05 16:31:51 +00:00
|
|
|
CcUnpinData(Context);
|
|
|
|
return TRUE;
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!FATX_ENTRY_DELETED(FatXDirEntry))
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Index++;
|
|
|
|
FatXDirEntry++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Context)
|
|
|
|
{
|
|
|
|
CcUnpinData(Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
NTSTATUS
|
2013-12-09 18:48:13 +00:00
|
|
|
FATGetNextDirEntry(
|
|
|
|
PVOID *pContext,
|
|
|
|
PVOID *pPage,
|
|
|
|
IN PVFATFCB pDirFcb,
|
|
|
|
PVFAT_DIRENTRY_CONTEXT DirContext,
|
|
|
|
BOOLEAN First)
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
{
|
|
|
|
ULONG dirMap;
|
|
|
|
PWCHAR pName;
|
|
|
|
LARGE_INTEGER FileOffset;
|
2004-12-05 16:31:51 +00:00
|
|
|
PFAT_DIR_ENTRY fatDirEntry;
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
slot * longNameEntry;
|
|
|
|
ULONG index;
|
2005-05-08 02:16:32 +00:00
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
UCHAR CheckSum, shortCheckSum;
|
|
|
|
USHORT i;
|
|
|
|
BOOLEAN Valid = TRUE;
|
|
|
|
BOOLEAN Back = FALSE;
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
|
2018-05-18 12:03:20 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
2011-10-21 13:21:56 +00:00
|
|
|
DirContext->LongNameU.Length = 0;
|
|
|
|
DirContext->LongNameU.Buffer[0] = UNICODE_NULL;
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
|
|
|
|
FileOffset.u.HighPart = 0;
|
2004-12-05 16:31:51 +00:00
|
|
|
FileOffset.u.LowPart = ROUND_DOWN(DirContext->DirIndex * sizeof(FAT_DIR_ENTRY), PAGE_SIZE);
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
|
2018-05-18 12:03:20 +00:00
|
|
|
Status = vfatFCBInitializeCacheFromVolume(DirContext->DeviceExt, pDirFcb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
if (*pContext == NULL || (DirContext->DirIndex % FAT_ENTRIES_PER_PAGE) == 0)
|
2001-07-05 01:51:53 +00:00
|
|
|
{
|
2008-11-30 20:12:04 +00:00
|
|
|
if (*pContext != NULL)
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
if (FileOffset.u.LowPart >= pDirFcb->RFCB.FileSize.u.LowPart)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
2016-07-10 17:14:33 +00:00
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(pDirFcb->FileObject, &FileOffset, PAGE_SIZE, MAP_WAIT, pContext, pPage);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
_SEH2_YIELD(return STATUS_NO_MORE_ENTRIES);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2001-07-05 01:51:53 +00:00
|
|
|
}
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
fatDirEntry = (PFAT_DIR_ENTRY)(*pPage) + DirContext->DirIndex % FAT_ENTRIES_PER_PAGE;
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
longNameEntry = (slot*) fatDirEntry;
|
|
|
|
dirMap = 0;
|
|
|
|
|
2003-10-11 17:51:56 +00:00
|
|
|
if (First)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
2005-05-08 02:16:32 +00:00
|
|
|
/* This is the first call to vfatGetNextDirEntry. Possible the start index points
|
2008-11-30 20:12:04 +00:00
|
|
|
* into a long name or points to a short name with an assigned long name.
|
|
|
|
* We must go back to the real start of the entry */
|
2005-05-08 02:16:32 +00:00
|
|
|
while (DirContext->DirIndex > 0 &&
|
2008-11-30 20:12:04 +00:00
|
|
|
!FAT_ENTRY_END(fatDirEntry) &&
|
|
|
|
!FAT_ENTRY_DELETED(fatDirEntry) &&
|
|
|
|
((!FAT_ENTRY_LONG(fatDirEntry) && !Back) ||
|
|
|
|
(FAT_ENTRY_LONG(fatDirEntry) && !(longNameEntry->id & 0x40))))
|
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
DirContext->DirIndex--;
|
2008-11-30 20:12:04 +00:00
|
|
|
Back = TRUE;
|
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
if ((DirContext->DirIndex % FAT_ENTRIES_PER_PAGE) == FAT_ENTRIES_PER_PAGE - 1)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
CcUnpinData(*pContext);
|
|
|
|
FileOffset.u.LowPart -= PAGE_SIZE;
|
2008-11-30 20:12:04 +00:00
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
if (FileOffset.u.LowPart >= pDirFcb->RFCB.FileSize.u.LowPart)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(pDirFcb->FileObject, &FileOffset, PAGE_SIZE, MAP_WAIT, pContext, pPage);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
_SEH2_YIELD(return STATUS_NO_MORE_ENTRIES);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
2004-12-05 16:31:51 +00:00
|
|
|
fatDirEntry = (PFAT_DIR_ENTRY)(*pPage) + DirContext->DirIndex % FAT_ENTRIES_PER_PAGE;
|
2003-10-11 17:51:56 +00:00
|
|
|
longNameEntry = (slot*) fatDirEntry;
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
fatDirEntry--;
|
2008-11-30 20:12:04 +00:00
|
|
|
longNameEntry--;
|
|
|
|
}
|
|
|
|
}
|
2003-10-11 17:51:56 +00:00
|
|
|
|
2005-05-08 02:16:32 +00:00
|
|
|
if (Back && !FAT_ENTRY_END(fatDirEntry) &&
|
2008-11-30 20:12:04 +00:00
|
|
|
(FAT_ENTRY_DELETED(fatDirEntry) || !FAT_ENTRY_LONG(fatDirEntry)))
|
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
DirContext->DirIndex++;
|
2008-11-30 20:12:04 +00:00
|
|
|
|
|
|
|
if ((DirContext->DirIndex % FAT_ENTRIES_PER_PAGE) == 0)
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
FileOffset.u.LowPart += PAGE_SIZE;
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
if (FileOffset.u.LowPart >= pDirFcb->RFCB.FileSize.u.LowPart)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(pDirFcb->FileObject, &FileOffset, PAGE_SIZE, MAP_WAIT, pContext, pPage);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
_SEH2_YIELD(return STATUS_NO_MORE_ENTRIES);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
fatDirEntry = (PFAT_DIR_ENTRY)*pPage;
|
|
|
|
longNameEntry = (slot*) *pPage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fatDirEntry++;
|
|
|
|
longNameEntry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-11 17:51:56 +00:00
|
|
|
|
|
|
|
DirContext->StartIndex = DirContext->DirIndex;
|
|
|
|
CheckSum = 0;
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
|
|
|
|
while (TRUE)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
|
|
|
if (FAT_ENTRY_END(fatDirEntry))
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
if (FAT_ENTRY_DELETED(fatDirEntry))
|
|
|
|
{
|
|
|
|
dirMap = 0;
|
|
|
|
DirContext->LongNameU.Buffer[0] = 0;
|
|
|
|
DirContext->StartIndex = DirContext->DirIndex + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FAT_ENTRY_LONG(fatDirEntry))
|
|
|
|
{
|
|
|
|
if (dirMap == 0)
|
|
|
|
{
|
2013-05-11 11:03:12 +00:00
|
|
|
DPRINT (" long name entry found at %u\n", DirContext->DirIndex);
|
2008-11-30 20:12:04 +00:00
|
|
|
RtlZeroMemory(DirContext->LongNameU.Buffer, DirContext->LongNameU.MaximumLength);
|
|
|
|
CheckSum = longNameEntry->alias_checksum;
|
|
|
|
Valid = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT(" name chunk1:[%.*S] chunk2:[%.*S] chunk3:[%.*S]\n",
|
|
|
|
5, longNameEntry->name0_4,
|
|
|
|
6, longNameEntry->name5_10,
|
|
|
|
2, longNameEntry->name11_12);
|
|
|
|
|
2011-10-21 13:21:56 +00:00
|
|
|
index = longNameEntry->id & 0x3f; // Note: it can be 0 for corrupted FS
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2016-11-13 15:31:39 +00:00
|
|
|
/* Make sure index is valid and we have enough space in buffer
|
2011-10-21 13:21:56 +00:00
|
|
|
(we count one char for \0) */
|
|
|
|
if (index > 0 &&
|
|
|
|
index * 13 < DirContext->LongNameU.MaximumLength / sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
index--; // make index 0 based
|
|
|
|
dirMap |= 1 << index;
|
|
|
|
|
|
|
|
pName = DirContext->LongNameU.Buffer + index * 13;
|
|
|
|
RtlCopyMemory(pName, longNameEntry->name0_4, 5 * sizeof(WCHAR));
|
|
|
|
RtlCopyMemory(pName + 5, longNameEntry->name5_10, 6 * sizeof(WCHAR));
|
|
|
|
RtlCopyMemory(pName + 11, longNameEntry->name11_12, 2 * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (longNameEntry->id & 0x40)
|
|
|
|
{
|
|
|
|
/* It's last LFN entry. Terminate filename with \0 */
|
|
|
|
pName[13] = UNICODE_NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DPRINT1("Long name entry has invalid index: %x!\n", longNameEntry->id);
|
2008-11-30 20:12:04 +00:00
|
|
|
|
|
|
|
DPRINT (" longName: [%S]\n", DirContext->LongNameU.Buffer);
|
|
|
|
|
|
|
|
if (CheckSum != longNameEntry->alias_checksum)
|
|
|
|
{
|
|
|
|
DPRINT1("Found wrong alias checksum in long name entry (first %x, current %x, %S)\n",
|
|
|
|
CheckSum, longNameEntry->alias_checksum, DirContext->LongNameU.Buffer);
|
|
|
|
Valid = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shortCheckSum = 0;
|
2003-10-11 17:51:56 +00:00
|
|
|
for (i = 0; i < 11; i++)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
2003-10-11 17:51:56 +00:00
|
|
|
shortCheckSum = (((shortCheckSum & 1) << 7)
|
|
|
|
| ((shortCheckSum & 0xfe) >> 1))
|
2005-08-24 18:29:45 +00:00
|
|
|
+ fatDirEntry->ShortName[i];
|
2008-11-30 20:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shortCheckSum != CheckSum && DirContext->LongNameU.Buffer[0])
|
|
|
|
{
|
|
|
|
DPRINT1("Checksum from long and short name is not equal (short: %x, long: %x, %S)\n",
|
|
|
|
shortCheckSum, CheckSum, DirContext->LongNameU.Buffer);
|
|
|
|
DirContext->LongNameU.Buffer[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Valid == FALSE)
|
|
|
|
{
|
|
|
|
DirContext->LongNameU.Buffer[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlCopyMemory (&DirContext->DirEntry.Fat, fatDirEntry, sizeof (FAT_DIR_ENTRY));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DirContext->DirIndex++;
|
|
|
|
|
|
|
|
if ((DirContext->DirIndex % FAT_ENTRIES_PER_PAGE) == 0)
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
FileOffset.u.LowPart += PAGE_SIZE;
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
if (FileOffset.u.LowPart >= pDirFcb->RFCB.FileSize.u.LowPart)
|
2008-11-30 20:12:04 +00:00
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:14:33 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(pDirFcb->FileObject, &FileOffset, PAGE_SIZE, MAP_WAIT, pContext, pPage);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
_SEH2_YIELD(return STATUS_NO_MORE_ENTRIES);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
2008-11-30 20:12:04 +00:00
|
|
|
fatDirEntry = (PFAT_DIR_ENTRY)*pPage;
|
|
|
|
longNameEntry = (slot*) *pPage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fatDirEntry++;
|
|
|
|
longNameEntry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-21 13:21:56 +00:00
|
|
|
/* Make sure filename is NULL terminate and calculate length */
|
|
|
|
DirContext->LongNameU.Buffer[DirContext->LongNameU.MaximumLength / sizeof(WCHAR) - 1]
|
|
|
|
= UNICODE_NULL;
|
2003-10-11 17:51:56 +00:00
|
|
|
DirContext->LongNameU.Length = wcslen(DirContext->LongNameU.Buffer) * sizeof(WCHAR);
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-10-21 13:21:56 +00:00
|
|
|
/* Init short name */
|
2004-12-05 16:31:51 +00:00
|
|
|
vfat8Dot3ToString(&DirContext->DirEntry.Fat, &DirContext->ShortNameU);
|
2008-11-30 20:12:04 +00:00
|
|
|
|
2011-10-21 13:21:56 +00:00
|
|
|
/* If we found no LFN, use short name as long */
|
2003-10-11 17:51:56 +00:00
|
|
|
if (DirContext->LongNameU.Length == 0)
|
|
|
|
RtlCopyUnicodeString(&DirContext->LongNameU, &DirContext->ShortNameU);
|
2008-11-30 20:12:04 +00:00
|
|
|
|
* Used look aside lists to allocate memory for VFATFCB, VFATCCB and VFAT_IRP_CONTEXT.
* Removed IsLastEntry, IsVolEntry, IsDeletedEntry, vfat_wstrlen, vfatGrabFCB,
vfat_initstr, vfat_wcsncat, vfat_wcsncpy, vfat_movestr, wstrcmpi and replaced
this functions with existing equivalents or functions from ntoskrnl.
* Merged GetEntryName into vfatGetNextDirEntry for reducing some overhead.
* Implemented a file name cache to speed up the searching for existing fcb.
* Removed some calls to FsdDosDateTimeToFileTime.
* Moved the call to CcZeroData behind the initializing of the cache (in VfatWrite).
* Using existing fcbs in FindFile if there is no '*?' within the search name.
svn path=/trunk/; revision=3740
2002-11-11 21:49:18 +00:00
|
|
|
return STATUS_SUCCESS;
|
2001-07-05 01:51:53 +00:00
|
|
|
}
|
2004-12-05 16:31:51 +00:00
|
|
|
|
2013-12-09 18:48:13 +00:00
|
|
|
NTSTATUS
|
|
|
|
FATXGetNextDirEntry(
|
|
|
|
PVOID *pContext,
|
|
|
|
PVOID *pPage,
|
|
|
|
IN PVFATFCB pDirFcb,
|
|
|
|
PVFAT_DIRENTRY_CONTEXT DirContext,
|
|
|
|
BOOLEAN First)
|
2004-12-05 16:31:51 +00:00
|
|
|
{
|
2013-12-09 18:48:13 +00:00
|
|
|
LARGE_INTEGER FileOffset;
|
|
|
|
PFATX_DIR_ENTRY fatxDirEntry;
|
|
|
|
OEM_STRING StringO;
|
|
|
|
ULONG DirIndex = DirContext->DirIndex;
|
2018-05-18 12:03:20 +00:00
|
|
|
NTSTATUS Status;
|
2013-12-09 18:48:13 +00:00
|
|
|
|
|
|
|
FileOffset.u.HighPart = 0;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(First);
|
|
|
|
|
|
|
|
if (!vfatFCBIsRoot(pDirFcb))
|
|
|
|
{
|
|
|
|
/* need to add . and .. entries */
|
|
|
|
switch (DirContext->DirIndex)
|
|
|
|
{
|
|
|
|
case 0: /* entry . */
|
|
|
|
DirContext->ShortNameU.Buffer[0] = 0;
|
|
|
|
DirContext->ShortNameU.Length = 0;
|
|
|
|
wcscpy(DirContext->LongNameU.Buffer, L".");
|
|
|
|
DirContext->LongNameU.Length = sizeof(WCHAR);
|
|
|
|
RtlCopyMemory(&DirContext->DirEntry.FatX, &pDirFcb->entry.FatX, sizeof(FATX_DIR_ENTRY));
|
|
|
|
DirContext->DirEntry.FatX.Filename[0] = '.';
|
|
|
|
DirContext->DirEntry.FatX.FilenameLength = 1;
|
|
|
|
DirContext->StartIndex = 0;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
case 1: /* entry .. */
|
|
|
|
DirContext->ShortNameU.Buffer[0] = 0;
|
|
|
|
DirContext->ShortNameU.Length = 0;
|
|
|
|
wcscpy(DirContext->LongNameU.Buffer, L"..");
|
|
|
|
DirContext->LongNameU.Length = 2 * sizeof(WCHAR);
|
|
|
|
RtlCopyMemory(&DirContext->DirEntry.FatX, &pDirFcb->entry.FatX, sizeof(FATX_DIR_ENTRY));
|
|
|
|
DirContext->DirEntry.FatX.Filename[0] = DirContext->DirEntry.FatX.Filename[1] = '.';
|
|
|
|
DirContext->DirEntry.FatX.FilenameLength = 2;
|
|
|
|
DirContext->StartIndex = 1;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DirIndex -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:03:20 +00:00
|
|
|
Status = vfatFCBInitializeCacheFromVolume(DirContext->DeviceExt, pDirFcb);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2013-12-09 18:48:13 +00:00
|
|
|
if (*pContext == NULL || (DirIndex % FATX_ENTRIES_PER_PAGE) == 0)
|
|
|
|
{
|
|
|
|
if (*pContext != NULL)
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
}
|
|
|
|
FileOffset.u.LowPart = ROUND_DOWN(DirIndex * sizeof(FATX_DIR_ENTRY), PAGE_SIZE);
|
2016-07-10 17:14:33 +00:00
|
|
|
if (FileOffset.u.LowPart >= pDirFcb->RFCB.FileSize.u.LowPart)
|
2013-12-09 18:48:13 +00:00
|
|
|
{
|
2005-01-25 21:14:57 +00:00
|
|
|
*pContext = NULL;
|
2013-12-09 18:48:13 +00:00
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
2016-07-10 17:14:33 +00:00
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(pDirFcb->FileObject, &FileOffset, PAGE_SIZE, MAP_WAIT, pContext, pPage);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
_SEH2_YIELD(return STATUS_NO_MORE_ENTRIES);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2013-12-09 18:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fatxDirEntry = (PFATX_DIR_ENTRY)(*pPage) + DirIndex % FATX_ENTRIES_PER_PAGE;
|
|
|
|
|
|
|
|
DirContext->StartIndex = DirContext->DirIndex;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
if (FATX_ENTRY_END(fatxDirEntry))
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FATX_ENTRY_DELETED(fatxDirEntry))
|
|
|
|
{
|
|
|
|
RtlCopyMemory(&DirContext->DirEntry.FatX, fatxDirEntry, sizeof(FATX_DIR_ENTRY));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DirContext->DirIndex++;
|
|
|
|
DirContext->StartIndex++;
|
|
|
|
DirIndex++;
|
|
|
|
if ((DirIndex % FATX_ENTRIES_PER_PAGE) == 0)
|
|
|
|
{
|
|
|
|
CcUnpinData(*pContext);
|
|
|
|
FileOffset.u.LowPart += PAGE_SIZE;
|
2016-07-10 17:14:33 +00:00
|
|
|
if (FileOffset.u.LowPart >= pDirFcb->RFCB.FileSize.u.LowPart)
|
2013-12-09 18:48:13 +00:00
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
2016-07-10 17:14:33 +00:00
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2016-07-10 18:16:03 +00:00
|
|
|
CcMapData(pDirFcb->FileObject, &FileOffset, PAGE_SIZE, MAP_WAIT, pContext, pPage);
|
2016-07-10 17:14:33 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
*pContext = NULL;
|
|
|
|
_SEH2_YIELD(return STATUS_NO_MORE_ENTRIES);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
2013-12-09 18:48:13 +00:00
|
|
|
fatxDirEntry = (PFATX_DIR_ENTRY)*pPage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fatxDirEntry++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DirContext->ShortNameU.Buffer[0] = 0;
|
|
|
|
DirContext->ShortNameU.Length = 0;
|
|
|
|
StringO.Buffer = (PCHAR)fatxDirEntry->Filename;
|
|
|
|
StringO.Length = StringO.MaximumLength = fatxDirEntry->FilenameLength;
|
|
|
|
RtlOemStringToUnicodeString(&DirContext->LongNameU, &StringO, FALSE);
|
|
|
|
return STATUS_SUCCESS;
|
2004-12-05 16:31:51 +00:00
|
|
|
}
|