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)
9 /* INCLUDES *****************************************************************/
14 /* FUNCTIONS ****************************************************************/
17 * FUNCTION: Cleans up after a file has been closed.
20 VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext
)
23 PFILE_OBJECT FileObject
= IrpContext
->FileObject
;
25 DPRINT("VfatCleanupFile(DeviceExt %p, FileObject %p)\n",
26 IrpContext
->DeviceExt
, FileObject
);
28 /* FIXME: handle file/directory deletion here */
29 pFcb
= (PVFATFCB
) FileObject
->FsContext
;
31 return STATUS_SUCCESS
;
33 if (pFcb
->Flags
& FCB_IS_VOLUME
)
35 pFcb
->OpenHandleCount
--;
37 if (pFcb
->OpenHandleCount
!= 0)
39 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
44 if(!ExAcquireResourceExclusiveLite (&pFcb
->MainResource
,
45 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
47 return STATUS_PENDING
;
49 if(!ExAcquireResourceExclusiveLite (&pFcb
->PagingIoResource
,
50 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
52 ExReleaseResourceLite (&pFcb
->MainResource
);
53 return STATUS_PENDING
;
56 pFcb
->OpenHandleCount
--;
58 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
59 FsRtlAreThereCurrentFileLocks(&pFcb
->FileLock
))
61 /* remove all locks this process have on this file */
62 FsRtlFastUnlockAll(&pFcb
->FileLock
,
64 IoGetRequestorProcess(IrpContext
->Irp
),
68 if (pFcb
->Flags
& FCB_IS_DIRTY
)
70 VfatUpdateEntry (pFcb
);
73 if (pFcb
->Flags
& FCB_DELETE_PENDING
&&
74 pFcb
->OpenHandleCount
== 0)
76 PFILE_OBJECT tmpFileObject
;
77 tmpFileObject
= pFcb
->FileObject
;
78 if (tmpFileObject
!= NULL
)
80 pFcb
->FileObject
= NULL
;
81 CcUninitializeCacheMap(tmpFileObject
, NULL
, NULL
);
82 ObDereferenceObject(tmpFileObject
);
85 CcPurgeCacheSection(FileObject
->SectionObjectPointer
, NULL
, 0, FALSE
);
88 /* Uninitialize the cache (should be done even if caching was never initialized) */
89 CcUninitializeCacheMap(FileObject
, &pFcb
->RFCB
.FileSize
, NULL
);
91 if (pFcb
->OpenHandleCount
!= 0)
93 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
96 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
98 ExReleaseResourceLite (&pFcb
->PagingIoResource
);
99 ExReleaseResourceLite (&pFcb
->MainResource
);
102 return STATUS_SUCCESS
;
106 * FUNCTION: Cleans up after a file has been closed.
108 NTSTATUS
VfatCleanup(PVFAT_IRP_CONTEXT IrpContext
)
112 DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext
->DeviceObject
, IrpContext
->Irp
);
114 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
116 Status
= STATUS_SUCCESS
;
120 if (!ExAcquireResourceExclusiveLite (&IrpContext
->DeviceExt
->DirResource
,
121 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
123 return VfatQueueRequest (IrpContext
);
126 Status
= VfatCleanupFile(IrpContext
);
128 ExReleaseResourceLite (&IrpContext
->DeviceExt
->DirResource
);
130 if (Status
== STATUS_PENDING
)
132 return VfatQueueRequest(IrpContext
);
136 IrpContext
->Irp
->IoStatus
.Status
= Status
;
137 IrpContext
->Irp
->IoStatus
.Information
= 0;
139 IoCompleteRequest (IrpContext
->Irp
, IO_NO_INCREMENT
);
140 VfatFreeIrpContext(IrpContext
);