ReactOS  0.4.15-dev-5120-gfb68e76
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:18
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 731 of file fat.c.

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

Referenced by VfatReadFileData(), and VfatWriteFileData().

◆ CountAvailableClusters()

NTSTATUS CountAvailableClusters ( PDEVICE_EXTENSION  DeviceExt,
PLARGE_INTEGER  Clusters 
)

Definition at line 541 of file fat.c.

544 {
546  ExAcquireResourceExclusiveLite (&DeviceExt->FatResource, TRUE);
547  if (!DeviceExt->AvailableClustersValid)
548  {
549  if (DeviceExt->FatInfo.FatType == FAT12)
550  Status = FAT12CountAvailableClusters(DeviceExt);
551  else if (DeviceExt->FatInfo.FatType == FAT16 || DeviceExt->FatInfo.FatType == FATX16)
552  Status = FAT16CountAvailableClusters(DeviceExt);
553  else
554  Status = FAT32CountAvailableClusters(DeviceExt);
555  }
556  if (Clusters != NULL)
557  {
558  Clusters->QuadPart = DeviceExt->AvailableClusters;
559  }
560  ExReleaseResourceLite (&DeviceExt->FatResource);
561 
562  return Status;
563 }
#define FAT12
Definition: fat.h:167
static NTSTATUS FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:435
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:490
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 FAT16
Definition: fat.h:168
static NTSTATUS FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:381
#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 244 of file fat.c.

247 {
248  ULONG FatLength;
249  ULONG StartCluster;
250  ULONG Entry;
251  PUSHORT CBlock;
252  ULONG i, j;
254  PVOID Context;
256 
257  FatLength = DeviceExt->FatInfo.NumberOfClusters + 2;
258  *Cluster = 0;
259  StartCluster = DeviceExt->LastAvailableCluster;
260  Offset.QuadPart = 0;
261  _SEH2_TRY
262  {
263  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
264  }
266  {
267  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector);
269  }
270  _SEH2_END;
271 
272  for (j = 0; j < 2; j++)
273  {
274  for (i = StartCluster; i < FatLength; i++)
275  {
276  CBlock = (PUSHORT)((char*)BaseAddress + (i * 12) / 8);
277  if ((i % 2) == 0)
278  {
279  Entry = *CBlock & 0xfff;
280  }
281  else
282  {
283  Entry = *CBlock >> 4;
284  }
285 
286  if (Entry == 0)
287  {
288  DPRINT("Found available cluster 0x%x\n", i);
289  DeviceExt->LastAvailableCluster = *Cluster = i;
290  if ((i % 2) == 0)
291  *CBlock = (*CBlock & 0xf000) | 0xfff;
292  else
293  *CBlock = (*CBlock & 0xf) | 0xfff0;
296  if (DeviceExt->AvailableClustersValid)
297  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
298  return STATUS_SUCCESS;
299  }
300  }
301  FatLength = StartCluster;
302  StartCluster = 2;
303  }
305  return STATUS_DISK_FULL;
306 }
struct _Entry Entry
Definition: kefuncs.h:629
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 123 of file fat.c.

127 {
128  PUSHORT CBlock;
129  ULONG Entry;
131  PVOID Context;
133 
134  *NextCluster = 0;
135 
136  Offset.QuadPart = 0;
137  _SEH2_TRY
138  {
139  CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, MAP_WAIT, &Context, &BaseAddress);
140  }
142  {
144  }
145  _SEH2_END;
146 
147  CBlock = (PUSHORT)((char*)BaseAddress + (CurrentCluster * 12) / 8);
148  if ((CurrentCluster % 2) == 0)
149  {
150  Entry = *CBlock & 0x0fff;
151  }
152  else
153  {
154  Entry = *CBlock >> 4;
155  }
156 
157 // DPRINT("Entry %x\n",Entry);
158  if (Entry >= 0xff8 && Entry <= 0xfff)
159  Entry = 0xffffffff;
160 
161 // DPRINT("Returning %x\n",Entry);
162  ASSERT(Entry != 0);
163  *NextCluster = Entry;
165 // return Entry == 0xffffffff ? STATUS_END_OF_FILE : STATUS_SUCCESS;
166  return STATUS_SUCCESS;
167 }
struct _Entry Entry
Definition: kefuncs.h:629
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
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:38
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 570 of file fat.c.

575 {
576  ULONG FATOffset;
577  PUCHAR CBlock;
579  PVOID Context;
581 
582  Offset.QuadPart = 0;
583  _SEH2_TRY
584  {
585  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
586  }
588  {
590  }
591  _SEH2_END;
592  CBlock = (PUCHAR)BaseAddress;
593 
594  FATOffset = (ClusterToWrite * 12) / 8;
595  DPRINT("Writing 0x%x for 0x%x at 0x%x\n",
596  NewValue, ClusterToWrite, FATOffset);
597  if ((ClusterToWrite % 2) == 0)
598  {
599  *OldValue = CBlock[FATOffset] + ((CBlock[FATOffset + 1] & 0x0f) << 8);
600  CBlock[FATOffset] = (UCHAR)NewValue;
601  CBlock[FATOffset + 1] &= 0xf0;
602  CBlock[FATOffset + 1] |= (NewValue & 0xf00) >> 8;
603  }
604  else
605  {
606  *OldValue = (CBlock[FATOffset] >> 4) + (CBlock[FATOffset + 1] << 4);
607  CBlock[FATOffset] &= 0x0f;
608  CBlock[FATOffset] |= (NewValue & 0xf) << 4;
609  CBlock[FATOffset + 1] = (UCHAR)(NewValue >> 4);
610  }
611  /* Write the changed FAT sector(s) to disk */
614  return STATUS_SUCCESS;
615 }
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 173 of file fat.c.

176 {
177  ULONG FatLength;
178  ULONG StartCluster;
179  ULONG i, j;
182  PVOID Context = 0;
184  PUSHORT Block;
185  PUSHORT BlockEnd;
186 
187  ChunkSize = CACHEPAGESIZE(DeviceExt);
188  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
189  *Cluster = 0;
190  StartCluster = DeviceExt->LastAvailableCluster;
191 
192  for (j = 0; j < 2; j++)
193  {
194  for (i = StartCluster; i < FatLength;)
195  {
196  Offset.QuadPart = ROUND_DOWN(i * 2, ChunkSize);
197  _SEH2_TRY
198  {
199  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
200  }
202  {
203  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
205  }
206  _SEH2_END;
207 
208  Block = (PUSHORT)((ULONG_PTR)BaseAddress + (i * 2) % ChunkSize);
209  BlockEnd = (PUSHORT)((ULONG_PTR)BaseAddress + ChunkSize);
210 
211  /* Now process the whole block */
212  while (Block < BlockEnd && i < FatLength)
213  {
214  if (*Block == 0)
215  {
216  DPRINT("Found available cluster 0x%x\n", i);
217  DeviceExt->LastAvailableCluster = *Cluster = i;
218  *Block = 0xffff;
221  if (DeviceExt->AvailableClustersValid)
222  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
223  return STATUS_SUCCESS;
224  }
225 
226  Block++;
227  i++;
228  }
229 
231  }
232 
233  FatLength = StartCluster;
234  StartCluster = 2;
235  }
236 
237  return STATUS_DISK_FULL;
238 }
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
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:18
_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 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 858 of file fat.c.

861 {
863  ULONG Length;
864 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
866 #else
867  PVOID Context;
868 #endif
869  struct _BootSector * Sector;
870 
871  /* We'll read the bootsector at 0 */
872  Offset.QuadPart = 0;
873  Length = DeviceExt->FatInfo.BytesPerSector;
874 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
875  /* Go through Cc for this */
876  _SEH2_TRY
877  {
878  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
879  }
881  {
883  }
884  _SEH2_END;
885 #else
886  /* No Cc, do it the old way:
887  * - Allocate a big enough buffer
888  * - And read the disk
889  */
891  if (Sector == NULL)
892  {
893  *DirtyStatus = TRUE;
895  }
896 
897  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
898  if (!NT_SUCCESS(Status))
899  {
900  *DirtyStatus = TRUE;
901  ExFreePoolWithTag(Sector, TAG_BUFFER);
902  return Status;
903  }
904 #endif
905 
906  /* Make sure we have a boot sector...
907  * FIXME: This check is a bit lame and should be improved
908  */
909  if (Sector->Signatur1 != 0xaa55)
910  {
911  /* Set we are dirty so that we don't attempt anything */
912  *DirtyStatus = TRUE;
913 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
915 #else
916  ExFreePoolWithTag(Sector, TAG_BUFFER);
917 #endif
919  }
920 
921  /* Return the status of the dirty bit */
922  if (Sector->Res1 & FAT_DIRTY_BIT)
923  *DirtyStatus = TRUE;
924  else
925  *DirtyStatus = FALSE;
926 
927 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
929 #else
930  ExFreePoolWithTag(Sector, TAG_BUFFER);
931 #endif
932  return STATUS_SUCCESS;
933 }
#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:70
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 77 of file fat.c.

81 {
84  ULONG FATOffset;
86  PVOID Context;
88 
89  ChunkSize = CACHEPAGESIZE(DeviceExt);
90  FATOffset = CurrentCluster * 2;
91  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
92  _SEH2_TRY
93  {
94  CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress);
95  }
97  {
99  }
100  _SEH2_END;
101 
102  CurrentCluster = *((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
103  if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
104  CurrentCluster = 0xffffffff;
105 
106  if (CurrentCluster == 0)
107  {
108  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
111  ASSERT(CurrentCluster != 0);
112  }
113 
115  *NextCluster = CurrentCluster;
116  return Status;
117 }
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:18
_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
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
ULONG Flags
Definition: vfat.h:413
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:38
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 1044 of file fat.c.

1047 {
1049  ULONG Length;
1050 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1051  NTSTATUS Status;
1052 #else
1053  PVOID Context;
1054 #endif
1055  struct _BootSector * Sector;
1056 
1057  /* We'll read (and then write) the bootsector at 0 */
1058  Offset.QuadPart = 0;
1059  Length = DeviceExt->FatInfo.BytesPerSector;
1060 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1061  /* Go through Cc for this */
1062  _SEH2_TRY
1063  {
1064  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1065  }
1067  {
1069  }
1070  _SEH2_END;
1071 #else
1072  /* No Cc, do it the old way:
1073  * - Allocate a big enough buffer
1074  * - And read the disk
1075  */
1077  if (Sector == NULL)
1078  {
1080  }
1081 
1082  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1083  if (!NT_SUCCESS(Status))
1084  {
1085  ExFreePoolWithTag(Sector, TAG_BUFFER);
1086  return Status;
1087  }
1088 #endif
1089 
1090  /* Make sure we have a boot sector...
1091  * FIXME: This check is a bit lame and should be improved
1092  */
1093  if (Sector->Signatur1 != 0xaa55)
1094  {
1095 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1097 #else
1098  ExFreePoolWithTag(Sector, TAG_BUFFER);
1099 #endif
1101  }
1102 
1103  /* Modify the dirty bit status according
1104  * to caller needs
1105  */
1106  if (!DirtyStatus)
1107  {
1108  Sector->Res1 &= ~FAT_DIRTY_BIT;
1109  }
1110  else
1111  {
1112  Sector->Res1 |= FAT_DIRTY_BIT;
1113  }
1114 
1115 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1116  /* Mark boot sector dirty so that it gets written to the disk */
1119  return STATUS_SUCCESS;
1120 #else
1121  /* Write back the boot sector to the disk */
1122  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1123  ExFreePoolWithTag(Sector, TAG_BUFFER);
1124  return Status;
1125 #endif
1126 }
#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:70
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
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:253

Referenced by VfatMount().

◆ FAT16WriteCluster()

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

Definition at line 621 of file fat.c.

626 {
628  ULONG FATOffset;
630  PVOID Context;
632  PUSHORT Cluster;
633 
634  ChunkSize = CACHEPAGESIZE(DeviceExt);
635  FATOffset = ClusterToWrite * 2;
636  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
637  _SEH2_TRY
638  {
639  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
640  }
642  {
644  }
645  _SEH2_END;
646 
647  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
648  ClusterToWrite);
649  Cluster = ((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
650  *OldValue = *Cluster;
651  *Cluster = (USHORT)NewValue;
654  return STATUS_SUCCESS;
655 }
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
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:18
_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
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 312 of file fat.c.

315 {
316  ULONG FatLength;
317  ULONG StartCluster;
318  ULONG i, j;
321  PVOID Context;
323  PULONG Block;
324  PULONG BlockEnd;
325 
326  ChunkSize = CACHEPAGESIZE(DeviceExt);
327  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
328  *Cluster = 0;
329  StartCluster = DeviceExt->LastAvailableCluster;
330 
331  for (j = 0; j < 2; j++)
332  {
333  for (i = StartCluster; i < FatLength;)
334  {
335  Offset.QuadPart = ROUND_DOWN(i * 4, ChunkSize);
336  _SEH2_TRY
337  {
338  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
339  }
341  {
342  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
344  }
345  _SEH2_END;
346  Block = (PULONG)((ULONG_PTR)BaseAddress + (i * 4) % ChunkSize);
347  BlockEnd = (PULONG)((ULONG_PTR)BaseAddress + ChunkSize);
348 
349  /* Now process the whole block */
350  while (Block < BlockEnd && i < FatLength)
351  {
352  if ((*Block & 0x0fffffff) == 0)
353  {
354  DPRINT("Found available cluster 0x%x\n", i);
355  DeviceExt->LastAvailableCluster = *Cluster = i;
356  *Block = 0x0fffffff;
359  if (DeviceExt->AvailableClustersValid)
360  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
361  return STATUS_SUCCESS;
362  }
363 
364  Block++;
365  i++;
366  }
367 
369  }
370  FatLength = StartCluster;
371  StartCluster = 2;
372  }
373  return STATUS_DISK_FULL;
374 }
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
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:18
_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
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 936 of file fat.c.

939 {
941  ULONG Length;
942 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
944 #else
945  PVOID Context;
946 #endif
947  struct _BootSector32 * Sector;
948 
949  /* We'll read the bootsector at 0 */
950  Offset.QuadPart = 0;
951  Length = DeviceExt->FatInfo.BytesPerSector;
952 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
953  /* Go through Cc for this */
954  _SEH2_TRY
955  {
956  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
957  }
959  {
961  }
962  _SEH2_END;
963 #else
964  /* No Cc, do it the old way:
965  * - Allocate a big enough buffer
966  * - And read the disk
967  */
969  if (Sector == NULL)
970  {
971  *DirtyStatus = TRUE;
973  }
974 
975  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
976  if (!NT_SUCCESS(Status))
977  {
978  *DirtyStatus = TRUE;
979  ExFreePoolWithTag(Sector, TAG_BUFFER);
980  return Status;
981  }
982 #endif
983 
984  /* Make sure we have a boot sector...
985  * FIXME: This check is a bit lame and should be improved
986  */
987  if (Sector->Signature1 != 0xaa55)
988  {
989  /* Set we are dirty so that we don't attempt anything */
990  *DirtyStatus = TRUE;
991 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
993 #else
994  ExFreePoolWithTag(Sector, TAG_BUFFER);
995 #endif
997  }
998 
999  /* Return the status of the dirty bit */
1000  if (Sector->Res4 & FAT_DIRTY_BIT)
1001  *DirtyStatus = TRUE;
1002  else
1003  *DirtyStatus = FALSE;
1004 
1005 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1007 #else
1008  ExFreePoolWithTag(Sector, TAG_BUFFER);
1009 #endif
1010  return STATUS_SUCCESS;
1011 }
#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:70
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 28 of file fat.c.

32 {
35  ULONG FATOffset;
37  PVOID Context = NULL;
39 
40  ChunkSize = CACHEPAGESIZE(DeviceExt);
41  FATOffset = CurrentCluster * sizeof(ULONG);
42  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
43  _SEH2_TRY
44  {
45  if (!CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress))
46  {
48  return STATUS_UNSUCCESSFUL;
49  }
50  }
52  {
54  }
55  _SEH2_END;
56 
57  CurrentCluster = (*(PULONG)((char*)BaseAddress + (FATOffset % ChunkSize))) & 0x0fffffff;
58  if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
59  CurrentCluster = 0xffffffff;
60 
61  if (CurrentCluster == 0)
62  {
63  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
66  ASSERT(CurrentCluster != 0);
67  }
69  *NextCluster = CurrentCluster;
70  return Status;
71 }
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:18
_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
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4400
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
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
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:38
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 1129 of file fat.c.

1132 {
1134  ULONG Length;
1135 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1136  NTSTATUS Status;
1137 #else
1138  PVOID Context;
1139 #endif
1140  struct _BootSector32 * Sector;
1141 
1142  /* We'll read (and then write) the bootsector at 0 */
1143  Offset.QuadPart = 0;
1144  Length = DeviceExt->FatInfo.BytesPerSector;
1145 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1146  /* Go through Cc for this */
1147  _SEH2_TRY
1148  {
1149  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1150  }
1152  {
1154  }
1155  _SEH2_END;
1156 #else
1157  /* No Cc, do it the old way:
1158  * - Allocate a big enough buffer
1159  * - And read the disk
1160  */
1162  if (Sector == NULL)
1163  {
1165  }
1166 
1167  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1168  if (!NT_SUCCESS(Status))
1169  {
1170  ExFreePoolWithTag(Sector, TAG_BUFFER);
1171  return Status;
1172  }
1173 #endif
1174 
1175  /* Make sure we have a boot sector...
1176  * FIXME: This check is a bit lame and should be improved
1177  */
1178  if (Sector->Signature1 != 0xaa55)
1179  {
1180  ASSERT(FALSE);
1181 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1183 #else
1184  ExFreePoolWithTag(Sector, TAG_BUFFER);
1185 #endif
1187  }
1188 
1189  /* Modify the dirty bit status according
1190  * to caller needs
1191  */
1192  if (!DirtyStatus)
1193  {
1194  Sector->Res4 &= ~FAT_DIRTY_BIT;
1195  }
1196  else
1197  {
1198  Sector->Res4 |= FAT_DIRTY_BIT;
1199  }
1200 
1201 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1202  /* Mark boot sector dirty so that it gets written to the disk */
1205  return STATUS_SUCCESS;
1206 #else
1207  /* Write back the boot sector to the disk */
1208  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1209  ExFreePoolWithTag(Sector, TAG_BUFFER);
1210  return Status;
1211 #endif
1212 }
#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:70
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
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
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:253
unsigned short Signature1
Definition: vfat.h:82

Referenced by VfatMount().

◆ FAT32UpdateFreeClustersCount()

NTSTATUS FAT32UpdateFreeClustersCount ( PDEVICE_EXTENSION  DeviceExt)

Definition at line 1215 of file fat.c.

1217 {
1219  ULONG Length;
1220 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1221  NTSTATUS Status;
1222 #else
1223  PVOID Context;
1224 #endif
1225  struct _FsInfoSector * Sector;
1226 
1227  if (!DeviceExt->AvailableClustersValid)
1228  {
1229  return STATUS_INVALID_PARAMETER;
1230  }
1231 
1232  /* We'll read (and then write) the fsinfo sector */
1233  Offset.QuadPart = DeviceExt->FatInfo.FSInfoSector * DeviceExt->FatInfo.BytesPerSector;
1234  Length = DeviceExt->FatInfo.BytesPerSector;
1235 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1236  /* Go through Cc for this */
1237  _SEH2_TRY
1238  {
1239  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1240  }
1242  {
1244  }
1245  _SEH2_END;
1246 #else
1247  /* No Cc, do it the old way:
1248  * - Allocate a big enough buffer
1249  * - And read the disk
1250  */
1252  if (Sector == NULL)
1253  {
1255  }
1256 
1257  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1258  if (!NT_SUCCESS(Status))
1259  {
1260  ExFreePoolWithTag(Sector, TAG_BUFFER);
1261  return Status;
1262  }
1263 #endif
1264 
1265  /* Make sure we have a FSINFO sector */
1266  if (Sector->ExtBootSignature2 != 0x41615252 ||
1267  Sector->FSINFOSignature != 0x61417272 ||
1268  Sector->Signatur2 != 0xaa550000)
1269  {
1270  ASSERT(FALSE);
1271 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1273 #else
1274  ExFreePoolWithTag(Sector, TAG_BUFFER);
1275 #endif
1277  }
1278 
1279  /* Update the free clusters count */
1280  Sector->FreeCluster = InterlockedCompareExchange((PLONG)&DeviceExt->AvailableClusters, 0, 0);
1281 
1282 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1283  /* Mark FSINFO sector dirty so that it gets written to the disk */
1286  return STATUS_SUCCESS;
1287 #else
1288  /* Write back the FSINFO sector to the disk */
1289  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1290  ExFreePoolWithTag(Sector, TAG_BUFFER);
1291  return Status;
1292 #endif
1293 }
#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:70
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
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
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:253

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

◆ FAT32WriteCluster()

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

Definition at line 661 of file fat.c.

666 {
668  ULONG FATOffset;
670  PVOID Context;
672  PULONG Cluster;
673 
674  ChunkSize = CACHEPAGESIZE(DeviceExt);
675 
676  FATOffset = (ClusterToWrite * 4);
677  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
678  _SEH2_TRY
679  {
680  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
681  }
683  {
685  }
686  _SEH2_END;
687 
688  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
689  ClusterToWrite);
690  Cluster = ((PULONG)((char*)BaseAddress + (FATOffset % ChunkSize)));
691  *OldValue = *Cluster & 0x0fffffff;
692  *Cluster = (*Cluster & 0xf0000000) | (NewValue & 0x0fffffff);
693 
696 
697  return STATUS_SUCCESS;
698 }
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
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:18
_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
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 83 of file create.c.

89 {
90  PWCHAR PathNameBuffer;
91  USHORT PathNameBufferLength;
93  PVOID Context = NULL;
94  PVOID Page;
95  PVFATFCB rcFcb;
96  BOOLEAN Found;
97  UNICODE_STRING PathNameU;
98  UNICODE_STRING FileToFindUpcase;
99  BOOLEAN WildCard;
100  BOOLEAN IsFatX = vfatVolumeIsFatX(DeviceExt);
101 
102  DPRINT("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
103  Parent, FileToFindU, DirContext->DirIndex);
104  DPRINT("FindFile: Path %wZ\n",&Parent->PathNameU);
105 
106  PathNameBufferLength = LONGNAME_MAX_LENGTH * sizeof(WCHAR);
107  PathNameBuffer = ExAllocatePoolWithTag(NonPagedPool, PathNameBufferLength + sizeof(WCHAR), TAG_NAME);
108  if (!PathNameBuffer)
109  {
111  }
112 
113  PathNameU.Buffer = PathNameBuffer;
114  PathNameU.Length = 0;
115  PathNameU.MaximumLength = PathNameBufferLength;
116 
117  DirContext->LongNameU.Length = 0;
118  DirContext->ShortNameU.Length = 0;
119 
120  WildCard = FsRtlDoesNameContainWildCards(FileToFindU);
121 
122  if (WildCard == FALSE)
123  {
124  /* if there is no '*?' in the search name, than look first for an existing fcb */
125  RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
126  if (!vfatFCBIsRoot(Parent))
127  {
128  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
129  PathNameU.Length += sizeof(WCHAR);
130  }
131  RtlAppendUnicodeStringToString(&PathNameU, FileToFindU);
132  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
133  rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
134  if (rcFcb)
135  {
136  ULONG startIndex = rcFcb->startIndex;
137  if (IsFatX && !vfatFCBIsRoot(Parent))
138  {
139  startIndex += 2;
140  }
141  if(startIndex >= DirContext->DirIndex)
142  {
143  RtlCopyUnicodeString(&DirContext->LongNameU, &rcFcb->LongNameU);
144  RtlCopyUnicodeString(&DirContext->ShortNameU, &rcFcb->ShortNameU);
145  RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
146  DirContext->StartIndex = rcFcb->startIndex;
147  DirContext->DirIndex = rcFcb->dirIndex;
148  DPRINT("FindFile: new Name %wZ, DirIndex %u (%u)\n",
149  &DirContext->LongNameU, DirContext->DirIndex, DirContext->StartIndex);
151  }
152  else
153  {
154  DPRINT("FCB not found for %wZ\n", &PathNameU);
156  }
157  vfatReleaseFCB(DeviceExt, rcFcb);
158  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
159  return Status;
160  }
161  }
162 
163  /* FsRtlIsNameInExpression need the searched string to be upcase,
164  * even if IgnoreCase is specified */
165  Status = RtlUpcaseUnicodeString(&FileToFindUpcase, FileToFindU, TRUE);
166  if (!NT_SUCCESS(Status))
167  {
168  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
169  return Status;
170  }
171 
172  while (TRUE)
173  {
175  First = FALSE;
177  {
178  break;
179  }
180  if (ENTRY_VOLUME(IsFatX, &DirContext->DirEntry))
181  {
182  DirContext->DirIndex++;
183  continue;
184  }
185  if (DirContext->LongNameU.Length == 0 ||
186  DirContext->ShortNameU.Length == 0)
187  {
188  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
190  {
191  ASSERT(DirContext->LongNameU.Length != 0 &&
192  DirContext->ShortNameU.Length != 0);
193  }
194  DirContext->DirIndex++;
195  continue;
196  }
197  if (WildCard)
198  {
199  Found = FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->LongNameU, TRUE, NULL) ||
200  FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->ShortNameU, TRUE, NULL);
201  }
202  else
203  {
204  Found = FsRtlAreNamesEqual(&DirContext->LongNameU, FileToFindU, TRUE, NULL) ||
205  FsRtlAreNamesEqual(&DirContext->ShortNameU, FileToFindU, TRUE, NULL);
206  }
207 
208  if (Found)
209  {
210  if (WildCard)
211  {
212  RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
213  if (!vfatFCBIsRoot(Parent))
214  {
215  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
216  PathNameU.Length += sizeof(WCHAR);
217  }
218  RtlAppendUnicodeStringToString(&PathNameU, &DirContext->LongNameU);
219  PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
220  rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
221  if (rcFcb != NULL)
222  {
223  RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
224  vfatReleaseFCB(DeviceExt, rcFcb);
225  }
226  }
227  DPRINT("%u\n", DirContext->LongNameU.Length);
228  DPRINT("FindFile: new Name %wZ, DirIndex %u\n",
229  &DirContext->LongNameU, DirContext->DirIndex);
230 
231  if (Context)
232  {
234  }
235  RtlFreeUnicodeString(&FileToFindUpcase);
236  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
237  return STATUS_SUCCESS;
238  }
239  DirContext->DirIndex++;
240  }
241 
242  if (Context)
243  {
245  }
246 
247  RtlFreeUnicodeString(&FileToFindUpcase);
248  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
249  return Status;
250 }
#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
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
VOID vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
Definition: fcb.c:335
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 L(x)
Definition: ntvdm.h:50
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
Definition: mm.h:1295
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
Definition: fcb.c:293
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)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
FORCEINLINE NTSTATUS VfatGetNextDirEntry(PDEVICE_EXTENSION DeviceExt, PVOID *pContext, PVOID *pPage, struct _VFATFCB *pDirFcb, struct _VFAT_DIRENTRY_CONTEXT *DirContext, BOOLEAN First)
Definition: vfat.h:397
PVFATFCB vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
Definition: fcb.c:594
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:407
DIR_ENTRY entry
Definition: vfat.h:457
unsigned short USHORT
Definition: pedump.c:61
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
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
#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 21 of file dir.c.

26 {
27  PDOSTIME pdtime = (PDOSTIME)&DosTime;
28  PDOSDATE pddate = (PDOSDATE)&DosDate;
30  LARGE_INTEGER LocalTime;
31 
32  if (SystemTime == NULL)
33  return FALSE;
34 
36  TimeFields.Second = pdtime->Second * 2;
37  TimeFields.Minute = pdtime->Minute;
38  TimeFields.Hour = pdtime->Hour;
39 
40  TimeFields.Day = pddate->Day;
41  TimeFields.Month = pddate->Month;
42  TimeFields.Year = (CSHORT)(DeviceExt->BaseDateYear + pddate->Year);
43 
44  RtlTimeFieldsToTime(&TimeFields, &LocalTime);
45  ExLocalTimeToSystemTime(&LocalTime, SystemTime);
46 
47  return TRUE;
48 }
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 52 of file dir.c.

57 {
58  PDOSTIME pdtime = (PDOSTIME)pDosTime;
59  PDOSDATE pddate = (PDOSDATE)pDosDate;
61  LARGE_INTEGER LocalTime;
62 
63  if (SystemTime == NULL)
64  return FALSE;
65 
66  ExSystemTimeToLocalTime(SystemTime, &LocalTime);
67  RtlTimeToTimeFields(&LocalTime, &TimeFields);
68 
69  if (pdtime)
70  {
71  pdtime->Second = TimeFields.Second / 2;
72  pdtime->Minute = TimeFields.Minute;
73  pdtime->Hour = TimeFields.Hour;
74  }
75 
76  if (pddate)
77  {
78  pddate->Day = TimeFields.Day;
79  pddate->Month = TimeFields.Month;
80  pddate->Year = (USHORT) (TimeFields.Year - DeviceExt->BaseDateYear);
81  }
82 
83  return TRUE;
84 }
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 831 of file fat.c.

834 {
836 
837  DPRINT("GetDirtyStatus(DeviceExt %p)\n", DeviceExt);
838 
839  /* FAT12 has no dirty bit */
840  if (DeviceExt->FatInfo.FatType == FAT12)
841  {
842  *DirtyStatus = FALSE;
843  return STATUS_SUCCESS;
844  }
845 
846  /* Not really in the FAT, but share the lock because
847  * we're really low-level and shouldn't happent that often
848  * And call the appropriate function
849  */
850  ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
851  Status = DeviceExt->GetDirtyStatus(DeviceExt, DirtyStatus);
852  ExReleaseResourceLite(&DeviceExt->FatResource);
853 
854  return Status;
855 }
#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 744 of file fat.c.

748 {
750 
751  DPRINT("GetNextCluster(DeviceExt %p, CurrentCluster %x)\n",
752  DeviceExt, CurrentCluster);
753 
754  if (CurrentCluster == 0)
755  {
756  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
758  ASSERT(CurrentCluster != 0);
760  }
761 
762  ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
763  Status = DeviceExt->GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
764  ExReleaseResourceLite(&DeviceExt->FatResource);
765 
766  return Status;
767 }
#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:18
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
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:38
#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 773 of file fat.c.

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

29 {
30  return ((Name->Length == sizeof(WCHAR) && Name->Buffer[0] == L'.') ||
31  (Name->Length == 2 * sizeof(WCHAR) && Name->Buffer[0] == L'.' && Name->Buffer[1] == L'.'));
32 }
#define L(x)
Definition: ntvdm.h:50
__wchar_t WCHAR
Definition: xmlstorage.h:180

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

◆ NextCluster()

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

Definition at line 38 of file rw.c.

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

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 59 of file rw.c.

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

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

◆ SetDirtyStatus()

NTSTATUS SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1017 of file fat.c.

1020 {
1021  NTSTATUS Status;
1022 
1023  DPRINT("SetDirtyStatus(DeviceExt %p, DirtyStatus %d)\n", DeviceExt, DirtyStatus);
1024 
1025  /* FAT12 has no dirty bit */
1026  if (DeviceExt->FatInfo.FatType == FAT12)
1027  {
1028  return STATUS_SUCCESS;
1029  }
1030 
1031  /* Not really in the FAT, but share the lock because
1032  * we're really low-level and shouldn't happent that often
1033  * And call the appropriate function
1034  * Acquire exclusive because we will modify ondisk value
1035  */
1036  ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
1037  Status = DeviceExt->SetDirtyStatus(DeviceExt, DirtyStatus);
1038  ExReleaseResourceLite(&DeviceExt->FatResource);
1039 
1040  return Status;
1041 }
#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 19 of file create.c.

22 {
23  OEM_STRING StringA;
24  USHORT Length;
25  CHAR cString[12];
26 
27  RtlCopyMemory(cString, pEntry->ShortName, 11);
28  cString[11] = 0;
29  if (cString[0] == 0x05)
30  {
31  cString[0] = 0xe5;
32  }
33 
34  StringA.Buffer = cString;
35  for (StringA.Length = 0;
36  StringA.Length < 8 && StringA.Buffer[StringA.Length] != ' ';
37  StringA.Length++);
38  StringA.MaximumLength = StringA.Length;
39 
40  RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
41 
43  {
44  RtlDowncaseUnicodeString(NameU, NameU, FALSE);
45  }
46 
47  if (cString[8] != ' ')
48  {
49  Length = NameU->Length;
50  NameU->Buffer += Length / sizeof(WCHAR);
52  {
53  Length += sizeof(WCHAR);
54  NameU->Buffer[0] = L'.';
55  NameU->Buffer++;
56  }
57  NameU->Length = 0;
58  NameU->MaximumLength -= Length;
59 
60  StringA.Buffer = &cString[8];
61  for (StringA.Length = 0;
62  StringA.Length < 3 && StringA.Buffer[StringA.Length] != ' ';
63  StringA.Length++);
64  StringA.MaximumLength = StringA.Length;
65  RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
67  {
68  RtlDowncaseUnicodeString(NameU, NameU, FALSE);
69  }
70  NameU->Buffer -= Length / sizeof(WCHAR);
71  NameU->Length += Length;
72  NameU->MaximumLength += Length;
73  }
74 
75  NameU->Buffer[NameU->Length / sizeof(WCHAR)] = 0;
76  DPRINT("'%wZ'\n", NameU);
77 }
_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 L(x)
Definition: ntvdm.h:50
#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
#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 723 of file fastio.c.

726 {
728  ASSERT(Fcb);
729  DPRINT("VfatAcquireForLazyWrite(): Fcb %p\n", Fcb);
730 
732  {
733  DPRINT("VfatAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
734  return FALSE;
735  }
736  return TRUE;
737 }
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 754 of file fcb.c.

758 {
759  PVFATCCB newCCB;
760 
761 #ifdef KDBG
762  if (DebugFile.Buffer != NULL && FsRtlIsNameInExpression(&DebugFile, &fcb->LongNameU, FALSE, NULL))
763  {
764  DPRINT1("Attaching %p to %p (%d)\n", fcb, fileObject, fcb->RefCount);
765  }
766 #endif
767 
768  newCCB = ExAllocateFromNPagedLookasideList(&VfatGlobalData->CcbLookasideList);
769  if (newCCB == NULL)
770  {
772  }
773  RtlZeroMemory(newCCB, sizeof (VFATCCB));
774 
775  fileObject->SectionObjectPointer = &fcb->SectionObjectPointers;
776  fileObject->FsContext = fcb;
777  fileObject->FsContext2 = newCCB;
778  fileObject->Vpb = vcb->IoVPB;
779  DPRINT("file open: fcb:%p PathName:%wZ\n", fcb, &fcb->PathNameU);
780 
781 #ifdef KDBG
782  fcb->Flags &= ~FCB_CLEANED_UP;
783  fcb->Flags &= ~FCB_CLOSED;
784 #endif
785 
786  return STATUS_SUCCESS;
787 }
#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:1364
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
#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 430 of file blockdev.c.

438 {
440  KEVENT Event;
441  PIRP Irp;
444 
445  DPRINT("VfatBlockDeviceIoControl(DeviceObject %p, CtlCode %x, "
446  "InputBuffer %p, InputBufferSize %x, OutputBuffer %p, "
447  "OutputBufferSize %p (%x)\n", DeviceObject, CtlCode,
448  InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize,
449  OutputBufferSize ? *OutputBufferSize : 0);
450 
451 again:
453 
454  DPRINT("Building device I/O control request ...\n");
456  DeviceObject,
457  InputBuffer,
458  InputBufferSize,
459  OutputBuffer,
460  (OutputBufferSize) ? *OutputBufferSize : 0,
461  FALSE,
462  &Event,
463  &IoStatus);
464  if (Irp == NULL)
465  {
466  DPRINT("IoBuildDeviceIoControlRequest failed\n");
468  }
469 
470  if (Override)
471  {
474  }
475 
476  DPRINT("Calling IO Driver... with irp %p\n", Irp);
478 
479  DPRINT("Waiting for IO Operation for %p\n", Irp);
480  if (Status == STATUS_PENDING)
481  {
482  DPRINT("Operation pending\n");
484  DPRINT("Getting IO Status... for %p\n", Irp);
485 
486  Status = IoStatus.Status;
487  }
488 
490  {
492 
493  DPRINT1("Media change detected!\n");
494 
495  /* Find the device to verify and reset the thread field to empty value again. */
499  FALSE);
500 
501  if (NT_SUCCESS(Status))
502  {
503  DPRINT1("Volume verification successful; Reissuing IOCTL request\n");
504  goto again;
505  }
506  }
507 
508  if (OutputBufferSize)
509  {
510  *OutputBufferSize = IoStatus.Information;
511  }
512 
513  DPRINT("Returning Status %x\n", Status);
514 
515  return Status;
516 }
#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 495 of file misc.c.

498 {
499  KIRQL OldIrql;
500  ULONG UnCleanCount;
501  PVPB Vpb;
502  BOOLEAN Delete;
503 
504  DPRINT1("VfatCheckForDismount(%p, %u)\n", DeviceExt, Force);
505 
506  /* If the VCB is OK (not under uninitialization) and we don't force dismount, do nothing */
507  if (BooleanFlagOn(DeviceExt->Flags, VCB_GOOD) && !Force)
508  {
509  return FALSE;
510  }
511 
512  /*
513  * NOTE: In their *CheckForDismount() function, our 3rd-party FS drivers
514  * as well as MS' fastfat, perform a comparison check of the current VCB's
515  * VPB ReferenceCount with some sort of "dangling"/"residual" open count,
516  * depending on whether or not we are in IRP_MJ_CREATE.
517  * It seems to be related to the fact that the volume root directory as
518  * well as auxiliary data stream(s) are still opened, and only these are
519  * allowed to be opened at that moment. After analysis it appears that for
520  * the ReactOS' vfatfs, this number is equal to "2".
521  */
522  UnCleanCount = 2;
523 
524  /* Lock VPB */
526 
527  /* Reference it and check if a create is being done */
528  Vpb = DeviceExt->IoVPB;
529  DPRINT("Vpb->ReferenceCount = %d\n", Vpb->ReferenceCount);
530  if (Vpb->ReferenceCount != UnCleanCount || DeviceExt->OpenHandleCount != 0)
531  {
532  /* If we force-unmount, copy the VPB to our local own to prepare later dismount */
533  if (Force && Vpb->RealDevice->Vpb == Vpb && DeviceExt->SpareVPB != NULL)
534  {
535  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
536  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
537  DeviceExt->SpareVPB->Size = sizeof(VPB);
538  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
539  DeviceExt->SpareVPB->DeviceObject = NULL;
540  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
541  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
542  DeviceExt->SpareVPB = NULL;
543  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
544 
545  /* We are uninitializing, the VCB cannot be used anymore */
546  ClearFlag(DeviceExt->Flags, VCB_GOOD);
547  }
548 
549  /* Don't do anything for now */
550  Delete = FALSE;
551  }
552  else
553  {
554  /* Otherwise, delete the volume */
555  Delete = TRUE;
556 
557  /* Swap the VPB with our local own */
558  if (Vpb->RealDevice->Vpb == Vpb && DeviceExt->SpareVPB != NULL)
559  {
560  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
561  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
562  DeviceExt->SpareVPB->Size = sizeof(VPB);
563  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
564  DeviceExt->SpareVPB->DeviceObject = NULL;
565  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
566  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
567  DeviceExt->SpareVPB = NULL;
568  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
569 
570  /* We are uninitializing, the VCB cannot be used anymore */
571  ClearFlag(DeviceExt->Flags, VCB_GOOD);
572  }
573 
574  /*
575  * We defer setting the VPB's DeviceObject to NULL for later because
576  * we want to handle the closing of the internal opened meta-files.
577  */
578 
579  /* Clear the mounted and locked flags in the VPB */
580  ClearFlag(Vpb->Flags, VPB_MOUNTED | VPB_LOCKED);
581  }
582 
583  /* Release lock and return status */
585 
586  /* If we were to delete, delete volume */
587  if (Delete)
588  {
589  LARGE_INTEGER Zero = {{0,0}};
590  PVFATFCB Fcb;
591 
592  /* We are uninitializing, the VCB cannot be used anymore */
593  ClearFlag(DeviceExt->Flags, VCB_GOOD);
594 
595  /* Invalidate and close the internal opened meta-files */
596  if (DeviceExt->RootFcb)
597  {
598  Fcb = DeviceExt->RootFcb;
600  &Zero,
601  NULL);
603  DeviceExt->RootFcb = NULL;
605  }
606  if (DeviceExt->VolumeFcb)
607  {
608  Fcb = DeviceExt->VolumeFcb;
609 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
611  &Zero,
612  NULL);
614 #endif
615  DeviceExt->VolumeFcb = NULL;
617  }
618  if (DeviceExt->FATFileObject)
619  {
620  Fcb = DeviceExt->FATFileObject->FsContext;
621  CcUninitializeCacheMap(DeviceExt->FATFileObject,
622  &Zero,
623  NULL);
624  DeviceExt->FATFileObject->FsContext = NULL;
625  ObDereferenceObject(DeviceExt->FATFileObject);
626  DeviceExt->FATFileObject = NULL;
628  }
629 
630  ASSERT(DeviceExt->OverflowQueueCount == 0);
631  ASSERT(IsListEmpty(&DeviceExt->OverflowQueue));
632  ASSERT(DeviceExt->PostedRequestCount == 0);
633 
634  /*
635  * Now that the closing of the internal opened meta-files has been
636  * handled, we can now set the VPB's DeviceObject to NULL.
637  */
638  Vpb->DeviceObject = NULL;
639 
640  /* If we have a local VPB, we'll have to delete it
641  * but we won't dismount us - something went bad before
642  */
643  if (DeviceExt->SpareVPB)
644  {
645  ExFreePool(DeviceExt->SpareVPB);
646  }
647  /* Otherwise, delete any of the available VPB if its reference count is zero */
648  else if (DeviceExt->IoVPB->ReferenceCount == 0)
649  {
650  ExFreePool(DeviceExt->IoVPB);
651  }
652 
653  /* Remove the volume from the list */
655  RemoveEntryList(&DeviceExt->VolumeListEntry);
657 
658  /* Uninitialize the notify synchronization object */
659  FsRtlNotifyUninitializeSync(&DeviceExt->NotifySync);
660 
661  /* Release resources */
662  ExFreePoolWithTag(DeviceExt->Statistics, TAG_STATS);
663  ExDeleteResourceLite(&DeviceExt->DirResource);
664  ExDeleteResourceLite(&DeviceExt->FatResource);
665 
666  /* Dismount our device if possible */
667  ObDereferenceObject(DeviceExt->StorageDevice);
668  IoDeleteDevice(DeviceExt->VolumeDevice);
669  }
670 
671  return Delete;
672 }
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
VOID vfatDestroyFCB(PVFATFCB pFCB)
Definition: fcb.c:268
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
#define ASSERT(a)
Definition: mode.c:44
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define VCB_GOOD
Definition: vfat.h:247
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
#define IO_TYPE_VPB
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
struct _VPB VPB
#define TAG_STATS
Definition: vfat.h:550
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
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:1668
#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 176 of file cleanup.c.

178 {
180 
181  DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
182 
183  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
184  {
185  IrpContext->Irp->IoStatus.Information = 0;
186  return STATUS_SUCCESS;
187  }
188 
189  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
190  Deleted = VfatCleanupFile(IrpContext);
191  if (!Deleted) ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
192 
193  IrpContext->Irp->IoStatus.Information = 0;
194  return STATUS_SUCCESS;
195 }
static BOOLEAN VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
Definition: cleanup.c:24
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:18
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 212 of file close.c.

214 {
216 
217  DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
218 
219  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
220  {
221  DPRINT("Closing file system\n");
222  IrpContext->Irp->IoStatus.Information = 0;
223  return STATUS_SUCCESS;
224  }
225  if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
226  {
227  return VfatMarkIrpContextForQueue(IrpContext);
228  }
229 
230  Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
231  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
232 
233  IrpContext->Irp->IoStatus.Information = 0;
234 
235  return Status;
236 }
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
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:18
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
NTSTATUS VfatCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: close.c:159
ULONG Flags
Definition: vfat.h:586
#define IRPCONTEXT_CANWAIT
Definition: ntfs.h:474
#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 159 of file close.c.

162 {
163  PVFATFCB pFcb;
164  PVFATCCB pCcb;
165  BOOLEAN IsVolume;
167 
168  DPRINT("VfatCloseFile(DeviceExt %p, FileObject %p)\n",
169  DeviceExt, FileObject);
170 
171  /* FIXME : update entry in directory? */
172  pCcb = (PVFATCCB) (FileObject->FsContext2);
173  pFcb = (PVFATFCB) (FileObject->FsContext);
174 
175  if (pFcb == NULL)
176  {
177  return STATUS_SUCCESS;
178  }
179 
180  IsVolume = BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME);
181 
182  if (pCcb)
183  {
184  vfatDestroyCCB(pCcb);
185  }
186 
187  /* If we have to close immediately, or if delaying failed, close */
190  {
191  VfatCommonCloseFile(DeviceExt, pFcb);
192  }
193 
194  FileObject->FsContext2 = NULL;
195  FileObject->FsContext = NULL;
196  FileObject->SectionObjectPointer = NULL;
197 
198 #ifdef ENABLE_SWAPOUT
199  if (IsVolume && DeviceExt->OpenHandleCount == 0)
200  {
201  VfatCheckForDismount(DeviceExt, FALSE);
202  }
203 #endif
204 
205  return Status;
206 }
NTSTATUS VfatPostCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: close.c:115
VOID VfatCommonCloseFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB pFcb)
Definition: close.c:19
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:257
struct _VFATFCB * PVFATFCB
#define FCB_DELAYED_CLOSE
Definition: vfat.h:439
BOOLEAN ShutdownStarted
Definition: vfat.h:428
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
#define NULL
Definition: types.h:112
#define FCB_IS_VOLUME
Definition: ntfs.h:510
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
BOOLEAN VfatCheckForDismount(IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Force)
Definition: misc.c:495

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

◆ VfatCreate()

NTSTATUS VfatCreate ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 1070 of file create.c.

1072 {
1073  NTSTATUS Status;
1074 
1075  ASSERT(IrpContext);
1076 
1077  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
1078  {
1079  /* DeviceObject represents FileSystem instead of logical volume */
1080  DPRINT ("FsdCreate called with file system\n");
1081  IrpContext->Irp->IoStatus.Information = FILE_OPENED;
1082  IrpContext->PriorityBoost = IO_DISK_INCREMENT;
1083 
1084  return STATUS_SUCCESS;
1085  }
1086 
1087  IrpContext->Irp->IoStatus.Information = 0;
1088  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
1089  Status = VfatCreateFile(IrpContext->DeviceObject, IrpContext->Irp);
1090  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
1091 
1092  if (NT_SUCCESS(Status))
1093  IrpContext->PriorityBoost = IO_DISK_INCREMENT;
1094 
1095  return Status;
1096 }
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
static NTSTATUS VfatCreateFile(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: create.c:404
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:18
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:584
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71

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 257 of file fcb.c.

259 {
260  if (pCcb->SearchPattern.Buffer)
261  {
263  }
264  ExFreeToNPagedLookasideList(&VfatGlobalData->CcbLookasideList, pCcb);
265 }
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:18
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by VfatCloseFile(), and VfatMount().

◆ vfatDestroyFCB()

VOID vfatDestroyFCB ( PVFATFCB  pFCB)

Definition at line 268 of file fcb.c.

270 {
271 #ifdef KDBG
272  if (DebugFile.Buffer != NULL && FsRtlIsNameInExpression(&DebugFile, &pFCB->LongNameU, FALSE, NULL))
273  {
274  DPRINT1("Destroying: %p (%wZ) %d\n", pFCB, &pFCB->PathNameU, pFCB->RefCount);
275  }
276 #endif
277 
279 
280  if (!vfatFCBIsRoot(pFCB) &&
282  {
284  }
285  ExFreePool(pFCB->PathNameBuffer);
289  ExFreeToNPagedLookasideList(&VfatGlobalData->FcbLookasideList, pFCB);
290 }
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: vfat.h:417