[FASTFAT]
[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 (pFcb->Flags & FCB_IS_VOLUME)
43 {
44 DPRINT("Volume\n");
45 FileObject->FsContext2 = NULL;
46 }
47 else
48 {
49 if (FileObject->DeletePending)
50 {
51 if (pFcb->Flags & FCB_DELETE_PENDING)
52 {
53 VfatDelEntry(DeviceExt, pFcb, NULL);
54
55 FsRtlNotifyFullReportChange(DeviceExt->NotifySync,
56 &(DeviceExt->NotifyList),
57 (PSTRING)&pFcb->PathNameU,
58 pFcb->PathNameU.Length - pFcb->LongNameU.Length,
59 NULL,
60 NULL,
61 ((*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) ?
62 FILE_NOTIFY_CHANGE_DIR_NAME : FILE_NOTIFY_CHANGE_FILE_NAME),
63 FILE_ACTION_REMOVED,
64 NULL);
65 }
66 else
67 {
68 Status = STATUS_DELETE_PENDING;
69 }
70 }
71
72 vfatReleaseFCB(DeviceExt, pFcb);
73 }
74
75 FileObject->FsContext2 = NULL;
76 FileObject->FsContext = NULL;
77 FileObject->SectionObjectPointer = NULL;
78 DeviceExt->OpenHandleCount--;
79
80 if (pCcb)
81 {
82 vfatDestroyCCB(pCcb);
83 }
84
85 if (DeviceExt->OpenHandleCount == 0)
86 {
87 VfatCheckForDismount(DeviceExt, FALSE);
88 }
89
90 return Status;
91 }
92
93 /*
94 * FUNCTION: Closes a file
95 */
96 NTSTATUS
97 VfatClose(
98 PVFAT_IRP_CONTEXT IrpContext)
99 {
100 NTSTATUS Status;
101
102 DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
103
104 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
105 {
106 DPRINT("Closing file system\n");
107 Status = STATUS_SUCCESS;
108 goto ByeBye;
109 }
110 #if 0
111 /* There occurs a dead look at the call to CcRosDeleteFileCache/ObDereferenceObject/VfatClose
112 in CmLazyCloseThreadMain if VfatClose is execute asynchronous in a worker thread. */
113 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
114 #else
115 if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE))
116 #endif
117 {
118 return VfatQueueRequest(IrpContext);
119 }
120
121 Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
122 ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
123
124 ByeBye:
125 IrpContext->Irp->IoStatus.Status = Status;
126 IrpContext->Irp->IoStatus.Information = 0;
127 IoCompleteRequest(IrpContext->Irp, IO_NO_INCREMENT);
128 VfatFreeIrpContext(IrpContext);
129
130 return Status;
131 }
132
133 /* EOF */