Separated close request

Fixed bugs in create request

svn path=/trunk/; revision=1250
This commit is contained in:
Eric Kohl 2000-07-07 02:14:14 +00:00
parent a20a2dd801
commit 0ea1d03808
3 changed files with 203 additions and 105 deletions

View file

@ -0,0 +1,77 @@
/* $Id: close.c,v 1.1 2000/07/07 02:14:14 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: services/fs/vfat/close.c
* PURPOSE: VFAT Filesystem
* PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#define NDEBUG
#include <debug.h>
#include "vfat.h"
/* FUNCTIONS ****************************************************************/
NTSTATUS FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
/*
* FUNCTION: Closes a file
*/
{
PVFATFCB pFcb;
PVFATCCB pCcb;
KIRQL oldIrql;
DPRINT("FsdCloseFile(DeviceExt %x, FileObject %x)\n",
DeviceExt,FileObject);
//FIXME : update entry in directory ?
pCcb = (PVFATCCB)(FileObject->FsContext2);
DPRINT("pCcb %x\n",pCcb);
if (pCcb == NULL)
{
return(STATUS_SUCCESS);
}
pFcb = pCcb->pFcb;
pFcb->RefCount--;
if(pFcb->RefCount<=0)
{
KeAcquireSpinLock(&DeviceExt->FcbListLock, &oldIrql);
RemoveEntryList(&pFcb->FcbListEntry);
KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
ExFreePool(pFcb);
}
ExFreePool(pCcb);
return STATUS_SUCCESS;
}
NTSTATUS FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Closes a file
*/
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = Stack->FileObject;
PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
NTSTATUS Status;
DPRINT("FsdClose(DeviceObject %x, Irp %x)\n",DeviceObject, Irp);
Status = FsdCloseFile(DeviceExtension,FileObject);
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(Status);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.5 2000/06/29 23:35:50 dwelch Exp $
/* $Id: create.c,v 1.6 2000/07/07 02:14:14 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -348,40 +348,6 @@ NTSTATUS FindFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
}
NTSTATUS FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
/*
* FUNCTION: Closes a file
*/
{
PVFATFCB pFcb;
PVFATCCB pCcb;
KIRQL oldIrql;
DPRINT("FsdCloseFile(DeviceExt %x, FileObject %x)\n",
DeviceExt,FileObject);
//FIXME : update entry in directory ?
pCcb = (PVFATCCB)(FileObject->FsContext2);
DPRINT("pCcb %x\n",pCcb);
if (pCcb == NULL)
{
return(STATUS_SUCCESS);
}
pFcb = pCcb->pFcb;
pFcb->RefCount--;
if(pFcb->RefCount<=0)
{
KeAcquireSpinLock(&DeviceExt->FcbListLock, &oldIrql);
RemoveEntryList(&pFcb->FcbListEntry);
KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
ExFreePool(pFcb);
}
ExFreePool(pCcb);
return STATUS_SUCCESS;
}
NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
PWSTR FileName)
@ -472,6 +438,7 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
KeReleaseSpinLock(&DeviceExt->FcbListLock, oldIrql);
CHECKPOINT;
DPRINT("FileName %S\n", FileName);
string = FileName;
ParentFcb = NULL;
@ -481,7 +448,7 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
next = &string[0];
CHECKPOINT;
while (next!=NULL)
while (TRUE)
{
CHECKPOINT;
*next = '\\';
@ -491,6 +458,13 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
{
*next=0;
}
else
{
/* reached the last path component */
DPRINT("exiting: current '%S'\n",current);
break;
}
DPRINT("current '%S'\n",current);
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
if (Status != STATUS_SUCCESS)
@ -502,7 +476,9 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
ExFreePool(ParentFcb);
if(AbsFileName)
ExFreePool(AbsFileName);
return(Status);
DPRINT("error STATUS_OBJECT_PATH_NOT_FOUND\n");
return STATUS_OBJECT_PATH_NOT_FOUND;
}
Temp = Fcb;
CHECKPOINT;
@ -518,6 +494,39 @@ CHECKPOINT;
CHECKPOINT;
ParentFcb = Temp;
}
/* searching for last path component */
DPRINT("current '%S'\n",current);
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
if (Status != STATUS_SUCCESS)
{
/* file does not exist */
CHECKPOINT;
if (Fcb != NULL)
ExFreePool(Fcb);
if (ParentFcb != NULL)
ExFreePool(ParentFcb);
if(AbsFileName)
ExFreePool(AbsFileName);
return STATUS_OBJECT_NAME_NOT_FOUND;
}
Temp = Fcb;
CHECKPOINT;
if (ParentFcb == NULL)
{
CHECKPOINT;
Fcb = ExAllocatePool(NonPagedPool,sizeof(VFATFCB));
memset(Fcb,0,sizeof(VFATFCB));
Fcb->ObjectName=Fcb->PathName;
}
else
Fcb = ParentFcb;
CHECKPOINT;
ParentFcb = Temp;
CHECKPOINT;
FileObject->FsContext =(PVOID) &ParentFcb->NTRequiredFCB;
newCCB = ExAllocatePool(NonPagedPool,sizeof(VFATCCB));
@ -537,35 +546,17 @@ CHECKPOINT;
ParentFcb->pDevExt=DeviceExt;
DPRINT("file open, fcb=%x\n",ParentFcb);
DPRINT("FileSize %d\n",ParentFcb->entry.FileSize);
if(Fcb) ExFreePool(Fcb);
if(AbsFileName)ExFreePool(AbsFileName);
if(Fcb)
ExFreePool(Fcb);
if(AbsFileName)
ExFreePool(AbsFileName);
CHECKPOINT;
return(STATUS_SUCCESS);
}
NTSTATUS FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Close a file
*/
{
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = Stack->FileObject;
PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
NTSTATUS Status;
DPRINT("FsdClose(DeviceObject %x, Irp %x)\n",DeviceObject, Irp);
Status = FsdCloseFile(DeviceExtension,FileObject);
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(Status);
}
NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
NTSTATUS FsdCreateFile (PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Create or open a file
*/
@ -578,19 +569,6 @@ NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
PVFATCCB pCcb;
PVFATFCB pFcb;
assert(DeviceObject);
assert(Irp);
if (DeviceObject->Size==sizeof(DEVICE_OBJECT))
{
/* DeviceObject represent FileSystem instead of logical volume */
DbgPrint("FsdCreate called with file system\n");
Irp->IoStatus.Status=Status;
Irp->IoStatus.Information=FILE_OPENED;
IoCompleteRequest(Irp,IO_NO_INCREMENT);
return(Status);
}
Stack = IoGetCurrentIrpStackLocation(Irp);
assert(Stack);
RequestedDisposition = ((Stack->Parameters.Create.Options>>24)&0xff);
@ -598,10 +576,18 @@ NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
FileObject = Stack->FileObject;
DeviceExt = DeviceObject->DeviceExtension;
assert(DeviceExt);
ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
CHECKPOINT;
Irp->IoStatus.Information = 0;
if (Status == STATUS_OBJECT_PATH_NOT_FOUND)
{
Irp->IoStatus.Status = Status;
return Status;
}
CHECKPOINT;
if(!NT_SUCCESS(Status))
{
if(RequestedDisposition==FILE_CREATE
@ -646,13 +632,47 @@ CHECKPOINT;
else Irp->IoStatus.Information = FILE_OPENED;
// FIXME : make supersed or overwrite if requested
}
CHECKPOINT;
CHECKPOINT;
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
ExReleaseResourceLite(&DeviceExt->DirResource);
return Status;
}
NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Create or open a file
*/
{
NTSTATUS Status=STATUS_SUCCESS;
PDEVICE_EXTENSION DeviceExt;
assert(DeviceObject);
assert(Irp);
if (DeviceObject->Size==sizeof(DEVICE_OBJECT))
{
/* DeviceObject represent FileSystem instead of logical volume */
DbgPrint("FsdCreate called with file system\n");
Irp->IoStatus.Status=Status;
Irp->IoStatus.Information=FILE_OPENED;
IoCompleteRequest(Irp,IO_NO_INCREMENT);
return(Status);
}
DeviceExt = DeviceObject->DeviceExtension;
assert(DeviceExt);
ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
Status = FsdCreateFile (DeviceObject, Irp);
ExReleaseResourceLite(&DeviceExt->DirResource);
Irp->IoStatus.Status = Status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}
/* EOF */

View file

@ -1,9 +1,10 @@
# $Id: makefile,v 1.16 2000/06/29 23:35:51 dwelch Exp $
# $Id: makefile,v 1.17 2000/07/07 02:14:14 ekohl Exp $
#
#
TARGET=vfatfs
OBJECTS = blockdev.o dir.o dirwr.o iface.o string.o fat.o rw.o finfo.o volume.o create.o $(TARGET).coff
OBJECTS = blockdev.o close.o create.o dir.o dirwr.o iface.o string.o fat.o \
rw.o finfo.o volume.o $(TARGET).coff
LIBS = ../../../ntoskrnl/ntoskrnl.a
BASE_CFLAGS = -I. -I../../../include