update for HEAD-2003021201
[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   PVFATCCB pCcb;
28   PVFATFCB pFcb;
29   PDEVICE_EXTENSION DeviceExt = IrpContext->DeviceExt;
30   PFILE_OBJECT FileObject = IrpContext->FileObject;
31   
32   DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
33          DeviceExt, FileObject);
34   
35   /* FIXME: handle file/directory deletion here */
36   pCcb = (PVFATCCB) (FileObject->FsContext2);
37   if (pCcb == NULL)
38     {
39       return  STATUS_SUCCESS;
40     }
41   pFcb = pCcb->pFcb;
42
43   if (!(pFcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY) &&
44      FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
45   {
46     /* remove all locks this process have on this file */
47     FsRtlFastUnlockAll(&pFcb->FileLock,
48                        FileObject,
49                        IoGetRequestorProcess(IrpContext->Irp),
50                        NULL
51                        );
52   }
53
54   /* Uninitialize file cache if initialized for this file object. */
55   if (pFcb->RFCB.Bcb != NULL)
56     {
57       CcRosReleaseFileCache (FileObject, pFcb->RFCB.Bcb);
58     }
59   
60   return STATUS_SUCCESS;
61 }
62
63 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
64 /*
65  * FUNCTION: Cleans up after a file has been closed.
66  */
67 {
68    NTSTATUS Status;
69
70    DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
71
72   if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
73     {
74       Status = STATUS_SUCCESS;
75       goto ByeBye;
76     }
77
78    if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource, IrpContext->Flags & IRPCONTEXT_CANWAIT))
79    {
80      return VfatQueueRequest (IrpContext);
81    }
82
83    Status = VfatCleanupFile(IrpContext);
84
85    ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
86
87 ByeBye:
88    IrpContext->Irp->IoStatus.Status = Status;
89    IrpContext->Irp->IoStatus.Information = 0;
90
91    IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
92    VfatFreeIrpContext(IrpContext);
93    return (Status);
94 }
95
96 /* EOF */