Reworked code for handling of asynchonous i/o requests.
[reactos.git] / reactos / drivers / fs / vfat / close.c
1 /* $Id: close.c,v 1.9 2001/11/02 22:44:34 hbirr Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/fs/vfat/close.c
6 * PURPOSE: VFAT Filesystem
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 #include "vfat.h"
18
19 /* FUNCTIONS ****************************************************************/
20
21 NTSTATUS
22 VfatCloseFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
23 /*
24 * FUNCTION: Closes a file
25 */
26 {
27 PVFATFCB pFcb;
28 PVFATCCB pCcb;
29 NTSTATUS Status = STATUS_SUCCESS;
30
31 DPRINT ("VfatCloseFile(DeviceExt %x, FileObject %x)\n",
32 DeviceExt, FileObject);
33
34 /* FIXME : update entry in directory? */
35 pCcb = (PVFATCCB) (FileObject->FsContext2);
36
37 DPRINT ("pCcb %x\n", pCcb);
38 if (pCcb == NULL)
39 {
40 return STATUS_SUCCESS;
41 }
42 if (FileObject->FileName.Buffer)
43 {
44 // This a FO, that was created outside from FSD.
45 // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
46 // This FO's haven't a FileName.
47 pFcb = pCcb->pFcb;
48 if (FileObject->DeletePending)
49 {
50 if (pFcb->Flags & FCB_DELETE_PENDING)
51 {
52 delEntry (DeviceExt, FileObject);
53 }
54 else
55 Status = STATUS_DELETE_PENDING;
56 }
57 FileObject->FsContext2 = NULL;
58 vfatReleaseFCB (DeviceExt, pFcb);
59 }
60 else
61 FileObject->FsContext2 = NULL;
62
63 ExFreePool (pCcb);
64
65 return Status;
66 }
67
68 NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext)
69 /*
70 * FUNCTION: Closes a file
71 */
72 {
73 NTSTATUS Status;
74
75 DPRINT ("VfatClose(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
76
77 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
78 {
79 return VfatQueueRequest (IrpContext);
80 }
81
82 Status = VfatCloseFile (IrpContext->DeviceExt, IrpContext->FileObject);
83 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
84
85 IrpContext->Irp->IoStatus.Status = Status;
86 IrpContext->Irp->IoStatus.Information = 0;
87 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
88 VfatFreeIrpContext(IrpContext);
89
90 return (Status);
91 }
92
93 /* EOF */