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