Modified: trunk/reactos/drivers/fs/vfat/cleanup.c
Modified: trunk/reactos/drivers/fs/vfat/close.c
Modified: trunk/reactos/drivers/fs/vfat/fcb.c
Modified: trunk/reactos/drivers/fs/vfat/fsctl.c
Modified: trunk/reactos/drivers/fs/vfat/vfat.h
--- trunk/reactos/drivers/fs/vfat/cleanup.c 2005-04-01 18:22:17 UTC (rev 14421)
+++ trunk/reactos/drivers/fs/vfat/cleanup.c 2005-04-01 18:35:34 UTC (rev 14422)
@@ -49,6 +49,19 @@
if (pFcb->Flags & FCB_DELETE_PENDING &&
pFcb->OpenHandleCount == 1)
{
+ PFILE_OBJECT tmpFileObject;
+ tmpFileObject = pFcb->FileObject;
+ if (tmpFileObject != NULL)
+ {
+ pFcb->FileObject = NULL;
+#ifdef USE_ROS_CC_AND_FS
+ CcRosReleaseFileCache(tmpFileObject);
+#else
+ CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
+#endif
+ ObDereferenceObject(tmpFileObject);
+ }
+
#if 0
/* FIXME:
* CcPurgeCacheSection is unimplemented.
--- trunk/reactos/drivers/fs/vfat/close.c 2005-04-01 18:22:17 UTC (rev 14421)
+++ trunk/reactos/drivers/fs/vfat/close.c 2005-04-01 18:35:34 UTC (rev 14422)
@@ -43,11 +43,8 @@
pFcb->RefCount--;
FileObject->FsContext2 = NULL;
}
- else if (FileObject->FileName.Buffer)
+ else
{
- // This a FO, that was created outside from FSD.
- // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
- // This FO's haven't a FileName.
if (FileObject->DeletePending)
{
if (pFcb->Flags & FCB_DELETE_PENDING)
--- trunk/reactos/drivers/fs/vfat/fcb.c 2005-04-01 18:22:17 UTC (rev 14421)
+++ trunk/reactos/drivers/fs/vfat/fcb.c 2005-04-01 18:35:34 UTC (rev 14422)
@@ -191,10 +191,10 @@
while (pFCB)
{
- Index = pFCB->Hash.Hash % FCB_HASH_TABLE_SIZE;
- ShortIndex = pFCB->ShortHash.Hash % FCB_HASH_TABLE_SIZE;
+ Index = pFCB->Hash.Hash % pVCB->HashTableSize;
+ ShortIndex = pFCB->ShortHash.Hash % pVCB->HashTableSize;
pFCB->RefCount--;
- if (pFCB->RefCount <= 0 && (!vfatFCBIsDirectory (pFCB) || pFCB->Flags & FCB_DELETE_PENDING))
+ if (pFCB->RefCount == 0)
{
tmpFcb = pFCB->parentFcb;
RemoveEntryList (&pFCB->FcbListEntry);
@@ -227,22 +227,6 @@
}
entry->next = pFCB->Hash.next;
}
- if (vfatFCBIsDirectory(pFCB))
- {
- /* Uninitialize file cache if initialized for this file object. */
- if (pFCB->FileObject->SectionObjectPointer->SharedCacheMap)
- {
-#ifdef USE_ROS_CC_AND_FS
- CcRosReleaseFileCache(pFCB->FileObject);
-#else
- CcUninitializeCacheMap(pFCB->FileObject, NULL, NULL);
-#endif
- }
- vfatDestroyCCB(pFCB->FileObject->FsContext2);
- pFCB->FileObject->FsContext2 = NULL;
- pFCB->FileObject->FsContext = NULL;
- ObDereferenceObject(pFCB->FileObject);
- }
vfatDestroyFCB (pFCB);
}
else
@@ -259,8 +243,8 @@
ULONG Index;
ULONG ShortIndex;
- Index = pFCB->Hash.Hash % FCB_HASH_TABLE_SIZE;
- ShortIndex = pFCB->ShortHash.Hash % FCB_HASH_TABLE_SIZE;
+ Index = pFCB->Hash.Hash % pVCB->HashTableSize;
+ ShortIndex = pFCB->ShortHash.Hash % pVCB->HashTableSize;
InsertTailList (&pVCB->FcbListHead, &pFCB->FcbListEntry);
@@ -292,7 +276,7 @@
Hash = vfatNameHash(0, PathNameU);
- entry = pVCB->FcbHashTable[Hash % FCB_HASH_TABLE_SIZE];
+ entry = pVCB->FcbHashTable[Hash % pVCB->HashTableSize];
if (entry)
{
vfatSplitPathName(PathNameU, &DirNameU, &FileNameU);
@@ -353,6 +337,7 @@
fileObject->FsContext = fcb;
fileObject->FsContext2 = newCCB;
fcb->FileObject = fileObject;
+ fcb->RefCount++;
#ifdef USE_ROS_CC_AND_FS
fileCacheQuantum = (vcb->FatInfo.BytesPerCluster >= PAGE_SIZE) ?
@@ -375,12 +360,7 @@
#endif
fcb->Flags |= FCB_CACHE_INITIALIZED;
-
-#ifdef USE_ROS_CC_AND_FS
- return status;
-#else
return STATUS_SUCCESS;
-#endif
}
PVFATFCB
--- trunk/reactos/drivers/fs/vfat/fsctl.c 2005-04-01 18:22:17 UTC (rev 14421)
+++ trunk/reactos/drivers/fs/vfat/fsctl.c 2005-04-01 18:35:34 UTC (rev 14422)
@@ -372,6 +372,8 @@
PDEVICE_OBJECT DeviceToMount;
UNICODE_STRING NameU = RTL_CONSTANT_STRING(L"\\$$Fat$$");
UNICODE_STRING VolumeNameU = RTL_CONSTANT_STRING(L"\\$$Volume$$");
+ ULONG HashTableSize;
+ FATINFO FatInfo;
DPRINT("VfatMount(IrpContext %x)\n", IrpContext);
@@ -385,7 +387,7 @@
DeviceToMount = IrpContext->Stack->Parameters.MountVolume.DeviceObject;
- Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS, NULL);
+ Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS, &FatInfo);
if (!NT_SUCCESS(Status))
{
goto ByeBye;
@@ -398,9 +400,24 @@
goto ByeBye;
}
+ /* Use prime numbers for the table size */
+ if (FatInfo.FatType == FAT12)
+ {
+ HashTableSize = 4099; // 4096 = 4 * 1024
+ }
+ else if (FatInfo.FatType == FAT16 ||
+ FatInfo.FatType == FATX16)
+ {
+ HashTableSize = 16411; // 16384 = 16 * 1024
+ }
+ else
+ {
+ HashTableSize = 65537; // 65536 = 64 * 1024;
+ }
+ HashTableSize = FCB_HASH_TABLE_SIZE;
DPRINT("VFAT: Recognized volume\n");
Status = IoCreateDevice(VfatGlobalData->DriverObject,
- sizeof (DEVICE_EXTENSION),
+ ROUND_UP(sizeof (DEVICE_EXTENSION), sizeof(DWORD)) + sizeof(HASHENTRY*) * HashTableSize,
NULL,
FILE_DEVICE_FILE_SYSTEM,
0,
@@ -413,7 +430,9 @@
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
DeviceExt = (PVOID) DeviceObject->DeviceExtension;
- RtlZeroMemory(DeviceExt, sizeof(DEVICE_EXTENSION));
+ RtlZeroMemory(DeviceExt, ROUND_UP(sizeof(DEVICE_EXTENSION), sizeof(DWORD)) + sizeof(HASHENTRY*) * HashTableSize);
+ DeviceExt->FcbHashTable = (HASHENTRY**)((ULONG_PTR)DeviceExt + ROUND_UP(sizeof(DEVICE_EXTENSION), sizeof(DWORD)));
+ DeviceExt->HashTableSize = HashTableSize;
/* use same vpb as device disk */
DeviceObject->Vpb = DeviceToMount->Vpb;
@@ -557,7 +576,7 @@
/* read volume label */
ReadVolumeLabel(DeviceExt, DeviceObject->Vpb);
-
+
Status = STATUS_SUCCESS;
ByeBye:
--- trunk/reactos/drivers/fs/vfat/vfat.h 2005-04-01 18:22:17 UTC (rev 14421)
+++ trunk/reactos/drivers/fs/vfat/vfat.h 2005-04-01 18:35:34 UTC (rev 14422)
@@ -241,7 +241,8 @@
KSPIN_LOCK FcbListLock;
LIST_ENTRY FcbListHead;
- struct _HASHENTRY* FcbHashTable[FCB_HASH_TABLE_SIZE];
+ ULONG HashTableSize;
+ struct _HASHENTRY** FcbHashTable;
PDEVICE_OBJECT StorageDevice;
PFILE_OBJECT FATFileObject;