ReactOS  0.4.11-dev-765-g5e024bf
vfat.h File Reference
#include <ntifs.h>
#include <ntdddisk.h>
#include <dos.h>
#include <pseh/pseh2.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 INIT_SECTION   /* Done via alloc_text for MSC */
 
#define USE_ROS_CC_AND_FS
 
#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 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_CONTEXT
PVFAT_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_CONTEXT
PVFAT_CLOSE_CONTEXT
 

Functions

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

#define BLOCKSIZE   512

Definition at line 233 of file vfat.h.

#define CCB_DELETE_ON_CLOSE   0x0001

Definition at line 526 of file vfat.h.

#define ENTRIES_PER_SECTOR   (BLOCKSIZE / sizeof(FATDirEntry))

Definition at line 549 of file vfat.h.

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

Definition at line 206 of file vfat.h.

Referenced by vfatFindDirSpace().

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

Definition at line 208 of file vfat.h.

Referenced by FsdSetFsLabelInformation(), ReadVolumeLabel(), and vfatFindDirSpace().

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

Definition at line 207 of file vfat.h.

Referenced by FindFile(), FsdSetFsLabelInformation(), ReadVolumeLabel(), and vfatDirFindFile().

#define FAT12   (2)

Definition at line 236 of file vfat.h.

#define FAT16   (1)

Definition at line 235 of file vfat.h.

#define FAT32   (3)

Definition at line 237 of file vfat.h.

#define FAT_DIRTY_BIT   0x01
#define FAT_EAFILE   "EA DATA. SF"

Definition at line 133 of file vfat.h.

#define FAT_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof (FAT_DIR_ENTRY))
#define FAT_ENTRY_DELETED (   DirEntry)    ((DirEntry)->Filename[0] == 0xe5)

Definition at line 210 of file vfat.h.

Referenced by FATGetNextDirEntry(), and FATIsDirectoryEmpty().

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

Definition at line 211 of file vfat.h.

Referenced by FATGetNextDirEntry(), and FATIsDirectoryEmpty().

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

Definition at line 212 of file vfat.h.

Referenced by FATGetNextDirEntry().

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

Definition at line 213 of file vfat.h.

Referenced by vfat8Dot3ToString().

#define FATX16   (4)

Definition at line 238 of file vfat.h.

#define FATX32   (5)

Definition at line 239 of file vfat.h.

#define FATX_ENTRIES_PER_PAGE   (PAGE_SIZE / sizeof (FATX_DIR_ENTRY))
#define FATX_ENTRY_DELETED (   DirEntry)    ((DirEntry)->FilenameLength == 0xe5)

Definition at line 215 of file vfat.h.

Referenced by FATXGetNextDirEntry(), and FATXIsDirectoryEmpty().

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

Definition at line 216 of file vfat.h.

Referenced by FATXGetNextDirEntry(), and FATXIsDirectoryEmpty().

#define FATX_ENTRY_LONG (   DirEntry)    (FALSE)

Definition at line 217 of file vfat.h.

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

Definition at line 218 of file vfat.h.

#define FCB_DELAYED_CLOSE   0x0040

Definition at line 431 of file vfat.h.

Referenced by VfatCleanupFile(), VfatCloseFile(), VfatCloseWorker(), and VfatOpenFile().

#define FCB_DELETE_PENDING   0x0002

Definition at line 426 of file vfat.h.

#define FCB_IS_DIRTY   0x0020
#define FCB_IS_FAT   0x0004
#define INIT_SECTION   /* Done via alloc_text for MSC */

Definition at line 16 of file vfat.h.

#define IRPCONTEXT_DEFERRED_WRITE   0x0010

Definition at line 571 of file vfat.h.

Referenced by VfatWrite().

#define IRPCONTEXT_PENDINGRETURNED   0x0008

Definition at line 570 of file vfat.h.

Referenced by VfatReadWritePartialCompletion().

#define IRPCONTEXT_QUEUE   0x0004
#define LONGNAME_MAX_LENGTH   256

Definition at line 204 of file vfat.h.

Referenced by DoQuery(), FATAddEntry(), FindFile(), and vfatMakeFullName().

#define NODE_TYPE_FCB   ((CSHORT)0x0502)
#define ROUND_DOWN (   n,
  align 
)    (((ULONG)n) & ~((align) - 1l))

Definition at line 26 of file vfat.h.

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

Definition at line 32 of file vfat.h.

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

Definition at line 29 of file vfat.h.

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

Definition at line 35 of file vfat.h.

Referenced by UpdateFileSize(), VfatCommonRead(), vfatInitFCBFromDirEntry(), and VfatReadFileData().

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

Definition at line 303 of file vfat.h.

#define TAG_CCB   'CtaF'

Definition at line 538 of file vfat.h.

#define TAG_CLOSE   'xtaF'

Definition at line 541 of file vfat.h.

Referenced by DriverEntry().

#define TAG_DIRENT   'DtaF'

Definition at line 547 of file vfat.h.

Referenced by FATAddEntry(), FatSetRenameInfo(), and ReadVolumeLabel().

#define TAG_IRP   'ItaF'

Definition at line 540 of file vfat.h.

Referenced by DriverEntry(), IoAllocateIrp(), and IoFreeIrp().

#define TAG_NAME   'ntaF'

Definition at line 545 of file vfat.h.

#define TAG_SEARCH   'LtaF'

Definition at line 546 of file vfat.h.

Referenced by DoQuery(), and vfatDestroyCCB().

#define TAG_STATS   'VtaF'

Definition at line 542 of file vfat.h.

Referenced by VfatDismountVolume(), and VfatMount().

#define TAG_VPB   'vtaF'

Definition at line 544 of file vfat.h.

#define USE_ROS_CC_AND_FS

Definition at line 19 of file vfat.h.

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

Definition at line 242 of file vfat.h.

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

Definition at line 243 of file vfat.h.

Referenced by VfatMount(), and vfatVolumeIsFatX().

#define VCB_IS_SYS_OR_HAS_PAGE   0x0008

Definition at line 244 of file vfat.h.

Referenced by VfatCreateFile(), VfatDismountVolume(), VfatLockOrUnlockVolume(), and VfatMount().

#define VCB_VOLUME_LOCKED   0x0001

Definition at line 241 of file vfat.h.

#define VFAT_BREAK_ON_CORRUPTION   1
#define VFAT_CASE_LOWER_BASE   8

Definition at line 201 of file vfat.h.

Referenced by FATAddEntry(), and vfat8Dot3ToString().

#define VFAT_CASE_LOWER_EXT   16

Definition at line 202 of file vfat.h.

Referenced by FATAddEntry(), and vfat8Dot3ToString().

#define vfatAddToStat (   Vcb,
  Stat,
  Inc 
)
Value:
{ \
Stats->Stat += Inc; \
}
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:325
struct _STATISTICS * PSTATISTICS
ULONG NumberProcessors
Definition: vfat.h:406
#define Vcb
Definition: cdprocs.h:1425

Definition at line 663 of file vfat.h.

Referenced by VfatCommonRead(), VfatCreateFile(), and VfatWrite().

Typedef Documentation

Definition at line 109 of file vfat.h.

typedef union _DIR_ENTRY DIR_ENTRY

Definition at line 231 of file vfat.h.

Definition at line 168 of file vfat.h.

Definition at line 135 of file vfat.h.

Definition at line 157 of file vfat.h.

Definition at line 144 of file vfat.h.

Definition at line 223 of file vfat.h.

Definition at line 289 of file vfat.h.

Definition at line 290 of file vfat.h.

Definition at line 282 of file vfat.h.

typedef union _DIR_ENTRY * PDIR_ENTRY

Definition at line 231 of file vfat.h.

Definition at line 168 of file vfat.h.

Definition at line 135 of file vfat.h.

Definition at line 157 of file vfat.h.

Definition at line 144 of file vfat.h.

typedef struct FATINFO * PFATINFO

Definition at line 223 of file vfat.h.

typedef NTSTATUS(* PFIND_AND_MARK_AVAILABLE_CLUSTER)(PDEVICE_EXTENSION, PULONG)

Definition at line 285 of file vfat.h.

typedef NTSTATUS(* PGET_DIRTY_STATUS)(PDEVICE_EXTENSION, PBOOLEAN)

Definition at line 292 of file vfat.h.

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

Definition at line 284 of file vfat.h.

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

Definition at line 291 of file vfat.h.

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

Definition at line 288 of file vfat.h.

typedef NTSTATUS(* PSET_DIRTY_STATUS)(PDEVICE_EXTENSION, BOOLEAN)

Definition at line 293 of file vfat.h.

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

Definition at line 286 of file vfat.h.

typedef struct _slot slot

Definition at line 197 of file vfat.h.

Function Documentation

ULONGLONG ClusterToSector ( PDEVICE_EXTENSION  DeviceExt,
ULONG  Cluster 
)

Definition at line 735 of file fat.c.

Referenced by VfatReadFileData(), and VfatWriteFileData().

738 {
739  return DeviceExt->FatInfo.dataStart +
740  ((ULONGLONG)(Cluster - 2) * DeviceExt->FatInfo.SectorsPerCluster);
741 
742 }
uint64_t ULONGLONG
Definition: typedefs.h:65
NTSTATUS CountAvailableClusters ( PDEVICE_EXTENSION  DeviceExt,
PLARGE_INTEGER  Clusters 
)

Definition at line 545 of file fat.c.

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

548 {
550  ExAcquireResourceExclusiveLite (&DeviceExt->FatResource, TRUE);
551  if (!DeviceExt->AvailableClustersValid)
552  {
553  if (DeviceExt->FatInfo.FatType == FAT12)
554  Status = FAT12CountAvailableClusters(DeviceExt);
555  else if (DeviceExt->FatInfo.FatType == FAT16 || DeviceExt->FatInfo.FatType == FATX16)
556  Status = FAT16CountAvailableClusters(DeviceExt);
557  else
558  Status = FAT32CountAvailableClusters(DeviceExt);
559  }
560  if (Clusters != NULL)
561  {
562  Clusters->QuadPart = DeviceExt->AvailableClusters;
563  }
564  ExReleaseResourceLite (&DeviceExt->FatResource);
565 
566  return Status;
567 }
#define FAT12
Definition: fat.h:167
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
static NTSTATUS FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:439
smooth NULL
Definition: ftsmooth.c:416
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:385
static NTSTATUS FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
Definition: fat.c:494
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
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:2710
NTSTATUS FAT12FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 248 of file fat.c.

Referenced by VfatMount().

251 {
252  ULONG FatLength;
253  ULONG StartCluster;
254  ULONG Entry;
255  PUSHORT CBlock;
256  ULONG i, j;
258  PVOID Context;
260 
261  FatLength = DeviceExt->FatInfo.NumberOfClusters + 2;
262  *Cluster = 0;
263  StartCluster = DeviceExt->LastAvailableCluster;
264  Offset.QuadPart = 0;
265  _SEH2_TRY
266  {
267  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
268  }
270  {
271  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector);
273  }
274  _SEH2_END;
275 
276  for (j = 0; j < 2; j++)
277  {
278  for (i = StartCluster; i < FatLength; i++)
279  {
280  CBlock = (PUSHORT)((char*)BaseAddress + (i * 12) / 8);
281  if ((i % 2) == 0)
282  {
283  Entry = *CBlock & 0xfff;
284  }
285  else
286  {
287  Entry = *CBlock >> 4;
288  }
289 
290  if (Entry == 0)
291  {
292  DPRINT("Found available cluster 0x%x\n", i);
293  DeviceExt->LastAvailableCluster = *Cluster = i;
294  if ((i % 2) == 0)
295  *CBlock = (*CBlock & 0xf000) | 0xfff;
296  else
297  *CBlock = (*CBlock & 0xf) | 0xfff0;
298  CcSetDirtyPinnedData(Context, NULL);
299  CcUnpinData(Context);
300  if (DeviceExt->AvailableClustersValid)
301  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
302  return STATUS_SUCCESS;
303  }
304  }
305  FatLength = StartCluster;
306  StartCluster = 2;
307  }
308  CcUnpinData(Context);
309  return STATUS_DISK_FULL;
310 }
DWORD *typedef PVOID
Definition: winlogon.h:61
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
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
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_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
unsigned short * PUSHORT
Definition: retypes.h:2
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:1027
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:2710
signed int * PLONG
Definition: retypes.h:5
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT12GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 127 of file fat.c.

Referenced by VfatMount().

131 {
132  PUSHORT CBlock;
133  ULONG Entry;
135  PVOID Context;
137 
138  *NextCluster = 0;
139 
140  Offset.QuadPart = 0;
141  _SEH2_TRY
142  {
143  CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, MAP_WAIT, &Context, &BaseAddress);
144  }
146  {
148  }
149  _SEH2_END;
150 
151  CBlock = (PUSHORT)((char*)BaseAddress + (CurrentCluster * 12) / 8);
152  if ((CurrentCluster % 2) == 0)
153  {
154  Entry = *CBlock & 0x0fff;
155  }
156  else
157  {
158  Entry = *CBlock >> 4;
159  }
160 
161 // DPRINT("Entry %x\n",Entry);
162  if (Entry >= 0xff8 && Entry <= 0xfff)
163  Entry = 0xffffffff;
164 
165 // DPRINT("Returning %x\n",Entry);
166  ASSERT(Entry != 0);
167  *NextCluster = Entry;
168  CcUnpinData(Context);
169 // return Entry == 0xffffffff ? STATUS_END_OF_FILE : STATUS_SUCCESS;
170  return STATUS_SUCCESS;
171 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
struct _Entry Entry
Definition: kefuncs.h:640
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
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
unsigned short * PUSHORT
Definition: retypes.h:2
_SEH2_END
Definition: create.c:4424
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT12WriteCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  ClusterToWrite,
ULONG  NewValue,
PULONG  OldValue 
)

Definition at line 574 of file fat.c.

Referenced by VfatMount().

579 {
580  ULONG FATOffset;
581  PUCHAR CBlock;
583  PVOID Context;
585 
586  Offset.QuadPart = 0;
587  _SEH2_TRY
588  {
589  CcPinRead(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, PIN_WAIT, &Context, &BaseAddress);
590  }
592  {
594  }
595  _SEH2_END;
596  CBlock = (PUCHAR)BaseAddress;
597 
598  FATOffset = (ClusterToWrite * 12) / 8;
599  DPRINT("Writing 0x%x for 0x%x at 0x%x\n",
600  NewValue, ClusterToWrite, FATOffset);
601  if ((ClusterToWrite % 2) == 0)
602  {
603  *OldValue = CBlock[FATOffset] + ((CBlock[FATOffset + 1] & 0x0f) << 8);
604  CBlock[FATOffset] = (UCHAR)NewValue;
605  CBlock[FATOffset + 1] &= 0xf0;
606  CBlock[FATOffset + 1] |= (NewValue & 0xf00) >> 8;
607  }
608  else
609  {
610  *OldValue = (CBlock[FATOffset] >> 4) + (CBlock[FATOffset + 1] << 4);
611  CBlock[FATOffset] &= 0x0f;
612  CBlock[FATOffset] |= (NewValue & 0xf) << 4;
613  CBlock[FATOffset + 1] = (UCHAR)(NewValue >> 4);
614  }
615  /* Write the changed FAT sector(s) to disk */
616  CcSetDirtyPinnedData(Context, NULL);
617  CcUnpinData(Context);
618  return STATUS_SUCCESS;
619 }
DWORD *typedef PVOID
Definition: winlogon.h:61
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:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT16FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 177 of file fat.c.

Referenced by VfatMount().

180 {
181  ULONG FatLength;
182  ULONG StartCluster;
183  ULONG i, j;
186  PVOID Context = 0;
188  PUSHORT Block;
189  PUSHORT BlockEnd;
190 
191  ChunkSize = CACHEPAGESIZE(DeviceExt);
192  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
193  *Cluster = 0;
194  StartCluster = DeviceExt->LastAvailableCluster;
195 
196  for (j = 0; j < 2; j++)
197  {
198  for (i = StartCluster; i < FatLength;)
199  {
200  Offset.QuadPart = ROUND_DOWN(i * 2, ChunkSize);
201  _SEH2_TRY
202  {
203  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
204  }
206  {
207  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
209  }
210  _SEH2_END;
211 
212  Block = (PUSHORT)((ULONG_PTR)BaseAddress + (i * 2) % ChunkSize);
213  BlockEnd = (PUSHORT)((ULONG_PTR)BaseAddress + ChunkSize);
214 
215  /* Now process the whole block */
216  while (Block < BlockEnd && i < FatLength)
217  {
218  if (*Block == 0)
219  {
220  DPRINT("Found available cluster 0x%x\n", i);
221  DeviceExt->LastAvailableCluster = *Cluster = i;
222  *Block = 0xffff;
223  CcSetDirtyPinnedData(Context, NULL);
224  CcUnpinData(Context);
225  if (DeviceExt->AvailableClustersValid)
226  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
227  return STATUS_SUCCESS;
228  }
229 
230  Block++;
231  i++;
232  }
233 
234  CcUnpinData(Context);
235  }
236 
237  FatLength = StartCluster;
238  StartCluster = 2;
239  }
240 
241  return STATUS_DISK_FULL;
242 }
DWORD *typedef PVOID
Definition: winlogon.h:61
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
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
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_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
unsigned short * PUSHORT
Definition: retypes.h:2
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:2710
signed int * PLONG
Definition: retypes.h:5
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT16GetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
PBOOLEAN  DirtyStatus 
)

Definition at line 862 of file fat.c.

Referenced by VfatMount().

865 {
867  ULONG Length;
868 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
870 #else
871  PVOID Context;
872 #endif
873  struct _BootSector * Sector;
874 
875  /* We'll read the bootsector at 0 */
876  Offset.QuadPart = 0;
877  Length = DeviceExt->FatInfo.BytesPerSector;
878 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
879  /* Go through Cc for this */
880  _SEH2_TRY
881  {
882  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
883  }
885  {
887  }
888  _SEH2_END;
889 #else
890  /* No Cc, do it the old way:
891  * - Allocate a big enough buffer
892  * - And read the disk
893  */
894  Sector = ExAllocatePoolWithTag(NonPagedPool, Length, TAG_BUFFER);
895  if (Sector == NULL)
896  {
897  *DirtyStatus = TRUE;
899  }
900 
901  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
902  if (!NT_SUCCESS(Status))
903  {
904  *DirtyStatus = TRUE;
905  ExFreePoolWithTag(Sector, TAG_BUFFER);
906  return Status;
907  }
908 #endif
909 
910  /* Make sure we have a boot sector...
911  * FIXME: This check is a bit lame and should be improved
912  */
913  if (Sector->Signatur1 != 0xaa55)
914  {
915  /* Set we are dirty so that we don't attempt anything */
916  *DirtyStatus = TRUE;
917 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
918  CcUnpinData(Context);
919 #else
920  ExFreePoolWithTag(Sector, TAG_BUFFER);
921 #endif
923  }
924 
925  /* Return the status of the dirty bit */
926  if (Sector->Res1 & FAT_DIRTY_BIT)
927  *DirtyStatus = TRUE;
928  else
929  *DirtyStatus = FALSE;
930 
931 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
932  CcUnpinData(Context);
933 #else
934  ExFreePoolWithTag(Sector, TAG_BUFFER);
935 #endif
936  return STATUS_SUCCESS;
937 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
#define TAG_BUFFER
Definition: vfat.h:543
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
unsigned short Signatur1
Definition: vfat.h:55
#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
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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
VOID UINTN Length
Definition: acefiex.h:744
unsigned char Res1
Definition: vfat.h:51
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:86
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT16GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 81 of file fat.c.

Referenced by VfatMount().

85 {
88  ULONG FATOffset;
90  PVOID Context;
92 
93  ChunkSize = CACHEPAGESIZE(DeviceExt);
94  FATOffset = CurrentCluster * 2;
95  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
96  _SEH2_TRY
97  {
98  CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress);
99  }
101  {
103  }
104  _SEH2_END;
105 
106  CurrentCluster = *((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
107  if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
108  CurrentCluster = 0xffffffff;
109 
110  if (CurrentCluster == 0)
111  {
112  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
113  Status = STATUS_FILE_CORRUPT_ERROR;
115  ASSERT(CurrentCluster != 0);
116  }
117 
118  CcUnpinData(Context);
119  *NextCluster = CurrentCluster;
120  return Status;
121 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
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
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
unsigned short * PUSHORT
Definition: retypes.h:2
Status
Definition: gdiplustypes.h:24
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:399
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:405
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT16SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1048 of file fat.c.

Referenced by VfatMount().

1051 {
1053  ULONG Length;
1054 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1055  NTSTATUS Status;
1056 #else
1057  PVOID Context;
1058 #endif
1059  struct _BootSector * Sector;
1060 
1061  /* We'll read (and then write) the bootsector at 0 */
1062  Offset.QuadPart = 0;
1063  Length = DeviceExt->FatInfo.BytesPerSector;
1064 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1065  /* Go through Cc for this */
1066  _SEH2_TRY
1067  {
1068  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1069  }
1071  {
1073  }
1074  _SEH2_END;
1075 #else
1076  /* No Cc, do it the old way:
1077  * - Allocate a big enough buffer
1078  * - And read the disk
1079  */
1080  Sector = ExAllocatePoolWithTag(NonPagedPool, Length, TAG_BUFFER);
1081  if (Sector == NULL)
1082  {
1084  }
1085 
1086  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1087  if (!NT_SUCCESS(Status))
1088  {
1089  ExFreePoolWithTag(Sector, TAG_BUFFER);
1090  return Status;
1091  }
1092 #endif
1093 
1094  /* Make sure we have a boot sector...
1095  * FIXME: This check is a bit lame and should be improved
1096  */
1097  if (Sector->Signatur1 != 0xaa55)
1098  {
1099 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1100  CcUnpinData(Context);
1101 #else
1102  ExFreePoolWithTag(Sector, TAG_BUFFER);
1103 #endif
1105  }
1106 
1107  /* Modify the dirty bit status according
1108  * to caller needs
1109  */
1110  if (!DirtyStatus)
1111  {
1112  Sector->Res1 &= ~FAT_DIRTY_BIT;
1113  }
1114  else
1115  {
1116  Sector->Res1 |= FAT_DIRTY_BIT;
1117  }
1118 
1119 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1120  /* Mark boot sector dirty so that it gets written to the disk */
1121  CcSetDirtyPinnedData(Context, NULL);
1122  CcUnpinData(Context);
1123  return STATUS_SUCCESS;
1124 #else
1125  /* Write back the boot sector to the disk */
1126  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1127  ExFreePoolWithTag(Sector, TAG_BUFFER);
1128  return Status;
1129 #endif
1130 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#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
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:543
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
unsigned short Signatur1
Definition: vfat.h:55
#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
LONG NTSTATUS
Definition: precomp.h:26
#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
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
VOID UINTN Length
Definition: acefiex.h:744
unsigned char Res1
Definition: vfat.h:51
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:86
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT16WriteCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  ClusterToWrite,
ULONG  NewValue,
PULONG  OldValue 
)

Definition at line 625 of file fat.c.

Referenced by VfatMount().

630 {
632  ULONG FATOffset;
634  PVOID Context;
636  PUSHORT Cluster;
637 
638  ChunkSize = CACHEPAGESIZE(DeviceExt);
639  FATOffset = ClusterToWrite * 2;
640  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
641  _SEH2_TRY
642  {
643  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
644  }
646  {
648  }
649  _SEH2_END;
650 
651  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
652  ClusterToWrite);
653  Cluster = ((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize)));
654  *OldValue = *Cluster;
655  *Cluster = (USHORT)NewValue;
656  CcSetDirtyPinnedData(Context, NULL);
657  CcUnpinData(Context);
658  return STATUS_SUCCESS;
659 }
DWORD *typedef PVOID
Definition: winlogon.h:61
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
unsigned short * PUSHORT
Definition: retypes.h:2
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:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT32FindAndMarkAvailableCluster ( PDEVICE_EXTENSION  DeviceExt,
PULONG  Cluster 
)

Definition at line 316 of file fat.c.

Referenced by VfatMount().

319 {
320  ULONG FatLength;
321  ULONG StartCluster;
322  ULONG i, j;
325  PVOID Context;
327  PULONG Block;
328  PULONG BlockEnd;
329 
330  ChunkSize = CACHEPAGESIZE(DeviceExt);
331  FatLength = (DeviceExt->FatInfo.NumberOfClusters + 2);
332  *Cluster = 0;
333  StartCluster = DeviceExt->LastAvailableCluster;
334 
335  for (j = 0; j < 2; j++)
336  {
337  for (i = StartCluster; i < FatLength;)
338  {
339  Offset.QuadPart = ROUND_DOWN(i * 4, ChunkSize);
340  _SEH2_TRY
341  {
342  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
343  }
345  {
346  DPRINT1("CcPinRead(Offset %x, Length %u) failed\n", (ULONG)Offset.QuadPart, ChunkSize);
348  }
349  _SEH2_END;
350  Block = (PULONG)((ULONG_PTR)BaseAddress + (i * 4) % ChunkSize);
351  BlockEnd = (PULONG)((ULONG_PTR)BaseAddress + ChunkSize);
352 
353  /* Now process the whole block */
354  while (Block < BlockEnd && i < FatLength)
355  {
356  if ((*Block & 0x0fffffff) == 0)
357  {
358  DPRINT("Found available cluster 0x%x\n", i);
359  DeviceExt->LastAvailableCluster = *Cluster = i;
360  *Block = 0x0fffffff;
361  CcSetDirtyPinnedData(Context, NULL);
362  CcUnpinData(Context);
363  if (DeviceExt->AvailableClustersValid)
364  InterlockedDecrement((PLONG)&DeviceExt->AvailableClusters);
365  return STATUS_SUCCESS;
366  }
367 
368  Block++;
369  i++;
370  }
371 
372  CcUnpinData(Context);
373  }
374  FatLength = StartCluster;
375  StartCluster = 2;
376  }
377  return STATUS_DISK_FULL;
378 }
DWORD *typedef PVOID
Definition: winlogon.h:61
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
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
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_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 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:1027
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:2710
signed int * PLONG
Definition: retypes.h:5
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT32GetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
PBOOLEAN  DirtyStatus 
)

Definition at line 940 of file fat.c.

Referenced by VfatMount().

943 {
945  ULONG Length;
946 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
948 #else
949  PVOID Context;
950 #endif
951  struct _BootSector32 * Sector;
952 
953  /* We'll read the bootsector at 0 */
954  Offset.QuadPart = 0;
955  Length = DeviceExt->FatInfo.BytesPerSector;
956 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
957  /* Go through Cc for this */
958  _SEH2_TRY
959  {
960  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
961  }
963  {
965  }
966  _SEH2_END;
967 #else
968  /* No Cc, do it the old way:
969  * - Allocate a big enough buffer
970  * - And read the disk
971  */
972  Sector = ExAllocatePoolWithTag(NonPagedPool, Length, TAG_BUFFER);
973  if (Sector == NULL)
974  {
975  *DirtyStatus = TRUE;
977  }
978 
979  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
980  if (!NT_SUCCESS(Status))
981  {
982  *DirtyStatus = TRUE;
983  ExFreePoolWithTag(Sector, TAG_BUFFER);
984  return Status;
985  }
986 #endif
987 
988  /* Make sure we have a boot sector...
989  * FIXME: This check is a bit lame and should be improved
990  */
991  if (Sector->Signature1 != 0xaa55)
992  {
993  /* Set we are dirty so that we don't attempt anything */
994  *DirtyStatus = TRUE;
995 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
996  CcUnpinData(Context);
997 #else
998  ExFreePoolWithTag(Sector, TAG_BUFFER);
999 #endif
1001  }
1002 
1003  /* Return the status of the dirty bit */
1004  if (Sector->Res4 & FAT_DIRTY_BIT)
1005  *DirtyStatus = TRUE;
1006  else
1007  *DirtyStatus = FALSE;
1008 
1009 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1010  CcUnpinData(Context);
1011 #else
1012  ExFreePoolWithTag(Sector, TAG_BUFFER);
1013 #endif
1014  return STATUS_SUCCESS;
1015 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char Res4
Definition: vfat.h:78
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
#define TAG_BUFFER
Definition: vfat.h:543
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
#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
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:86
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
unsigned short Signature1
Definition: vfat.h:83
NTSTATUS FAT32GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 36 of file fat.c.

Referenced by VfatMount().

40 {
43  ULONG FATOffset;
45  PVOID Context;
47 
48  ChunkSize = CACHEPAGESIZE(DeviceExt);
49  FATOffset = CurrentCluster * sizeof(ULONG);
50  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
51  _SEH2_TRY
52  {
53  CcMapData(DeviceExt->FATFileObject, &Offset, ChunkSize, MAP_WAIT, &Context, &BaseAddress);
54  }
56  {
58  }
59  _SEH2_END;
60 
61  CurrentCluster = (*(PULONG)((char*)BaseAddress + (FATOffset % ChunkSize))) & 0x0fffffff;
62  if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
63  CurrentCluster = 0xffffffff;
64 
65  if (CurrentCluster == 0)
66  {
67  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
70  ASSERT(CurrentCluster != 0);
71  }
72  CcUnpinData(Context);
73  *NextCluster = CurrentCluster;
74  return Status;
75 }
DWORD *typedef PVOID
Definition: winlogon.h:61
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
Definition: rw.c:40
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
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
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
Status
Definition: gdiplustypes.h:24
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:399
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:405
#define DPRINT1
Definition: precomp.h:8
#define CACHEPAGESIZE(pDeviceExt)
Definition: fat.c:20
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT32SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1133 of file fat.c.

Referenced by VfatMount().

1136 {
1138  ULONG Length;
1139 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1140  NTSTATUS Status;
1141 #else
1142  PVOID Context;
1143 #endif
1144  struct _BootSector32 * Sector;
1145 
1146  /* We'll read (and then write) the bootsector at 0 */
1147  Offset.QuadPart = 0;
1148  Length = DeviceExt->FatInfo.BytesPerSector;
1149 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1150  /* Go through Cc for this */
1151  _SEH2_TRY
1152  {
1153  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1154  }
1156  {
1158  }
1159  _SEH2_END;
1160 #else
1161  /* No Cc, do it the old way:
1162  * - Allocate a big enough buffer
1163  * - And read the disk
1164  */
1165  Sector = ExAllocatePoolWithTag(NonPagedPool, Length, TAG_BUFFER);
1166  if (Sector == NULL)
1167  {
1169  }
1170 
1171  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1172  if (!NT_SUCCESS(Status))
1173  {
1174  ExFreePoolWithTag(Sector, TAG_BUFFER);
1175  return Status;
1176  }
1177 #endif
1178 
1179  /* Make sure we have a boot sector...
1180  * FIXME: This check is a bit lame and should be improved
1181  */
1182  if (Sector->Signature1 != 0xaa55)
1183  {
1184  ASSERT(FALSE);
1185 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1186  CcUnpinData(Context);
1187 #else
1188  ExFreePoolWithTag(Sector, TAG_BUFFER);
1189 #endif
1191  }
1192 
1193  /* Modify the dirty bit status according
1194  * to caller needs
1195  */
1196  if (!DirtyStatus)
1197  {
1198  Sector->Res4 &= ~FAT_DIRTY_BIT;
1199  }
1200  else
1201  {
1202  Sector->Res4 |= FAT_DIRTY_BIT;
1203  }
1204 
1205 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1206  /* Mark boot sector dirty so that it gets written to the disk */
1207  CcSetDirtyPinnedData(Context, NULL);
1208  CcUnpinData(Context);
1209  return STATUS_SUCCESS;
1210 #else
1211  /* Write back the boot sector to the disk */
1212  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1213  ExFreePoolWithTag(Sector, TAG_BUFFER);
1214  return Status;
1215 #endif
1216 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char Res4
Definition: vfat.h:78
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
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
#define TAG_BUFFER
Definition: vfat.h:543
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
#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
LONG NTSTATUS
Definition: precomp.h:26
#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
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
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define FAT_DIRTY_BIT
Definition: vfat.h:86
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
unsigned short Signature1
Definition: vfat.h:83
NTSTATUS FAT32UpdateFreeClustersCount ( PDEVICE_EXTENSION  DeviceExt)

Definition at line 1219 of file fat.c.

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

1221 {
1223  ULONG Length;
1224 #ifdef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1225  NTSTATUS Status;
1226 #else
1227  PVOID Context;
1228 #endif
1229  struct _FsInfoSector * Sector;
1230 
1231  if (!DeviceExt->AvailableClustersValid)
1232  {
1233  return STATUS_INVALID_PARAMETER;
1234  }
1235 
1236  /* We'll read (and then write) the fsinfo sector */
1237  Offset.QuadPart = DeviceExt->FatInfo.FSInfoSector * DeviceExt->FatInfo.BytesPerSector;
1238  Length = DeviceExt->FatInfo.BytesPerSector;
1239 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1240  /* Go through Cc for this */
1241  _SEH2_TRY
1242  {
1243  CcPinRead(DeviceExt->VolumeFcb->FileObject, &Offset, Length, PIN_WAIT, &Context, (PVOID *)&Sector);
1244  }
1246  {
1248  }
1249  _SEH2_END;
1250 #else
1251  /* No Cc, do it the old way:
1252  * - Allocate a big enough buffer
1253  * - And read the disk
1254  */
1255  Sector = ExAllocatePoolWithTag(NonPagedPool, Length, TAG_BUFFER);
1256  if (Sector == NULL)
1257  {
1259  }
1260 
1261  Status = VfatReadDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1262  if (!NT_SUCCESS(Status))
1263  {
1264  ExFreePoolWithTag(Sector, TAG_BUFFER);
1265  return Status;
1266  }
1267 #endif
1268 
1269  /* Make sure we have a FSINFO sector */
1270  if (Sector->ExtBootSignature2 != 0x41615252 ||
1271  Sector->FSINFOSignature != 0x61417272 ||
1272  Sector->Signatur2 != 0xaa550000)
1273  {
1274  ASSERT(FALSE);
1275 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1276  CcUnpinData(Context);
1277 #else
1278  ExFreePoolWithTag(Sector, TAG_BUFFER);
1279 #endif
1281  }
1282 
1283  /* Update the free clusters count */
1284  Sector->FreeCluster = InterlockedCompareExchange((PLONG)&DeviceExt->AvailableClusters, 0, 0);
1285 
1286 #ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
1287  /* Mark FSINFO sector dirty so that it gets written to the disk */
1288  CcSetDirtyPinnedData(Context, NULL);
1289  CcUnpinData(Context);
1290  return STATUS_SUCCESS;
1291 #else
1292  /* Write back the FSINFO sector to the disk */
1293  Status = VfatWriteDisk(DeviceExt->StorageDevice, &Offset, Length, (PUCHAR)Sector, FALSE);
1294  ExFreePoolWithTag(Sector, TAG_BUFFER);
1295  return Status;
1296 #endif
1297 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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
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:106
_SEH2_TRY
Definition: create.c:4250
#define TAG_BUFFER
Definition: vfat.h:543
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
#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
LONG NTSTATUS
Definition: precomp.h:26
#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
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned long FSINFOSignature
Definition: vfat.h:102
VOID UINTN Length
Definition: acefiex.h:744
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
unsigned long FreeCluster
Definition: vfat.h:103
unsigned long ExtBootSignature2
Definition: vfat.h:100
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
struct tagContext Context
Definition: acpixf.h:1027
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:2710
signed int * PLONG
Definition: retypes.h:5
LONGLONG QuadPart
Definition: typedefs.h:112
NTSTATUS FAT32WriteCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  ClusterToWrite,
ULONG  NewValue,
PULONG  OldValue 
)

Definition at line 665 of file fat.c.

Referenced by VfatMount().

670 {
672  ULONG FATOffset;
674  PVOID Context;
676  PULONG Cluster;
677 
678  ChunkSize = CACHEPAGESIZE(DeviceExt);
679 
680  FATOffset = (ClusterToWrite * 4);
681  Offset.QuadPart = ROUND_DOWN(FATOffset, ChunkSize);
682  _SEH2_TRY
683  {
684  CcPinRead(DeviceExt->FATFileObject, &Offset, ChunkSize, PIN_WAIT, &Context, &BaseAddress);
685  }
687  {
689  }
690  _SEH2_END;
691 
692  DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
693  ClusterToWrite);
694  Cluster = ((PULONG)((char*)BaseAddress + (FATOffset % ChunkSize)));
695  *OldValue = *Cluster & 0x0fffffff;
696  *Cluster = (*Cluster & 0xf0000000) | (NewValue & 0x0fffffff);
697 
698  CcSetDirtyPinnedData(Context, NULL);
699  CcUnpinData(Context);
700 
701  return STATUS_SUCCESS;
702 }
DWORD *typedef PVOID
Definition: winlogon.h:61
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:1027
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:2710
LONGLONG QuadPart
Definition: typedefs.h:112
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);
168  Status = STATUS_SUCCESS;
169  }
170  else
171  {
172  DPRINT("FCB not found for %wZ\n", &PathNameU);
173  Status = STATUS_UNSUCCESSFUL;
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;
194  if (Status == STATUS_NO_MORE_ENTRIES)
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  {
251  CcUnpinData(Context);
252  }
253  RtlFreeUnicodeString(&FileToFindUpcase);
254  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
255  return STATUS_SUCCESS;
256  }
257  DirContext->DirIndex++;
258  }
259 
260  if (Context)
261  {
262  CcUnpinData(Context);
263  }
264 
265  RtlFreeUnicodeString(&FileToFindUpcase);
266  ExFreePoolWithTag(PathNameBuffer, TAG_NAME);
267  return Status;
268 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TAG_NAME
Definition: sdbtagid.h:126
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#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:458
Definition: vfat.h:439
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG dirIndex
Definition: vfat.h:494
Iosb Status
Definition: create.c:4311
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
__wchar_t WCHAR
Definition: xmlstorage.h:180
UNICODE_STRING LongNameU
Definition: vfat.h:594
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
UNICODE_STRING LongNameU
Definition: vfat.h:455
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
Definition: fcb.c:293
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:207
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
WCHAR First[]
Definition: FormatMessage.c:11
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
return Found
Definition: dirsup.c:1270
ULONG startIndex
Definition: vfat.h:497
FORCEINLINE BOOLEAN vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt)
Definition: vfat.h:643
BOOLEAN NTAPI FsRtlAreNamesEqual(IN PCUNICODE_STRING Name1, IN PCUNICODE_STRING Name2, IN BOOLEAN IgnoreCase, IN PCWCH UpcaseTable OPTIONAL)
Definition: name.c:296
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
UNICODE_STRING ShortNameU
Definition: vfat.h:595
DIR_ENTRY DirEntry
Definition: vfat.h:593
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
PVFATFCB vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
Definition: fcb.c:588
#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:389
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:399
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
DIR_ENTRY entry
Definition: vfat.h:449
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
Definition: vfat.h:225
ULONG Flags
Definition: vfat.h:405
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING PathNameU
Definition: vfat.h:464
#define LONGNAME_MAX_LENGTH
Definition: vfat.h:204
unsigned int ULONG
Definition: retypes.h:1
VOID vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
Definition: fcb.c:331
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2710
BOOLEAN FsdDosDateTimeToSystemTime ( PDEVICE_EXTENSION  DeviceExt,
USHORT  DosDate,
USHORT  DosTime,
PLARGE_INTEGER  SystemTime 
)

Definition at line 22 of file dir.c.

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

27 {
28  PDOSTIME pdtime = (PDOSTIME)&DosTime;
29  PDOSDATE pddate = (PDOSDATE)&DosDate;
31  LARGE_INTEGER LocalTime;
32 
33  if (SystemTime == NULL)
34  return FALSE;
35 
36  TimeFields.Milliseconds = 0;
37  TimeFields.Second = pdtime->Second * 2;
38  TimeFields.Minute = pdtime->Minute;
39  TimeFields.Hour = pdtime->Hour;
40 
41  TimeFields.Day = pddate->Day;
42  TimeFields.Month = pddate->Month;
43  TimeFields.Year = (CSHORT)(DeviceExt->BaseDateYear + pddate->Year);
44 
45  RtlTimeFieldsToTime(&TimeFields, &LocalTime);
46  ExLocalTimeToSystemTime(&LocalTime, SystemTime);
47 
48  return TRUE;
49 }
WORD Month
Definition: cabinet.c:40
#define TRUE
Definition: types.h:120
WORD Year
Definition: cabinet.c:41
WORD Second
Definition: cabinet.c:32
struct _DOSDATE * PDOSDATE
WORD Minute
Definition: cabinet.c:33
struct _DOSTIME * PDOSTIME
#define FALSE
Definition: types.h:117
WORD Hour
Definition: cabinet.c:34
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
BOOLEAN FsdSystemTimeToDosDateTime ( PDEVICE_EXTENSION  DeviceExt,
PLARGE_INTEGER  SystemTime,
USHORT pDosDate,
USHORT pDosTime 
)

Definition at line 53 of file dir.c.

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

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

Definition at line 835 of file fat.c.

Referenced by VfatMount().

838 {
840 
841  DPRINT("GetDirtyStatus(DeviceExt %p)\n", DeviceExt);
842 
843  /* FAT12 has no dirty bit */
844  if (DeviceExt->FatInfo.FatType == FAT12)
845  {
846  *DirtyStatus = FALSE;
847  return STATUS_SUCCESS;
848  }
849 
850  /* Not really in the FAT, but share the lock because
851  * we're really low-level and shouldn't happent that often
852  * And call the appropriate function
853  */
854  ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
855  Status = DeviceExt->GetDirtyStatus(DeviceExt, DirtyStatus);
856  ExReleaseResourceLite(&DeviceExt->FatResource);
857 
858  return Status;
859 }
#define FAT12
Definition: fat.h:167
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTSTATUS
Definition: precomp.h:26
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:2710
NTSTATUS GetNextCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  CurrentCluster,
PULONG  NextCluster 
)

Definition at line 748 of file fat.c.

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

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

Definition at line 777 of file fat.c.

Referenced by NextCluster(), and OffsetToCluster().

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

Definition at line 40 of file rw.c.

Referenced by FATAddEntry(), FATDelEntry(), FATXDelEntry(), VfatGetRetrievalPointers(), vfatInitFCBFromDirEntry(), vfatMakeRootFCB(), VfatReadFileData(), VfatSetAllocationSizeInformation(), and VfatWriteFileData().

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:777
NTSTATUS GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:748
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS OffsetToCluster ( PDEVICE_EXTENSION  DeviceExt,
ULONG  FirstCluster,
ULONG  FileOffset,
PULONG  Cluster,
BOOLEAN  Extend 
)

Definition at line 61 of file rw.c.

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

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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS GetNextClusterExtend(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:777
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
Status
Definition: gdiplustypes.h:24
NTSTATUS GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster, PULONG NextCluster)
Definition: fat.c:748
_In_ PLARGE_INTEGER FileOffset
Definition: cctypes.h:53
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS SetDirtyStatus ( PDEVICE_EXTENSION  DeviceExt,
BOOLEAN  DirtyStatus 
)

Definition at line 1021 of file fat.c.

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

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

Definition at line 37 of file create.c.

Referenced by FATGetNextDirEntry(), and ReadVolumeLabel().

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:116
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
#define FAT_ENTRY_VOLUME(DirEntry)
Definition: vfat.h:213
#define VFAT_CASE_LOWER_BASE
Definition: vfat.h:201
static const WCHAR L[]
Definition: oid.c:1087
VOID UINTN Length
Definition: acefiex.h:744
#define VFAT_CASE_LOWER_EXT
Definition: vfat.h:202
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:119
NTSYSAPI NTSTATUS WINAPI RtlDowncaseUnicodeString(UNICODE_STRING *, const UNICODE_STRING *, BOOLEAN)
BOOLEAN NTAPI VfatAcquireForLazyWrite ( IN PVOID  Context,
IN BOOLEAN  Wait 
)

Definition at line 728 of file fastio.c.

Referenced by DriverEntry().

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:439
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
struct _VFATFCB * PVFATFCB
ERESOURCE MainResource
Definition: vfat.h:444
_In_ BOOLEAN Wait
Definition: cctypes.h:23
_In_ PFCB Fcb
Definition: cdprocs.h:151
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 367 of file vfat.h.

Referenced by VfatCreateFile(), and VfatMoveEntry().

374 {
375  return DeviceExt->Dispatch.AddEntry(DeviceExt, NameU, Fcb, ParentFcb, RequestedOptions, ReqAttr, MoveContext);
376 }
NTSTATUS vfatAttachFCBToFileObject ( PDEVICE_EXTENSION  vcb,
PVFATFCB  fcb,
PFILE_OBJECT  fileObject 
)

Definition at line 743 of file fcb.c.

Referenced by VfatCreateFile(), and VfatOpenFile().

747 {
748  PVFATCCB newCCB;
749 
751 
752 #ifdef KDBG
753  if (DebugFile.Buffer != NULL && FsRtlIsNameInExpression(&DebugFile, &fcb->LongNameU, FALSE, NULL))
754  {
755  DPRINT1("Attaching %p to %p (%d)\n", fcb, fileObject, fcb->RefCount);
756  }
757 #endif
758 
759  newCCB = ExAllocateFromNPagedLookasideList(&VfatGlobalData->CcbLookasideList);
760  if (newCCB == NULL)
761  {
763  }
764  RtlZeroMemory(newCCB, sizeof (VFATCCB));
765 
766  fileObject->SectionObjectPointer = &fcb->SectionObjectPointers;
767  fileObject->FsContext = fcb;
768  fileObject->FsContext2 = newCCB;
769  fileObject->Vpb = vcb->IoVPB;
770  DPRINT("file open: fcb:%p PathName:%wZ\n", fcb, &fcb->PathNameU);
771 
772 #ifdef KDBG
773  fcb->Flags &= ~FCB_CLEANED_UP;
774  fcb->Flags &= ~FCB_CLOSED;
775 #endif
776 
777  return STATUS_SUCCESS;
778 }
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: vfat.h:443
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: vfat.h:528
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
UNICODE_STRING LongNameU
Definition: vfat.h:455
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:473
#define FALSE
Definition: types.h:117
ULONG Flags
Definition: vfat.h:488
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NPAGED_LOOKASIDE_LIST CcbLookasideList
Definition: vfat.h:410
struct _fcb fcb
Definition: btrfs_drv.h:1289
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING PathNameU
Definition: vfat.h:464
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2710
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.

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

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");
457  Irp = IoBuildDeviceIoControlRequest(CtlCode,
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  {
474  Stack = IoGetNextIrpStackLocation(Irp);
476  }
477 
478  DPRINT("Calling IO Driver... with irp %p\n", Irp);
479  Status = IoCallDriver(DeviceObject, 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 
491  if (Status == STATUS_VERIFY_REQUIRED)
492  {
494 
495  DPRINT1("Media change detected!\n");
496 
497  /* Find the device to verify and reset the thread field to empty value again. */
498  DeviceToVerify = IoGetDeviceToVerify(PsGetCurrentThread());
500  Status = IoVerifyVolume(DeviceToVerify,
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
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
ACPI_EFI_EVENT Event
Definition: acefiex.h:633
#define FALSE
Definition: types.h:117
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
LONG NTSTATUS
Definition: precomp.h:26
#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
PVOID PIRP
Definition: usb.h:38
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
NTSTATUS NTAPI VfatBuildRequest ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)
BOOLEAN VfatCheckForDismount ( IN PDEVICE_EXTENSION  DeviceExt,
IN BOOLEAN  Create 
)

Definition at line 417 of file misc.c.

Referenced by VfatCleanupFile(), and VfatCloseFile().

420 {
421  KIRQL OldIrql;
422  PVPB Vpb;
423  BOOLEAN Delete;
424 
425  DPRINT1("VfatCheckForDismount(%p, %u)\n", DeviceExt, Create);
426 
427  /* Lock VPB */
428  IoAcquireVpbSpinLock(&OldIrql);
429 
430  /* Reference it and check if a create is being done */
431  Vpb = DeviceExt->IoVPB;
432  if (Vpb->ReferenceCount != Create)
433  {
434  /* Copy the VPB to our local own to prepare later dismount */
435  if (DeviceExt->SpareVPB != NULL)
436  {
437  RtlZeroMemory(DeviceExt->SpareVPB, sizeof(VPB));
438  DeviceExt->SpareVPB->Type = IO_TYPE_VPB;
439  DeviceExt->SpareVPB->Size = sizeof(VPB);
440  DeviceExt->SpareVPB->RealDevice = DeviceExt->IoVPB->RealDevice;
441  DeviceExt->SpareVPB->DeviceObject = NULL;
442  DeviceExt->SpareVPB->Flags = DeviceExt->IoVPB->Flags & VPB_REMOVE_PENDING;
443  DeviceExt->IoVPB->RealDevice->Vpb = DeviceExt->SpareVPB;
444  DeviceExt->SpareVPB = NULL;
445  DeviceExt->IoVPB->Flags |= VPB_PERSISTENT;
446  }
447 
448  /* Don't do anything */
449  Delete = FALSE;
450  }
451  else
452  {
453  /* Otherwise, delete the volume */
454  Delete = TRUE;
455 
456  /* Check if it has a VPB and unmount it */
457  if (Vpb->RealDevice->Vpb == Vpb)
458  {
459  Vpb->DeviceObject = NULL;
460  Vpb->Flags &= ~VPB_MOUNTED;
461  }
462  }
463 
464  /* Release lock and return status */
465  IoReleaseVpbSpinLock(OldIrql);
466 
467  /* If we were to delete, delete volume */
468  if (Delete)
469  {
470  PVPB DelVpb;
471 
472  /* If we have a local VPB, we'll have to delete it
473  * but we won't dismount us - something went bad before
474  */
475  if (DeviceExt->SpareVPB)
476  {
477  DelVpb = DeviceExt->SpareVPB;
478  }
479  /* Otherwise, dismount our device if possible */
480  else
481  {
482  if (DeviceExt->IoVPB->ReferenceCount)
483  {
484  ObfDereferenceObject(DeviceExt->StorageDevice);
485  IoDeleteDevice(DeviceExt->VolumeDevice);
486  return Delete;
487  }
488 
489  DelVpb = DeviceExt->IoVPB;
490  }
491 
492  /* Delete any of the available VPB and dismount */
493  ExFreePool(DelVpb);
494  ObfDereferenceObject(DeviceExt->StorageDevice);
495  IoDeleteDevice(DeviceExt->VolumeDevice);
496 
497  return Delete;
498  }
499 
500  return Delete;
501 }
LONG_PTR FASTCALL ObfDereferenceObject(IN PVOID Object)
Definition: obref.c:320
#define TRUE
Definition: types.h:120
USHORT Flags
Definition: iotypes.h:169
_In_ BOOLEAN Create
Definition: pstypes.h:511
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1201
#define VPB_PERSISTENT
Definition: iotypes.h:1765
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
ULONG ReferenceCount
Definition: iotypes.h:174
smooth NULL
Definition: ftsmooth.c:416
struct _DEVICE_OBJECT * DeviceObject
Definition: iotypes.h:171
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
unsigned char BOOLEAN
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define IO_TYPE_VPB
struct _VPB VPB
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1059
#define DPRINT1
Definition: precomp.h:8
Definition: iotypes.h:166
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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
NTSTATUS VfatCleanup ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 175 of file cleanup.c.

Referenced by VfatDispatchRequest().

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:577
static NTSTATUS VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
Definition: cleanup.c:24
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:404
LONG NTSTATUS
Definition: precomp.h:26
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:576
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS VfatClose ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 210 of file close.c.

Referenced by VfatDispatchRequest().

212 {
214 
215  DPRINT("VfatClose(DeviceObject %p, Irp %p)\n", IrpContext->DeviceObject, IrpContext->Irp);
216 
217  if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
218  {
219  DPRINT("Closing file system\n");
220  IrpContext->Irp->IoStatus.Information = 0;
221  return STATUS_SUCCESS;
222  }
223  if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_CANWAIT)))
224  {
225  return VfatMarkIrpContextForQueue(IrpContext);
226  }
227 
228  Status = VfatCloseFile(IrpContext->DeviceExt, IrpContext->FileObject);
229  ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
230 
231  IrpContext->Irp->IoStatus.Information = 0;
232 
233  return Status;
234 }
NTSTATUS VfatCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: close.c:160
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:577
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
PFILE_OBJECT FileObject
Definition: vfat.h:583
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IRPCONTEXT_CANWAIT
Definition: vfat.h:567
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:404
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE NTSTATUS VfatMarkIrpContextForQueue(PVFAT_IRP_CONTEXT IrpContext)
Definition: vfat.h:617
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:576
ULONG Flags
Definition: vfat.h:578
return STATUS_SUCCESS
Definition: btrfs.c:2710
NTSTATUS VfatCloseFile ( PDEVICE_EXTENSION  DeviceExt,
PFILE_OBJECT  FileObject 
)

Definition at line 160 of file close.c.

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

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

Definition at line 1083 of file create.c.

Referenced by VfatDispatchRequest().

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:577
Iosb Status
Definition: create.c:4311
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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:586
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:404
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
PDEVICE_OBJECT DeviceObject
Definition: vfat.h:576
return STATUS_SUCCESS
Definition: btrfs.c:2710
static NTSTATUS VfatCreateFile(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: create.c:424
FORCEINLINE NTSTATUS VfatDelEntry ( PDEVICE_EXTENSION  DeviceExt,
struct _VFATFCB Fcb,
struct _VFAT_MOVE_CONTEXT MoveContext 
)

Definition at line 380 of file vfat.h.

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

383 {
384  return DeviceExt->Dispatch.DelEntry(DeviceExt, Fcb, MoveContext);
385 }
VOID vfatDestroyCCB ( PVFATCCB  pCcb)

Definition at line 258 of file fcb.c.

Referenced by VfatCloseFile(), and VfatMount().

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

Definition at line 269 of file fcb.c.

Referenced by VfatDismountVolume(), and VfatMount().

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  if (!vfatFCBIsRoot(pFCB) &&
282  {
284  }
285  ExFreePool(pFCB->PathNameBuffer);
289  ExFreeToNPagedLookasideList(&VfatGlobalData->FcbLookasideList, pFCB);
290 }
NPAGED_LOOKASIDE_LIST FcbLookasideList
Definition: vfat.h:409
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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:455
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
Definition: fcb.c:293
_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:473
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define FALSE
Definition: types.h:117
ULONG Flags
Definition: vfat.h:488
smooth NULL
Definition: ftsmooth.c:416
FILE_LOCK FileLock
Definition: vfat.h:512
#define FCB_IS_FAT
Definition: vfat.h:427
PWCHAR PathNameBuffer
Definition: vfat.h:467
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define FCB_IS_VOLUME
Definition: vfat.h:429
ERESOURCE PagingIoResource
Definition: vfat.h:445
ERESOURCE MainResource
Definition: vfat.h:444
#define DPRINT1
Definition: precomp.h:8
UNICODE_STRING PathNameU
Definition: vfat.h:464
LIST_ENTRY ParentListHead
Definition: vfat.h:485
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LIST_ENTRY ParentListEntry
Definition: vfat.h:479
NTSTATUS VfatDirectoryControl ( PVFAT_IRP_CONTEXT  IrpContext)

Definition at line 728 of file dir.c.

Referenced by VfatDispatchRequest().

730 {
732 
733  IrpContext->Irp->IoStatus.Information = 0;
734 
735  switch (IrpContext->MinorFunction)
736  {
738  Status = DoQuery (IrpContext);
739  break;
740 
742  Status = VfatNotifyChangeDirectory(IrpContext);
743  break;
744 
745  default:
746  /* Error */
747  DPRINT("Unexpected minor function %x in VFAT driver\n",
748  IrpContext->MinorFunction);
750  break;
751  }
752 
753  if (Status == STATUS_PENDING && BooleanFlagOn(IrpContext->Flags, IRPCONTEXT_COMPLETE))
754  {
755  return VfatMarkIrpContextForQueue(IrpContext);
756  }
757 
758  return Status;
759 }
#define IRP_MN_NOTIFY_CHANGE_DIRECTORY
Definition: rdpdr.c:56
#define IRPCONTEXT_COMPLETE
Definition: vfat.h:568
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IRP_MN_QUERY_DIRECTORY
Definition: rdpdr.c:55
static NTSTATUS DoQuery(PVFAT_IRP_CONTEXT IrpContext)
Definition: dir.c:475
NTSTATUS VfatNotifyChangeDirectory(PVFAT_IRP_CONTEXT IrpContext)
Definition: dir.c:698
void DPRINT(...)
Definition: polytest.cpp:61
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_PENDING
Definition: ntstatus.h:82
FORCEINLINE NTSTATUS VfatMarkIrpContextForQueue(PVFAT_IRP_CONTEXT IrpContext)
Definition: vfat.h:617
UCHAR MinorFunction
Definition: vfat.h:582
Status
Definition: gdiplustypes.h:24
ULONG Flags
Definition: vfat.h:578
return STATUS_SUCCESS
Definition: btrfs.c:2710
ULONG vfatDirEntryGetFirstCluster ( PDEVICE_EXTENSION  pDeviceExt,
PDIR_ENTRY  pDirEntry 
)

Definition at line 19 of file direntry.c.

Referenced by FATDelEntry(), FATXDelEntry(), VfatGetInternalInformation(), VfatGetRetrievalPointers(), vfatInitFCBFromDirEntry(), VfatReadFileData(), VfatSetAllocationSizeInformation(), VfatWrite(), and VfatWriteFileData().

22 {
23  ULONG cluster;
24 
25  if (pDeviceExt->FatInfo.FatType == FAT32)
26  {
27  cluster = pFatDirEntry->Fat.FirstCluster |
28  (pFatDirEntry->Fat.FirstClusterHigh << 16);
29  }
30  else if (vfatVolumeIsFatX(pDeviceExt))
31  {
32  cluster = pFatDirEntry->FatX.FirstCluster;
33  }
34  else
35  {
36  cluster = pFatDirEntry->Fat.FirstCluster;
37  }
38 
39  return cluster;
40 }
FORCEINLINE BOOLEAN vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt)
Definition: vfat.h:643
#define FAT32
Definition: fat.h:169
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS vfatDirFindFile ( PDEVICE_EXTENSION  pVCB,
PVFATFCB  parentFCB,
PUNICODE_STRING  FileToFindU,
PVFATFCB fileFCB 
)

Definition at line 781 of file fcb.c.

Referenced by vfatGetFCBForFile().

786 {
788  PVOID Context = NULL;
789  PVOID Page = NULL;
790  BOOLEAN First = TRUE;
792  /* This buffer must have a size of 260 characters, because
793  vfatMakeFCBFromDirEntry can copy 20 name entries with 13 characters. */
794  WCHAR LongNameBuffer[260];
795  WCHAR ShortNameBuffer[13];
796  BOOLEAN FoundLong = FALSE;
797  BOOLEAN FoundShort = FALSE;
798  BOOLEAN IsFatX = vfatVolumeIsFatX(pDeviceExt);
799 
800  ASSERT(pDeviceExt);
801  ASSERT(pDirectoryFCB);
802  ASSERT(FileToFindU);
803 
804  DPRINT("vfatDirFindFile(VCB:%p, dirFCB:%p, File:%wZ)\n",
805  pDeviceExt, pDirectoryFCB, FileToFindU);
806  DPRINT("Dir Path:%wZ\n", &pDirectoryFCB->PathNameU);
807 
808  DirContext.DirIndex = 0;
809  DirContext.LongNameU.Buffer = LongNameBuffer;
810  DirContext.LongNameU.Length = 0;
811  DirContext.LongNameU.MaximumLength = sizeof(LongNameBuffer);
812  DirContext.ShortNameU.Buffer = ShortNameBuffer;
813  DirContext.ShortNameU.Length = 0;
814  DirContext.ShortNameU.MaximumLength = sizeof(ShortNameBuffer);
815  DirContext.DeviceExt = pDeviceExt;
816 
817  while (TRUE)
818  {
819  status = VfatGetNextDirEntry(pDeviceExt,
820  &Context,
821  &Page,
822  pDirectoryFCB,
823  &DirContext,
824  First);
825  First = FALSE;
826  if (status == STATUS_NO_MORE_ENTRIES)
827  {
829  }
830  if (!NT_SUCCESS(status))
831  {
832  return status;
833  }
834 
835  DPRINT(" Index:%u longName:%wZ\n",
836  DirContext.DirIndex, &DirContext.LongNameU);
837 
838  if (!ENTRY_VOLUME(IsFatX, &DirContext.DirEntry))
839  {
840  if (DirContext.LongNameU.Length == 0 ||
841  DirContext.ShortNameU.Length == 0)
842  {
843  DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
845  {
846  ASSERT(DirContext.LongNameU.Length != 0 &&
847  DirContext.ShortNameU.Length != 0);
848  }
849  DirContext.DirIndex++;
850  continue;
851  }
852  FoundLong = RtlEqualUnicodeString(FileToFindU, &DirContext.LongNameU, TRUE);
853  if (FoundLong == FALSE)
854  {
855  FoundShort = RtlEqualUnicodeString(FileToFindU, &DirContext.ShortNameU, TRUE);
856  }
857  if (FoundLong || FoundShort)
858  {
859  status = vfatMakeFCBFromDirEntry(pDeviceExt,
860  pDirectoryFCB,
861  &DirContext,
862  pFoundFCB);
863  CcUnpinData(Context);
864  return status;
865  }
866  }
867  DirContext.DirIndex++;
868  }
869 
871 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define TRUE
Definition: types.h:120
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:193
USHORT MaximumLength
Definition: env_spec_w32.h:370
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
__wchar_t WCHAR
Definition: xmlstorage.h:180
UNICODE_STRING LongNameU
Definition: vfat.h:594
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
NTSTATUS vfatMakeFCBFromDirEntry(PVCB vcb, PVFATFCB directoryFCB, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB *fileFCB)
Definition: fcb.c:713
#define ENTRY_VOLUME(IsFatX, DirEntry)
Definition: vfat.h:207
WCHAR First[]
Definition: FormatMessage.c:11
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
FORCEINLINE BOOLEAN vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt)
Definition: vfat.h:643
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
UNICODE_STRING ShortNameU
Definition: vfat.h:595
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT DirContext
Definition: cdprocs.h:429
DIR_ENTRY DirEntry
Definition: vfat.h:593
FORCEINLINE NTSTATUS VfatGetNextDirEntry(PDEVICE_EXTENSION DeviceExt, PVOID *pContext, PVOID *pPage, struct _VFATFCB *pDirFcb, struct _VFAT_DIRENTRY_CONTEXT *DirContext, BOOLEAN First)
Definition: vfat.h:389
#define VFAT_BREAK_ON_CORRUPTION
Definition: vfat.h:399
PVFAT_GLOBAL_DATA VfatGlobalData
Definition: iface.c:40
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
ULONG Flags
Definition: vfat.h:405
#define DPRINT1
Definition: precomp.h:8
PDEVICE_EXTENSION DeviceExt
Definition: vfat.h:596
static SERVICE_STATUS status
Definition: service.c:31
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSTATUS vfatFCBInitializeCacheFromVolume ( PVCB  vcb,
PVFATFCB  fcb 
)

Definition at line 24 of file dirwr.c.

Referenced by FATAddEntry(), FATDelEntry(), FATGetNextDirEntry(), FATIsDirectoryEmpty(), FATXDelEntry(), FATXGetNextDirEntry(), FATXIsDirectoryEmpty(), FsdSetFsLabelInformation(), vfatFindDirSpace(), vfatMakeRootFCB(), vfatRenameEntry(), and VfatUpdateEntry().

27 {
28  PFILE_OBJECT fileObject;
29  PVFATCCB newCCB;
31  BOOLEAN Acquired;
32 
33  /* Don't re-initialize if already done */
35  {
36  return STATUS_SUCCESS;
37  }
38 
39  ASSERT(