:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / fs / vfat / cleanup.c
1 /* $Id$
2  *
3  * COPYRIGHT:        See COPYING in the top level directory
4  * PROJECT:          ReactOS kernel
5  * FILE:             services/fs/vfat/cleanup.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 static NTSTATUS
22 VfatCleanupFile(PDEVICE_EXTENSION DeviceExt,
23                 PFILE_OBJECT FileObject)
24 /*
25  * FUNCTION: Cleans up after a file has been closed.
26  */
27 {
28   PVFATCCB pCcb;
29   PVFATFCB pFcb;
30   
31   DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
32          DeviceExt, FileObject);
33   
34   /* FIXME: handle file/directory deletion here */
35   pCcb = (PVFATCCB) (FileObject->FsContext2);
36   if (pCcb == NULL)
37     {
38       return  STATUS_SUCCESS;
39     }
40   pFcb = pCcb->pFcb;
41
42   if (FileObject->FileName.Buffer)
43     {
44       if (pFcb->Flags & FCB_UPDATE_DIRENTRY)
45         {
46           VfatUpdateEntry (DeviceExt, FileObject);
47           pFcb->Flags &= ~FCB_UPDATE_DIRENTRY;
48         }
49     }
50
51   /* Uninitialize the file cache. */
52   CcRosReleaseFileCache (FileObject, pFcb->RFCB.Bcb);
53   
54   return STATUS_SUCCESS;
55 }
56
57 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
58 /*
59  * FUNCTION: Cleans up after a file has been closed.
60  */
61 {
62    NTSTATUS Status;
63
64    DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
65
66   if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
67     {
68       Status = STATUS_SUCCESS;
69       goto ByeBye;
70     }
71
72    if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
73    {
74      return VfatQueueRequest (IrpContext);
75    }
76
77    Status = VfatCleanupFile(IrpContext->DeviceExt, IrpContext->FileObject);
78
79    ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
80
81 ByeBye:
82    IrpContext->Irp->IoStatus.Status = Status;
83    IrpContext->Irp->IoStatus.Information = 0;
84
85    IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
86    VfatFreeIrpContext(IrpContext);
87    return (Status);
88 }
89
90 /* EOF */