Changed the directory access to Cc...Data().

Removed the useing of dummy FileObjects in some calls to VfatReadFile()/VfatWriteFile().

svn path=/trunk/; revision=2286
This commit is contained in:
Hartmut Birr 2001-10-10 22:15:51 +00:00
parent 069a01eede
commit 068a4a38d5

View file

@ -1,4 +1,4 @@
/* $Id: dirwr.c,v 1.21 2001/08/14 20:47:30 hbirr Exp $ /* $Id: dirwr.c,v 1.22 2001/10/10 22:15:51 hbirr Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -95,17 +95,16 @@ NTSTATUS updEntry (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT pFileObject)
update an existing FAT entry update an existing FAT entry
*/ */
{ {
VFATFCB Fcb; PVOID Context;
VFATCCB Ccb; PVOID Buffer;
ULONG Entry = 0;
NTSTATUS status; NTSTATUS status;
FILE_OBJECT FileObject;
PVFATFCB pDirFcb = NULL, pFcb = NULL; PVFATFCB pDirFcb = NULL, pFcb = NULL;
PWCHAR pName; LARGE_INTEGER Offset;
DPRINT ("updEntry PathFileName \'%S\'\n", pFileObject->FileName.Buffer); DPRINT ("updEntry PathFileName \'%S\'\n",
((PVFATCCB)(pFileObject->FsContext2))->pFcb->PathName);
status = vfatGetFCBForFile(DeviceExt, &pDirFcb, &pFcb, pFileObject->FileName.Buffer); status = vfatGetFCBForFile(DeviceExt, &pDirFcb, &pFcb,
((PVFATCCB)(pFileObject->FsContext2))->pFcb->PathName);
if (pFcb != NULL) if (pFcb != NULL)
{ {
vfatReleaseFCB(DeviceExt, pFcb); vfatReleaseFCB(DeviceExt, pFcb);
@ -119,27 +118,18 @@ NTSTATUS updEntry (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT pFileObject)
return status; return status;
} }
pName = ((PVFATCCB)(pFileObject->FsContext2))->pFcb->ObjectName; Offset.QuadPart = pFcb->dirIndex * sizeof(FATDirEntry);
if (*pName == L'\\') if(CcMapData (pDirFcb->FileObject, &Offset, sizeof(FATDirEntry),
TRUE, &Context, &Buffer))
{ {
pName ++; memcpy(Buffer, &pFcb->entry, sizeof(FATDirEntry));
} CcSetDirtyPinnedData(Context, NULL);
status = FindFile (DeviceExt, &Fcb, pDirFcb, pName, &Entry, NULL); CcUnpinData(Context);
if (NT_SUCCESS (status))
{
DPRINT ("update entry: %d\n", Entry);
memset (&FileObject, 0, sizeof(FILE_OBJECT));
memset (&Ccb, 0, sizeof(VFATCCB));
FileObject.FsContext2 = &Ccb;
FileObject.FsContext = &pDirFcb->RFCB;
Ccb.pFcb = pDirFcb;
status = VfatWriteFile(DeviceExt, &FileObject, &pFcb->entry,
sizeof(FATDirEntry), Entry * sizeof(FATDirEntry), FALSE);
if (!NT_SUCCESS (status))
DbgPrint ("Failed to open \'%S\'. Status %lx\n", pDirFcb->PathName, status);
} }
else
DPRINT1 ("Failed write to \'%S\'.\n", pDirFcb->PathName);
vfatReleaseFCB(DeviceExt, pDirFcb); vfatReleaseFCB(DeviceExt, pDirFcb);
return status; return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
@ -153,7 +143,6 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
VFATFCB FileFcb; VFATFCB FileFcb;
FATDirEntry FatEntry; FATDirEntry FatEntry;
NTSTATUS status; NTSTATUS status;
FILE_OBJECT FileObject;
FATDirEntry *pEntry; FATDirEntry *pEntry;
slot *pSlots; slot *pSlots;
ULONG LengthRead, Offset; ULONG LengthRead, Offset;
@ -164,8 +153,7 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster; ULONG CurrentCluster;
LARGE_INTEGER SystemTime, LocalTime; LARGE_INTEGER SystemTime, LocalTime;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PVFATFCB pFcb; PVFATFCB pDirFcb;
PVFATCCB pCcb;
PathFileName = pFileObject->FileName.Buffer; PathFileName = pFileObject->FileName.Buffer;
DPRINT ("addEntry: Pathname=%S\n", PathFileName); DPRINT ("addEntry: Pathname=%S\n", PathFileName);
@ -191,16 +179,11 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
DirName[posCar] = 0; DirName[posCar] = 0;
} }
// open parent directory // open parent directory
memset (&FileObject, 0, sizeof (FILE_OBJECT)); pDirFcb = vfatGrabFCBFromTable(DeviceExt, DirName);
status = VfatOpenFile (DeviceExt, &FileObject, DirName); if (pDirFcb == NULL)
if (!NT_SUCCESS(status))
{ {
return Status; return STATUS_UNSUCCESSFUL;
} }
pCcb = FileObject.FsContext2;
assert (pCcb);
pFcb = pCcb->pFcb;
assert (pFcb);
nbSlots = (NameLen + 12) / 13 + 1; //nb of entry needed for long name+normal entry nbSlots = (NameLen + 12) / 13 + 1; //nb of entry needed for long name+normal entry
DPRINT ("NameLen= %d, nbSlots =%d\n", NameLen, nbSlots); DPRINT ("NameLen= %d, nbSlots =%d\n", NameLen, nbSlots);
Buffer = Buffer =
@ -283,7 +266,7 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
{ {
DirName[posCar-1] = '0' + i; DirName[posCar-1] = '0' + i;
pEntry->Filename[posCar - 1] = '0' + i; pEntry->Filename[posCar - 1] = '0' + i;
status = FindFile (DeviceExt, &FileFcb, pFcb, DirName, NULL, NULL); status = FindFile (DeviceExt, &FileFcb, pDirFcb, DirName, NULL, NULL);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
break; break;
} }
@ -303,13 +286,13 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
DirName[posCar - 2] = '0' + i / 10; DirName[posCar - 2] = '0' + i / 10;
pEntry->Filename[posCar - 1] = '0' + i % 10; pEntry->Filename[posCar - 1] = '0' + i % 10;
pEntry->Filename[posCar - 2] = '0' + i / 10; pEntry->Filename[posCar - 2] = '0' + i / 10;
status = FindFile (DeviceExt, &FileFcb, pFcb, DirName, NULL, NULL); status = FindFile (DeviceExt, &FileFcb, pDirFcb, DirName, NULL, NULL);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
break; break;
} }
if (i == 100) //FIXME : what to do after 99 tilde ? if (i == 100) //FIXME : what to do after 99 tilde ?
{ {
VfatCloseFile (DeviceExt, &FileObject); vfatReleaseFCB(DeviceExt, pDirFcb);
ExFreePool (Buffer); ExFreePool (Buffer);
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
@ -390,7 +373,8 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
for (i = 0, status = STATUS_SUCCESS; status == STATUS_SUCCESS; i++) for (i = 0, status = STATUS_SUCCESS; status == STATUS_SUCCESS; i++)
{ {
status = status =
VfatReadFile (DeviceExt, &FileObject, &FatEntry, sizeof (FATDirEntry), VfatReadFile (DeviceExt, pDirFcb->FileObject,
&FatEntry, sizeof (FATDirEntry),
i * sizeof (FATDirEntry), &LengthRead, FALSE); i * sizeof (FATDirEntry), &LengthRead, FALSE);
if (status == STATUS_END_OF_FILE) if (status == STATUS_END_OF_FILE)
break; break;
@ -422,7 +406,7 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
status = NextCluster (DeviceExt, 0, &CurrentCluster, TRUE); status = NextCluster (DeviceExt, 0, &CurrentCluster, TRUE);
if (CurrentCluster == 0xffffffff || !NT_SUCCESS(status)) if (CurrentCluster == 0xffffffff || !NT_SUCCESS(status))
{ {
VfatCloseFile (DeviceExt, &FileObject); vfatReleaseFCB(DeviceExt, pDirFcb);
ExFreePool (Buffer); ExFreePool (Buffer);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
@ -433,7 +417,7 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
// zero the cluster // zero the cluster
Buffer2 = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster); Buffer2 = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
memset (Buffer2, 0, DeviceExt->BytesPerCluster); memset (Buffer2, 0, DeviceExt->BytesPerCluster);
VfatRawWriteCluster (DeviceExt, 0, Buffer2, CurrentCluster); VfatRawWriteCluster (DeviceExt, 0, Buffer2, CurrentCluster, 1);
ExFreePool (Buffer2); ExFreePool (Buffer2);
if (DeviceExt->FatType == FAT32) if (DeviceExt->FatType == FAT32)
{ {
@ -447,21 +431,23 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
{ //use old slots { //use old slots
Offset = (i - nbSlots + 1) * sizeof (FATDirEntry); Offset = (i - nbSlots + 1) * sizeof (FATDirEntry);
status = status =
VfatWriteFile (DeviceExt, &FileObject, Buffer, VfatWriteFile (DeviceExt, pDirFcb->FileObject,
sizeof (FATDirEntry) * nbSlots, Offset, FALSE); Buffer, sizeof (FATDirEntry) * nbSlots,
Offset, FALSE, FALSE);
DPRINT ("VfatWriteFile() returned: %x\n", status); DPRINT ("VfatWriteFile() returned: %x\n", status);
} }
else else
{ //write at end of directory { //write at end of directory
Offset = (i - nbFree) * sizeof (FATDirEntry); Offset = (i - nbFree) * sizeof (FATDirEntry);
status = status =
VfatWriteFile (DeviceExt, &FileObject, Buffer, VfatWriteFile (DeviceExt, pDirFcb->FileObject,
sizeof (FATDirEntry) * (nbSlots + 1), Offset, FALSE); Buffer, sizeof (FATDirEntry) * (nbSlots + 1),
Offset, FALSE, FALSE);
} }
DPRINT ("write entry offset %d status=%x\n", Offset, status); DPRINT ("write entry offset %d status=%x\n", Offset, status);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
VfatCloseFile (DeviceExt, &FileObject); vfatReleaseFCB (DeviceExt, pDirFcb);
if (RequestedOptions & FILE_DIRECTORY_FILE) if (RequestedOptions & FILE_DIRECTORY_FILE)
{ {
// free the reserved cluster // free the reserved cluster
@ -472,7 +458,8 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
} }
// FEXME: check status // FEXME: check status
vfatMakeFCBFromDirEntry (DeviceExt, pFcb, FileName, pEntry, &newFCB); vfatMakeFCBFromDirEntry (DeviceExt, pDirFcb, FileName,
pEntry, Offset / sizeof(FATDirEntry) + nbSlots-1, &newFCB);
vfatAttachFCBToFileObject (DeviceExt, newFCB, pFileObject); vfatAttachFCBToFileObject (DeviceExt, newFCB, pFileObject);
DPRINT ("new : entry=%11.11s\n", newFCB->entry.Filename); DPRINT ("new : entry=%11.11s\n", newFCB->entry.Filename);
@ -484,19 +471,17 @@ addEntry (PDEVICE_EXTENSION DeviceExt,
memcpy (pEntry->Filename, ". ", 11); memcpy (pEntry->Filename, ". ", 11);
status = status =
VfatWriteFile (DeviceExt, pFileObject, pEntry, sizeof (FATDirEntry), VfatWriteFile (DeviceExt, pFileObject, pEntry, sizeof (FATDirEntry),
0L, FALSE); 0L, FALSE, FALSE);
pEntry->FirstCluster = pEntry->FirstCluster = pDirFcb->entry.FirstCluster;
((VFATCCB *) (FileObject.FsContext2))->pFcb->entry.FirstCluster; pEntry->FirstClusterHigh = pDirFcb->entry.FirstClusterHigh;
pEntry->FirstClusterHigh =
((VFATCCB *) (FileObject.FsContext2))->pFcb->entry.FirstClusterHigh;
memcpy (pEntry->Filename, ".. ", 11); memcpy (pEntry->Filename, ".. ", 11);
if (pEntry->FirstCluster == 1 && DeviceExt->FatType != FAT32) if (pEntry->FirstCluster == 1 && DeviceExt->FatType != FAT32)
pEntry->FirstCluster = 0; pEntry->FirstCluster = 0;
status = status =
VfatWriteFile (DeviceExt, pFileObject, pEntry, sizeof (FATDirEntry), VfatWriteFile (DeviceExt, pFileObject, pEntry, sizeof (FATDirEntry),
sizeof (FATDirEntry), FALSE); sizeof (FATDirEntry), FALSE, FALSE);
} }
VfatCloseFile (DeviceExt, &FileObject); vfatReleaseFCB (DeviceExt, pDirFcb);
ExFreePool (Buffer); ExFreePool (Buffer);
DPRINT ("addentry ok\n"); DPRINT ("addentry ok\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -513,8 +498,6 @@ delEntry (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT pFileObject)
NTSTATUS status; NTSTATUS status;
PWSTR pName; PWSTR pName;
ULONG Entry = 0, startEntry, Read, CurrentCluster, NextCluster, i; ULONG Entry = 0, startEntry, Read, CurrentCluster, NextCluster, i;
FILE_OBJECT FileObject;
VFATCCB Ccb;
FATDirEntry DirEntry; FATDirEntry DirEntry;
DPRINT ("delEntry PathFileName \'%S\'\n", pFileObject->FileName.Buffer); DPRINT ("delEntry PathFileName \'%S\'\n", pFileObject->FileName.Buffer);
@ -542,21 +525,15 @@ delEntry (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT pFileObject)
if (NT_SUCCESS(status)) if (NT_SUCCESS(status))
{ {
DPRINT ("delete entry: %d to %d\n", startEntry, Entry); DPRINT ("delete entry: %d to %d\n", startEntry, Entry);
memset (&FileObject, 0, sizeof(FILE_OBJECT));
memset (&Ccb, 0, sizeof(VFATCCB));
FileObject.FsContext2 = &Ccb;
FileObject.FsContext = &pDirFcb->RFCB;
Ccb.pFcb = pDirFcb;
for (i = startEntry; i <= Entry; i++) for (i = startEntry; i <= Entry; i++)
{ {
// FIXME: check status // FIXME: using Cc-functions
VfatReadFile (DeviceExt, &FileObject, &DirEntry, sizeof (FATDirEntry), VfatReadFile (DeviceExt, pDirFcb->FileObject, &DirEntry,
i * sizeof(FATDirEntry), &Read, FALSE); sizeof (FATDirEntry), i * sizeof(FATDirEntry), &Read, FALSE);
DirEntry.Filename[0] = 0xe5; DirEntry.Filename[0] = 0xe5;
// FIXME: check status // FIXME: check status
VfatWriteFile (DeviceExt, &FileObject, &DirEntry, sizeof(FATDirEntry), VfatWriteFile (DeviceExt, pDirFcb->FileObject, &DirEntry,
i * sizeof(FATDirEntry), FALSE); sizeof(FATDirEntry), i * sizeof(FATDirEntry), FALSE, FALSE);
} }
CurrentCluster = vfatDirEntryGetFirstCluster (DeviceExt, &DirEntry); CurrentCluster = vfatDirEntryGetFirstCluster (DeviceExt, &DirEntry);
while (CurrentCluster && CurrentCluster != 0xffffffff) while (CurrentCluster && CurrentCluster != 0xffffffff)