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 CcRosReleaseFileCache (FileObject);
53 }
54
55 pFcb->OpenHandleCount--;
56 IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess);
57 }
58 return STATUS_SUCCESS;
59 }
60
61 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
62 /*
63 * FUNCTION: Cleans up after a file has been closed.
64 */
65 {
66 NTSTATUS Status;
67
68 DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
69
70 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
71 {
72 Status = STATUS_SUCCESS;
73 goto ByeBye;
74 }
75
76 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
77 (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
78 {
79 return VfatQueueRequest (IrpContext);
80 }
81
82 Status = VfatCleanupFile(IrpContext);
83
84 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
85
86 ByeBye:
87 IrpContext->Irp->IoStatus.Status = Status;
88 IrpContext->Irp->IoStatus.Information = 0;
89
90 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
91 VfatFreeIrpContext(IrpContext);
92 return (Status);
93 }
94
95 /* EOF */