ReactOS  0.4.12-dev-409-g9f418243
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)
 
INIT_FUNCTION 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)
 
INIT_FUNCTION NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
NTSTATUS NTAPI VfatBuildRequest (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
PVOID VfatGetUserBuffer (IN PIRP, IN BOOLEAN Paging)
 
NTSTATUS VfatLockUserBuffer (IN PIRP, IN ULONG, IN LOCK_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 IrpContext)
 
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 wstrcmpjoki (PWSTR s1, PWSTR s2)
 
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 528 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 551 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 427 of file vfat.h.

◆ FCB_DELAYED_CLOSE

#define FCB_DELAYED_CLOSE   0x0040

Definition at line 433 of file vfat.h.

◆ FCB_DELETE_PENDING

#define FCB_DELETE_PENDING   0x0002

Definition at line 428 of file vfat.h.

◆ FCB_IS_DIRTY

#define FCB_IS_DIRTY   0x0020

Definition at line 432 of file vfat.h.

◆ FCB_IS_FAT

#define FCB_IS_FAT   0x0004

Definition at line 429 of file vfat.h.

◆ FCB_IS_PAGE_FILE

#define FCB_IS_PAGE_FILE   0x0008

Definition at line 430 of file vfat.h.

◆ FCB_IS_VOLUME

#define FCB_IS_VOLUME   0x0010

Definition at line 431 of file vfat.h.

◆ IRPCONTEXT_CANWAIT

#define IRPCONTEXT_CANWAIT   0x0001

Definition at line 569 of file vfat.h.

◆ IRPCONTEXT_COMPLETE

#define IRPCONTEXT_COMPLETE   0x0002

Definition at line 570 of file vfat.h.

◆ IRPCONTEXT_DEFERRED_WRITE

#define IRPCONTEXT_DEFERRED_WRITE   0x0010

Definition at line 573 of file vfat.h.

◆ IRPCONTEXT_PENDINGRETURNED

#define IRPCONTEXT_PENDINGRETURNED   0x0008

Definition at line 572 of file vfat.h.

◆ IRPCONTEXT_QUEUE

#define IRPCONTEXT_QUEUE   0x0004

Definition at line 571 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 439 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 545 of file vfat.h.

◆ TAG_CCB

#define TAG_CCB   'CtaF'

Definition at line 540 of file vfat.h.

◆ TAG_CLOSE

#define TAG_CLOSE   'xtaF'

Definition at line 543 of file vfat.h.

◆ TAG_DIRENT

#define TAG_DIRENT   'DtaF'

Definition at line 549 of file vfat.h.

◆ TAG_FCB

#define TAG_FCB   'FtaF'

Definition at line 541 of file vfat.h.

◆ TAG_IRP

#define TAG_IRP   'ItaF'

Definition at line 542 of file vfat.h.

◆ TAG_NAME

#define TAG_NAME   'ntaF'

Definition at line 547 of file vfat.h.

◆ TAG_SEARCH

#define TAG_SEARCH   'LtaF'

Definition at line 548 of file vfat.h.

◆ TAG_STATS

#define TAG_STATS   'VtaF'

Definition at line 544 of file vfat.h.

◆ TAG_VPB

#define TAG_VPB   'vtaF'

Definition at line 546 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 401 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:40
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:325
ULONG NumberProcessors
Definition: vfat.h:408
#define Vcb
Definition: cdprocs.h:1425

Definition at line 665 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 729 of file fat.c.

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

Referenced by VfatReadFileData(), and VfatWriteFileData().

◆ CountAvailableClusters()

NTSTATUS CountAvailableClusters ( PDEVICE_EXTENSION  DeviceExt,
PLARGE_INTEGER  Clusters 
)

Definition at line 539 of file fat.c.

542 {
544  ExAcquireResourceExclusiveLite (&DeviceExt->FatResource, TRUE);
545  if (!DeviceExt->AvailableClustersValid)
546  {
547  if (DeviceExt->FatInfo.FatType == FAT12)
548  Status = FAT12CountAvailableClusters(DeviceExt);
549  else if (DeviceExt->FatInfo.FatType == FAT16 || DeviceExt->FatInfo.FatType == FATX16)
550  Status = FAT16CountAvailableClusters(DeviceExt);
551  else
552  Status = FAT32CountAvailableClusters(DeviceExt);
553  }
554  if (Clusters != NULL)
555  {
556  Clusters->QuadPart = DeviceExt->AvailableClusters;
557  }
558  ExReleaseResourceLite (&DeviceExt->FatResource);
559 
560  return Status;
561 }
#define FAT12
Definition: fat.h:167
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
static NTSTATUS FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:433
smooth NULL
Definition: ftsmooth.c:416
static NTSTATUS FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:379
static NTSTATUS FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:488
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define FAT16
Definition: fat.h:168
Status
Definition: gdiplustypes.h:24
#define FATX16
Definition: fat.h:170
return STATUS_SUCCESS
Definition: btrfs.c:2725
LONGLONG QuadPart
Definition: typedefs.h:112

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

◆ DriverEntry()

INIT_FUNCTION 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 }
void DPRINT(...)
Definition: polytest.cpp:61
return STATUS_SUCCESS
Definition: btrfs.c:2725

◆ FAT12FindAndMarkAvailableCluster()

NTSTATUS FAT12FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 242 of file fat.c.

245 {
246  ULONG FatLength;
247  ULONG StartCluster;
248  ULONG Entry;
249  PUSHORT CBlock;
250  ULONG i, j;
252  PVOID Context;
254 
255  FatLength = DeviceExt->FatInfo.NumberOfClusters + 2;
256  *Cluster = 0;
257  StartCluster = DeviceExt->LastAvailableCluster;
258  Offset.QuadPart = 0;
259  _SEH2_TRY
260  {
261  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
262  }
264  {
265  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector);
267  }
268  _SEH2_END;
269 
270  for (j = 0; j < 2; j++)
271  {
272  for (i = StartCluster; i < FatLength; i++)
273  {
274  CBlock = (PUSHORT)((char*)BaseAddress + (i * 12) / 8);
275  if ((i % 2) == 0)
276  {
277  Entry = *CBlock & 0xfff;
278  }
279  else
280  {
281  Entry = *CBlock >> 4;
282  }
283 
284  if (Entry == 0)
285  {
286  DPRINT("Found available cluster 0x%x\n", i);
287  DeviceExt->LastAvailableCluster = *Cluster = i;
288  if ((i % 2) == 0)
289  *CBlock = (*CBlock & 0xf000) | 0xfff;
290  else
291  *CBlock = (*CBlock & 0xf) | 0xfff0;
294  if (DeviceExt->AvailableClustersValid)
295  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
296  return STATUS_SUCCESS;
297  }
298  }
299  FatLength = StartCluster;
300  StartCluster = 2;
301  }
303  return STATUS_DISK_FULL;
304 }
struct _Entry Entry
Definition: kefuncs.h:640
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:4250
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_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
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
_SEH2_END
Definition: create.c:4424
#define DPRINT1
Definition: precomp.h:8
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
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 121 of file fat.c.

125 {
126  PUSHORT CBlock;
127  ULONG Entry;
129  PVOID Context;
131 
132  *NextCluster = 0;
133 
134  Offset.QuadPart = 0;
135  _SEH2_TRY
136  {
137  CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, MAP_WAIT, &Context, &BaseAddress);
138  }
140  {
142  }
143  _SEH2_END;
144 
145  CBlock = (PUSHORT)((char*)BaseAddress + (CurrentCluster * 12) / 8);
146  if ((CurrentCluster % 2) == 0)
147  {
148  Entry = *CBlock & 0x0fff;
149  }
150  else
151  {
152  Entry = *CBlock >> 4;
153  }
154 
155 // DPRINT("Entry %x\n",Entry);
156  if (Entry >= 0xff8 && Entry <= 0xfff)
157  Entry = 0xffffffff;
158 
159 // DPRINT("Returning %x\n",Entry);
160  ASSERT(Entry != 0);
161  *NextCluster = Entry;
163 // return Entry == 0xffffffff ? STATUS_END_OF_FILE : STATUS_SUCCESS;
164  return STATUS_SUCCESS;
165 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
struct _Entry Entry
Definition: kefuncs.h:640
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
_SEH2_TRY
Definition: create.c:4250
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_SEH2_END
Definition: create.c:4424
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
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 568 of file fat.c.

573 {
574  ULONG FATOffset;
575  PUCHAR CBlock;
577  PVOID Context;
579 
580  Offset.QuadPart = 0;
581  _SEH2_TRY
582  {
583  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
584  }
586  {
588  }
589  _SEH2_END;
590  CBlock = (PUCHAR)BaseAddress;
591 
592  FATOffset = (ClusterToWrite * 12) / 8;
593  DPRINT("Writing 0x%x for 0x%x at 0x%x\n",
594  NewValue, ClusterToWrite, FATOffset);
595  if ((ClusterToWrite % 2) == 0)
596  {
597  *OldValue = CBlock[FATOffset] + ((CBlock[FATOffset + 1] & 0x0f) << 8);
598  CBlock[FATOffset] = (UCHAR)NewValue;
599  CBlock[FATOffset + 1] &= 0xf0;
600  CBlock[FATOffset + 1] |= (NewValue & 0xf00) >> 8;
601  }
602  else
603  {
604  *OldValue = (CBlock[FATOffset] >> 4) + (CBlock[FATOffset + 1] << 4);
605  CBlock[FATOffset] &= 0x0f;
606  CBlock[FATOffset] |= (NewValue & 0xf) << 4;
607  CBlock[FATOffset + 1] = (UCHAR)(NewValue >> 4);
608  }
609  /* Write the changed FAT sector(s) to disk */
612  return STATUS_SUCCESS;
613 }
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:4250
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
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
_SEH2_END
Definition: create.c:4424
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by VfatMount().

◆ FAT16FindAndMarkAvailableCluster()

NTSTATUS FAT16FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 171 of file fat.c.

174 {
175  ULONG FatLength;
176  ULONG StartCluster;
177  ULONG i, j;
180  PVOID Context = 0;
182  PUSHORT Block;
183  PUSHORT BlockEnd;
184 
185  ChunkSize = CACHEPAGESIZE(DeviceExt);
186  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
187  *Cluster = 0;
188  StartCluster = DeviceExt->LastAvailableCluster;
189 
190  for (j = 0; j < 2; j++)
191  {
192  for (i = StartCluster; i < FatLength;)
193  {
194  Offset.QuadPart = ROUND_DOWN(i * 2, ChunkSize);
195  _SEH2_TRY
196  {
197  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
198  }
200  {
201  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
203  }
204  _SEH2_END;
205 
206  Block = (PUSHORT)((ULONG_PTR)BaseAddress + (i * 2) % ChunkSize);
207  BlockEnd = (PUSHORT)((ULONG_PTR)BaseAddress + ChunkSize);
208 
209  /* Now process the whole block */
210  while (Block < BlockEnd && i < FatLength)
211  {
212  if (*Block == 0)
213  {
214  DPRINT("Found available cluster 0x%x\n", i);
215  DeviceExt->LastAvailableCluster = *Cluster = i;
216  *Block = 0xffff;
219  if (DeviceExt->AvailableClustersValid)
220  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
221  return STATUS_SUCCESS;
222  }
223 
224  Block++;
225  i++;
226  }
227 
229  }
230 
231  FatLength = StartCluster;
232  StartCluster = 2;
233  }
234 
235  return STATUS_DISK_FULL;
236 }
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:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
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_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
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
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4424
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
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 856 of file fat.c.

859 {
861  ULONG Length;
862 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
864 #else
865  PVOID Context;
866 #endif
867  struct _BootSector * Sector;
868 
869  /* We'll read the bootsector at 0 */
870  Offset.QuadPart = 0;
871  Length = DeviceExt->FatInfo.BytesPerSector;
872 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
873  /* Go through Cc for this */
874  _SEH2_TRY
875  {
876  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
877  }
879  {
881  }
882  _SEH2_END;
883 #else
884  /* No Cc, do it the old way:
885  * - Allocate a big enough buffer
886  * - And read the disk
887  */
889  if (Sector == NULL)
890  {
891  *DirtyStatus = TRUE;
893  }
894 
895  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
896  if (!NT_SUCCESS(Status))
897  {
898  *DirtyStatus = TRUE;
899  ExFreePoolWithTag(Sector, TAG_BUFFER);
900  return Status;
901  }
902 #endif
903 
904  /* Make sure we have a boot sector...
905  * FIXME: This check is a bit lame and should be improved
906  */
907  if (Sector->Signatur1 != 0xaa55)
908  {
909  /* Set we are dirty so that we don't attempt anything */
910  *DirtyStatus = TRUE;
911 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
913 #else
914  ExFreePoolWithTag(Sector, TAG_BUFFER);
915 #endif
917  }
918 
919  /* Return the status of the dirty bit */
920  if (Sector->Res1 & FAT_DIRTY_BIT)
921  *DirtyStatus = TRUE;
922  else
923  *DirtyStatus = FALSE;
924 
925 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
927 #else
928  ExFreePoolWithTag(Sector, TAG_BUFFER);
929 #endif
930  return STATUS_SUCCESS;
931 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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:4250
#define TAG_BUFFER
Definition: vfat.h:545
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned short Signatur1
Definition: vfat.h:54
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by VfatMount().

◆ FAT16GetNextCluster()

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

Definition at line 75 of file fat.c.

79 {
82  ULONG FATOffset;
84  PVOID Context;
86 
87  ChunkSize = CACHEPAGESIZE(DeviceExt);
88  FATOffset = CurrentCluster * 2;
89  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
90  _SEH2_TRY
91  {
92  CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress);
93  }
95  {
97  }
98  _SEH2_END;
99 
100  CurrentCluster = *((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
101  if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
102  CurrentCluster = 0xffffffff;
103 
104  if (CurrentCluster == 0)
105  {
106  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
109  ASSERT(CurrentCluster != 0);
110  }
111 
113  *NextCluster = CurrentCluster;
114  return Status;
115 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
_SEH2_TRY
Definition: create.c:4250
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:401
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4424
ULONG Flags
Definition: vfat.h:407
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VfatMount().

◆ FAT16SetDirtyStatus()

NTSTATUS FAT16SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1042 of file fat.c.

1045 {
1047  ULONG Length;
1048 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1049  NTSTATUS Status;
1050 #else
1051  PVOID Context;
1052 #endif
1053  struct _BootSector * Sector;
1054 
1055  /* We'll read (and then write) the bootsector at 0 */
1056  Offset.QuadPart = 0;
1057  Length = DeviceExt->FatInfo.BytesPerSector;
1058 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1059  /* Go through Cc for this */
1060  _SEH2_TRY
1061  {
1062  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1063  }
1065  {
1067  }
1068  _SEH2_END;
1069 #else
1070  /* No Cc, do it the old way:
1071  * - Allocate a big enough buffer
1072  * - And read the disk
1073  */
1075  if (Sector == NULL)
1076  {
1078  }
1079 
1080  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1081  if (!NT_SUCCESS(Status))
1082  {
1083  ExFreePoolWithTag(Sector, TAG_BUFFER);
1084  return Status;
1085  }
1086 #endif
1087 
1088  /* Make sure we have a boot sector...
1089  * FIXME: This check is a bit lame and should be improved
1090  */
1091  if (Sector->Signatur1 != 0xaa55)
1092  {
1093 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1095 #else
1096  ExFreePoolWithTag(Sector, TAG_BUFFER);
1097 #endif
1099  }
1100 
1101  /* Modify the dirty bit status according
1102  * to caller needs
1103  */
1104  if (!DirtyStatus)
1105  {
1106  Sector->Res1 &= ~FAT_DIRTY_BIT;
1107  }
1108  else
1109  {
1110  Sector->Res1 |= FAT_DIRTY_BIT;
1111  }
1112 
1113 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1114  /* Mark boot sector dirty so that it gets written to the disk */
1117  return STATUS_SUCCESS;
1118 #else
1119  /* Write back the boot sector to the disk */
1120  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1121  ExFreePoolWithTag(Sector, TAG_BUFFER);
1122  return Status;
1123 #endif
1124 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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:4250
#define TAG_BUFFER
Definition: vfat.h:545
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned short Signatur1
Definition: vfat.h:54
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:255
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by VfatMount().

◆ FAT16WriteCluster()

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

Definition at line 619 of file fat.c.

624 {
626  ULONG FATOffset;
628  PVOID Context;
630  PUSHORT Cluster;
631 
632  ChunkSize = CACHEPAGESIZE(DeviceExt);
633  FATOffset = ClusterToWrite * 2;
634  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
635  _SEH2_TRY
636  {
637  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
638  }
640  {
642  }
643  _SEH2_END;
644 
645  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
646  ClusterToWrite);
647  Cluster = ((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
648  *OldValue = *Cluster;
649  *Cluster = (USHORT)NewValue;
652  return STATUS_SUCCESS;
653 }
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:4250
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
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 ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4424
unsigned short USHORT
Definition: pedump.c:61
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by VfatMount().

◆ FAT32FindAndMarkAvailableCluster()

NTSTATUS FAT32FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 310 of file fat.c.

313 {
314  ULONG FatLength;
315  ULONG StartCluster;
316  ULONG i, j;
319  PVOID Context;
321  PULONG Block;
322  PULONG BlockEnd;
323 
324  ChunkSize = CACHEPAGESIZE(DeviceExt);
325  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
326  *Cluster = 0;
327  StartCluster = DeviceExt->LastAvailableCluster;
328 
329  for (j = 0; j < 2; j++)
330  {
331  for (i = StartCluster; i < FatLength;)
332  {
333  Offset.QuadPart = ROUND_DOWN(i * 4, ChunkSize);
334  _SEH2_TRY
335  {
336  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
337  }
339  {
340  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
342  }
343  _SEH2_END;
344  Block = (PULONG)((ULONG_PTR)BaseAddress + (i * 4) % ChunkSize);
345  BlockEnd = (PULONG)((ULONG_PTR)BaseAddress + ChunkSize);
346 
347  /* Now process the whole block */
348  while (Block < BlockEnd && i < FatLength)
349  {
350  if ((*Block & 0x0fffffff) == 0)
351  {
352  DPRINT("Found available cluster 0x%x\n", i);
353  DeviceExt->LastAvailableCluster = *Cluster = i;
354  *Block = 0x0fffffff;
357  if (DeviceExt->AvailableClustersValid)
358  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
359  return STATUS_SUCCESS;
360  }
361 
362  Block++;
363  i++;
364  }
365 
367  }
368  FatLength = StartCluster;
369  StartCluster = 2;
370  }
371  return STATUS_DISK_FULL;
372 }
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:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
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_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
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
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4424
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
signed int * PLONG
Definition: retypes.h:5

Referenced by VfatMount().

◆ FAT32GetDirtyStatus()

NTSTATUS FAT32GetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
PBOOLEAN  DirtyStatus 
)

Definition at line 934 of file fat.c.

937 {
939  ULONG Length;
940 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
942 #else
943  PVOID Context;
944 #endif
945  struct _BootSector32 * Sector;
946 
947  /* We'll read the bootsector at 0 */
948  Offset.QuadPart = 0;
949  Length = DeviceExt->FatInfo.BytesPerSector;
950 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
951  /* Go through Cc for this */
952  _SEH2_TRY
953  {
954  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
955  }
957  {
959  }
960  _SEH2_END;
961 #else
962  /* No Cc, do it the old way:
963  * - Allocate a big enough buffer
964  * - And read the disk
965  */
967  if (Sector == NULL)
968  {
969  *DirtyStatus = TRUE;
971  }
972 
973  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
974  if (!NT_SUCCESS(Status))
975  {
976  *DirtyStatus = TRUE;
977  ExFreePoolWithTag(Sector, TAG_BUFFER);
978  return Status;
979  }
980 #endif
981 
982  /* Make sure we have a boot sector...
983  * FIXME: This check is a bit lame and should be improved
984  */
985  if (Sector->Signature1 != 0xaa55)
986  {
987  /* Set we are dirty so that we don't attempt anything */
988  *DirtyStatus = TRUE;
989 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
991 #else
992  ExFreePoolWithTag(Sector, TAG_BUFFER);
993 #endif
995  }
996 
997  /* Return the status of the dirty bit */
998  if (Sector->Res4 & FAT_DIRTY_BIT)
999  *DirtyStatus = TRUE;
1000  else
1001  *DirtyStatus = FALSE;
1002 
1003 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1005 #else
1006  ExFreePoolWithTag(Sector, TAG_BUFFER);
1007 #endif
1008  return STATUS_SUCCESS;
1009 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char Res4
Definition: vfat.h:77
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:4250
#define TAG_BUFFER
Definition: vfat.h:545
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
unsigned short Signature1
Definition: vfat.h:82

Referenced by VfatMount().

◆ FAT32GetNextCluster()

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

Definition at line 30 of file fat.c.

34 {
37  ULONG FATOffset;
39  PVOID Context;
41 
42  ChunkSize = CACHEPAGESIZE(DeviceExt);
43  FATOffset = CurrentCluster * sizeof(ULONG);
44  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
45  _SEH2_TRY
46  {
47  CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress);
48  }
50  {
52  }
53  _SEH2_END;
54 
55  CurrentCluster = (*(PULONG)((char*)BaseAddress + (FATOffset % ChunkSize))) & 0x0fffffff;
56  if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
57  CurrentCluster = 0xffffffff;
58 
59  if (CurrentCluster == 0)
60  {
61  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
64  ASSERT(CurrentCluster != 0);
65  }
67  *NextCluster = CurrentCluster;
68  return Status;
69 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
_SEH2_TRY
Definition: create.c:4250
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
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 _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:401
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4424
unsigned int * PULONG
Definition: retypes.h:1
ULONG Flags
Definition: vfat.h:407
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by VfatMount().

◆ FAT32SetDirtyStatus()

NTSTATUS FAT32SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1127 of file fat.c.

1130 {
1132  ULONG Length;
1133 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1134  NTSTATUS Status;
1135 #else
1136  PVOID Context;
1137 #endif
1138  struct _BootSector32 * Sector;
1139 
1140  /* We'll read (and then write) the bootsector at 0 */
1141  Offset.QuadPart = 0;
1142  Length = DeviceExt->FatInfo.BytesPerSector;
1143 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1144  /* Go through Cc for this */
1145  _SEH2_TRY
1146  {
1147  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1148  }
1150  {
1152  }
1153  _SEH2_END;
1154 #else
1155  /* No Cc, do it the old way:
1156  * - Allocate a big enough buffer
1157  * - And read the disk
1158  */
1160  if (Sector == NULL)
1161  {
1163  }
1164 
1165  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1166  if (!NT_SUCCESS(Status))
1167  {
1168  ExFreePoolWithTag(Sector, TAG_BUFFER);
1169  return Status;
1170  }
1171 #endif
1172 
1173  /* Make sure we have a boot sector...
1174  * FIXME: This check is a bit lame and should be improved
1175  */
1176  if (Sector->Signature1 != 0xaa55)
1177  {
1178  ASSERT(FALSE);
1179 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1181 #else
1182  ExFreePoolWithTag(Sector, TAG_BUFFER);
1183 #endif
1185  }
1186 
1187  /* Modify the dirty bit status according
1188  * to caller needs
1189  */
1190  if (!DirtyStatus)
1191  {
1192  Sector->Res4 &= ~FAT_DIRTY_BIT;
1193  }
1194  else
1195  {
1196  Sector->Res4 |= FAT_DIRTY_BIT;
1197  }
1198 
1199 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1200  /* Mark boot sector dirty so that it gets written to the disk */
1203  return STATUS_SUCCESS;
1204 #else
1205  /* Write back the boot sector to the disk */
1206  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1207  ExFreePoolWithTag(Sector, TAG_BUFFER);
1208  return Status;
1209 #endif
1210 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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:4250
#define TAG_BUFFER
Definition: vfat.h:545
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:255
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:85
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
unsigned short Signature1
Definition: vfat.h:82

Referenced by VfatMount().

◆ FAT32UpdateFreeClustersCount()

NTSTATUS FAT32UpdateFreeClustersCount ( PDEVICE_EXTENSION  DeviceExt)

Definition at line 1213 of file fat.c.

1215 {
1217  ULONG Length;
1218 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1219  NTSTATUS Status;
1220 #else
1221  PVOID Context;
1222 #endif
1223  struct _FsInfoSector * Sector;
1224 
1225  if (!DeviceExt->AvailableClustersValid)
1226  {
1227  return STATUS_INVALID_PARAMETER;
1228  }
1229 
1230  /* We'll read (and then write) the fsinfo sector */
1231  Offset.QuadPart = DeviceExt->FatInfo.FSInfoSector * DeviceExt->FatInfo.BytesPerSector;
1232  Length = DeviceExt->FatInfo.BytesPerSector;
1233 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1234  /* Go through Cc for this */
1235  _SEH2_TRY
1236  {
1237  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1238  }
1240  {
1242  }
1243  _SEH2_END;
1244 #else
1245  /* No Cc, do it the old way:
1246  * - Allocate a big enough buffer
1247  * - And read the disk
1248  */
1250  if (Sector == NULL)
1251  {
1253  }
1254 
1255  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1256  if (!NT_SUCCESS(Status))
1257  {
1258  ExFreePoolWithTag(Sector, TAG_BUFFER);
1259  return Status;
1260  }
1261 #endif
1262 
1263  /* Make sure we have a FSINFO sector */
1264  if (Sector->ExtBootSignature2 != 0x41615252 ||
1265  Sector->FSINFOSignature != 0x61417272 ||
1266  Sector->Signatur2 != 0xaa550000)
1267  {
1268  ASSERT(FALSE);
1269 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1271 #else
1272  ExFreePoolWithTag(Sector, TAG_BUFFER);
1273 #endif
1275  }
1276 
1277  /* Update the free clusters count */
1278  Sector->FreeCluster = InterlockedCompareExchange((PLONG)&DeviceExt->AvailableClusters, 0, 0);
1279 
1280 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1281  /* Mark FSINFO sector dirty so that it gets written to the disk */
1284  return STATUS_SUCCESS;
1285 #else
1286  /* Write back the FSINFO sector to the disk */
1287  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1288  ExFreePoolWithTag(Sector, TAG_BUFFER);
1289  return Status;
1290 #endif
1291 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#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:4250
#define TAG_BUFFER
Definition: vfat.h:545
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER ReadOffset, IN ULONG ReadLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:72
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject, IN PLARGE_INTEGER WriteOffset, IN ULONG WriteLength, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:255
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned long FSINFOSignature
Definition: vfat.h:101
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
unsigned long FreeCluster
Definition: vfat.h:102
unsigned long ExtBootSignature2
Definition: vfat.h:99
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725
signed int * PLONG
Definition: retypes.h:5

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

◆ FAT32WriteCluster()

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

Definition at line 659 of file fat.c.

664 {
666  ULONG FATOffset;
668  PVOID Context;
670  PULONG Cluster;
671 
672  ChunkSize = CACHEPAGESIZE(DeviceExt);
673 
674  FATOffset = (ClusterToWrite * 4);
675  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
676  _SEH2_TRY
677  {
678  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
679  }
681  {
683  }
684  _SEH2_END;
685 
686  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
687  ClusterToWrite);
688  Cluster = ((PULONG)((char*)BaseAddress + (FATOffset % ChunkSize)));
689  *OldValue = *Cluster & 0x0fffffff;
690  *Cluster = (*Cluster & 0xf0000000) | (NewValue & 0x0fffffff);
691 
694 
695  return STATUS_SUCCESS;
696 }
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:4250
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2276
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
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 ROUND_DOWN(n, align)
Definition: eventvwr.h:30
_SEH2_END
Definition: create.c:4424
unsigned int * PULONG
Definition: retypes.h:1
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1020
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by VfatMount().

◆ FindFile()

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

Definition at line 101 of file create.c.

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

◆ FsdDosDateTimeToSystemTime()

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

Definition at line 22 of file dir.c.

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

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

◆ FsdSystemTimeToDosDateTime()

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

Definition at line 53 of file dir.c.

58 {
59  PDOSTIME pdtime = (PDOSTIME)pDosTime;
60  PDOSDATE pddate = (PDOSDATE)pDosDate;
62  LARGE_INTEGER LocalTime;
63 
64  if (SystemTime == NULL)
65  return FALSE;
66 
67  ExSystemTimeToLocalTime(SystemTime, &LocalTime);
68  RtlTimeToTimeFields(&LocalTime, &TimeFields);
69 
70  if (pdtime)
71  {
72  pdtime->Second = TimeFields.Second / 2;
73  pdtime->Minute = TimeFields.Minute;
74  pdtime->Hour = TimeFields.Hour;
75  }
76 
77  if (pddate)
78  {
79  pddate->Day = TimeFields.Day;
80  pddate->Month = TimeFields.Month;
81  pddate->Year = (USHORT) (TimeFields.Year - DeviceExt->BaseDateYear);
82  }
83 
84  return TRUE;
85 }
WORD Month
Definition: cabinet.c:40
#define TRUE
Definition: types.h:120
WORD Year
Definition: cabinet.c:41
WORD Second
Definition: cabinet.c:32
struct _DOSDATE * PDOSDATE
WORD Minute
Definition: cabinet.c:33
struct _DOSTIME * PDOSTIME
WORD Hour
Definition: cabinet.c:34
smooth NULL
Definition: ftsmooth.c:416
#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
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 829 of file fat.c.

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

Referenced by VfatMount().

◆ GetNextCluster()

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

Definition at line 742 of file fat.c.

746 {
748 
749  DPRINT("GetNextCluster(DeviceExt %p, CurrentCluster %x)\n",
750  DeviceExt, CurrentCluster);
751 
752  if (CurrentCluster == 0)
753  {
754  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
756  ASSERT(CurrentCluster != 0);
758  }
759 
760  ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
761  Status = DeviceExt->GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
762  ExReleaseResourceLite(&DeviceExt->FatResource);
763 
764  return Status;
765 }
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168
void DPRINT(...)
Definition: polytest.cpp:61
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:401
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
ULONG Flags
Definition: vfat.h:407
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define DPRINT1
Definition: precomp.h:8

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

◆ GetNextClusterExtend()

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

Definition at line 771 of file fat.c.

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

Referenced by NextCluster(), and OffsetToCluster().

◆ NextCluster()

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

Definition at line 40 of file rw.c.

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

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

◆ OffsetToCluster()

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

Definition at line 61 of file rw.c.

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

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

◆ SetDirtyStatus()

NTSTATUS SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1015 of file fat.c.

1018 {
1019  NTSTATUS Status;
1020 
1021  DPRINT("SetDirtyStatus(DeviceExt %p, DirtyStatus %d)\n", DeviceExt, DirtyStatus);
1022 
1023  /* FAT12 has no dirty bit */
1024  if (DeviceExt->FatInfo.FatType == FAT12)
1025  {
1026  return STATUS_SUCCESS;
1027  }
1028 
1029  /* Not really in the FAT, but share the lock because
1030  * we're really low-level and shouldn't happent that often
1031  * And call the appropriate function
1032  * Acquire exclusive because we will modify ondisk value
1033  */
1034  ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
1035  Status = DeviceExt->SetDirtyStatus(DeviceExt, DirtyStatus);
1036  ExReleaseResourceLite(&DeviceExt->FatResource);
1037 
1038  return Status;
1039 }
#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
void DPRINT(...)
Definition: polytest.cpp:61
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2725

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

◆ vfat8Dot3ToString()

VOID vfat8Dot3ToString ( PFAT_DIR_ENTRY  pEntry,
PUNICODE_STRING  NameU 
)

Definition at line 37 of file create.c.

40 {
41  OEM_STRING StringA;
42  USHORT Length;
43  CHAR cString[12];
44 
45  RtlCopyMemory(cString, pEntry->ShortName, 11);
46  cString[11] = 0;
47  if (cString[0] == 0x05)
48  {
49  cString[0] = 0xe5;
50  }
51 
52  StringA.Buffer = cString;
53  for (StringA.Length = 0;
54  StringA.Length < 8 && StringA.Buffer[StringA.Length] != ' ';
55  StringA.Length++);
56  StringA.MaximumLength = StringA.Length;
57 
58  RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
59 
61  {
62  RtlDowncaseUnicodeString(NameU, NameU, FALSE);
63  }
64 
65  if (cString[8] != ' ')
66  {
67  Length = NameU->Length;
68  NameU->Buffer += Length / sizeof(WCHAR);
69  if (!FAT_ENTRY_VOLUME(pEntry))
70  {
71  Length += sizeof(WCHAR);
72  NameU->Buffer[0] = L'.';
73  NameU->Buffer++;
74  }
75  NameU->Length = 0;
76  NameU->MaximumLength -= Length;
77 
78  StringA.Buffer = &cString[8];
79  for (StringA.Length = 0;
80  StringA.Length < 3 && StringA.Buffer[StringA.Length] != ' ';
81  StringA.Length++);
82  StringA.MaximumLength = StringA.Length;
83  RtlOemStringToUnicodeString(NameU, &StringA, FALSE);
85  {
86  RtlDowncaseUnicodeString(NameU, NameU, FALSE);
87  }
88  NameU->Buffer -= Length / sizeof(WCHAR);
89  NameU->Length += Length;
90  NameU->MaximumLength += Length;
91  }
92 
93  NameU->Buffer[NameU->Length / sizeof(WCHAR)] = 0;
94  DPRINT("'%wZ'\n", NameU);
95 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
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
#define WCHAR
Definition: msvc.h:43
unsigned char ShortName[11]
Definition: vfat.h:115
void DPRINT(...)
Definition: polytest.cpp:61
#define FAT_ENTRY_VOLUME(DirEntry)
Definition: vfat.h:212
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define VFAT_CASE_LOWER_BASE
Definition: vfat.h:200
static const WCHAR L[]
Definition: oid.c:1087
#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
unsigned char lCase
Definition: vfat.h:118
NTSYSAPI NTSTATUS WINAPI RtlDowncaseUnicodeString(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN)

Referenced by FATGetNextDirEntry(), and ReadVolumeLabel().

◆ VfatAcquireForLazyWrite()

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

Definition at line 728 of file fastio.c.

731 {
733  ASSERT(Fcb);
734  DPRINT("VfatAcquireForLazyWrite(): Fcb %p\n", Fcb);
735 
737  {
738  DPRINT("VfatAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
739  return FALSE;
740  }
741  return TRUE;
742 }
#define TRUE
Definition: types.h:120
Definition: vfat.h:441
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ERESOURCE MainResource
Definition: ntfs.h:512
struct _VFATFCB * PVFATFCB
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN Wait
Definition: fatprocs.h:1529

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 369 of file vfat.h.

376 {
377  return DeviceExt->Dispatch.AddEntry(DeviceExt, NameU, Fcb, ParentFcb, RequestedOptions, ReqAttr, MoveContext);
378 }
_In_ PFCB ParentFcb
Definition: cdprocs.h:741
_In_ PFCB Fcb
Definition: cdprocs.h:151

Referenced by VfatCreateFile(), and VfatMoveEntry().

◆ vfatAttachFCBToFileObject()

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

Definition at line 755 of file fcb.c.

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

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

◆ VfatBlockDeviceIoControl()

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

Definition at line 432 of file blockdev.c.

440 {
441  PIO_STACK_LOCATION Stack;
442  KEVENT Event;
443  PIRP Irp;
446 
447  DPRINT("VfatBlockDeviceIoControl(DeviceObject %p, CtlCode %x, "
448  "InputBuffer %p, InputBufferSize %x, OutputBuffer %p, "
449  "OutputBufferSize %p (%x)\n", DeviceObject, CtlCode,
450  InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize,
451  OutputBufferSize ? *OutputBufferSize : 0);
452 
453 again:
455 
456  DPRINT("Building device I/O control request ...\n");
458  DeviceObject,
459  InputBuffer,
460  InputBufferSize,
461  OutputBuffer,
462  (OutputBufferSize) ? *OutputBufferSize : 0,
463  FALSE,
464  &Event,
465  &IoStatus);
466  if (Irp == NULL)
467  {
468  DPRINT("IoBuildDeviceIoControlRequest failed\n");
470  }
471 
472  if (Override)
473  {
476  }
477 
478  DPRINT("Calling IO Driver... with irp %p\n", Irp);
480 
481  DPRINT("Waiting for IO Operation for %p\n", Irp);
482  if (Status == STATUS_PENDING)
483  {
484  DPRINT("Operation pending\n");
486  DPRINT("Getting IO Status... for %p\n", Irp);
487 
488  Status = IoStatus.Status;
489  }
490 
492  {
494 
495  DPRINT1("Media change detected!\n");
496 
497  /* Find the device to verify and reset the thread field to empty value again. */
501  FALSE);
502 
503  if (NT_SUCCESS(Status))
504  {
505  DPRINT1("Volume verification successful; Reissuing IOCTL request\n");
506  goto again;
507  }
508  }
509 
510  if (OutputBufferSize)
511  {
512  *OutputBufferSize = IoStatus.Information;
513  }
514 
515  DPRINT("Returning Status %x\n", Status);
516 
517  return Status;
518 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetDeviceToVerify(IN PETHREAD Thread)
Definition: util.c:328
#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
CHAR InputBuffer[80]
Definition: conmgr.c:33
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
smooth NULL
Definition: ftsmooth.c:416
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_PENDING
Definition: ntstatus.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN AllowRawMount)
Definition: volume.c:874
VOID NTAPI IoSetDeviceToVerify(IN PETHREAD Thread, IN PDEVICE_OBJECT DeviceObject)
Definition: util.c:304
_Inout_ PIRP _In_ PDEVICE_OBJECT DeviceToVerify
Definition: cdprocs.h:1417

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 417 of file misc.c.

420 {
421  KIRQL OldIrql;
422  ULONG UnCleanCount;
423  PVPB Vpb;
424  BOOLEAN Delete;
425 
426  DPRINT1("VfatCheckForDismount(%p, %u)\n", DeviceExt, Force);
427 
428  /* If the VCB is OK (not under uninitialization) and we don't force dismount, do nothing */
429  if (BooleanFlagOn(DeviceExt->Flags, VCB_GOOD) && !Force)
430  {
431  return FALSE;
432  }
433 
434  /*
435  * NOTE: In their *CheckForDismount() function, our 3rd-party FS drivers
436  * as well as MS' fastfat, perform a comparison check of the current VCB's
437  * VPB ReferenceCount with some sort of "dangling"/"residual" open count,
438  * depending on whether or not we are in IRP_MJ_CREATE.
439  * It seems to be related to the fact that the volume root directory as
440  * well as auxiliary data stream(s) are still opened, and only these are
441  * allowed to be opened at that moment. After analysis it appears that for
442  * the ReactOS' fastfat, this number is equal to "3".
443  */
444  UnCleanCount = 3;
445 
446  /* Lock VPB */
448 
449  /* Reference it and check if a create is being done */
450  Vpb = DeviceExt->IoVPB;
451  DPRINT("Vpb->ReferenceCount = %d\n", Vpb->ReferenceCount);
452  if (Vpb->ReferenceCount != UnCleanCount || DeviceExt->OpenHandleCount != 0)
453  {
454  /* If we force-unmount, copy the VPB to our local own to prepare later dismount */
455  if (Force && Vpb->RealDevice->Vpb == Vpb && DeviceExt->SpareVPB != NULL)
456  {
457  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
458  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
459  DeviceExt->SpareVPB->Size = sizeof(VPB);
460  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
461  DeviceExt->SpareVPB->DeviceObject = NULL;
462  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
463  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
464  DeviceExt->SpareVPB = NULL;
465  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
466 
467  /* We are uninitializing, the VCB cannot be used anymore */
468  ClearFlag(DeviceExt->Flags, VCB_GOOD);
469  }
470 
471  /* Don't do anything for now */
472  Delete = FALSE;
473  }
474  else
475  {
476  /* Otherwise, delete the volume */
477  Delete = TRUE;
478 
479  /* Swap the VPB with our local own */
480  if (Vpb->RealDevice->Vpb == Vpb && DeviceExt->SpareVPB != NULL)
481  {
482  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
483  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
484  DeviceExt->SpareVPB->Size = sizeof(VPB);
485  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
486  DeviceExt->SpareVPB->DeviceObject = NULL;
487  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
488  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
489  DeviceExt->SpareVPB = NULL;
490  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
491 
492  /* We are uninitializing, the VCB cannot be used anymore */
493  ClearFlag(DeviceExt->Flags, VCB_GOOD);
494  }
495 
496  /*
497  * We defer setting the VPB's DeviceObject to NULL for later because
498  * we want to handle the closing of the internal opened meta-files.
499  */
500 
501  /* Clear the mounted and locked flags in the VPB */
502  ClearFlag(Vpb->Flags, VPB_MOUNTED | VPB_LOCKED);
503  }
504 
505  /* Release lock and return status */
507 
508  /* If we were to delete, delete volume */
509  if (Delete)
510  {
511  LARGE_INTEGER Zero = {{0,0}};
512  PVFATFCB Fcb;
513 
514  /* We are uninitializing, the VCB cannot be used anymore */
515  ClearFlag(DeviceExt->Flags, VCB_GOOD);
516 
517  /* Invalidate and close the internal opened meta-files */
518  if (DeviceExt->RootFcb)
519  {
520  Fcb = DeviceExt->RootFcb;
522  &Zero,
523  NULL);
525  DeviceExt->RootFcb = NULL;
527  }
528  if (DeviceExt->VolumeFcb)
529  {
530  Fcb = DeviceExt->VolumeFcb;
531 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
533  &Zero,
534  NULL);
536 #endif
537  DeviceExt->VolumeFcb = NULL;
539  }
540  if (DeviceExt->FATFileObject)
541  {
542  Fcb = DeviceExt->FATFileObject->FsContext;
543  CcUninitializeCacheMap(DeviceExt->FATFileObject,
544  &Zero,
545  NULL);
546  DeviceExt->FATFileObject->FsContext = NULL;
547  ObDereferenceObject(DeviceExt->FATFileObject);
548  DeviceExt->FATFileObject = NULL;
550  }
551 
552  /*
553  * Now that the closing of the internal opened meta-files has been
554  * handled, we can now set the VPB's DeviceObject to NULL.
555  */
556  Vpb->DeviceObject = NULL;
557 
558  /* If we have a local VPB, we'll have to delete it
559  * but we won't dismount us - something went bad before
560  */
561  if (DeviceExt->SpareVPB)
562  {
563  ExFreePool(DeviceExt->SpareVPB);
564  }
565  /* Otherwise, delete any of the available VPB if its reference count is zero */
566  else if (DeviceExt->IoVPB->ReferenceCount == 0)
567  {
568  ExFreePool(DeviceExt->IoVPB);
569  }
570 
571  /* Remove the volume from the list */
573  RemoveEntryList(&DeviceExt->VolumeListEntry);
575 
576  /* Uninitialize the notify synchronization object */
577  FsRtlNotifyUninitializeSync(&DeviceExt->NotifySync);
578 
579  /* Release resources */
580  ExFreePoolWithTag(DeviceExt->Statistics, TAG_STATS);
581  ExDeleteResourceLite(&DeviceExt->DirResource);
582  ExDeleteResourceLite(&DeviceExt->FatResource);
583 
584  /* Dismount our device if possible */
585  ObfDereferenceObject(DeviceExt->StorageDevice);
586  IoDeleteDevice(DeviceExt->VolumeDevice);
587  }
588 
589  return Delete;
590 }
LONG_PTR FASTCALL ObfDereferenceObject(IN PVOID Object)
Definition: obref.c:320
#define TRUE
Definition: types.h:120
Definition: vfat.h:441
PFILE_OBJECT FileObject
Definition: ntfs.h:504
#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:1201
PVPB Vpb
Definition: cdstruc.h:517
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define VPB_PERSISTENT
Definition: iotypes.h:1765
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 VPB_LOCKED
Definition: iotypes.h:1764
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
VOID vfatDestroyFCB(PVFATFCB pFCB)
Definition: fcb.c:269
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define VCB_GOOD
Definition: vfat.h:247
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define IO_TYPE_VPB
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
struct _VPB VPB
#define TAG_STATS
Definition: vfat.h:544
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:402
#define DPRINT1
Definition: precomp.h:8
ERESOURCE VolumeListLock
Definition: vfat.h:409
Definition: iotypes.h:166
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI FsRtlNotifyUninitializeSync(IN PNOTIFY_SYNC *NotifySync)
Definition: notify.c:1639
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_In_ PFCB Fcb
Definition: cdprocs.h:151
#define VPB_MOUNTED
Definition: iotypes.h:1763
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1212
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1664
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Inout_ PVCB _In_ BOOLEAN Force
Definition: cdprocs.h:1425

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

◆ VfatCleanup()

NTSTATUS VfatCleanup ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 175 of file cleanup.c.

177 {
179 
180  DPRINT("VfatCleanup(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
181 
182  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
183  {
184  IrpContext->Irp->IoStatus.Information = 0;
185  return STATUS_SUCCESS;
186  }
187 
188  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
189  Status = VfatCleanupFile(IrpContext);
190  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
191 
192  IrpContext->Irp->IoStatus.Information = 0;
193  return Status;
194 }
#define TRUE
Definition: types.h:120
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:579
static NTSTATUS VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
Definition: cleanup.c:24
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:406
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Status
Definition: gdiplustypes.h:24
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:578
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by VfatDispatchRequest().

◆ VfatClose()

NTSTATUS VfatClose ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 213 of file close.c.

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

Referenced by VfatDispatchRequest().

◆ VfatCloseFile()

NTSTATUS VfatCloseFile ( PDEVICE_EXTENSION  DeviceExt,
PFILE_OBJECT  FileObject 
)

Definition at line 160 of file close.c.

163 {
164  PVFATFCB pFcb;
165  PVFATCCB pCcb;
166  BOOLEAN IsVolume;
168 
169  DPRINT("VfatCloseFile(DeviceExt %p, FileObject %p)\n",
170  DeviceExt, FileObject);
171 
172  /* FIXME : update entry in directory? */
173  pCcb = (PVFATCCB) (FileObject->FsContext2);
174  pFcb = (PVFATFCB) (FileObject->FsContext);
175 
176  if (pFcb == NULL)
177  {
178  return STATUS_SUCCESS;
179  }
180 
181  IsVolume = BooleanFlagOn(pFcb->Flags, FCB_IS_VOLUME);
182 
183  if (pCcb)
184  {
185  vfatDestroyCCB(pCcb);
186  }
187 
188  /* If we have to close immediately, or if delaying failed, close */
191  {
192  VfatCommonCloseFile(DeviceExt, pFcb);
193  }
194 
195  FileObject->FsContext2 = NULL;
196  FileObject->FsContext = NULL;
197  FileObject->SectionObjectPointer = NULL;
198 
199 #ifdef ENABLE_SWAPOUT
200  if (IsVolume && DeviceExt->OpenHandleCount == 0)
201  {
202  VfatCheckForDismount(DeviceExt, FALSE);
203  }
204 #endif
205 
206  return Status;
207 }
NTSTATUS VfatPostCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: close.c:116
Definition: vfat.h:441
Definition: vfat.h:530
struct _VFATCCB * PVFATCCB
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
LONG NTSTATUS
Definition: precomp.h:26
ULONG Flags
Definition: vfat.h:490
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID vfatDestroyCCB(PVFATCCB pCcb)
Definition: fcb.c:258
BOOLEAN VfatCheckForDismount(IN PDEVICE_EXTENSION DeviceExt, IN BOOLEAN Force)
Definition: misc.c:417
struct _VFATFCB * PVFATFCB
Status
Definition: gdiplustypes.h:24
#define FCB_DELAYED_CLOSE
Definition: vfat.h:433
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define FCB_IS_VOLUME
Definition: vfat.h:431
BOOLEAN ShutdownStarted
Definition: vfat.h:422
return STATUS_SUCCESS
Definition: btrfs.c:2725
VOID VfatCommonCloseFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB pFcb)
Definition: close.c:20

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

◆ VfatCreate()

NTSTATUS VfatCreate ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 1083 of file create.c.

1085 {
1086  NTSTATUS Status;
1087 
1088  ASSERT(IrpContext);
1089 
1090  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
1091  {
1092  /* DeviceObject represents FileSystem instead of logical volume */
1093  DPRINT ("FsdCreate called with file system\n");
1094  IrpContext->Irp->IoStatus.Information = FILE_OPENED;
1095  IrpContext->PriorityBoost = IO_DISK_INCREMENT;
1096 
1097  return STATUS_SUCCESS;
1098  }
1099 
1100  IrpContext->Irp->IoStatus.Information = 0;
1101  ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, TRUE);
1102  Status = VfatCreateFile(IrpContext->DeviceObject, IrpContext->Irp);
1103  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
1104 
1105  if (NT_SUCCESS(Status))
1106  IrpContext->PriorityBoost = IO_DISK_INCREMENT;
1107 
1108  return Status;
1109 }
#define TRUE
Definition: types.h:120
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:579
Iosb Status
Definition: create.c:4311
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
CCHAR PriorityBoost
Definition: vfat.h:588
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:578
return STATUS_SUCCESS
Definition: btrfs.c:2725
static NTSTATUS VfatCreateFile(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: create.c:424

Referenced by VfatDispatchRequest().

◆ VfatDelEntry()

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

Definition at line 382 of file vfat.h.

385 {
386  return DeviceExt->Dispatch.DelEntry(DeviceExt, Fcb, MoveContext);
387 }
_In_ PFCB Fcb
Definition: cdprocs.h:151

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

◆ vfatDestroyCCB()

VOID vfatDestroyCCB ( PVFATCCB  pCcb)

Definition at line 258 of file fcb.c.

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

Referenced by VfatCloseFile(), and VfatMount().

◆ vfatDestroyFCB()

VOID vfatDestroyFCB ( PVFATFCB  pFCB)

Definition at line 269 of file fcb.c.

271 {
272 #ifdef KDBG
273  if (DebugFile.Buffer != NULL && FsRtlIsNameInExpression(&DebugFile, &pFCB->LongNameU, FALSE, NULL))
274  {
275  DPRINT1("Destroying: %p (%wZ) %d\n", pFCB, &pFCB->PathNameU, pFCB->RefCount);
276  }
277 #endif
278 
280 
281  if (!vfatFCBIsRoot(pFCB) &&
283  {
285  }
286  ExFreePool(pFCB->PathNameBuffer);
290  ExFreeToNPagedLookasideList(&VfatGlobalData->FcbLookasideList, pFCB);
291 }
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: vfat.h:411
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
Definition: filelock.c:1278
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
UNICODE_STRING LongNameU
Definition: vfat.h:457
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
Definition: fcb.c:294
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN NTAPI FsRtlIsNameInExpression(IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
Definition: name.c:514
LONG RefCount
Definition: vfat.h:475
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
ULONG Flags
Definition: vfat.h:490
smooth NULL
Definition: ftsmooth.c:416
FILE_LOCK FileLock
Definition: vfat.h:514
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define FCB_IS_FAT
Definition: vfat.h:429
PWCHAR PathNameBuffer
Definition: vfat.h:469
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define FCB_IS_VOLUME
Definition: vfat.h:431
ERESOURCE PagingIoResource
Definition: vfat.h:447
ERESOURCE MainResource
Definition: vfat.h:446
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING PathNameU
Definition: vfat.h:466
LIST_ENTRY ParentListHead
Definition: vfat.h:487
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LIST_ENTRY ParentListEntry
Definition: vfat.h:481

Referenced by VfatCheckForDismount(), VfatDismountVolume(), VfatMount(), and vfatReleaseFCB().

◆ VfatDirectoryControl()

NTSTATUS VfatDirectoryControl ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 728 of file dir.c.

730 {
732 
733  IrpContext->Irp->IoStatus.Information = 0;
734 
735  switch (IrpContext->MinorFunction)
736  {
738  Status = DoQuery (IrpContext);
739  break;
740 
742