10d7704636d6cf1ba575ece9c3c5a2194195adc8
[reactos.git] / drivers / filesystems / cdfs / cleanup.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
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.
9 *
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.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: drivers/filesystems/cdfs/cleanup.c
23 * PURPOSE: CDROM (ISO 9660) filesystem driver
24 * PROGRAMMER:
25 * UPDATE HISTORY:
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include "cdfs.h"
31
32 #define NDEBUG
33 #include <debug.h>
34
35 /* FUNCTIONS ****************************************************************/
36
37 static NTSTATUS
38 CdfsCleanupFile(PCDFS_IRP_CONTEXT IrpContext,
39 PFILE_OBJECT FileObject)
40 /*
41 * FUNCTION: Cleans up after a file has been closed.
42 */
43 {
44 PDEVICE_EXTENSION DeviceExt;
45 PFCB Fcb;
46
47 DPRINT("CdfsCleanupFile(IrpContext %p, FileObject %p)\n",
48 IrpContext,
49 FileObject);
50
51 DeviceExt = IrpContext->DeviceObject->DeviceExtension;
52 Fcb = FileObject->FsContext;
53 if (!Fcb)
54 {
55 return STATUS_SUCCESS;
56 }
57
58 DeviceExt->OpenHandleCount--;
59
60 /* Notify about the cleanup */
61 FsRtlNotifyCleanup(DeviceExt->NotifySync,
62 &(DeviceExt->NotifyList),
63 FileObject->FsContext2);
64
65 if (!CdfsFCBIsDirectory(Fcb) &&
66 FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
67 {
68 FsRtlFastUnlockAll(&Fcb->FileLock,
69 FileObject,
70 IoGetRequestorProcess(IrpContext->Irp),
71 NULL);
72 }
73
74 /* Uninitialize file cache if initialized for this file object. */
75 if (FileObject->SectionObjectPointer && FileObject->SectionObjectPointer->SharedCacheMap)
76 {
77 CcUninitializeCacheMap (FileObject, NULL, NULL);
78 }
79
80 return STATUS_SUCCESS;
81 }
82
83 NTSTATUS NTAPI
84 CdfsCleanup(
85 PCDFS_IRP_CONTEXT IrpContext)
86 {
87 PIRP Irp;
88 PDEVICE_OBJECT DeviceObject;
89 PDEVICE_EXTENSION DeviceExtension;
90 PIO_STACK_LOCATION Stack;
91 PFILE_OBJECT FileObject;
92 NTSTATUS Status;
93
94 DPRINT("CdfsCleanup() called\n");
95
96 ASSERT(IrpContext);
97
98 Irp = IrpContext->Irp;
99 DeviceObject = IrpContext->DeviceObject;
100 Stack = IrpContext->Stack;
101
102 if (DeviceObject == CdfsGlobalData->CdFsDeviceObject || DeviceObject == CdfsGlobalData->HddFsDeviceObject)
103 {
104 DPRINT("Closing file system\n");
105 Status = STATUS_SUCCESS;
106 goto ByeBye;
107 }
108
109 FileObject = Stack->FileObject;
110 DeviceExtension = DeviceObject->DeviceExtension;
111
112 KeEnterCriticalRegion();
113 ExAcquireResourceExclusiveLite(&DeviceExtension->DirResource, TRUE);
114
115 Status = CdfsCleanupFile(IrpContext, FileObject);
116
117 ExReleaseResourceLite(&DeviceExtension->DirResource);
118 KeLeaveCriticalRegion();
119
120 ByeBye:
121 Irp->IoStatus.Information = 0;
122
123 return(Status);
124 }
125
126 /* EOF */