merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / drivers / fs / vfat / cleanup.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: drivers/fs/vfat/cleanup.c
6 * PURPOSE: VFAT Filesystem
7 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
8 * Hartmut Birr
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #define NDEBUG
14 #include "vfat.h"
15
16 /* FUNCTIONS ****************************************************************/
17
18 static NTSTATUS
19 VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
20 /*
21 * FUNCTION: Cleans up after a file has been closed.
22 */
23 {
24 PVFATFCB pFcb;
25 PFILE_OBJECT FileObject = IrpContext->FileObject;
26
27 DPRINT("VfatCleanupFile(DeviceExt %x, FileObject %x)\n",
28 IrpContext->DeviceExt, FileObject);
29
30 /* FIXME: handle file/directory deletion here */
31 pFcb = (PVFATFCB) FileObject->FsContext;
32 if (pFcb)
33 {
34 if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) &&
35 FsRtlAreThereCurrentFileLocks(&pFcb->FileLock))
36 {
37 /* remove all locks this process have on this file */
38 FsRtlFastUnlockAll(&pFcb->FileLock,
39 FileObject,
40 IoGetRequestorProcess(IrpContext->Irp),
41 NULL);
42 }
43
44 if (pFcb->Flags & FCB_IS_DIRTY)
45 {
46 VfatUpdateEntry (pFcb);
47 }
48
49 if (pFcb->Flags & FCB_DELETE_PENDING &&
50 pFcb->OpenHandleCount == 1)
51 {
52 PFILE_OBJECT tmpFileObject;
53 tmpFileObject = pFcb->FileObject;
54 if (tmpFileObject != NULL)
55 {
56 pFcb->FileObject = NULL;
57 #ifdef USE_ROS_CC_AND_FS
58 CcRosReleaseFileCache(tmpFileObject);
59 #else
60 CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
61 #endif
62 ObDereferenceObject(tmpFileObject);
63 }
64
65 #if 0
66 /* FIXME:
67 * CcPurgeCacheSection is unimplemented.
68 */
69 CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, FALSE);
70 #endif
71 }
72 /* Uninitialize file cache if. */
73 #ifdef USE_ROS_CC_AND_FS
74 CcRosReleaseFileCache (FileObject);
75 #else
76 CcUninitializeCacheMap (FileObject, NULL, NULL);
77 #endif
78 pFcb->OpenHandleCount--;
79 IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess);
80 }
81 return STATUS_SUCCESS;
82 }
83
84 NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
85 /*
86 * FUNCTION: Cleans up after a file has been closed.
87 */
88 {
89 NTSTATUS Status;
90
91 DPRINT("VfatCleanup(DeviceObject %x, Irp %x)\n", IrpContext->DeviceObject, IrpContext->Irp);
92
93 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
94 {
95 Status = STATUS_SUCCESS;
96 goto ByeBye;
97 }
98
99 if (!ExAcquireResourceExclusiveLite (&IrpContext->DeviceExt->DirResource,
100 (BOOLEAN)(IrpContext->Flags & IRPCONTEXT_CANWAIT)))
101 {
102 return VfatQueueRequest (IrpContext);
103 }
104
105 Status = VfatCleanupFile(IrpContext);
106
107 ExReleaseResourceLite (&IrpContext->DeviceExt->DirResource);
108
109 ByeBye:
110 IrpContext->Irp->IoStatus.Status = Status;
111 IrpContext->Irp->IoStatus.Information = 0;
112
113 IoCompleteRequest (IrpContext->Irp, IO_NO_INCREMENT);
114 VfatFreeIrpContext(IrpContext);
115 return (Status);
116 }
117
118 /* EOF */