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 *****************************************************************/
16 /* FUNCTIONS ****************************************************************/
19 * FUNCTION: Cleans up after a file has been closed.
24 PVFAT_IRP_CONTEXT IrpContext
)
27 PFILE_OBJECT FileObject
= IrpContext
->FileObject
;
29 DPRINT("VfatCleanupFile(DeviceExt %p, FileObject %p)\n",
30 IrpContext
->DeviceExt
, FileObject
);
32 /* FIXME: handle file/directory deletion here */
33 pFcb
= (PVFATFCB
)FileObject
->FsContext
;
35 return STATUS_SUCCESS
;
37 if (pFcb
->Flags
& FCB_IS_VOLUME
)
39 pFcb
->OpenHandleCount
--;
41 if (pFcb
->OpenHandleCount
!= 0)
43 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
48 if(!ExAcquireResourceExclusiveLite(&pFcb
->MainResource
,
49 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
51 return STATUS_PENDING
;
53 if(!ExAcquireResourceExclusiveLite(&pFcb
->PagingIoResource
,
54 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
56 ExReleaseResourceLite(&pFcb
->MainResource
);
57 return STATUS_PENDING
;
60 /* Notify about the cleanup */
61 FsRtlNotifyCleanup(IrpContext
->DeviceExt
->NotifySync
,
62 &(IrpContext
->DeviceExt
->NotifyList
),
63 FileObject
->FsContext2
);
65 pFcb
->OpenHandleCount
--;
67 if (!(*pFcb
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
68 FsRtlAreThereCurrentFileLocks(&pFcb
->FileLock
))
70 /* remove all locks this process have on this file */
71 FsRtlFastUnlockAll(&pFcb
->FileLock
,
73 IoGetRequestorProcess(IrpContext
->Irp
),
77 if (pFcb
->Flags
& FCB_IS_DIRTY
)
79 VfatUpdateEntry (pFcb
);
82 if (pFcb
->Flags
& FCB_DELETE_PENDING
&&
83 pFcb
->OpenHandleCount
== 0)
85 PFILE_OBJECT tmpFileObject
;
86 tmpFileObject
= pFcb
->FileObject
;
87 if (tmpFileObject
!= NULL
)
89 pFcb
->FileObject
= NULL
;
90 CcUninitializeCacheMap(tmpFileObject
, NULL
, NULL
);
91 ObDereferenceObject(tmpFileObject
);
94 CcPurgeCacheSection(FileObject
->SectionObjectPointer
, NULL
, 0, FALSE
);
97 /* Uninitialize the cache (should be done even if caching was never initialized) */
98 CcUninitializeCacheMap(FileObject
, &pFcb
->RFCB
.FileSize
, NULL
);
100 if (pFcb
->OpenHandleCount
!= 0)
102 IoRemoveShareAccess(FileObject
, &pFcb
->FCBShareAccess
);
105 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
107 ExReleaseResourceLite(&pFcb
->PagingIoResource
);
108 ExReleaseResourceLite(&pFcb
->MainResource
);
111 return STATUS_SUCCESS
;
115 * FUNCTION: Cleans up after a file has been closed.
119 PVFAT_IRP_CONTEXT IrpContext
)
123 DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext
->DeviceObject
, IrpContext
->Irp
);
125 if (IrpContext
->DeviceObject
== VfatGlobalData
->DeviceObject
)
127 Status
= STATUS_SUCCESS
;
131 if (!ExAcquireResourceExclusiveLite(&IrpContext
->DeviceExt
->DirResource
,
132 (BOOLEAN
)(IrpContext
->Flags
& IRPCONTEXT_CANWAIT
)))
134 return VfatQueueRequest(IrpContext
);
137 Status
= VfatCleanupFile(IrpContext
);
139 ExReleaseResourceLite(&IrpContext
->DeviceExt
->DirResource
);
141 if (Status
== STATUS_PENDING
)
143 return VfatQueueRequest(IrpContext
);
147 IrpContext
->Irp
->IoStatus
.Status
= Status
;
148 IrpContext
->Irp
->IoStatus
.Information
= 0;
150 IoCompleteRequest(IrpContext
->Irp
, IO_NO_INCREMENT
);
151 VfatFreeIrpContext(IrpContext
);