ReactOS  0.4.15-dev-318-g99b52df
fsctrl.c File Reference
#include "fatprocs.h"
Include dependency graph for fsctrl.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (FAT_BUG_CHECK_FSCTRL)
 
#define Dbg   (DEBUG_TRACE_FSCTRL)
 
#define MCB_SCALE_LOG2   (Vcb->AllocationSupport.LogOfBytesPerSector)
 
#define MCB_SCALE   (1 << MCB_SCALE_LOG2)
 
#define MCB_SCALE_MODULO   (MCB_SCALE - 1)
 

Functions

 _Requires_lock_held_ (_Requires_lock_held_() NTSTATUSFatInvalidateVolumes(IN PIRP Irp) _Global_critical_region_)
 
BOOLEAN FatAddMcbEntry (IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, IN LBO Lbo, IN ULONG SectorCount)
 
BOOLEAN FatLookupMcbEntry (IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, OUT PLBO Lbo, OUT PULONG ByteCount OPTIONAL, OUT PULONG Index OPTIONAL)
 
BOOLEAN FatLookupLastMcbEntry (IN PVCB Vcb, IN PLARGE_MCB Mcb, OUT PVBO Vbo, OUT PLBO Lbo, OUT PULONG Index)
 
BOOLEAN FatGetNextMcbEntry (IN PVCB Vcb, IN PLARGE_MCB Mcb, IN ULONG RunIndex, OUT PVBO Vbo, OUT PLBO Lbo, OUT PULONG ByteCount)
 
VOID FatRemoveMcbEntry (IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, IN ULONG SectorCount)
 
 _Function_class_ (IRP_MJ_FILE_SYSTEM_CONTROL)
 
 _Requires_lock_held_ (_Global_critical_region_)
 
BOOLEAN FatIsBootSectorFat (IN PPACKED_BOOT_SECTOR BootSector)
 
BOOLEAN FatIsMediaWriteProtected (IN PIRP_CONTEXT IrpContext, IN PDEVICE_OBJECT TargetDeviceObject)
 
NTSTATUS FatUnlockVolume (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
NTSTATUS FatUnlockVolumeInternal (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PFILE_OBJECT FileObject OPTIONAL)
 
NTSTATUS FatIsVolumeDirty (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
NTSTATUS FatIsVolumeMounted (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
NTSTATUS FatIsPathnameValid (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
NTSTATUS FatQueryBpb (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
BOOLEAN FatPerformVerifyDiskRead (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PVOID Buffer, IN LBO Lbo, IN ULONG NumberOfBytesToRead, IN BOOLEAN ReturnOnError)
 
NTSTATUS FatGetStatistics (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
VOID FatComputeMoveFileSplicePoints (IN PIRP_CONTEXT IrpContext, IN PFCB FcbOrDcb, IN ULONG FileOffset, IN ULONG TargetCluster, IN ULONG BytesToReallocate, OUT PULONG FirstSpliceSourceCluster, OUT PULONG FirstSpliceTargetCluster, OUT PULONG SecondSpliceSourceCluster, OUT PULONG SecondSpliceTargetCluster, IN OUT PLARGE_MCB SourceMcb)
 
NTSTATUS FatAllowExtendedDasdIo (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
 
NTSTATUS FatSearchBufferForLabel (IN PIRP_CONTEXT IrpContext, IN PVPB Vpb, IN PVOID Buffer, IN ULONG Size, OUT PBOOLEAN LabelFound)
 
VOID FatVerifyLookupFatEntry (IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN ULONG FatIndex, IN OUT PULONG FatEntry)
 
NTSTATUS FatSetZeroOnDeallocate (__in PIRP_CONTEXT IrpContext, __in PIRP Irp)
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (FAT_BUG_CHECK_FSCTRL)

Definition at line 24 of file fsctrl.c.

◆ Dbg

#define Dbg   (DEBUG_TRACE_FSCTRL)

Definition at line 30 of file fsctrl.c.

◆ MCB_SCALE

#define MCB_SCALE   (1 << MCB_SCALE_LOG2)

◆ MCB_SCALE_LOG2

#define MCB_SCALE_LOG2   (Vcb->AllocationSupport.LogOfBytesPerSector)

◆ MCB_SCALE_MODULO

#define MCB_SCALE_MODULO   (MCB_SCALE - 1)

Function Documentation

◆ _Function_class_()

_Function_class_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 635 of file fsctrl.c.

663 {
664  BOOLEAN Wait;
666  PIRP_CONTEXT IrpContext = NULL;
667 
669 
670  PAGED_CODE();
671  UNREFERENCED_PARAMETER( VolumeDeviceObject );
672 
673  DebugTrace(+1, Dbg,"FatFsdFileSystemControl\n", 0);
674 
675  //
676  // Call the common FileSystem Control routine, with blocking allowed if
677  // synchronous. This opeation needs to special case the mount
678  // and verify suboperations because we know they are allowed to block.
679  // We identify these suboperations by looking at the file object field
680  // and seeing if its null.
681  //
682 
684 
685  Wait = TRUE;
686 
687  } else {
688 
689  Wait = CanFsdWait( Irp );
690  }
691 
693 
695 
696  _SEH2_TRY {
697 
699 
701 
702  //
703  // We need to made a special check here for the InvalidateVolumes
704  // FSCTL as that comes in with a FileSystem device object instead
705  // of a volume device object.
706  //
707 
711  (IrpSp->Parameters.FileSystemControl.FsControlCode ==
713 
714  Status = FatInvalidateVolumes( Irp );
715 
716  } else {
717 
718  IrpContext = FatCreateIrpContext( Irp, Wait );
719 
720  Status = FatCommonFileSystemControl( IrpContext, Irp );
721  }
722 
724 
725  //
726  // We had some trouble trying to perform the requested
727  // operation, so we'll abort the I/O request with
728  // the error status that we get back from the
729  // execption code
730  //
731 
732  Status = FatProcessException( IrpContext, Irp, _SEH2_GetExceptionCode() );
733  } _SEH2_END;
734 
735  if (TopLevel) { IoSetTopLevelIrp( NULL ); }
736 
738 
739  //
740  // And return to our caller
741  //
742 
743  DebugTrace(-1, Dbg, "FatFsdFileSystemControl -> %08lx\n", Status);
744 
745  return Status;
746 }
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define FatDeviceIsFatFsdo(D)
Definition: fatprocs.h:3083
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
_SEH2_TRY
Definition: create.c:4250
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2401
#define FSCTL_INVALIDATE_VOLUMES
Definition: nt_native.h:847
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PIRP_CONTEXT FatCreateIrpContext(IN PIRP Irp, IN BOOLEAN Wait)
Definition: strucsup.c:2300
#define Dbg
Definition: fsctrl.c:30
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4047
#define IRP_MJ_FILE_SYSTEM_CONTROL
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
#define CanFsdWait(I)
Definition: cdprocs.h:2011
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_SEH2_END
Definition: create.c:4424
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define PAGED_CODE()
IN BOOLEAN Wait
Definition: fatprocs.h:1529

◆ _Requires_lock_held_() [1/2]

_Requires_lock_held_ ( _Requires_lock_held_()NTSTATUSFatInvalidateVolumes ( IN PIRP Irp _Global_critical_region_)

Definition at line 36 of file fsctrl.c.

341 {
342  LBO Lbo;
343  ULONG Index = 0;
344  LONGLONG llVbo = 0;
345 
347 
348  while (FsRtlGetNextLargeMcbEntry(Mcb, Index, &llVbo, &Lbo, ByteCount)) {
349  *Vbo = (VBO)llVbo;
350  if (((ULONG)Lbo) == -1) {
351  return FALSE;
352  }
353 
354  Index++;
355  }
356 
357  *Vbo = (VBO)llVbo;
358 
359  return TRUE;
360 }
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
ULONG32 VBO
Definition: fat.h:38
IN PFCB IN VBO OUT PLBO Lbo
Definition: fatprocs.h:297
BOOLEAN NTAPI FsRtlGetNextLargeMcbEntry(IN PLARGE_MCB Mcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
Definition: largemcb.c:391
LONGLONG LBO
Definition: fat.h:34
int64_t LONGLONG
Definition: typedefs.h:67
#define Vcb
Definition: cdprocs.h:1425
static const UCHAR Index[8]
Definition: usbohci.c:18
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1061
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
unsigned int ULONG
Definition: retypes.h:1
IN PFCB IN VBO Vbo
Definition: fatprocs.h:297

◆ _Requires_lock_held_() [2/2]

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 749 of file fsctrl.c.

773 {
776 
777  PAGED_CODE();
778 
779  //
780  // Get a pointer to the current Irp stack location
781  //
782 
784 
785  DebugTrace(+1, Dbg,"FatCommonFileSystemControl\n", 0);
786  DebugTrace( 0, Dbg,"Irp = %p\n", Irp);
787  DebugTrace( 0, Dbg,"MinorFunction = %08lx\n", IrpSp->MinorFunction);
788 
789  //
790  // We know this is a file system control so we'll case on the
791  // minor function, and call a internal worker routine to complete
792  // the irp.
793  //
794 
795  switch (IrpSp->MinorFunction) {
796 
798 
799  Status = FatUserFsCtrl( IrpContext, Irp );
800  break;
801 
802  case IRP_MN_MOUNT_VOLUME:
803 
804  Status = FatMountVolume( IrpContext,
805  IrpSp->Parameters.MountVolume.DeviceObject,
806  IrpSp->Parameters.MountVolume.Vpb,
807  IrpSp->DeviceObject );
808 
809  //
810  // Complete the request.
811  //
812  // We do this here because FatMountVolume can be called recursively,
813  // but the Irp is only to be completed once.
814  //
815  // NOTE: I don't think this is true anymore (danlo 3/15/1999). Probably
816  // an artifact of the old doublespace attempt.
817  //
818 
819  FatCompleteRequest( IrpContext, Irp, Status );
820  break;
821 
823 
824  Status = FatVerifyVolume( IrpContext, Irp );
825  break;
826 
827  default:
828 
829  DebugTrace( 0, Dbg, "Invalid FS Control Minor Function %08lx\n", IrpSp->MinorFunction);
830 
833  break;
834  }
835 
836  DebugTrace(-1, Dbg, "FatCommonFileSystemControl -> %08lx\n", Status);
837 
838  return Status;
839 }
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4049
#define Dbg
Definition: fsctrl.c:30
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4048
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4047
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define PAGED_CODE()

◆ FatAddMcbEntry()

BOOLEAN FatAddMcbEntry ( IN PVCB  Vcb,
IN PLARGE_MCB  Mcb,
IN VBO  Vbo,
IN LBO  Lbo,
IN ULONG  SectorCount 
)

Definition at line 364 of file fsctrl.c.

372 {
373  BOOLEAN Result;
374 #if DBG
375  VBO SparseVbo;
376  LONGLONG SparseByteCount;
377 #endif
378 
379  PAGED_CODE();
380 
381  if (SectorCount) {
382 
383  //
384  // Round up sectors, but be careful as SectorCount approaches 4Gb.
385  // Note that for x>0, (x+m-1)/m = ((x-1)/m)+(m/m) = ((x-1)/m)+1
386  //
387 
388  SectorCount--;
390  SectorCount++;
391  }
392 
393  Vbo >>= MCB_SCALE_LOG2;
394  Lbo >>= MCB_SCALE_LOG2;
395 
396  NT_ASSERT( SectorCount != 0 );
397 
398  if (Mcb != &Vcb->DirtyFatMcb) {
399  NT_ASSERT( FatNonSparseMcb( Vcb, Mcb, &SparseVbo, &SparseByteCount ) ||
400  ((SparseVbo == Vbo) && (SparseByteCount == SectorCount )) );
401  }
402 
404  ((LONGLONG) Vbo),
405  ((LONGLONG) Lbo),
406  ((LONGLONG) SectorCount) );
407 
408  if (Mcb != &Vcb->DirtyFatMcb) {
409  NT_ASSERT( FatNonSparseMcb( Vcb, Mcb, &SparseVbo, &SparseByteCount ) ||
410  ((SparseVbo == Vbo) && (SparseByteCount == SectorCount )) );
411  }
412 
413  return Result;
414 }
ULONG32 VBO
Definition: fat.h:38
IN PFCB IN VBO OUT PLBO Lbo
Definition: fatprocs.h:297
#define MCB_SCALE_LOG2
unsigned char BOOLEAN
_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
int64_t LONGLONG
Definition: typedefs.h:67
#define Vcb
Definition: cdprocs.h:1425
BOOLEAN NTAPI FsRtlAddLargeMcbEntry(IN PLARGE_MCB Mcb, IN LONGLONG Vbn, IN LONGLONG Lbn, IN LONGLONG SectorCount)
Definition: largemcb.c:282
ULONG SectorCount
Definition: part_xbox.c:31
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
IN PFCB IN VBO Vbo
Definition: fatprocs.h:297
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by _Requires_lock_held_(), FatComputeMoveFileSplicePoints(), FatExamineFatEntries(), and FatSetFatRun().

◆ FatAllowExtendedDasdIo()

NTSTATUS FatAllowExtendedDasdIo ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 7038 of file fsctrl.c.

7059 {
7061  PVCB Vcb;
7062  PFCB Fcb;
7063  PCCB Ccb;
7064 
7065  PAGED_CODE();
7066 
7067  //
7068  // Get the current Irp stack location and save some references.
7069  //
7070 
7072 
7073  //
7074  // Extract and decode the file object and check for type of open.
7075  //
7076 
7078 
7080  return STATUS_INVALID_PARAMETER;
7081  }
7082 
7083  if ((Ccb == NULL) || !FlagOn( Ccb->Flags, CCB_FLAG_MANAGE_VOLUME_ACCESS )) {
7084 
7086 
7087  DebugTrace(-1, Dbg, "FatAllowExtendedDasdIo -> %08lx\n", STATUS_INVALID_PARAMETER);
7088  return STATUS_INVALID_PARAMETER;
7089  }
7090 
7092 
7093  FatCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
7094  return STATUS_SUCCESS;
7095 }
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define CCB_FLAG_ALLOW_EXTENDED_DASD_IO
Definition: cdstruc.h:1114
Definition: cdstruc.h:1073
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
Definition: cdstruc.h:504
#define CCB_FLAG_MANAGE_VOLUME_ACCESS
Definition: fatstruc.h:1337
smooth NULL
Definition: ftsmooth.c:416
#define Dbg
Definition: fsctrl.c:30
#define Vcb
Definition: cdprocs.h:1425
ULONG Flags
Definition: ntfs.h:532
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:3014
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
#define PAGED_CODE()

◆ FatComputeMoveFileSplicePoints()

VOID FatComputeMoveFileSplicePoints ( IN PIRP_CONTEXT  IrpContext,
IN PFCB  FcbOrDcb,
IN ULONG  FileOffset,
IN ULONG  TargetCluster,
IN ULONG  BytesToReallocate,
OUT PULONG  FirstSpliceSourceCluster,
OUT PULONG  FirstSpliceTargetCluster,
OUT PULONG  SecondSpliceSourceCluster,
OUT PULONG  SecondSpliceTargetCluster,
IN OUT PLARGE_MCB  SourceMcb 
)

Definition at line 6838 of file fsctrl.c.

6890 {
6891  VBO SourceVbo;
6892  LBO SourceLbo;
6893  ULONG SourceIndex;
6894  ULONG SourceBytesInRun;
6895  ULONG SourceBytesRemaining;
6896 
6897  ULONG SourceMcbVbo = 0;
6898  ULONG SourceMcbBytesInRun = 0;
6899 
6900  PVCB Vcb;
6901  BOOLEAN Result;
6902 
6903  PAGED_CODE();
6904 
6905  Vcb = FcbOrDcb->Vcb;
6906 
6907  //
6908  // Get information on the final cluster in the previous allocation and
6909  // prepare to enumerate it in the follow loop.
6910  //
6911 
6912  if (FileOffset == 0) {
6913 
6914  SourceIndex = 0;
6915  *FirstSpliceSourceCluster = 0;
6917  0,
6918  &SourceVbo,
6919  &SourceLbo,
6920  &SourceBytesInRun );
6921 
6922  } else {
6923 
6925  FileOffset-1,
6926  &SourceLbo,
6927  &SourceBytesInRun,
6928  &SourceIndex);
6929 
6930  *FirstSpliceSourceCluster = FatGetIndexFromLbo( Vcb, SourceLbo );
6931 
6932  if ((Result) && (SourceBytesInRun == 1)) {
6933 
6934  SourceIndex += 1;
6936  SourceIndex,
6937  &SourceVbo,
6938  &SourceLbo,
6939  &SourceBytesInRun);
6940 
6941  } else {
6942 
6943  SourceVbo = FileOffset;
6944  SourceLbo += 1;
6945  SourceBytesInRun -= 1;
6946  }
6947  }
6948 
6949  //
6950  // Run should always be present, but don't bugcheck in the case where it's not.
6951  //
6952 
6953  if (!Result) {
6954 
6955  NT_ASSERT( FALSE);
6957  }
6958 
6959  //
6960  // At this point the variables:
6961  //
6962  // - SourceIndex - SourceLbo - SourceBytesInRun -
6963  //
6964  // all correctly decribe the allocation to be removed. In the loop
6965  // below we will start here and continue enumerating the Mcb runs
6966  // until we are finished with the allocation to be relocated.
6967  //
6968 
6969  *FirstSpliceTargetCluster = TargetCluster;
6970 
6971  *SecondSpliceSourceCluster =
6972  *FirstSpliceTargetCluster +
6973  (BytesToReallocate >> Vcb->AllocationSupport.LogOfBytesPerCluster) - 1;
6974 
6975  for (SourceBytesRemaining = BytesToReallocate, SourceMcbVbo = 0;
6976 
6977  SourceBytesRemaining > 0;
6978 
6979  SourceIndex += 1,
6980  SourceBytesRemaining -= SourceMcbBytesInRun,
6981  SourceMcbVbo += SourceMcbBytesInRun) {
6982 
6983  if (SourceMcbVbo != 0) {
6984 #ifdef _MSC_VER
6985 #pragma prefast( suppress:28931, "needed for debug build" )
6986 #endif
6988  SourceIndex,
6989  &SourceVbo,
6990  &SourceLbo,
6991  &SourceBytesInRun );
6992  NT_ASSERT( Result);
6993  }
6994 
6995  NT_ASSERT( SourceVbo == SourceMcbVbo + FileOffset );
6996 
6997  SourceMcbBytesInRun =
6998  SourceBytesInRun < SourceBytesRemaining ?
6999  SourceBytesInRun : SourceBytesRemaining;
7000 
7001  FatAddMcbEntry( Vcb, SourceMcb,
7002  SourceMcbVbo,
7003  SourceLbo,
7004  SourceMcbBytesInRun );
7005  }
7006 
7007  //
7008  // Now compute the cluster of the target of the second
7009  // splice. If the final run in the above loop was
7010  // more than we needed, then we can just do arithmetic,
7011  // otherwise we have to look up the next run.
7012  //
7013 
7014  if (SourceMcbBytesInRun < SourceBytesInRun) {
7015 
7016  *SecondSpliceTargetCluster =
7017  FatGetIndexFromLbo( Vcb, SourceLbo + SourceMcbBytesInRun );
7018 
7019  } else {
7020 
7022  SourceIndex,
7023  &SourceVbo,
7024  &SourceLbo,
7025  &SourceBytesInRun )) {
7026 
7027  *SecondSpliceTargetCluster = FatGetIndexFromLbo( Vcb, SourceLbo );
7028 
7029  } else {
7030 
7031  *SecondSpliceTargetCluster = FAT_CLUSTER_LAST;
7032  }
7033  }
7034 }
#define FAT_CLUSTER_LAST
Definition: fat.h:258
ULONG32 VBO
Definition: fat.h:38
Definition: cdstruc.h:504
#define FatRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2965
BOOLEAN FatLookupMcbEntry(IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, OUT PLBO Lbo, OUT PULONG ByteCount OPTIONAL, OUT PULONG Index OPTIONAL)
Definition: fsctrl.c:418
IN PFCB FcbOrDcb
Definition: fatprocs.h:297
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
LONGLONG LBO
Definition: fat.h:34
unsigned char BOOLEAN
_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 FatGetIndexFromLbo(VCB, LBO)
Definition: fat.h:566
#define Vcb
Definition: cdprocs.h:1425
CD_MCB Mcb
Definition: cdstruc.h:1022
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
unsigned int ULONG
Definition: retypes.h:1
PVCB Vcb
Definition: cdstruc.h:939
BOOLEAN FatGetNextMcbEntry(IN PVCB Vcb, IN PLARGE_MCB Mcb, IN ULONG RunIndex, OUT PVBO Vbo, OUT PLBO Lbo, OUT PULONG ByteCount)
Definition: fsctrl.c:541
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312
BOOLEAN FatAddMcbEntry(IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, IN LBO Lbo, IN ULONG SectorCount)
Definition: fsctrl.c:364

◆ FatGetNextMcbEntry()

BOOLEAN FatGetNextMcbEntry ( IN PVCB  Vcb,
IN PLARGE_MCB  Mcb,
IN ULONG  RunIndex,
OUT PVBO  Vbo,
OUT PLBO  Lbo,
OUT PULONG  ByteCount 
)

Definition at line 541 of file fsctrl.c.

550 {
551  BOOLEAN Results;
552  LONGLONG LiVbo;
553  LONGLONG LiLbo;
554  LONGLONG LiSectorCount;
555 
556  PAGED_CODE();
557 
558  LiVbo = LiLbo = 0;
559 
560  Results = FsRtlGetNextLargeMcbEntry( Mcb,
561  RunIndex,
562  &LiVbo,
563  &LiLbo,
564  &LiSectorCount );
565 
566  if (Results) {
567 
568  *Vbo = ((VBO) LiVbo) << MCB_SCALE_LOG2;
569 
570  if (((ULONG) LiLbo) != -1) {
571 
572  *Lbo = ((LBO) LiLbo) << MCB_SCALE_LOG2;
573 
574  } else {
575 
576  *Lbo = 0;
577  }
578 
579  *ByteCount = ((ULONG) LiSectorCount) << MCB_SCALE_LOG2;
580 
581  if ((*ByteCount == 0) && (LiSectorCount != 0)) {
582 
583  //
584  // If 'ByteCount' overflows, then this is likely a file of
585  // max supported size (2^32 - 1) in one contiguous run.
586  //
587 
588  NT_ASSERT( RunIndex == 0 );
589 
590  *ByteCount = 0xFFFFFFFF;
591  }
592  }
593 
594  return Results;
595 }
ULONG32 VBO
Definition: fat.h:38
IN PFCB IN VBO OUT PLBO Lbo
Definition: fatprocs.h:297
_Must_inspect_result_ _In_ ULONG RunIndex
Definition: fsrtlfuncs.h:538
BOOLEAN NTAPI FsRtlGetNextLargeMcbEntry(IN PLARGE_MCB Mcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
Definition: largemcb.c:391
LONGLONG LBO
Definition: fat.h:34
#define MCB_SCALE_LOG2
unsigned char BOOLEAN
int64_t LONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1061
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
unsigned int ULONG
Definition: retypes.h:1
IN PFCB IN VBO Vbo
Definition: fatprocs.h:297
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by _Requires_lock_held_(), FatComputeMoveFileSplicePoints(), and FatPagingFileIo().

◆ FatGetStatistics()

NTSTATUS FatGetStatistics ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 4904 of file fsctrl.c.

4926 {
4928  NTSTATUS Status;
4929  PVCB Vcb;
4930 
4933  ULONG StatsSize;
4935 
4936  PAGED_CODE();
4937 
4939 
4940  DebugTrace(+1, Dbg, "FatGetStatistics...\n", 0);
4941 
4942  //
4943  // Extract the buffer
4944  //
4945 
4946  BufferLength = IrpSp->Parameters.FileSystemControl.OutputBufferLength;
4947 
4948  //
4949  // Get a pointer to the output buffer.
4950  //
4951 
4952  Buffer = Irp->AssociatedIrp.SystemBuffer;
4953 
4954  //
4955  // Make sure the buffer is big enough for at least the common part.
4956  //
4957 
4958  if (BufferLength < sizeof(FILESYSTEM_STATISTICS)) {
4959 
4961 
4962  DebugTrace(-1, Dbg, "FatGetStatistics -> %08lx\n", STATUS_BUFFER_TOO_SMALL );
4963 
4964  return STATUS_BUFFER_TOO_SMALL;
4965  }
4966 
4967  //
4968  // Now see how many bytes we can copy.
4969  //
4970 
4971  StatsSize = sizeof(FILE_SYSTEM_STATISTICS) * FatData.NumberProcessors;
4972 
4973  if (BufferLength < StatsSize) {
4974 
4977 
4978  } else {
4979 
4980  BytesToCopy = StatsSize;
4982  }
4983 
4984  //
4985  // Get the Vcb.
4986  //
4987 
4989 
4990  //
4991  // Fill in the output buffer
4992  //
4993 
4994  RtlCopyMemory( Buffer, Vcb->Statistics, BytesToCopy );
4995 
4996  Irp->IoStatus.Information = BytesToCopy;
4997 
4998  FatCompleteRequest( IrpContext, Irp, Status );
4999 
5000  DebugTrace(-1, Dbg, "FatGetStatistics -> %08lx\n", Status);
5001 
5002  return Status;
5003 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
Definition: cdstruc.h:504
VOLUME_DEVICE_OBJECT * PVOLUME_DEVICE_OBJECT
Definition: cdstruc.h:775
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
ULONG NumberProcessors
Definition: fatstruc.h:80
_In_ ULONG BufferLength
Definition: usbdlib.h:225
Definition: bufpool.h:45
#define Dbg
Definition: fsctrl.c:30
FAT_DATA FatData
Definition: fatdata.c:56
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define Vcb
Definition: cdprocs.h:1425
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int ULONG
Definition: retypes.h:1
struct _FILE_SYSTEM_STATISTICS FILE_SYSTEM_STATISTICS
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

◆ FatIsBootSectorFat()

BOOLEAN FatIsBootSectorFat ( IN PPACKED_BOOT_SECTOR  BootSector)

Definition at line 2526 of file fsctrl.c.

2546 {
2547  BOOLEAN Result;
2548  BIOS_PARAMETER_BLOCK Bpb = {0};
2549 
2550  DebugTrace(+1, Dbg, "FatIsBootSectorFat, BootSector = %p\n", BootSector);
2551 
2552  //
2553  // The result is true unless we decide that it should be false
2554  //
2555 
2556  Result = TRUE;
2557 
2558  //
2559  // Unpack the bios and then test everything
2560  //
2561 
2562  FatUnpackBios( &Bpb, &BootSector->PackedBpb );
2563  if (Bpb.Sectors != 0) { Bpb.LargeSectors = 0; }
2564 
2565  if ((BootSector->Jump[0] != 0xe9) &&
2566  (BootSector->Jump[0] != 0xeb) &&
2567  (BootSector->Jump[0] != 0x49)) {
2568 
2569  Result = FALSE;
2570 
2571  //
2572  // Enforce some sanity on the sector size (easy check)
2573  //
2574 
2575  } else if ((Bpb.BytesPerSector != 128) &&
2576  (Bpb.BytesPerSector != 256) &&
2577  (Bpb.BytesPerSector != 512) &&
2578  (Bpb.BytesPerSector != 1024) &&
2579  (Bpb.BytesPerSector != 2048) &&
2580  (Bpb.BytesPerSector != 4096)) {
2581 
2582  Result = FALSE;
2583 
2584  //
2585  // Likewise on the clustering.
2586  //
2587 
2588  } else if ((Bpb.SectorsPerCluster != 1) &&
2589  (Bpb.SectorsPerCluster != 2) &&
2590  (Bpb.SectorsPerCluster != 4) &&
2591  (Bpb.SectorsPerCluster != 8) &&
2592  (Bpb.SectorsPerCluster != 16) &&
2593  (Bpb.SectorsPerCluster != 32) &&
2594  (Bpb.SectorsPerCluster != 64) &&
2595  (Bpb.SectorsPerCluster != 128)) {
2596 
2597  Result = FALSE;
2598 
2599  //
2600  // Likewise on the reserved sectors (must reflect at least the boot sector!)
2601  //
2602 
2603  } else if (Bpb.ReservedSectors == 0) {
2604 
2605  Result = FALSE;
2606 
2607  //
2608  // No FATs? Wrong ...
2609  //
2610 
2611  } else if (Bpb.Fats == 0) {
2612 
2613  Result = FALSE;
2614 
2615  //
2616  // Prior to DOS 3.2 might contains value in both of Sectors and
2617  // Sectors Large.
2618  //
2619 
2620  } else if ((Bpb.Sectors == 0) && (Bpb.LargeSectors == 0)) {
2621 
2622  Result = FALSE;
2623 
2624  //
2625  // Check that FAT32 (SectorsPerFat == 0) claims some FAT space and
2626  // is of a version we recognize, currently Version 0.0.
2627  //
2628 
2629  } else if (Bpb.SectorsPerFat == 0 && ( Bpb.LargeSectorsPerFat == 0 ||
2630  Bpb.FsVersion != 0 )) {
2631 
2632  Result = FALSE;
2633 
2634  } else if ((Bpb.Media != 0xf0) &&
2635  (Bpb.Media != 0xf8) &&
2636  (Bpb.Media != 0xf9) &&
2637  (Bpb.Media != 0xfb) &&
2638  (Bpb.Media != 0xfc) &&
2639  (Bpb.Media != 0xfd) &&
2640  (Bpb.Media != 0xfe) &&
2641  (Bpb.Media != 0xff) &&
2642  (!FatData.FujitsuFMR || ((Bpb.Media != 0x00) &&
2643  (Bpb.Media != 0x01) &&
2644  (Bpb.Media != 0xfa)))) {
2645 
2646  Result = FALSE;
2647 
2648  //
2649  // If this isn't FAT32, then there better be a claimed root directory
2650  // size here ...
2651  //
2652 
2653  } else if (Bpb.SectorsPerFat != 0 && Bpb.RootEntries == 0) {
2654 
2655  Result = FALSE;
2656 
2657  //
2658  // If this is FAT32 (i.e., extended BPB), look for and refuse to mount
2659  // mirror-disabled volumes. If we did, we would need to only write to
2660  // the FAT# indicated in the ActiveFat field. The only user of this is
2661  // the FAT->FAT32 converter after the first pass of protected mode work
2662  // (booting into realmode) and NT should absolutely not be attempting
2663  // to mount such an in-transition volume.
2664  //
2665 
2666  } else if (Bpb.SectorsPerFat == 0 && Bpb.MirrorDisabled) {
2667 
2668  Result = FALSE;
2669  }
2670 
2671  DebugTrace(-1, Dbg, "FatIsBootSectorFat -> %08lx\n", Result);
2672 
2673  return Result;
2674 }
#define TRUE
Definition: types.h:120
BOOLEAN FujitsuFMR
Definition: fatstruc.h:94
USHORT SectorsPerFat
Definition: fat.h:111
ULONG MirrorDisabled
Definition: fat.h:122
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
USHORT FsVersion
Definition: fat.h:126
USHORT Sectors
Definition: fat.h:109
unsigned char BOOLEAN
_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 Dbg
Definition: fsctrl.c:30
FAT_DATA FatData
Definition: fatdata.c:56
USHORT BytesPerSector
Definition: fat.h:104
USHORT RootEntries
Definition: fat.h:108
ULONG32 LargeSectorsPerFat
Definition: fat.h:116
USHORT ReservedSectors
Definition: fat.h:106
UCHAR SectorsPerCluster
Definition: fat.h:105
#define FatUnpackBios(Bios, Pbios)
Definition: fat.h:136
ULONG32 LargeSectors
Definition: fat.h:115

◆ FatIsMediaWriteProtected()

BOOLEAN FatIsMediaWriteProtected ( IN PIRP_CONTEXT  IrpContext,
IN PDEVICE_OBJECT  TargetDeviceObject 
)

Definition at line 2682 of file fsctrl.c.

2703 {
2704  PIRP Irp;
2705  KEVENT Event;
2706  NTSTATUS Status;
2708 
2709  PAGED_CODE();
2710  UNREFERENCED_PARAMETER( IrpContext );
2711 
2712  //
2713  // Query the partition table
2714  //
2715 
2717 
2718  //
2719  // See if the media is write protected. On success or any kind
2720  // of error (possibly illegal device function), assume it is
2721  // writeable, and only complain if he tells us he is write protected.
2722  //
2723 
2726  NULL,
2727  0,
2728  NULL,
2729  0,
2730  FALSE,
2731  &Event,
2732  &Iosb );
2733 
2734  //
2735  // Just return FALSE in the unlikely event we couldn't allocate an Irp.
2736  //
2737 
2738  if ( Irp == NULL ) {
2739 
2740  return FALSE;
2741  }
2742 
2744 
2746 
2747  if ( Status == STATUS_PENDING ) {
2748 
2750  Executive,
2751  KernelMode,
2752  FALSE,
2753  (PLARGE_INTEGER)NULL );
2754 
2755  Status = Iosb.Status;
2756  }
2757 
2759 }
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1780
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
return Iosb
Definition: create.c:4426
#define STATUS_PENDING
Definition: ntstatus.h:82
#define VOID
Definition: acefi.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1664
#define PAGED_CODE()

◆ FatIsPathnameValid()

NTSTATUS FatIsPathnameValid ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 4176 of file fsctrl.c.

4203 {
4204  PAGED_CODE();
4205 
4206  DebugTrace(+1, Dbg, "FatIsPathnameValid...\n", 0);
4207 
4208  FatCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
4209 
4210  DebugTrace(-1, Dbg, "FatIsPathnameValid -> %08lx\n", STATUS_SUCCESS);
4211 
4212  return STATUS_SUCCESS;
4213 }
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define Dbg
Definition: fsctrl.c:30
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

◆ FatIsVolumeDirty()

NTSTATUS FatIsVolumeDirty ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 3969 of file fsctrl.c.

3990 {
3992 
3994  PVCB Vcb;
3995  PFCB Fcb;
3996  PCCB Ccb;
3997 
3999 
4000  PAGED_CODE();
4001 
4002  //
4003  // Get the current stack location and extract the output
4004  // buffer information.
4005  //
4006 
4008 
4009  //
4010  // Get a pointer to the output buffer. Look at the system buffer field in the
4011  // irp first. Then the Irp Mdl.
4012  //
4013 
4014  if (Irp->AssociatedIrp.SystemBuffer != NULL) {
4015 
4016  VolumeState = Irp->AssociatedIrp.SystemBuffer;
4017 
4018  } else if (Irp->MdlAddress != NULL) {
4019 
4020 #ifndef __REACTOS__
4021  VolumeState = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, LowPagePriority | MdlMappingNoExecute );
4022 #else
4024 #endif
4025 
4026  if (VolumeState == NULL) {
4027 
4030  }
4031 
4032  } else {
4033 
4036  }
4037 
4038  //
4039  // Make sure the output buffer is large enough and then initialize
4040  // the answer to be that the volume isn't dirty.
4041  //
4042 
4043  if (IrpSp->Parameters.FileSystemControl.OutputBufferLength < sizeof(ULONG)) {
4044 
4046  return STATUS_INVALID_PARAMETER;
4047  }
4048 
4049  *VolumeState = 0;
4050 
4051  //
4052  // Decode the file object
4053  //
4054 
4056 
4057  if (TypeOfOpen != UserVolumeOpen) {
4058 
4060  return STATUS_INVALID_PARAMETER;
4061  }
4062 
4063  if (Vcb->VcbCondition != VcbGood) {
4064 
4066  return STATUS_VOLUME_DISMOUNTED;
4067  }
4068 
4069  //
4070  // Disable PopUps, we want to return any error.
4071  //
4072 
4073  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_POPUPS);
4074 
4075  //
4076  // Verify the Vcb. We want to make double sure that this volume
4077  // is around so that we know our information is good.
4078  //
4079 
4080  FatVerifyVcb( IrpContext, Vcb );
4081 
4082  //
4083  // Now set the returned information. We can avoid probing the disk since
4084  // we know our internal state is in sync.
4085  //
4086 
4087  if ( FlagOn(Vcb->VcbState, VCB_STATE_FLAG_MOUNTED_DIRTY) ) {
4088 
4090  }
4091 
4092  Irp->IoStatus.Information = sizeof( ULONG );
4093 
4094  FatCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
4095  return STATUS_SUCCESS;
4096 }
IN PVCB IN FAT_VOLUME_STATE VolumeState
Definition: fatprocs.h:1987
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define VCB_STATE_FLAG_MOUNTED_DIRTY
Definition: fatstruc.h:561
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: cdstruc.h:1073
#define VOLUME_IS_DIRTY
Definition: ntifs_ex.h:330
Definition: cdstruc.h:504
VOID FatVerifyVcb(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
Definition: verfysup.c:270
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS
Definition: cdstruc.h:1228
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:593
#define STATUS_INVALID_USER_BUFFER
Definition: udferr_usr.h:166
smooth NULL
Definition: ftsmooth.c:416
#define Vcb
Definition: cdprocs.h:1425
enum _TYPE_OF_OPEN TYPE_OF_OPEN
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int * PULONG
Definition: retypes.h:1
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:733
unsigned int ULONG
Definition: retypes.h:1
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:3014
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
#define PAGED_CODE()

◆ FatIsVolumeMounted()

NTSTATUS FatIsVolumeMounted ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 4104 of file fsctrl.c.

4125 {
4126  NTSTATUS Status;
4127 
4129 
4130  PVCB Vcb = NULL;
4131  PFCB Fcb;
4132  PCCB Ccb;
4133 
4134  PAGED_CODE();
4135 
4137 
4139 
4140  DebugTrace(+1, Dbg, "FatIsVolumeMounted...\n", 0);
4141 
4142  //
4143  // Decode the file object.
4144  //
4145 
4147 
4148  NT_ASSERT( Vcb != NULL );
4149  _Analysis_assume_( Vcb != NULL );
4150 
4151  //
4152  // Disable PopUps, we want to return any error.
4153  //
4154 
4155  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_POPUPS);
4156 
4157  //
4158  // Verify the Vcb.
4159  //
4160 
4161  FatVerifyVcb( IrpContext, Vcb );
4162 
4163  FatCompleteRequest( IrpContext, Irp, Status );
4164 
4165  DebugTrace(-1, Dbg, "FatIsVolumeMounted -> %08lx\n", Status);
4166 
4167  return Status;
4168 }
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
Definition: cdstruc.h:1073
LONG NTSTATUS
Definition: precomp.h:26
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
Definition: cdstruc.h:504
VOID FatVerifyVcb(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
Definition: verfysup.c:270
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS
Definition: cdstruc.h:1228
smooth NULL
Definition: ftsmooth.c:416
#define Dbg
Definition: fsctrl.c:30
#define Vcb
Definition: cdprocs.h:1425
#define VOID
Definition: acefi.h:82
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:3014
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
#define _Analysis_assume_(expr)
Definition: no_sal2.h:10
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

◆ FatLookupLastMcbEntry()

BOOLEAN FatLookupLastMcbEntry ( IN PVCB  Vcb,
IN PLARGE_MCB  Mcb,
OUT PVBO  Vbo,
OUT PLBO  Lbo,
OUT PULONG Index   
)

Definition at line 494 of file fsctrl.c.

502 {
503  BOOLEAN Results;
504  LONGLONG LiVbo;
505  LONGLONG LiLbo;
506  ULONG LocalIndex;
507 
508  PAGED_CODE();
509 
510  LiVbo = LiLbo = 0;
511  LocalIndex = 0;
512 
514  &LiVbo,
515  &LiLbo,
516  &LocalIndex );
517 
518  *Vbo = ((VBO) LiVbo) << MCB_SCALE_LOG2;
519 
520  if (((ULONG) LiLbo) != -1) {
521 
522  *Lbo = ((LBO) LiLbo) << MCB_SCALE_LOG2;
523 
524  *Lbo += (MCB_SCALE - 1);
525  *Vbo += (MCB_SCALE - 1);
526 
527  } else {
528 
529  *Lbo = 0;
530  }
531 
532  if (Index) {
533  *Index = LocalIndex;
534  }
535 
536  return Results;
537 }
#define MCB_SCALE
ULONG32 VBO
Definition: fat.h:38
IN PFCB IN VBO OUT PLBO Lbo
Definition: fatprocs.h:297
LONGLONG LBO
Definition: fat.h:34
#define MCB_SCALE_LOG2
unsigned char BOOLEAN
int64_t LONGLONG
Definition: typedefs.h:67
static const UCHAR Index[8]
Definition: usbohci.c:18
BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex(IN PLARGE_MCB OpaqueMcb, OUT PLONGLONG LargeVbn, OUT PLONGLONG LargeLbn, OUT PULONG Index)
Definition: largemcb.c:675
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
unsigned int ULONG
Definition: retypes.h:1
IN PFCB IN VBO Vbo
Definition: fatprocs.h:297
#define PAGED_CODE()

Referenced by _Requires_lock_held_().

◆ FatLookupMcbEntry()

BOOLEAN FatLookupMcbEntry ( IN PVCB  Vcb,
IN PLARGE_MCB  Mcb,
IN VBO  Vbo,
OUT PLBO  Lbo,
OUT PULONG ByteCount  OPTIONAL,
OUT PULONG Index  OPTIONAL 
)

Definition at line 418 of file fsctrl.c.

426 {
427  BOOLEAN Results;
428  LONGLONG LiLbo;
429  LONGLONG LiSectorCount;
431 
432  LiLbo = 0;
433  LiSectorCount = 0;
434 
436 
437  Results = FsRtlLookupLargeMcbEntry( Mcb,
438  (Vbo >> MCB_SCALE_LOG2),
439  &LiLbo,
440  ARGUMENT_PRESENT(ByteCount) ? &LiSectorCount : NULL,
441  NULL,
442  NULL,
443  Index );
444 
445  if ((ULONG) LiLbo != -1) {
446 
447  *Lbo = (((LBO) LiLbo) << MCB_SCALE_LOG2);
448 
449  if (Results) {
450 
451  *Lbo += Remainder;
452  }
453 
454  } else {
455 
456  *Lbo = 0;
457  }
458 
460 
461  *ByteCount = (ULONG) LiSectorCount;
462 
463  if (*ByteCount) {
464 
466 
467  //
468  // If ByteCount overflows, then this is likely the case of
469  // a file of max-supported size (4GiB - 1), allocated in a
470  // single continuous run.
471  //
472 
473  if (*ByteCount == 0) {
474 
475  *ByteCount = 0xFFFFFFFF;
476  }
477 
478  if (Results) {
479 
480  *ByteCount -= Remainder;
481  }
482  }
483 
484  }
485 
486  return Results;
487 }
IN PFCB IN VBO OUT PLBO Lbo
Definition: fatprocs.h:297
LONGLONG LBO
Definition: fat.h:34
#define MCB_SCALE_LOG2
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
int64_t LONGLONG
Definition: typedefs.h:67
#define ARGUMENT_PRESENT(ArgumentPointer)
static const UCHAR Index[8]
Definition: usbohci.c:18
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1061
BOOLEAN NTAPI FsRtlLookupLargeMcbEntry(IN PLARGE_MCB Mcb, IN LONGLONG Vbn, OUT PLONGLONG Lbn OPTIONAL, OUT PLONGLONG SectorCountFromLbn OPTIONAL, OUT PLONGLONG StartingLbn OPTIONAL, OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL, OUT PULONG Index OPTIONAL)
Definition: largemcb.c:564
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
unsigned int ULONG
Definition: retypes.h:1
#define MCB_SCALE_MODULO
IN PFCB IN VBO Vbo
Definition: fatprocs.h:297
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046

Referenced by _Requires_lock_held_(), FatComputeMoveFileSplicePoints(), and FatPagingFileIo().

◆ FatPerformVerifyDiskRead()

BOOLEAN FatPerformVerifyDiskRead ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb,
IN PVOID  Buffer,
IN LBO  Lbo,
IN ULONG  NumberOfBytesToRead,
IN BOOLEAN  ReturnOnError 
)

Definition at line 4577 of file fsctrl.c.

4615 {
4616  KEVENT Event;
4617  PIRP Irp;
4619  NTSTATUS Status;
4621 
4622  PAGED_CODE();
4623 
4624  DebugTrace(0, Dbg, "FatPerformVerifyDiskRead, Lbo = %08lx\n", Lbo );
4625 
4626  //
4627  // Initialize the event we're going to use
4628  //
4629 
4631 
4632  //
4633  // Build the irp for the operation and also set the overrride flag
4634  //
4635 
4636  ByteOffset.QuadPart = Lbo;
4637 
4639  Vcb->TargetDeviceObject,
4640  Buffer,
4641  NumberOfBytesToRead,
4642  &ByteOffset,
4643  &Event,
4644  &Iosb );
4645 
4646  if ( Irp == NULL ) {
4647 
4649  }
4650 
4652 
4653  //
4654  // Call the device to do the read and wait for it to finish.
4655  //
4656 
4657  Status = IoCallDriver( Vcb->TargetDeviceObject, Irp );
4658 
4659  if (Status == STATUS_PENDING) {
4660 
4662 
4663  Status = Iosb.Status;
4664  }
4665 
4667 
4668  //
4669  // Special case this error code because this probably means we used
4670  // the wrong sector size and we want to reject STATUS_WRONG_VOLUME.
4671  //
4672 
4674 
4675  return FALSE;
4676  }
4677 
4678  //
4679  // If it doesn't succeed then either return or raise the error.
4680  //
4681 
4682  if (!NT_SUCCESS(Status)) {
4683 
4684  if (ReturnOnError) {
4685 
4686  return FALSE;
4687 
4688  } else {
4689 
4690  FatNormalizeAndRaiseStatus( IrpContext, Status );
4691  }
4692  }
4693 
4694  //
4695  // And return to our caller
4696  //
4697 
4698  return TRUE;
4699 }
#define TRUE
Definition: types.h:120
#define FatNormalizeAndRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2983
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
IN PFCB IN VBO OUT PLBO Lbo
Definition: fatprocs.h:297
#define FatRaiseStatus(IRPCONTEXT, STATUS)
Definition: fatprocs.h:2965
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1780
Definition: bufpool.h:45
#define Dbg
Definition: fsctrl.c:30
return Iosb
Definition: create.c:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define Vcb
Definition: cdprocs.h:1425
#define VOID
Definition: acefi.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by FatVerifyLookupFatEntry().

◆ FatQueryBpb()

NTSTATUS FatQueryBpb ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 4221 of file fsctrl.c.

4242 {
4244 
4245  PVCB Vcb;
4246 
4247  PFSCTL_QUERY_FAT_BPB_BUFFER BpbBuffer;
4248 
4249  PAGED_CODE();
4250 
4252 
4253  DebugTrace(+1, Dbg, "FatQueryBpb...\n", 0);
4254 
4255  //
4256  // Get the Vcb. If we didn't keep the information needed for this call,
4257  // we had a reason ...
4258  //
4259 
4261 
4262  if (Vcb->First0x24BytesOfBootSector == NULL) {
4263 
4265  DebugTrace(-1, Dbg, "FatQueryBpb -> %08lx\n", STATUS_INVALID_DEVICE_REQUEST );
4267  }
4268 
4269  //
4270  // Extract the buffer
4271  //
4272 
4273  BpbBuffer = (PFSCTL_QUERY_FAT_BPB_BUFFER)Irp->AssociatedIrp.SystemBuffer;
4274 
4275  //
4276  // Make sure the buffer is big enough.
4277  //
4278 
4279  if (IrpSp->Parameters.FileSystemControl.OutputBufferLength < 0x24) {
4280 
4282  DebugTrace(-1, Dbg, "FatQueryBpb -> %08lx\n", STATUS_BUFFER_TOO_SMALL );
4283  return STATUS_BUFFER_TOO_SMALL;
4284  }
4285 
4286  //
4287  // Fill in the output buffer
4288  //
4289 
4291  Vcb->First0x24BytesOfBootSector,
4292  0x24 );
4293 
4294  Irp->IoStatus.Information = 0x24;
4295 
4296  FatCompleteRequest( IrpContext, Irp, STATUS_SUCCESS );
4297  DebugTrace(-1, Dbg, "FatQueryBpb -> %08lx\n", STATUS_SUCCESS);
4298  return STATUS_SUCCESS;
4299 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
UCHAR First0x24BytesOfBootSector[0x24]
Definition: iotypes.h:5878
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
Definition: cdstruc.h:504
VOLUME_DEVICE_OBJECT * PVOLUME_DEVICE_OBJECT
Definition: cdstruc.h:775
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
smooth NULL
Definition: ftsmooth.c:416
#define Dbg
Definition: fsctrl.c:30
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct _FSCTL_QUERY_FAT_BPB_BUFFER * PFSCTL_QUERY_FAT_BPB_BUFFER
#define Vcb
Definition: cdprocs.h:1425
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2867
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

◆ FatRemoveMcbEntry()

VOID FatRemoveMcbEntry ( IN PVCB  Vcb,
IN PLARGE_MCB  Mcb,
IN VBO  Vbo,
IN ULONG  SectorCount 
)

Definition at line 599 of file fsctrl.c.

605 {
606  PAGED_CODE();
607 
608  if ((SectorCount) && (SectorCount != 0xFFFFFFFF)) {
609 
610  SectorCount--;
612  SectorCount++;
613  }
614 
615  Vbo >>= MCB_SCALE_LOG2;
616 
617 #if DBG
618  _SEH2_TRY {
619 #endif
620 
622  (LONGLONG) Vbo,
624 
625 #if DBG
626  } _SEH2_EXCEPT(FatBugCheckExceptionFilter( _SEH2_GetExceptionInformation() )) {
627 
628  NOTHING;
629  } _SEH2_END;
630 #endif
631 
632 }
VOID NTAPI FsRtlRemoveLargeMcbEntry(IN PLARGE_MCB Mcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
Definition: largemcb.c:862
_SEH2_TRY
Definition: create.c:4250
#define MCB_SCALE_LOG2
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:11
int64_t LONGLONG
Definition: typedefs.h:67
#define NOTHING
Definition: env_spec_w32.h:461
ULONG SectorCount
Definition: part_xbox.c:31
_SEH2_END
Definition: create.c:4424
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:334
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
IN PFCB IN VBO Vbo
Definition: fatprocs.h:297
#define PAGED_CODE()

Referenced by _Requires_lock_held_(), FatCloseEaFile(), and FatTearDownAllocationSupport().

◆ FatSearchBufferForLabel()

NTSTATUS FatSearchBufferForLabel ( IN PIRP_CONTEXT  IrpContext,
IN PVPB  Vpb,
IN PVOID  Buffer,
IN ULONG  Size,
OUT PBOOLEAN  LabelFound 
)

Definition at line 7835 of file fsctrl.c.

7873 {
7874  NTSTATUS Status;
7875  WCHAR UnicodeBuffer[11];
7876 
7877  PDIRENT Dirent;
7878  PDIRENT TerminationDirent;
7879  ULONG VolumeLabelLength;
7882 
7883  PAGED_CODE();
7884 
7885  UNREFERENCED_PARAMETER( IrpContext );
7886 
7887  Dirent = Buffer;
7888 
7889  TerminationDirent = Dirent + Size / sizeof(DIRENT);
7890 
7891  while ( Dirent < TerminationDirent ) {
7892 
7893  if ( Dirent->FileName[0] == FAT_DIRENT_NEVER_USED ) {
7894 
7895  Dirent = TerminationDirent;
7896  break;
7897  }
7898 
7899  //
7900  // If the entry is the non-deleted volume label break from the loop.
7901  //
7902  // Note that all out parameters are already correctly set.
7903  //
7904 
7905  if (((Dirent->Attributes & ~FAT_DIRENT_ATTR_ARCHIVE) ==
7907  (Dirent->FileName[0] != FAT_DIRENT_DELETED)) {
7908 
7909  break;
7910  }
7911 
7912  Dirent += 1;
7913  }
7914 
7915  if (Dirent >= TerminationDirent) {
7916 
7917  //
7918  // We've run out of buffer.
7919  //
7920 
7921  *LabelFound = FALSE;
7922  return STATUS_SUCCESS;
7923  }
7924 
7925 
7926  //
7927  // Compute the length of the volume name
7928  //
7929 
7930  OemString.Buffer = (PCHAR)&Dirent->FileName[0];
7931  OemString.MaximumLength = 11;
7932 
7933  for ( OemString.Length = 11;
7934  OemString.Length > 0;
7935  OemString.Length -= 1) {
7936 
7937  if ( (Dirent->FileName[OemString.Length-1] != 0x00) &&
7938  (Dirent->FileName[OemString.Length-1] != 0x20) ) { break; }
7939  }
7940 
7941  UnicodeString.MaximumLength = sizeof( UnicodeBuffer );
7942  UnicodeString.Buffer = &UnicodeBuffer[0];
7943 
7945  &OemString,
7946  FALSE );
7947 
7948  if ( !NT_SUCCESS( Status ) ) {
7949 
7950  return Status;
7951  }
7952 
7953  VolumeLabelLength = UnicodeString.Length;
7954 
7955  if ( (VolumeLabelLength != (ULONG)Vpb->VolumeLabelLength) ||
7956  (!RtlEqualMemory(&UnicodeBuffer[0],
7957  &Vpb->VolumeLabel[0],
7958  VolumeLabelLength)) ) {
7959 
7960  return STATUS_WRONG_VOLUME;
7961  }
7962 
7963  //
7964  // We found a matching label.
7965  //
7966 
7967  *LabelFound = TRUE;
7968  return STATUS_SUCCESS;
7969 }
*BytesInOemString PCHAR OemString
Definition: rtlfuncs.h:1561
#define TRUE
Definition: types.h:120
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1979
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define FAT_DIRENT_NEVER_USED
Definition: fat.h:334
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI RtlOemStringToCountedUnicodeString(IN OUT PUNICODE_STRING UniDest, IN PCOEM_STRING OemSource, IN BOOLEAN AllocateDestinationString)
Definition: unicode.c:1463
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140
STRING OEM_STRING
Definition: umtypes.h:203
#define PCHAR
Definition: match.c:90
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define for
Definition: utility.h:88
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Status
Definition: gdiplustypes.h:24
#define FAT_DIRENT_ATTR_ARCHIVE
Definition: fat.h:373
#define FAT_DIRENT_DELETED
Definition: fat.h:337
#define FAT_DIRENT_ATTR_VOLUME_ID
Definition: fat.h:371
#define DIRENT
Definition: fatfs.h:187
unsigned int ULONG
Definition: retypes.h:1
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT _Inout_ PDIRENT Dirent
Definition: cdprocs.h:429
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1664
#define PAGED_CODE()

◆ FatSetZeroOnDeallocate()

NTSTATUS FatSetZeroOnDeallocate ( __in PIRP_CONTEXT  IrpContext,
__in PIRP  Irp 
)

Definition at line 8131 of file fsctrl.c.

8135 {
8137 
8138  PVCB Vcb;
8139  PFCB FcbOrDcb;
8140  PCCB Ccb;
8141 
8143 
8145 
8146  BOOLEAN ReleaseFcb = FALSE;
8147 
8148  PAGED_CODE();
8149 
8150  //
8151  // This call should always be synchronous.
8152  //
8153 
8154  SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT );
8155 
8157 
8158  if ((TypeOfOpen != UserFileOpen) ||
8159  (!IrpSp->FileObject->WriteAccess) ) {
8160 
8162  return STATUS_ACCESS_DENIED;
8163  }
8164 
8165  //
8166  // Readonly mount should be just that: read only.
8167  //
8168 
8169  if (FlagOn( Vcb->VcbState, VCB_STATE_FLAG_WRITE_PROTECTED)) {
8170 
8173  }
8174 
8175  //
8176  // Acquire main then paging to exclude everyone from this FCB.
8177  //
8178 
8179  FatAcquireExclusiveFcb(IrpContext, FcbOrDcb);
8180  ReleaseFcb = TRUE;
8181 
8182  _SEH2_TRY {
8183 
8185 
8186  } _SEH2_FINALLY {
8187 
8188  if (ReleaseFcb) {
8189  FatReleaseFcb(IrpContext, FcbOrDcb);
8190  }
8191 
8192  } _SEH2_END;
8193 
8194  FatCompleteRequest( IrpContext, Irp, Status );
8195  return Status;
8196 }
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define FCB_STATE_ZERO_ON_DEALLOCATION
Definition: fatstruc.h:1223
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
Definition: cdstruc.h:1073
LONG NTSTATUS
Definition: precomp.h:26
Definition: cdstruc.h:504
#define VCB_STATE_FLAG_WRITE_PROTECTED
Definition: fatstruc.h:569
_SEH2_TRY
Definition: create.c:4250
IN PFCB FcbOrDcb
Definition: fatprocs.h:297
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:593
unsigned char BOOLEAN
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define FatReleaseFcb(IRPCONTEXT, Fcb)
Definition: fatprocs.h:1635
#define Vcb
Definition: cdprocs.h:1425
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
enum _TYPE_OF_OPEN TYPE_OF_OPEN
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_SEH2_FINALLY
Definition: create.c:4395
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG FcbState
Definition: cdstruc.h:977
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
#define PAGED_CODE()

◆ FatUnlockVolume()

NTSTATUS FatUnlockVolume ( IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp 
)

Definition at line 3358 of file fsctrl.c.

3380 {
3381  NTSTATUS Status;
3382 
3384 
3385  PVCB Vcb;
3386  PFCB Fcb;
3387  PCCB Ccb;
3388 
3389  PAGED_CODE();
3390 
3392 
3393  DebugTrace(+1, Dbg, "FatUnlockVolume...\n", 0);
3394 
3395  //
3396  // Decode the file object, the only type of opens we accept are
3397  // user volume opens.
3398  //
3399 
3401 
3403 
3404  DebugTrace(-1, Dbg, "FatUnlockVolume -> %08lx\n", STATUS_INVALID_PARAMETER);
3405  return STATUS_INVALID_PARAMETER;
3406  }
3407 
3408  if ((Ccb == NULL) || !FlagOn( Ccb->Flags, CCB_FLAG_MANAGE_VOLUME_ACCESS )) {
3409 
3411 
3412  DebugTrace(-1, Dbg, "FatUnlockVolume -> %08lx\n", STATUS_INVALID_PARAMETER);
3413  return STATUS_INVALID_PARAMETER;
3414  }
3415 
3416  Status = FatUnlockVolumeInternal( IrpContext, Vcb, IrpSp->FileObject );
3417 
3418  //
3419  // Send notification that the volume is avaliable.
3420  //
3421 
3422  if (NT_SUCCESS( Status )) {
3423 
3425  }
3426 
3427  FatCompleteRequest( IrpContext, Irp, Status );
3428 
3429  DebugTrace(-1, Dbg, "FatUnlockVolume -> %08lx\n", Status);
3430 
3431  return Status;
3432 }
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2621
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: cdstruc.h:1073
LONG NTSTATUS
Definition: precomp.h:26
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
Definition: cdstruc.h:504
#define CCB_FLAG_MANAGE_VOLUME_ACCESS
Definition: fatstruc.h:1337
NTSTATUS FatUnlockVolumeInternal(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PFILE_OBJECT FileObject OPTIONAL)
Definition: fsctrl.c:3605
smooth NULL
Definition: ftsmooth.c:416
#define Dbg
Definition: fsctrl.c:30
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
ULONG Flags
Definition: ntfs.h:532
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_In_ PFCB Fcb
Definition: cdprocs.h:151
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
#define PAGED_CODE()

◆ FatUnlockVolumeInternal()

NTSTATUS FatUnlockVolumeInternal ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb,
IN PFILE_OBJECT FileObject  OPTIONAL 
)

Definition at line 3605 of file fsctrl.c.

3634 {
3635  KIRQL SavedIrql;
3637 
3638  UNREFERENCED_PARAMETER( IrpContext );
3639 
3640  IoAcquireVpbSpinLock( &SavedIrql );
3641 
3642  if (FlagOn(Vcb->Vpb->Flags, VPB_LOCKED) && FileObject == Vcb->FileObjectWithVcbLocked) {
3643 
3644  //
3645  // This one locked it, unlock the volume
3646  //
3647 
3648  ClearFlag( Vcb->Vpb->Flags, (VPB_LOCKED | VPB_DIRECT_WRITES_ALLOWED) );
3649  ClearFlag( Vcb->VcbState, VCB_STATE_FLAG_LOCKED );
3650  Vcb->FileObjectWithVcbLocked = NULL;
3651 
3653  }
3654 
3655  IoReleaseVpbSpinLock( SavedIrql );
3656 
3657  return Status;
3658 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1209
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define VPB_LOCKED
Definition: iotypes.h:1765
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define VCB_STATE_FLAG_LOCKED
Definition: fatstruc.h:558
#define VPB_DIRECT_WRITES_ALLOWED
Definition: iotypes.h:1769
#define Vcb
Definition: cdprocs.h:1425
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
Status
Definition: gdiplustypes.h:24
#define STATUS_NOT_LOCKED
Definition: ntstatus.h:265
return STATUS_SUCCESS
Definition: btrfs.c:3014
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1220

Referenced by FatUnlockVolume().

◆ FatVerifyLookupFatEntry()

VOID FatVerifyLookupFatEntry ( IN PIRP_CONTEXT  IrpContext,
IN PVCB  Vcb,
IN ULONG  FatIndex,
IN OUT PULONG  FatEntry 
)

Definition at line 7973 of file fsctrl.c.

7979 {
7980  ULONG PageEntryOffset;
7981  ULONG OffsetIntoVolumeFile;
7982  PVOID Buffer;
7983 
7984  PAGED_CODE();
7985 
7986  NT_ASSERT(Vcb->AllocationSupport.FatIndexBitSize == 32);
7987 
7988  FatVerifyIndexIsValid( IrpContext, Vcb, FatIndex);
7989 
7990 #ifndef __REACTOS__
7991  Buffer = FsRtlAllocatePoolWithTag( NonPagedPoolNxCacheAligned,
7992 #else
7994 #endif
7995  PAGE_SIZE,
7997 
7998  OffsetIntoVolumeFile = FatReservedBytes(&Vcb->Bpb) + FatIndex * sizeof(ULONG);
7999  PageEntryOffset = (OffsetIntoVolumeFile % PAGE_SIZE) / sizeof(ULONG);
8000 
8001  _SEH2_TRY {
8002 
8003  FatPerformVerifyDiskRead( IrpContext,
8004  Vcb,
8005  Buffer,
8006  OffsetIntoVolumeFile & ~(PAGE_SIZE - 1),
8007  PAGE_SIZE,
8008  TRUE );
8009 
8010  *FatEntry = ((PULONG)(Buffer))[PageEntryOffset];
8011 
8012  } _SEH2_FINALLY {
8013 
8014  ExFreePool( Buffer );
8015  } _SEH2_END;
8016 }
#define TRUE
Definition: types.h:120
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
#define FatVerifyIndexIsValid(IC, V, I)
Definition: fat.h:532
_SEH2_TRY
Definition: create.c:4250
#define FatReservedBytes(B)
Definition: fat.h:414
Definition: bufpool.h:45
#define TAG_ENTRY_LOOKUP_BUFFER
Definition: nodetype.h:181
#define Vcb
Definition: cdprocs.h:1425
IN PVCB IN ULONG FatIndex
Definition: fatprocs.h:373
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_SEH2_END
Definition: create.c:4424
_SEH2_FINALLY
Definition: create.c:4395
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
IN PVCB IN ULONG IN FAT_ENTRY FatEntry
Definition: fatprocs.h:373
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
BOOLEAN FatPerformVerifyDiskRead(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PVOID Buffer, IN LBO Lbo, IN ULONG NumberOfBytesToRead, IN BOOLEAN ReturnOnError)
Definition: fsctrl.c:4577
#define PAGED_CODE()
#define NT_ASSERT
Definition: rtlfuncs.h:3312