update for HEAD-2003091401
[reactos.git] / drivers / fs / vfat / close.c
1 /* $Id$
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   pFcb = (PVFATFCB) (FileObject->FsContext);
37
38   if (pFcb == NULL)
39   {
40      return STATUS_SUCCESS;
41   }
42
43   if (pFcb->Flags & FCB_IS_VOLUME)
44   {
45      DPRINT1("Volume\n");
46      pFcb->RefCount--;
47      FileObject->FsContext2 = NULL;
48   }
49   else if (FileObject->FileName.Buffer)
50   {
51     // This a FO, that was created outside from FSD.
52     // Some FO's are created with IoCreateStreamFileObject() insid from FSD.
53     // This FO's haven't a FileName.
54     if (FileObject->DeletePending)
55     {
56       if (pFcb->Flags & FCB_DELETE_PENDING)
57       {
58         delEntry (DeviceExt, FileObject);
59       }
60       else
61       {
62         Status = STATUS_DELETE_PENDING;
63       }
64     }
65     vfatReleaseFCB (DeviceExt, pFcb);
66   }
67     
68   FileObject->FsContext2 = NULL;
69   FileObject->FsContext = NULL;
70   FileObject->SectionObjectPointer = NULL;
71
72   if (pCcb)
73   {
74     vfatDestroyCCB(pCcb);
75   }
76   
77   return  Status;
78 }
79
80 NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext)
81 /*
82  * FUNCTION: Closes a file
83  */
84 {
85   NTSTATUS Status;
86
87   DPRINT ("VfatClose(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
88
89   if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
90     {
91       DPRINT("Closing file system\n");
92       Status = STATUS_SUCCESS;
93       goto ByeBye;
94     }
95 #if 0
96   /* There occurs a dead look at the call to CcRosDeleteFileCache/ObDereferenceObject/VfatClose 
97      in CmLazyCloseThreadMain if VfatClose is execute asynchronous in a worker thread. */
98   if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
99 #else
100   if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, TRUE))
101 #endif
102   {
103      return VfatQueueRequest (IrpContext);
104   }
105
106   Status = VfatCloseFile (IrpContext->DeviceExt, IrpContext->FileObject);
107   ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
108
109 ByeBye:
110   IrpContext->Irp->IoStatus.Status = Status;
111   IrpContext->Irp->IoStatus.Information = 0;
112   IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
113   VfatFreeIrpContext(IrpContext);
114
115   return (Status);
116 }
117
118 /* EOF */