ReactOS  0.4.14-dev-49-gfb4591c
flush.c File Reference
#include "ntifs.h"
#include "ffsdrv.h"
Include dependency graph for flush.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI FFSFlushCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Contxt)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSFlushFiles (IN PFFS_VCB Vcb, BOOLEAN bShutDown)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSFlushVolume (IN PFFS_VCB Vcb, BOOLEAN bShutDown)
 
NTSTATUS FFSFlushFile (IN PFFS_FCB Fcb)
 
__drv_mustHoldCriticalRegion NTSTATUS FFSFlush (IN PFFS_IRP_CONTEXT IrpContext)
 

Variables

PFFS_GLOBAL FFSGlobal
 

Function Documentation

◆ FFSFlush()

Definition at line 169 of file flush.c.

171 {
173 
174  PIRP Irp;
176 
177  PFFS_VCB Vcb = 0;
178  PFFS_FCBVCB FcbOrVcb = 0;
180 
182 
183  BOOLEAN MainResourceAcquired = FALSE;
184 
185  PAGED_CODE();
186 
187  _SEH2_TRY
188  {
189  ASSERT(IrpContext);
190 
191  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
192  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
193 
194  DeviceObject = IrpContext->DeviceObject;
195 
196  //
197  // This request is not allowed on the main device object
198  //
200  {
202  _SEH2_LEAVE;
203  }
204 
206 
207  ASSERT(Vcb != NULL);
208 
209  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
210  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
211 
212  ASSERT(IsMounted(Vcb));
213 
214  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
216  {
218  _SEH2_LEAVE;
219  }
220 
221  Irp = IrpContext->Irp;
222 
224 
225  FileObject = IrpContext->FileObject;
226 
227  FcbOrVcb = (PFFS_FCBVCB)FileObject->FsContext;
228 
229  ASSERT(FcbOrVcb != NULL);
230 #ifdef _MSC_VER
231 #pragma prefast( suppress: 28137, "by design" )
232 #endif
234  &FcbOrVcb->MainResource,
235  IrpContext->IsSynchronous))
236  {
238  _SEH2_LEAVE;
239  }
240 
241  MainResourceAcquired = TRUE;
242 
243  if (FcbOrVcb->Identifier.Type == FFSVCB)
244  {
245  Status = FFSFlushFiles((PFFS_VCB)(FcbOrVcb), FALSE);
246 
247  if (NT_SUCCESS(Status))
248  {
249  _SEH2_LEAVE;
250  }
251 
252  Status = FFSFlushVolume((PFFS_VCB)(FcbOrVcb), FALSE);
253 
254  if (NT_SUCCESS(Status) && IsFlagOn(Vcb->StreamObj->Flags, FO_FILE_MODIFIED))
255  {
256  ClearFlag(Vcb->StreamObj->Flags, FO_FILE_MODIFIED);
257  }
258  }
259  else if (FcbOrVcb->Identifier.Type == FFSFCB)
260  {
261  Status = FFSFlushFile((PFFS_FCB)(FcbOrVcb));
262 
264  {
266  }
267  }
268  }
269 
271  {
272  if (MainResourceAcquired)
273  {
275  &FcbOrVcb->MainResource,
277  }
278 
279  if (!IrpContext->ExceptionInProgress)
280  {
281  if (!IsFlagOn(Vcb->Flags, VCB_READ_ONLY))
282  {
283  // Call the disk driver to flush the physial media.
284  NTSTATUS DriverStatus;
285  PIO_STACK_LOCATION NextIrpSp;
286 
287  IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp);
288  NextIrpSp = IoGetNextIrpStackLocation(IrpContext->Irp);
289 
290  *NextIrpSp = *IrpSp;
291 
292  IoSetCompletionRoutine(IrpContext->Irp,
294  NULL,
295  TRUE,
296  TRUE,
297  TRUE);
298 
299  DriverStatus = IoCallDriver(Vcb->TargetDeviceObject, IrpContext->Irp);
300 
301  Status = (DriverStatus == STATUS_INVALID_DEVICE_REQUEST) ?
302  Status : DriverStatus;
303 
304  IrpContext->Irp = NULL;
305  }
306 
307  FFSCompleteIrpContext(IrpContext, Status);
308  }
309  } _SEH2_END;
310 
311  return Status;
312 }
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
Definition: ffsdrv.h:281
#define IsMounted(Vcb)
Definition: ext2fs.h:803
#define TRUE
Definition: types.h:120
NTSTATUS FFSFlushFile(IN PFFS_FCB Fcb)
Definition: flush.c:133
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
Definition: ffsdrv.h:283
PDEVICE_OBJECT DeviceObject
Definition: ffsdrv.h:371
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
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
struct _FFS_VCB * PFFS_VCB
FFS_IDENTIFIER_TYPE Type
Definition: ffsdrv.h:294
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct _FFS_FCBVCB * PFFS_FCBVCB
__drv_mustHoldCriticalRegion NTSTATUS FFSFlushVolume(IN PFFS_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:107
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
__drv_mustHoldCriticalRegion NTSTATUS FFSFlushFiles(IN PFFS_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:54
#define Vcb
Definition: cdprocs.h:1425
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
FFS_IDENTIFIER Identifier
Definition: ffsdrv.h:426
Definition: ffsdrv.h:280
__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
_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
ERESOURCE MainResource
Definition: ffsdrv.h:421
#define _SEH2_LEAVE
Definition: filesup.c:20
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS NTAPI FFSFlushCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Contxt)
Definition: flush.c:36

Referenced by FFSDispatchRequest().

◆ FFSFlushCompletionRoutine()

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

Definition at line 36 of file flush.c.

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

Referenced by FFSFlush().

◆ FFSFlushFile()

NTSTATUS FFSFlushFile ( IN PFFS_FCB  Fcb)

Definition at line 133 of file flush.c.

135 {
137 
138  PAGED_CODE();
139 
140  ASSERT(Fcb != NULL);
141 
142  ASSERT((Fcb->Identifier.Type == FFSFCB) &&
143  (Fcb->Identifier.Size == sizeof(FFS_FCB)));
144 
145  if (IsDirectory(Fcb))
146  return STATUS_SUCCESS;
147 
148  FFSPrint((DBG_INFO, "FFSFlushFile: Flushing File Inode=%xh %S ...\n",
149  Fcb->FFSMcb->Inode, Fcb->FFSMcb->ShortName.Buffer));
150  /*
151  {
152  ULONG ResShCnt, ResExCnt;
153  ResShCnt = ExIsResourceAcquiredSharedLite(&Fcb->PagingIoResource);
154  ResExCnt = ExIsResourceAcquiredExclusiveLite(&Fcb->PagingIoResource);
155 
156  FFSPrint((DBG_INFO, "FFSFlushFile: PagingIoRes: %xh:%xh\n", ResShCnt, ResExCnt));
157  }
158  */
159  CcFlushCache(&(Fcb->SectionObject), NULL, 0, &IoStatus);
160 
162 
163  return IoStatus.Status;
164 }
Definition: ffsdrv.h:281
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 PAGED_CODE()
Definition: video.h:57
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
ULONG Type
Definition: ntfs.h:95
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:873
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
#define DBG_INFO
Definition: ffsdrv.h:1034
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
ULONG Size
Definition: ntfs.h:96

Referenced by FFSCleanup(), FFSFlush(), and FFSFlushFiles().

◆ FFSFlushFiles()

__drv_mustHoldCriticalRegion NTSTATUS FFSFlushFiles ( IN PFFS_VCB  Vcb,
BOOLEAN  bShutDown 
)

Definition at line 54 of file flush.c.

57 {
59 
60  PFFS_FCB Fcb;
61  PLIST_ENTRY ListEntry;
62 
63  PAGED_CODE();
64 
65  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
67  {
68  return STATUS_SUCCESS;
69  }
70 
71  FFSPrint((DBG_INFO, "Flushing Files ...\n"));
72 
73  // Flush all Fcbs in Vcb list queue.
74  {
75  for (ListEntry = Vcb->FcbList.Flink;
76  ListEntry != &Vcb->FcbList;
77  ListEntry = ListEntry->Flink)
78  {
79  Fcb = CONTAINING_RECORD(ListEntry, FFS_FCB, Next);
80 
82  &Fcb->MainResource,
83  TRUE))
84  {
85  IoStatus.Status = FFSFlushFile(Fcb);
86 #if 0
87 /*
88  if (bShutDown)
89  IoStatus.Status = FFSPurgeFile(Fcb, TRUE);
90  else
91  IoStatus.Status = FFSFlushFile(Fcb);
92 */
93 #endif
95  &Fcb->MainResource,
97  }
98  }
99  }
100 
101  return IoStatus.Status;
102 }
#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
NTSTATUS FFSFlushFile(IN PFFS_FCB Fcb)
Definition: flush.c:133
#define PAGED_CODE()
Definition: video.h:57
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:119
#define Vcb
Definition: cdprocs.h:1425
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
Definition: typedefs.h:117
ERESOURCE MainResource
Definition: ntfs.h:524
#define VCB_READ_ONLY
Definition: ext2fs.h:795
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
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:2966

Referenced by FFSCreateVolume(), FFSDismountVolume(), FFSFlush(), and FFSShutDown().

◆ FFSFlushVolume()

__drv_mustHoldCriticalRegion NTSTATUS FFSFlushVolume ( IN PFFS_VCB  Vcb,
BOOLEAN  bShutDown 
)

Definition at line 107 of file flush.c.

110 {
112 
113  PAGED_CODE();
114 
115  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
117  {
118  return STATUS_SUCCESS;
119  }
120 
121  FFSPrint((DBG_INFO, "FFSFlushVolume: Flushing Vcb ...\n"));
122 
123  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
124  ExReleaseResourceLite(&Vcb->PagingIoResource);
125 
126  CcFlushCache(&(Vcb->SectionObject), NULL, 0, &IoStatus);
127 
128  return IoStatus.Status;
129 }
#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 PAGED_CODE()
Definition: video.h:57
#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 VCB_READ_ONLY
Definition: ext2fs.h:795
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
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:2966

Referenced by FFSCreateVolume(), FFSDismountVolume(), FFSFlush(), and FFSShutDown().

Variable Documentation

◆ FFSGlobal

PFFS_GLOBAL FFSGlobal

Definition at line 22 of file init.c.

Referenced by FFSFlush().