ReactOS  0.4.15-dev-3287-gfec35dc
vfat.h File Reference
#include <ntifs.h>
#include <ntdddisk.h>
#include <dos.h>
#include <pseh/pseh2.h>
#include <section_attribs.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for vfat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _BootSector
 
struct  _BootSector32
 
struct  _BootSectorFatX
 
struct  _FsInfoSector
 
struct  _FATDirEntry
 
struct  _EAFileHeader
 
struct  _EASetHeader
 
struct  _EAHeader
 
struct  _FATXDirEntry
 
struct  _slot
 
union  _DIR_ENTRY
 
struct  FATINFO
 
struct  _HASHENTRY
 
struct  _VFAT_DISPATCH
 
struct  _STATISTICS
 
struct  DEVICE_EXTENSION
 
struct  VFAT_GLOBAL_DATA
 
struct  _VFATFCB
 
struct  _VFATCCB
 
struct  __DOSTIME
 
struct  __DOSDATE
 
struct  VFAT_IRP_CONTEXT
 
struct  _VFAT_DIRENTRY_CONTEXT
 
struct  _VFAT_MOVE_CONTEXT
 
struct  _VFAT_CLOSE_CONTEXT
 

Macros

#define USE_ROS_CC_AND_FS
 
#define ENABLE_SWAPOUT
 
#define VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
 
#define ROUND_DOWN(n, align)   (((ULONG)n) & ~((align) - 1l))
 
#define ROUND_UP(n, align)   ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
 
#define ROUND_DOWN_64(n, align)   (((ULONGLONG)n) & ~((align) - 1LL))
 
#define ROUND_UP_64(n, align)   ROUND_DOWN_64(((ULONGLONG)n) + (align) - 1LL, (align))
 
#define FAT_DIRTY_BIT   0x01
 
#define FAT_EAFILE   "EA DATA. SF"
 
#define VFAT_CASE_LOWER_BASE   8
 
#define VFAT_CASE_LOWER_EXT   16
 
#define LONGNAME_MAX_LENGTH   256
 
#define ENTRY_DELETED(IsFatX, DirEntry)   (IsFatX ? FATX_ENTRY_DELETED(&((DirEntry)->FatX)) : FAT_ENTRY_DELETED(&((DirEntry)->Fat)))
 
#define ENTRY_VOLUME(IsFatX, DirEntry)   (IsFatX ? FATX_ENTRY_VOLUME(&((DirEntry)->FatX)) : FAT_ENTRY_VOLUME(&((DirEntry)->Fat)))
 
#define ENTRY_END(IsFatX, DirEntry)   (IsFatX ? FATX_ENTRY_END(&((DirEntry)->FatX)) : FAT_ENTRY_END(&((DirEntry)->Fat)))
 
#define FAT_ENTRY_DELETED(DirEntry)   ((DirEntry)->Filename[0] == 0xe5)
 
#define FAT_ENTRY_END(DirEntry)   ((DirEntry)->Filename[0] == 0)
 
#define FAT_ENTRY_LONG(DirEntry)   (((DirEntry)->Attrib & 0x3f) == 0x0f)
 
#define FAT_ENTRY_VOLUME(DirEntry)   (((DirEntry)->Attrib & 0x1f) == 0x08)
 
#define FATX_ENTRY_DELETED(DirEntry)   ((DirEntry)->FilenameLength == 0xe5)
 
#define FATX_ENTRY_END(DirEntry)   ((DirEntry)->FilenameLength == 0xff)
 
#define FATX_ENTRY_LONG(DirEntry)   (FALSE)
 
#define FATX_ENTRY_VOLUME(DirEntry)   (((DirEntry)->Attrib & 0x1f) == 0x08)
 
#define FAT_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof (FAT_DIR_ENTRY))
 
#define FATX_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof (FATX_DIR_ENTRY))
 
#define BLOCKSIZE   512
 
#define FAT16   (1)
 
#define FAT12   (2)
 
#define FAT32   (3)
 
#define FATX16   (4)
 
#define FATX32   (5)
 
#define VCB_VOLUME_LOCKED   0x0001
 
#define VCB_DISMOUNT_PENDING   0x0002
 
#define VCB_IS_FATX   0x0004
 
#define VCB_IS_SYS_OR_HAS_PAGE   0x0008
 
#define VCB_IS_DIRTY   0x4000 /* Volume is dirty */
 
#define VCB_CLEAR_DIRTY   0x8000 /* Clean dirty flag at shutdown */
 
#define VCB_GOOD   0x0010 /* If not set, the VCB is improper for usage */
 
#define STATISTICS_SIZE_NO_PAD   (sizeof(FILESYSTEM_STATISTICS) + sizeof(FAT_STATISTICS))
 
#define VFAT_BREAK_ON_CORRUPTION   1
 
#define FCB_CACHE_INITIALIZED   0x0001
 
#define FCB_DELETE_PENDING   0x0002
 
#define FCB_IS_FAT   0x0004
 
#define FCB_IS_PAGE_FILE   0x0008
 
#define FCB_IS_VOLUME   0x0010
 
#define FCB_IS_DIRTY   0x0020
 
#define FCB_DELAYED_CLOSE   0x0040
 
#define NODE_TYPE_FCB   ((CSHORT)0x0502)
 
#define CCB_DELETE_ON_CLOSE   0x0001
 
#define TAG_CCB   'CtaF'
 
#define TAG_FCB   'FtaF'
 
#define TAG_IRP   'ItaF'
 
#define TAG_CLOSE   'xtaF'
 
#define TAG_STATS   'VtaF'
 
#define TAG_BUFFER   'OtaF'
 
#define TAG_VPB   'vtaF'
 
#define TAG_NAME   'ntaF'
 
#define TAG_SEARCH   'LtaF'
 
#define TAG_DIRENT   'DtaF'
 
#define ENTRIES_PER_SECTOR   (BLOCKSIZE / sizeof(FATDirEntry))
 
#define IRPCONTEXT_CANWAIT   0x0001
 
#define IRPCONTEXT_COMPLETE   0x0002
 
#define IRPCONTEXT_QUEUE   0x0004
 
#define IRPCONTEXT_PENDINGRETURNED   0x0008
 
#define IRPCONTEXT_DEFERRED_WRITE   0x0010
 
#define vfatAddToStat(Vcb, Stat, Inc)
 

Typedefs

typedef struct _BootSector BootSector
 
typedef struct _EAFileHeader FAT_EA_FILE_HEADER
 
typedef struct _EAFileHeaderPFAT_EA_FILE_HEADER
 
typedef struct _EASetHeader FAT_EA_SET_HEADER
 
typedef struct _EASetHeaderPFAT_EA_SET_HEADER
 
typedef struct _EAHeader FAT_EA_HEADER
 
typedef struct _EAHeaderPFAT_EA_HEADER
 
typedef struct _FATDirEntry FAT_DIR_ENTRY
 
typedef struct _FATDirEntryPFAT_DIR_ENTRY
 
typedef struct _slot slot
 
typedef struct _FATXDirEntry FATX_DIR_ENTRY
 
typedef struct _FATXDirEntryPFATX_DIR_ENTRY
 
typedef union _DIR_ENTRY DIR_ENTRY
 
typedef union _DIR_ENTRYPDIR_ENTRY
 
typedef struct FATINFOPFATINFO
 
typedef struct _HASHENTRY HASHENTRY
 
typedef struct DEVICE_EXTENSIONPDEVICE_EXTENSION
 
typedef NTSTATUS(* PGET_NEXT_CLUSTER) (PDEVICE_EXTENSION, ULONG, PULONG)
 
typedef NTSTATUS(* PFIND_AND_MARK_AVAILABLE_CLUSTER) (PDEVICE_EXTENSION, PULONG)
 
typedef NTSTATUS(* PWRITE_CLUSTER) (PDEVICE_EXTENSION, ULONG, ULONG, PULONG)
 
typedef BOOLEAN(* PIS_DIRECTORY_EMPTY) (PDEVICE_EXTENSION, struct _VFATFCB *)
 
typedef NTSTATUS(* PADD_ENTRY) (PDEVICE_EXTENSION, PUNICODE_STRING, struct _VFATFCB **, struct _VFATFCB *, ULONG, UCHAR, struct _VFAT_MOVE_CONTEXT *)
 
typedef NTSTATUS(* PDEL_ENTRY) (PDEVICE_EXTENSION, struct _VFATFCB *, struct _VFAT_MOVE_CONTEXT *)
 
typedef NTSTATUS(* PGET_NEXT_DIR_ENTRY) (PVOID *, PVOID *, struct _VFATFCB *, struct _VFAT_DIRENTRY_CONTEXT *, BOOLEAN)
 
typedef NTSTATUS(* PGET_DIRTY_STATUS) (PDEVICE_EXTENSION, PBOOLEAN)
 
typedef NTSTATUS(* PSET_DIRTY_STATUS) (PDEVICE_EXTENSION, BOOLEAN)
 
typedef struct _VFAT_DISPATCH VFAT_DISPATCH
 
typedef struct _VFAT_DISPATCHPVFAT_DISPATCH
 
typedef struct _STATISTICS STATISTICS
 
typedef struct _STATISTICSPSTATISTICS
 
typedef struct DEVICE_EXTENSION DEVICE_EXTENSION
 
typedef struct DEVICE_EXTENSION VCB
 
typedef struct DEVICE_EXTENSIONPVCB
 
typedef struct VFAT_GLOBAL_DATAPVFAT_GLOBAL_DATA
 
typedef struct _VFATFCB VFATFCB
 
typedef struct _VFATFCBPVFATFCB
 
typedef struct _VFATCCB VFATCCB
 
typedef struct _VFATCCBPVFATCCB
 
typedef struct __DOSTIME DOSTIME
 
typedef struct __DOSTIMEPDOSTIME
 
typedef struct __DOSDATE DOSDATE
 
typedef struct __DOSDATEPDOSDATE
 
typedef struct VFAT_IRP_CONTEXTPVFAT_IRP_CONTEXT
 
typedef struct _VFAT_DIRENTRY_CONTEXT VFAT_DIRENTRY_CONTEXT
 
typedef struct _VFAT_DIRENTRY_CONTEXTPVFAT_DIRENTRY_CONTEXT
 
typedef struct _VFAT_MOVE_CONTEXT VFAT_MOVE_CONTEXT
 
typedef struct _VFAT_MOVE_CONTEXTPVFAT_MOVE_CONTEXT
 
typedef struct _VFAT_CLOSE_CONTEXT VFAT_CLOSE_CONTEXT
 
typedef struct _VFAT_CLOSE_CONTEXTPVFAT_CLOSE_CONTEXT
 

Functions

FORCEINLINE BOOLEAN VfatIsDirectoryEmpty (PDEVICE_EXTENSION DeviceExt, struct _VFATFCB *Fcb)
 
FORCEINLINE NTSTATUS VfatAddEntry (PDEVICE_EXTENSION DeviceExt, PUNICODE_STRING NameU, struct _VFATFCB **Fcb, struct _VFATFCB *ParentFcb, ULONG RequestedOptions, UCHAR ReqAttr, struct _VFAT_MOVE_CONTEXT *MoveContext)
 
FORCEINLINE NTSTATUS VfatDelEntry (PDEVICE_EXTENSION DeviceExt, struct _VFATFCB *Fcb, struct _VFAT_MOVE_CONTEXT *MoveContext)
 
FORCEINLINE NTSTATUS VfatGetNextDirEntry (PDEVICE_EXTENSION DeviceExt, PVOID *pContext, PVOID *pPage, struct _VFATFCB *pDirFcb, struct _VFAT_DIRENTRY_CONTEXT *DirContext, BOOLEAN First)
 
FORCEINLINE NTSTATUS VfatMarkIrpContextForQueue (PVFAT_IRP_CONTEXT IrpContext)
 
FORCEINLINE BOOLEAN vfatFCBIsDirectory (PVFATFCB FCB)
 
FORCEINLINE BOOLEAN vfatFCBIsReadOnly (PVFATFCB FCB)
 
FORCEINLINE BOOLEAN vfatVolumeIsFatX (PDEVICE_EXTENSION DeviceExt)
 
FORCEINLINE VOID vfatReportChange (IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB Fcb, IN ULONG FilterMatch, IN ULONG Action)
 
NTSTATUS VfatReadDisk (IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN PUCHAR Buffer, IN BOOLEAN Override)
 
NTSTATUS VfatReadDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN ULONG BufferOffset, IN BOOLEAN Wait)
 
NTSTATUS VfatWriteDisk (IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
 
NTSTATUS VfatWriteDiskPartial (IN PVFAT_IRP_CONTEXT IrpContext, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN ULONG BufferOffset, IN BOOLEAN Wait)
 
NTSTATUS VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject, IN ULONG CtlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, IN OUT PVOID OutputBuffer, IN OUT PULONG pOutputBufferSize, IN BOOLEAN Override)
 
NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatClose (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatCloseFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
 
NTSTATUS VfatCreate (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS FindFile (PDEVICE_EXTENSION DeviceExt, PVFATFCB Parent, PUNICODE_STRING FileToFindU, PVFAT_DIRENTRY_CONTEXT DirContext, BOOLEAN First)
 
VOID vfat8Dot3ToString (PFAT_DIR_ENTRY pEntry, PUNICODE_STRING NameU)
 
NTSTATUS VfatDirectoryControl (PVFAT_IRP_CONTEXT IrpContext)
 
BOOLEAN FsdDosDateTimeToSystemTime (PDEVICE_EXTENSION DeviceExt, USHORT DosDate, USHORT DosTime, PLARGE_INTEGER SystemTime)
 
BOOLEAN FsdSystemTimeToDosDateTime (PDEVICE_EXTENSION DeviceExt, PLARGE_INTEGER SystemTime, USHORT *pDosDate, USHORT *pDosTime)
 
ULONG vfatDirEntryGetFirstCluster (PDEVICE_EXTENSION pDeviceExt, PDIR_ENTRY pDirEntry)
 
NTSTATUS vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
 
NTSTATUS VfatUpdateEntry (IN PDEVICE_EXTENSION DeviceExt, PVFATFCB pFcb)
 
BOOLEAN vfatFindDirSpace (PDEVICE_EXTENSION DeviceExt, PVFATFCB pDirFcb, ULONG nbSlots, PULONG start)
 
NTSTATUS vfatRenameEntry (IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB pFcb, IN PUNICODE_STRING FileName, IN BOOLEAN CaseChangeOnly)
 
NTSTATUS VfatMoveEntry (IN PDEVICE_EXTENSION DeviceExt, IN PVFATFCB pFcb, IN PUNICODE_STRING FileName, IN PVFATFCB ParentFcb)
 
NTSTATUS VfatSetExtendedAttributes (PFILE_OBJECT FileObject, PVOID Ea, ULONG EaLength)
 
VOID VfatInitFastIoRoutines (PFAST_IO_DISPATCH FastIoDispatch)
 
BOOLEAN NTAPI VfatAcquireForLazyWrite (IN PVOID Context, IN BOOLEAN Wait)
 
VOID NTAPI VfatReleaseFromLazyWrite (IN PVOID Context)
 
NTSTATUS FAT12GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
 
NTSTATUS FAT12FindAndMarkAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
 
NTSTATUS FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, ULONG NewValue, PULONG OldValue)
 
NTSTATUS FAT16GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
 
NTSTATUS FAT16FindAndMarkAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
 
NTSTATUS FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, ULONG NewValue, PULONG OldValue)
 
NTSTATUS FAT32GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
 
NTSTATUS FAT32FindAndMarkAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
 
NTSTATUS FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, ULONG NewValue, PULONG OldValue)
 
NTSTATUS OffsetToCluster (PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, ULONG FileOffset, PULONG Cluster, BOOLEAN Extend)
 
ULONGLONG ClusterToSector (PDEVICE_EXTENSION DeviceExt, ULONG Cluster)
 
NTSTATUS GetNextCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
 
NTSTATUS GetNextClusterExtend (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
 
NTSTATUS CountAvailableClusters (PDEVICE_EXTENSION DeviceExt, PLARGE_INTEGER Clusters)
 
NTSTATUS WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, ULONG NewValue)
 
NTSTATUS GetDirtyStatus (PDEVICE_EXTENSION DeviceExt, PBOOLEAN DirtyStatus)
 
NTSTATUS FAT16GetDirtyStatus (PDEVICE_EXTENSION DeviceExt, PBOOLEAN DirtyStatus)
 
NTSTATUS FAT32GetDirtyStatus (PDEVICE_EXTENSION DeviceExt, PBOOLEAN DirtyStatus)
 
NTSTATUS SetDirtyStatus (PDEVICE_EXTENSION DeviceExt, BOOLEAN DirtyStatus)
 
NTSTATUS FAT16SetDirtyStatus (PDEVICE_EXTENSION DeviceExt, BOOLEAN DirtyStatus)
 
NTSTATUS FAT32SetDirtyStatus (PDEVICE_EXTENSION DeviceExt, BOOLEAN DirtyStatus)
 
NTSTATUS FAT32UpdateFreeClustersCount (PDEVICE_EXTENSION DeviceExt)
 
PVFATFCB vfatNewFCB (PDEVICE_EXTENSION pVCB, PUNICODE_STRING pFileNameU)
 
NTSTATUS vfatSetFCBNewDirName (PDEVICE_EXTENSION pVCB, PVFATFCB Fcb, PVFATFCB ParentFcb)
 
NTSTATUS vfatUpdateFCB (PDEVICE_EXTENSION pVCB, PVFATFCB Fcb, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB ParentFcb)
 
VOID vfatDestroyFCB (PVFATFCB pFCB)
 
VOID vfatDestroyCCB (PVFATCCB pCcb)
 
VOID vfatGrabFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
 
VOID vfatReleaseFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
 
PVFATFCB vfatGrabFCBFromTable (PDEVICE_EXTENSION pDeviceExt, PUNICODE_STRING pFileNameU)
 
PVFATFCB vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
 
PVFATFCB vfatOpenRootFCB (PDEVICE_EXTENSION pVCB)
 
BOOLEAN vfatFCBIsRoot (PVFATFCB FCB)
 
NTSTATUS vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb, PVFATFCB fcb, PFILE_OBJECT fileObject)
 
NTSTATUS vfatDirFindFile (PDEVICE_EXTENSION pVCB, PVFATFCB parentFCB, PUNICODE_STRING FileToFindU, PVFATFCB *fileFCB)
 
NTSTATUS vfatGetFCBForFile (PDEVICE_EXTENSION pVCB, PVFATFCB *pParentFCB, PVFATFCB *pFCB, PUNICODE_STRING pFileNameU)
 
NTSTATUS vfatMakeFCBFromDirEntry (PVCB vcb, PVFATFCB directoryFCB, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB *fileFCB)
 
NTSTATUS VfatGetStandardInformation (PVFATFCB FCB, PFILE_STANDARD_INFORMATION StandardInfo, PULONG BufferLength)
 
NTSTATUS VfatGetBasicInformation (PFILE_OBJECT FileObject, PVFATFCB FCB, PDEVICE_EXTENSION DeviceExt, PFILE_BASIC_INFORMATION BasicInfo, PULONG BufferLength)
 
NTSTATUS VfatQueryInformation (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatSetInformation (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatSetAllocationSizeInformation (PFILE_OBJECT FileObject, PVFATFCB Fcb, PDEVICE_EXTENSION DeviceExt, PLARGE_INTEGER AllocationSize)
 
NTSTATUS VfatFlush (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatFlushVolume (PDEVICE_EXTENSION DeviceExt, PVFATFCB VolumeFcb)
 
NTSTATUS VfatFileSystemControl (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
NTSTATUS NTAPI VfatBuildRequest (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
PVOID VfatGetUserBuffer (IN PIRP Irp, IN BOOLEAN Paging)
 
NTSTATUS VfatLockUserBuffer (IN PIRP Irp, IN ULONG Length, IN LOCK_OPERATION Operation)
 
BOOLEAN VfatCheckForDismount (IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Create)
 
VOID NTAPI VfatHandleDeferredWrite (IN PVOID IrpContext, IN PVOID Unused)
 
NTSTATUS VfatPnp (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatRead (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT *pIrpContext)
 
NTSTATUS NextCluster (PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
 
NTSTATUS NTAPI VfatShutdown (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID vfatSplitPathName (PUNICODE_STRING PathNameU, PUNICODE_STRING DirNameU, PUNICODE_STRING FileNameU)
 
BOOLEAN vfatIsLongIllegal (WCHAR c)
 
BOOLEAN IsDotOrDotDot (PCUNICODE_STRING Name)
 
NTSTATUS VfatQueryVolumeInformation (PVFAT_IRP_CONTEXT IrpContext)
 
NTSTATUS VfatSetVolumeInformation (PVFAT_IRP_CONTEXT IrpContext)
 

Variables

PVFAT_GLOBAL_DATA VfatGlobalData
 
DRIVER_DISPATCH VfatBuildRequest
 
DRIVER_DISPATCH VfatShutdown
 

Macro Definition Documentation

◆ BLOCKSIZE

#define BLOCKSIZE   512

Definition at line 232 of file vfat.h.

◆ CCB_DELETE_ON_CLOSE

#define CCB_DELETE_ON_CLOSE   0x0001

Definition at line 534 of file vfat.h.

◆ ENABLE_SWAPOUT

#define ENABLE_SWAPOUT

Definition at line 16 of file vfat.h.

◆ ENTRIES_PER_SECTOR

#define ENTRIES_PER_SECTOR   (BLOCKSIZE / sizeof(FATDirEntry))

Definition at line 557 of file vfat.h.

◆ ENTRY_DELETED

#define ENTRY_DELETED (   IsFatX,
  DirEntry 
)    (IsFatX ? FATX_ENTRY_DELETED(&((DirEntry)->FatX)) : FAT_ENTRY_DELETED(&((DirEntry)->Fat)))

Definition at line 205 of file vfat.h.

◆ ENTRY_END

#define ENTRY_END (   IsFatX,
  DirEntry 
)    (IsFatX ? FATX_ENTRY_END(&((DirEntry)->FatX)) : FAT_ENTRY_END(&((DirEntry)->Fat)))

Definition at line 207 of file vfat.h.

◆ ENTRY_VOLUME

#define ENTRY_VOLUME (   IsFatX,
  DirEntry 
)    (IsFatX ? FATX_ENTRY_VOLUME(&((DirEntry)->FatX)) : FAT_ENTRY_VOLUME(&((DirEntry)->Fat)))

Definition at line 206 of file vfat.h.

◆ FAT12

#define FAT12   (2)

Definition at line 235 of file vfat.h.

◆ FAT16

#define FAT16   (1)

Definition at line 234 of file vfat.h.

◆ FAT32

#define FAT32   (3)

Definition at line 236 of file vfat.h.

◆ FAT_DIRTY_BIT

#define FAT_DIRTY_BIT   0x01

Definition at line 85 of file vfat.h.

◆ FAT_EAFILE

#define FAT_EAFILE   "EA DATA. SF"

Definition at line 132 of file vfat.h.

◆ FAT_ENTRIES_PER_PAGE

#define FAT_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof (FAT_DIR_ENTRY))

Definition at line 219 of file vfat.h.

◆ FAT_ENTRY_DELETED

#define FAT_ENTRY_DELETED (   DirEntry)    ((DirEntry)->Filename[0] == 0xe5)

Definition at line 209 of file vfat.h.

◆ FAT_ENTRY_END

#define FAT_ENTRY_END (   DirEntry)    ((DirEntry)->Filename[0] == 0)

Definition at line 210 of file vfat.h.

◆ FAT_ENTRY_LONG

#define FAT_ENTRY_LONG (   DirEntry)    (((DirEntry)->Attrib & 0x3f) == 0x0f)

Definition at line 211 of file vfat.h.

◆ FAT_ENTRY_VOLUME

#define FAT_ENTRY_VOLUME (   DirEntry)    (((DirEntry)->Attrib & 0x1f) == 0x08)

Definition at line 212 of file vfat.h.

◆ FATX16

#define FATX16   (4)

Definition at line 237 of file vfat.h.

◆ FATX32

#define FATX32   (5)

Definition at line 238 of file vfat.h.

◆ FATX_ENTRIES_PER_PAGE

#define FATX_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof (FATX_DIR_ENTRY))

Definition at line 220 of file vfat.h.

◆ FATX_ENTRY_DELETED

#define FATX_ENTRY_DELETED (   DirEntry)    ((DirEntry)->FilenameLength == 0xe5)

Definition at line 214 of file vfat.h.

◆ FATX_ENTRY_END

#define FATX_ENTRY_END (   DirEntry)    ((DirEntry)->FilenameLength == 0xff)

Definition at line 215 of file vfat.h.

◆ FATX_ENTRY_LONG

#define FATX_ENTRY_LONG (   DirEntry)    (FALSE)

Definition at line 216 of file vfat.h.

◆ FATX_ENTRY_VOLUME

#define FATX_ENTRY_VOLUME (   DirEntry)    (((DirEntry)->Attrib & 0x1f) == 0x08)

Definition at line 217 of file vfat.h.

◆ FCB_CACHE_INITIALIZED

#define FCB_CACHE_INITIALIZED   0x0001

Definition at line 433 of file vfat.h.

◆ FCB_DELAYED_CLOSE

#define FCB_DELAYED_CLOSE   0x0040

Definition at line 439 of file vfat.h.

◆ FCB_DELETE_PENDING

#define FCB_DELETE_PENDING   0x0002

Definition at line 434 of file vfat.h.

◆ FCB_IS_DIRTY

#define FCB_IS_DIRTY   0x0020

Definition at line 438 of file vfat.h.

◆ FCB_IS_FAT

#define FCB_IS_FAT   0x0004

Definition at line 435 of file vfat.h.

◆ FCB_IS_PAGE_FILE

#define FCB_IS_PAGE_FILE   0x0008

Definition at line 436 of file vfat.h.

◆ FCB_IS_VOLUME

#define FCB_IS_VOLUME   0x0010

Definition at line 437 of file vfat.h.

◆ IRPCONTEXT_CANWAIT

#define IRPCONTEXT_CANWAIT   0x0001

Definition at line 575 of file vfat.h.

◆ IRPCONTEXT_COMPLETE

#define IRPCONTEXT_COMPLETE   0x0002

Definition at line 576 of file vfat.h.

◆ IRPCONTEXT_DEFERRED_WRITE

#define IRPCONTEXT_DEFERRED_WRITE   0x0010

Definition at line 579 of file vfat.h.

◆ IRPCONTEXT_PENDINGRETURNED

#define IRPCONTEXT_PENDINGRETURNED   0x0008

Definition at line 578 of file vfat.h.

◆ IRPCONTEXT_QUEUE

#define IRPCONTEXT_QUEUE   0x0004

Definition at line 577 of file vfat.h.

◆ LONGNAME_MAX_LENGTH

#define LONGNAME_MAX_LENGTH   256

Definition at line 203 of file vfat.h.

◆ NODE_TYPE_FCB

#define NODE_TYPE_FCB   ((CSHORT)0x0502)

Definition at line 445 of file vfat.h.

◆ ROUND_DOWN

#define ROUND_DOWN (   n,
  align 
)    (((ULONG)n) & ~((align) - 1l))

Definition at line 25 of file vfat.h.

◆ ROUND_DOWN_64

#define ROUND_DOWN_64 (   n,
  align 
)    (((ULONGLONG)n) & ~((align) - 1LL))

Definition at line 31 of file vfat.h.

◆ ROUND_UP

#define ROUND_UP (   n,
  align 
)    ROUND_DOWN(((ULONG)n) + (align) - 1, (align))

Definition at line 28 of file vfat.h.

◆ ROUND_UP_64

#define ROUND_UP_64 (   n,
  align 
)    ROUND_DOWN_64(((ULONGLONG)n) + (align) - 1LL, (align))

Definition at line 34 of file vfat.h.

◆ STATISTICS_SIZE_NO_PAD

#define STATISTICS_SIZE_NO_PAD   (sizeof(FILESYSTEM_STATISTICS) + sizeof(FAT_STATISTICS))

Definition at line 304 of file vfat.h.

◆ TAG_BUFFER

#define TAG_BUFFER   'OtaF'

Definition at line 551 of file vfat.h.

◆ TAG_CCB

#define TAG_CCB   'CtaF'

Definition at line 546 of file vfat.h.

◆ TAG_CLOSE

#define TAG_CLOSE   'xtaF'

Definition at line 549 of file vfat.h.

◆ TAG_DIRENT

#define TAG_DIRENT   'DtaF'

Definition at line 555 of file vfat.h.

◆ TAG_FCB

#define TAG_FCB   'FtaF'

Definition at line 547 of file vfat.h.

◆ TAG_IRP

#define TAG_IRP   'ItaF'

Definition at line 548 of file vfat.h.

◆ TAG_NAME

#define TAG_NAME   'ntaF'

Definition at line 553 of file vfat.h.

◆ TAG_SEARCH

#define TAG_SEARCH   'LtaF'

Definition at line 554 of file vfat.h.

◆ TAG_STATS

#define TAG_STATS   'VtaF'

Definition at line 550 of file vfat.h.

◆ TAG_VPB

#define TAG_VPB   'vtaF'

Definition at line 552 of file vfat.h.

◆ USE_ROS_CC_AND_FS

#define USE_ROS_CC_AND_FS

Definition at line 15 of file vfat.h.

◆ VCB_CLEAR_DIRTY

#define VCB_CLEAR_DIRTY   0x8000 /* Clean dirty flag at shutdown */

Definition at line 245 of file vfat.h.

◆ VCB_DISMOUNT_PENDING

#define VCB_DISMOUNT_PENDING   0x0002

Definition at line 241 of file vfat.h.

◆ VCB_GOOD

#define VCB_GOOD   0x0010 /* If not set, the VCB is improper for usage */

Definition at line 247 of file vfat.h.

◆ VCB_IS_DIRTY

#define VCB_IS_DIRTY   0x4000 /* Volume is dirty */

Definition at line 244 of file vfat.h.

◆ VCB_IS_FATX

#define VCB_IS_FATX   0x0004

Definition at line 242 of file vfat.h.

◆ VCB_IS_SYS_OR_HAS_PAGE

#define VCB_IS_SYS_OR_HAS_PAGE   0x0008

Definition at line 243 of file vfat.h.

◆ VCB_VOLUME_LOCKED

#define VCB_VOLUME_LOCKED   0x0001

Definition at line 240 of file vfat.h.

◆ VFAT_BREAK_ON_CORRUPTION

#define VFAT_BREAK_ON_CORRUPTION   1

Definition at line 407 of file vfat.h.

◆ VFAT_CASE_LOWER_BASE

#define VFAT_CASE_LOWER_BASE   8

Definition at line 200 of file vfat.h.

◆ VFAT_CASE_LOWER_EXT

#define VFAT_CASE_LOWER_EXT   16

Definition at line 201 of file vfat.h.

◆ vfatAddToStat

#define vfatAddToStat (   Vcb,
  Stat,
  Inc 
)
Value:
{ \
PSTATISTICS Stats = &(Vcb)->Statistics[KeGetCurrentProcessorNumber() % VfatGlobalData->NumberProcessors]; \
Stats->Stat += Inc; \
}
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:337
ULONG NumberProcessors
Definition: vfat.h:414
#define Vcb
Definition: cdprocs.h:1415

Definition at line 671 of file vfat.h.

◆ VOLUME_IS_NOT_CACHED_WORK_AROUND_IT

#define VOLUME_IS_NOT_CACHED_WORK_AROUND_IT

Definition at line 22 of file vfat.h.

Typedef Documentation

◆ BootSector

Definition at line 108 of file vfat.h.

◆ DEVICE_EXTENSION

◆ DIR_ENTRY

typedef union _DIR_ENTRY DIR_ENTRY

Definition at line 230 of file vfat.h.

◆ DOSDATE

◆ DOSTIME

◆ FAT_DIR_ENTRY

Definition at line 167 of file vfat.h.

◆ FAT_EA_FILE_HEADER

Definition at line 134 of file vfat.h.

◆ FAT_EA_HEADER

Definition at line 156 of file vfat.h.

◆ FAT_EA_SET_HEADER

Definition at line 143 of file vfat.h.

◆ FATX_DIR_ENTRY

Definition at line 222 of file vfat.h.

◆ HASHENTRY

◆ PADD_ENTRY

Definition at line 290 of file vfat.h.

◆ PDEL_ENTRY

Definition at line 291 of file vfat.h.

◆ PDEVICE_EXTENSION

Definition at line 283 of file vfat.h.

◆ PDIR_ENTRY

typedef union _DIR_ENTRY * PDIR_ENTRY

Definition at line 230 of file vfat.h.

◆ PDOSDATE

◆ PDOSTIME

◆ PFAT_DIR_ENTRY

Definition at line 167 of file vfat.h.

◆ PFAT_EA_FILE_HEADER

Definition at line 134 of file vfat.h.

◆ PFAT_EA_HEADER

Definition at line 156 of file vfat.h.

◆ PFAT_EA_SET_HEADER

Definition at line 143 of file vfat.h.

◆ PFATINFO

typedef struct FATINFO * PFATINFO

◆ PFATX_DIR_ENTRY

Definition at line 222 of file vfat.h.

◆ PFIND_AND_MARK_AVAILABLE_CLUSTER

typedef NTSTATUS(* PFIND_AND_MARK_AVAILABLE_CLUSTER) (PDEVICE_EXTENSION, PULONG)

Definition at line 286 of file vfat.h.

◆ PGET_DIRTY_STATUS

typedef NTSTATUS(* PGET_DIRTY_STATUS) (PDEVICE_EXTENSION, PBOOLEAN)

Definition at line 293 of file vfat.h.

◆ PGET_NEXT_CLUSTER

typedef NTSTATUS(* PGET_NEXT_CLUSTER) (PDEVICE_EXTENSION, ULONG, PULONG)

Definition at line 285 of file vfat.h.

◆ PGET_NEXT_DIR_ENTRY

typedef NTSTATUS(* PGET_NEXT_DIR_ENTRY) (PVOID *, PVOID *, struct _VFATFCB *, struct _VFAT_DIRENTRY_CONTEXT *, BOOLEAN)

Definition at line 292 of file vfat.h.

◆ PIS_DIRECTORY_EMPTY

typedef BOOLEAN(* PIS_DIRECTORY_EMPTY) (PDEVICE_EXTENSION, struct _VFATFCB *)

Definition at line 289 of file vfat.h.

◆ PSET_DIRTY_STATUS

typedef NTSTATUS(* PSET_DIRTY_STATUS) (PDEVICE_EXTENSION, BOOLEAN)

Definition at line 294 of file vfat.h.

◆ PSTATISTICS

◆ PVCB

◆ PVFAT_CLOSE_CONTEXT

◆ PVFAT_DIRENTRY_CONTEXT

◆ PVFAT_DISPATCH

◆ PVFAT_GLOBAL_DATA

◆ PVFAT_IRP_CONTEXT

◆ PVFAT_MOVE_CONTEXT

◆ PVFATCCB

◆ PVFATFCB

◆ PWRITE_CLUSTER

typedef NTSTATUS(* PWRITE_CLUSTER) (PDEVICE_EXTENSION, ULONG, ULONG, PULONG)

Definition at line 287 of file vfat.h.

◆ slot

typedef struct _slot slot

Definition at line 196 of file vfat.h.

◆ STATISTICS

◆ VCB

◆ VFAT_CLOSE_CONTEXT

◆ VFAT_DIRENTRY_CONTEXT

◆ VFAT_DISPATCH

◆ VFAT_MOVE_CONTEXT

◆ VFATCCB

◆ VFATFCB

Function Documentation

◆ ClusterToSector()

ULONGLONG ClusterToSector ( PDEVICE_EXTENSION  DeviceExt,
ULONG  Cluster 
)

Definition at line 733 of file fat.c.

736 {
737  return DeviceExt->FatInfo.dataStart +
738  ((ULONGLONG)(Cluster - 2) * DeviceExt->FatInfo.SectorsPerCluster);
739 
740 }
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by VfatReadFileData(), and VfatWriteFileData().

◆ CountAvailableClusters()

NTSTATUS CountAvailableClusters ( PDEVICE_EXTENSION  DeviceExt,
PLARGE_INTEGER  Clusters 
)

Definition at line 543 of file fat.c.

546 {
548  ExAcquireResourceExclusiveLite (&DeviceExt->FatResource, TRUE);
549  if (!DeviceExt->AvailableClustersValid)
550  {
551  if (DeviceExt->FatInfo.FatType == FAT12)
552  Status = FAT12CountAvailableClusters(DeviceExt);
553  else if (DeviceExt->FatInfo.FatType == FAT16 || DeviceExt->FatInfo.FatType == FATX16)
554  Status = FAT16CountAvailableClusters(DeviceExt);
555  else
556  Status = FAT32CountAvailableClusters(DeviceExt);
557  }
558  if (Clusters != NULL)
559  {
560  Clusters->QuadPart = DeviceExt->AvailableClusters;
561  }
562  ExReleaseResourceLite (&DeviceExt->FatResource);
563 
564  return Status;
565 }
#define FAT12
Definition: fat.h:167
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
static NTSTATUS FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:437
Status
Definition: gdiplustypes.h:24
static NTSTATUS FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:383
static NTSTATUS FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:492
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define FAT16
Definition: fat.h:168
#define FATX16
Definition: fat.h:170
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by FsdGetFsFullSizeInformation(), FsdGetFsSizeInformation(), and VfatMount().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 16 of file battc.c.

18 {
19  DPRINT("Battery class driver initialized\n");
20 
21  return STATUS_SUCCESS;
22 }
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

◆ FAT12FindAndMarkAvailableCluster()

NTSTATUS FAT12FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 246 of file fat.c.

249 {
250  ULONG FatLength;
251  ULONG StartCluster;
252  ULONG Entry;
253  PUSHORT CBlock;
254  ULONG i, j;
256  PVOID Context;
258 
259  FatLength = DeviceExt->FatInfo.NumberOfClusters + 2;
260  *Cluster = 0;
261  StartCluster = DeviceExt->LastAvailableCluster;
262  Offset.QuadPart = 0;
263  _SEH2_TRY
264  {
265  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
266  }
268  {
269  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector);
271  }
272  _SEH2_END;
273 
274  for (j = 0; j < 2; j++)
275  {
276  for (i = StartCluster; i < FatLength; i++)
277  {
278  CBlock = (PUSHORT)((char*)BaseAddress + (i * 12) / 8);
279  if ((i % 2) == 0)
280  {
281  Entry = *CBlock & 0xfff;
282  }
283  else
284  {
285  Entry = *CBlock >> 4;
286  }
287 
288  if (Entry == 0)
289  {
290  DPRINT("Found available cluster 0x%x\n", i);
291  DeviceExt->LastAvailableCluster = *Cluster = i;
292  if ((i % 2) == 0)
293  *CBlock = (*CBlock & 0xf000) | 0xfff;
294  else
295  *CBlock = (*CBlock & 0xf) | 0xfff0;
298  if (DeviceExt->AvailableClustersValid)
299  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
300  return STATUS_SUCCESS;
301  }
302  }
303  FatLength = StartCluster;
304  StartCluster = 2;
305  }
307  return STATUS_DISK_FULL;
308 }
struct _Entry Entry
Definition: kefuncs.h:627
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
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 GLint GLint j
Definition: glfuncs.h:250
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define InterlockedDecrement
Definition: armddk.h:52
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
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
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define DPRINT
Definition: sndvol32.h:71
signed int * PLONG
Definition: retypes.h:5
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82

Referenced by VfatMount().

◆ FAT12GetNextCluster()

NTSTATUS FAT12GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 125 of file fat.c.

129 {
130  PUSHORT CBlock;
131  ULONG Entry;
133  PVOID Context;
135 
136  *NextCluster = 0;
137 
138  Offset.QuadPart = 0;
139  _SEH2_TRY
140  {
141  CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, MAP_WAIT, &Context, &BaseAddress);
142  }
144  {
146  }
147  _SEH2_END;
148 
149  CBlock = (PUSHORT)((char*)BaseAddress + (CurrentCluster * 12) / 8);
150  if ((CurrentCluster % 2) == 0)
151  {
152  Entry = *CBlock & 0x0fff;
153  }
154  else
155  {
156  Entry = *CBlock >> 4;
157  }
158 
159 // DPRINT("Entry %x\n",Entry);
160  if (Entry >= 0xff8 && Entry <= 0xfff)
161  Entry = 0xffffffff;
162 
163 // DPRINT("Returning %x\n",Entry);
164  ASSERT(Entry != 0);
165  *NextCluster = Entry;
167 // return Entry == 0xffffffff ? STATUS_END_OF_FILE : STATUS_SUCCESS;
168  return STATUS_SUCCESS;
169 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
struct _Entry Entry
Definition: kefuncs.h:627
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
_SEH2_TRY
Definition: create.c:4226
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:44
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82

Referenced by VfatMount().

◆ FAT12WriteCluster()

NTSTATUS FAT12WriteCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  ClusterToWrite,
ULONG  NewValue,
PULONG  OldValue 
)

Definition at line 572 of file fat.c.

577 {
578  ULONG FATOffset;
579  PUCHAR CBlock;
581  PVOID Context;
583 
584  Offset.QuadPart = 0;
585  _SEH2_TRY
586  {
587  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
588  }
590  {
592  }
593  _SEH2_END;
594  CBlock = (PUCHAR)BaseAddress;
595 
596  FATOffset = (ClusterToWrite * 12) / 8;
597  DPRINT("Writing 0x%x for 0x%x at 0x%x\n",
598  NewValue, ClusterToWrite, FATOffset);
599  if ((ClusterToWrite % 2) == 0)
600  {
601  *OldValue = CBlock[FATOffset] + ((CBlock[FATOffset + 1] & 0x0f) << 8);
602  CBlock[FATOffset] = (UCHAR)NewValue;
603  CBlock[FATOffset + 1] &= 0xf0;
604  CBlock[FATOffset + 1] |= (NewValue & 0xf00) >> 8;
605  }
606  else
607  {
608  *OldValue = (CBlock[FATOffset] >> 4) + (CBlock[FATOffset + 1] << 4);
609  CBlock[FATOffset] &= 0x0f;
610  CBlock[FATOffset] |= (NewValue & 0xf) << 4;
611  CBlock[FATOffset + 1] = (UCHAR)(NewValue >> 4);
612  }
613  /* Write the changed FAT sector(s) to disk */
616  return STATUS_SUCCESS;
617 }
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
unsigned char * PUCHAR
Definition: retypes.h:3
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
unsigned char UCHAR
Definition: xmlstorage.h:181
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatMount().

◆ FAT16FindAndMarkAvailableCluster()

NTSTATUS FAT16FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 175 of file fat.c.

178 {
179  ULONG FatLength;
180  ULONG StartCluster;
181  ULONG i, j;
184  PVOID Context = 0;
186  PUSHORT Block;
187  PUSHORT BlockEnd;
188 
189  ChunkSize = CACHEPAGESIZE(DeviceExt);
190  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
191  *Cluster = 0;
192  StartCluster = DeviceExt->LastAvailableCluster;
193 
194  for (j = 0; j < 2; j++)
195  {
196  for (i = StartCluster; i < FatLength;)
197  {
198  Offset.QuadPart = ROUND_DOWN(i * 2, ChunkSize);
199  _SEH2_TRY
200  {
201  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
202  }
204  {
205  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
207  }
208  _SEH2_END;
209 
210  Block = (PUSHORT)((ULONG_PTR)BaseAddress + (i * 2) % ChunkSize);
211  BlockEnd = (PUSHORT)((ULONG_PTR)BaseAddress + ChunkSize);
212 
213  /* Now process the whole block */
214  while (Block < BlockEnd && i < FatLength)
215  {
216  if (*Block == 0)
217  {
218  DPRINT("Found available cluster 0x%x\n", i);
219  DeviceExt->LastAvailableCluster = *Cluster = i;
220  *Block = 0xffff;
223  if (DeviceExt->AvailableClustersValid)
224  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
225  return STATUS_SUCCESS;
226  }
227 
228  Block++;
229  i++;
230  }
231 
233  }
234 
235  FatLength = StartCluster;
236  StartCluster = 2;
237  }
238 
239  return STATUS_DISK_FULL;
240 }
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
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 GLint GLint j
Definition: glfuncs.h:250
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define InterlockedDecrement
Definition: armddk.h:52
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
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
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define DPRINT
Definition: sndvol32.h:71
signed int * PLONG
Definition: retypes.h:5
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VfatMount().

◆ FAT16GetDirtyStatus()

NTSTATUS FAT16GetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
PBOOLEAN  DirtyStatus 
)

Definition at line 860 of file fat.c.

863 {
865  ULONG Length;
866 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
868 #else
869  PVOID Context;
870 #endif
871  struct _BootSector * Sector;
872 
873  /* We'll read the bootsector at 0 */
874  Offset.QuadPart = 0;
875  Length = DeviceExt->FatInfo.BytesPerSector;
876 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
877  /* Go through Cc for this */
878  _SEH2_TRY
879  {
880  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
881  }
883  {
885  }
886  _SEH2_END;
887 #else
888  /* No Cc, do it the old way:
889  * - Allocate a big enough buffer
890  * - And read the disk
891  */
893  if (Sector == NULL)
894  {
895  *DirtyStatus = TRUE;
897  }
898 
899  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
900  if (!NT_SUCCESS(Status))
901  {
902  *DirtyStatus = TRUE;
903  ExFreePoolWithTag(Sector, TAG_BUFFER);
904  return Status;
905  }
906 #endif
907 
908  /* Make sure we have a boot sector...
909  * FIXME: This check is a bit lame and should be improved
910  */
911  if (Sector->Signatur1 != 0xaa55)
912  {
913  /* Set we are dirty so that we don't attempt anything */
914  *DirtyStatus = TRUE;
915 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
917 #else
918  ExFreePoolWithTag(Sector, TAG_BUFFER);
919 #endif
921  }
922 
923  /* Return the status of the dirty bit */
924  if (Sector->Res1 & FAT_DIRTY_BIT)
925  *DirtyStatus = TRUE;
926  else
927  *DirtyStatus = FALSE;
928 
929 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
931 #else
932  ExFreePoolWithTag(Sector, TAG_BUFFER);
933 #endif
934  return STATUS_SUCCESS;
935 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
#define TAG_BUFFER
Definition: vfat.h:551
#define FALSE
Definition: types.h:117
unsigned short Signatur1
Definition: vfat.h:54
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char Res1
Definition: vfat.h:50
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by VfatMount().

◆ FAT16GetNextCluster()

NTSTATUS FAT16GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 79 of file fat.c.

83 {
86  ULONG FATOffset;
88  PVOID Context;
90 
91  ChunkSize = CACHEPAGESIZE(DeviceExt);
92  FATOffset = CurrentCluster * 2;
93  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
94  _SEH2_TRY
95  {
96  CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress);
97  }
99  {
101  }
102  _SEH2_END;
103 
104  CurrentCluster = *((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
105  if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
106  CurrentCluster = 0xffffffff;
107 
108  if (CurrentCluster == 0)
109  {
110  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
113  ASSERT(CurrentCluster != 0);
114  }
115 
117  *NextCluster = CurrentCluster;
118  return Status;
119 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
_SEH2_TRY
Definition: create.c:4226
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:44
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:407
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
ULONG Flags
Definition: vfat.h:413
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VfatMount().

◆ FAT16SetDirtyStatus()

NTSTATUS FAT16SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1046 of file fat.c.

1049 {
1051  ULONG Length;
1052 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1053  NTSTATUS Status;
1054 #else
1055  PVOID Context;
1056 #endif
1057  struct _BootSector * Sector;
1058 
1059  /* We'll read (and then write) the bootsector at 0 */
1060  Offset.QuadPart = 0;
1061  Length = DeviceExt->FatInfo.BytesPerSector;
1062 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1063  /* Go through Cc for this */
1064  _SEH2_TRY
1065  {
1066  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1067  }
1069  {
1071  }
1072  _SEH2_END;
1073 #else
1074  /* No Cc, do it the old way:
1075  * - Allocate a big enough buffer
1076  * - And read the disk
1077  */
1079  if (Sector == NULL)
1080  {
1082  }
1083 
1084  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1085  if (!NT_SUCCESS(Status))
1086  {
1087  ExFreePoolWithTag(Sector, TAG_BUFFER);
1088  return Status;
1089  }
1090 #endif
1091 
1092  /* Make sure we have a boot sector...
1093  * FIXME: This check is a bit lame and should be improved
1094  */
1095  if (Sector->Signatur1 != 0xaa55)
1096  {
1097 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1099 #else
1100  ExFreePoolWithTag(Sector, TAG_BUFFER);
1101 #endif
1103  }
1104 
1105  /* Modify the dirty bit status according
1106  * to caller needs
1107  */
1108  if (!DirtyStatus)
1109  {
1110  Sector->Res1 &= ~FAT_DIRTY_BIT;
1111  }
1112  else
1113  {
1114  Sector->Res1 |= FAT_DIRTY_BIT;
1115  }
1116 
1117 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1118  /* Mark boot sector dirty so that it gets written to the disk */
1121  return STATUS_SUCCESS;
1122 #else
1123  /* Write back the boot sector to the disk */
1124  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1125  ExFreePoolWithTag(Sector, TAG_BUFFER);
1126  return Status;
1127 #endif
1128 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
#define TAG_BUFFER
Definition: vfat.h:551
#define FALSE
Definition: types.h:117
unsigned short Signatur1
Definition: vfat.h:54
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:255
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char Res1
Definition: vfat.h:50
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by VfatMount().

◆ FAT16WriteCluster()

NTSTATUS FAT16WriteCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  ClusterToWrite,
ULONG  NewValue,
PULONG  OldValue 
)

Definition at line 623 of file fat.c.

628 {
630  ULONG FATOffset;
632  PVOID Context;
634  PUSHORT Cluster;
635 
636  ChunkSize = CACHEPAGESIZE(DeviceExt);
637  FATOffset = ClusterToWrite * 2;
638  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
639  _SEH2_TRY
640  {
641  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
642  }
644  {
646  }
647  _SEH2_END;
648 
649  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
650  ClusterToWrite);
651  Cluster = ((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
652  *OldValue = *Cluster;
653  *Cluster = (USHORT)NewValue;
656  return STATUS_SUCCESS;
657 }
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define DPRINT
Definition: sndvol32.h:71
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VfatMount().

◆ FAT32FindAndMarkAvailableCluster()

NTSTATUS FAT32FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 314 of file fat.c.

317 {
318  ULONG FatLength;
319  ULONG StartCluster;
320  ULONG i, j;
323  PVOID Context;
325  PULONG Block;
326  PULONG BlockEnd;
327 
328  ChunkSize = CACHEPAGESIZE(DeviceExt);
329  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
330  *Cluster = 0;
331  StartCluster = DeviceExt->LastAvailableCluster;
332 
333  for (j = 0; j < 2; j++)
334  {
335  for (i = StartCluster; i < FatLength;)
336  {
337  Offset.QuadPart = ROUND_DOWN(i * 4, ChunkSize);
338  _SEH2_TRY
339  {
340  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
341  }
343  {
344  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
346  }
347  _SEH2_END;
348  Block = (PULONG)((ULONG_PTR)BaseAddress + (i * 4) % ChunkSize);
349  BlockEnd = (PULONG)((ULONG_PTR)BaseAddress + ChunkSize);
350 
351  /* Now process the whole block */
352  while (Block < BlockEnd && i < FatLength)
353  {
354  if ((*Block & 0x0fffffff) == 0)
355  {
356  DPRINT("Found available cluster 0x%x\n", i);
357  DeviceExt->LastAvailableCluster = *Cluster = i;
358  *Block = 0x0fffffff;
361  if (DeviceExt->AvailableClustersValid)
362  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
363  return STATUS_SUCCESS;
364  }
365 
366  Block++;
367  i++;
368  }
369 
371  }
372  FatLength = StartCluster;
373  StartCluster = 2;
374  }
375  return STATUS_DISK_FULL;
376 }
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
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 GLint GLint j
Definition: glfuncs.h:250
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define InterlockedDecrement
Definition: armddk.h:52
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
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
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define DPRINT
Definition: sndvol32.h:71
signed int * PLONG
Definition: retypes.h:5

Referenced by VfatMount().

◆ FAT32GetDirtyStatus()

NTSTATUS FAT32GetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
PBOOLEAN  DirtyStatus 
)

Definition at line 938 of file fat.c.

941 {
943  ULONG Length;
944 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
946 #else
947  PVOID Context;
948 #endif
949  struct _BootSector32 * Sector;
950 
951  /* We'll read the bootsector at 0 */
952  Offset.QuadPart = 0;
953  Length = DeviceExt->FatInfo.BytesPerSector;
954 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
955  /* Go through Cc for this */
956  _SEH2_TRY
957  {
958  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
959  }
961  {
963  }
964  _SEH2_END;
965 #else
966  /* No Cc, do it the old way:
967  * - Allocate a big enough buffer
968  * - And read the disk
969  */
971  if (Sector == NULL)
972  {
973  *DirtyStatus = TRUE;
975  }
976 
977  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
978  if (!NT_SUCCESS(Status))
979  {
980  *DirtyStatus = TRUE;
981  ExFreePoolWithTag(Sector, TAG_BUFFER);
982  return Status;
983  }
984 #endif
985 
986  /* Make sure we have a boot sector...
987  * FIXME: This check is a bit lame and should be improved
988  */
989  if (Sector->Signature1 != 0xaa55)
990  {
991  /* Set we are dirty so that we don't attempt anything */
992  *DirtyStatus = TRUE;
993 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
995 #else
996  ExFreePoolWithTag(Sector, TAG_BUFFER);
997 #endif
999  }
1000 
1001  /* Return the status of the dirty bit */
1002  if (Sector->Res4 & FAT_DIRTY_BIT)
1003  *DirtyStatus = TRUE;
1004  else
1005  *DirtyStatus = FALSE;
1006 
1007 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1009 #else
1010  ExFreePoolWithTag(Sector, TAG_BUFFER);
1011 #endif
1012  return STATUS_SUCCESS;
1013 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char Res4
Definition: vfat.h:77
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
#define TAG_BUFFER
Definition: vfat.h:551
#define FALSE
Definition: types.h:117
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
unsigned short Signature1
Definition: vfat.h:82

Referenced by VfatMount().

◆ FAT32GetNextCluster()

NTSTATUS FAT32GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 30 of file fat.c.

34 {
37  ULONG FATOffset;
39  PVOID Context = NULL;
41 
42  ChunkSize = CACHEPAGESIZE(DeviceExt);
43  FATOffset = CurrentCluster * sizeof(ULONG);
44  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
45  _SEH2_TRY
46  {
47  if (!CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress))
48  {
50  return STATUS_UNSUCCESSFUL;
51  }
52  }
54  {
56  }
57  _SEH2_END;
58 
59  CurrentCluster = (*(PULONG)((char*)BaseAddress + (FATOffset % ChunkSize))) & 0x0fffffff;
60  if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
61  CurrentCluster = 0xffffffff;
62 
63  if (CurrentCluster == 0)
64  {
65  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
68  ASSERT(CurrentCluster != 0);
69  }
71  *NextCluster = CurrentCluster;
72  return Status;
73 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
_SEH2_TRY
Definition: create.c:4226
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
#define FALSE
Definition: types.h:117
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:44
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:407
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
ULONG Flags
Definition: vfat.h:413
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by VfatMount().

◆ FAT32SetDirtyStatus()

NTSTATUS FAT32SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1131 of file fat.c.

1134 {
1136  ULONG Length;
1137 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1138  NTSTATUS Status;
1139 #else
1140  PVOID Context;
1141 #endif
1142  struct _BootSector32 * Sector;
1143 
1144  /* We'll read (and then write) the bootsector at 0 */
1145  Offset.QuadPart = 0;
1146  Length = DeviceExt->FatInfo.BytesPerSector;
1147 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1148  /* Go through Cc for this */
1149  _SEH2_TRY
1150  {
1151  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1152  }
1154  {
1156  }
1157  _SEH2_END;
1158 #else
1159  /* No Cc, do it the old way:
1160  * - Allocate a big enough buffer
1161  * - And read the disk
1162  */
1164  if (Sector == NULL)
1165  {
1167  }
1168 
1169  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1170  if (!NT_SUCCESS(Status))
1171  {
1172  ExFreePoolWithTag(Sector, TAG_BUFFER);
1173  return Status;
1174  }
1175 #endif
1176 
1177  /* Make sure we have a boot sector...
1178  * FIXME: This check is a bit lame and should be improved
1179  */
1180  if (Sector->Signature1 != 0xaa55)
1181  {
1182  ASSERT(FALSE);
1183 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1185 #else
1186  ExFreePoolWithTag(Sector, TAG_BUFFER);
1187 #endif
1189  }
1190 
1191  /* Modify the dirty bit status according
1192  * to caller needs
1193  */
1194  if (!DirtyStatus)
1195  {
1196  Sector->Res4 &= ~FAT_DIRTY_BIT;
1197  }
1198  else
1199  {
1200  Sector->Res4 |= FAT_DIRTY_BIT;
1201  }
1202 
1203 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1204  /* Mark boot sector dirty so that it gets written to the disk */
1207  return STATUS_SUCCESS;
1208 #else
1209  /* Write back the boot sector to the disk */
1210  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1211  ExFreePoolWithTag(Sector, TAG_BUFFER);
1212  return Status;
1213 #endif
1214 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char Res4
Definition: vfat.h:77
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
#define TAG_BUFFER
Definition: vfat.h:551
#define FALSE
Definition: types.h:117
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:255
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
unsigned short Signature1
Definition: vfat.h:82

Referenced by VfatMount().

◆ FAT32UpdateFreeClustersCount()

NTSTATUS FAT32UpdateFreeClustersCount ( PDEVICE_EXTENSION  DeviceExt)

Definition at line 1217 of file fat.c.

1219 {
1221  ULONG Length;
1222 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1223  NTSTATUS Status;
1224 #else
1225  PVOID Context;
1226 #endif
1227  struct _FsInfoSector * Sector;
1228 
1229  if (!DeviceExt->AvailableClustersValid)
1230  {
1231  return STATUS_INVALID_PARAMETER;
1232  }
1233 
1234  /* We'll read (and then write) the fsinfo sector */
1235  Offset.QuadPart = DeviceExt->FatInfo.FSInfoSector * DeviceExt->FatInfo.BytesPerSector;
1236  Length = DeviceExt->FatInfo.BytesPerSector;
1237 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1238  /* Go through Cc for this */
1239  _SEH2_TRY
1240  {
1241  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1242  }
1244  {
1246  }
1247  _SEH2_END;
1248 #else
1249  /* No Cc, do it the old way:
1250  * - Allocate a big enough buffer
1251  * - And read the disk
1252  */
1254  if (Sector == NULL)
1255  {
1257  }
1258 
1259  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1260  if (!NT_SUCCESS(Status))
1261  {
1262  ExFreePoolWithTag(Sector, TAG_BUFFER);
1263  return Status;
1264  }
1265 #endif
1266 
1267  /* Make sure we have a FSINFO sector */
1268  if (Sector->ExtBootSignature2 != 0x41615252 ||
1269  Sector->FSINFOSignature != 0x61417272 ||
1270  Sector->Signatur2 != 0xaa550000)
1271  {
1272  ASSERT(FALSE);
1273 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1275 #else
1276  ExFreePoolWithTag(Sector, TAG_BUFFER);
1277 #endif
1279  }
1280 
1281  /* Update the free clusters count */
1282  Sector->FreeCluster = InterlockedCompareExchange((PLONG)&DeviceExt->AvailableClusters, 0, 0);
1283 
1284 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1285  /* Mark FSINFO sector dirty so that it gets written to the disk */
1288  return STATUS_SUCCESS;
1289 #else
1290  /* Write back the FSINFO sector to the disk */
1291  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1292  ExFreePoolWithTag(Sector, TAG_BUFFER);
1293  return Status;
1294 #endif
1295 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define PIN_WAIT
unsigned long Signatur2
Definition: vfat.h:105
_SEH2_TRY
Definition: create.c:4226
#define TAG_BUFFER
Definition: vfat.h:551
#define FALSE
Definition: types.h:117
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:255
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned long FSINFOSignature
Definition: vfat.h:101
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_SEH2_END
Definition: create.c:4400
unsigned long FreeCluster
Definition: vfat.h:102
unsigned long ExtBootSignature2
Definition: vfat.h:99
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
signed int * PLONG
Definition: retypes.h:5

Referenced by FATAddEntry(), FATDelEntry(), and VfatSetAllocationSizeInformation().

◆ FAT32WriteCluster()

NTSTATUS FAT32WriteCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  ClusterToWrite,
ULONG  NewValue,
PULONG  OldValue 
)

Definition at line 663 of file fat.c.

668 {
670  ULONG FATOffset;
672  PVOID Context;
674  PULONG Cluster;
675 
676  ChunkSize = CACHEPAGESIZE(DeviceExt);
677 
678  FATOffset = (ClusterToWrite * 4);
679  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
680  _SEH2_TRY
681  {
682  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
683  }
685  {
687  }
688  _SEH2_END;
689 
690  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
691  ClusterToWrite);
692  Cluster = ((PULONG)((char*)BaseAddress + (FATOffset % ChunkSize)));
693  *OldValue = *Cluster & 0x0fffffff;
694  *Cluster = (*Cluster & 0xf0000000) | (NewValue & 0x0fffffff);
695 
698 
699  return STATUS_SUCCESS;
700 }
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define PIN_WAIT
_SEH2_TRY
Definition: create.c:4226
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2274
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatMount().

◆ FindFile()

NTSTATUS FindFile ( PDEVICE_EXTENSION  DeviceExt,
PVFATFCB  Parent,
PUNICODE_STRING  FileToFindU,
PVFAT_DIRENTRY_CONTEXT  DirContext,
BOOLEAN  First 
)

Definition at line 101 of file create.c.

107 {
108  PWCHAR PathNameBuffer;
109  USHORT PathNameBufferLength;
111  PVOID Context = NULL;
112  PVOID Page;
113  PVFATFCB rcFcb;
114  BOOLEAN Found;
115  UNICODE_STRING PathNameU;
116  UNICODE_STRING FileToFindUpcase;
117  BOOLEAN WildCard;
118  BOOLEAN IsFatX = vfatVolumeIsFatX(DeviceExt);
119 
120  DPRINT("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
121  Parent, FileToFindU, DirContext->DirIndex);
122  DPRINT("FindFile: Path %wZ\n",&Parent->PathNameU);
123 
124  PathNameBufferLength = LONGNAME_MAX_LENGTH * sizeof(WCHAR);
125  PathNameBuffer = ExAllocatePoolWithTag(NonPagedPool, PathNameBufferLength + sizeof(WCHAR), TAG_NAME);
126  if (!PathNameBuffer)
127  {
129  }
130 
131  PathNameU.Buffer = PathNameBuffer;
132  PathNameU.Length = 0;
133  PathNameU.MaximumLength = PathNameBufferLength;
134 
135  DirContext->LongNameU.Length = 0;
136  DirContext->ShortNameU.Length = 0;
137 
138  WildCard = FsRtlDoesNameContainWildCards(FileToFindU);
139 
140  if (WildCard == FALSE)
141  {
142  /* if there is no '*?' in the search name, than look first for an existing fcb */
143  RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
144  if (!vfatFCBIsRoot(Parent))
145  {
146  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
147  PathNameU.Length += sizeof(WCHAR);
148  }
149  RtlAppendUnicodeStringToString(&PathNameU, FileToFindU);
150  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
151  rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
152  if (rcFcb)
153  {
154  ULONG startIndex = rcFcb->startIndex;
155  if (IsFatX && !vfatFCBIsRoot(Parent))
156  {
157  startIndex += 2;
158  }
159  if(startIndex >= DirContext->DirIndex)
160  {
161  RtlCopyUnicodeString(&DirContext->LongNameU, &rcFcb->LongNameU);
162  RtlCopyUnicodeString(&DirContext->ShortNameU, &rcFcb->ShortNameU);
163  RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
164  DirContext->StartIndex = rcFcb->startIndex;
165  DirContext->DirIndex = rcFcb->dirIndex;
166  DPRINT("FindFile: new Name %wZ, DirIndex %u (%u)\n",
167  &DirContext->LongNameU, DirContext->DirIndex, DirContext->StartIndex);
169  }
170  else
171  {
172  DPRINT("FCB not found for %wZ\n", &PathNameU);
174  }
175  vfatReleaseFCB(DeviceExt, rcFcb);
176  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
177  return Status;
178  }
179  }
180 
181  /* FsRtlIsNameInExpression need the searched string to be upcase,
182  * even if IgnoreCase is specified */
183  Status = RtlUpcaseUnicodeString(&FileToFindUpcase, FileToFindU, TRUE);
184  if (!NT_SUCCESS(Status))
185  {
186  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
187  return Status;
188  }
189 
190  while (TRUE)
191  {
193  First = FALSE;
195  {
196  break;
197  }
198  if (ENTRY_VOLUME(IsFatX, &DirContext->DirEntry))
199  {
200  DirContext->DirIndex++;
201  continue;
202  }
203  if (DirContext->LongNameU.Length == 0 ||
204  DirContext->ShortNameU.Length == 0)
205  {
206  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
208  {
209  ASSERT(DirContext->LongNameU.Length != 0 &&
210  DirContext->ShortNameU.Length != 0);
211  }
212  DirContext->DirIndex++;
213  continue;
214  }
215  if (WildCard)
216  {
217  Found = FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->LongNameU, TRUE, NULL) ||
218  FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->ShortNameU, TRUE, NULL);
219  }
220  else
221  {
222  Found = FsRtlAreNamesEqual(&DirContext->LongNameU, FileToFindU, TRUE, NULL) ||
223  FsRtlAreNamesEqual(&DirContext->ShortNameU, FileToFindU, TRUE, NULL);
224  }
225 
226  if (Found)
227  {
228  if (WildCard)
229  {
230  RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
231  if (!vfatFCBIsRoot(Parent))
232  {
233  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
234  PathNameU.Length += sizeof(WCHAR);
235  }
236  RtlAppendUnicodeStringToString(&PathNameU, &DirContext->LongNameU);
237  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
238  rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
239  if (rcFcb != NULL)
240  {
241  RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
242  vfatReleaseFCB(DeviceExt, rcFcb);
243  }
244  }
245  DPRINT("%u\n", DirContext->LongNameU.Length);
246  DPRINT("FindFile: new Name %wZ, DirIndex %u\n",
247  &DirContext->LongNameU, DirContext->DirIndex);
248 
249  if (Context)
250  {
252  }
253  RtlFreeUnicodeString(&FileToFindUpcase);
254  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
255  return STATUS_SUCCESS;
256  }
257  DirContext->DirIndex++;
258  }
259 
260  if (Context)
261  {
263  }
264 
265  RtlFreeUnicodeString(&FileToFindUpcase);
266  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
267  return Status;
268 }
#define TAG_NAME
Definition: vfat.h:553
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
UNICODE_STRING ShortNameU
Definition: vfat.h:466
Definition: vfat.h:447
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG dirIndex
Definition: vfat.h:502
Iosb Status
Definition: create.c:4287
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
ULONG DirIndex
Definition: ntfs.h:533
UNICODE_STRING LongNameU
Definition: vfat.h:463
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
Definition: fcb.c:294
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:728
uint16_t * PWCHAR
Definition: typedefs.h:56
BOOLEAN NTAPI FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name)
Definition: name.c:464
BOOLEAN NTAPI FsRtlIsNameInExpression(IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
Definition: name.c:514
#define ENTRY_VOLUME(IsFatX, DirEntry)
Definition: vfat.h:206
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
WCHAR First[]
Definition: FormatMessage.c:11
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
PFN_NUMBER Page
Definition: section.c:4923
return Found
Definition: dirsup.c:1270
ULONG startIndex
Definition: vfat.h:505
Status
Definition: gdiplustypes.h:24
FORCEINLINE BOOLEAN vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt)
Definition: vfat.h:651
BOOLEAN NTAPI FsRtlAreNamesEqual(IN PCUNICODE_STRING Name1, IN PCUNICODE_STRING Name2, IN BOOLEAN IgnoreCase, IN PCWCH UpcaseTable OPTIONAL)
Definition: name.c:296
#define ASSERT(a)
Definition: mode.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT DirContext
Definition: cdprocs.h:424
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
PVFATFCB vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
Definition: fcb.c:594
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
FORCEINLINE NTSTATUS VfatGetNextDirEntry(PDEVICE_EXTENSION DeviceExt, PVOID *pContext, PVOID *pPage, struct _VFATFCB *pDirFcb, struct _VFAT_DIRENTRY_CONTEXT *DirContext, BOOLEAN First)
Definition: vfat.h:397
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:407
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
DIR_ENTRY entry
Definition: vfat.h:457
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
Definition: vfat.h:224
#define NULL
Definition: types.h:112
ULONG Flags
Definition: vfat.h:413
#define DPRINT1
Definition: precomp.h:8
#define LONGNAME_MAX_LENGTH
Definition: vfat.h:203
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
Definition: fcb.c:336
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

◆ FsdDosDateTimeToSystemTime()

BOOLEAN FsdDosDateTimeToSystemTime ( PDEVICE_EXTENSION  DeviceExt,
USHORT  DosDate,
USHORT  DosTime,
PLARGE_INTEGER  SystemTime 
)

Definition at line 22 of file dir.c.

27 {
28  PDOSTIME pdtime = (PDOSTIME)&DosTime;
29  PDOSDATE pddate = (PDOSDATE)&DosDate;
31  LARGE_INTEGER LocalTime;
32 
33  if (SystemTime == NULL)
34  return FALSE;
35 
37  TimeFields.Second = pdtime->Second * 2;
38  TimeFields.Minute = pdtime->Minute;
39  TimeFields.Hour = pdtime->Hour;
40 
41  TimeFields.Day = pddate->Day;
42  TimeFields.Month = pddate->Month;
43  TimeFields.Year = (CSHORT)(DeviceExt->BaseDateYear + pddate->Year);
44 
45  RtlTimeFieldsToTime(&TimeFields, &LocalTime);
46  ExLocalTimeToSystemTime(&LocalTime, SystemTime);
47 
48  return TRUE;
49 }
WORD Month
Definition: cabinet.c:40
#define TRUE
Definition: types.h:120
WORD Year
Definition: cabinet.c:41
WORD Second
Definition: cabinet.c:32
struct _DOSDATE * PDOSDATE
WORD Minute
Definition: cabinet.c:33
struct _DOSTIME * PDOSTIME
#define FALSE
Definition: types.h:117
WORD Hour
Definition: cabinet.c:34
USHORT Milliseconds
Definition: env_spec_w32.h:717
#define ExLocalTimeToSystemTime(LocTime, SysTime)
Definition: env_spec_w32.h:738
#define NULL
Definition: types.h:112
WORD Day
Definition: cabinet.c:39
BOOLEAN RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields, IN PLARGE_INTEGER Time)
static PTIME_FIELDS TimeFields
Definition: time.c:104
short CSHORT
Definition: umtypes.h:127

Referenced by FsdGetFsVolumeInformation(), VfatGetBasicInformation(), VfatGetFileBothInformation(), VfatGetFileDirectoryInformation(), VfatGetFileFullDirectoryInformation(), and VfatGetNetworkOpenInformation().

◆ FsdSystemTimeToDosDateTime()

BOOLEAN FsdSystemTimeToDosDateTime ( PDEVICE_EXTENSION  DeviceExt,
PLARGE_INTEGER  SystemTime,
USHORT pDosDate,
USHORT pDosTime 
)

Definition at line 53 of file dir.c.

58 {
59  PDOSTIME pdtime = (PDOSTIME)pDosTime;
60  PDOSDATE pddate = (PDOSDATE)pDosDate;
62  LARGE_INTEGER LocalTime;
63 
64  if (SystemTime == NULL)
65  return FALSE;
66 
67  ExSystemTimeToLocalTime(SystemTime, &LocalTime);
68  RtlTimeToTimeFields(&LocalTime, &TimeFields);
69 
70  if (pdtime)
71  {
72  pdtime->Second = TimeFields.Second / 2;
73  pdtime->Minute = TimeFields.Minute;
74  pdtime->Hour = TimeFields.Hour;
75  }
76 
77  if (pddate)
78  {
79  pddate->Day = TimeFields.Day;
80  pddate->Month = TimeFields.Month;
81  pddate->Year = (USHORT) (TimeFields.Year - DeviceExt->BaseDateYear);
82  }
83 
84  return TRUE;
85 }
WORD Month
Definition: cabinet.c:40
#define TRUE
Definition: types.h:120
WORD Year
Definition: cabinet.c:41
WORD Second
Definition: cabinet.c:32
struct _DOSDATE * PDOSDATE
WORD Minute
Definition: cabinet.c:33
struct _DOSTIME * PDOSTIME
#define FALSE
Definition: types.h:117
WORD Hour
Definition: cabinet.c:34
#define ExSystemTimeToLocalTime(SysTime, LocTime)
Definition: env_spec_w32.h:729
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
WORD Day
Definition: cabinet.c:39
static PTIME_FIELDS TimeFields
Definition: time.c:104

Referenced by FATAddEntry(), FATXAddEntry(), VfatCreateFile(), VfatSetBasicInformation(), and VfatWrite().

◆ GetDirtyStatus()

NTSTATUS GetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
PBOOLEAN  DirtyStatus 
)

Definition at line 833 of file fat.c.

836 {
838 
839  DPRINT("GetDirtyStatus(DeviceExt %p)\n", DeviceExt);
840 
841  /* FAT12 has no dirty bit */
842  if (DeviceExt->FatInfo.FatType == FAT12)
843  {
844  *DirtyStatus = FALSE;
845  return STATUS_SUCCESS;
846  }
847 
848  /* Not really in the FAT, but share the lock because
849  * we're really low-level and shouldn't happent that often
850  * And call the appropriate function
851  */
852  ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
853  Status = DeviceExt->GetDirtyStatus(DeviceExt, DirtyStatus);
854  ExReleaseResourceLite(&DeviceExt->FatResource);
855 
856  return Status;
857 }
#define FAT12
Definition: fat.h:167
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatMount().

◆ GetNextCluster()

NTSTATUS GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 746 of file fat.c.

750 {
752 
753  DPRINT("GetNextCluster(DeviceExt %p, CurrentCluster %x)\n",
754  DeviceExt, CurrentCluster);
755 
756  if (CurrentCluster == 0)
757  {
758  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
760  ASSERT(CurrentCluster != 0);
762  }
763 
764  ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
765  Status = DeviceExt->GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
766  ExReleaseResourceLite(&DeviceExt->FatResource);
767 
768  return Status;
769 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:407
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
ULONG Flags
Definition: vfat.h:413
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define DPRINT1
Definition: precomp.h:8
#define DPRINT
Definition: sndvol32.h:71

Referenced by FATDelEntry(), FATXDelEntry(), NextCluster(), and OffsetToCluster().

◆ GetNextClusterExtend()

NTSTATUS GetNextClusterExtend ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 775 of file fat.c.

779 {
780  ULONG NewCluster;
782 
783  DPRINT("GetNextClusterExtend(DeviceExt %p, CurrentCluster %x)\n",
784  DeviceExt, CurrentCluster);
785 
786  ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
787  /*
788  * If the file hasn't any clusters allocated then we need special
789  * handling
790  */
791  if (CurrentCluster == 0)
792  {
793  Status = DeviceExt->FindAndMarkAvailableCluster(DeviceExt, &NewCluster);
794  if (!NT_SUCCESS(Status))
795  {
796  ExReleaseResourceLite(&DeviceExt->FatResource);
797  return Status;
798  }
799 
800  *NextCluster = NewCluster;
801  ExReleaseResourceLite(&DeviceExt->FatResource);
802  return STATUS_SUCCESS;
803  }
804 
805  Status = DeviceExt->GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
806 
807  if ((*NextCluster) == 0xFFFFFFFF)
808  {
809  /* We are after last existing cluster, we must add one to file */
810  /* Firstly, find the next available open allocation unit and
811  mark it as end of file */
812  Status = DeviceExt->FindAndMarkAvailableCluster(DeviceExt, &NewCluster);
813  if (!NT_SUCCESS(Status))
814  {
815  ExReleaseResourceLite(&DeviceExt->FatResource);
816  return Status;
817  }
818 
819  /* Now, write the AU of the LastCluster with the value of the newly
820  found AU */
821  WriteCluster(DeviceExt, CurrentCluster, NewCluster);
822  *NextCluster = NewCluster;
823  }
824 
825  ExReleaseResourceLite(&DeviceExt->FatResource);
826  return Status;
827 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
NTSTATUS WriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, ULONG NewValue)
Definition: fat.c:707
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by NextCluster(), and OffsetToCluster().

◆ IsDotOrDotDot()

BOOLEAN IsDotOrDotDot ( PCUNICODE_STRING  Name)

Definition at line 30 of file string.c.

31 {
32  return ((Name->Length == sizeof(WCHAR) && Name->Buffer[0] == L'.') ||
33  (Name->Length == 2 * sizeof(WCHAR) && Name->Buffer[0] == L'.' && Name->Buffer[1] == L'.'));
34 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250

Referenced by VfatCreateFile(), VfatOpenFile(), VfatSetDispositionInformation(), and VfatSetRenameInformation().

◆ NextCluster()

NTSTATUS NextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  FirstCluster,
PULONG  CurrentCluster,
BOOLEAN  Extend 
)

Definition at line 40 of file rw.c.

45 {
46  if (FirstCluster == 1)
47  {
48  (*CurrentCluster) += DeviceExt->FatInfo.SectorsPerCluster;
49  return STATUS_SUCCESS;
50  }
51  else
52  {
53  if (Extend)
54  return GetNextClusterExtend(DeviceExt, (*CurrentCluster), CurrentCluster);
55  else
56  return GetNextCluster(DeviceExt, (*CurrentCluster), CurrentCluster);
57  }
58 }
VOID NTAPI Extend(VOID)
Definition: extend.c:14
NTSTATUS GetNextClusterExtend(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:775
NTSTATUS GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:746
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by FAT12GetNextCluster(), FAT16GetNextCluster(), FAT32GetNextCluster(), FATAddEntry(), FATDelEntry(), FATXDelEntry(), GetNextCluster(), GetNextClusterExtend(), VfatGetRetrievalPointers(), vfatInitFCBFromDirEntry(), vfatMakeRootFCB(), VfatReadFileData(), VfatSetAllocationSizeInformation(), and VfatWriteFileData().

◆ OffsetToCluster()

NTSTATUS OffsetToCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  FirstCluster,
ULONG  FileOffset,
PULONG  Cluster,
BOOLEAN  Extend 
)

Definition at line 61 of file rw.c.

67 {
68  ULONG CurrentCluster;
69  ULONG i;
71 /*
72  DPRINT("OffsetToCluster(DeviceExt %x, Fcb %x, FirstCluster %x,"
73  " FileOffset %x, Cluster %x, Extend %d)\n", DeviceExt,
74  Fcb, FirstCluster, FileOffset, Cluster, Extend);
75 */
76  if (FirstCluster == 0)
77  {
78  DbgPrint("OffsetToCluster is called with FirstCluster = 0!\n");
79  ASSERT(FALSE);
80  }
81 
82  if (FirstCluster == 1)
83  {
84  /* root of FAT16 or FAT12 */
85  *Cluster = DeviceExt->FatInfo.rootStart + FileOffset
86  / (DeviceExt->FatInfo.BytesPerCluster) * DeviceExt->FatInfo.SectorsPerCluster;
87  return STATUS_SUCCESS;
88  }
89  else
90  {
91  CurrentCluster = FirstCluster;
92  if (Extend)
93  {
94  for (i = 0; i < FileOffset / DeviceExt->FatInfo.BytesPerCluster; i++)
95  {
96  Status = GetNextClusterExtend (DeviceExt, CurrentCluster, &CurrentCluster);
97  if (!NT_SUCCESS(Status))
98  return Status;
99  }
100  *Cluster = CurrentCluster;
101  }
102  else
103  {
104  for (i = 0; i < FileOffset / DeviceExt->FatInfo.BytesPerCluster; i++)
105  {
106  Status = GetNextCluster (DeviceExt, CurrentCluster, &CurrentCluster);
107  if (!NT_SUCCESS(Status))
108  return Status;
109  }
110  *Cluster = CurrentCluster;
111  }
112  return STATUS_SUCCESS;
113  }
114 }
VOID NTAPI Extend(VOID)
Definition: extend.c:14
#define DbgPrint
Definition: hal.h:12
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
NTSTATUS GetNextClusterExtend(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:775
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:746
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
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by VfatGetRetrievalPointers(), VfatReadFileData(), VfatSetAllocationSizeInformation(), and VfatWriteFileData().

◆ SetDirtyStatus()

NTSTATUS SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1019 of file fat.c.

1022 {
1023  NTSTATUS Status;
1024 
1025  DPRINT("SetDirtyStatus(DeviceExt %p, DirtyStatus %d)\n", DeviceExt, DirtyStatus);
1026 
1027  /* FAT12 has no dirty bit */
1028  if (DeviceExt->FatInfo.FatType == FAT12)
1029  {
1030  return STATUS_SUCCESS;
1031  }
1032 
1033  /* Not really in the FAT, but share the lock because
1034  * we're really low-level and shouldn't happent that often
1035  * And call the appropriate function
1036  * Acquire exclusive because we will modify ondisk value
1037  */
1038  ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
1039  Status = DeviceExt->SetDirtyStatus(DeviceExt, DirtyStatus);
1040  ExReleaseResourceLite(&DeviceExt->FatResource);
1041 
1042  return Status;
1043 }
#define FAT12
Definition: fat.h:167
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatDismountVolume(), VfatLockOrUnlockVolume(), VfatMarkVolumeDirty(), VfatMount(), and VfatShutdown().

◆ vfat8Dot3ToString()

VOID vfat8Dot3ToString ( PFAT_DIR_ENTRY  pEntry,
PUNICODE_STRING  NameU 
)

Definition at line 37 of file create.c.

40 {
41  OEM_STRING StringA;
42  USHORT Length;
43  CHAR cString[12];
44 
45  RtlCopyMemory(cString, pEntry->ShortName, 11);
46  cString[11] = 0;
47  if (cString[0] == 0x05)
48  {
49  cString[0] = 0xe5;
50  }
51 
52  StringA.Buffer = cString;
53  for (StringA.Length = 0;
54  StringA.Length < 8 && StringA.Buffer[StringA.Length] != ' ';
55  StringA.Length++);
56  StringA.MaximumLength = StringA.Length;
57 
58  RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
59 
61  {
62  RtlDowncaseUnicodeString(NameU, NameU, FALSE);
63  }
64 
65  if (cString[8] != ' ')
66  {
67  Length = NameU->Length;
68  NameU->Buffer += Length / sizeof(WCHAR);
70  {
71  Length += sizeof(WCHAR);
72  NameU->Buffer[0] = L'.';
73  NameU->Buffer++;
74  }
75  NameU->Length = 0;
76  NameU->MaximumLength -= Length;
77 
78  StringA.Buffer = &cString[8];
79  for (StringA.Length = 0;
80  StringA.Length < 3 && StringA.Buffer[StringA.Length] != ' ';
81  StringA.Length++);
82  StringA.MaximumLength = StringA.Length;
83  RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
85  {
86  RtlDowncaseUnicodeString(NameU, NameU, FALSE);
87  }
88  NameU->Buffer -= Length / sizeof(WCHAR);
89  NameU->Length += Length;
90  NameU->MaximumLength += Length;
91  }
92 
93  NameU->Buffer[NameU->Length / sizeof(WCHAR)] = 0;
94  DPRINT("'%wZ'\n", NameU);
95 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
char CHAR
Definition: xmlstorage.h:175
STRING OEM_STRING
Definition: umtypes.h:203
NTSYSAPI NTSTATUS WINAPI RtlDowncaseUnicodeString(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN)
#define FALSE
Definition: types.h:117
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define FAT_ENTRY_VOLUME(DirEntry)
Definition: vfat.h:212
#define VFAT_CASE_LOWER_BASE
Definition: vfat.h:200
static const WCHAR L[]
Definition: oid.c:1250
#define VFAT_CASE_LOWER_EXT
Definition: vfat.h:201
NTSYSAPI NTSTATUS NTAPI RtlOemStringToUnicodeString(PUNICODE_STRING DestinationString, PCOEM_STRING SourceString, BOOLEAN AllocateDestinationString)
unsigned short USHORT
Definition: pedump.c:61
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DPRINT
Definition: sndvol32.h:71
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484

Referenced by FATGetNextDirEntry(), and ReadVolumeLabel().

◆ VfatAcquireForLazyWrite()

BOOLEAN NTAPI VfatAcquireForLazyWrite ( IN PVOID  Context,
IN BOOLEAN  Wait 
)

Definition at line 724 of file fastio.c.

727 {
729  ASSERT(Fcb);
730  DPRINT("VfatAcquireForLazyWrite(): Fcb %p\n", Fcb);
731 
733  {
734  DPRINT("VfatAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
735  return FALSE;
736  }
737  return TRUE;
738 }
Definition: vfat.h:447
#define TRUE
Definition: types.h:120
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
ERESOURCE MainResource
Definition: ntfs.h:528
struct _VFATFCB * PVFATFCB
#define DPRINT
Definition: sndvol32.h:71
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by DriverEntry().

◆ VfatAddEntry()

FORCEINLINE NTSTATUS VfatAddEntry ( PDEVICE_EXTENSION  DeviceExt,
PUNICODE_STRING  NameU,
struct _VFATFCB **  Fcb,
struct _VFATFCB ParentFcb,
ULONG  RequestedOptions,
UCHAR  ReqAttr,
struct _VFAT_MOVE_CONTEXT MoveContext 
)

Definition at line 375 of file vfat.h.

382 {
383  return DeviceExt->Dispatch.AddEntry(DeviceExt, NameU, Fcb, ParentFcb, RequestedOptions, ReqAttr, MoveContext);
384 }
_In_ PFCB ParentFcb
Definition: cdprocs.h:736
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by VfatCreateFile(), and VfatMoveEntry().

◆ vfatAttachFCBToFileObject()

NTSTATUS vfatAttachFCBToFileObject ( PDEVICE_EXTENSION  vcb,
PVFATFCB  fcb,
PFILE_OBJECT  fileObject 
)

Definition at line 755 of file fcb.c.

759 {
760  PVFATCCB newCCB;
761 
762 #ifdef KDBG
763  if (DebugFile.Buffer != NULL && FsRtlIsNameInExpression(&DebugFile, &fcb->LongNameU, FALSE, NULL))
764  {
765  DPRINT1("Attaching %p to %p (%d)\n", fcb, fileObject, fcb->RefCount);
766  }
767 #endif
768 
769  newCCB = ExAllocateFromNPagedLookasideList(&VfatGlobalData->CcbLookasideList);
770  if (newCCB == NULL)
771  {
773  }
774  RtlZeroMemory(newCCB, sizeof (VFATCCB));
775 
776  fileObject->SectionObjectPointer = &fcb->SectionObjectPointers;
777  fileObject->FsContext = fcb;
778  fileObject->FsContext2 = newCCB;
779  fileObject->Vpb = vcb->IoVPB;
780  DPRINT("file open: fcb:%p PathName:%wZ\n", fcb, &fcb->PathNameU);
781 
782 #ifdef KDBG
783  fcb->Flags &= ~FCB_CLEANED_UP;
784  fcb->Flags &= ~FCB_CLOSED;
785 #endif
786 
787  return STATUS_SUCCESS;
788 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: vfat.h:536
BOOLEAN NTAPI FsRtlIsNameInExpression(IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
Definition: name.c:514
#define FALSE
Definition: types.h:117
NPAGED_LOOKASIDE_LIST CcbLookasideList
Definition: vfat.h:418
struct _fcb fcb
Definition: btrfs_drv.h:1357
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatCreateFile(), VfatMount(), and VfatOpenFile().

◆ VfatBlockDeviceIoControl()

NTSTATUS VfatBlockDeviceIoControl ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  CtlCode,
IN PVOID  InputBuffer,
IN ULONG  InputBufferSize,
IN OUT PVOID  OutputBuffer,
IN OUT PULONG  pOutputBufferSize,
IN BOOLEAN  Override 
)

Definition at line 432 of file blockdev.c.

440 {
442  KEVENT Event;
443  PIRP Irp;
446 
447  DPRINT("VfatBlockDeviceIoControl(DeviceObject %p, CtlCode %x, "
448  "InputBuffer %p, InputBufferSize %x, OutputBuffer %p, "
449  "OutputBufferSize %p (%x)\n", DeviceObject, CtlCode,
450  InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize,
451  OutputBufferSize ? *OutputBufferSize : 0);
452 
453 again:
455 
456  DPRINT("Building device I/O control request ...\n");
458  DeviceObject,
459  InputBuffer,
460  InputBufferSize,
461  OutputBuffer,
462  (OutputBufferSize) ? *OutputBufferSize : 0,
463  FALSE,
464  &Event,
465  &IoStatus);
466  if (Irp == NULL)
467  {
468  DPRINT("IoBuildDeviceIoControlRequest failed\n");
470  }
471 
472  if (Override)
473  {
476  }
477 
478  DPRINT("Calling IO Driver... with irp %p\n", Irp);
480 
481  DPRINT("Waiting for IO Operation for %p\n", Irp);
482  if (Status == STATUS_PENDING)
483  {
484  DPRINT("Operation pending\n");
486  DPRINT("Getting IO Status... for %p\n", Irp);
487 
488  Status = IoStatus.Status;
489  }
490 
492  {
494 
495  DPRINT1("Media change detected!\n");
496 
497  /* Find the device to verify and reset the thread field to empty value again. */
501  FALSE);
502 
503  if (NT_SUCCESS(Status))
504  {
505  DPRINT1("Volume verification successful; Reissuing IOCTL request\n");
506  goto again;
507  }
508  }
509 
510  if (OutputBufferSize)
511  {
512  *OutputBufferSize = IoStatus.Information;
513  }
514 
515  DPRINT("Returning Status %x\n", Status);
516 
517  return Status;
518 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetDeviceToVerify(IN PETHREAD Thread)
Definition: util.c:336
#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
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1823
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
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
#define DPRINT1
Definition: precomp.h:8
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
#define DPRINT
Definition: sndvol32.h:71
NTSTATUS NTAPI IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN AllowRawMount)
Definition: volume.c:877
VOID NTAPI IoSetDeviceToVerify(IN PETHREAD Thread, IN PDEVICE_OBJECT DeviceObject)
Definition: util.c:304
_Inout_ PIRP _In_ PDEVICE_OBJECT DeviceToVerify
Definition: cdprocs.h:1407

Referenced by VfatHasFileSystem(), VfatOpenFile(), and VfatVerify().

◆ VfatBuildRequest()

NTSTATUS NTAPI VfatBuildRequest ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

◆ VfatCheckForDismount()

BOOLEAN VfatCheckForDismount ( IN PDEVICE_EXTENSION  DeviceExt,
IN BOOLEAN  Create 
)

Definition at line 496 of file misc.c.

499 {
500  KIRQL OldIrql;
501  ULONG UnCleanCount;
502  PVPB Vpb;
503  BOOLEAN Delete;
504 
505  DPRINT1("VfatCheckForDismount(%p, %u)\n", DeviceExt, Force);
506 
507  /* If the VCB is OK (not under uninitialization) and we don't force dismount, do nothing */
508  if (BooleanFlagOn(DeviceExt->Flags, VCB_GOOD) && !Force)
509  {
510  return FALSE;
511  }
512 
513  /*
514  * NOTE: In their *CheckForDismount() function, our 3rd-party FS drivers
515  * as well as MS' fastfat, perform a comparison check of the current VCB's
516  * VPB ReferenceCount with some sort of "dangling"/"residual" open count,
517  * depending on whether or not we are in IRP_MJ_CREATE.
518  * It seems to be related to the fact that the volume root directory as
519  * well as auxiliary data stream(s) are still opened, and only these are
520  * allowed to be opened at that moment. After analysis it appears that for
521  * the ReactOS' fastfat, this number is equal to "2".
522  */
523  UnCleanCount = 2;
524 
525  /* Lock VPB */
527 
528  /* Reference it and check if a create is being done */
529  Vpb = DeviceExt->IoVPB;
530  DPRINT("Vpb->ReferenceCount = %d\n", Vpb->ReferenceCount);
531  if (Vpb->ReferenceCount != UnCleanCount || DeviceExt->OpenHandleCount != 0)
532  {
533  /* If we force-unmount, copy the VPB to our local own to prepare later dismount */
534  if (Force && Vpb->RealDevice->Vpb == Vpb && DeviceExt->SpareVPB != NULL)
535  {
536  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
537  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
538  DeviceExt->SpareVPB->Size = sizeof(VPB);
539  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
540  DeviceExt->SpareVPB->DeviceObject = NULL;
541  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
542  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
543  DeviceExt->SpareVPB = NULL;
544  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
545 
546  /* We are uninitializing, the VCB cannot be used anymore */
547  ClearFlag(DeviceExt->Flags, VCB_GOOD);
548  }
549 
550  /* Don't do anything for now */
551  Delete = FALSE;
552  }
553  else
554  {
555  /* Otherwise, delete the volume */
556  Delete = TRUE;
557 
558  /* Swap the VPB with our local own */
559  if (Vpb->RealDevice->Vpb == Vpb && DeviceExt->SpareVPB != NULL)
560  {
561  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
562  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
563  DeviceExt->SpareVPB->Size = sizeof(VPB);
564  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
565  DeviceExt->SpareVPB->DeviceObject = NULL;
566  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
567  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
568  DeviceExt->SpareVPB = NULL;
569  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
570 
571  /* We are uninitializing, the VCB cannot be used anymore */
572  ClearFlag(DeviceExt->Flags, VCB_GOOD);
573  }
574 
575  /*
576  * We defer setting the VPB's DeviceObject to NULL for later because
577  * we want to handle the closing of the internal opened meta-files.
578  */
579 
580  /* Clear the mounted and locked flags in the VPB */
581  ClearFlag(Vpb->Flags, VPB_MOUNTED | VPB_LOCKED);
582  }
583 
584  /* Release lock and return status */
586 
587  /* If we were to delete, delete volume */
588  if (Delete)
589  {
590  LARGE_INTEGER Zero = {{0,0}};
591  PVFATFCB Fcb;
592 
593  /* We are uninitializing, the VCB cannot be used anymore */
594  ClearFlag(DeviceExt->Flags, VCB_GOOD);
595 
596  /* Invalidate and close the internal opened meta-files */
597  if (DeviceExt->RootFcb)
598  {
599  Fcb = DeviceExt->RootFcb;
601  &Zero,
602  NULL);
604  DeviceExt->RootFcb = NULL;
606  }
607  if (DeviceExt->VolumeFcb)
608  {
609  Fcb = DeviceExt->VolumeFcb;
610 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
612  &Zero,
613  NULL);
615 #endif
616  DeviceExt->VolumeFcb = NULL;
618  }
619  if (DeviceExt->FATFileObject)
620  {
621  Fcb = DeviceExt->FATFileObject->FsContext;
622  CcUninitializeCacheMap(DeviceExt->FATFileObject,
623  &Zero,
624  NULL);
625  DeviceExt->FATFileObject->FsContext = NULL;
626  ObDereferenceObject(DeviceExt->FATFileObject);
627  DeviceExt->FATFileObject = NULL;
629  }
630 
631  ASSERT(DeviceExt->OverflowQueueCount == 0);
632  ASSERT(IsListEmpty(&DeviceExt->OverflowQueue));
633  ASSERT(DeviceExt->PostedRequestCount == 0);
634 
635  /*
636  * Now that the closing of the internal opened meta-files has been
637  * handled, we can now set the VPB's DeviceObject to NULL.
638  */
639  Vpb->DeviceObject = NULL;
640 
641  /* If we have a local VPB, we'll have to delete it
642  * but we won't dismount us - something went bad before
643  */
644  if (DeviceExt->SpareVPB)
645  {
646  ExFreePool(DeviceExt->SpareVPB);
647  }
648  /* Otherwise, delete any of the available VPB if its reference count is zero */
649  else if (DeviceExt->IoVPB->ReferenceCount == 0)
650  {
651  ExFreePool(DeviceExt->IoVPB);
652  }
653 
654  /* Remove the volume from the list */
656  RemoveEntryList(&DeviceExt->VolumeListEntry);
658 
659  /* Uninitialize the notify synchronization object */
660  FsRtlNotifyUninitializeSync(&DeviceExt->NotifySync);
661 
662  /* Release resources */
663  ExFreePoolWithTag(DeviceExt->Statistics, TAG_STATS);
664  ExDeleteResourceLite(&DeviceExt->DirResource);
665  ExDeleteResourceLite(&DeviceExt->FatResource);
666 
667  /* Dismount our device if possible */
668  ObDereferenceObject(DeviceExt->StorageDevice);
669  IoDeleteDevice(DeviceExt->VolumeDevice);
670  }
671 
672  return Delete;
673 }
Definition: vfat.h:447
PFILE_OBJECT FileObject
Definition: ntfs.h:520
#define TRUE
Definition: types.h:120
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1204
PVPB Vpb
Definition: cdstruc.h:511
#define VPB_PERSISTENT
Definition: iotypes.h:1809
_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
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define VPB_LOCKED
Definition: iotypes.h:1808
unsigned char BOOLEAN
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
KIRQL OldIrql
Definition: mm.h:1502
#define ASSERT(a)
Definition: mode.c:44
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID vfatDestroyFCB(PVFATFCB pFCB)
Definition: fcb.c:269
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define VCB_GOOD
Definition: vfat.h:247
#define IO_TYPE_VPB
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
struct _VPB VPB
#define TAG_STATS
Definition: vfat.h:550
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define NULL
Definition: types.h:112
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:411
#define DPRINT1
Definition: precomp.h:8
ERESOURCE VolumeListLock
Definition: vfat.h:415
Definition: iotypes.h:189
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VOID NTAPI FsRtlNotifyUninitializeSync(IN PNOTIFY_SYNC *NotifySync)
Definition: notify.c:1639
#define DPRINT
Definition: sndvol32.h:71
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define VPB_MOUNTED
Definition: iotypes.h:1807
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1215
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1673
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Inout_ PVCB _In_ BOOLEAN Force
Definition: cdprocs.h:1415

Referenced by VfatCleanupFile(), VfatCloseFile(), and VfatShutdown().

◆ VfatCleanup()

NTSTATUS VfatCleanup ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 177 of file cleanup.c.

179 {
181 
182  DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
183 
184  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
185  {
186  IrpContext->Irp->IoStatus.Information = 0;
187  return STATUS_SUCCESS;
188  }
189 
190  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
191  Deleted = VfatCleanupFile(IrpContext);
192  if (!Deleted) ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
193 
194  IrpContext->Irp->IoStatus.Information = 0;
195  return STATUS_SUCCESS;
196 }
static BOOLEAN VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
Definition: cleanup.c:25
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:585
#define TRUE
Definition: types.h:120
IO_STATUS_BLOCK IoStatus
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
unsigned char BOOLEAN
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:412
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatDispatchRequest().

◆ VfatClose()

NTSTATUS VfatClose ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 213 of file close.c.

215 {
217 
218  DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
219 
220  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
221  {
222  DPRINT("Closing file system\n");
223  IrpContext->Irp->IoStatus.Information = 0;
224  return STATUS_SUCCESS;
225  }
226  if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
227  {
228  return VfatMarkIrpContextForQueue(IrpContext);
229  }
230 
231  Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
232  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
233 
234  IrpContext->Irp->IoStatus.Information = 0;
235 
236  return Status;
237 }
NTSTATUS VfatCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: close.c:160
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:585
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
IO_STATUS_BLOCK IoStatus
PFILE_OBJECT FileObject
Definition: vfat.h:591
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IRPCONTEXT_CANWAIT
Definition: vfat.h:575
Status
Definition: gdiplustypes.h:24
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:412
FORCEINLINE NTSTATUS VfatMarkIrpContextForQueue(PVFAT_IRP_CONTEXT IrpContext)
Definition: vfat.h:625
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
ULONG Flags
Definition: vfat.h:586
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

Referenced by VfatDispatchRequest().

◆ VfatCloseFile()

NTSTATUS VfatCloseFile ( PDEVICE_EXTENSION  DeviceExt,
PFILE_OBJECT  FileObject 
)

Definition at line 160 of file close.c.

163 {
164  PVFATFCB pFcb;
165  PVFATCCB pCcb;
166  BOOLEAN IsVolume;
168 
169  DPRINT("VfatCloseFile(DeviceExt %p, FileObject %p)\n",
170  DeviceExt, FileObject);
171 
172  /* FIXME : update entry in directory? */
173  pCcb = (PVFATCCB) (FileObject->FsContext2);
174  pFcb = (PVFATFCB) (FileObject->FsContext);
175 
176  if (pFcb == NULL)
177  {
178  return STATUS_SUCCESS;
179  }
180 
181  IsVolume = BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME);
182 
183  if (pCcb)
184  {
185  vfatDestroyCCB(pCcb);
186  }
187 
188  /* If we have to close immediately, or if delaying failed, close */
191  {
192  VfatCommonCloseFile(DeviceExt, pFcb);
193  }
194 
195  FileObject->FsContext2 = NULL;
196  FileObject->FsContext = NULL;
197  FileObject->SectionObjectPointer = NULL;
198 
199 #ifdef ENABLE_SWAPOUT
200  if (IsVolume && DeviceExt->OpenHandleCount == 0)
201  {
202  VfatCheckForDismount(DeviceExt, FALSE);
203  }
204 #endif
205 
206  return Status;
207 }
NTSTATUS VfatPostCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: close.c:116
Definition: vfat.h:447
Definition: vfat.h:536
struct _VFATCCB * PVFATCCB
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
ULONG Flags
Definition: vfat.h:496
unsigned char BOOLEAN
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID vfatDestroyCCB(PVFATCCB pCcb)
Definition: fcb.c:258
BOOLEAN VfatCheckForDismount(IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Force)
Definition: misc.c:496
struct _VFATFCB * PVFATFCB
#define FCB_DELAYED_CLOSE
Definition: vfat.h:439
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
#define FCB_IS_VOLUME
Definition: vfat.h:437
BOOLEAN ShutdownStarted
Definition: vfat.h:428
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
VOID VfatCommonCloseFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB pFcb)
Definition: close.c:20

Referenced by VfatClose(), VfatCreateFile(), and vfatPrepareTargetForRename().

◆ VfatCreate()

NTSTATUS VfatCreate ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 1088 of file create.c.

1090 {
1091  NTSTATUS Status;
1092 
1093  ASSERT(IrpContext);
1094 
1095  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
1096  {
1097  /* DeviceObject represents FileSystem instead of logical volume */
1098  DPRINT ("FsdCreate called with file system\n");
1099  IrpContext->Irp->IoStatus.Information = FILE_OPENED;
1100  IrpContext->PriorityBoost = IO_DISK_INCREMENT;
1101 
1102  return STATUS_SUCCESS;
1103  }
1104 
1105  IrpContext->Irp->IoStatus.Information = 0;
1106  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
1107  Status = VfatCreateFile(IrpContext->DeviceObject, IrpContext->Irp);
1108  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
1109 
1110  if (NT_SUCCESS(Status))
1111  IrpContext->PriorityBoost = IO_DISK_INCREMENT;
1112 
1113  return Status;
1114 }
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:585
Iosb Status
Definition: create.c:4287
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
IO_STATUS_BLOCK IoStatus
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
CCHAR PriorityBoost
Definition: vfat.h:594
#define IO_DISK_INCREMENT
Definition: iotypes.h:600
Status
Definition: gdiplustypes.h:24
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:412
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
static NTSTATUS VfatCreateFile(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: create.c:422

Referenced by VfatDispatchRequest().

◆ VfatDelEntry()

FORCEINLINE NTSTATUS VfatDelEntry ( PDEVICE_EXTENSION  DeviceExt,
struct _VFATFCB Fcb,
struct _VFAT_MOVE_CONTEXT MoveContext 
)

Definition at line 388 of file vfat.h.

391 {
392  return DeviceExt->Dispatch.DelEntry(DeviceExt, Fcb, MoveContext);
393 }
_In_ PFCB Fcb
Definition: cdprocs.h:159

Referenced by VfatCleanupFile(), VfatMoveEntry(), and vfatPrepareTargetForRename().

◆ vfatDestroyCCB()

VOID vfatDestroyCCB ( PVFATCCB  pCcb)

Definition at line 258 of file fcb.c.

260 {
261  if (pCcb->SearchPattern.Buffer)
262  {
264  }
265  ExFreeToNPagedLookasideList(&VfatGlobalData->CcbLookasideList, pCcb);
266 }
UNICODE_STRING SearchPattern
Definition: vfat.h:543
NPAGED_LOOKASIDE_LIST CcbLookasideList
Definition: vfat.h:418
#define TAG_SEARCH
Definition: vfat.h:554
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:36
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by VfatCloseFile(), and VfatMount().

◆ vfatDestroyFCB()

VOID vfatDestroyFCB ( PVFATFCB  pFCB)

Definition at line 269 of file fcb.c.

271 {
272 #ifdef KDBG
273  if (DebugFile.Buffer != NULL && FsRtlIsNameInExpression(&DebugFile, &pFCB->LongNameU, FALSE, NULL))
274  {
275  DPRINT1("Destroying: %p (%wZ) %d\n", pFCB, &pFCB->PathNameU, pFCB->RefCount);
276  }
277 #endif
278 
280 
281  if (!vfatFCBIsRoot(pFCB) &&
283  {
285  }
286  ExFreePool(pFCB->PathNameBuffer);
290  ExFreeToNPagedLookasideList(&VfatGlobalData->FcbLookasideList, pFCB);
291 }
NPAGED_LOOKASIDE_LIST FcbLookasideLi