ReactOS  0.4.14-dev-52-g6116262
flush.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: GNU GENERAL PUBLIC LICENSE VERSION 2
3  * PROJECT: ReiserFs file system driver for Windows NT/2000/XP/Vista.
4  * FILE: flush.c
5  * PURPOSE:
6  * PROGRAMMER: Mark Piper, Matt Wu, Bo BrantÚn.
7  * HOMEPAGE:
8  * UPDATE HISTORY:
9  */
10 
11 /* INCLUDES *****************************************************************/
12 
13 #include "rfsd.h"
14 
15 /* GLOBALS ***************************************************************/
16 
18 
19 /* DEFINITIONS *************************************************************/
20 
21 #ifdef ALLOC_PRAGMA
22 #pragma alloc_text(PAGE, RfsdFlushFile)
23 #pragma alloc_text(PAGE, RfsdFlushFiles)
24 #pragma alloc_text(PAGE, RfsdFlushVolume)
25 #pragma alloc_text(PAGE, RfsdFlush)
26 #endif
27 
28 #ifdef _PREFAST_
29 IO_COMPLETION_ROUTINE RfsdFlushCompletionRoutine;
30 #endif // _PREFAST_
31 
35  IN PIRP Irp,
36  IN PVOID Contxt )
37 
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 }
48 
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 }
94 
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 }
117 
118 NTSTATUS
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 }
150 
152 NTSTATUS
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 IN
Definition: typedefs.h:38
#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
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
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
PRFSD_GLOBAL RfsdGlobal
Definition: init.c:17
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
volatile BOOL bShutDown
Definition: ServiceMain.c:12
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
Definition: rfsd.h:323
#define PAGED_CODE()
Definition: video.h:57
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:515
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FO_FILE_MODIFIED
Definition: iotypes.h:1745
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#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
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 _RFSD_VCB * PRFSD_VCB
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#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
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* 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)
ULONG Flags
Definition: ntfs.h:532
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
_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
Definition: typedefs.h:117
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
ERESOURCE MainResource
Definition: ntfs.h:524
#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
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlush(IN PRFSD_IRP_CONTEXT IrpContext)
Definition: flush.c:153
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
#define DBG_INFO
Definition: ffsdrv.h:1034
RFSD_IDENTIFIER Identifier
Definition: rfsd.h:470
#define _SEH2_LEAVE
Definition: filesup.c:20
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2966
IoMarkIrpPending(Irp)
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
ULONG Size
Definition: ntfs.h:96
__drv_mustHoldCriticalRegion NTSTATUS RfsdFlushVolume(IN PRFSD_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:97