992ccac4c2c0f86a2a38c454702b4cbf17665c8d
[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 #ifdef KDBG
52 pFcb->Flags |= FCB_CLOSED;
53 #endif
54 vfatReleaseFCB(DeviceExt, pFcb);
55 }
56
57 FileObject->FsContext2 = NULL;
58 FileObject->FsContext = NULL;
59 FileObject->SectionObjectPointer = NULL;
60
61 if (pCcb)
62 {
63 vfatDestroyCCB(pCcb);
64 }
65
66 #ifdef ENABLE_SWAPOUT
67 if (IsVolume && DeviceExt->OpenHandleCount == 0)
68 {
69 VfatCheckForDismount(DeviceExt, FALSE);
70 }
71 #endif
72
73 return Status;
74 }
75
76 /*
77 * FUNCTION: Closes a file
78 */
79 NTSTATUS
80 VfatClose(
81 PVFAT_IRP_CONTEXT IrpContext)
82 {
83 NTSTATUS Status;
84
85 DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
86
87 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
88 {
89 DPRINT("Closing file system\n");
90 IrpContext->Irp->IoStatus.Information = 0;
91 return STATUS_SUCCESS;
92 }
93 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
94 {
95 return VfatMarkIrpContextForQueue(IrpContext);
96 }
97
98 Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
99 ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
100
101 IrpContext->Irp->IoStatus.Information = 0;
102
103 return Status;
104 }
105
106 /* EOF */