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