Sync with trunk (r48545)
[reactos.git] / drivers / filesystems / cdfs / close.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 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/cdfs/close.c
24 * PURPOSE: CDROM (ISO 9660) filesystem driver
25 * PROGRAMMER: Art Yerkes
26 * UPDATE HISTORY:
27 */
28
29 /* INCLUDES *****************************************************************/
30
31 #include "cdfs.h"
32
33 #define NDEBUG
34 #include <debug.h>
35
36 /* FUNCTIONS ****************************************************************/
37
38 NTSTATUS
39 CdfsCloseFile(PDEVICE_EXTENSION DeviceExt,
40 PFILE_OBJECT FileObject)
41 /*
42 * FUNCTION: Closes a file
43 */
44 {
45 PCCB Ccb;
46
47 DPRINT("CdfsCloseFile(DeviceExt %x, FileObject %x)\n",
48 DeviceExt,
49 FileObject);
50
51 Ccb = (PCCB)(FileObject->FsContext2);
52
53 DPRINT("Ccb %x\n", Ccb);
54 if (Ccb == NULL)
55 {
56 return(STATUS_SUCCESS);
57 }
58
59 FileObject->FsContext2 = NULL;
60
61 if (FileObject->FileName.Buffer)
62 {
63 // This a FO, that was created outside from FSD.
64 // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
65 // This FO's don't have a FileName.
66 CdfsReleaseFCB(DeviceExt, FileObject->FsContext);
67 }
68
69 if (Ccb->DirectorySearchPattern.Buffer)
70 {
71 ExFreePoolWithTag(Ccb->DirectorySearchPattern.Buffer, TAG_CCB);
72 }
73 ExFreePoolWithTag(Ccb, TAG_CCB);
74
75 return(STATUS_SUCCESS);
76 }
77
78
79 NTSTATUS NTAPI
80 CdfsClose(PDEVICE_OBJECT DeviceObject,
81 PIRP Irp)
82 {
83 PDEVICE_EXTENSION DeviceExtension;
84 PIO_STACK_LOCATION Stack;
85 PFILE_OBJECT FileObject;
86 NTSTATUS Status;
87
88 DPRINT("CdfsClose() called\n");
89
90 if (DeviceObject == CdfsGlobalData->DeviceObject)
91 {
92 DPRINT("Closing file system\n");
93 Status = STATUS_SUCCESS;
94 goto ByeBye;
95 }
96
97 Stack = IoGetCurrentIrpStackLocation(Irp);
98 FileObject = Stack->FileObject;
99 DeviceExtension = DeviceObject->DeviceExtension;
100
101 Status = CdfsCloseFile(DeviceExtension,FileObject);
102
103 ByeBye:
104 Irp->IoStatus.Status = Status;
105 Irp->IoStatus.Information = 0;
106
107 IoCompleteRequest(Irp, IO_NO_INCREMENT);
108 return(Status);
109 }
110
111 /* EOF */
112