3 * Copyright (C) 2002 ReactOS Team
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.
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.
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.
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
27 /* INCLUDES *****************************************************************/
34 /* FUNCTIONS ****************************************************************/
37 * FUNCTION: Closes a file
40 NtfsCloseFile(PDEVICE_EXTENSION DeviceExt
,
41 PFILE_OBJECT FileObject
)
46 DPRINT("NtfsCloseFile(DeviceExt %p, FileObject %p)\n",
50 Ccb
= (PNTFS_CCB
)(FileObject
->FsContext2
);
51 Fcb
= (PNTFS_FCB
)(FileObject
->FsContext
);
53 DPRINT("Ccb %p\n", Ccb
);
56 return STATUS_SUCCESS
;
59 FileObject
->FsContext2
= NULL
;
60 FileObject
->FsContext
= NULL
;
61 FileObject
->SectionObjectPointer
= NULL
;
62 DeviceExt
->OpenHandleCount
--;
64 if (FileObject
->FileName
.Buffer
)
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
, Fcb
);
72 if (Ccb
->DirectorySearchPattern
)
74 ExFreePool(Ccb
->DirectorySearchPattern
);
79 return STATUS_SUCCESS
;
84 NtfsClose(PNTFS_IRP_CONTEXT IrpContext
)
86 PDEVICE_EXTENSION DeviceExtension
;
87 PFILE_OBJECT FileObject
;
89 PDEVICE_OBJECT DeviceObject
;
91 DPRINT("NtfsClose() called\n");
93 DeviceObject
= IrpContext
->DeviceObject
;
94 if (DeviceObject
== NtfsGlobalData
->DeviceObject
)
96 DPRINT("Closing file system\n");
97 IrpContext
->Irp
->IoStatus
.Information
= 0;
98 return STATUS_SUCCESS
;
101 FileObject
= IrpContext
->FileObject
;
102 DeviceExtension
= DeviceObject
->DeviceExtension
;
104 if (!ExAcquireResourceExclusiveLite(&DeviceExtension
->DirResource
,
105 BooleanFlagOn(IrpContext
->Flags
, IRPCONTEXT_CANWAIT
)))
107 return NtfsMarkIrpContextForQueue(IrpContext
);
110 Status
= NtfsCloseFile(DeviceExtension
, FileObject
);
112 ExReleaseResourceLite(&DeviceExtension
->DirResource
);
114 if (Status
== STATUS_PENDING
)
116 return NtfsMarkIrpContextForQueue(IrpContext
);
119 IrpContext
->Irp
->IoStatus
.Information
= 0;