f46ecdbe0fde3874a436093a207a885e2637ee42
[reactos.git] / reactos / 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: services/fs/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(PDEVICE_EXTENSION DeviceExt,
39 PFILE_OBJECT FileObject)
40 /*
41 * FUNCTION: Cleans up after a file has been closed.
42 */
43 {
44 PFCB Fcb;
45
46 DPRINT("CdfsCleanupFile(DeviceExt %p, FileObject %p)\n",
47 DeviceExt,
48 FileObject);
49
50 Fcb = FileObject->FsContext;
51 if (!Fcb)
52 {
53 return STATUS_SUCCESS;
54 }
55
56 /* Notify about the cleanup */
57 FsRtlNotifyCleanup(DeviceExt->NotifySync,
58 &(DeviceExt->NotifyList),
59 FileObject->FsContext2);
60
61 /* Uninitialize file cache if initialized for this file object. */
62 if (FileObject->SectionObjectPointer && FileObject->SectionObjectPointer->SharedCacheMap)
63 {
64 CcUninitializeCacheMap (FileObject, NULL, NULL);
65 }
66
67 return STATUS_SUCCESS;
68 }
69
70 NTSTATUS NTAPI
71 CdfsCleanup(PDEVICE_OBJECT DeviceObject,
72 PIRP Irp)
73 {
74 PDEVICE_EXTENSION DeviceExtension;
75 PIO_STACK_LOCATION Stack;
76 PFILE_OBJECT FileObject;
77 NTSTATUS Status;
78
79 DPRINT("CdfsCleanup() called\n");
80
81 if (DeviceObject == CdfsGlobalData->DeviceObject)
82 {
83 DPRINT("Closing file system\n");
84 Status = STATUS_SUCCESS;
85 goto ByeBye;
86 }
87
88 Stack = IoGetCurrentIrpStackLocation(Irp);
89 FileObject = Stack->FileObject;
90 DeviceExtension = DeviceObject->DeviceExtension;
91
92 KeEnterCriticalRegion();
93 ExAcquireResourceExclusiveLite(&DeviceExtension->DirResource, TRUE);
94
95 Status = CdfsCleanupFile(DeviceExtension, FileObject);
96
97 ExReleaseResourceLite(&DeviceExtension->DirResource);
98 KeLeaveCriticalRegion();
99
100
101 ByeBye:
102 Irp->IoStatus.Status = Status;
103 Irp->IoStatus.Information = 0;
104
105 IoCompleteRequest(Irp, IO_NO_INCREMENT);
106 return(Status);
107 }
108
109 /* EOF */