7fae9a7db9011da05856c46241eaebf28be3eb02
[reactos.git] / drivers / fs / vfat / close.c
1 /* $Id$
2  *
3  * COPYRIGHT:        See COPYING in the top level directory
4  * PROJECT:          ReactOS kernel
5  * FILE:             services/fs/vfat/close.c
6  * PURPOSE:          VFAT Filesystem
7  * PROGRAMMER:       Jason Filby (jasonfilby@yahoo.com)
8  */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 #include "vfat.h"
18
19 /* FUNCTIONS ****************************************************************/
20
21 NTSTATUS
22 VfatCloseFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
23 /*
24  * FUNCTION: Closes a file
25  */
26 {
27   PVFATFCB pFcb;
28   PVFATCCB pCcb;
29   NTSTATUS Status = STATUS_SUCCESS;
30
31   DPRINT ("VfatCloseFile(DeviceExt %x, FileObject %x)\n",
32           DeviceExt, FileObject);
33
34   /* FIXME : update entry in directory? */
35   pCcb = (PVFATCCB) (FileObject->FsContext2);
36
37   DPRINT ("pCcb %x\n", pCcb);
38   if (pCcb == NULL)
39   {
40     return  STATUS_SUCCESS;
41   }
42   pFcb = pCcb->pFcb;
43   if (pFcb->Flags & FCB_IS_VOLUME)
44   {
45      DPRINT1("Volume\n");
46      pFcb->RefCount--;
47      FileObject->FsContext2 = NULL;
48   }
49   else if (FileObject->FileName.Buffer)
50   {
51     // This a FO, that was created outside from FSD.
52     // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
53     // This FO's haven't a FileName.
54     if (FileObject->DeletePending)
55     {
56       if (pFcb->Flags & FCB_DELETE_PENDING)
57       {
58         delEntry (DeviceExt, FileObject);
59       }
60       else
61        Status = STATUS_DELETE_PENDING;
62     }
63     FileObject->FsContext2 = NULL;
64     vfatReleaseFCB (DeviceExt, pFcb);
65   }
66   else
67     FileObject->FsContext2 = NULL;
68
69   vfatDestroyCCB(pCcb);
70   
71   return  Status;
72 }
73
74 NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext)
75 /*
76  * FUNCTION: Closes a file
77  */
78 {
79   NTSTATUS Status;
80
81   DPRINT ("VfatClose(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
82
83   if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
84     {
85       DPRINT("Closing file system\n");
86       Status = STATUS_SUCCESS;
87       goto ByeBye;
88     }
89 #if 0
90   /* There occurs a dead look at the call to CcRosDeleteFileCache/ObDereferenceObject/VfatClose 
91      in CmLazyCloseThreadMain if VfatClose is execute asynchronous in a worker thread. */
92   if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
93 #else
94   if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, TRUE))
95 #endif
96   {
97      return VfatQueueRequest (IrpContext);
98   }
99
100   Status = VfatCloseFile (IrpContext->DeviceExt, IrpContext->FileObject);
101   ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
102
103 ByeBye:
104   IrpContext->Irp->IoStatus.Status = Status;
105   IrpContext->Irp->IoStatus.Information = 0;
106   IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
107   VfatFreeIrpContext(IrpContext);
108
109   return (Status);
110 }
111
112 /* EOF */