⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfsd.h

📁 This is a ReiserFs file system driver for Windows NT/2000/XP/Vista.
💻 H
📖 第 1 页 / 共 4 页
字号:
    // The FileObject of Volume used to lock the volume
    PFILE_OBJECT                LockFile;

    // List of FCBs for open files on this volume
    LIST_ENTRY                  FcbList;

    // List of IRPs pending on directory change notify requests
    LIST_ENTRY                  NotifyList;

    // Pointer to syncronization primitive for this list
    PNOTIFY_SYNC                NotifySync;
    
    // This volumes device object
    PDEVICE_OBJECT              DeviceObject;
    
    // The physical device object (the disk)
    PDEVICE_OBJECT              TargetDeviceObject;

    // The physical device object (the disk)
    PDEVICE_OBJECT              RealDevice;
    
    // Information about the physical device object
    DISK_GEOMETRY               DiskGeometry;
    PARTITION_INFORMATION       PartitionInformation;
    
    PRFSD_SUPER_BLOCK           SuperBlock;
    PVOID						GroupDesc;		// (NOTE: unused in ReiserFS, but preserved in order to minimize changes to existing code)
//  PVOID                       GroupDescBcb;

    // Number of Group Decsciptions
    ULONG                       NumOfGroups;
/*
    // Bitmap Block per group
    PRTL_BITMAP                 BlockBitMaps;
    PRTL_BITMAP                 InodeBitMaps;
*/
    // Block / Cluster size
    ULONG                       BlockSize;

    // Sector size in bits  (NOTE: unused in ReiserFS)
    //ULONG                       SectorBits;
    
    ULONG                       dwData[RFSD_BLOCK_TYPES];
    ULONG                       dwMeta[RFSD_BLOCK_TYPES];

    // Flags for the volume
    ULONG                       Flags;

    // Streaming File Object
    PFILE_OBJECT                StreamObj;

    // Resource Lock for Mcb
    ERESOURCE                   McbResource;

    // Dirty Mcbs of modifications for volume stream
    LARGE_MCB                   DirtyMcbs;

    // Entry of Mcb Tree (Root Node)
    PRFSD_MCB                   McbTree;
    LIST_ENTRY                  McbList;
    
} RFSD_VCB, *PRFSD_VCB;

//
// Flags for RFSD_VCB
//
#define VCB_INITIALIZED         0x00000001
#define VCB_VOLUME_LOCKED       0x00000002
#define VCB_MOUNTED             0x00000004
#define VCB_DISMOUNT_PENDING    0x00000008
#define VCB_READ_ONLY           0x00000010

#define VCB_WRITE_PROTECTED     0x10000000
#define VCB_FLOPPY_DISK         0x20000000
#define VCB_REMOVAL_PREVENTED   0x40000000
#define VCB_REMOVABLE_MEDIA     0x80000000


#define IsMounted(Vcb)    (IsFlagOn(Vcb->Flags, VCB_MOUNTED))

//
// RFSD_FCB File Control Block
//
// Data that represents an open file
// There is a single instance of the FCB for every open file
//
typedef struct _RFSD_FCB {
    
    // FCB header required by NT
    FSRTL_COMMON_FCB_HEADER         Header;
    SECTION_OBJECT_POINTERS         SectionObject;
    ERESOURCE                       MainResource;
    ERESOURCE                       PagingIoResource;
    // end FCB header required by NT
    
    // Identifier for this structure
    RFSD_IDENTIFIER                 Identifier;
    
    // List of FCBs for this volume
    LIST_ENTRY                      Next;
    
    // Share Access for the file object
    SHARE_ACCESS                    ShareAccess;

    // List of byte-range locks for this file
    FILE_LOCK                       FileLockAnchor;

    // Incremented on IRP_MJ_CREATE, decremented on IRP_MJ_CLEANUP
    ULONG                           OpenHandleCount;
    
    // Incremented on IRP_MJ_CREATE, decremented on IRP_MJ_CLOSE
    ULONG                           ReferenceCount;

    // Incremented on IRP_MJ_CREATE, decremented on IRP_MJ_CLEANUP
    // But only for Files with FO_NO_INTERMEDIATE_BUFFERING flag
    ULONG                           NonCachedOpenCount;

    // Flags for the FCB
    ULONG                           Flags;
    
    // Pointer to the inode  / stat data structure
    PRFSD_INODE                     Inode;

    // Hint block for next allocation
    ULONG                           BlkHint;
    
    // Vcb

    PRFSD_VCB                       Vcb;

    // Mcb Node ...
    PRFSD_MCB                       RfsdMcb;

    // Full Path Name
    UNICODE_STRING                  LongName;

#if DBG
    // The Ansi Filename for debugging
    OEM_STRING                      AnsiFileName;   
#endif


} RFSD_FCB, *PRFSD_FCB;


//
// Flags for RFSD_FCB
//
#define FCB_FROM_POOL               0x00000001
#define FCB_PAGE_FILE               0x00000002
#define FCB_DELETE_ON_CLOSE         0x00000004
#define FCB_DELETE_PENDING          0x00000008
#define FCB_FILE_DELETED            0x00000010
#define FCB_FILE_MODIFIED           0x00000020

// Mcb Node

struct _RFSD_MCB {

    // Identifier for this structure
    RFSD_IDENTIFIER                 Identifier;

    // Flags
    ULONG                           Flags;

    // Link List Info

    PRFSD_MCB                       Parent; // Parent
    PRFSD_MCB                       Child;  // Children
    PRFSD_MCB                       Next;   // Brothers

    // Mcb Node Info

    // -> Fcb
    PRFSD_FCB                       RfsdFcb;

    // Short name
    UNICODE_STRING                  ShortName;

    // Inode number (ReiserFS uses 128-bit keys instead of inode numbers)
	RFSD_KEY_IN_MEMORY				Key;

    // Dir entry offset in parent (relative to the start of the directory listing)
    ULONG                           DeOffset;

    // File attribute
    ULONG                           FileAttr;

    // List Link to Vcb->McbList
    LIST_ENTRY                      Link;
};

//
// Flags for MCB
//
#define MCB_FROM_POOL               0x00000001
#define MCB_IN_TREE                 0x00000002
#define MCB_IN_USE                  0x00000004

#define IsMcbUsed(Mcb) IsFlagOn(Mcb->Flags, MCB_IN_USE)

//
// RFSD_CCB Context Control Block
//
// Data that represents one instance of an open file
// There is one instance of the CCB for every instance of an open file
//
typedef struct _RFSD_CCB {
    
    // Identifier for this structure
    RFSD_IDENTIFIER  Identifier;

    // Flags
    ULONG             Flags;
    
    // State that may need to be maintained
    ULONG             CurrentByteOffset;
    USHORT            deh_location;
    UNICODE_STRING    DirectorySearchPattern;
    
} RFSD_CCB, *PRFSD_CCB;

//
// Flags for CCB
//

#define CCB_FROM_POOL               0x00000001

#define CCB_ALLOW_EXTENDED_DASD_IO  0x80000000

//
// RFSD_IRP_CONTEXT
//
// Used to pass information about a request between the drivers functions
//
typedef struct _RFSD_IRP_CONTEXT {
    
    // Identifier for this structure
    RFSD_IDENTIFIER     Identifier;
    
    // Pointer to the IRP this request describes
    PIRP                Irp;

    // Flags
    ULONG               Flags;
    
    // The major and minor function code for the request
    UCHAR               MajorFunction;
    UCHAR               MinorFunction;
    
    // The device object
    PDEVICE_OBJECT      DeviceObject;

    // The real device object
    PDEVICE_OBJECT      RealDevice;

    // The file object
    PFILE_OBJECT        FileObject;

    PRFSD_FCB           Fcb;
    PRFSD_CCB           Ccb;
    
    // If the request is synchronous (we are allowed to block)
    BOOLEAN             IsSynchronous;
    
    // If the request is top level
    BOOLEAN             IsTopLevel;
    
    // Used if the request needs to be queued for later processing
    WORK_QUEUE_ITEM     WorkQueueItem;
    
    // If an exception is currently in progress
    BOOLEAN             ExceptionInProgress;
    
    // The exception code when an exception is in progress
    NTSTATUS            ExceptionCode;

    // Repinned BCBs List
    RFSD_REPINNED_BCBS  Repinned;
    
} RFSD_IRP_CONTEXT, *PRFSD_IRP_CONTEXT;


#define IRP_CONTEXT_FLAG_FROM_POOL       (0x00000001)
#define IRP_CONTEXT_FLAG_WAIT            (0x00000002)
#define IRP_CONTEXT_FLAG_WRITE_THROUGH   (0x00000004)
#define IRP_CONTEXT_FLAG_FLOPPY          (0x00000008)
#define IRP_CONTEXT_FLAG_RECURSIVE_CALL  (0x00000010)
#define IRP_CONTEXT_FLAG_DISABLE_POPUPS  (0x00000020)
#define IRP_CONTEXT_FLAG_DEFERRED        (0x00000040)
#define IRP_CONTEXT_FLAG_VERIFY_READ     (0x00000080)
#define IRP_CONTEXT_STACK_IO_CONTEXT     (0x00000100)
#define IRP_CONTEXT_FLAG_REQUEUED        (0x00000200)
#define IRP_CONTEXT_FLAG_USER_IO         (0x00000400)
#define IRP_CONTEXT_FLAG_DELAY_CLOSE     (0x00000800)

//
// RFSD_ALLOC_HEADER
//
// In the checked version of the driver this header is put in the beginning of
// every memory allocation
//
typedef struct _RFSD_ALLOC_HEADER {
    RFSD_IDENTIFIER Identifier;
} RFSD_ALLOC_HEADER, *PRFSD_ALLOC_HEADER;

typedef struct _FCB_LIST_ENTRY {
    PRFSD_FCB    Fcb;
    LIST_ENTRY   Next;
} FCB_LIST_ENTRY, *PFCB_LIST_ENTRY;


// Block Description List
typedef struct _RFSD_BDL {
    ULONGLONG    Lba;
    ULONGLONG    Offset;
    ULONG        Length;
    PIRP         Irp;
} RFSD_BDL, *PRFSD_BDL;

#pragma pack()


/* FUNCTIONS DECLARATION *****************************************************/

//
//  The following macro is used to determine if an FSD thread can block
//  for I/O or wait for a resource.  It returns TRUE if the thread can
//  block and FALSE otherwise.  This attribute can then be used to call
//  the FSD & FSP common work routine with the proper wait value.
//

#define CanRfsdWait(IRP) IoIsOperationSynchronous(Irp)

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif

//
// RfsdBlock.c
//

// TODO move allocate and load block here

NTSTATUS
RfsdFindItemHeaderInBlock(
	 IN PRFSD_VCB			Vcb,
	 IN PRFSD_KEY_IN_MEMORY	pKey,						// The key to match against
	 IN PUCHAR				pBlockBuffer,				// A filled disk block, provided by the caller
	 OUT PRFSD_ITEM_HEAD*	ppTargetItemHeader,			// A pointer to a PRFSD_ITEM_HEAD.  The PRFSD_ITEM_HEAD will point to the item head matching Key, or NULL if there was no such item head in the given block.
	 IN	RFSD_KEY_COMPARISON (*fpComparisonFunction)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY)
	 );

NTSTATUS
RfsdLoadItem(
	IN	  PRFSD_VCB				Vcb,
	IN   PRFSD_KEY_IN_MEMORY	pItemKey,					// The key of the item to find
	OUT  PRFSD_ITEM_HEAD*		ppMatchingItemHeader,
	OUT  PUCHAR*				ppItemBuffer,				
	OUT  PUCHAR*				ppBlockBuffer,				// Block buffer, which backs the other output data structures.  The caller must free this (even in the case of an error)!
	OUT	 PULONG					pBlockNumber,				// The ordinal disk block number at which the item was found
	IN	RFSD_KEY_COMPARISON (*fpComparisonFunction)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY)
	);
//
// Block.c
//

NTSTATUS
RfsdLockUserBuffer (
        IN PIRP             Irp,
        IN ULONG            Length,
        IN LOCK_OPERATION   Operation);
PVOID
RfsdGetUserBuffer (IN PIRP Irp);


NTSTATUS
RfsdReadWriteBlocks(
        IN PRFSD_IRP_CONTEXT IrpContext,
        IN PRFSD_VCB        Vcb,
        IN PRFSD_BDL        RfsdBDL,
        IN ULONG            Length,
        IN ULONG            Count,
        IN BOOLEAN          bVerify );

PUCHAR
RfsdAllocateAndLoadBlock(
	IN	PRFSD_VCB			Vcb,
	IN	ULONG				BlockIndex );

NTSTATUS
RfsdReadSync(
        IN PRFSD_VCB        Vcb,
        IN ULONGLONG        Offset,
        IN ULONG            Length,
        OUT PVOID           Buffer,
        IN BOOLEAN          bVerify );

NTSTATUS
RfsdReadDisk(
         IN PRFSD_VCB       Vcb,
         IN ULONGLONG       Offset,
         IN ULONG           Size,
         IN PVOID           Buffer,
         IN BOOLEAN         bVerify  );

NTSTATUS 
RfsdDiskIoControl (
        IN PDEVICE_OBJECT   DeviceOjbect,
        IN ULONG            IoctlCode,
        IN PVOID            InputBuffer,
        IN ULONG            InputBufferSize,
        IN OUT PVOID        OutputBuffer,
        IN OUT PULONG       OutputBufferSize );

VOID
RfsdMediaEjectControl (
        IN PRFSD_IRP_CONTEXT IrpContext,
        IN PRFSD_VCB Vcb,
        IN BOOLEAN bPrevent );

NTSTATUS
RfsdDiskShutDown(PRFSD_VCB Vcb);


//
// Cleanup.c
//
NTSTATUS
RfsdCleanup (IN PRFSD_IRP_CONTEXT IrpContext);

//
// Close.c
//
NTSTATUS
RfsdClose (IN PRFSD_IRP_CONTEXT IrpContext);

VOID
RfsdQueueCloseRequest (IN PRFSD_IRP_CONTEXT IrpContext);

VOID
RfsdDeQueueCloseRequest (IN PVOID Context);

//
// Cmcb.c
//

BOOLEAN
RfsdAcquireForLazyWrite (
        IN PVOID    Context,
        IN BOOLEAN  Wait );
VOID
RfsdReleaseFromLazyWrite (IN PVOID Context);

BOOLEAN
RfsdAcquireForReadAhead (
        IN PVOID    Context,
        IN BOOLEAN  Wait );

BOOLEAN
RfsdNoOpAcquire (
        IN PVOID Fcb,
        IN BOOLEAN Wait );

VOID
RfsdNoOpRelease (IN PVOID Fcb    );

VOID
RfsdReleaseFromReadAhead (IN PVOID Context);

//
// Create.c
//

PRFSD_FCB
RfsdSearchFcbList(
        IN PRFSD_VCB    Vcb,
        IN ULONG        inode);

NTSTATUS
RfsdScanDir (IN PRFSD_VCB       Vcb,
         IN PRFSD_MCB           ParentMcb,				// Mcb of the directory to be scanned
         IN PUNICODE_STRING     FileName,				// Short file name (not necisarilly null-terminated!)
         IN OUT PULONG          Index,					// Offset (in bytes) of the dentry relative to the start of the directory listing
         IN OUT PRFSD_DENTRY_HEAD rfsd_dir);			// Directory entry of the found item

NTSTATUS
RfsdLookupFileName (
        IN PRFSD_VCB            Vcb,
        IN PUNICODE_STRING      FullFileName,
        IN PRFSD_MCB            ParentMcb,
        OUT PRFSD_MCB *         RfsdMcb,
        IN OUT PRFSD_INODE      Inode);

NTSTATUS
RfsdCreateFile(
        IN PRFSD_IRP_CONTEXT IrpContext,
        IN PRFSD_VCB Vcb );

NTSTATUS
RfsdCreateVolume(
        IN PRFSD_IRP_CONTEXT IrpContext, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -