ReactOS  0.4.13-dev-52-g0efcfec
flush.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/fs/vfat/flush.c
5  * PURPOSE: VFAT Filesystem
6  * PROGRAMMER:
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include "vfat.h"
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ****************************************************************/
17 
18 static
21  PDEVICE_EXTENSION DeviceExt,
22  PVFATFCB Fcb)
23 {
26 
27  DPRINT("VfatFlushFile(DeviceExt %p, Fcb %p) for '%wZ'\n", DeviceExt, Fcb, &Fcb->PathNameU);
28 
30  if (IoStatus.Status == STATUS_INVALID_PARAMETER)
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;
56  PVFATFCB Fcb;
57  NTSTATUS Status, ReturnStatus = STATUS_SUCCESS;
58  PIRP Irp;
59  KEVENT Event;
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;
71  if (!vfatFCBIsDirectory(Fcb))
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,
114  &IoStatusBlock);
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 
148 NTSTATUS
150  PVFAT_IRP_CONTEXT IrpContext)
151 {
153  PVFATFCB Fcb;
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  {
167  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
168  Status = VfatFlushVolume(IrpContext->DeviceExt, Fcb);
169  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
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 */
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FCB_IS_DIRTY
Definition: vfat.h:432
#define IRP_MJ_FLUSH_BUFFERS
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
Definition: vfat.h:441
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:579
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
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS VfatFlushVolume(PDEVICE_EXTENSION DeviceExt, PVFATFCB VolumeFcb)
Definition: flush.c:51
FORCEINLINE BOOLEAN vfatFCBIsDirectory(PVFATFCB FCB)
Definition: vfat.h:631
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
static NTSTATUS VfatFlushFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb)
Definition: flush.c:20
PFILE_OBJECT FileObject
Definition: vfat.h:585
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:520
NTSTATUS VfatFlush(PVFAT_IRP_CONTEXT IrpContext)
Definition: flush.c:149
Definition: typedefs.h:117
ERESOURCE MainResource
Definition: ntfs.h:512
struct _VFATFCB * PVFATFCB
Status
Definition: gdiplustypes.h:24
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define FCB_IS_VOLUME
Definition: vfat.h:431
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:578
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define DPRINT1
Definition: precomp.h:8
NTSTATUS VfatUpdateEntry(IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB pFcb)
Definition: dirwr.c:117
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2725
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:502