minor corrections by M.Taguchi
[reactos.git] / reactos / drivers / fs / 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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: close.c,v 1.1 2003/07/17 13:31:39 chorns Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/ntfs/close.c
24 * PURPOSE: NTFS filesystem driver
25 * PROGRAMMER: Art Yerkes
26 * UPDATE HISTORY:
27 */
28
29 /* INCLUDES *****************************************************************/
30
31 #include <ddk/ntddk.h>
32
33 //#define NDEBUG
34 #include <debug.h>
35
36 #include "ntfs.h"
37
38
39 /* FUNCTIONS ****************************************************************/
40
41 static NTSTATUS
42 NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
43 PFILE_OBJECT FileObject)
44 /*
45 * FUNCTION: Closes a file
46 */
47 {
48 PCCB Ccb;
49
50 DPRINT("NtfsCloseFile(DeviceExt %x, FileObject %x)\n",
51 DeviceExt,
52 FileObject);
53
54 Ccb = (PCCB)(FileObject->FsContext2);
55
56 DPRINT("Ccb %x\n", Ccb);
57 if (Ccb == NULL)
58 {
59 return(STATUS_SUCCESS);
60 }
61
62 FileObject->FsContext2 = NULL;
63
64 if (FileObject->FileName.Buffer)
65 {
66 // This a FO, that was created outside from FSD.
67 // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
68 // This FO's don't have a FileName.
69 NtfsReleaseFCB(DeviceExt, FileObject->FsContext);
70 }
71
72 if (Ccb->DirectorySearchPattern)
73 {
74 ExFreePool(Ccb->DirectorySearchPattern);
75 }
76 ExFreePool(Ccb);
77
78 return(STATUS_SUCCESS);
79 }
80
81
82 NTSTATUS STDCALL
83 NtfsClose(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 }