Revert my last changes.
[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 IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess);
79 }
80 return STATUS_SUCCESS;
81 }
82
83 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
84 /*
85 * FUNCTION: Cleans up after a file has been closed.
86 */
87 {
88 NTSTATUS Status;
89
90 DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
91
92 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
93 {
94 Status = STATUS_SUCCESS;
95 goto ByeBye;
96 }
97
98 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
99 (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
100 {
101 return VfatQueueRequest (IrpContext);
102 }
103
104 Status = VfatCleanupFile(IrpContext);
105
106 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
107
108 ByeBye:
109 IrpContext->Irp->IoStatus.Status = Status;
110 IrpContext->Irp->IoStatus.Information = 0;
111
112 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
113 VfatFreeIrpContext(IrpContext);
114 return (Status);
115 }
116
117 /* EOF */