ReactOS  0.4.15-dev-1206-g731eddf
strucsup.c File Reference
#include "fatprocs.h"
Include dependency graph for strucsup.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (FAT_BUG_CHECK_STRUCSUP)
 
#define Dbg   (DEBUG_TRACE_STRUCSUP)
 
#define FillMemory(BUF, SIZ, MASK)
 
#define IRP_CONTEXT_HEADER   (sizeof( IRP_CONTEXT ) * 0x10000 + FAT_NTC_IRP_CONTEXT)
 
#define FAT_FILL_FREE   0
 

Functions

INLINE PCCB FatAllocateCcb ()
 
INLINE VOID FatFreeCcb (IN PCCB Ccb)
 
INLINE PFCB FatAllocateFcb ()
 
INLINE VOID FatFreeFcb (IN PFCB Fcb)
 
INLINE PNON_PAGED_FCB FatAllocateNonPagedFcb ()
 
INLINE VOID FatFreeNonPagedFcb (PNON_PAGED_FCB NonPagedFcb)
 
INLINE PERESOURCE FatAllocateResource ()
 
INLINE VOID FatFreeResource (IN PERESOURCE Resource)
 
INLINE PIRP_CONTEXT FatAllocateIrpContext ()
 
INLINE VOID FatFreeIrpContext (IN PIRP_CONTEXT IrpContext)
 
 _Requires_lock_held_ (_Global_critical_region_)
 
VOID FatTearDownVcb (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
 
VOID FatDeleteVcb (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
 
PFCB FatCreateFcb (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PDCB ParentDcb, IN ULONG LfnOffsetWithinDirectory, IN ULONG DirentOffsetWithinDirectory, IN PDIRENT Dirent, IN PUNICODE_STRING Lfn OPTIONAL, IN PUNICODE_STRING OrigLfn OPTIONAL, IN BOOLEAN IsPagingFile, IN BOOLEAN SingleResource)
 
PDCB FatCreateDcb (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PDCB ParentDcb, IN ULONG LfnOffsetWithinDirectory, IN ULONG DirentOffsetWithinDirectory, IN PDIRENT Dirent, IN PUNICODE_STRING Lfn OPTIONAL)
 
VOID FatDeleteFcb (IN PIRP_CONTEXT IrpContext, IN PFCB *FcbPtr)
 
PCCB FatCreateCcb (IN PIRP_CONTEXT IrpContext)
 
VOID FatDeallocateCcbStrings (IN PCCB Ccb)
 
VOID FatDeleteCcb (IN PIRP_CONTEXT IrpContext, IN PCCB *Ccb)
 
PIRP_CONTEXT FatCreateIrpContext (IN PIRP Irp, IN BOOLEAN Wait)
 
VOID FatDeleteIrpContext_Real (IN PIRP_CONTEXT IrpContext)
 
PFCB FatGetNextFcbBottomUp (IN PIRP_CONTEXT IrpContext, IN PFCB Fcb OPTIONAL, IN PFCB TerminationFcb)
 
PFCB FatGetNextFcbTopDown (IN PIRP_CONTEXT IrpContext, IN PFCB Fcb, IN PFCB TerminationFcb)
 
BOOLEAN FatSwapVpb (IN PIRP_CONTEXT IrpContext, PVCB Vcb)
 
VOID FatConstructNamesInFcb (IN PIRP_CONTEXT IrpContext, PFCB Fcb, PDIRENT Dirent, PUNICODE_STRING Lfn OPTIONAL)
 
BOOLEAN FatIsHandleCountZero (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
 
PCLOSE_CONTEXT FatAllocateCloseContext (OPTIONAL PVCB Vcb)
 
VOID FatPreallocateCloseContext (PVCB Vcb)
 
VOID FatEnsureStringBufferEnough (_Inout_ PVOID String, _In_ USHORT DesiredBufferSize)
 
VOID FatFreeStringBuffer (_Inout_ PVOID String)
 
BOOLEAN FatScanForDataTrack (IN PIRP_CONTEXT IrpContext, IN PDEVICE_OBJECT TargetDeviceObject)
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (FAT_BUG_CHECK_STRUCSUP)

Definition at line 23 of file strucsup.c.

◆ Dbg

#define Dbg   (DEBUG_TRACE_STRUCSUP)

Definition at line 29 of file strucsup.c.

◆ FAT_FILL_FREE

#define FAT_FILL_FREE   0

Definition at line 52 of file strucsup.c.

◆ FillMemory

#define FillMemory (   BUF,
  SIZ,
  MASK 
)
Value:
{ \
ULONG i; \
for (i = 0; i < (((SIZ)/4) - 1); i += 2) { \
((PULONG)(BUF))[i] = (MASK); \
} \
}
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
ULONG MASK
Definition: afilter.h:45
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: jssnprintf.c:29
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1

Definition at line 31 of file strucsup.c.

◆ IRP_CONTEXT_HEADER

#define IRP_CONTEXT_HEADER   (sizeof( IRP_CONTEXT ) * 0x10000 + FAT_NTC_IRP_CONTEXT)

Definition at line 39 of file strucsup.c.

Function Documentation

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 211 of file strucsup.c.

247 {
249  PDEVICE_OBJECT RealDevice;
250  ULONG i;
251 
252  STORAGE_HOTPLUG_INFO HotplugInfo;
253  STORAGE_DEVICE_NUMBER StorDeviceNumber;
255 
256  //
257  // The following variables are used for abnormal unwind
258  //
259 
260  PLIST_ENTRY UnwindEntryList = NULL;
261  PERESOURCE UnwindResource = NULL;
262  PERESOURCE UnwindResource2 = NULL;
263  PFILE_OBJECT UnwindFileObject = NULL;
264  PFILE_OBJECT UnwindCacheMap = NULL;
265  BOOLEAN UnwindWeAllocatedMcb = FALSE;
266  PFILE_SYSTEM_STATISTICS UnwindStatistics = NULL;
267  BOOLEAN UnwindWeAllocatedBadBlockMap = FALSE;
268  BOOLEAN CloseContextAllocated = FALSE;
269 
270  PAGED_CODE();
272 
273  DebugTrace(+1, Dbg, "FatInitializeVcb, Vcb = %p\n", Vcb);
274 
275  _SEH2_TRY {
276 
277  //
278  // We start by first zeroing out all of the VCB, this will guarantee
279  // that any stale data is wiped clean
280  //
281 
282  RtlZeroMemory( Vcb, sizeof(VCB) );
283 
284  //
285  // Set the proper node type code and node byte size
286  //
287 
288  Vcb->VolumeFileHeader.NodeTypeCode = FAT_NTC_VCB;
289  Vcb->VolumeFileHeader.NodeByteSize = sizeof(VCB);
290 
291  //
292  // Initialize the tunneling cache
293  //
294 
296 
297  //
298  // Insert this Vcb record on the FatData.VcbQueue
299  //
300 
301  NT_ASSERT( FlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) );
302 
303 
304 #ifdef _MSC_VER
305 #pragma prefast( push )
306 #pragma prefast( disable: 28137, "prefast wants the wait to be a constant, but that isn't possible for the way fastfat is designed" )
307 #pragma prefast( disable: 28193, "this will always wait" )
308 #endif
309 
310  (VOID)FatAcquireExclusiveGlobal( IrpContext );
311 
312 #ifdef _MSC_VER
313 #pragma prefast( pop )
314 #endif
315 
316  InsertTailList( &FatData.VcbQueue, &Vcb->VcbLinks );
317  FatReleaseGlobal( IrpContext );
318  UnwindEntryList = &Vcb->VcbLinks;
319 
320  //
321  // Set the Target Device Object, Vpb, and Vcb State fields
322  //
323 
324 
326  Vcb->TargetDeviceObject = TargetDeviceObject;
327  Vcb->Vpb = Vpb;
328 
329  Vcb->CurrentDevice = Vpb->RealDevice;
330 
331  //
332  // Set the removable media and defflush flags based on the storage
333  // inquiry and the old characteristic bits.
334  //
335 
336  Status = FatPerformDevIoCtrl( IrpContext,
339  NULL,
340  0,
341  &HotplugInfo,
342  sizeof(HotplugInfo),
343  FALSE,
344  TRUE,
345  NULL );
346 
347  if (NT_SUCCESS( Status )) {
348 
349  if (HotplugInfo.MediaRemovable) {
350 
352  }
353 
354  //
355  // If the media or device is hot-pluggable, then set this flag.
356  //
357 
358  if (HotplugInfo.MediaHotplug || HotplugInfo.DeviceHotplug) {
359 
361  }
362 
363  if (!HotplugInfo.WriteCacheEnableOverride) {
364 
365  //
366  // If the device or media is hotplug and the override is not
367  // set, force defflush behavior for the device.
368  //
369 
370  if (HotplugInfo.MediaHotplug || HotplugInfo.DeviceHotplug) {
371 
373 
375 
376  //
377  // Now, for removables that claim to be lockable, lob a lock
378  // request and see if it works. There can unfortunately be
379  // transient, media dependent reasons that it can fail. If
380  // it does not, we must force defflush on.
381  //
382 
383  } else if (HotplugInfo.MediaRemovable &&
384  !HotplugInfo.MediaHotplug) {
385 
386  Status = FatToggleMediaEjectDisable( IrpContext, Vcb, TRUE );
387 
388  if (!NT_SUCCESS( Status )) {
389 
391 
392  }
393 
394  (VOID)FatToggleMediaEjectDisable( IrpContext, Vcb, FALSE );
395  }
396  }
397  }
398 
399  if (FlagOn(Vpb->RealDevice->Characteristics, FILE_REMOVABLE_MEDIA)) {
400 
402  }
403 
404  //
405  // Make sure we turn on deferred flushing for floppies like we always
406  // have.
407  //
408 
409  if (FlagOn(Vpb->RealDevice->Characteristics, FILE_FLOPPY_DISKETTE)) {
410 
412  }
413 
414  //
415  // Query the storage device number.
416  //
417 
418  Status = FatPerformDevIoCtrl( IrpContext,
421  NULL,
422  0,
423  &StorDeviceNumber,
424  sizeof(StorDeviceNumber),
425  FALSE,
426  TRUE,
427  NULL );
428 
429  if (NT_SUCCESS( Status )) {
430 
431  Vcb->DeviceNumber = StorDeviceNumber.DeviceNumber;
432 
433  } else {
434 
435  Vcb->DeviceNumber = (ULONG)(-1);
436  }
437 
439 
440  //
441  // Initialize the resource variable for the Vcb
442  //
443 
444  ExInitializeResourceLite( &Vcb->Resource );
445  UnwindResource = &Vcb->Resource;
446 
447  ExInitializeResourceLite( &Vcb->ChangeBitMapResource );
448  UnwindResource2 = &Vcb->ChangeBitMapResource;
449 
450  //
451  // Initialize the free cluster bitmap mutex.
452  //
453 
454  ExInitializeFastMutex( &Vcb->FreeClusterBitMapMutex );
455 
456  //
457  // Create the special file object for the virtual volume file with a close
458  // context, its pointers back to the Vcb and the section object pointer.
459  //
460  // We don't have to unwind the close context. That will happen in the close
461  // path automatically.
462  //
463 
464  RealDevice = Vcb->CurrentDevice;
465 
467  CloseContextAllocated = TRUE;
468 
469  Vcb->VirtualVolumeFile = UnwindFileObject = IoCreateStreamFileObject( NULL, RealDevice );
470 
471  FatSetFileObject( Vcb->VirtualVolumeFile,
473  Vcb,
474  NULL );
475 
476  //
477  // Remember this internal, residual open.
478  //
479 
480  InterlockedIncrement( (LONG*)&(Vcb->InternalOpenCount) );
481  InterlockedIncrement( (LONG*)&(Vcb->ResidualOpenCount) );
482 
483  Vcb->VirtualVolumeFile->SectionObjectPointer = &Vcb->SectionObjectPointers;
484 
485  Vcb->VirtualVolumeFile->ReadAccess = TRUE;
486  Vcb->VirtualVolumeFile->WriteAccess = TRUE;
487  Vcb->VirtualVolumeFile->DeleteAccess = TRUE;
488 
489  //
490  // Initialize the notify structures.
491  //
492 
493  InitializeListHead( &Vcb->DirNotifyList );
494 
495  FsRtlNotifyInitializeSync( &Vcb->NotifySync );
496 
497  //
498  // Initialize the Cache Map for the volume file. The size is
499  // initially set to that of our first read. It will be extended
500  // when we know how big the Fat is.
501  //
502 
506 
507  FatInitializeCacheMap( Vcb->VirtualVolumeFile,
508  &FileSizes,
509  TRUE,
511  Vcb );
512 
513  UnwindCacheMap = Vcb->VirtualVolumeFile;
514 
515  //
516  // Initialize the structure that will keep track of dirty fat sectors.
517  // The largest possible Mcb structures are less than 1K, so we use
518  // non paged pool.
519  //
520 
521  FsRtlInitializeLargeMcb( &Vcb->DirtyFatMcb, PagedPool );
522 
523  UnwindWeAllocatedMcb = TRUE;
524 
525  //
526  // Initialize the structure that will keep track of bad clusters on the volume.
527  //
528  // It will be empty until it is populated by FSCTL_GET_RETRIEVAL_POINTERS with a volume handle.
529  //
530 
531  FsRtlInitializeLargeMcb( &Vcb->BadBlockMcb, PagedPool );
532  UnwindWeAllocatedBadBlockMap = TRUE;
533 
534  //
535  // Set the cluster index hint to the first valid cluster of a fat: 2
536  //
537 
538  Vcb->ClusterHint = 2;
539 
540  //
541  // Initialize the directory stream file object creation event.
542  // This event is also "borrowed" for async non-cached writes.
543  //
544 
545  ExInitializeFastMutex( &Vcb->DirectoryFileCreationMutex );
546 
547  //
548  // Initialize the clean volume callback Timer and DPC.
549  //
550 
551  KeInitializeTimer( &Vcb->CleanVolumeTimer );
552 
553  KeInitializeDpc( &Vcb->CleanVolumeDpc, FatCleanVolumeDpc, Vcb );
554 
555  //
556  // Initialize the performance counters.
557  //
558 
559  Vcb->Statistics = FsRtlAllocatePoolWithTag( NonPagedPoolNx,
561  TAG_VCB_STATS );
562  UnwindStatistics = Vcb->Statistics;
563 
565 
566  for (i = 0; i < FatData.NumberProcessors; i += 1) {
567  Vcb->Statistics[i].Common.FileSystemType = FILESYSTEM_STATISTICS_TYPE_FAT;
568  Vcb->Statistics[i].Common.Version = 1;
569  Vcb->Statistics[i].Common.SizeOfCompleteStructure =
570  sizeof(FILE_SYSTEM_STATISTICS);
571  }
572 
573  //
574  // Pick up a VPB right now so we know we can pull this filesystem stack off
575  // of the storage stack on demand.
576  //
577 
578  Vcb->SwapVpb = FsRtlAllocatePoolWithTag( NonPagedPoolNx,
579  sizeof( VPB ),
580  TAG_VPB );
581 
582  RtlZeroMemory( Vcb->SwapVpb, sizeof( VPB ) );
583 
584  //
585  // Initialize the close queue listheads.
586  //
587 
588  InitializeListHead( &Vcb->AsyncCloseList );
589  InitializeListHead( &Vcb->DelayedCloseList );
590 
591  //
592  // Initialize the Advanced FCB Header
593  //
594 
595  ExInitializeFastMutex( &Vcb->AdvancedFcbHeaderMutex );
596  FsRtlSetupAdvancedHeader( &Vcb->VolumeFileHeader,
597  &Vcb->AdvancedFcbHeaderMutex );
598 
599 
600  //
601  // With the Vcb now set up, set the IrpContext Vcb field.
602  //
603 
604  IrpContext->Vcb = Vcb;
605 
606  } _SEH2_FINALLY {
607 
608  DebugUnwind( FatInitializeVcb );
609 
610  //
611  // If this is an abnormal termination then undo our work
612  //
613 
615 
616  if (UnwindCacheMap != NULL) { FatSyncUninitializeCacheMap( IrpContext, UnwindCacheMap ); }
617  if (UnwindFileObject != NULL) { ObDereferenceObject( UnwindFileObject ); }
618  if (UnwindResource != NULL) { FatDeleteResource( UnwindResource ); }
619  if (UnwindResource2 != NULL) { FatDeleteResource( UnwindResource2 ); }
620  if (UnwindWeAllocatedMcb) { FsRtlUninitializeLargeMcb( &Vcb->DirtyFatMcb ); }
621  if (UnwindWeAllocatedBadBlockMap) { FsRtlUninitializeLargeMcb(&Vcb->BadBlockMcb ); }
622  if (UnwindEntryList != NULL) {
623 #ifdef _MSC_VER
624 #pragma prefast( suppress: 28137, "prefast wants the wait to be a constant, but that isn't possible for the way fastfat is designed" )
625 #endif
626  (VOID)FatAcquireExclusiveGlobal( IrpContext );
627  RemoveEntryList( UnwindEntryList );
628  FatReleaseGlobal( IrpContext );
629  }
630  if (UnwindStatistics != NULL) { ExFreePool( UnwindStatistics ); }
631 
632  //
633  // Cleanup the close context we preallocated above.
634  //
635 
636  if (CloseContextAllocated && (Vcb->VirtualVolumeFile == NULL)) {
637 
638  //
639  // FatAllocateCloseContext does not allocate memory, it
640  // pulls a close context off the preallocated slist queue.
641  //
642  // Doing this here is necessary to balance out the one we
643  // preallocated for the Vcb earlier in this function, but
644  // only if we failed to create the virtual volume file.
645  //
646  // If VirtualVolumeFile is not NULL, then this CloseContext
647  // will get cleaned up when the close comes in for it during
648  // Vcb teardown.
649  //
650 
652 
653  ExFreePool( CloseContext );
654  CloseContextAllocated = FALSE;
655  }
656  }
657 
658  DebugTrace(-1, Dbg, "FatInitializeVcb -> VOID\n", 0);
659  } _SEH2_END;
660 
661  //
662  // and return to our caller
663  //
664 
665  UNREFERENCED_PARAMETER( IrpContext );
666 
667  return;
668 }
FatSetFileObject(FileObject, UserDirectoryOpen,(*Dcb), UnwindCcb=FatCreateCcb(IrpContext))
#define FatReleaseGlobal(IRPCONTEXT)
Definition: fatprocs.h:1636
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
VOID FatSyncUninitializeCacheMap(IN PIRP_CONTEXT IrpContext, IN PFILE_OBJECT FileObject)
Definition: cachesup.c:1812
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
#define VCB_STATE_FLAG_DEFERRED_FLUSH
Definition: fatstruc.h:567
#define Dbg
Definition: strucsup.c:29
BOOLEAN DeviceHotplug
Definition: imports.h:248
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define IOCTL_STORAGE_GET_HOTPLUG_INFO
Definition: imports.h:238
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Definition: cdstruc.h:498
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static CC_FILE_SIZES FileSizes
#define InsertTailList(ListHead, Entry)
struct _PACKED_BOOT_SECTOR PACKED_BOOT_SECTOR
#define TAG_VPB
Definition: cdprocs.h:106
KDEFERRED_ROUTINE FatCleanVolumeDpc
Definition: fatprocs.h:1981
LARGE_INTEGER FileSize
Definition: cctypes.h:16
_SEH2_TRY
Definition: create.c:4226
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN MediaHotplug
Definition: imports.h:247
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
ULONG NumberProcessors
Definition: fatstruc.h:80
#define FALSE
Definition: types.h:117
struct _VCB VCB
long LONG
Definition: pedump.c:60
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
VOID NTAPI FsRtlInitializeLargeMcb(IN PLARGE_MCB Mcb, IN POOL_TYPE PoolType)
Definition: largemcb.c:450
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define VCB_STATE_FLAG_HOTPLUGGABLE
Definition: fatstruc.h:576
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:13
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define IOCTL_STORAGE_GET_DEVICE_NUMBER
Definition: ntddstor.h:143
#define VCB_STATE_FLAG_REMOVABLE_MEDIA
Definition: fatstruc.h:559
NTSTATUS FatPerformDevIoCtrl(IN PIRP_CONTEXT IrpContext, IN ULONG IoControlCode, IN PDEVICE_OBJECT Device, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN BOOLEAN OverrideVerify, OUT PIO_STATUS_BLOCK Iosb OPTIONAL)
Definition: deviosup.c:3621
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3186
NTSTATUS FatToggleMediaEjectDisable(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN BOOLEAN PreventRemoval)
Definition: deviosup.c:3495
#define DebugUnwind(X)
Definition: fatdata.h:315
FAT_DATA FatData
Definition: fatdata.c:56
BOOLEAN WriteCacheEnableOverride
Definition: imports.h:249
PCLOSE_CONTEXT FatAllocateCloseContext(OPTIONAL PVCB Vcb)
Definition: strucsup.c:3647
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define Vcb
Definition: cdprocs.h:1415
VOID NTAPI FsRtlInitializeTunnelCache(IN PTUNNEL Cache)
Definition: tunnel.c:891
* PFILE_OBJECT
Definition: iotypes.h:1978
VOID FatPreallocateCloseContext(PVCB Vcb)
Definition: strucsup.c:3684
Status
Definition: gdiplustypes.h:24
#define VOID
Definition: acefi.h:82
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB IN PDEVICE_OBJECT FsDeviceObject
Definition: fatprocs.h:1673
LARGE_INTEGER ValidDataLength
Definition: cctypes.h:17
Definition: typedefs.h:119
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatSetVcbCondition(V, X)
Definition: fatprocs.h:1438
LIST_ENTRY VcbQueue
Definition: fatstruc.h:48
VOID FatInitializeCacheMap(_In_ PFILE_OBJECT FileObject, _In_ PCC_FILE_SIZES FileSizes, _In_ BOOLEAN PinAccess, _In_ PCACHE_MANAGER_CALLBACKS Callbacks, _In_ PVOID LazyWriteContext)
Definition: cachesup.c:62
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4400
LARGE_INTEGER AllocationSize
Definition: cctypes.h:15
#define InterlockedIncrement
Definition: armddk.h:53
LARGE_INTEGER FatMaxLarge
Definition: fatdata.c:63
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_SEH2_FINALLY
Definition: create.c:4371
VOID NTAPI FsRtlUninitializeLargeMcb(IN PLARGE_MCB Mcb)
Definition: largemcb.c:1053
VOID NTAPI FsRtlNotifyInitializeSync(IN PNOTIFY_SYNC *NotifySync)
Definition: notify.c:1561
Definition: iotypes.h:168
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FAT_NTC_VCB
Definition: nodetype.h:28
#define TAG_VCB_STATS
Definition: nodetype.h:171
struct _FILE_SYSTEM_STATISTICS FILE_SYSTEM_STATISTICS
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
BOOLEAN MediaRemovable
Definition: imports.h:246
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1673
#define FatDeleteResource(RESRC)
Definition: fatprocs.h:1632
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1673
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define FILESYSTEM_STATISTICS_TYPE_FAT
Definition: winioctl.h:673
LONGLONG QuadPart
Definition: typedefs.h:114
#define FatAcquireExclusiveGlobal(IRPCONTEXT)
Definition: fatprocs.h:1387
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312
CACHE_MANAGER_CALLBACKS CacheManagerNoOpCallbacks
Definition: fatstruc.h:159

◆ FatAllocateCcb()

INLINE PCCB FatAllocateCcb ( )

Definition at line 56 of file strucsup.c.

58 {
59  return (PCCB) FsRtlAllocatePoolWithTag( PagedPool, sizeof(CCB), TAG_CCB );
60 }
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
Definition: cdstruc.h:1067
#define TAG_CCB
Definition: cdprocs.h:85

Referenced by FatCreateCcb().

◆ FatAllocateCloseContext()

PCLOSE_CONTEXT FatAllocateCloseContext ( OPTIONAL PVCB  Vcb)

Definition at line 3647 of file strucsup.c.

3667 {
3668  PAGED_CODE();
3670 
3671 #if DBG
3672  if (ARGUMENT_PRESENT(Vcb)) {
3673 
3674  NT_ASSERT( 0 != Vcb->CloseContextCount);
3675  InterlockedDecrement( (LONG*)&Vcb->CloseContextCount);
3676  }
3677 #endif
3680 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
KSPIN_LOCK GeneralSpinLock
Definition: fatstruc.h:151
SLIST_HEADER FatCloseContextSList
Definition: fatdata.c:106
struct _SINGLE_LIST_ENTRY *__fastcall ExInterlockedPopEntrySList(union _SLIST_HEADER *, unsigned long *)
long LONG
Definition: pedump.c:60
FAT_DATA FatData
Definition: fatdata.c:56
#define ARGUMENT_PRESENT(ArgumentPointer)
#define Vcb
Definition: cdprocs.h:1415
#define InterlockedDecrement
Definition: armddk.h:52
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by _Requires_lock_held_().

◆ FatAllocateFcb()

INLINE PFCB FatAllocateFcb ( )

Definition at line 77 of file strucsup.c.

79 {
80  return (PFCB) FsRtlAllocatePoolWithTag( PagedPool, sizeof(FCB), TAG_FCB );
81 }
#define TAG_FCB
Definition: vfat.h:547
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
Definition: cdstruc.h:902

Referenced by FatCreateDcb(), and FatCreateFcb().

◆ FatAllocateIrpContext()

INLINE PIRP_CONTEXT FatAllocateIrpContext ( )

Definition at line 163 of file strucsup.c.

165 {
166  return (PIRP_CONTEXT) ExAllocateFromNPagedLookasideList( &FatIrpContextLookasideList );
167 }
NPAGED_LOOKASIDE_LIST FatIrpContextLookasideList
Definition: fatdata.c:102

Referenced by FatCreateIrpContext().

◆ FatAllocateNonPagedFcb()

INLINE PNON_PAGED_FCB FatAllocateNonPagedFcb ( )

Definition at line 101 of file strucsup.c.

103 {
104  return (PNON_PAGED_FCB) ExAllocateFromNPagedLookasideList( &FatNonPagedFcbLookasideList );
105 }
NPAGED_LOOKASIDE_LIST FatNonPagedFcbLookasideList
Definition: fatdata.c:103

Referenced by FatCreateDcb(), and FatCreateFcb().

◆ FatAllocateResource()

INLINE PERESOURCE FatAllocateResource ( )

Definition at line 128 of file strucsup.c.

130 {
132 
133  Resource = (PERESOURCE) ExAllocateFromNPagedLookasideList( &FatEResourceLookasideList );
134 
136 
137  return Resource;
138 }
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
NPAGED_LOOKASIDE_LIST FatEResourceLookasideList
Definition: fatdata.c:104

Referenced by FatCreateDcb(), and FatCreateFcb().

◆ FatConstructNamesInFcb()

VOID FatConstructNamesInFcb ( IN PIRP_CONTEXT  IrpContext,
PFCB  Fcb,
PDIRENT  Dirent,
PUNICODE_STRING Lfn  OPTIONAL 
)

Definition at line 3010 of file strucsup.c.

3087 {
3088 #ifndef __REACTOS__
3089  NTSTATUS Status;
3090 #endif
3091  ULONG i;
3092 
3093 #ifndef __REACTOS__
3094  OEM_STRING OemA;
3095  OEM_STRING OemB;
3096 #endif
3097  UNICODE_STRING Unicode;
3099  POEM_STRING LongOemName;
3100  PUNICODE_STRING LongUniName;
3101 
3102  PAGED_CODE();
3103 
3105 
3106  NT_ASSERT( ShortName->Buffer == NULL );
3107 
3108  _SEH2_TRY {
3109 
3110  //
3111  // First do the short name.
3112  //
3113 
3114  //
3115  // Copy over the case flags for the short name of the file
3116  //
3117 
3119 
3121 
3122  } else {
3123 
3125  }
3126 
3128 
3130 
3131  } else {
3132 
3134  }
3135 
3136  ShortName->MaximumLength = 16;
3138  16,
3140 
3141  Fat8dot3ToString( IrpContext, Dirent, FALSE, ShortName );
3142 
3144 
3145  //
3146  // If no Lfn was specified, we are done. In either case, set the
3147  // final name length.
3148  //
3149 
3151 
3152  if (!ARGUMENT_PRESENT(Lfn) || (Lfn->Length == 0)) {
3153 
3156 
3157  try_return( NOTHING );
3158  }
3159 
3160  //
3161  // If we already set up the full filename, we could be in trouble. If the fast
3162  // path for doing it already fired, FatSetFullFileNameInFcb, it will have missed
3163  // this and could have built the full filename out of the shortname of the file.
3164  //
3165  // At that point, disaster could be inevitable since the final name length will not
3166  // match. We use this to tell the notify package what to do - FatNotifyReportChange.
3167  //
3168 
3170 
3171  //
3172  // We know now we have an Lfn, save away a copy.
3173  //
3174 
3176 
3179  Lfn->Length,
3182 
3183  //
3184  // First check for no extended characters.
3185  //
3186 
3187  for (i=0; i < Lfn->Length/sizeof(WCHAR); i++) {
3188 
3189  if (Lfn->Buffer[i] >= 0x80) {
3190 
3191  break;
3192  }
3193  }
3194 
3195  if (i == Lfn->Length/sizeof(WCHAR)) {
3196 
3197  //
3198  // Cool, I can go with the Oem, upcase it fast by hand.
3199  //
3200 
3201  LongOemName = &Fcb->LongName.Oem.Name.Oem;
3202 
3203 
3204  LongOemName->Buffer = FsRtlAllocatePoolWithTag( PagedPool,
3205  Lfn->Length/sizeof(WCHAR),
3207  LongOemName->Length =
3208  LongOemName->MaximumLength = Lfn->Length/sizeof(WCHAR);
3209 
3210  for (i=0; i < Lfn->Length/sizeof(WCHAR); i++) {
3211 
3212  WCHAR c;
3213 
3214  c = Lfn->Buffer[i];
3215 
3216 #ifdef _MSC_VER
3217 #pragma warning( push )
3218 #pragma warning( disable:4244 )
3219 #endif
3220  LongOemName->Buffer[i] = c < 'a' ?
3221  (UCHAR)c :
3222  c <= 'z' ?
3223  c - (UCHAR)('a'-'A') :
3224  (UCHAR)c;
3225 #ifdef _MSC_VER
3226 #pragma warning( pop )
3227 #endif
3228  }
3229 
3230  //
3231  // If this name happens to be exactly the same as the short
3232  // name, don't add it to the splay table.
3233  //
3234 
3235  if (FatAreNamesEqual(IrpContext, *ShortName, *LongOemName) ||
3236  (FatFindFcb( IrpContext,
3237  &Fcb->ParentDcb->Specific.Dcb.RootOemNode,
3238  LongOemName,
3239  NULL) != NULL)) {
3240 
3241  ExFreePool( LongOemName->Buffer );
3242 
3243  LongOemName->Buffer = NULL;
3244  LongOemName->Length =
3245  LongOemName->MaximumLength = 0;
3246 
3247  } else {
3248 
3250  }
3251 
3252  try_return( NOTHING );
3253  }
3254 
3255  //
3256  // Now we have the fun part. Make a copy of the Lfn.
3257  //
3258 
3259 #ifndef __REACTOS__
3260  OemA.Buffer = NULL;
3261  OemB.Buffer = NULL;
3262 #endif
3263  Unicode.Buffer = NULL;
3264 
3265  Unicode.Length =
3266  Unicode.MaximumLength = Lfn->Length;
3268  Lfn->Length,
3270 
3271  RtlCopyMemory( Unicode.Buffer, Lfn->Buffer, Lfn->Length );
3272 
3273 #ifndef __REACTOS__
3275 #endif
3276 
3277 #if TRUE
3278  //
3279  // Unfortunately, this next block of code breaks down when you have
3280  // two long Unicode filenames that both map to the same Oem (and are,
3281  // well, long, i.e. are not the short names). In this case, with one
3282  // in the prefix table first, the other will hit the common Oem
3283  // representation. This leads to several forms of user astonishment.
3284  //
3285  // It isn't worth it, or probably even possible, to try to figure out
3286  // when this is really safe to go through. Simply omit the attempt.
3287  //
3288  // Ex: ANSI 0x82 and 0x84 in the 1252 ANSI->UNI and 437 UNI->OEM codepages.
3289  //
3290  // 0x82 => 0x201a => 0x2c
3291  // 0x84 => 0x201e => 0x2c
3292  //
3293  // 0x2c is comma, so is FAT Oem illegal and forces shortname generation.
3294  // Since it is otherwise well-formed by the rules articulated previously,
3295  // we would have put 0x2c in the Oem prefix tree. In terms of the
3296  // argument given above, even though there exist no Y and U s.t.
3297  //
3298  // Up(Y) == Up(U) && BestOemFit(U) != BestOemFit(Y)
3299  //
3300  // there most certainly exist Y and U s.t.
3301  //
3302  // Up(Y) != Up(U) && BestOemFit(U) == BestOemFit(Y)
3303  //
3304  // and that is enough to keep us from doing this. Note that the < 0x80
3305  // case is OK since we know that the mapping in the OEM codepages are
3306  // the identity in that range.
3307  //
3308  // We still need to monocase it, though. Do this through a full down/up
3309  // transition.
3310  //
3311 
3312  (VOID)RtlDowncaseUnicodeString( &Unicode, &Unicode, FALSE );
3313  (VOID)RtlUpcaseUnicodeString( &Unicode, &Unicode, FALSE );
3314 #else
3315  //
3316  // Downcase and convert to upcased Oem. Only continue if we can
3317  // convert without error. Any error other than UNMAPPABLE_CHAR
3318  // is a fatal error and we raise.
3319  //
3320  // Note that even if the conversion fails, we must leave Unicode
3321  // in an upcased state.
3322  //
3323  // NB: The Rtl doesn't NULL .Buffer on error.
3324  //
3325 
3326  (VOID)RtlDowncaseUnicodeString( &Unicode, &Unicode, FALSE );
3328  (VOID)RtlUpcaseUnicodeString( &Unicode, &Unicode, FALSE );
3329 
3330  if (!NT_SUCCESS(Status)) {
3331 
3333 
3335  ExFreePool(Unicode.Buffer);
3336  FatNormalizeAndRaiseStatus( IrpContext, Status );
3337  }
3338 
3339  } else {
3340 
3341  //
3342  // The same as above except upcase.
3343  //
3344 
3346 
3347  if (!NT_SUCCESS(Status)) {
3348 
3349  RtlFreeOemString( &OemA );
3350 
3352 
3354  ExFreePool(Unicode.Buffer);
3355  FatNormalizeAndRaiseStatus( IrpContext, Status );
3356  }
3357  }
3358  }
3359 
3360  //
3361  // If the final OemNames are equal, I can use save only the Oem
3362  // name. If the name did not map, then I have to go with the UNICODE
3363  // name because I could get a case varient that didn't convert
3364  // in create, but did match the LFN.
3365  //
3366 
3367  if (NT_SUCCESS(Status) && FatAreNamesEqual( IrpContext, OemA, OemB )) {
3368 
3369  //
3370  // Cool, I can go with the Oem. If we didn't convert correctly,
3371  // get a fresh convert from the original LFN.
3372  //
3373 
3374  ExFreePool(Unicode.Buffer);
3375 
3376  RtlFreeOemString( &OemB );
3377 
3378  Fcb->LongName.Oem.Name.Oem = OemA;
3379 
3380  //
3381  // If this name happens to be exactly the same as the short
3382  // name, or a similar short name already exists don't add it
3383  // to the splay table (note the final condition implies a
3384  // corrupt disk.
3385  //
3386 
3387  if (FatAreNamesEqual(IrpContext, *ShortName, OemA) ||
3388  (FatFindFcb( IrpContext,
3389  &Fcb->ParentDcb->Specific.Dcb.RootOemNode,
3390  &OemA,
3391  NULL) != NULL)) {
3392 
3393  RtlFreeOemString( &OemA );
3394 
3395  } else {
3396 
3398  }
3399 
3400  try_return( NOTHING );
3401  }
3402 
3403  //
3404  // The long name must be left in UNICODE. Free the two Oem strings
3405  // if we got here just because they weren't equal.
3406  //
3407 
3408  if (NT_SUCCESS(Status)) {
3409 
3410  RtlFreeOemString( &OemA );
3411  RtlFreeOemString( &OemB );
3412  }
3413 #endif
3414 
3415  LongUniName = &Fcb->LongName.Unicode.Name.Unicode;
3416 
3417  LongUniName->Length =
3418  LongUniName->MaximumLength = Unicode.Length;
3419  LongUniName->Buffer = Unicode.Buffer;
3420 
3422 
3423  try_exit: NOTHING;
3424  } _SEH2_FINALLY {
3425 
3426  if (_SEH2_AbnormalTermination()) {
3427 
3428  if (ShortName->Buffer != NULL) {
3429 
3430  ExFreePool( ShortName->Buffer );
3431  ShortName->Buffer = NULL;
3432  }
3433 
3434  } else {
3435 
3436  //
3437  // Creating all the names worked, so add all the names
3438  // to the splay tree.
3439  //
3440 
3441  FatInsertName( IrpContext,
3442  &Fcb->ParentDcb->Specific.Dcb.RootOemNode,
3443  &Fcb->ShortName );
3444 
3445  Fcb->ShortName.Fcb = Fcb;
3446 
3448 
3449  FatInsertName( IrpContext,
3450  &Fcb->ParentDcb->Specific.Dcb.RootOemNode,
3451  &Fcb->LongName.Oem );
3452 
3453  Fcb->LongName.Oem.Fcb = Fcb;
3454  }
3455 
3457 
3458  FatInsertName( IrpContext,
3459  &Fcb->ParentDcb->Specific.Dcb.RootUnicodeNode,
3460  &Fcb->LongName.Unicode );
3461 
3462  Fcb->LongName.Unicode.Fcb = Fcb;
3463  }
3464 
3466  }
3467  } _SEH2_END;
3468 
3469  return;
3470 }
IN PDCB IN POEM_STRING IN PUNICODE_STRING IN OUT POEM_STRING ShortName
Definition: fatprocs.h:1303
struct _FCB * Fcb
Definition: fatstruc.h:684
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define FatNormalizeAndRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2992
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
FILE_NAME_NODE Oem
Definition: fatstruc.h:1158
USHORT MaximumLength
Definition: env_spec_w32.h:370
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING Lfn
Definition: create.c:4137
#define TRUE
Definition: types.h:120
VOID Fat8dot3ToString(_In_ PIRP_CONTEXT IrpContext, _In_ PDIRENT Dirent, _In_ BOOLEAN RestoreCase, _Out_ POEM_STRING OutputString)
Definition: namesup.c:179
union _FCB::@713 LongName
LONG NTSTATUS
Definition: precomp.h:26
PFCB FatFindFcb(IN PIRP_CONTEXT IrpContext, IN OUT PRTL_SPLAY_LINKS *RootNode, IN PSTRING Name, OUT PBOOLEAN FileNameDos OPTIONAL)
Definition: splaysup.c:306
#define FCB_STATE_3_LOWER_CASE
Definition: fatstruc.h:1210
#define FCB_STATE_HAS_UNICODE_LONG_NAME
Definition: fatstruc.h:1201
unsigned short Length
Definition: sprintf.c:451
STRING OEM_STRING
Definition: umtypes.h:203
struct _FCB * ParentDcb
Definition: fatstruc.h:835
_SEH2_TRY
Definition: create.c:4226
#define FAT_DIRENT_NT_BYTE_8_LOWER_CASE
Definition: fat.h:361
BOOLEAN FileNameDos
Definition: fatstruc.h:703
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI NTSTATUS WINAPI RtlDowncaseUnicodeString(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN)
void * Buffer
Definition: sprintf.c:453
#define FCB_STATE_NAMES_IN_SPLAY_TREE
Definition: fatstruc.h:1199
#define FALSE
Definition: types.h:117
union _FILE_NAME_NODE::@711 Name
smooth NULL
Definition: ftsmooth.c:416
FILE_NAME_NODE Unicode
Definition: fatstruc.h:1165
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:13
OEM_STRING Oem
Definition: fatstruc.h:692
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define try_return(S)
Definition: cdprocs.h:2179
VOID FatInsertName(IN PIRP_CONTEXT IrpContext, IN PRTL_SPLAY_LINKS *RootNode, IN PFILE_NAME_NODE Name)
Definition: splaysup.c:39
#define ARGUMENT_PRESENT(ArgumentPointer)
const GLubyte * c
Definition: glext.h:8905
#define TAG_FILENAME_BUFFER
Definition: nodetype.h:167
UNICODE_STRING FullFileName
Definition: fatstruc.h:1121
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define VOID
Definition: acefi.h:82
#define FCB_STATE_8_LOWER_CASE
Definition: fatstruc.h:1209
#define NOTHING
Definition: env_spec_w32.h:461
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatAreNamesEqual(IRPCONTEXT, NAMEA, NAMEB)
Definition: fatprocs.h:1158
#define FCB_STATE_HAS_OEM_LONG_NAME
Definition: fatstruc.h:1200
NTSYSAPI NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString(STRING *, const UNICODE_STRING *, BOOLEAN)
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
UNICODE_STRING Unicode
Definition: fatstruc.h:694
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define FAT_DIRENT_NT_BYTE_3_LOWER_CASE
Definition: fat.h:362
_SEH2_END
Definition: create.c:4400
#define STATUS_UNMAPPABLE_CHARACTER
Definition: ntstatus.h:590
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
_SEH2_FINALLY
Definition: create.c:4371
VOID NTAPI RtlFreeOemString(POEM_STRING OemString)
#define c
Definition: ke_i.h:80
unsigned int ULONG
Definition: retypes.h:1
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT _Inout_ PDIRENT Dirent
Definition: cdprocs.h:424
_In_ PFCB Fcb
Definition: cdprocs.h:159
return STATUS_SUCCESS
Definition: btrfs.c:3014
unsigned short MaximumLength
Definition: sprintf.c:452
USHORT FinalNameLength
Definition: fatstruc.h:1123
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
ULONG FcbState
Definition: cdstruc.h:971
UNICODE_STRING ExactCaseLongName
Definition: fatstruc.h:1138
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define RtlOemStringToCountedUnicodeSize(STRING)
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by FatCreateDcb(), FatCreateFcb(), and FatSetRenameInfo().

◆ FatCreateCcb()

PCCB FatCreateCcb ( IN PIRP_CONTEXT  IrpContext)

Definition at line 2143 of file strucsup.c.

2161 {
2162  PCCB Ccb;
2163 
2164  PAGED_CODE();
2165 
2166  DebugTrace(+1, Dbg, "FatCreateCcb\n", 0);
2167 
2168  //
2169  // Allocate a new CCB Record
2170  //
2171 
2172  Ccb = FatAllocateCcb();
2173 
2174  RtlZeroMemory( Ccb, sizeof(CCB) );
2175 
2176  //
2177  // Set the proper node type code and node byte size
2178  //
2179 
2180  Ccb->NodeTypeCode = FAT_NTC_CCB;
2181  Ccb->NodeByteSize = sizeof(CCB);
2182 
2183  //
2184  // return and tell the caller
2185  //
2186 
2187  DebugTrace(-1, Dbg, "FatCreateCcb -> %p\n", Ccb);
2188 
2189  UNREFERENCED_PARAMETER( IrpContext );
2190 
2191  return Ccb;
2192 }
#define Dbg
Definition: strucsup.c:29
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
Definition: cdstruc.h:1067
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define FAT_NTC_CCB
Definition: nodetype.h:32
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
struct _CCB CCB
INLINE PCCB FatAllocateCcb()
Definition: strucsup.c:56
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define PAGED_CODE()

◆ FatCreateDcb()

PDCB FatCreateDcb ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb,
IN PDCB  ParentDcb,
IN ULONG  LfnOffsetWithinDirectory,
IN ULONG  DirentOffsetWithinDirectory,
IN PDIRENT  Dirent,
IN PUNICODE_STRING Lfn  OPTIONAL 
)

Definition at line 1611 of file strucsup.c.

1655 {
1656  PDCB Dcb = NULL;
1657 
1658  //
1659  // The following variables are used for abnormal unwind
1660  //
1661 
1662  PVOID UnwindStorage[2] = { NULL, NULL };
1663  PERESOURCE UnwindResource = NULL;
1664  PERESOURCE UnwindResource2 = NULL;
1665  PLIST_ENTRY UnwindEntryList = NULL;
1666  PLARGE_MCB UnwindMcb = NULL;
1667  POPLOCK UnwindOplock = NULL;
1668 
1669  PAGED_CODE();
1670 
1671  DebugTrace(+1, Dbg, "FatCreateDcb\n", 0);
1672 
1673  _SEH2_TRY {
1674 
1675  //
1676  // assert that the only time we are called is if wait is true
1677  //
1678 
1679  NT_ASSERT( FlagOn(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT) );
1680 
1681  //
1682  // Allocate a new DCB, and zero it out
1683  //
1684 
1685  UnwindStorage[0] = Dcb = FatAllocateFcb();
1686 
1687  RtlZeroMemory( Dcb, sizeof(DCB) );
1688 
1689  UnwindStorage[1] =
1690  Dcb->NonPaged = FatAllocateNonPagedFcb();
1691 
1692  RtlZeroMemory( Dcb->NonPaged, sizeof( NON_PAGED_FCB ) );
1693 
1694  //
1695  // Set the proper node type code, node byte size and call backs
1696  //
1697 
1698  Dcb->Header.NodeTypeCode = FAT_NTC_DCB;
1699  Dcb->Header.NodeByteSize = sizeof(DCB);
1700 
1701  Dcb->FcbCondition = FcbGood;
1702 
1703  //
1704  // The initial state, open count, and directory change count fields are
1705  // already zero so we can skip setting them
1706  //
1707 
1708  //
1709  // Initialize the resource variable
1710  //
1711 
1712 
1713  UnwindResource =
1714  Dcb->Header.Resource = FatAllocateResource();
1715 
1716  //
1717  // Initialize the PagingIo Resource. We no longer use the FsRtl common
1718  // shared pool because this led to a) deadlocks due to cases where files
1719  // and their parent directories shared a resource and b) there is no way
1720  // to anticipate inter-driver induced deadlock via recursive operation.
1721  //
1722 
1723  UnwindResource2 =
1724  Dcb->Header.PagingIoResource = FatAllocateResource();
1725 
1726  //
1727  // Insert this Dcb into our parent dcb's queue
1728  //
1729  // There is a deep reason why this goes on the head, to allow us
1730  // to easily enumerate all child directories before child files.
1731  // This is important to let us maintain whole-volume lockorder
1732  // via BottomUp enumeration.
1733  //
1734 
1735  InsertHeadList( &ParentDcb->Specific.Dcb.ParentDcbQueue,
1736  &Dcb->ParentDcbLinks );
1737  UnwindEntryList = &Dcb->ParentDcbLinks;
1738 
1739  //
1740  // Point back to our parent dcb
1741  //
1742 
1743  Dcb->ParentDcb = ParentDcb;
1744 
1745  //
1746  // Set the Vcb
1747  //
1748 
1749  Dcb->Vcb = Vcb;
1750 
1751  //
1752  // Set the dirent offset within the directory
1753  //
1754 
1755  Dcb->LfnOffsetWithinDirectory = LfnOffsetWithinDirectory;
1756  Dcb->DirentOffsetWithinDirectory = DirentOffsetWithinDirectory;
1757 
1758  //
1759  // Set the DirentFatFlags and LastWriteTime
1760  //
1761 
1762  Dcb->DirentFatFlags = Dirent->Attributes;
1763 
1764  Dcb->LastWriteTime = FatFatTimeToNtTime( IrpContext,
1766  0 );
1767 
1768  //
1769  // These fields are only non-zero when in Chicago mode.
1770  //
1771 
1772  if (FatData.ChicagoMode) {
1773 
1774  LARGE_INTEGER FatSystemJanOne1980 = {0};
1775 
1776  //
1777  // If either date is possibly zero, get the system
1778  // version of 1/1/80.
1779  //
1780 
1781  if ((((PUSHORT)Dirent)[9] & ((PUSHORT)Dirent)[8]) == 0) {
1782 
1784  &FatSystemJanOne1980 );
1785  }
1786 
1787  //
1788  // Only do the really hard work if this field is non-zero.
1789  //
1790 
1791  if (((PUSHORT)Dirent)[9] != 0) {
1792 
1793  Dcb->LastAccessTime =
1794  FatFatDateToNtTime( IrpContext,
1795  Dirent->LastAccessDate );
1796 
1797  } else {
1798 
1799  Dcb->LastAccessTime = FatSystemJanOne1980;
1800  }
1801 
1802  //
1803  // Only do the really hard work if this field is non-zero.
1804  //
1805 
1806  if (((PUSHORT)Dirent)[8] != 0) {
1807 
1808  Dcb->CreationTime =
1809  FatFatTimeToNtTime( IrpContext,
1811  Dirent->CreationMSec );
1812 
1813  } else {
1814 
1815  Dcb->CreationTime = FatSystemJanOne1980;
1816  }
1817  }
1818 
1819  //
1820  // Initialize Advanced FCB Header fields
1821  //
1822 
1823  ExInitializeFastMutex( &Dcb->NonPaged->AdvancedFcbHeaderMutex );
1824  FsRtlSetupAdvancedHeader( &Dcb->Header,
1825  &Dcb->NonPaged->AdvancedFcbHeaderMutex );
1826 
1827  //
1828  // Initialize the Mcb
1829  //
1830 
1832  UnwindMcb = &Dcb->Mcb;
1833 
1834  //
1835  // Set the file size, first cluster of file, and allocation size
1836  // based on the information stored in the dirent
1837  //
1838 
1839  Dcb->FirstClusterOfFile = (ULONG)Dirent->FirstClusterOfFile;
1840 
1841  if ( FatIsFat32(Dcb->Vcb) ) {
1842 
1843  Dcb->FirstClusterOfFile += Dirent->FirstClusterOfFileHi << 16;
1844  }
1845 
1846  if ( Dcb->FirstClusterOfFile == 0 ) {
1847 
1848  Dcb->Header.AllocationSize.QuadPart = 0;
1849 
1850  } else {
1851 
1852  Dcb->Header.AllocationSize.QuadPart = FCB_LOOKUP_ALLOCATIONSIZE_HINT;
1853  }
1854 
1855 
1856  // initialize the notify queues, and the parent dcb queue.
1857  //
1858 
1859  InitializeListHead( &Dcb->Specific.Dcb.ParentDcbQueue );
1860 
1861  //
1862  // Setup the free dirent bitmap buffer. Since we don't know the
1863  // size of the directory, leave it zero for now.
1864  //
1865 
1866  RtlInitializeBitMap( &Dcb->Specific.Dcb.FreeDirentBitmap,
1867  NULL,
1868  0 );
1869 
1870  //
1871  // Set our two create dirent aids to represent that we have yet to
1872  // enumerate the directory for never used or deleted dirents.
1873  //
1874 
1875  Dcb->Specific.Dcb.UnusedDirentVbo = 0xffffffff;
1876  Dcb->Specific.Dcb.DeletedDirentHint = 0xffffffff;
1877 
1878 #if (NTDDI_VERSION >= NTDDI_WIN8)
1879  //
1880  // Initialize the oplock structure.
1881  //
1882 
1884  UnwindOplock = FatGetFcbOplock(Dcb);
1885 #endif
1886 
1887  //
1888  // Postpone initializing the cache map until we need to do a read/write
1889  // of the directory file.
1890 
1891 
1892  //
1893  // set the file names. This must be the last thing we do.
1894  //
1895 
1896  FatConstructNamesInFcb( IrpContext,
1897  Dcb,
1898  Dirent,
1899  Lfn );
1900 
1901  Dcb->ShortName.FileNameDos = TRUE;
1902 
1903  } _SEH2_FINALLY {
1904 
1906 
1907  //
1908  // If this is an abnormal termination then undo our work
1909  //
1910 
1911  if (_SEH2_AbnormalTermination()) {
1912 
1913  ULONG i;
1914 
1915  if (UnwindOplock != NULL) { FsRtlUninitializeOplock( UnwindOplock ); }
1916  if (UnwindMcb != NULL) { FsRtlUninitializeLargeMcb( UnwindMcb ); }
1917  if (UnwindEntryList != NULL) { RemoveEntryList( UnwindEntryList ); }
1918  if (UnwindResource != NULL) { FatFreeResource( UnwindResource ); }
1919  if (UnwindResource2 != NULL) { FatFreeResource( UnwindResource2 ); }
1920 
1921  for (i = 0; i < sizeof(UnwindStorage)/sizeof(PVOID); i += 1) {
1922  if (UnwindStorage[i] != NULL) { ExFreePool( UnwindStorage[i] ); }
1923  }
1924  }
1925 
1926  DebugTrace(-1, Dbg, "FatCreateDcb -> %p\n", Dcb);
1927  } _SEH2_END;
1928 
1929  //
1930  // return and tell the caller
1931  //
1932 
1933  DebugTrace(-1, Dbg, "FatCreateDcb -> %p\n", Dcb);
1934 
1935  return Dcb;
1936 }
LONGLONG CreationTime
Definition: cdstruc.h:1030
LARGE_INTEGER LastWriteTime
Definition: fatstruc.h:921
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
#define FCB_LOOKUP_ALLOCATIONSIZE_HINT
Definition: fatstruc.h:1240
LARGE_INTEGER FatFatDateToNtTime(_In_ PIRP_CONTEXT IrpContext, _In_ FAT_DATE FatDate)
Definition: timesup.c:171
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING Lfn
Definition: create.c:4137
#define Dbg
Definition: strucsup.c:29
#define TRUE
Definition: types.h:120
Definition: cdstruc.h:902
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
FCB DCB
Definition: fatstruc.h:1183
BOOLEAN ChicagoMode
Definition: fatstruc.h:86
VOID NTAPI FsRtlUninitializeOplock(IN POPLOCK Oplock)
Definition: oplock.c:1602
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB ParentDcb
Definition: create.c:4137
PDCB FatCreateDcb(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PDCB ParentDcb, IN ULONG LfnOffsetWithinDirectory, IN ULONG DirentOffsetWithinDirectory, IN PDIRENT Dirent, IN PUNICODE_STRING Lfn OPTIONAL)
Definition: strucsup.c:1611
_SEH2_TRY
Definition: create.c:4226
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
LARGE_INTEGER FatFatTimeToNtTime(_In_ PIRP_CONTEXT IrpContext, _In_ FAT_TIME_STAMP FatTime, _In_ UCHAR TenMilliSeconds)
Definition: timesup.c:233
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
LARGE_INTEGER FatJanOne1980
Definition: fatdata.c:73
#define FatGetFcbOplock(F)
Definition: fatprocs.h:1656
VOID NTAPI FsRtlInitializeLargeMcb(IN PLARGE_MCB Mcb, IN POOL_TYPE PoolType)
Definition: largemcb.c:450
smooth NULL
Definition: ftsmooth.c:416
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:13
#define DebugUnwind(X)
Definition: fatdata.h:315
FAT_DATA FatData
Definition: fatdata.c:56
if(!(yy_init))
Definition: macro.lex.yy.c:714
VOID NTAPI FsRtlInitializeOplock(IN OUT POPLOCK Oplock)
Definition: oplock.c:1402
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define Vcb
Definition: cdprocs.h:1415
INLINE VOID FatFreeResource(IN PERESOURCE Resource)
Definition: strucsup.c:145
Definition: typedefs.h:119
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatIsFat32(VCB)
Definition: fatprocs.h:1446
INLINE PFCB FatAllocateFcb()
Definition: strucsup.c:77
_SEH2_END
Definition: create.c:4400
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_SEH2_FINALLY
Definition: create.c:4371
VOID NTAPI FsRtlUninitializeLargeMcb(IN PLARGE_MCB Mcb)
Definition: largemcb.c:1053
#define FAT_NTC_DCB
Definition: nodetype.h:30
ULONG FirstClusterOfFile
Definition: fatstruc.h:817
unsigned int ULONG
Definition: retypes.h:1
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT _Inout_ PDIRENT Dirent
Definition: cdprocs.h:424
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
INLINE PERESOURCE FatAllocateResource()
Definition: strucsup.c:128
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB * Dcb
Definition: create.c:4137
unsigned short * PUSHORT
Definition: retypes.h:2
INLINE PNON_PAGED_FCB FatAllocateNonPagedFcb()
Definition: strucsup.c:101
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID FatConstructNamesInFcb(IN PIRP_CONTEXT IrpContext, PFCB Fcb, PDIRENT Dirent, PUNICODE_STRING Lfn OPTIONAL)
Definition: strucsup.c:3010
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ FatCreateFcb()

PFCB FatCreateFcb ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb,
IN PDCB  ParentDcb,
IN ULONG  LfnOffsetWithinDirectory,
IN ULONG  DirentOffsetWithinDirectory,
IN PDIRENT  Dirent,
IN PUNICODE_STRING Lfn  OPTIONAL,
IN PUNICODE_STRING OrigLfn  OPTIONAL,
IN BOOLEAN  IsPagingFile,
IN BOOLEAN  SingleResource 
)

Definition at line 1240 of file strucsup.c.

1289 {
1290  PFCB Fcb = NULL;
1292 
1293  //
1294  // The following variables are used for abnormal unwind
1295  //
1296 
1297  PVOID UnwindStorage[2] = { NULL, NULL };
1298  PERESOURCE UnwindResource = NULL;
1299  PERESOURCE UnwindResource2 = NULL;
1300  PLIST_ENTRY UnwindEntryList = NULL;
1301  PLARGE_MCB UnwindMcb = NULL;
1302  PFILE_LOCK UnwindFileLock = NULL;
1303  POPLOCK UnwindOplock = NULL;
1304 
1305  PAGED_CODE();
1306 
1307  UNREFERENCED_PARAMETER( OrigLfn );
1308 
1309  DebugTrace(+1, Dbg, "FatCreateFcb\n", 0);
1310 
1311  _SEH2_TRY {
1312 
1313  //
1314  // Determine the pool type we should be using for the fcb and the
1315  // mcb structure
1316  //
1317 
1318  if (IsPagingFile) {
1319 
1320  PoolType = NonPagedPoolNx;
1321  Fcb = UnwindStorage[0] = FsRtlAllocatePoolWithTag( NonPagedPoolNx,
1322  sizeof(FCB),
1323  TAG_FCB );
1324  } else {
1325 
1326  PoolType = PagedPool;
1327  Fcb = UnwindStorage[0] = FatAllocateFcb();
1328 
1329  }
1330 
1331  //
1332  // ... and zero it out
1333  //
1334 
1335  RtlZeroMemory( Fcb, sizeof(FCB) );
1336 
1337  UnwindStorage[1] =
1339 
1340  RtlZeroMemory( Fcb->NonPaged, sizeof( NON_PAGED_FCB ) );
1341 
1342  //
1343  // Set the proper node type code, node byte size, and call backs
1344  //
1345 
1346  Fcb->Header.NodeTypeCode = FAT_NTC_FCB;
1347  Fcb->Header.NodeByteSize = sizeof(FCB);
1348 
1350 
1351  //
1352  // Check to see if we need to set the Fcb state to indicate that this
1353  // is a paging/system file. This will prevent it from being opened
1354  // again.
1355  //
1356 
1357  if (IsPagingFile) {
1358 
1360  }
1361 
1362  //
1363  // The initial state, open count, and segment objects fields are already
1364  // zero so we can skip setting them
1365  //
1366 
1367  //
1368  // Initialize the resource variable
1369  //
1370 
1371 
1372  UnwindResource =
1373  Fcb->Header.Resource = FatAllocateResource();
1374 
1375  //
1376  // Initialize the PagingIo Resource. We no longer use the FsRtl common
1377  // shared pool because this led to a) deadlocks due to cases where files
1378  // and their parent directories shared a resource and b) there is no way
1379  // to anticipate inter-driver induced deadlock via recursive operation.
1380  //
1381 
1382  if (SingleResource) {
1383 
1384  Fcb->Header.PagingIoResource = Fcb->Header.Resource;
1385 
1386  } else {
1387 
1388  UnwindResource2 =
1389  Fcb->Header.PagingIoResource = FatAllocateResource();
1390  }
1391 
1392  //
1393  // Insert this fcb into our parent dcb's queue.
1394  //
1395  // There is a deep reason why this goes on the tail, to allow us
1396  // to easily enumerate all child directories before child files.
1397  // This is important to let us maintain whole-volume lockorder
1398  // via BottomUp enumeration.
1399  //
1400 
1401  InsertTailList( &ParentDcb->Specific.Dcb.ParentDcbQueue,
1402  &Fcb->ParentDcbLinks );
1403  UnwindEntryList = &Fcb->ParentDcbLinks;
1404 
1405  //
1406  // Point back to our parent dcb
1407  //
1408 
1409  Fcb->ParentDcb = ParentDcb;
1410 
1411  //
1412  // Set the Vcb
1413  //
1414 
1415  Fcb->Vcb = Vcb;
1416 
1417  //
1418  // Set the dirent offset within the directory
1419  //
1420 
1421  Fcb->LfnOffsetWithinDirectory = LfnOffsetWithinDirectory;
1422  Fcb->DirentOffsetWithinDirectory = DirentOffsetWithinDirectory;
1423 
1424  //
1425  // Set the DirentFatFlags and LastWriteTime
1426  //
1427 
1428  Fcb->DirentFatFlags = Dirent->Attributes;
1429 
1430  Fcb->LastWriteTime = FatFatTimeToNtTime( IrpContext,
1432  0 );
1433 
1434  //
1435  // These fields are only non-zero when in Chicago mode.
1436  //
1437 
1438  if (FatData.ChicagoMode) {
1439 
1440  LARGE_INTEGER FatSystemJanOne1980 = {0};
1441 
1442  //
1443  // If either date is possibly zero, get the system
1444  // version of 1/1/80.
1445  //
1446 
1447  if ((((PUSHORT)Dirent)[9] & ((PUSHORT)Dirent)[8]) == 0) {
1448 
1450  &FatSystemJanOne1980 );
1451  }
1452 
1453  //
1454  // Only do the really hard work if this field is non-zero.
1455  //
1456 
1457  if (((PUSHORT)Dirent)[9] != 0) {
1458 
1459  Fcb->LastAccessTime =
1460  FatFatDateToNtTime( IrpContext,
1461  Dirent->LastAccessDate );
1462 
1463  } else {
1464 
1465  Fcb->LastAccessTime = FatSystemJanOne1980;
1466  }
1467 
1468  //
1469  // Only do the really hard work if this field is non-zero.
1470  //
1471 
1472  if (((PUSHORT)Dirent)[8] != 0) {
1473 
1474  Fcb->CreationTime =
1475  FatFatTimeToNtTime( IrpContext,
1477  Dirent->CreationMSec );
1478 
1479  } else {
1480 
1481  Fcb->CreationTime = FatSystemJanOne1980;
1482  }
1483  }
1484 
1485  //
1486  // Initialize Advanced FCB Header fields
1487  //
1488 
1490  FsRtlSetupAdvancedHeader( &Fcb->Header,
1492 
1493  //
1494  // To make FAT match the present functionality of NTFS, disable
1495  // stream contexts on paging files
1496  //
1497 
1498  if (IsPagingFile) {
1499 
1502  }
1503 
1504  //
1505  // Initialize the Mcb
1506  //
1507 
1509  UnwindMcb = &Fcb->Mcb;
1510 
1511  //
1512  // Set the file size, valid data length, first cluster of file,
1513  // and allocation size based on the information stored in the dirent
1514  //
1515 
1516  Fcb->Header.FileSize.LowPart = Dirent->FileSize;
1517 
1518  Fcb->Header.ValidDataLength.LowPart = Dirent->FileSize;
1519 
1520  Fcb->ValidDataToDisk = Dirent->FileSize;
1521 
1523 
1524  if ( FatIsFat32(Vcb) ) {
1525 
1526  Fcb->FirstClusterOfFile += Dirent->FirstClusterOfFileHi << 16;
1527  }
1528 
1529  if ( Fcb->FirstClusterOfFile == 0 ) {
1530 
1531  Fcb->Header.AllocationSize.QuadPart = 0;
1532 
1533  } else {
1534 
1535  Fcb->Header.AllocationSize.QuadPart = FCB_LOOKUP_ALLOCATIONSIZE_HINT;
1536  }
1537 
1538 
1539  //
1540  // Initialize the Fcb's file lock record
1541  //
1542 
1543  FsRtlInitializeFileLock( &Fcb->Specific.Fcb.FileLock, NULL, NULL );
1544  UnwindFileLock = &Fcb->Specific.Fcb.FileLock;
1545 
1546  //
1547  // Initialize the oplock structure.
1548  //
1549 
1551  UnwindOplock = FatGetFcbOplock(Fcb);
1552 
1553  //
1554  // Indicate that Fast I/O is possible
1555  //
1556 
1557  Fcb->Header.IsFastIoPossible = TRUE;
1558 
1559  //
1560  // Set the file names. This must be the last thing we do.
1561  //
1562 
1563  FatConstructNamesInFcb( IrpContext,
1564  Fcb,
1565  Dirent,
1566  Lfn );
1567 
1568  //
1569  // Drop the shortname hint so prefix searches can figure out
1570  // what they found
1571  //
1572 
1574 
1575  } _SEH2_FINALLY {
1576 
1578 
1579  //
1580  // If this is an abnormal termination then undo our work
1581  //
1582 
1583  if (_SEH2_AbnormalTermination()) {
1584 
1585  ULONG i;
1586 
1587  if (UnwindOplock != NULL) { FsRtlUninitializeOplock( UnwindOplock ); }
1588  if (UnwindFileLock != NULL) { FsRtlUninitializeFileLock( UnwindFileLock ); }
1589  if (UnwindMcb != NULL) { FsRtlUninitializeLargeMcb( UnwindMcb ); }
1590  if (UnwindEntryList != NULL) { RemoveEntryList( UnwindEntryList ); }
1591  if (UnwindResource != NULL) { FatFreeResource( UnwindResource ); }
1592  if (UnwindResource2 != NULL) { FatFreeResource( UnwindResource2 ); }
1593 
1594  for (i = 0; i < sizeof(UnwindStorage)/sizeof(PVOID); i += 1) {
1595  if (UnwindStorage[i] != NULL) { ExFreePool( UnwindStorage[i] ); }
1596  }
1597  }
1598 
1599  DebugTrace(-1, Dbg, "FatCreateFcb -> %p\n", Fcb);
1600  } _SEH2_END;
1601 
1602  //
1603  // return and tell the caller
1604  //
1605 
1606  return Fcb;
1607 }
LONGLONG CreationTime
Definition: cdstruc.h:1030
LARGE_INTEGER LastWriteTime
Definition: fatstruc.h:921
#define TAG_FCB
Definition: vfat.h:547
#define FCB_STATE_SYSTEM_FILE
Definition: fatstruc.h:1198
#define FCB_LOOKUP_ALLOCATIONSIZE_HINT
Definition: fatstruc.h:1240
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
LARGE_INTEGER FatFatDateToNtTime(_In_ PIRP_CONTEXT IrpContext, _In_ FAT_DATE FatDate)
Definition: timesup.c:171
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
VOID NTAPI FsRtlInitializeFileLock(IN PFILE_LOCK FileLock, IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL, IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL)
Definition: filelock.c:1261
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING Lfn
Definition: create.c:4137
#define Dbg
Definition: strucsup.c:29
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
Definition: cdstruc.h:902
struct _FCB::@712::@715 Fcb
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
Definition: filelock.c:1278
#define FSRTL_FLAG2_IS_PAGING_FILE
Definition: fsrtltypes.h:57
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
BOOLEAN ChicagoMode
Definition: fatstruc.h:86
VOID NTAPI FsRtlUninitializeOplock(IN POPLOCK Oplock)
Definition: oplock.c:1602
LIST_ENTRY ParentDcbLinks
Definition: fatstruc.h:827
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB ParentDcb
Definition: create.c:4137
#define InsertTailList(ListHead, Entry)
struct _FCB * ParentDcb
Definition: fatstruc.h:835
_SEH2_TRY
Definition: create.c:4226
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN FileNameDos
Definition: fatstruc.h:703
LARGE_INTEGER FatFatTimeToNtTime(_In_ PIRP_CONTEXT IrpContext, _In_ FAT_TIME_STAMP FatTime, _In_ UCHAR TenMilliSeconds)
Definition: timesup.c:233
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LARGE_INTEGER LastAccessTime
Definition: fatstruc.h:920
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
#define FCB_STATE_PAGING_FILE
Definition: fatstruc.h:1194
LARGE_INTEGER FatJanOne1980
Definition: fatdata.c:73
#define FatGetFcbOplock(F)
Definition: fatprocs.h:1656
UCHAR DirentFatFlags
Definition: fatstruc.h:1132
PNON_PAGED_FCB NonPaged
Definition: fatstruc.h:810
VOID NTAPI FsRtlInitializeLargeMcb(IN PLARGE_MCB Mcb, IN POOL_TYPE PoolType)
Definition: largemcb.c:450
struct _FCB FCB
smooth NULL
Definition: ftsmooth.c:416
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:13
#define DebugUnwind(X)
Definition: fatdata.h:315
FAT_DATA FatData
Definition: fatdata.c:56
if(!(yy_init))
Definition: macro.lex.yy.c:714
INT POOL_TYPE
Definition: typedefs.h:78
VOID NTAPI FsRtlInitializeOplock(IN OUT POPLOCK Oplock)
Definition: oplock.c:1402
VBO LfnOffsetWithinDirectory
Definition: fatstruc.h:912
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define Vcb
Definition: cdprocs.h:1415
#define FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS
Definition: fsrtltypes.h:55
CD_MCB Mcb
Definition: cdstruc.h:1016
FAST_MUTEX AdvancedFcbHeaderMutex
Definition: fatstruc.h:749
INLINE VOID FatFreeResource(IN PERESOURCE Resource)
Definition: strucsup.c:145
Definition: typedefs.h:119
#define FatIsFat32(VCB)
Definition: fatprocs.h:1446
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
PFCB FatCreateFcb(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PDCB ParentDcb, IN ULONG LfnOffsetWithinDirectory, IN ULONG DirentOffsetWithinDirectory, IN PDIRENT Dirent, IN PUNICODE_STRING Lfn OPTIONAL, IN PUNICODE_STRING OrigLfn OPTIONAL, IN BOOLEAN IsPagingFile, IN BOOLEAN SingleResource)
Definition: strucsup.c:1240
INLINE PFCB FatAllocateFcb()
Definition: strucsup.c:77
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
_SEH2_END
Definition: create.c:4400
VBO DirentOffsetWithinDirectory
Definition: fatstruc.h:905
ULONG ValidDataToDisk
Definition: fatstruc.h:927
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
_SEH2_FINALLY
Definition: create.c:4371
VOID NTAPI FsRtlUninitializeLargeMcb(IN PLARGE_MCB Mcb)
Definition: largemcb.c:1053
ULONG FirstClusterOfFile
Definition: fatstruc.h:817
unsigned int ULONG
Definition: retypes.h:1
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT _Inout_ PDIRENT Dirent
Definition: cdprocs.h:424
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PVCB Vcb
Definition: cdstruc.h:933
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
INLINE PERESOURCE FatAllocateResource()
Definition: strucsup.c:128
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
ULONG FcbState
Definition: cdstruc.h:971
unsigned short * PUSHORT
Definition: retypes.h:2
union _FCB::@712 Specific
INLINE PNON_PAGED_FCB FatAllocateNonPagedFcb()
Definition: strucsup.c:101
#define FAT_NTC_FCB
Definition: nodetype.h:29
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID FatConstructNamesInFcb(IN PIRP_CONTEXT IrpContext, PFCB Fcb, PDIRENT Dirent, PUNICODE_STRING Lfn OPTIONAL)
Definition: strucsup.c:3010
#define PAGED_CODE()
FCB_CONDITION FcbCondition
Definition: fatstruc.h:849

◆ FatCreateIrpContext()

PIRP_CONTEXT FatCreateIrpContext ( IN PIRP  Irp,
IN BOOLEAN  Wait 
)

Definition at line 2289 of file strucsup.c.

2312 {
2313  PIRP_CONTEXT IrpContext;
2315 
2316  PAGED_CODE();
2317 
2318  DebugTrace(+1, Dbg, "FatCreateIrpContext\n", 0);
2319 
2321 
2322  //
2323  // The only operations a filesystem device object should ever receive
2324  // are create/teardown of fsdo handles and operations which do not
2325  // occur in the context of fileobjects (i.e., mount).
2326  //
2327 
2329 
2330  if (IrpSp->FileObject != NULL &&
2334 
2336  }
2337 
2338  NT_ASSERT( IrpSp->FileObject != NULL ||
2339 
2342  IrpSp->Parameters.FileSystemControl.FsControlCode == FSCTL_INVALIDATE_VOLUMES) ||
2343 
2346 
2348  }
2349 
2350  //
2351  // Attemtp to allocate from the region first and failing that allocate
2352  // from pool.
2353  //
2354 
2355  DebugDoit( FatFsdEntryCount += 1);
2356 
2357  IrpContext = FatAllocateIrpContext();
2358 
2359  //
2360  // Zero out the irp context.
2361  //
2362 
2363  RtlZeroMemory( IrpContext, sizeof(IRP_CONTEXT) );
2364 
2365  //
2366  // Set the proper node type code and node byte size
2367  //
2368 
2369  IrpContext->NodeTypeCode = FAT_NTC_IRP_CONTEXT;
2370  IrpContext->NodeByteSize = sizeof(IRP_CONTEXT);
2371 
2372  //
2373  // Set the originating Irp field
2374  //
2375 
2376  IrpContext->OriginatingIrp = Irp;
2377 
2378  //
2379  // Major/Minor Function codes
2380  //
2381 
2382  IrpContext->MajorFunction = IrpSp->MajorFunction;
2383  IrpContext->MinorFunction = IrpSp->MinorFunction;
2384 
2385  //
2386  // Copy RealDevice for workque algorithms, and also set Write Through
2387  // and Removable Media if there is a file object. Only file system
2388  // control Irps won't have a file object, and they should all have
2389  // a Vpb as the first IrpSp location.
2390  //
2391 
2392  if (IrpSp->FileObject != NULL) {
2393 
2395 
2396  IrpContext->RealDevice = FileObject->DeviceObject;
2397  IrpContext->Vcb = &((PVOLUME_DEVICE_OBJECT)(IrpSp->DeviceObject))->Vcb;
2398 
2399  //
2400  // See if the request is Write Through. Look for both FileObjects opened
2401  // as write through, and non-cached requests with the SL_WRITE_THROUGH flag set.
2402  //
2403  // The latter can only originate from kernel components. (Note - NtWriteFile()
2404  // does redundantly set the SL_W_T flag for all requests it issues on write
2405  // through file objects)
2406  //
2407 
2408  if (IsFileWriteThrough( FileObject, IrpContext->Vcb ) ||
2409  ( (IrpSp->MajorFunction == IRP_MJ_WRITE) &&
2410  BooleanFlagOn( Irp->Flags, IRP_NOCACHE) &&
2412 
2413  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_WRITE_THROUGH);
2414  }
2415  } else if (IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL) {
2416 
2417  IrpContext->RealDevice = IrpSp->Parameters.MountVolume.Vpb->RealDevice;
2418  }
2419 
2420  //
2421  // Set the wait parameter
2422  //
2423 
2424  if (Wait) { SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT); }
2425 
2426  //
2427  // Set the recursive file system call parameter. We set it true if
2428  // the TopLevelIrp field in the thread local storage is not the current
2429  // irp, otherwise we leave it as FALSE.
2430  //
2431 
2432  if ( IoGetTopLevelIrp() != Irp) {
2433 
2434  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_RECURSIVE_CALL);
2435  }
2436 
2437  //
2438  // return and tell the caller
2439  //
2440 
2441  DebugTrace(-1, Dbg, "FatCreateIrpContext -> %p\n", IrpContext);
2442 
2443  return IrpContext;
2444 }
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define DebugDoit(X)
Definition: fatdata.h:316
#define IRP_MJ_SHUTDOWN
#define Dbg
Definition: strucsup.c:29
_In_ PIRP Irp
Definition: csq.h:116
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define IRP_CONTEXT_FLAG_WRITE_THROUGH
Definition: ext2fs.h:1079
#define FatDeviceIsFatFsdo(D)
Definition: fatprocs.h:3092
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define IRP_NOCACHE
#define ExRaiseStatus
Definition: ntoskrnl.h:96
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
VOLUME_DEVICE_OBJECT * PVOLUME_DEVICE_OBJECT
Definition: cdstruc.h:769
INLINE PIRP_CONTEXT FatAllocateIrpContext()
Definition: strucsup.c:163
#define FSCTL_INVALIDATE_VOLUMES
Definition: nt_native.h:847
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4383
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4382
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define Vcb
Definition: cdprocs.h:1415
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3202
PIRP NTAPI IoGetTopLevelIrp(VOID)
Definition: irp.c:1843
* PFILE_OBJECT
Definition: iotypes.h:1978
struct _IRP_CONTEXT IRP_CONTEXT
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define FAT_NTC_IRP_CONTEXT
Definition: nodetype.h:33
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define IsFileWriteThrough(FO, VCB)
Definition: fatprocs.h:2793
#define SL_WRITE_THROUGH
Definition: iotypes.h:1804
#define IRP_MJ_CLEANUP
#define IRP_CONTEXT_FLAG_RECURSIVE_CALL
Definition: fatstruc.h:1561
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
#define PAGED_CODE()
IN BOOLEAN Wait
Definition: fatprocs.h:1538
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by _Function_class_(), _Requires_lock_held_(), FatMultiAsyncCompletionRoutine(), and FatSingleAsyncCompletionRoutine().

◆ FatDeallocateCcbStrings()

VOID FatDeallocateCcbStrings ( IN PCCB  Ccb)

Definition at line 2197 of file strucsup.c.

2215 {
2216  PAGED_CODE();
2217 
2218  //
2219  // If we allocated query template buffers, deallocate them now.
2220  //
2221 
2223 
2224  NT_ASSERT( Ccb->UnicodeQueryTemplate.Buffer);
2226  RtlFreeUnicodeString( &Ccb->UnicodeQueryTemplate );
2227  }
2228 
2230 
2231  NT_ASSERT( Ccb->OemQueryTemplate.Wild.Buffer );
2233  RtlFreeOemString( &Ccb->OemQueryTemplate.Wild );
2234  }
2235 
2237 }
#define CCB_FLAG_FREE_OEM_BEST_FIT
Definition: fatstruc.h:1258
#define CCB_FLAG_FREE_UNICODE
Definition: fatstruc.h:1259
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
ULONG Flags
Definition: ntfs.h:532
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
VOID NTAPI RtlFreeOemString(POEM_STRING OemString)
#define CCB_FLAG_CLOSE_CONTEXT
Definition: fatstruc.h:1323
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by FatDeleteCcb().

◆ FatDeleteCcb()

VOID FatDeleteCcb ( IN PIRP_CONTEXT  IrpContext,
IN PCCB Ccb 
)

Definition at line 2242 of file strucsup.c.

2264 {
2265  PAGED_CODE();
2266 
2267  DebugTrace(+1, Dbg, "FatDeleteCcb, Ccb = %p\n", *Ccb);
2268 
2270 
2271  //
2272  // Deallocate the Ccb record
2273  //
2274 
2275  FatFreeCcb( *Ccb );
2276  *Ccb = NULL;
2277 
2278  //
2279  // return and tell the caller
2280  //
2281 
2282  DebugTrace(-1, Dbg, "FatDeleteCcb -> VOID\n", 0);
2283 
2284  UNREFERENCED_PARAMETER( IrpContext );
2285 }
#define Dbg
Definition: strucsup.c:29
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
INLINE VOID FatFreeCcb(IN PCCB Ccb)
Definition: strucsup.c:64
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
VOID FatDeallocateCcbStrings(IN PCCB Ccb)
Definition: strucsup.c:2197
#define PAGED_CODE()

Referenced by if().

◆ FatDeleteFcb()

VOID FatDeleteFcb ( IN PIRP_CONTEXT  IrpContext,
IN PFCB FcbPtr 
)

Definition at line 1940 of file strucsup.c.

1963 {
1964  PFCB Fcb = *FcbPtr;
1965 
1966  PAGED_CODE();
1967 
1968  DebugTrace(+1, Dbg, "FatDeleteFcb, Fcb = %p\n", Fcb);
1969 
1970  //
1971  // We can only delete this record if the open count is zero.
1972  //
1973 
1974  if (Fcb->OpenCount != 0) {
1975 
1976  DebugDump("Error deleting Fcb, Still Open\n", 0, Fcb);
1977 #ifdef _MSC_VER
1978 #pragma prefast( suppress:28159, "things are seriously wrong if we get here" )
1979 #endif
1980  FatBugCheck( 0, 0, 0 );
1981  }
1982 
1983  //
1984  // Better be an FCB/DCB.
1985  //
1986 
1987  if ((Fcb->Header.NodeTypeCode != FAT_NTC_DCB) &&
1988  (Fcb->Header.NodeTypeCode != FAT_NTC_ROOT_DCB) &&
1989  (Fcb->Header.NodeTypeCode != FAT_NTC_FCB)) {
1990 
1991 #ifdef _MSC_VER
1992 #pragma prefast( suppress:28159, "things are seriously wrong if we get here" )
1993 #endif
1994  FatBugCheck( 0, 0, 0 );
1995  }
1996 
1997  //
1998  // If this is a DCB then remove every Notify record from the two
1999  // notify queues
2000  //
2001 
2002  if ((Fcb->Header.NodeTypeCode == FAT_NTC_DCB) ||
2003  (Fcb->Header.NodeTypeCode == FAT_NTC_ROOT_DCB)) {
2004 
2005  //
2006  // If we allocated a free dirent bitmap buffer, free it.
2007  //
2008 
2009  if ((Fcb->Specific.Dcb.FreeDirentBitmap.Buffer != NULL) &&
2010  (Fcb->Specific.Dcb.FreeDirentBitmap.Buffer !=
2011  &Fcb->Specific.Dcb.FreeDirentBitmapBuffer[0])) {
2012 
2013  ExFreePool(Fcb->Specific.Dcb.FreeDirentBitmap.Buffer);
2014  }
2015 
2016 #if (NTDDI_VERSION >= NTDDI_WIN8)
2017  //
2018  // Uninitialize the oplock.
2019  //
2020 
2022 #endif
2023 
2024  NT_ASSERT( Fcb->Specific.Dcb.DirectoryFileOpenCount == 0 );
2025  NT_ASSERT( IsListEmpty(&Fcb->Specific.Dcb.ParentDcbQueue) );
2026  NT_ASSERT( NULL == Fcb->Specific.Dcb.DirectoryFile);
2027 
2028  } else {
2029 
2030  //
2031  // Uninitialize the byte range file locks and opportunistic locks
2032  //
2033 
2034  FsRtlUninitializeFileLock( &Fcb->Specific.Fcb.FileLock );
2036  }
2037 
2038 
2039  //
2040  // Release any Filter Context structures associated with this FCB
2041  //
2042 
2044 
2045  //
2046  // Uninitialize the Mcb
2047  //
2048 
2050 
2051  //
2052  // If this is not the root dcb then we need to remove ourselves from
2053  // our parents Dcb queue
2054  //
2055 
2056  if (Fcb->Header.NodeTypeCode != FAT_NTC_ROOT_DCB) {
2057 
2059  }
2060 
2061  //
2062  // Remove the entry from the splay table if there is still is one.
2063  //
2064 
2066 
2067  FatRemoveNames( IrpContext, Fcb );
2068  }
2069 
2070  //
2071  // Free the file name pool if allocated.
2072  //
2073 
2074  if (Fcb->Header.NodeTypeCode != FAT_NTC_ROOT_DCB) {
2075 
2076  //
2077  // If we blew up at inconvenient times, the shortname
2078  // could be null even though you will *never* see this
2079  // normally. Rename is a good example of this case.
2080  //
2081 
2082  if (Fcb->ShortName.Name.Oem.Buffer) {
2083 
2084  ExFreePool( Fcb->ShortName.Name.Oem.Buffer );
2085  }
2086 
2087  if (Fcb->FullFileName.Buffer) {
2088 
2090  }
2091  }
2092 
2093  if (Fcb->ExactCaseLongName.Buffer) {
2094 
2096  }
2097 
2098 #ifdef SYSCACHE_COMPILE
2099 
2100  if (Fcb->WriteMask) {
2101 
2102  ExFreePool( Fcb->WriteMask );
2103  }
2104 
2105 #endif
2106 
2107  //
2108  // Finally deallocate the Fcb and non-paged fcb records
2109  //
2110 
2111  FatFreeResource( Fcb->Header.Resource );
2112 
2113  if (Fcb->Header.PagingIoResource != Fcb->Header.Resource) {
2114 
2115  FatFreeResource( Fcb->Header.PagingIoResource );
2116  }
2117 
2118  //
2119  // If an Event was allocated, get rid of it.
2120  //
2121 
2123 
2125  }
2126 
2128 
2129  Fcb->Header.NodeTypeCode = NTC_UNDEFINED;
2130 
2131  FatFreeFcb( Fcb );
2132  *FcbPtr = NULL;
2133 
2134  //
2135  // and return to our caller
2136  //
2137 
2138  DebugTrace(-1, Dbg, "FatDeleteFcb -> VOID\n", 0);
2139 }
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
#define Dbg
Definition: strucsup.c:29
INLINE VOID FatFreeNonPagedFcb(PNON_PAGED_FCB NonPagedFcb)
Definition: strucsup.c:112
Definition: cdstruc.h:902
struct _FCB::@712::@715 Fcb
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
Definition: filelock.c:1278
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
struct _FCB::@712::@714 Dcb
VOID NTAPI FsRtlUninitializeOplock(IN POPLOCK Oplock)
Definition: oplock.c:1602
LIST_ENTRY ParentDcbLinks
Definition: fatstruc.h:827
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define FCB_STATE_NAMES_IN_SPLAY_TREE
Definition: fatstruc.h:1199
union _FILE_NAME_NODE::@711 Name
#define FatGetFcbOplock(F)
Definition: fatprocs.h:1656
#define FatBugCheck(A, B, C)
Definition: nodetype.h:104
PNON_PAGED_FCB NonPaged
Definition: fatstruc.h:810
#define NTC_UNDEFINED
Definition: nodetype.h:25
smooth NULL
Definition: ftsmooth.c:416
OEM_STRING Oem
Definition: fatstruc.h:692
VOID FatRemoveNames(IN PIRP_CONTEXT IrpContext, IN PFCB Fcb)
Definition: splaysup.c:222
VOID NTAPI FsRtlTeardownPerStreamContexts(IN PFSRTL_ADVANCED_FCB_HEADER AdvFcbHeader)
Definition: filtrctx.c:368
UNICODE_STRING FullFileName
Definition: fatstruc.h:1121
CD_MCB Mcb
Definition: cdstruc.h:1016
INLINE VOID FatFreeResource(IN PERESOURCE Resource)
Definition: strucsup.c:145
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
INLINE VOID FatFreeFcb(IN PFCB Fcb)
Definition: strucsup.c:85
#define FAT_NTC_ROOT_DCB
Definition: nodetype.h:31
PKEVENT OutstandingAsyncEvent
Definition: fatstruc.h:742
VOID NTAPI FsRtlUninitializeLargeMcb(IN PLARGE_MCB Mcb)
Definition: largemcb.c:1053
CLONG OpenCount
Definition: fatstruc.h:880
#define FAT_NTC_DCB
Definition: nodetype.h:30
_In_ PFCB Fcb
Definition: cdprocs.h:159
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
ULONG FcbState
Definition: cdstruc.h:971
union _FCB::@712 Specific
#define FAT_NTC_FCB
Definition: nodetype.h:29
UNICODE_STRING ExactCaseLongName
Definition: fatstruc.h:1138
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()
#define DebugDump(STR, LEVEL, PTR)
Definition: fatdata.h:314
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by FatDeleteVcb(), and if().

◆ FatDeleteIrpContext_Real()

VOID FatDeleteIrpContext_Real ( IN PIRP_CONTEXT  IrpContext)

Definition at line 2449 of file strucsup.c.

2471 {
2472  PAGED_CODE();
2473 
2474  DebugTrace(+1, Dbg, "FatDeleteIrpContext, IrpContext = %p\n", IrpContext);
2475 
2476  NT_ASSERT( IrpContext->NodeTypeCode == FAT_NTC_IRP_CONTEXT );
2477  NT_ASSERT( IrpContext->PinCount == 0 );
2478 
2479 
2480  //
2481  // If there is a FatIoContext that was allocated, free it.
2482  //
2483 
2484  if (IrpContext->FatIoContext != NULL) {
2485 
2486  if (!FlagOn(IrpContext->Flags, IRP_CONTEXT_STACK_IO_CONTEXT)) {
2487 
2488  if (IrpContext->FatIoContext->ZeroMdl) {
2489  IoFreeMdl( IrpContext->FatIoContext->ZeroMdl );
2490  }
2491 
2492  ExFreePool( IrpContext->FatIoContext );
2493  }
2494  }
2495 
2496  //
2497  // Drop the IrpContext.
2498  //
2499 
2500  FatFreeIrpContext( IrpContext );
2501 
2502  //
2503  // return and tell the caller
2504  //
2505 
2506  DebugTrace(-1, Dbg, "FatDeleteIrpContext -> VOID\n", 0);
2507 
2508  return;
2509 }
INLINE VOID FatFreeIrpContext(IN PIRP_CONTEXT IrpContext)
Definition: strucsup.c:174
#define Dbg
Definition: strucsup.c:29
#define IRP_CONTEXT_STACK_IO_CONTEXT
Definition: ext2fs.h:1084
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define FAT_NTC_IRP_CONTEXT
Definition: nodetype.h:33
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ FatDeleteVcb()

VOID FatDeleteVcb ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb 
)

Definition at line 760 of file strucsup.c.

783 {
784  PFCB Fcb;
785 
786  PAGED_CODE();
787 
788  DebugTrace(+1, Dbg, "FatDeleteVcb, Vcb = %p\n", Vcb);
789 
790  //
791  // If the IrpContext points to the VCB being deleted NULL out the stail
792  // pointer.
793  //
794 
795  if (IrpContext->Vcb == Vcb) {
796 
797  IrpContext->Vcb = NULL;
798 
799  }
800 
801  //
802  // Chuck the backpocket Vpb we kept just in case.
803  //
804 
805  if (Vcb->SwapVpb) {
806 
807  ExFreePool( Vcb->SwapVpb );
808 
809  }
810 
811  //
812  // Free the VPB, if we need to.
813  //
814 
815  if (FlagOn( Vcb->VcbState, VCB_STATE_FLAG_VPB_MUST_BE_FREED )) {
816 
817  //
818  // We swapped the VPB, so we need to free the main one.
819  //
820 
821  ExFreePool( Vcb->Vpb );
822  }
823 
824  if (Vcb->VolumeGuidPath.Buffer) {
825  ExFreePool( Vcb->VolumeGuidPath.Buffer );
826  Vcb->VolumeGuidPath.Buffer = NULL;
827  }
828 
829  //
830  // Remove this record from the global list of all Vcb records.
831  // Note that the global lock must already be held when calling
832  // this function.
833  //
834 
835  RemoveEntryList( &(Vcb->VcbLinks) );
836 
837  //
838  // Make sure the direct access open count is zero, and the open file count
839  // is also zero.
840  //
841 
842  if ((Vcb->DirectAccessOpenCount != 0) || (Vcb->OpenFileCount != 0)) {
843 
844 #ifdef _MSC_VER
845 #pragma prefast( suppress:28159, "things are seriously wrong if we get here" )
846 #endif
847  FatBugCheck( 0, 0, 0 );
848  }
849 
850  //
851  // Remove the EaFcb and dereference the Fcb for the Ea file if it
852  // exists.
853  //
854 
855  if (Vcb->EaFcb != NULL) {
856 
857  Vcb->EaFcb->OpenCount = 0;
858  FatDeleteFcb( IrpContext, &Vcb->EaFcb );
859  }
860 
861  //
862  // Remove the Root Dcb
863  //
864 
865  if (Vcb->RootDcb != NULL) {
866 
867  //
868  // Rundown stale child Fcbs that may be hanging around. Yes, this
869  // can happen. No, the create path isn't perfectly defensive about
870  // tearing down branches built up on creates that don't wind up
871  // succeeding. Normal system operation usually winds up having
872  // cleaned them out through re-visiting, but ...
873  //
874  // Just pick off Fcbs from the bottom of the tree until we run out.
875  // Then we delete the root Dcb.
876  //
877 
878  while( (Fcb = FatGetNextFcbBottomUp( IrpContext, NULL, Vcb->RootDcb )) != Vcb->RootDcb ) {
879 
880  FatDeleteFcb( IrpContext, &Fcb );
881  }
882 
883  FatDeleteFcb( IrpContext, &Vcb->RootDcb );
884  }
885 
886  //
887  // Uninitialize the notify sychronization object.
888  //
889 
890  FsRtlNotifyUninitializeSync( &Vcb->NotifySync );
891 
892  //
893  // Uninitialize the resource variable for the Vcb
894  //
895 
896  FatDeleteResource( &Vcb->Resource );
897  FatDeleteResource( &Vcb->ChangeBitMapResource );
898 
899  //
900  // If allocation support has been setup, free it.
901  //
902 
903  if (Vcb->FreeClusterBitMap.Buffer != NULL) {
904 
905  FatTearDownAllocationSupport( IrpContext, Vcb );
906  }
907 
908  //
909  // UnInitialize the Mcb structure that kept track of dirty fat sectors.
910  //
911 
912  FsRtlUninitializeLargeMcb( &Vcb->DirtyFatMcb );
913 
914  //
915  // Uninitialize the Mcb structure that kept track of bad sectors.
916  //
917 
918  FsRtlUninitializeLargeMcb( &Vcb->BadBlockMcb );
919 
920  //
921  // Free the pool for the stached copy of the boot sector
922  //
923 
924  if ( Vcb->First0x24BytesOfBootSector ) {
925 
926  ExFreePool( Vcb->First0x24BytesOfBootSector );
927  Vcb->First0x24BytesOfBootSector = NULL;
928  }
929 
930  //
931  // Cancel the CleanVolume Timer and Dpc
932  //
933 
934  (VOID)KeCancelTimer( &Vcb->CleanVolumeTimer );
935 
936  (VOID)KeRemoveQueueDpc( &Vcb->CleanVolumeDpc );
937 
938  //
939  // Free the performance counters memory
940  //
941 
942  ExFreePool( Vcb->Statistics );
943 
944  //
945  // Clean out the tunneling cache
946  //
947 
948  FsRtlDeleteTunnelCache(&Vcb->Tunnel);
949 
950  //
951  // Dereference the target device object.
952  //
953 
954  ObDereferenceObject( Vcb->TargetDeviceObject );
955 
956  //
957  // We better have used all the close contexts we allocated. There could be
958  // one remaining if we're doing teardown due to a final close coming in on
959  // a directory file stream object. It will be freed on the way back up.
960  //
961 
962  NT_ASSERT( Vcb->CloseContextCount <= 1);
963 
964  //
965  // And zero out the Vcb, this will help ensure that any stale data is
966  // wiped clean
967  //
968 
969  RtlZeroMemory( Vcb, sizeof(VCB) );
970 
971  //
972  // return and tell the caller
973  //
974 
975  DebugTrace(-1, Dbg, "FatDeleteVcb -> VOID\n", 0);
976 
977  return;
978 }
PFCB FatGetNextFcbBottomUp(IN PIRP_CONTEXT IrpContext, IN PFCB Fcb OPTIONAL, IN PFCB TerminationFcb)
Definition: strucsup.c:2513
#define Dbg
Definition: strucsup.c:29
Definition: cdstruc.h:902
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
BOOLEAN NTAPI KeRemoveQueueDpc(IN PKDPC Dpc)
Definition: dpc.c:877
Definition: cdstruc.h:498
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define FatBugCheck(A, B, C)
Definition: nodetype.h:104
smooth NULL
Definition: ftsmooth.c:416
VOID FatTearDownAllocationSupport(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
Definition: allocsup.c:547
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define Vcb
Definition: cdprocs.h:1415
VOID FatDeleteFcb(IN PIRP_CONTEXT IrpContext, IN PFCB *FcbPtr)
Definition: strucsup.c:1940
#define VOID
Definition: acefi.h:82
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define VCB_STATE_FLAG_VPB_MUST_BE_FREED
Definition: fatstruc.h:573
VOID NTAPI FsRtlUninitializeLargeMcb(IN PLARGE_MCB Mcb)
Definition: largemcb.c:1053
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VOID NTAPI FsRtlNotifyUninitializeSync(IN PNOTIFY_SYNC *NotifySync)
Definition: notify.c:1639
_In_ PFCB Fcb
Definition: cdprocs.h:159
VOID NTAPI FsRtlDeleteTunnelCache(IN PTUNNEL Cache)
Definition: tunnel.c:690
#define FatDeleteResource(RESRC)
Definition: fatprocs.h:1632
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ FatEnsureStringBufferEnough()

VOID FatEnsureStringBufferEnough ( _Inout_ PVOID  String,
_In_ USHORT  DesiredBufferSize 
)

Definition at line 3727 of file strucsup.c.

3752 {
3753  PSTRING LocalString = String;
3754 
3755  PAGED_CODE();
3756 
3757  if (LocalString->MaximumLength < DesiredBufferSize) {
3758 
3759  FatFreeStringBuffer( LocalString);
3760 
3761  LocalString->Buffer = FsRtlAllocatePoolWithTag( PagedPool,
3762  DesiredBufferSize,
3764  NT_ASSERT( LocalString->Buffer);
3765 
3766  LocalString->MaximumLength = DesiredBufferSize;
3767  }
3768 }
#define TAG_DYNAMIC_NAME_BUFFER
Definition: nodetype.h:186
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
static WCHAR String[]
Definition: stringtable.c:55
VOID FatFreeStringBuffer(_Inout_ PVOID String)
Definition: strucsup.c:3772
void * Buffer
Definition: sprintf.c:453
unsigned short MaximumLength
Definition: sprintf.c:452
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ FatFreeCcb()

INLINE VOID FatFreeCcb ( IN PCCB  Ccb)

Definition at line 64 of file strucsup.c.

67 {
68 #if FAT_FILL_FREE
70 #endif
71 
72  ExFreePool( Ccb );
73 }
Definition: cdstruc.h:1067
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
#define FAT_FILL_FREE
Definition: strucsup.c:52
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FatDeleteCcb().

◆ FatFreeFcb()

INLINE VOID FatFreeFcb ( IN PFCB  Fcb)

Definition at line 85 of file strucsup.c.

88 {
89 #if FAT_FILL_FREE
91 #endif
92 
93  ExFreePool( Fcb );
94 }
Definition: cdstruc.h:902
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
#define FAT_FILL_FREE
Definition: strucsup.c:52
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by FatDeleteFcb().

◆ FatFreeIrpContext()

INLINE VOID FatFreeIrpContext ( IN PIRP_CONTEXT  IrpContext)

Definition at line 174 of file strucsup.c.

177 {
178 #if FAT_FILL_FREE
179  RtlFillMemoryUlong(IrpContext, sizeof(IRP_CONTEXT), FAT_FILL_FREE);
180 #endif
181 
182  ExFreeToNPagedLookasideList( &FatIrpContextLookasideList, (PVOID) IrpContext );
183 }
NPAGED_LOOKASIDE_LIST FatIrpContextLookasideList
Definition: fatdata.c:102
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
#define FAT_FILL_FREE
Definition: strucsup.c:52

Referenced by FatDeleteIrpContext_Real().

◆ FatFreeNonPagedFcb()

INLINE VOID FatFreeNonPagedFcb ( PNON_PAGED_FCB  NonPagedFcb)

Definition at line 112 of file strucsup.c.

115 {
116 #if FAT_FILL_FREE
117  RtlFillMemoryUlong(NonPagedFcb, sizeof(NON_PAGED_FCB), FAT_FILL_FREE);
118 #endif
119 
120  ExFreeToNPagedLookasideList( &FatNonPagedFcbLookasideList, (PVOID) NonPagedFcb );
121 }
NPAGED_LOOKASIDE_LIST FatNonPagedFcbLookasideList
Definition: fatdata.c:103
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
#define FAT_FILL_FREE
Definition: strucsup.c:52

Referenced by FatDeleteFcb().

◆ FatFreeResource()

INLINE VOID FatFreeResource ( IN PERESOURCE  Resource)

Definition at line 145 of file strucsup.c.

148 {
150 
151 #if FAT_FILL_FREE
153 #endif
154 
155  ExFreeToNPagedLookasideList( &FatEResourceLookasideList, (PVOID) Resource );
156 }
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
NPAGED_LOOKASIDE_LIST FatEResourceLookasideList
Definition: fatdata.c:104
#define FAT_FILL_FREE
Definition: strucsup.c:52
ULONG ERESOURCE
Definition: env_spec_w32.h:594

Referenced by FatCreateDcb(), FatCreateFcb(), and FatDeleteFcb().

◆ FatFreeStringBuffer()

VOID FatFreeStringBuffer ( _Inout_ PVOID  String)

Definition at line 3772 of file strucsup.c.

3792 {
3793  ULONG_PTR High, Low;
3794  PSTRING LocalString = String;
3795 
3796  PAGED_CODE();
3797 
3798  if (NULL != LocalString->Buffer) {
3799 
3800  IoGetStackLimits( &Low, &High );
3801 
3802  if (((ULONG_PTR)(LocalString->Buffer) < Low) ||
3803  ((ULONG_PTR)(LocalString->Buffer) > High)) {
3804 
3805  ExFreePool( LocalString->Buffer);
3806  }
3807 
3808  LocalString->Buffer = NULL;
3809  }
3810 
3811  LocalString->MaximumLength = LocalString->Length = 0;
3812 }
unsigned short Length
Definition: sprintf.c:451
Definition: strmini.h:380
static WCHAR String[]
Definition: stringtable.c:55
uint32_t ULONG_PTR
Definition: typedefs.h:65
void * Buffer
Definition: sprintf.c:453
smooth NULL
Definition: ftsmooth.c:416
Definition: strmini.h:378
VOID NTAPI IoGetStackLimits(OUT PULONG_PTR LowLimit, OUT PULONG_PTR HighLimit)
Definition: util.c:78
unsigned short MaximumLength
Definition: sprintf.c:452
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

Referenced by FatEnsureStringBufferEnough().

◆ FatGetNextFcbBottomUp()

PFCB FatGetNextFcbBottomUp ( IN PIRP_CONTEXT  IrpContext,
IN PFCB Fcb  OPTIONAL,
IN PFCB  TerminationFcb 
)

Definition at line 2513 of file strucsup.c.

2558 {
2559  PFCB NextFcb;
2560 
2561  PAGED_CODE();
2562  UNREFERENCED_PARAMETER( IrpContext );
2563 
2564  NT_ASSERT( FatVcbAcquiredExclusive( IrpContext, TerminationFcb->Vcb ) ||
2565  FlagOn( TerminationFcb->Vcb->VcbState, VCB_STATE_FLAG_LOCKED ) );
2566 
2567  //
2568  // Do we need to begin the enumeration?
2569  //
2570 
2571  if (Fcb != NULL) {
2572 
2573  //
2574  // Did we complete?
2575  //
2576 
2577  if (Fcb == TerminationFcb) {
2578 
2579  return NULL;
2580  }
2581 
2582  //
2583  // Do we have a sibling to return?
2584  //
2585 
2586  NextFcb = FatGetNextSibling( Fcb );
2587 
2588  //
2589  // If not, return our parent. We are done with this branch.
2590  //
2591 
2592  if (NextFcb == NULL) {
2593 
2594  return Fcb->ParentDcb;
2595  }
2596 
2597  } else {
2598 
2599  NextFcb = TerminationFcb;
2600  }
2601 
2602  //
2603  // Decend to its furthest child (if it exists) and return it.
2604  //
2605 
2606  for (;
2607  NodeType( NextFcb ) != FAT_NTC_FCB && FatGetFirstChild( NextFcb ) != NULL;
2608  NextFcb = FatGetFirstChild( NextFcb )) {
2609  }
2610 
2611  return NextFcb;
2612 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
Definition: cdstruc.h:902
struct _FCB * ParentDcb
Definition: fatstruc.h:835
#define FatGetFirstChild(DIR)
Definition: fatprocs.h:1785
smooth NULL
Definition: ftsmooth.c:416
NodeType
Definition: Node.h:5
#define VCB_STATE_FLAG_LOCKED
Definition: fatstruc.h:558
#define FatGetNextSibling(FILE)
Definition: fatprocs.h:1791
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatVcbAcquiredExclusive(IRPCONTEXT, VCB)
Definition: fatprocs.h:1495
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define FAT_NTC_FCB
Definition: nodetype.h:29
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by FatDeleteVcb(), and FatSetRenameInfo().

◆ FatGetNextFcbTopDown()

PFCB FatGetNextFcbTopDown ( IN PIRP_CONTEXT  IrpContext,
IN PFCB  Fcb,
IN PFCB  TerminationFcb 
)

Definition at line 2615 of file strucsup.c.

2655 {
2656  PFCB Sibling;
2657 
2658  PAGED_CODE();
2659  UNREFERENCED_PARAMETER( IrpContext );
2660 
2661  NT_ASSERT( FatVcbAcquiredExclusive( IrpContext, Fcb->Vcb ) ||
2663 
2664  //
2665  // If this was a directory (ie. not a file), get the child. If
2666  // there aren't any children and this is our termination Fcb,
2667  // return NULL.
2668  //
2669 
2670  if ( ((NodeType(Fcb) == FAT_NTC_DCB) ||
2671  (NodeType(Fcb) == FAT_NTC_ROOT_DCB)) &&
2672  !IsListEmpty(&Fcb->Specific.Dcb.ParentDcbQueue) ) {
2673 
2674  return FatGetFirstChild( Fcb );
2675  }
2676 
2677  //
2678  // Were we only meant to do one iteration?
2679  //
2680 
2681  if ( Fcb == TerminationFcb ) {
2682 
2683  return NULL;
2684  }
2685 
2686  Sibling = FatGetNextSibling(Fcb);
2687 
2688  while (TRUE) {
2689 
2690  //
2691  // Do we still have an "older" sibling in this directory who is
2692  // not the termination Fcb?
2693  //
2694 
2695  if ( Sibling != NULL ) {
2696 
2697  return (Sibling != TerminationFcb) ? Sibling : NULL;
2698  }
2699 
2700  //
2701  // OK, let's move on to out parent and see if he is the termination
2702  // node or has any older siblings.
2703  //
2704 
2705  if ( Fcb->ParentDcb == TerminationFcb ) {
2706 
2707  return NULL;
2708  }
2709 
2710  Fcb = Fcb->ParentDcb;
2711 
2712  Sibling = FatGetNextSibling(Fcb);
2713  }
2714 }
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
Definition: cdstruc.h:902
struct _FCB::@712::@714 Dcb
ULONG VcbState
Definition: cdstruc.h:540
struct _FCB * ParentDcb
Definition: fatstruc.h:835
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define FatGetFirstChild(DIR)
Definition: fatprocs.h:1785
smooth NULL
Definition: ftsmooth.c:416
NodeType
Definition: Node.h:5
#define VCB_STATE_FLAG_LOCKED
Definition: fatstruc.h:558
#define FatGetNextSibling(FILE)
Definition: fatprocs.h:1791
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FAT_NTC_ROOT_DCB
Definition: nodetype.h:31
#define FAT_NTC_DCB
Definition: nodetype.h:30
#define FatVcbAcquiredExclusive(IRPCONTEXT, VCB)
Definition: fatprocs.h:1495
PVCB Vcb
Definition: cdstruc.h:933
_In_ PFCB Fcb
Definition: cdprocs.h:159
union _FCB::@712 Specific
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by _Requires_lock_held_(), and FatIsHandleCountZero().

◆ FatIsHandleCountZero()

BOOLEAN FatIsHandleCountZero ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb 
)

Definition at line 3602 of file strucsup.c.

3624 {
3625  PFCB Fcb;
3626 
3627  PAGED_CODE();
3628 
3629  Fcb = Vcb->RootDcb;
3630 
3631  while (Fcb != NULL) {
3632 
3633  if (Fcb->UncleanCount != 0) {
3634 
3635  return FALSE;
3636  }
3637 
3638  Fcb = FatGetNextFcbTopDown(IrpContext, Fcb, Vcb->RootDcb);
3639  }
3640 
3641  return TRUE;
3642 }
#define TRUE
Definition: types.h:120
Definition: cdstruc.h:902
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
PFCB FatGetNextFcbTopDown(IN PIRP_CONTEXT IrpContext, IN PFCB Fcb, IN PFCB TerminationFcb)
Definition: strucsup.c:2615
#define Vcb
Definition: cdprocs.h:1415
CLONG UncleanCount
Definition: fatstruc.h:872
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define PAGED_CODE()

◆ FatPreallocateCloseContext()

VOID FatPreallocateCloseContext ( PVCB  Vcb)

Definition at line 3684 of file strucsup.c.

3706 {
3707  PCLOSE_CONTEXT CloseContext;
3708 
3709  PAGED_CODE();
3710 
3712 
3713  CloseContext = FsRtlAllocatePoolWithTag( PagedPool,
3714  sizeof(CLOSE_CONTEXT),
3716 
3718  (PSLIST_ENTRY) CloseContext,
3720 
3721  DbgDoit( InterlockedIncrement( (LONG*)&Vcb->CloseContextCount));
3722 }
#define DbgDoit(X)
Definition: fatdata.h:336
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
struct _SINGLE_LIST_ENTRY *__fastcall ExInterlockedPushEntrySList(union _SLIST_HEADER *, struct _SINGLE_LIST_ENTRY *, unsigned long *)
KSPIN_LOCK GeneralSpinLock
Definition: fatstruc.h:151
SLIST_HEADER FatCloseContextSList
Definition: fatdata.c:106
long LONG
Definition: pedump.c:60
FAT_DATA FatData
Definition: fatdata.c:56
#define Vcb
Definition: cdprocs.h:1415
#define PSLIST_ENTRY
Definition: rtltypes.h:134
#define InterlockedIncrement
Definition: armddk.h:53
#define TAG_FAT_CLOSE_CONTEXT
Definition: nodetype.h:164
#define PAGED_CODE()

Referenced by _Requires_lock_held_().

◆ FatScanForDataTrack()

BOOLEAN FatScanForDataTrack ( IN PIRP_CONTEXT  IrpContext,
IN PDEVICE_OBJECT  TargetDeviceObject 
)

Definition at line 3816 of file strucsup.c.

3845 {
3846  NTSTATUS Status;
3848 
3849  ULONG LocalTrackCount;
3850  ULONG LocalTocLength;
3851 
3852  PCDROM_TOC CdromToc;
3853  BOOLEAN Result = FALSE;
3854 
3855  PAGED_CODE();
3856 
3857  CdromToc = FsRtlAllocatePoolWithTag( PagedPool,
3858  sizeof( CDROM_TOC ),
3859  TAG_IO_BUFFER );
3860 
3861  RtlZeroMemory( CdromToc, sizeof( CDROM_TOC ));
3862 
3863  _SEH2_TRY {
3864 
3865  //
3866  // Go ahead and read the table of contents
3867  //
3868 
3869  Status = FatPerformDevIoCtrl( IrpContext,
3872  NULL,
3873  0,
3874  CdromToc,
3875  sizeof( CDROM_TOC ),
3876  FALSE,
3877  TRUE,
3878  &Iosb );
3879 
3880  //
3881  // Nothing to process if this request fails.
3882  //
3883 
3884  if (Status != STATUS_SUCCESS) {
3885 
3886  //
3887  // If we get the special error indicating a failed TOC read on PD media just
3888  // plow ahead with the mount (see comments above).
3889  //
3890 
3892 
3893  Result = TRUE;
3894 
3895  }
3896 
3897  try_leave( NOTHING );
3898  }
3899 
3900  //
3901  // Get the number of tracks and stated size of this structure.
3902  //
3903 
3904  LocalTrackCount = CdromToc->LastTrack - CdromToc->FirstTrack + 1;
3905  LocalTocLength = PtrOffset( CdromToc, &CdromToc->TrackData[LocalTrackCount + 1] );
3906 
3907  //
3908  // Get out if there is an immediate problem with the TOC, or more than
3909  // one track.
3910  //
3911 
3912  if ((LocalTocLength > Iosb.Information) ||
3913  (CdromToc->FirstTrack > CdromToc->LastTrack) ||
3914  (LocalTrackCount != 1)) {
3915 
3916  try_leave( NOTHING);
3917  }
3918 
3919  //
3920  // Is it a data track? DVD-RAM reports single, data, track.
3921  //
3922 
3923  Result = BooleanFlagOn( CdromToc->TrackData[ 0].Control, 0x04 );
3924  }
3925  _SEH2_FINALLY {
3926 
3927  ExFreePool( CdromToc);
3928  } _SEH2_END;
3929 
3930  return Result;
3931 }
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
UCHAR FirstTrack
Definition: ntddcdrm.h:197
#define PtrOffset(BASE, OFFSET)
Definition: cdprocs.h:1547
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_SEH2_TRY
Definition: create.c:4226
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
NTSTATUS FatPerformDevIoCtrl(IN PIRP_CONTEXT IrpContext, IN ULONG IoControlCode, IN PDEVICE_OBJECT Device, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN BOOLEAN OverrideVerify, OUT PIO_STATUS_BLOCK Iosb OPTIONAL)
Definition: deviosup.c:3621
#define try_leave(S)
Definition: cdprocs.h:2180
return Iosb
Definition: create.c:4402
UCHAR LastTrack
Definition: ntddcdrm.h:198
Status
Definition: gdiplustypes.h:24
UCHAR Control
Definition: ntddcdrm.h:137
#define NOTHING
Definition: env_spec_w32.h:461
_SEH2_END
Definition: create.c:4400
_SEH2_FINALLY
Definition: create.c:4371
#define TAG_IO_BUFFER
Definition: cdprocs.h:95
TRACK_DATA TrackData[MAXIMUM_NUMBER_TRACKS]
Definition: ntddcdrm.h:199
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IOCTL_CDROM_READ_TOC
Definition: ntddcdrm.h:34
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1673
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

◆ FatSwapVpb()

BOOLEAN FatSwapVpb ( IN PIRP_CONTEXT  IrpContext,
PVCB  Vcb 
)

Definition at line 2718 of file strucsup.c.

2745 {
2746  BOOLEAN Result = FALSE;
2747  PVPB OldVpb;
2749 
2750 
2751  //
2752  // Make sure we have not already swapped it.
2753  //
2754 
2755  OldVpb = Vcb->Vpb;
2756 
2757 #ifdef _MSC_VER
2758 #pragma prefast( push )
2759 #pragma prefast( disable: 28175, "touching Vpb is ok for a filesystem" )
2760 #endif
2761 
2762  if (!FlagOn( Vcb->VcbState, VCB_STATE_FLAG_VPB_MUST_BE_FREED ) && OldVpb->RealDevice->Vpb == OldVpb) {
2763 
2764  //
2765  // If not the final reference and we are forcing the disconnect,
2766  // then swap out the Vpb. We must preserve the REMOVE_PENDING flag
2767  // so that the device is not remounted in the middle of a PnP remove
2768  // operation.
2769  //
2770 
2771  NT_ASSERT( Vcb->SwapVpb != NULL );
2772 
2773  Vcb->SwapVpb->Type = IO_TYPE_VPB;
2774  Vcb->SwapVpb->Size = sizeof( VPB );
2775  Vcb->SwapVpb->RealDevice = OldVpb->RealDevice;
2776 
2777  Vcb->SwapVpb->RealDevice->Vpb = Vcb->SwapVpb;
2778 
2779  Vcb->SwapVpb->Flags = FlagOn( OldVpb->Flags, VPB_REMOVE_PENDING );
2780 
2781  //
2782  // If we are working on a mount request, we need to make sure we update
2783  // the VPB in the IRP, since the one it points to may no longer be valid.
2784  //
2785 
2786  if (IrpContext->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL && IrpContext->MinorFunction == IRP_MN_MOUNT_VOLUME) {
2787 
2788  //
2789  // Get the IRP stack.
2790  //
2791 
2792  IrpSp = IoGetCurrentIrpStackLocation( IrpContext->OriginatingIrp );
2793 
2794  NT_ASSERT( IrpSp->FileObject == NULL );
2795 
2796  //
2797  // Check the VPB in the IRP to see if it is the one we are swapping.
2798  //
2799 
2800  if (IrpSp->Parameters.MountVolume.Vpb == OldVpb) {
2801 
2802  //
2803  // Change the IRP to point to the swap VPB.
2804  //
2805 
2806  IrpSp->Parameters.MountVolume.Vpb = Vcb->SwapVpb;
2807  }
2808  }
2809 
2810 #ifdef _MSC_VER
2811 #pragma prefast( pop )
2812 #endif
2813 
2814  //
2815  // We place the volume in the Bad state (as opposed to NotMounted) so
2816  // that it is not eligible for a remount. Also indicate we used up
2817  // the swap.
2818  //
2819 
2820  Vcb->SwapVpb = NULL;
2823 
2824  Result = TRUE;
2825  }
2826 
2827  return Result;
2828 }
USHORT Flags
Definition: iotypes.h:171
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4383
#define IRP_MJ_FILE_SYSTEM_CONTROL
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:174
#define Vcb
Definition: cdprocs.h:1415
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FatSetVcbCondition(V, X)
Definition: fatprocs.h:1438
#define IO_TYPE_VPB
struct _VPB VPB
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
#define VCB_STATE_FLAG_VPB_MUST_BE_FREED
Definition: fatstruc.h:573
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
Definition: iotypes.h:168
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ FatTearDownVcb()

VOID FatTearDownVcb ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb 
)

Definition at line 672 of file strucsup.c.

695 {
696  PFILE_OBJECT DirectoryFileObject;
697 
698 
699  PAGED_CODE();
700 
701  //
702  // Get rid of the virtual volume file, if we need to.
703  //
704 
705  if (Vcb->VirtualVolumeFile != NULL) {
706 
707  //
708  // Uninitialize the cache
709  //
710 
711  CcUninitializeCacheMap( Vcb->VirtualVolumeFile,
712  &FatLargeZero,
713  NULL );
714 
715  FsRtlTeardownPerStreamContexts( &Vcb->VolumeFileHeader );
716 
717  ObDereferenceObject( Vcb->VirtualVolumeFile );
718 
719  Vcb->VirtualVolumeFile = NULL;
720  }
721 
722  //
723  // Close down the EA file.
724  //
725 
726  FatCloseEaFile( IrpContext, Vcb, FALSE );
727 
728  //
729  // Close down the root directory stream..
730  //
731 
732  if (Vcb->RootDcb != NULL) {
733 
734  DirectoryFileObject = Vcb->RootDcb->Specific.Dcb.DirectoryFile;
735 
736  if (DirectoryFileObject != NULL) {
737 
738  //
739  // Tear down this directory file.
740  //
741 
742  CcUninitializeCacheMap( DirectoryFileObject,
743  &FatLargeZero,
744  NULL );
745 
746  Vcb->RootDcb->Specific.Dcb.DirectoryFile = NULL;
747  ObDereferenceObject( DirectoryFileObject );
748  }
749  }
750 
751  //
752  // The VCB can no longer be used.
753  //
754 
756 }
LARGE_INTEGER FatLargeZero
Definition: fatdata.c:62
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI FsRtlTeardownPerStreamContexts(IN PFSRTL_ADVANCED_FCB_HEADER AdvFcbHeader)
Definition: filtrctx.c:368
#define Vcb
Definition: cdprocs.h:1415
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FatSetVcbCondition(V, X)
Definition: fatprocs.h:1438
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
VOID FatCloseEaFile(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN BOOLEAN FlushFirst)
Definition: cachesup.c:1079
#define PAGED_CODE()