xref: /reactos/drivers/filesystems/cdfs/close.c (revision 5100859e)
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/close.c
23  * PURPOSE:          CDROM (ISO 9660) filesystem driver
24  * PROGRAMMER:       Art Yerkes
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 NTSTATUS
38 CdfsCloseFile(PDEVICE_EXTENSION DeviceExt,
39               PFILE_OBJECT FileObject)
40               /*
41               * FUNCTION: Closes a file
42               */
43 {
44     PCCB Ccb;
45 
46     DPRINT("CdfsCloseFile(DeviceExt %p, FileObject %p)\n",
47         DeviceExt,
48         FileObject);
49 
50     Ccb = (PCCB)(FileObject->FsContext2);
51 
52     DPRINT("Ccb %p\n", Ccb);
53     if (Ccb == NULL)
54     {
55         return(STATUS_SUCCESS);
56     }
57 
58     FileObject->FsContext2 = NULL;
59 
60     if (FileObject->FileName.Buffer)
61     {
62         // This a FO, that was created outside from FSD.
63         // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
64         // This FO's don't have a FileName.
65         CdfsReleaseFCB(DeviceExt, FileObject->FsContext);
66     }
67 
68     if (Ccb->DirectorySearchPattern.Buffer)
69     {
70         ExFreePoolWithTag(Ccb->DirectorySearchPattern.Buffer, CDFS_SEARCH_PATTERN_TAG);
71     }
72     ExFreePoolWithTag(Ccb, CDFS_CCB_TAG);
73 
74     return(STATUS_SUCCESS);
75 }
76 
77 
78 NTSTATUS NTAPI
79 CdfsClose(
80     PCDFS_IRP_CONTEXT IrpContext)
81 {
82     PIRP Irp;
83     PDEVICE_OBJECT DeviceObject;
84     PDEVICE_EXTENSION DeviceExtension;
85     PIO_STACK_LOCATION Stack;
86     PFILE_OBJECT FileObject;
87     NTSTATUS Status;
88 
89     DPRINT("CdfsClose() called\n");
90 
91     ASSERT(IrpContext);
92 
93     Irp = IrpContext->Irp;
94     DeviceObject = IrpContext->DeviceObject;
95     Stack = IrpContext->Stack;
96 
97     if (DeviceObject == CdfsGlobalData->CdFsDeviceObject || DeviceObject == CdfsGlobalData->HddFsDeviceObject)
98     {
99         DPRINT("Closing file system\n");
100         Status = STATUS_SUCCESS;
101         goto ByeBye;
102     }
103 
104     FileObject = Stack->FileObject;
105     DeviceExtension = DeviceObject->DeviceExtension;
106 
107     Status = CdfsCloseFile(DeviceExtension,FileObject);
108 
109 ByeBye:
110     Irp->IoStatus.Information = 0;
111 
112     return(Status);
113 }
114 
115 /* EOF */
116