branch update for HEAD-2003050101
[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(PVFAT_IRP_CONTEXT IrpContext)
23 /*
24  * FUNCTION: Cleans up after a file has been closed.
25  */
26 {
27   PVFATFCB pFcb;
28   PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt;
29   PFILE_OBJECT FileObject = IrpContext->FileObject;
30   
31   DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
32          DeviceExt, FileObject);
33   
34   /* FIXME: handle file/directory deletion here */
35   pFcb = (PVFATFCB) FileObject->FsContext;
36   if (pFcb)
37   {
38      if (!(pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY) &&
39         FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
40      {
41         /* remove all locks this process have on this file */
42         FsRtlFastUnlockAll(&pFcb->FileLock,
43                            FileObject,
44                            IoGetRequestorProcess(IrpContext->Irp),
45                            NULL);
46      }
47
48      /* Uninitialize file cache if initialized for this file object. */
49      if (FileObject->PrivateCacheMap)
50      {
51         CcRosReleaseFileCache (FileObject);
52      }
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);
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 */