[NTFS] - In the NtfsAddFilenameToDirectory() function, rename DirectoryContext parame...
[reactos.git] / drivers / filesystems / ntfs / close.c
index 6213455..008f453 100644 (file)
@@ -59,6 +59,7 @@ NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
     FileObject->FsContext2 = NULL;
     FileObject->FsContext = NULL;
     FileObject->SectionObjectPointer = NULL;
+    DeviceExt->OpenHandleCount--;
 
     if (FileObject->FileName.Buffer)
     {
@@ -79,35 +80,43 @@ NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
 }
 
 
-NTSTATUS NTAPI
-NtfsFsdClose(PDEVICE_OBJECT DeviceObject,
-             PIRP Irp)
+NTSTATUS
+NtfsClose(PNTFS_IRP_CONTEXT IrpContext)
 {
     PDEVICE_EXTENSION DeviceExtension;
-    PIO_STACK_LOCATION Stack;
     PFILE_OBJECT FileObject;
     NTSTATUS Status;
+    PDEVICE_OBJECT DeviceObject;
 
     DPRINT("NtfsClose() called\n");
 
+    DeviceObject = IrpContext->DeviceObject;
     if (DeviceObject == NtfsGlobalData->DeviceObject)
     {
         DPRINT("Closing file system\n");
-        Status = STATUS_SUCCESS;
-        goto ByeBye;
+        IrpContext->Irp->IoStatus.Information = 0;
+        return STATUS_SUCCESS;
     }
 
-    Stack = IoGetCurrentIrpStackLocation(Irp);
-    FileObject = Stack->FileObject;
+    FileObject = IrpContext->FileObject;
     DeviceExtension = DeviceObject->DeviceExtension;
 
-    Status = NtfsCloseFile(DeviceExtension,FileObject);
+    if (!ExAcquireResourceExclusiveLite(&DeviceExtension->DirResource,
+                                        BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
+    {
+        return NtfsMarkIrpContextForQueue(IrpContext);
+    }
+
+    Status = NtfsCloseFile(DeviceExtension, FileObject);
+
+    ExReleaseResourceLite(&DeviceExtension->DirResource);
 
-ByeBye:
-    Irp->IoStatus.Status = Status;
-    Irp->IoStatus.Information = 0;
+    if (Status == STATUS_PENDING)
+    {
+        return NtfsMarkIrpContextForQueue(IrpContext);
+    }
 
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    IrpContext->Irp->IoStatus.Information = 0;
     return Status;
 }