Sync with trunk r63283
[reactos.git] / 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 /* FUNCTIONS ****************************************************************/
35
36 /*
37 * FUNCTION: Closes a file
38 */
39 static
40 NTSTATUS
41 NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
42 PFILE_OBJECT FileObject)
43 {
44 PNTFS_CCB Ccb;
45
46 DPRINT("NtfsCloseFile(DeviceExt %p, FileObject %p)\n",
47 DeviceExt,
48 FileObject);
49
50 Ccb = (PNTFS_CCB)(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 NtfsReleaseFCB(DeviceExt, FileObject->FsContext);
66 }
67
68 if (Ccb->DirectorySearchPattern)
69 {
70 ExFreePool(Ccb->DirectorySearchPattern);
71 }
72
73 ExFreePool(Ccb);
74
75 return STATUS_SUCCESS;
76 }
77
78
79 NTSTATUS NTAPI
80 NtfsFsdClose(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("NtfsClose() called\n");
89
90 if (DeviceObject == NtfsGlobalData->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 = NtfsCloseFile(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 */