ReactOS  0.4.14-dev-1007-g90d795b
verfysup.c File Reference
#include "fatprocs.h"
Include dependency graph for verfysup.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (FAT_BUG_CHECK_VERFYSUP)
 
#define Dbg   (DEBUG_TRACE_VERFYSUP)
 

Functions

VOID FatResetFcb (IN PIRP_CONTEXT IrpContext, IN PFCB Fcb)
 
BOOLEAN FatMatchFileSize (__in PIRP_CONTEXT IrpContext, __in PDIRENT Dirent, __in PFCB Fcb)
 
 _Requires_lock_held_ (_Global_critical_region_)
 
BOOLEAN FatMarkDevForVerifyIfVcbMounted (IN PVCB Vcb)
 
VOID FatVerifyVcb (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
 
VOID NTAPI FatDeferredCleanVolume (_In_ PVOID Parameter)
 
VOID NTAPI FatCleanVolumeDpc (_In_ PKDPC Dpc, _In_opt_ PVOID DeferredContext, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2)
 
VOID NTAPI FatFspMarkVolumeDirtyWithRecover (PVOID Parameter)
 
VOID FatCheckDirtyBit (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
 
VOID FatVerifyOperationIsLegal (IN PIRP_CONTEXT IrpContext)
 
VOID FatQuickVerifyVcb (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
 
NTSTATUS NTAPI FatMarkVolumeCompletionRoutine (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_reads_opt_(_Inexpressible_("varies")) PVOID Contxt)
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (FAT_BUG_CHECK_VERFYSUP)

Definition at line 23 of file verfysup.c.

◆ Dbg

#define Dbg   (DEBUG_TRACE_VERFYSUP)

Definition at line 29 of file verfysup.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 48 of file verfysup.c.

119 {
120  PAGED_CODE();
121 
122  DebugTrace(+1, Dbg, "FatMarkFcbCondition, Fcb = %p\n", Fcb );
123 
124  //
125  // If we are marking this Fcb something other than Good, we will need
126  // to have the Vcb exclusive.
127  //
128 
129  NT_ASSERT( FcbCondition != FcbNeedsToBeVerified ? TRUE :
130  FatVcbAcquiredExclusive(IrpContext, Fcb->Vcb) );
131 
132  //
133  // If this is a PagingFile it has to be good unless media underneath is
134  // removable. The "removable" check was added specifically for ReadyBoost,
135  // which opens its cache file on a removable device as a paging file and
136  // relies on the file system to validate its mapping information after a
137  // power transition.
138  //
139 
142 
144  return;
145  }
146 
147  //
148  // Update the condition of the Fcb.
149  //
150 
151  Fcb->FcbCondition = FcbCondition;
152 
153  DebugTrace(0, Dbg, "MarkFcb: %wZ\n", &Fcb->FullFileName);
154 
155  //
156  // This FastIo flag is based on FcbCondition, so update it now. This only
157  // applies to regular FCBs, of course.
158  //
159 
160  if (Fcb->Header.NodeTypeCode == FAT_NTC_FCB) {
161 
162  Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
163  }
164 
165  if (FcbCondition == FcbNeedsToBeVerified) {
166  FatResetFcb( IrpContext, Fcb );
167  }
168 
169  //
170  // Now if we marked NeedsVerify or Bad a directory then we also need to
171  // go and mark all of our children with the same condition.
172  //
173 
174  if ( ((FcbCondition == FcbNeedsToBeVerified) ||
175  (FcbCondition == FcbBad)) &&
176  Recursive &&
177  ((Fcb->Header.NodeTypeCode == FAT_NTC_DCB) ||
178  (Fcb->Header.NodeTypeCode == FAT_NTC_ROOT_DCB)) ) {
179 
180  PFCB OriginalFcb = Fcb;
181 
182  while ( (Fcb = FatGetNextFcbTopDown(IrpContext, Fcb, OriginalFcb)) != NULL ) {
183 
184  DebugTrace(0, Dbg, "MarkFcb: %wZ\n", &Fcb->FullFileName);
185 
186  Fcb->FcbCondition = FcbCondition;
187 
188  //
189  // We already know that FastIo is not possible since we are propagating
190  // a parent's bad/verify flag down the tree - IO to the children must
191  // take the long route for now.
192  //
193 
194  Fcb->Header.IsFastIoPossible = FastIoIsNotPossible;
195 
196  //
197  // Leave all the Fcbs in a condition to be verified.
198  //
199 
200  if (FcbCondition == FcbNeedsToBeVerified) {
201  FatResetFcb( IrpContext, Fcb );
202  }
203 
204  }
205  }
206 
207  DebugTrace(-1, Dbg, "FatMarkFcbCondition -> VOID\n", 0);
208 
209  return;
210 }
#define TRUE
Definition: types.h:120
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
Definition: cdstruc.h:908
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
ULONG VcbState
Definition: cdstruc.h:546
#define PAGED_CODE()
Definition: video.h:57
#define Dbg
Definition: verfysup.c:29
#define FCB_STATE_PAGING_FILE
Definition: fatstruc.h:1194
smooth NULL
Definition: ftsmooth.c:416
#define VCB_STATE_FLAG_REMOVABLE_MEDIA
Definition: fatstruc.h:559
VOID FatResetFcb(IN PIRP_CONTEXT IrpContext, IN PFCB Fcb)
Definition: verfysup.c:1400
UNICODE_STRING FullFileName
Definition: fatstruc.h:1121
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatIsFastIoPossible(FCB)
Definition: fatprocs.h:2801
#define FAT_NTC_ROOT_DCB
Definition: nodetype.h:31
#define FAT_NTC_DCB
Definition: nodetype.h:30
#define FatVcbAcquiredExclusive(IRPCONTEXT, VCB)
Definition: fatprocs.h:1486
PVCB Vcb
Definition: cdstruc.h:939
_In_ PFCB Fcb
Definition: cdprocs.h:151
ULONG FcbState
Definition: cdstruc.h:977
#define FAT_NTC_FCB
Definition: nodetype.h:29
#define NT_ASSERT
Definition: rtlfuncs.h:3312
PFCB FatGetNextFcbTopDown(IN PIRP_CONTEXT IrpContext, IN PFCB Fcb, IN PFCB TerminationFcb)
Definition: strucsup.c:2626
FCB_CONDITION FcbCondition
Definition: fatstruc.h:849

◆ FatCheckDirtyBit()

VOID FatCheckDirtyBit ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb 
)

Definition at line 1189 of file verfysup.c.

1211 {
1212  BOOLEAN Dirty;
1213 
1215  PBCB BootSectorBcb;
1216 
1217  UNICODE_STRING VolumeLabel;
1218 
1219  PAGED_CODE();
1220 
1221  //
1222  // Look in the boot sector
1223  //
1224 
1225  FatReadVolumeFile( IrpContext,
1226  Vcb,
1227  0,
1228  sizeof(PACKED_BOOT_SECTOR),
1229  &BootSectorBcb,
1230  (PVOID *)&BootSector );
1231 
1232  _SEH2_TRY {
1233 
1234  //
1235  // Check if the magic bit is set
1236  //
1237 
1238  if (IsBpbFat32(&BootSector->PackedBpb)) {
1239  Dirty = BooleanFlagOn( ((PPACKED_BOOT_SECTOR_EX)BootSector)->CurrentHead,
1241  } else {
1242  Dirty = BooleanFlagOn( BootSector->CurrentHead, FAT_BOOT_SECTOR_DIRTY );
1243  }
1244 
1245  //
1246  // Setup the VolumeLabel string
1247  //
1248 
1249  VolumeLabel.Length = Vcb->Vpb->VolumeLabelLength;
1251  VolumeLabel.Buffer = &Vcb->Vpb->VolumeLabel[0];
1252 
1253  if ( Dirty ) {
1254 
1255  //
1256  // Do not trigger the mounted dirty bit if this is a verify
1257  // and the volume is a boot or paging device. We know that
1258  // a boot or paging device cannot leave the system, and thus
1259  // that on its mount we will have figured this out correctly.
1260  //
1261  // This logic is a reasonable change. Why?
1262  // 'cause setup cracked a non-exclusive DASD handle near the
1263  // end of setup, wrote some data, closed the handle and we
1264  // set the verify bit ... came back around and saw that other
1265  // arbitrary activity had left the volume in a temporarily dirty
1266  // state.
1267  //
1268  // Of course, the real problem is that we don't have a journal.
1269  //
1270 
1271  if (!(IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL &&
1272  IrpContext->MinorFunction == IRP_MN_VERIFY_VOLUME &&
1274 
1277  "FASTFAT: WARNING! Mounting Dirty Volume %Z\n",
1278  &VolumeLabel));
1279 
1281  }
1282 
1283  } else {
1284 
1285  if (FlagOn(Vcb->VcbState, VCB_STATE_FLAG_MOUNTED_DIRTY)) {
1286 
1289  "FASTFAT: Volume %Z has been cleaned.\n",
1290  &VolumeLabel));
1291 
1293 
1294  } else {
1295 
1296  (VOID)FsRtlBalanceReads( Vcb->TargetDeviceObject );
1297  }
1298  }
1299 
1300  } _SEH2_FINALLY {
1301 
1302  FatUnpinBcb( IrpContext, BootSectorBcb );
1303  } _SEH2_END;
1304 }
#define IsBpbFat32(bpb)
Definition: fat.h:101
#define VCB_STATE_FLAG_MOUNTED_DIRTY
Definition: fatstruc.h:561
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define FAT_BOOT_SECTOR_DIRTY
Definition: fat.h:213
#define DPFLTR_INFO_LEVEL
Definition: kdtypes.h:33
VOID FatReadVolumeFile(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN VBO StartingVbo, IN ULONG ByteCount, OUT PBCB *Bcb, OUT PVOID *Buffer)
Definition: cachesup.c:102
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define KdPrintEx(_x_)
Definition: kdfuncs.h:114
struct _BootSector BootSector
Definition: vfat.h:108
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4049
#define FatUnpinBcb(IRPCONTEXT, BCB)
Definition: fatprocs.h:537
unsigned char BOOLEAN
#define MAXIMUM_VOLUME_LABEL_LENGTH
Definition: iotypes.h:154
#define VCB_STATE_FLAG_BOOT_OR_PAGING_FILE
Definition: fatstruc.h:566
NTSTATUS NTAPI FsRtlBalanceReads(PDEVICE_OBJECT TargetDevice)
Definition: faulttol.c:35
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define Vcb
Definition: cdprocs.h:1425
#define VOID
Definition: acefi.h:82
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
_SEH2_FINALLY
Definition: create.c:4395

◆ FatCleanVolumeDpc()

VOID NTAPI FatCleanVolumeDpc ( _In_ PKDPC  Dpc,
_In_opt_ PVOID  DeferredContext,
_In_opt_ PVOID  SystemArgument1,
_In_opt_ PVOID  SystemArgument2 
)

Definition at line 654 of file verfysup.c.

679 {
680  PVCB Vcb;
682 
686 
688 
689 
690  //
691  // If there is still dirty data (highly unlikely), set the timer for a
692  // second in the future.
693  //
694 
695  if (CcIsThereDirtyData(Vcb->Vpb)) {
696 
697  LARGE_INTEGER TwoSecondsFromNow;
698 
699  TwoSecondsFromNow.QuadPart = (LONG)-2*1000*1000*10;
700 
701  KeSetTimer( &Vcb->CleanVolumeTimer,
702  TwoSecondsFromNow,
703  &Vcb->CleanVolumeDpc );
704 
705  return;
706  }
707 
708  //
709  // If we couldn't get pool, oh well....
710  //
711 
712 #ifndef __REACTOS__
713  Packet = ExAllocatePoolWithTag(NonPagedPoolNx, sizeof(CLEAN_AND_DIRTY_VOLUME_PACKET), ' taF');
714 #else
716 #endif
717 
718  if ( Packet ) {
719 
720  Packet->Vcb = Vcb;
721  Packet->Irp = NULL;
722 
723  //
724  // Clear the dirty flag now since we cannot synchronize after this point.
725  //
726 
727  ClearFlag( Packet->Vcb->VcbState, VCB_STATE_FLAG_VOLUME_DIRTY );
728 
730 
731 #ifdef _MSC_VER
732 #pragma prefast( suppress:28159, "prefast indicates this is an obsolete API, but it is ok for fastfat to keep using it" )
733 #endif
735  }
736 
737  return;
738 }
#define VCB_STATE_FLAG_VOLUME_DIRTY
Definition: fatstruc.h:560
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
BOOLEAN NTAPI CcIsThereDirtyData(IN PVPB Vpb)
Definition: logsup.c:55
Definition: cdstruc.h:504
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
_In_ LARGE_INTEGER _In_opt_ PKDPC Dpc
Definition: kefuncs.h:511
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
VOID NTAPI FatDeferredCleanVolume(_In_ PVOID Parameter)
Definition: verfysup.c:499
#define Vcb
Definition: cdprocs.h:1425
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
struct _VCB * PVCB
Definition: fatstruc.h:556
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
LONGLONG QuadPart
Definition: typedefs.h:113
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675

◆ FatDeferredCleanVolume()

VOID NTAPI FatDeferredCleanVolume ( _In_ PVOID  Parameter)

Definition at line 499 of file verfysup.c.

521 {
523  PLIST_ENTRY Links;
524  PVCB Vcb;
525  IRP_CONTEXT IrpContext;
526  BOOLEAN VcbExists = FALSE;
527 
528  PAGED_CODE();
529 
530  DebugTrace(+1, Dbg, "FatDeferredCleanVolume\n", 0);
531 
533 
534  Vcb = Packet->Vcb;
535 
536  //
537  // Make us appear as a top level FSP request so that we will
538  // receive any errors from the operation.
539  //
540 
542 
543  //
544  // Dummy up and Irp Context so we can call our worker routines
545  //
546 
547  RtlZeroMemory( &IrpContext, sizeof(IRP_CONTEXT));
548 
549  SetFlag(IrpContext.Flags, IRP_CONTEXT_FLAG_WAIT);
550 
551  //
552  // Acquire shared access to the global lock and make sure this volume
553  // still exists.
554  //
555 
556 #ifdef _MSC_VER
557 #pragma prefast( push )
558 #pragma prefast( disable: 28193, "this will always wait" )
559 #endif
560  FatAcquireSharedGlobal( &IrpContext );
561 #ifdef _MSC_VER
562 #pragma prefast( pop )
563 #endif
564 
565  for (Links = FatData.VcbQueue.Flink;
566  Links != &FatData.VcbQueue;
567  Links = Links->Flink) {
568 
569  PVCB ExistingVcb;
570 
571  ExistingVcb = CONTAINING_RECORD(Links, VCB, VcbLinks);
572 
573  if ( Vcb == ExistingVcb ) {
574 
575  VcbExists = TRUE;
576  break;
577  }
578  }
579 
580  //
581  // If the vcb is good then mark it clean. Ignore any problems.
582  //
583 
584  if ( VcbExists &&
585  (Vcb->VcbCondition == VcbGood) &&
586  !FlagOn(Vcb->VcbState, VCB_STATE_FLAG_SHUTDOWN) ) {
587 
588  _SEH2_TRY {
589 
590  if (!FlagOn(Vcb->VcbState, VCB_STATE_FLAG_MOUNTED_DIRTY)) {
591 
592  FatMarkVolume( &IrpContext, Vcb, VolumeClean );
593  }
594 
595  //
596  // Check for a pathological race condition, and fix it.
597  //
598 
599  if (FlagOn(Vcb->VcbState, VCB_STATE_FLAG_VOLUME_DIRTY)) {
600 
601  FatMarkVolume( &IrpContext, Vcb, VolumeDirty );
602 
603  } else {
604 
605  //
606  // Unlock the volume if it is removable.
607  //
608 
609  if (FlagOn(Vcb->VcbState, VCB_STATE_FLAG_REMOVABLE_MEDIA) &&
611 
612  FatToggleMediaEjectDisable( &IrpContext, Vcb, FALSE );
613  }
614  }
615 
618 
619  NOTHING;
620  } _SEH2_END;
621  }
622 
623  //
624  // Release the global resource, unpin and repinned Bcbs and return.
625  //
626 
627  FatReleaseGlobal( &IrpContext );
628 
629  _SEH2_TRY {
630 
631  FatUnpinRepinnedBcbs( &IrpContext );
632 
635 
636  NOTHING;
637  } _SEH2_END;
638 
640 
641  //
642  // and finally free the packet.
643  //
644 
645  ExFreePool( Packet );
646 
647  return;
648 }
BOOLEAN NTAPI FsRtlIsNtstatusExpected(IN NTSTATUS NtStatus)
Definition: filter.c:61
#define VCB_STATE_FLAG_VOLUME_DIRTY
Definition: fatstruc.h:560
#define TRUE
Definition: types.h:120
#define FatReleaseGlobal(IRPCONTEXT)
Definition: fatprocs.h:1627
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define VCB_STATE_FLAG_MOUNTED_DIRTY
Definition: fatstruc.h:561
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID FatUnpinRepinnedBcbs(IN PIRP_CONTEXT IrpContext)
Definition: cachesup.c:1407
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
Definition: cdstruc.h:504
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define PAGED_CODE()
Definition: video.h:57
#define Dbg
Definition: verfysup.c:29
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define VCB_STATE_FLAG_REMOVABLE_MEDIA
Definition: fatstruc.h:559
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 _CLEAN_AND_DIRTY_VOLUME_PACKET * PCLEAN_AND_DIRTY_VOLUME_PACKET
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
NTSTATUS FatToggleMediaEjectDisable(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN BOOLEAN PreventRemoval)
Definition: deviosup.c:3515
FAT_DATA FatData
Definition: fatdata.c:56
#define FatAcquireSharedGlobal(IRPCONTEXT)
Definition: fatprocs.h:1382
#define VCB_STATE_FLAG_BOOT_OR_PAGING_FILE
Definition: fatstruc.h:566
#define Vcb
Definition: cdprocs.h:1425
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define NOTHING
Definition: env_spec_w32.h:461
Definition: typedefs.h:118
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
LIST_ENTRY VcbQueue
Definition: fatstruc.h:48
#define VCB_STATE_FLAG_SHUTDOWN
Definition: fatstruc.h:562
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FatCleanVolumeDpc().

◆ FatFspMarkVolumeDirtyWithRecover()

VOID NTAPI FatFspMarkVolumeDirtyWithRecover ( PVOID  Parameter)

Definition at line 1102 of file verfysup.c.

1127 {
1129  PVCB Vcb;
1130  IRP_CONTEXT IrpContext;
1131  PIRP Irp;
1132 
1133  DebugTrace(+1, Dbg, "FatFspMarkVolumeDirtyWithRecover\n", 0);
1134 
1136 
1137  Vcb = Packet->Vcb;
1138  Irp = Packet->Irp;
1139 
1140  //
1141  // Dummy up the IrpContext so we can call our worker routines
1142  //
1143 
1144  RtlZeroMemory( &IrpContext, sizeof(IRP_CONTEXT));
1145 
1146  SetFlag(IrpContext.Flags, IRP_CONTEXT_FLAG_WAIT);
1147  IrpContext.OriginatingIrp = Irp;
1148 
1149  //
1150  // Make us appear as a top level FSP request so that we will
1151  // receive any errors from the operation.
1152  //
1153 
1155 
1156  //
1157  // Try to write out the dirty bit. If something goes wrong, we
1158  // tried.
1159  //
1160 
1161  _SEH2_TRY {
1162 
1164 
1165  FatMarkVolume( &IrpContext, Vcb, VolumeDirtyWithSurfaceTest );
1166 
1168 
1169  NOTHING;
1170  } _SEH2_END;
1171 
1173 
1174  //
1175  // Now complete the originating Irp or set the synchronous event.
1176  //
1177 
1178  if (Packet->Event) {
1179  KeSetEvent( Packet->Event, 0, FALSE );
1180  } else {
1182  }
1183 
1184  DebugTrace(-1, Dbg, "FatFspMarkVolumeDirtyWithRecover -> VOID\n", 0);
1185 }
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define VCB_STATE_FLAG_MOUNTED_DIRTY
Definition: fatstruc.h:561
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
_In_ PIRP Irp
Definition: csq.h:116
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
Definition: cdstruc.h:504
_In_ PVOID Parameter
Definition: ldrtypes.h:241
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define Dbg
Definition: verfysup.c:29
_SEH2_TRY
Definition: create.c:4250
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
struct _CLEAN_AND_DIRTY_VOLUME_PACKET * PCLEAN_AND_DIRTY_VOLUME_PACKET
#define Vcb
Definition: cdprocs.h:1425
#define FSRTL_FSP_TOP_LEVEL_IRP
Definition: fsrtltypes.h:59
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define NOTHING
Definition: env_spec_w32.h:461
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4424
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

◆ FatMarkDevForVerifyIfVcbMounted()

BOOLEAN FatMarkDevForVerifyIfVcbMounted ( IN PVCB  Vcb)

Definition at line 213 of file verfysup.c.

234 {
235  BOOLEAN Marked = FALSE;
236  KIRQL SavedIrql;
237 
238  IoAcquireVpbSpinLock( &SavedIrql );
239 
240 #ifdef _MSC_VER
241 #pragma prefast( push )
242 #pragma prefast( disable: 28175, "touching Vpb is ok for a filesystem" )
243 #endif
244 
245  if (Vcb->Vpb->RealDevice->Vpb == Vcb->Vpb) {
246 
247  SetFlag( Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME);
248  Marked = TRUE;
249  }
250  else {
251 
252  //
253  // Flag this to avoid the VPB spinlock in future passes.
254  //
255 
257  }
258 
259 #ifdef _MSC_VER
260 #pragma prefast( pop )
261 #endif
262 
263  IoReleaseVpbSpinLock( SavedIrql );
264 
265  return Marked;
266 }
#define TRUE
Definition: types.h:120
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1209
#define Marked(f)
Definition: render.c:146
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
#define Vcb
Definition: cdprocs.h:1425
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define VCB_STATE_VPB_NOT_ON_DEVICE
Definition: cdstruc.h:720
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1220

Referenced by FatQuickVerifyVcb().

◆ FatMarkVolumeCompletionRoutine()

NTSTATUS NTAPI FatMarkVolumeCompletionRoutine ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_reads_opt_(_Inexpressible_("varies")) PVOID  Contxt 
)

Definition at line 2017 of file verfysup.c.

2023 {
2024  //
2025  // Set the event so that our call will wake up.
2026  //
2027 
2028  KeSetEvent( (PKEVENT)Contxt, 0, FALSE );
2029 
2032 
2034 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

◆ FatMatchFileSize()

BOOLEAN FatMatchFileSize ( __in PIRP_CONTEXT  IrpContext,
__in PDIRENT  Dirent,
__in PFCB  Fcb 
)

Definition at line 1499 of file verfysup.c.

1504 {
1505 
1506  UNREFERENCED_PARAMETER(IrpContext);
1507 
1508  if (NodeType(Fcb) != FAT_NTC_FCB) {
1509  return TRUE;
1510  }
1511 
1512 
1513  if (Fcb->Header.FileSize.LowPart != Dirent->FileSize) {
1514  return FALSE;
1515  }
1516 
1517 
1518  return TRUE;
1519 }
#define TRUE
Definition: types.h:120
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
NodeType
Definition: Node.h:5
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT _Inout_ PDIRENT Dirent
Definition: cdprocs.h:429
_In_ PFCB Fcb
Definition: cdprocs.h:151
#define FAT_NTC_FCB
Definition: nodetype.h:29

◆ FatQuickVerifyVcb()

VOID FatQuickVerifyVcb ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb 
)

Definition at line 1666 of file verfysup.c.

1689 {
1690  PAGED_CODE();
1691 
1692  //
1693  // If the real device needs to be verified we'll set the
1694  // DeviceToVerify to be our real device and raise VerifyRequired.
1695  //
1696 
1697  if (FlagOn(Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME)) {
1698 
1699  DebugTrace(0, Dbg, "The Vcb needs to be verified\n", 0);
1700 
1701  IoSetHardErrorOrVerifyDevice( IrpContext->OriginatingIrp,
1702  Vcb->Vpb->RealDevice );
1703 
1704  FatRaiseStatus( IrpContext, STATUS_VERIFY_REQUIRED );
1705  }
1706 
1707  //
1708  // Based on the condition of the Vcb we'll either return to our
1709  // caller or raise an error condition
1710  //
1711 
1712  switch (Vcb->VcbCondition) {
1713 
1714  case VcbGood:
1715 
1716  DebugTrace(0, Dbg, "The Vcb is good\n", 0);
1717 
1718  //
1719  // Do a check here of an operation that would try to modify a
1720  // write protected media.
1721  //
1722 
1723  if (FlagOn(Vcb->VcbState, VCB_STATE_FLAG_WRITE_PROTECTED) &&
1724  ((IrpContext->MajorFunction == IRP_MJ_WRITE) ||
1725  (IrpContext->MajorFunction == IRP_MJ_SET_INFORMATION) ||
1726  (IrpContext->MajorFunction == IRP_MJ_SET_EA) ||
1727  (IrpContext->MajorFunction == IRP_MJ_FLUSH_BUFFERS) ||
1728  (IrpContext->MajorFunction == IRP_MJ_SET_VOLUME_INFORMATION) ||
1729  (IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL &&
1730  IrpContext->MinorFunction == IRP_MN_USER_FS_REQUEST &&
1731  IoGetCurrentIrpStackLocation(IrpContext->OriginatingIrp)->Parameters.FileSystemControl.FsControlCode ==
1733 
1734  //
1735  // Set the real device for the pop-up info, and set the verify
1736  // bit in the device object, so that we will force a verify
1737  // in case the user put the correct media back in.
1738  //
1739 
1740 
1741  IoSetHardErrorOrVerifyDevice( IrpContext->OriginatingIrp,
1742  Vcb->Vpb->RealDevice );
1743 
1745 
1747  }
1748 
1749  break;
1750 
1751  case VcbNotMounted:
1752 
1753  DebugTrace(0, Dbg, "The Vcb is not mounted\n", 0);
1754 
1755  //
1756  // Set the real device for the pop-up info, and set the verify
1757  // bit in the device object, so that we will force a verify
1758  // in case the user put the correct media back in.
1759  //
1760 
1761  IoSetHardErrorOrVerifyDevice( IrpContext->OriginatingIrp,
1762  Vcb->Vpb->RealDevice );
1763 
1764  FatRaiseStatus( IrpContext, STATUS_WRONG_VOLUME );
1765 
1766  break;
1767 
1768  case VcbBad:
1769 
1770  DebugTrace(0, Dbg, "The Vcb is bad\n", 0);
1771 
1772  if (FlagOn( Vcb->VcbState, VCB_STATE_FLAG_VOLUME_DISMOUNTED )) {
1773 
1775 
1776  } else {
1777 
1778  FatRaiseStatus( IrpContext, STATUS_FILE_INVALID );
1779  }
1780  break;
1781 
1782  default:
1783 
1784  DebugDump("Invalid VcbCondition\n", 0, Vcb);
1785 #ifdef _MSC_VER
1786 #pragma prefast( suppress:28159, "things are seriously wrong if we get here" )
1787 #endif
1788  FatBugCheck( Vcb->VcbCondition, 0, 0 );
1789  }
1790 }
#define IRP_MJ_FLUSH_BUFFERS
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
#define IRP_MJ_SET_VOLUME_INFORMATION
#define VCB_STATE_FLAG_WRITE_PROTECTED
Definition: fatstruc.h:569
#define STATUS_FILE_INVALID
Definition: ntstatus.h:374
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140
#define VCB_STATE_FLAG_VOLUME_DISMOUNTED
Definition: fatstruc.h:571
#define FatRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2965
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
#define FSCTL_MARK_VOLUME_DIRTY
Definition: nt_native.h:838
#define PAGED_CODE()
Definition: video.h:57
#define Dbg
Definition: verfysup.c:29
#define IRP_MJ_SET_EA
#define FatBugCheck(A, B, C)
Definition: nodetype.h:104
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4047
#define IRP_MJ_FILE_SYSTEM_CONTROL
BOOLEAN FatMarkDevForVerifyIfVcbMounted(IN PVCB Vcb)
Definition: verfysup.c:213
#define Vcb
Definition: cdprocs.h:1425
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:733
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
VOID NTAPI IoSetHardErrorOrVerifyDevice(IN PIRP Irp, IN PDEVICE_OBJECT DeviceObject)
Definition: util.c:316
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define DebugDump(STR, LEVEL, PTR)
Definition: fatdata.h:314

Referenced by _Requires_lock_held_(), and FatVerifyVcb().

◆ FatResetFcb()

VOID FatResetFcb ( IN PIRP_CONTEXT  IrpContext,
IN PFCB  Fcb 
)

Definition at line 1400 of file verfysup.c.

1427 {
1428  LOGICAL IsRealPagingFile;
1429 
1430  PAGED_CODE();
1431  UNREFERENCED_PARAMETER( IrpContext );
1432 
1433  //
1434  // Don't do the two following operations for the Root Dcb
1435  // of a non FAT32 volume or paging files. Paging files!?
1436  // Yes, if someone diddles a volume we try to reverify all
1437  // of the Fcbs just in case; however, there is no safe way
1438  // to chuck and retrieve the mapping pair information for
1439  // a real paging file. Lose it and die.
1440  //
1441  // An exception is made for ReadyBoost cache files, which
1442  // are created as paging files on removable devices and
1443  // require validation after a power transition.
1444  //
1445 
1448 
1449  IsRealPagingFile = TRUE;
1450 
1451  } else {
1452 
1453  IsRealPagingFile = FALSE;
1454  }
1455 
1456  if ( (NodeType(Fcb) != FAT_NTC_ROOT_DCB ||
1457  FatIsFat32( Fcb->Vcb )) &&
1458  !IsRealPagingFile ) {
1459 
1460  //
1461  // Reset the mcb mapping.
1462  //
1463 
1464  FsRtlRemoveLargeMcbEntry( &Fcb->Mcb, 0, 0xFFFFFFFF );
1465 
1466  //
1467  // Reset the allocation size to 0 or unknown
1468  //
1469 
1470  if ( Fcb->FirstClusterOfFile == 0 ) {
1471 
1472  Fcb->Header.AllocationSize.QuadPart = 0;
1473 
1474  } else {
1475 
1476  Fcb->Header.AllocationSize.QuadPart = FCB_LOOKUP_ALLOCATIONSIZE_HINT;
1477  }
1478  }
1479 
1480  //
1481  // If this is a directory, reset the hints.
1482  //
1483 
1484  if ( (NodeType(Fcb) == FAT_NTC_DCB) ||
1485  (NodeType(Fcb) == FAT_NTC_ROOT_DCB) ) {
1486 
1487  //
1488  // Force a rescan of the directory
1489  //
1490 
1491  Fcb->Specific.Dcb.UnusedDirentVbo = 0xffffffff;
1492  Fcb->Specific.Dcb.DeletedDirentHint = 0xffffffff;
1493  }
1494 }
#define TRUE
Definition: types.h:120
#define FCB_LOOKUP_ALLOCATIONSIZE_HINT
Definition: fatstruc.h:1240
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
VOID NTAPI FsRtlRemoveLargeMcbEntry(IN PLARGE_MCB Mcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
Definition: largemcb.c:862
ULONG VcbState
Definition: cdstruc.h:546
#define PAGED_CODE()
Definition: video.h:57
#define FCB_STATE_PAGING_FILE
Definition: fatstruc.h:1194
#define VCB_STATE_FLAG_REMOVABLE_MEDIA
Definition: fatstruc.h:559
NodeType
Definition: Node.h:5
union _FCB::@710 Specific
CD_MCB Mcb
Definition: cdstruc.h:1022
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatIsFat32(VCB)
Definition: fatprocs.h:1437
#define FAT_NTC_ROOT_DCB
Definition: nodetype.h:31
#define FAT_NTC_DCB
Definition: nodetype.h:30
ULONG FirstClusterOfFile
Definition: fatstruc.h:817
PVCB Vcb
Definition: cdstruc.h:939
_In_ PFCB Fcb
Definition: cdprocs.h:151
struct _FCB::@710::@712 Dcb
ULONG FcbState
Definition: cdstruc.h:977

◆ FatVerifyOperationIsLegal()

VOID FatVerifyOperationIsLegal ( IN PIRP_CONTEXT  IrpContext)

Definition at line 1308 of file verfysup.c.

1330 {
1331  PIRP Irp;
1333 
1334  PAGED_CODE();
1335 
1336  Irp = IrpContext->OriginatingIrp;
1337 
1338  //
1339  // If the Irp is not present, then we got here via close.
1340  //
1341  //
1342 
1343  if ( Irp == NULL ) {
1344 
1345  return;
1346  }
1347 
1349 
1350  //
1351  // If there is not a file object, we cannot continue.
1352  //
1353 
1354  if ( FileObject == NULL ) {
1355 
1356  return;
1357  }
1358 
1359  //
1360  // If the file object has already been cleaned up, and
1361  //
1362  // A) This request is a paging io read or write, or
1363  // B) This request is a close operation, or
1364  // C) This request is a set or query info call (for Lou)
1365  // D) This is an MDL complete
1366  //
1367  // let it pass, otherwise return STATUS_FILE_CLOSED.
1368  //
1369 
1370  if ( FlagOn(FileObject->Flags, FO_CLEANUP_COMPLETE) ) {
1371 
1373 
1374  if ( (FlagOn(Irp->Flags, IRP_PAGING_IO)) ||
1375  (IrpSp->MajorFunction == IRP_MJ_CLOSE ) ||
1378  ( ( (IrpSp->MajorFunction == IRP_MJ_READ) ||
1379  (IrpSp->MajorFunction == IRP_MJ_WRITE) ) &&
1381 
1382  NOTHING;
1383 
1384  } else {
1385 
1386  FatRaiseStatus( IrpContext, STATUS_FILE_CLOSED );
1387  }
1388  }
1389 
1390  return;
1391 }
_In_ PIRP Irp
Definition: csq.h:116
#define FatRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2965
#define PAGED_CODE()
Definition: video.h:57
#define IRP_MN_COMPLETE
Definition: iotypes.h:4064
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
* PFILE_OBJECT
Definition: iotypes.h:1955
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define NOTHING
Definition: env_spec_w32.h:461
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1747
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IRP_PAGING_IO
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

Referenced by _Requires_lock_held_().

◆ FatVerifyVcb()

VOID FatVerifyVcb ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb 
)

Definition at line 270 of file verfysup.c.

292 {
293  BOOLEAN DevMarkedForVerify;
294 
295  PAGED_CODE();
296 
297  DebugTrace(+1, Dbg, "FatVerifyVcb, Vcb = %p\n", Vcb );
298 
299  //
300  // If the verify volume flag in the device object is set
301  // this means the media has potentially changed.
302  //
303  // Note that we only force this ping for create operations.
304  // For others we take a sporting chance. If in the end we
305  // have to physically access the disk, the right thing will happen.
306  //
307 
308  DevMarkedForVerify = BooleanFlagOn(Vcb->Vpb->RealDevice->Flags, DO_VERIFY_VOLUME);
309 
310  //
311  // We ALWAYS force CREATE requests on unmounted volumes through the
312  // verify path. These requests could have been in limbo between
313  // IoCheckMountedVpb and us, when a verify/mount took place and caused
314  // a completely different fs/volume to be mounted. In this case the
315  // checks above may not have caught the condition, since we may already
316  // have verified (wrong volume) and decided that we have nothing to do.
317  // We want the requests to be re routed to the currently mounted volume,
318  // since they were directed at the 'drive', not our volume. So we take
319  // the verify path for synchronisation, and the request will eventually
320  // be bounced back to IO with STATUS_REPARSE by our verify handler.
321  //
322 
323  if (!DevMarkedForVerify &&
324  (IrpContext->MajorFunction == IRP_MJ_CREATE) &&
325  (IrpContext->OriginatingIrp != NULL)) {
326 
327  PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( IrpContext->OriginatingIrp);
328 
329  if ((IrpSp->FileObject->RelatedFileObject == NULL) &&
330  (Vcb->VcbCondition == VcbNotMounted)) {
331 
332  DevMarkedForVerify = TRUE;
333  }
334  }
335 
336  //
337  // Raise any error condition otherwise.
338  //
339 
340  if (DevMarkedForVerify) {
341 
342  DebugTrace(0, Dbg, "The Vcb needs to be verified\n", 0);
343 
344  IoSetHardErrorOrVerifyDevice( IrpContext->OriginatingIrp,
345  Vcb->Vpb->RealDevice );
346 
348  }
349 
350  //
351  // Check the operation is legal for current Vcb state.
352  //
353 
354  FatQuickVerifyVcb( IrpContext, Vcb );
355 
356  DebugTrace(-1, Dbg, "FatVerifyVcb -> VOID\n", 0);
357 }
#define TRUE
Definition: types.h:120
#define FatNormalizeAndRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2983
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
#define PAGED_CODE()
Definition: video.h:57
#define Dbg
Definition: verfysup.c:29
VOID FatQuickVerifyVcb(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
Definition: verfysup.c:1666
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define Vcb
Definition: cdprocs.h:1425
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
VOID NTAPI IoSetHardErrorOrVerifyDevice(IN PIRP Irp, IN PDEVICE_OBJECT DeviceObject)
Definition: util.c:316

Referenced by FatFlushFat(), FatIsVolumeDirty(), and FatIsVolumeMounted().