Added cache access for GetEntyName() and FindFile().

Fixed a minor bug in VfatCreateFile().
Added update of the cachesize in VfatCreateFile(), when a the file size is set zero.

svn path=/trunk/; revision=2283
This commit is contained in:
Hartmut Birr 2001-10-10 22:12:34 +00:00
parent 1e43cf0d82
commit b61f55deae

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.32 2001/08/14 20:47:30 hbirr Exp $ /* $Id: create.c,v 1.33 2001/10/10 22:12:34 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -21,6 +21,8 @@
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
#define ENTRIES_PER_PAGE (PAGESIZE / sizeof (FATDirEntry))
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
BOOLEAN BOOLEAN
@ -98,8 +100,8 @@ static void vfat8Dot3ToVolumeLabel (PCHAR pBasename, PCHAR pExtension, PWSTR pN
} }
NTSTATUS NTSTATUS
GetEntryName(PDEVICE_EXTENSION DeviceExt, GetEntryName(PVOID *pContext,
PVOID Block, PVOID *Block,
PFILE_OBJECT FileObject, PFILE_OBJECT FileObject,
PWSTR Name, PWSTR Name,
PULONG pIndex, PULONG pIndex,
@ -112,14 +114,15 @@ GetEntryName(PDEVICE_EXTENSION DeviceExt,
FATDirEntry * test; FATDirEntry * test;
slot * test2; slot * test2;
ULONG cpos; ULONG cpos;
ULONG Offset = *pIndex % ENTRIES_PER_SECTOR; ULONG Offset = *pIndex % ENTRIES_PER_PAGE;
ULONG Read; ULONG Read;
LARGE_INTEGER FileOffset;
*Name = 0; *Name = 0;
while (TRUE) while (TRUE)
{ {
test = (FATDirEntry *) Block; test = (FATDirEntry *) *Block;
test2 = (slot *) Block; test2 = (slot *) *Block;
if (vfatIsDirEntryEndMarker(&test[Offset])) if (vfatIsDirEntryEndMarker(&test[Offset]))
{ {
return STATUS_NO_MORE_ENTRIES; return STATUS_NO_MORE_ENTRIES;
@ -150,16 +153,17 @@ GetEntryName(PDEVICE_EXTENSION DeviceExt,
(*pIndex)++; (*pIndex)++;
Offset++; Offset++;
if (Offset == ENTRIES_PER_SECTOR) if (Offset == ENTRIES_PER_PAGE)
{ {
Offset = 0; Offset = 0;
Status = VfatReadFile (DeviceExt, FileObject, Block, BLOCKSIZE, CcUnpinData(*pContext);
*pIndex * sizeof(FATDirEntry), &Read, TRUE); FileOffset.QuadPart = *pIndex * sizeof(FATDirEntry);
if (!NT_SUCCESS(Status) || Read != BLOCKSIZE) if(!CcMapData(FileObject, &FileOffset, PAGESIZE, TRUE, pContext, Block))
{ {
*pContext = NULL;
return STATUS_NO_MORE_ENTRIES; return STATUS_NO_MORE_ENTRIES;
} }
test2 = (slot *) Block; test2 = (slot *) *Block;
} }
DPRINT (" long name entry found at %d\n", *pIndex); DPRINT (" long name entry found at %d\n", *pIndex);
@ -178,17 +182,18 @@ GetEntryName(PDEVICE_EXTENSION DeviceExt,
} }
(*pIndex)++; (*pIndex)++;
Offset++; Offset++;
if (Offset == ENTRIES_PER_SECTOR) if (Offset == ENTRIES_PER_PAGE)
{ {
Offset = 0; Offset = 0;
Status = VfatReadFile (DeviceExt, FileObject, Block, BLOCKSIZE, CcUnpinData(*pContext);
*pIndex * sizeof(FATDirEntry), &Read, TRUE); FileOffset.QuadPart = *pIndex * sizeof(FATDirEntry);
if (!NT_SUCCESS(Status) || Read != BLOCKSIZE) if(!CcMapData(FileObject, &FileOffset, PAGESIZE, TRUE, pContext, Block))
{ {
*pContext = NULL;
return STATUS_NO_MORE_ENTRIES; return STATUS_NO_MORE_ENTRIES;
} }
test2 = (slot *) Block; test2 = (slot *) *Block;
test = (FATDirEntry*) Block; test = (FATDirEntry*) *Block;
} }
} }
else else
@ -304,7 +309,6 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
{ {
WCHAR name[256]; WCHAR name[256];
WCHAR name2[14]; WCHAR name2[14];
FILE_OBJECT tmpFileObject;
char * block; char * block;
WCHAR TempStr[2]; WCHAR TempStr[2];
NTSTATUS Status; NTSTATUS Status;
@ -314,7 +318,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster; ULONG FirstCluster;
ULONG Read; ULONG Read;
BOOL isRoot; BOOL isRoot;
BOOL first; LARGE_INTEGER FileOffset;
PVOID Context = NULL;
DPRINT ("FindFile(Parent %x, FileToFind '%S', DirIndex: %d)\n", Parent, FileToFind, pDirIndex ? *pDirIndex : 0); DPRINT ("FindFile(Parent %x, FileToFind '%S', DirIndex: %d)\n", Parent, FileToFind, pDirIndex ? *pDirIndex : 0);
DPRINT ("FindFile: old Pathname %x, old Objectname %x)\n",Fcb->PathName, Fcb->ObjectName); DPRINT ("FindFile: old Pathname %x, old Objectname %x)\n",Fcb->PathName, Fcb->ObjectName);
@ -386,30 +391,22 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
if (pDirIndex && (*pDirIndex)) if (pDirIndex && (*pDirIndex))
DirIndex = *pDirIndex; DirIndex = *pDirIndex;
Offset = DirIndex % ENTRIES_PER_PAGE;
memset (&tmpFileObject, 0, sizeof(FILE_OBJECT));
Status = VfatOpenFile(DeviceExt, &tmpFileObject, Parent->PathName);
if (!NT_SUCCESS(Status))
{
if (pDirIndex)
*pDirIndex = DirIndex;
return (STATUS_UNSUCCESSFUL);
}
Offset = DirIndex % ENTRIES_PER_SECTOR;
first = TRUE;
block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
while(TRUE) while(TRUE)
{ {
if (first || Offset == ENTRIES_PER_SECTOR) if (Context == NULL || Offset == ENTRIES_PER_PAGE)
{ {
first = FALSE; if (Offset == ENTRIES_PER_PAGE)
if (Offset == ENTRIES_PER_SECTOR)
Offset = 0; Offset = 0;
Status = VfatReadFile (DeviceExt, &tmpFileObject, block, BLOCKSIZE, if (Context)
(DirIndex - Offset) * sizeof(FATDirEntry), &Read, TRUE);
if (!NT_SUCCESS(Status) || Read != BLOCKSIZE)
{ {
CcUnpinData(Context);
}
FileOffset.QuadPart = (DirIndex - Offset) * sizeof(FATDirEntry);
if (!CcMapData(Parent->FileObject, &FileOffset, PAGESIZE, TRUE,
&Context, (PVOID*)&block))
{
Context = NULL;
break; break;
} }
} }
@ -419,10 +416,11 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
DirIndex++; DirIndex++;
continue; continue;
} }
Status = GetEntryName (DeviceExt, block, &tmpFileObject, name, &DirIndex, pDirIndex2); Status = GetEntryName (&Context, (PVOID*)&block, Parent->FileObject, name,
&DirIndex, pDirIndex2);
if (Status == STATUS_NO_MORE_ENTRIES) if (Status == STATUS_NO_MORE_ENTRIES)
break; break;
Offset = DirIndex % ENTRIES_PER_SECTOR; Offset = DirIndex % ENTRIES_PER_PAGE;
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
vfat8Dot3ToString(((FATDirEntry *) block)[Offset].Filename,((FATDirEntry *) block)[Offset].Ext, name2); vfat8Dot3ToString(((FATDirEntry *) block)[Offset].Filename,((FATDirEntry *) block)[Offset].Ext, name2);
@ -453,8 +451,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
if (pDirIndex) if (pDirIndex)
*pDirIndex = DirIndex; *pDirIndex = DirIndex;
DPRINT("FindFile: new Pathname %S, new Objectname %S, DirIndex %d\n",Fcb->PathName, Fcb->ObjectName, DirIndex); DPRINT("FindFile: new Pathname %S, new Objectname %S, DirIndex %d\n",Fcb->PathName, Fcb->ObjectName, DirIndex);
ExFreePool (block); if (Context)
VfatCloseFile(DeviceExt, &tmpFileObject); CcUnpinData(Context);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
} }
@ -463,8 +461,8 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
} }
if (pDirIndex) if (pDirIndex)
*pDirIndex = DirIndex; *pDirIndex = DirIndex;
ExFreePool (block); if (Context)
VfatCloseFile(DeviceExt, &tmpFileObject); CcUnpinData(Context);
return (STATUS_UNSUCCESSFUL); return (STATUS_UNSUCCESSFUL);
} }
@ -681,9 +679,16 @@ VfatCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
pFcb->entry.FirstCluster = 0; pFcb->entry.FirstCluster = 0;
pFcb->entry.FirstClusterHigh = 0; pFcb->entry.FirstClusterHigh = 0;
updEntry (DeviceExt, FileObject); updEntry (DeviceExt, FileObject);
if ((ULONG)pFcb->RFCB.FileSize.QuadPart > 0)
{
pFcb->RFCB.AllocationSize.QuadPart = 0;
pFcb->RFCB.FileSize.QuadPart = 0;
pFcb->RFCB.ValidDataLength.QuadPart = 0;
CcSetFileSizes(FileObject, (PCC_FILE_SIZES)&pFcb->RFCB.AllocationSize);
}
while (Cluster != 0xffffffff && Cluster > 1) while (Cluster != 0xffffffff && Cluster > 1)
{ {
Status = GetNextCluster (DeviceExt, Cluster, &NextCluster, TRUE); Status = GetNextCluster (DeviceExt, Cluster, &NextCluster, FALSE);
WriteCluster (DeviceExt, Cluster, 0); WriteCluster (DeviceExt, Cluster, 0);
Cluster = NextCluster; Cluster = NextCluster;
} }