Based on a patch by Herve Poussineau <poussine@freesurf.fr>:
[reactos.git] / reactos / drivers / fs / vfat / cleanup.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: drivers/fs/vfat/cleanup.c
6 * PURPOSE: VFAT Filesystem
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
8 * Hartmut Birr
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #define NDEBUG
14 #include "vfat.h"
15
16 /* FUNCTIONS ****************************************************************/
17
18 static NTSTATUS
19 VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
20 /*
21 * FUNCTION: Cleans up after a file has been closed.
22 */
23 {
24 PVFATFCB pFcb;
25 PFILE_OBJECT FileObject = IrpContext->FileObject;
26
27 DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
28 IrpContext->DeviceExt, FileObject);
29
30 /* FIXME: handle file/directory deletion here */
31 pFcb = (PVFATFCB) FileObject->FsContext;
32 if (pFcb)
33 {
34 if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) &&
35 FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
36 {
37 /* remove all locks this process have on this file */
38 FsRtlFastUnlockAll(&pFcb->FileLock,
39 FileObject,
40 IoGetRequestorProcess(IrpContext->Irp),
41 NULL);
42 }
43
44 if (pFcb->Flags & FCB_IS_DIRTY)
45 {
46 VfatUpdateEntry (pFcb);
47 }
48
49 /* Uninitialize file cache if initialized for this file object. */
50 if (FileObject->PrivateCacheMap)
51 {
52 #ifdef USE_ROS_CC_AND_FS
53 CcRosReleaseFileCache (FileObject);
54 #else
55 CcUninitializeCacheMap (FileObject, NULL, NULL);
56 #endif
57 }
58
59 pFcb->OpenHandleCount--;
60 IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess);
61 }
62 return STATUS_SUCCESS;
63 }
64
65 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
66 /*
67 * FUNCTION: Cleans up after a file has been closed.
68 */
69 {
70 NTSTATUS Status;
71
72 DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
73
74 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
75 {
76 Status = STATUS_SUCCESS;
77 goto ByeBye;
78 }
79
80 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
81 (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
82 {
83 return VfatQueueRequest (IrpContext);
84 }
85
86 Status = VfatCleanupFile(IrpContext);
87
88 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
89
90 ByeBye:
91 IrpContext->Irp->IoStatus.Status = Status;
92 IrpContext->Irp->IoStatus.Information = 0;
93
94 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
95 VfatFreeIrpContext(IrpContext);
96 return (Status);
97 }
98
99 /* EOF */