1019111b94c8dabbf32cc1c198868f32ac906bde
[reactos.git] / reactos / 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 NTSTATUS Status = STATUS_SUCCESS;
29
30 DPRINT("VfatCloseFile(DeviceExt %p, FileObject %p)\n",
31 DeviceExt, FileObject);
32
33 /* FIXME : update entry in directory? */
34 pCcb = (PVFATCCB) (FileObject->FsContext2);
35 pFcb = (PVFATFCB) (FileObject->FsContext);
36
37 if (pFcb == NULL)
38 {
39 return STATUS_SUCCESS;
40 }
41
42 if (BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME))
43 {
44 DPRINT("Volume\n");
45 FileObject->FsContext2 = NULL;
46 }
47 else
48 {
49 vfatReleaseFCB(DeviceExt, pFcb);
50 }
51
52 FileObject->FsContext2 = NULL;
53 FileObject->FsContext = NULL;
54 FileObject->SectionObjectPointer = NULL;
55 DeviceExt->OpenHandleCount--;
56
57 if (pCcb)
58 {
59 vfatDestroyCCB(pCcb);
60 }
61
62 #ifdef ENABLE_SWAPOUT
63 if (DeviceExt->OpenHandleCount == 0)
64 {
65 VfatCheckForDismount(DeviceExt, FALSE);
66 }
67 #endif
68
69 return Status;
70 }
71
72 /*
73 * FUNCTION: Closes a file
74 */
75 NTSTATUS
76 VfatClose(
77 PVFAT_IRP_CONTEXT IrpContext)
78 {
79 NTSTATUS Status;
80
81 DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
82
83 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
84 {
85 DPRINT("Closing file system\n");
86 IrpContext->Irp->IoStatus.Information = 0;
87 return STATUS_SUCCESS;
88 }
89 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
90 {
91 return VfatMarkIrpContextForQueue(IrpContext);
92 }
93
94 Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
95 ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
96
97 IrpContext->Irp->IoStatus.Information = 0;
98
99 return Status;
100 }
101
102 /* EOF */