6573b98ec5668ce45ea55a37f72e44d935fcaa54
[reactos.git] / reactos / drivers / fs / vfat / cleanup.c
1 /* $Id: cleanup.c,v 1.14 2003/10/11 17:51:56 hbirr Exp $
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 #include <ddk/ntddk.h>
14
15 #define NDEBUG
16 #include <debug.h>
17
18 #include "vfat.h"
19
20 /* FUNCTIONS ****************************************************************/
21
22 static NTSTATUS
23 VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
24 /*
25 * FUNCTION: Cleans up after a file has been closed.
26 */
27 {
28 PVFATFCB pFcb;
29 PFILE_OBJECT FileObject = IrpContext->FileObject;
30
31 DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
32 IrpContext->DeviceExt, FileObject);
33
34 /* FIXME: handle file/directory deletion here */
35 pFcb = (PVFATFCB) FileObject->FsContext;
36 if (pFcb)
37 {
38 if (!(pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY) &&
39 FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
40 {
41 /* remove all locks this process have on this file */
42 FsRtlFastUnlockAll(&pFcb->FileLock,
43 FileObject,
44 IoGetRequestorProcess(IrpContext->Irp),
45 NULL);
46 }
47
48 if (pFcb->Flags & FCB_IS_DIRTY)
49 {
50 VfatUpdateEntry (pFcb);
51 }
52
53 /* Uninitialize file cache if initialized for this file object. */
54 if (FileObject->PrivateCacheMap)
55 {
56 CcRosReleaseFileCache (FileObject);
57 }
58 }
59 return STATUS_SUCCESS;
60 }
61
62 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
63 /*
64 * FUNCTION: Cleans up after a file has been closed.
65 */
66 {
67 NTSTATUS Status;
68
69 DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
70
71 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
72 {
73 Status = STATUS_SUCCESS;
74 goto ByeBye;
75 }
76
77 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
78 (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
79 {
80 return VfatQueueRequest (IrpContext);
81 }
82
83 Status = VfatCleanupFile(IrpContext);
84
85 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
86
87 ByeBye:
88 IrpContext->Irp->IoStatus.Status = Status;
89 IrpContext->Irp->IoStatus.Information = 0;
90
91 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
92 VfatFreeIrpContext(IrpContext);
93 return (Status);
94 }
95
96 /* EOF */