ReactOS  0.4.15-dev-321-g2d9b385
flush.c File Reference
#include "rfsd.h"
Include dependency graph for flush.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI RfsdFlushCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Contxt)
 
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushFiles (IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
 
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushVolume (IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
 
NTSTATUS RfsdFlushFile (IN PRFSD_FCB Fcb)
 
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlush (IN PRFSD_IRP_CONTEXT IrpContext)
 

Variables

PRFSD_GLOBAL RfsdGlobal
 

Function Documentation

◆ RfsdFlush()

Definition at line 153 of file flush.c.

154 {
156 
157  PIRP Irp;
159 
160  PRFSD_VCB Vcb = 0;
161  PRFSD_FCBVCB FcbOrVcb = 0;
163 
165 
166  BOOLEAN MainResourceAcquired = FALSE;
167 
168  PAGED_CODE();
169 
170  _SEH2_TRY {
171 
172  ASSERT(IrpContext);
173 
174  ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
175  (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
176 
177  DeviceObject = IrpContext->DeviceObject;
178 
179  //
180  // This request is not allowed on the main device object
181  //
184  _SEH2_LEAVE;
185  }
186 
188 
189  ASSERT(Vcb != NULL);
190 
191  ASSERT((Vcb->Identifier.Type == RFSDVCB) &&
192  (Vcb->Identifier.Size == sizeof(RFSD_VCB)));
193 
194  ASSERT(IsMounted(Vcb));
195 
196  if ( IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
197  IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED)) {
199  _SEH2_LEAVE;
200  }
201 
202  Irp = IrpContext->Irp;
203 
205 
206  FileObject = IrpContext->FileObject;
207 
208  FcbOrVcb = (PRFSD_FCBVCB) FileObject->FsContext;
209 
210  ASSERT(FcbOrVcb != NULL);
211 
212 #ifdef _MSC_VER
213 #pragma prefast( suppress: 28137, "by design" )
214 #endif
216  &FcbOrVcb->MainResource,
217  IrpContext->IsSynchronous )) {
219  _SEH2_LEAVE;
220  }
221 
222  MainResourceAcquired = TRUE;
223 
224  if (FcbOrVcb->Identifier.Type == RFSDVCB) {
225 
226  Status = RfsdFlushFiles((PRFSD_VCB)(FcbOrVcb), FALSE);
227 
228  if (NT_SUCCESS(Status)) {
229  _SEH2_LEAVE;
230  }
231 
232  Status = RfsdFlushVolume((PRFSD_VCB)(FcbOrVcb), FALSE);
233 
234  if (NT_SUCCESS(Status) && IsFlagOn(Vcb->StreamObj->Flags, FO_FILE_MODIFIED)) {
235  ClearFlag(Vcb->StreamObj->Flags, FO_FILE_MODIFIED);
236  }
237 
238  } else if (FcbOrVcb->Identifier.Type == RFSDFCB) {
239 
240  Status = RfsdFlushFile((PRFSD_FCB)(FcbOrVcb));
241 
244  }
245  }
246 
247  } _SEH2_FINALLY {
248 
249  if (MainResourceAcquired) {
251  &FcbOrVcb->MainResource,
253  }
254 
255  if (!IrpContext->ExceptionInProgress) {
256 
257  if (!IsFlagOn(Vcb->Flags, VCB_READ_ONLY)) {
258 
259  // Call the disk driver to flush the physial media.
260  NTSTATUS DriverStatus;
262  PIO_STACK_LOCATION NextIrpSp;
263 
264  IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp);
265  NextIrpSp = IoGetNextIrpStackLocation(IrpContext->Irp);
266 
267  *NextIrpSp = *IrpSp;
268 
269  IoSetCompletionRoutine( IrpContext->Irp,
271  NULL,
272  TRUE,
273  TRUE,
274  TRUE );
275 
276  DriverStatus = IoCallDriver(Vcb->TargetDeviceObject, IrpContext->Irp);
277 
278  Status = (DriverStatus == STATUS_INVALID_DEVICE_REQUEST) ?
279  Status : DriverStatus;
280 
281  IrpContext->Irp = Irp = NULL;
282  }
283 
284  RfsdCompleteIrpContext(IrpContext, Status);
285  }
286  } _SEH2_END;
287 
288  return Status;
289 }
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define IsMounted(Vcb)
Definition: ext2fs.h:803
NTSTATUS RfsdCompleteIrpContext(IN PRFSD_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: memory.c:160
#define TRUE
Definition: types.h:120
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
Definition: rfsd.h:323
PDEVICE_OBJECT DeviceObject
Definition: rfsd.h:407
_SEH2_TRY
Definition: create.c:4250
Definition: rfsd.h:324
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FO_FILE_MODIFIED
Definition: iotypes.h:1745
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
RFSD_IDENTIFIER_TYPE Type
Definition: rfsd.h:336
Definition: rfsd.h:326
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct _RFSD_VCB * PRFSD_VCB
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1425
NTSTATUS RfsdFlushFile(IN PRFSD_FCB Fcb)
Definition: flush.c:119
* PFILE_OBJECT
Definition: iotypes.h:1955
struct _RFSD_FCBVCB * PRFSD_FCBVCB
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushFiles(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:51
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define VCB_READ_ONLY
Definition: ext2fs.h:795
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ERESOURCE MainResource
Definition: rfsd.h:465
NTSTATUS NTAPI RfsdFlushCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Contxt)
Definition: flush.c:33
_SEH2_END
Definition: create.c:4424
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_SEH2_FINALLY
Definition: create.c:4395
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
RFSD_IDENTIFIER Identifier
Definition: rfsd.h:470
#define _SEH2_LEAVE
Definition: filesup.c:20
return STATUS_SUCCESS
Definition: btrfs.c:3014
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushVolume(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:97
#define PAGED_CODE()

Referenced by RfsdDispatchRequest().

◆ RfsdFlushCompletionRoutine()

NTSTATUS NTAPI RfsdFlushCompletionRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Contxt 
)

Definition at line 33 of file flush.c.

38 {
39  if (Irp->PendingReturned)
41 
42 
43  if (Irp->IoStatus.Status == STATUS_INVALID_DEVICE_REQUEST)
44  Irp->IoStatus.Status = STATUS_SUCCESS;
45 
46  return STATUS_SUCCESS;
47 }
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
return STATUS_SUCCESS
Definition: btrfs.c:3014
IoMarkIrpPending(Irp)

Referenced by RfsdFlush().

◆ RfsdFlushFile()

NTSTATUS RfsdFlushFile ( IN PRFSD_FCB  Fcb)

Definition at line 119 of file flush.c.

120 {
122 
123  PAGED_CODE();
124 
125  ASSERT(Fcb != NULL);
126 
127  ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
128  (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
129 
130  if (IsDirectory(Fcb))
131  return STATUS_SUCCESS;
132 
133  RfsdPrint((DBG_INFO, "RfsdFlushFile: Flushing File Key=%x,%xh %S ...\n",
134  Fcb->RfsdMcb->Key.k_dir_id, Fcb->RfsdMcb->Key.k_objectid, Fcb->RfsdMcb->ShortName.Buffer));
135 /*
136  {
137  ULONG ResShCnt, ResExCnt;
138  ResShCnt = ExIsResourceAcquiredSharedLite(&Fcb->PagingIoResource);
139  ResExCnt = ExIsResourceAcquiredExclusiveLite(&Fcb->PagingIoResource);
140 
141  RfsdPrint((DBG_INFO, "RfsdFlushFile: PagingIoRes: %xh:%xh\n", ResShCnt, ResExCnt));
142  }
143 */
144  CcFlushCache(&(Fcb->SectionObject), NULL, 0, &IoStatus);
145 
147 
148  return IoStatus.Status;
149 }
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 PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
Definition: rfsd.h:324
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:532
_Must_inspect_result_ _In_ PFLT_INSTANCE _Out_ PBOOLEAN IsDirectory
Definition: fltkernel.h:1139
#define RfsdPrint(arg)
Definition: rfsd.h:1069
ULONG Type
Definition: ntfs.h:95
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:873
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
#define DBG_INFO
Definition: ffsdrv.h:1034
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:3014
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
ULONG Size
Definition: ntfs.h:96
#define PAGED_CODE()

Referenced by RfsdCleanup(), RfsdFlush(), and RfsdFlushFiles().

◆ RfsdFlushFiles()

__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushFiles ( IN PRFSD_VCB  Vcb,
BOOLEAN  bShutDown 
)

Definition at line 51 of file flush.c.

52 {
54  PRFSD_FCB Fcb;
55  PLIST_ENTRY ListEntry;
56 
57  PAGED_CODE();
58 
59  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
60  IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED)) {
61  return STATUS_SUCCESS;
62  }
63 
64  RfsdPrint((DBG_INFO, "Flushing Files ...\n"));
65 
66  // Flush all Fcbs in Vcb list queue.
67  {
68  for (ListEntry = Vcb->FcbList.Flink;
69  ListEntry != &Vcb->FcbList;
70  ListEntry = ListEntry->Flink ) {
71 
72  Fcb = CONTAINING_RECORD(ListEntry, RFSD_FCB, Next);
73 
75  &Fcb->MainResource,
76  TRUE )) {
77 
78  IoStatus.Status = RfsdFlushFile(Fcb);
79 /*
80  if (bShutDown)
81  IoStatus.Status = RfsdPurgeFile(Fcb, TRUE);
82  else
83  IoStatus.Status = RfsdFlushFile(Fcb);
84 */
86  &Fcb->MainResource,
88  }
89  }
90  }
91 
92  return IoStatus.Status;
93 }
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
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:120
#define Vcb
Definition: cdprocs.h:1425
NTSTATUS RfsdFlushFile(IN PRFSD_FCB Fcb)
Definition: flush.c:119
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
#define RfsdPrint(arg)
Definition: rfsd.h:1069
Definition: typedefs.h:118
ERESOURCE MainResource
Definition: ntfs.h:524
#define VCB_READ_ONLY
Definition: ext2fs.h:795
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define DBG_INFO
Definition: ffsdrv.h:1034
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by RfsdCreateVolume(), RfsdDismountVolume(), RfsdFlush(), and RfsdShutDown().

◆ RfsdFlushVolume()

__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushVolume ( IN PRFSD_VCB  Vcb,
BOOLEAN  bShutDown 
)

Definition at line 97 of file flush.c.

98 {
100 
101  PAGED_CODE();
102 
103  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
104  IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED)) {
105  return STATUS_SUCCESS;
106  }
107 
108  RfsdPrint((DBG_INFO, "RfsdFlushVolume: Flushing Vcb ...\n"));
109 
110  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
111  ExReleaseResourceLite(&Vcb->PagingIoResource);
112 
113  CcFlushCache(&(Vcb->SectionObject), NULL, 0, &IoStatus);
114 
115  return IoStatus.Status;
116 }
#define TRUE
Definition: types.h:120
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 PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
smooth NULL
Definition: ftsmooth.c:416
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
#define RfsdPrint(arg)
Definition: rfsd.h:1069
#define VCB_READ_ONLY
Definition: ext2fs.h:795
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
#define DBG_INFO
Definition: ffsdrv.h:1034
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by RfsdCreateVolume(), RfsdDismountVolume(), RfsdFlush(), and RfsdShutDown().

Variable Documentation

◆ RfsdGlobal

PRFSD_GLOBAL RfsdGlobal

Definition at line 17 of file init.c.

Referenced by RfsdFlush().