Sync with trunk r62754.
[reactos.git] / drivers / filesystems / fastfat / close.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/fs/vfat/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 (pFcb->Flags & FCB_IS_VOLUME)
43 {
44 DPRINT1("Volume\n");
45 pFcb->RefCount--;
46 FileObject->FsContext2 = NULL;
47 }
48 else
49 {
50 if (FileObject->DeletePending)
51 {
52 if (pFcb->Flags & FCB_DELETE_PENDING)
53 {
54 VfatDelEntry(DeviceExt, pFcb);
55 }
56 else
57 {
58 Status = STATUS_DELETE_PENDING;
59 }
60 }
61
62 vfatReleaseFCB(DeviceExt, pFcb);
63 }
64
65 FileObject->FsContext2 = NULL;
66 FileObject->FsContext = NULL;
67 FileObject->SectionObjectPointer = NULL;
68
69 if (pCcb)
70 {
71 vfatDestroyCCB(pCcb);
72 }
73
74 return Status;
75 }
76
77 /*
78 * FUNCTION: Closes a file
79 */
80 NTSTATUS
81 VfatClose(
82 PVFAT_IRP_CONTEXT IrpContext)
83 {
84 NTSTATUS Status;
85
86 DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
87
88 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
89 {
90 DPRINT("Closing file system\n");
91 Status = STATUS_SUCCESS;
92 goto ByeBye;
93 }
94 #if 0
95 /* There occurs a dead look at the call to CcRosDeleteFileCache/ObDereferenceObject/VfatClose
96 in CmLazyCloseThreadMain if VfatClose is execute asynchronous in a worker thread. */
97 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
98 #else
99 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE))
100 #endif
101 {
102 return VfatQueueRequest(IrpContext);
103 }
104
105 Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
106 ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
107
108 ByeBye:
109 IrpContext->Irp->IoStatus.Status = Status;
110 IrpContext->Irp->IoStatus.Information = 0;
111 IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
112 VfatFreeIrpContext(IrpContext);
113
114 return Status;
115 }
116
117 /* EOF */