ReactOS 0.4.15-dev-5666-gc548b97
flush.c
Go to the documentation of this file.
1/*
2 * PROJECT: VFAT Filesystem
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Flushing routines
5 * COPYRIGHT: Copyright 2004-2013 Eric Kohl <eric.kohl@reactos.org>
6 * Copyright 2014-2018 Pierre Schweitzer <pierre@reactos.org>
7 */
8
9/* INCLUDES *****************************************************************/
10
11#include "vfat.h"
12
13#define NDEBUG
14#include <debug.h>
15
16/* FUNCTIONS ****************************************************************/
17
18static
21 PDEVICE_EXTENSION DeviceExt,
23{
26
27 DPRINT("VfatFlushFile(DeviceExt %p, Fcb %p) for '%wZ'\n", DeviceExt, Fcb, &Fcb->PathNameU);
28
31 {
32 /* FIXME: Caching was possible not initialized */
33 IoStatus.Status = STATUS_SUCCESS;
34 }
35
36 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
38 {
39 Status = VfatUpdateEntry(DeviceExt, Fcb);
40 if (!NT_SUCCESS(Status))
41 {
42 IoStatus.Status = Status;
43 }
44 }
45 ExReleaseResourceLite(&DeviceExt->DirResource);
46
47 return IoStatus.Status;
48}
49
52 PDEVICE_EXTENSION DeviceExt,
53 PVFATFCB VolumeFcb)
54{
55 PLIST_ENTRY ListEntry;
57 NTSTATUS Status, ReturnStatus = STATUS_SUCCESS;
58 PIRP Irp;
61
62 DPRINT("VfatFlushVolume(DeviceExt %p, VolumeFcb %p)\n", DeviceExt, VolumeFcb);
63
64 ASSERT(VolumeFcb == DeviceExt->VolumeFcb);
65
66 ListEntry = DeviceExt->FcbListHead.Flink;
67 while (ListEntry != &DeviceExt->FcbListHead)
68 {
69 Fcb = CONTAINING_RECORD(ListEntry, VFATFCB, FcbListEntry);
70 ListEntry = ListEntry->Flink;
72 {
74 Status = VfatFlushFile(DeviceExt, Fcb);
76 if (!NT_SUCCESS(Status))
77 {
78 DPRINT1("VfatFlushFile failed, status = %x\n", Status);
79 ReturnStatus = Status;
80 }
81 }
82 /* FIXME: Stop flushing if this is a removable media and the media was removed */
83 }
84
85 ListEntry = DeviceExt->FcbListHead.Flink;
86 while (ListEntry != &DeviceExt->FcbListHead)
87 {
88 Fcb = CONTAINING_RECORD(ListEntry, VFATFCB, FcbListEntry);
89 ListEntry = ListEntry->Flink;
91 {
93 Status = VfatFlushFile(DeviceExt, Fcb);
95 if (!NT_SUCCESS(Status))
96 {
97 DPRINT1("VfatFlushFile failed, status = %x\n", Status);
98 ReturnStatus = Status;
99 }
100 }
101 /* FIXME: Stop flushing if this is a removable media and the media was removed */
102 }
103
104 Fcb = (PVFATFCB) DeviceExt->FATFileObject->FsContext;
105
106 ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
107 Status = VfatFlushFile(DeviceExt, Fcb);
108 ExReleaseResourceLite(&DeviceExt->FatResource);
109
110 /* Prepare an IRP to flush device buffers */
112 DeviceExt->StorageDevice,
113 NULL, 0, NULL, &Event,
115 if (Irp != NULL)
116 {
118
119 Status = IoCallDriver(DeviceExt->StorageDevice, Irp);
120 if (Status == STATUS_PENDING)
121 {
124 }
125
126 /* Ignore device not supporting flush operation */
128 {
129 DPRINT1("Flush not supported, ignored\n");
131
132 }
133 }
134 else
135 {
137 }
138
139 if (!NT_SUCCESS(Status))
140 {
141 DPRINT1("VfatFlushFile failed, status = %x\n", Status);
142 ReturnStatus = Status;
143 }
144
145 return ReturnStatus;
146}
147
150 PVFAT_IRP_CONTEXT IrpContext)
151{
154
155 /* This request is not allowed on the main device object. */
156 if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
157 {
158 IrpContext->Irp->IoStatus.Information = 0;
160 }
161
162 Fcb = (PVFATFCB)IrpContext->FileObject->FsContext;
163 ASSERT(Fcb);
164
166 {
168 Status = VfatFlushVolume(IrpContext->DeviceExt, Fcb);
170 }
171 else
172 {
174 Status = VfatFlushFile(IrpContext->DeviceExt, Fcb);
176 }
177
178 IrpContext->Irp->IoStatus.Information = 0;
179 return Status;
180}
181
182/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
_In_ PFCB Fcb
Definition: cdprocs.h:159
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS VfatUpdateEntry(IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB pFcb)
Definition: dirwr.c:115
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FCB_IS_VOLUME
Definition: ntfs.h:510
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
ERESOURCE DirResource
Definition: ntfs.h:103
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:412
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:585
PFILE_OBJECT FileObject
Definition: vfat.h:591
ULONG Flags
Definition: ntfs.h:536
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:518
ERESOURCE MainResource
Definition: ntfs.h:528
IO_STATUS_BLOCK IoStatus
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: vfat.h:448
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
struct _VFATFCB * PVFATFCB
FORCEINLINE BOOLEAN vfatFCBIsDirectory(PVFATFCB FCB)
Definition: vfat.h:637
#define FCB_IS_DIRTY
Definition: vfat.h:438
NTSTATUS VfatFlush(PVFAT_IRP_CONTEXT IrpContext)
Definition: flush.c:149
NTSTATUS VfatFlushVolume(PDEVICE_EXTENSION DeviceExt, PVFATFCB VolumeFcb)
Definition: flush.c:51
static NTSTATUS VfatFlushFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb)
Definition: flush.c:20
#define IRP_MJ_FLUSH_BUFFERS
@ Executive
Definition: ketypes.h:403