[FASTFAT] Uninit directory cache on last handle close.
[reactos.git] / drivers / filesystems / fastfat / close.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/filesystems/fastfat/close.c
5 * PURPOSE: VFAT Filesystem
6 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include "vfat.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS ****************************************************************/
17
18 /*
19 * FUNCTION: Closes a file
20 */
21 NTSTATUS
22 VfatCloseFile(
23 PDEVICE_EXTENSION DeviceExt,
24 PFILE_OBJECT FileObject)
25 {
26 PVFATFCB pFcb;
27 PVFATCCB pCcb;
28 BOOLEAN IsVolume;
29 NTSTATUS Status = STATUS_SUCCESS;
30
31 DPRINT("VfatCloseFile(DeviceExt %p, FileObject %p)\n",
32 DeviceExt, FileObject);
33
34 /* FIXME : update entry in directory? */
35 pCcb = (PVFATCCB) (FileObject->FsContext2);
36 pFcb = (PVFATFCB) (FileObject->FsContext);
37
38 if (pFcb == NULL)
39 {
40 return STATUS_SUCCESS;
41 }
42
43 IsVolume = BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME);
44 if (IsVolume)
45 {
46 DPRINT("Volume\n");
47 FileObject->FsContext2 = NULL;
48 }
49 else
50 {
51 if (pFcb->OpenHandleCount == 0 && BooleanFlagOn(pFcb->Flags, FCB_CACHE_INITIALIZED))
52 {
53 PFILE_OBJECT tmpFileObject;
54 tmpFileObject = pFcb->FileObject;
55 if (tmpFileObject != NULL)
56 {
57 pFcb->FileObject = NULL;
58 CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
59 ClearFlag(pFcb->Flags, FCB_CACHE_INITIALIZED);
60 ObDereferenceObject(tmpFileObject);
61 }
62 }
63
64 #ifdef KDBG
65 pFcb->Flags |= FCB_CLOSED;
66 #endif
67 vfatReleaseFCB(DeviceExt, pFcb);
68 }
69
70 FileObject->FsContext2 = NULL;
71 FileObject->FsContext = NULL;
72 FileObject->SectionObjectPointer = NULL;
73
74 if (pCcb)
75 {
76 vfatDestroyCCB(pCcb);
77 }
78
79 #ifdef ENABLE_SWAPOUT
80 if (IsVolume && DeviceExt->OpenHandleCount == 0)
81 {
82 VfatCheckForDismount(DeviceExt, FALSE);
83 }
84 #endif
85
86 return Status;
87 }
88
89 /*
90 * FUNCTION: Closes a file
91 */
92 NTSTATUS
93 VfatClose(
94 PVFAT_IRP_CONTEXT IrpContext)
95 {
96 NTSTATUS Status;
97
98 DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
99
100 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
101 {
102 DPRINT("Closing file system\n");
103 IrpContext->Irp->IoStatus.Information = 0;
104 return STATUS_SUCCESS;
105 }
106 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
107 {
108 return VfatMarkIrpContextForQueue(IrpContext);
109 }
110
111 Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
112 ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
113
114 IrpContext->Irp->IoStatus.Information = 0;
115
116 return Status;
117 }
118
119 /* EOF */