Sync with trunk head (r48654)
[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 /* GLOBALS *****************************************************************/
35
36
37 /* FUNCTIONS ****************************************************************/
38
39 static NTSTATUS
40 NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
41 PFILE_OBJECT FileObject)
42 /*
43 * FUNCTION: Closes a file
44 */
45 {
46 PNTFS_CCB Ccb;
47
48 DPRINT("NtfsCloseFile(DeviceExt %p, FileObject %p)\n",
49 DeviceExt,
50 FileObject);
51
52 Ccb = (PNTFS_CCB)(FileObject->FsContext2);
53
54 DPRINT("Ccb %p\n", Ccb);
55 if (Ccb == NULL)
56 {
57 return(STATUS_SUCCESS);
58 }
59
60 FileObject->FsContext2 = NULL;
61
62 if (FileObject->FileName.Buffer)
63 {
64 // This a FO, that was created outside from FSD.
65 // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
66 // This FO's don't have a FileName.
67 NtfsReleaseFCB(DeviceExt, FileObject->FsContext);
68 }
69
70 if (Ccb->DirectorySearchPattern)
71 {
72 ExFreePool(Ccb->DirectorySearchPattern);
73 }
74 ExFreePool(Ccb);
75
76 return(STATUS_SUCCESS);
77 }
78
79
80 NTSTATUS NTAPI
81 NtfsFsdClose(PDEVICE_OBJECT DeviceObject,
82 PIRP Irp)
83 {
84 PDEVICE_EXTENSION DeviceExtension;
85 PIO_STACK_LOCATION Stack;
86 PFILE_OBJECT FileObject;
87 NTSTATUS Status;
88
89 DPRINT("NtfsClose() called\n");
90
91 if (DeviceObject == NtfsGlobalData->DeviceObject)
92 {
93 DPRINT("Closing file system\n");
94 Status = STATUS_SUCCESS;
95 goto ByeBye;
96 }
97
98 Stack = IoGetCurrentIrpStackLocation(Irp);
99 FileObject = Stack->FileObject;
100 DeviceExtension = DeviceObject->DeviceExtension;
101
102 Status = NtfsCloseFile(DeviceExtension,FileObject);
103
104 ByeBye:
105 Irp->IoStatus.Status = Status;
106 Irp->IoStatus.Information = 0;
107
108 IoCompleteRequest(Irp, IO_NO_INCREMENT);
109 return(Status);
110 }