- Update to r53061
[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 #define NDEBUG
12 #include "vfat.h"
13
14 /* FUNCTIONS ****************************************************************/
15
16 NTSTATUS
17 VfatCloseFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
18 /*
19 * FUNCTION: Closes a file
20 */
21 {
22 PVFATFCB pFcb;
23 PVFATCCB pCcb;
24 NTSTATUS Status = STATUS_SUCCESS;
25
26 DPRINT ("VfatCloseFile(DeviceExt %p, FileObject %p)\n",
27 DeviceExt, FileObject);
28
29 /* FIXME : update entry in directory? */
30 pCcb = (PVFATCCB) (FileObject->FsContext2);
31 pFcb = (PVFATFCB) (FileObject->FsContext);
32
33 if (pFcb == NULL)
34 {
35 return STATUS_SUCCESS;
36 }
37
38 if (pFcb->Flags & FCB_IS_VOLUME)
39 {
40 DPRINT1("Volume\n");
41 pFcb->RefCount--;
42 FileObject->FsContext2 = NULL;
43 }
44 else
45 {
46 if (FileObject->DeletePending)
47 {
48 if (pFcb->Flags & FCB_DELETE_PENDING)
49 {
50 VfatDelEntry (DeviceExt, pFcb);
51 }
52 else
53 {
54 Status = STATUS_DELETE_PENDING;
55 }
56 }
57 vfatReleaseFCB (DeviceExt, pFcb);
58 }
59
60 FileObject->FsContext2 = NULL;
61 FileObject->FsContext = NULL;
62 FileObject->SectionObjectPointer = NULL;
63
64 if (pCcb)
65 {
66 vfatDestroyCCB(pCcb);
67 }
68
69 return Status;
70 }
71
72 NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext)
73 /*
74 * FUNCTION: Closes a file
75 */
76 {
77 NTSTATUS Status;
78
79 DPRINT ("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
80
81 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
82 {
83 DPRINT("Closing file system\n");
84 Status = STATUS_SUCCESS;
85 goto ByeBye;
86 }
87 #if 0
88 /* There occurs a dead look at the call to CcRosDeleteFileCache/ObDereferenceObject/VfatClose
89 in CmLazyCloseThreadMain if VfatClose is execute asynchronous in a worker thread. */
90 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
91 #else
92 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, TRUE))
93 #endif
94 {
95 return VfatQueueRequest (IrpContext);
96 }
97
98 Status = VfatCloseFile (IrpContext->DeviceExt, IrpContext->FileObject);
99 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
100
101 ByeBye:
102 IrpContext->Irp->IoStatus.Status = Status;
103 IrpContext->Irp->IoStatus.Information = 0;
104 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
105 VfatFreeIrpContext(IrpContext);
106
107 return (Status);
108 }
109
110 /* EOF */