3 * Copyright (C) 2016 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/cleanup.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Pierre Schweitzer (pierre@reactos.org)
27 /* INCLUDES *****************************************************************/
34 /* FUNCTIONS ****************************************************************/
37 * FUNCTION: Cleans up a file
40 NtfsCleanupFile(PDEVICE_EXTENSION DeviceExt
,
41 PFILE_OBJECT FileObject
,
46 DPRINT("NtfsCleanupFile(DeviceExt %p, FileObject %p, CanWait %u)\n",
51 Fcb
= (PNTFS_FCB
)(FileObject
->FsContext
);
53 return STATUS_SUCCESS
;
55 if (Fcb
->Flags
& FCB_IS_VOLUME
)
57 Fcb
->OpenHandleCount
--;
59 if (Fcb
->OpenHandleCount
!= 0)
61 // Remove share access when handled
66 if (!ExAcquireResourceExclusiveLite(&Fcb
->MainResource
, CanWait
))
68 return STATUS_PENDING
;
71 Fcb
->OpenHandleCount
--;
73 CcUninitializeCacheMap(FileObject
, &Fcb
->RFCB
.FileSize
, NULL
);
75 if (Fcb
->OpenHandleCount
!= 0)
77 // Remove share access when handled
80 FileObject
->Flags
|= FO_CLEANUP_COMPLETE
;
82 ExReleaseResourceLite(&Fcb
->MainResource
);
85 return STATUS_SUCCESS
;
89 NtfsCleanup(PNTFS_IRP_CONTEXT IrpContext
)
91 PDEVICE_EXTENSION DeviceExtension
;
92 PFILE_OBJECT FileObject
;
94 PDEVICE_OBJECT DeviceObject
;
96 DPRINT("NtfsCleanup() called\n");
98 DeviceObject
= IrpContext
->DeviceObject
;
99 if (DeviceObject
== NtfsGlobalData
->DeviceObject
)
101 DPRINT("Cleaning up file system\n");
102 IrpContext
->Irp
->IoStatus
.Information
= 0;
103 return STATUS_SUCCESS
;
106 FileObject
= IrpContext
->FileObject
;
107 DeviceExtension
= DeviceObject
->DeviceExtension
;
109 if (!ExAcquireResourceExclusiveLite(&DeviceExtension
->DirResource
,
110 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
112 return NtfsMarkIrpContextForQueue(IrpContext
);
115 Status
= NtfsCleanupFile(DeviceExtension
, FileObject
, BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
));
117 ExReleaseResourceLite(&DeviceExtension
->DirResource
);
119 if (Status
== STATUS_PENDING
)
121 return NtfsMarkIrpContextForQueue(IrpContext
);
124 IrpContext
->Irp
->IoStatus
.Information
= 0;