migrate substitution keywords to SVN
[reactos.git] / reactos / drivers / fs / vfat / close.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: drivers/fs/vfat/close.c
6 * PURPOSE: VFAT Filesystem
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
8 * Hartmut Birr
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14
15 #define NDEBUG
16 #include <debug.h>
17
18 #include "vfat.h"
19
20 /* FUNCTIONS ****************************************************************/
21
22 NTSTATUS
23 VfatCloseFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
24 /*
25 * FUNCTION: Closes a file
26 */
27 {
28 PVFATFCB pFcb;
29 PVFATCCB pCcb;
30 NTSTATUS Status = STATUS_SUCCESS;
31
32 DPRINT ("VfatCloseFile(DeviceExt %x, FileObject %x)\n",
33 DeviceExt, FileObject);
34
35 /* FIXME : update entry in directory? */
36 pCcb = (PVFATCCB) (FileObject->FsContext2);
37 pFcb = (PVFATFCB) (FileObject->FsContext);
38
39 if (pFcb == NULL)
40 {
41 return STATUS_SUCCESS;
42 }
43
44 if (pFcb->Flags & FCB_IS_VOLUME)
45 {
46 DPRINT1("Volume\n");
47 pFcb->RefCount--;
48 FileObject->FsContext2 = NULL;
49 }
50 else if (FileObject->FileName.Buffer)
51 {
52 // This a FO, that was created outside from FSD.
53 // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
54 // This FO's haven't a FileName.
55 if (FileObject->DeletePending)
56 {
57 if (pFcb->Flags & FCB_DELETE_PENDING)
58 {
59 VfatDelEntry (DeviceExt, pFcb);
60 }
61 else
62 {
63 Status = STATUS_DELETE_PENDING;
64 }
65 }
66 vfatReleaseFCB (DeviceExt, pFcb);
67 }
68
69 FileObject->FsContext2 = NULL;
70 FileObject->FsContext = NULL;
71 FileObject->SectionObjectPointer = NULL;
72
73 if (pCcb)
74 {
75 vfatDestroyCCB(pCcb);
76 }
77
78 return Status;
79 }
80
81 NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext)
82 /*
83 * FUNCTION: Closes a file
84 */
85 {
86 NTSTATUS Status;
87
88 DPRINT ("VfatClose(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
89
90 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
91 {
92 DPRINT("Closing file system\n");
93 Status = STATUS_SUCCESS;
94 goto ByeBye;
95 }
96 #if 0
97 /* There occurs a dead look at the call to CcRosDeleteFileCache/ObDereferenceObject/VfatClose
98 in CmLazyCloseThreadMain if VfatClose is execute asynchronous in a worker thread. */
99 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
100 #else
101 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, TRUE))
102 #endif
103 {
104 return VfatQueueRequest (IrpContext);
105 }
106
107 Status = VfatCloseFile (IrpContext->DeviceExt, IrpContext->FileObject);
108 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
109
110 ByeBye:
111 IrpContext->Irp->IoStatus.Status = Status;
112 IrpContext->Irp->IoStatus.Information = 0;
113 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
114 VfatFreeIrpContext(IrpContext);
115
116 return (Status);
117 }
118
119 /* EOF */