2009-01-23 09:49:45 +00:00
|
|
|
#ifndef __STRUCT_H__
|
|
|
|
#define __STRUCT_H__
|
|
|
|
|
|
|
|
typedef struct _FAT_SCAN_CONTEXT *PFAT_SCAN_CONTEXT;
|
|
|
|
typedef struct _FAT_IO_CONTEXT *PFAT_IO_CONTEXT;
|
2009-02-25 12:25:06 +00:00
|
|
|
typedef struct _FAT_IRP_CONTEXT *PFAT_IRP_CONTEXT;
|
2009-01-23 09:49:45 +00:00
|
|
|
typedef PVOID PBCB;
|
|
|
|
|
2009-02-25 12:25:06 +00:00
|
|
|
typedef NTSTATUS (*PFAT_OPERATION_HANDLER) (PFAT_IRP_CONTEXT);
|
|
|
|
|
2009-09-28 10:43:27 +00:00
|
|
|
/* Node type stuff */
|
|
|
|
typedef CSHORT FAT_NODE_TYPE;
|
|
|
|
typedef FAT_NODE_TYPE *PFAT_NODE_TYPE;
|
|
|
|
|
|
|
|
#define FatNodeType(Ptr) (*((PFAT_NODE_TYPE)(Ptr)))
|
|
|
|
|
|
|
|
/* Node type codes */
|
|
|
|
#define FAT_NTC_VCB (CSHORT) '00VF'
|
|
|
|
#define FAT_NTC_FCB (CSHORT) 'CF'
|
|
|
|
#define FAT_NTC_DCB (CSHORT) 'DF'
|
|
|
|
#define FAT_NTC_ROOT_DCB (CSHORT) 'RFD'
|
2009-09-30 16:16:18 +00:00
|
|
|
#define FAT_NTC_CCB (CSHORT) 'BCC'
|
2009-09-28 10:43:27 +00:00
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
typedef struct _FAT_GLOBAL_DATA
|
|
|
|
{
|
|
|
|
ERESOURCE Resource;
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
PDEVICE_OBJECT DiskDeviceObject;
|
|
|
|
LIST_ENTRY VcbListHead;
|
|
|
|
NPAGED_LOOKASIDE_LIST NonPagedFcbList;
|
|
|
|
NPAGED_LOOKASIDE_LIST ResourceList;
|
|
|
|
NPAGED_LOOKASIDE_LIST IrpContextList;
|
|
|
|
FAST_IO_DISPATCH FastIoDispatch;
|
|
|
|
CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
|
|
|
|
CACHE_MANAGER_CALLBACKS CacheMgrNoopCallbacks;
|
|
|
|
BOOLEAN Win31FileSystem;
|
|
|
|
/* Jan 1, 1980 System Time */
|
|
|
|
LARGE_INTEGER DefaultFileTime;
|
2009-09-29 10:08:43 +00:00
|
|
|
|
|
|
|
/* FullFAT integration */
|
|
|
|
FF_IOMAN *Ioman;
|
|
|
|
FF_ERROR FF_Error;
|
2009-01-23 09:49:45 +00:00
|
|
|
} FAT_GLOBAL_DATA;
|
|
|
|
|
2009-02-25 12:25:06 +00:00
|
|
|
typedef struct _FAT_PAGE_CONTEXT
|
|
|
|
{
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
LARGE_INTEGER EndOfData;
|
|
|
|
LARGE_INTEGER Offset;
|
|
|
|
LARGE_INTEGER EndOfPage;
|
|
|
|
SIZE_T ValidLength;
|
|
|
|
PVOID Buffer;
|
|
|
|
PBCB Bcb;
|
|
|
|
BOOLEAN CanWait;
|
|
|
|
} FAT_PAGE_CONTEXT, *PFAT_PAGE_CONTEXT;
|
|
|
|
|
|
|
|
#define FatPinSetupContext(xContext, xFcb, CanWait) \
|
|
|
|
{ \
|
|
|
|
(xContext)->FileObject = (xFcb)->StreamFileObject; \
|
|
|
|
(xContext)->EndOfData = (xFcb)->Header.FileSize; \
|
|
|
|
(xContext)->Offset.QuadPart = -1LL; \
|
|
|
|
(xContext)->Bcb = NULL; \
|
|
|
|
(xContext)->CanWait = CanWait; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FatPinCleanupContext(xContext) \
|
|
|
|
if ((xContext)->Bcb != NULL) { \
|
|
|
|
CcUnpinData((xContext)->Bcb); \
|
|
|
|
(xContext)->Bcb = NULL; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#define FatPinEndOfPage(xContext, xType) \
|
|
|
|
Add2Ptr((xContext)->Buffer, (xContext)->ValidLength, xType)
|
|
|
|
|
|
|
|
#define FatPinIsLastPage(xContext) \
|
|
|
|
((xContext)->ValidLength != PAGE_SIZE)
|
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
#define IRPCONTEXT_CANWAIT 0x0001
|
|
|
|
#define IRPCONTEXT_PENDINGRETURNED 0x0002
|
|
|
|
#define IRPCONTEXT_STACK_IO_CONTEXT 0x0004
|
|
|
|
#define IRPCONTEXT_WRITETHROUGH 0x0008
|
|
|
|
#define IRPCONTEXT_TOPLEVEL 0x0010
|
|
|
|
|
|
|
|
typedef struct _FAT_IRP_CONTEXT
|
|
|
|
{
|
|
|
|
PIRP Irp;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
UCHAR MajorFunction;
|
|
|
|
UCHAR MinorFunction;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
ULONG Flags;
|
|
|
|
struct _VCB *Vcb;
|
|
|
|
ULONG PinCount;
|
2009-02-25 12:25:06 +00:00
|
|
|
FAT_PAGE_CONTEXT Page;
|
2009-01-23 09:49:45 +00:00
|
|
|
struct _FAT_IO_CONTEXT *FatIoContext;
|
|
|
|
WORK_QUEUE_ITEM WorkQueueItem;
|
2009-02-25 12:25:06 +00:00
|
|
|
PFAT_OPERATION_HANDLER QueuedOperationHandler;
|
2009-01-23 09:49:45 +00:00
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
KEVENT Event;
|
2009-02-25 12:25:06 +00:00
|
|
|
} FAT_IRP_CONTEXT;
|
2009-01-23 09:49:45 +00:00
|
|
|
|
|
|
|
typedef struct _FAT_IO_CONTEXT
|
|
|
|
{
|
|
|
|
PMDL ZeroMdl;
|
2009-02-25 12:25:06 +00:00
|
|
|
PIRP Irp;
|
|
|
|
LONG RunCount;
|
|
|
|
SIZE_T Length;
|
|
|
|
LONGLONG Offset;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
PERESOURCE Resource;
|
|
|
|
PERESOURCE PagingIoResource;
|
|
|
|
ERESOURCE_THREAD ResourceThreadId;
|
|
|
|
} Async;
|
|
|
|
KEVENT SyncEvent;
|
|
|
|
} Wait;
|
2009-02-25 12:25:06 +00:00
|
|
|
PIRP AssociatedIrp[0];
|
2009-01-23 09:49:45 +00:00
|
|
|
} FAT_IO_CONTEXT;
|
|
|
|
|
2009-02-25 12:25:06 +00:00
|
|
|
typedef ULONG (*PFAT_SCANFAT_FOR_CONTINOUS_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, PULONG, BOOLEAN);
|
|
|
|
typedef ULONG (*PFAT_SETFAT_CONTINOUS_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, ULONG, ULONG, BOOLEAN);
|
|
|
|
typedef ULONG (*PFAT_SCANFAT_FOR_VALUE_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, PULONG, ULONG, BOOLEAN);
|
|
|
|
typedef ULONG (*PFAT_SETFAT_VALUE_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, ULONG, ULONG, ULONG, BOOLEAN);
|
2009-01-23 09:49:45 +00:00
|
|
|
|
|
|
|
typedef struct _FAT_METHODS {
|
|
|
|
PFAT_SCANFAT_FOR_CONTINOUS_RUN_ROUTINE ScanContinousRun;
|
|
|
|
PFAT_SETFAT_CONTINOUS_RUN_ROUTINE SetContinousRun;
|
|
|
|
PFAT_SCANFAT_FOR_VALUE_RUN_ROUTINE ScanValueRun;
|
|
|
|
PFAT_SETFAT_VALUE_RUN_ROUTINE SetValueRun;
|
|
|
|
} FAT_METHODS, *PFAT_METHODS;
|
|
|
|
|
2009-09-28 10:43:27 +00:00
|
|
|
#define VCB_STATE_FLAG_LOCKED 0x01
|
|
|
|
|
|
|
|
typedef enum _VCB_CONDITION
|
|
|
|
{
|
|
|
|
VcbGood,
|
|
|
|
VcbNotMounted,
|
|
|
|
VcbBad
|
|
|
|
} VCB_CONDITION;
|
2009-01-23 10:09:22 +00:00
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
/* Volume Control Block */
|
|
|
|
typedef struct _VCB
|
|
|
|
{
|
|
|
|
FSRTL_ADVANCED_FCB_HEADER Header;
|
|
|
|
FAST_MUTEX HeaderMutex;
|
|
|
|
SECTION_OBJECT_POINTERS SectionObjectPointers;
|
|
|
|
|
2009-02-25 12:25:06 +00:00
|
|
|
PFILE_OBJECT StreamFileObject;
|
2009-01-23 09:49:45 +00:00
|
|
|
PDEVICE_OBJECT TargetDeviceObject;
|
|
|
|
LIST_ENTRY VcbLinks;
|
2009-02-25 12:25:06 +00:00
|
|
|
PVPB Vpb;
|
2009-09-28 10:43:27 +00:00
|
|
|
ULONG State;
|
|
|
|
VCB_CONDITION Condition;
|
|
|
|
ERESOURCE Resource;
|
2009-01-23 09:49:45 +00:00
|
|
|
|
2009-01-23 12:18:38 +00:00
|
|
|
/* Notifications support */
|
|
|
|
PNOTIFY_SYNC NotifySync;
|
|
|
|
LIST_ENTRY NotifyList;
|
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
/* Volume Characteristics: */
|
|
|
|
ULONG SerialNumber;
|
|
|
|
BIOS_PARAMETER_BLOCK Bpb;
|
|
|
|
ULONG BytesPerClusterLog;
|
|
|
|
ULONG BytesPerCluster;
|
|
|
|
ULONG SectorsPerFat;
|
|
|
|
ULONG DataArea;
|
|
|
|
ULONG Sectors;
|
|
|
|
ULONG Clusters;
|
|
|
|
ULONG IndexDepth;
|
|
|
|
ULONG RootDirent;
|
|
|
|
ULONG RootDirentSectors;
|
2009-01-23 19:36:35 +00:00
|
|
|
LONGLONG BeyondLastClusterInFat;
|
2009-01-23 09:49:45 +00:00
|
|
|
FAT_METHODS Methods;
|
2009-09-28 11:02:34 +00:00
|
|
|
|
|
|
|
/* Root Directory Control block */
|
|
|
|
struct _FCB *RootDcb;
|
2009-01-25 08:55:52 +00:00
|
|
|
|
|
|
|
ULONG MediaChangeCount;
|
2009-09-29 10:08:43 +00:00
|
|
|
|
|
|
|
/* FullFAT integration */
|
|
|
|
FF_IOMAN *Ioman;
|
2009-01-23 09:49:45 +00:00
|
|
|
} VCB, *PVCB;
|
|
|
|
|
|
|
|
#define VcbToVolumeDeviceObject(xVcb) \
|
|
|
|
CONTAINING_RECORD((xVcb), VOLUME_DEVICE_OBJECT, Vcb))
|
|
|
|
|
|
|
|
#define VcbToDeviceObject(xVcb) \
|
|
|
|
&(VcbToVolumeDeviceObject(xVcb)->DeviceObject)
|
|
|
|
|
|
|
|
|
|
|
|
#define SectorsToBytes(xVcb, xSectrors) \
|
|
|
|
((xVcb)->Bpb.BytesPerSector * (xSectrors))
|
|
|
|
|
|
|
|
#define BytesToSectors(xVcb, xBytes) \
|
|
|
|
((xBytes + (xVcb)->Bpb.BytesPerSector - 1) / (xVcb)->Bpb.BytesPerSector)
|
|
|
|
|
|
|
|
#define SectorsToClusters(xVcb, xSectors) \
|
|
|
|
((xSectors + (xVcb)->Bpb.SectorsPerCluster - 1) / (xVcb)->Bpb.SectorsPerCluster)
|
|
|
|
|
|
|
|
#define VCB_FAT_BITMAP_SIZE 0x10000
|
|
|
|
#define VcbFatBitmapIndex(xCluster) ((xCluster)/VCB_FAT_BITMAP_SIZE)
|
|
|
|
|
|
|
|
/* Volume Device Object */
|
|
|
|
typedef struct _VOLUME_DEVICE_OBJECT
|
|
|
|
{
|
|
|
|
DEVICE_OBJECT DeviceObject;
|
|
|
|
union {
|
|
|
|
FSRTL_COMMON_FCB_HEADER VolumeHeader;
|
|
|
|
VCB Vcb; /* Must be the last entry! */
|
|
|
|
};
|
|
|
|
} VOLUME_DEVICE_OBJECT, *PVOLUME_DEVICE_OBJECT;
|
|
|
|
//
|
|
|
|
// Short name always exists in FAT
|
|
|
|
//
|
|
|
|
enum _FCB_NAME_TYPE {
|
|
|
|
FcbShortName = 0x0,
|
|
|
|
FcbLongName
|
|
|
|
} FCB_NAME_TYPE;
|
|
|
|
|
|
|
|
typedef struct _FCB_NAME_LINK {
|
2009-09-29 13:09:16 +00:00
|
|
|
struct _FCB *Fcb;
|
2009-01-23 09:49:45 +00:00
|
|
|
RTL_SPLAY_LINKS Links;
|
2009-09-28 18:04:31 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
OEM_STRING Ansi;
|
|
|
|
UNICODE_STRING String;
|
|
|
|
} Name;
|
2009-09-29 13:09:16 +00:00
|
|
|
BOOLEAN IsDosName;
|
2009-01-23 09:49:45 +00:00
|
|
|
} FCB_NAME_LINK, *PFCB_NAME_LINK;
|
|
|
|
|
2009-09-28 18:04:31 +00:00
|
|
|
typedef enum _FCB_CONDITION
|
|
|
|
{
|
|
|
|
FcbGood,
|
|
|
|
FcbBad,
|
|
|
|
FcbNeedsToBeVerified
|
|
|
|
} FCB_CONDITION;
|
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
typedef struct _FCB
|
|
|
|
{
|
|
|
|
FSRTL_ADVANCED_FCB_HEADER Header;
|
|
|
|
/*
|
|
|
|
* Later we might want to move the next four fields
|
|
|
|
* into a separate structureif we decide to split
|
|
|
|
* FCB into paged and non paged parts
|
|
|
|
* (as it is done in MS implementation
|
|
|
|
*/
|
2009-09-28 18:04:31 +00:00
|
|
|
FAST_MUTEX HeaderMutex; // nonpaged!
|
2009-01-23 09:49:45 +00:00
|
|
|
SECTION_OBJECT_POINTERS SectionObjectPointers;
|
2009-09-28 18:04:31 +00:00
|
|
|
ERESOURCE Resource; // nonpaged!
|
|
|
|
ERESOURCE PagingIoResource; // nonpaged!
|
2009-01-23 09:49:45 +00:00
|
|
|
|
|
|
|
FILE_LOCK Lock;
|
2009-09-28 18:04:31 +00:00
|
|
|
/* First cluster in the fat allocation chain */
|
|
|
|
ULONG FirstClusterOfFile;
|
|
|
|
/* A list of all FCBs of that DCB */
|
|
|
|
LIST_ENTRY ParentDcbLinks;
|
2009-01-23 09:49:45 +00:00
|
|
|
/* Reference to the Parent Dcb*/
|
|
|
|
struct _FCB *ParentFcb;
|
|
|
|
/* Pointer to a Vcb */
|
|
|
|
PVCB Vcb;
|
2009-09-28 18:04:31 +00:00
|
|
|
/* Fcb state */
|
|
|
|
ULONG State;
|
|
|
|
/* Fcb condition */
|
|
|
|
FCB_CONDITION Condition;
|
2009-01-23 09:49:45 +00:00
|
|
|
/* Mcb mapping Vbo->Lbo */
|
|
|
|
LARGE_MCB Mcb;
|
|
|
|
ULONG FirstCluster;
|
|
|
|
/* Links into FCB Trie */
|
2009-09-28 18:04:31 +00:00
|
|
|
FCB_NAME_LINK FileName;
|
2009-01-23 09:49:45 +00:00
|
|
|
/* Buffer for the short name */
|
|
|
|
WCHAR ShortNameBuffer[0xc];
|
2009-09-28 10:43:27 +00:00
|
|
|
/* Full file name */
|
|
|
|
UNICODE_STRING FullFileName;
|
2009-09-28 18:04:31 +00:00
|
|
|
/* A copy of fat attribute byte */
|
|
|
|
UCHAR DirentFatFlags;
|
2009-02-25 12:25:06 +00:00
|
|
|
/* File basic info */
|
|
|
|
FILE_BASIC_INFORMATION BasicInfo;
|
2009-01-23 09:49:45 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2009-09-28 18:04:31 +00:00
|
|
|
/* A list of all FCBs/DCBs opened under this DCB */
|
|
|
|
LIST_ENTRY ParentDcbList;
|
2009-02-25 12:25:06 +00:00
|
|
|
/* Directory data stream (just handy to have it). */
|
|
|
|
PFILE_OBJECT StreamFileObject;
|
2009-01-23 09:49:45 +00:00
|
|
|
/* Bitmap to search for free dirents. */
|
2009-09-28 18:04:31 +00:00
|
|
|
RTL_BITMAP FreeBitmap;
|
2009-09-29 13:09:16 +00:00
|
|
|
/* Names */
|
|
|
|
PRTL_SPLAY_LINKS SplayLinksAnsi;
|
|
|
|
PRTL_SPLAY_LINKS SplayLinksUnicode;
|
2009-01-23 09:49:45 +00:00
|
|
|
} Dcb;
|
|
|
|
};
|
|
|
|
} FCB, *PFCB;
|
|
|
|
|
2009-02-25 12:25:06 +00:00
|
|
|
typedef struct _FAT_ENUM_DIRENT_CONTEXT *PFAT_ENUM_DIRENT_CONTEXT;
|
|
|
|
typedef struct _FAT_ENUM_DIR_CONTEXT *PFAT_ENUM_DIR_CONTEXT;
|
|
|
|
|
|
|
|
typedef ULONG (*PFAT_COPY_DIRENT_ROUTINE) (PFAT_ENUM_DIR_CONTEXT, PDIR_ENTRY, PVOID);
|
|
|
|
|
|
|
|
typedef struct _FAT_ENUM_DIRENT_CONTEXT
|
|
|
|
{
|
|
|
|
FAT_PAGE_CONTEXT Page;
|
|
|
|
|
|
|
|
/* Copy dirent to dirinfo */
|
|
|
|
PFAT_COPY_DIRENT_ROUTINE CopyDirent;
|
|
|
|
LONGLONG BytesPerClusterMask;
|
|
|
|
|
|
|
|
/* Info buffer characteristics */
|
|
|
|
PVOID Buffer;
|
|
|
|
SIZE_T Offset;
|
|
|
|
SIZE_T Length;
|
|
|
|
|
|
|
|
/* Criteria */
|
|
|
|
PUNICODE_STRING FileName;
|
|
|
|
UCHAR CcbFlags;
|
|
|
|
|
|
|
|
/* Lfn buffer/length offsets */
|
|
|
|
ULONG LengthOffset;
|
|
|
|
ULONG NameOffset;
|
|
|
|
} FAT_ENUM_DIRENT_CONTEXT;
|
|
|
|
|
|
|
|
typedef struct _FAT_FIND_DIRENT_CONTEXT
|
|
|
|
{
|
|
|
|
FAT_PAGE_CONTEXT Page;
|
|
|
|
UNICODE_STRING ShortName;
|
|
|
|
WCHAR ShortNameBuffer[0x18];
|
|
|
|
/* Criteria */
|
|
|
|
PUNICODE_STRING FileName;
|
|
|
|
BOOLEAN Valid8dot3Name;
|
|
|
|
} FAT_FIND_DIRENT_CONTEXT, *PFAT_FIND_DIRENT_CONTEXT;
|
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
typedef struct _CCB
|
|
|
|
{
|
2009-09-30 16:16:18 +00:00
|
|
|
CSHORT NodeTypeCode;
|
|
|
|
CSHORT NodeByteSize;
|
|
|
|
|
2009-01-23 09:49:45 +00:00
|
|
|
LARGE_INTEGER CurrentByteOffset;
|
|
|
|
ULONG Entry;
|
|
|
|
UNICODE_STRING SearchPattern;
|
2009-02-25 12:25:06 +00:00
|
|
|
UCHAR Flags;
|
2009-01-23 09:49:45 +00:00
|
|
|
} CCB, *PCCB;
|
|
|
|
|
2009-09-28 10:43:27 +00:00
|
|
|
typedef enum _TYPE_OF_OPEN
|
|
|
|
{
|
|
|
|
UnopenedFileObject,
|
|
|
|
UserFileOpen,
|
|
|
|
UserDirectoryOpen,
|
|
|
|
UserVolumeOpen,
|
|
|
|
VirtualVolumeFile,
|
|
|
|
DirectoryFile,
|
|
|
|
EaFile
|
|
|
|
} TYPE_OF_OPEN;
|
2009-02-25 12:25:06 +00:00
|
|
|
|
|
|
|
#define CCB_SEARCH_RETURN_SINGLE_ENTRY 0x01
|
|
|
|
#define CCB_SEARCH_PATTERN_LEGAL_8DOT3 0x02
|
|
|
|
#define CCB_SEARCH_PATTERN_HAS_WILD_CARD 0x04
|
|
|
|
#define CCB_DASD_IO 0x10
|
2009-01-23 09:49:45 +00:00
|
|
|
extern FAT_GLOBAL_DATA FatGlobalData;
|
|
|
|
|
|
|
|
#endif//__STRUCT_H__
|