ReactOS  0.4.15-dev-321-g2d9b385
rfsdblock.c File Reference
#include "rfsd.h"
Include dependency graph for rfsdblock.c:

Go to the source code of this file.

Functions

PUCHAR RfsdAllocateAndLoadBlock (IN PRFSD_VCB Vcb, IN ULONG BlockIndex)
 
NTSTATUS RfsdFindItemHeaderInBlock (IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY pTargetKey, IN PUCHAR pBlockBuffer, OUT PRFSD_ITEM_HEAD *ppMatchingItemHeader, 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, OUT PRFSD_ITEM_HEAD *ppMatchingItemHeader, OUT PUCHAR *ppItemBuffer, OUT PUCHAR *ppBlockBuffer, OPTIONAL OUT PULONG pBlockNumber, IN RFSD_KEY_COMPARISON(*fpComparisonFunction)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY))
 

Variables

PRFSD_GLOBAL RfsdGlobal
 

Function Documentation

◆ RfsdAllocateAndLoadBlock()

PUCHAR RfsdAllocateAndLoadBlock ( IN PRFSD_VCB  Vcb,
IN ULONG  BlockIndex 
)

Returns the address of an allocated buffer (WHICH THE CALLER WILL BE RESPONSIBLE FOR FREEING!), filled with the contents of the given block number on disk. (This is really just an alternative interface to LoadBlock)

Definition at line 34 of file rfsdblock.c.

37 {
38  // Allocate the return buffer (the caller will be responsible for freeing this!)
39  PUCHAR pReturnBuffer = ExAllocatePoolWithTag(NonPagedPool, Vcb->BlockSize, RFSD_POOL_TAG); // NOTE: for now, I'm switching this to non-paged, because i was getting crashes
40 
41  PAGED_CODE();
42 
43  if (!pReturnBuffer)
44  { DbgBreak(); return NULL; }
45 
46  // Read the block in from disk, or from cache.
47  if (!RfsdLoadBlock(Vcb, BlockIndex, pReturnBuffer))
48  { DbgBreak(); ExFreePool(pReturnBuffer); return NULL; }
49 
50  // Return the result to the caller.
51  return pReturnBuffer;
52 }
unsigned char * PUCHAR
Definition: retypes.h:3
#define RFSD_POOL_TAG
Definition: rfsd.h:99
smooth NULL
Definition: ftsmooth.c:416
#define Vcb
Definition: cdprocs.h:1425
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DbgBreak()
Definition: ext2fs.h:46
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
BOOLEAN RfsdLoadBlock(IN PRFSD_VCB Vcb, IN ULONG dwBlk, IN PVOID Buffer)
#define PAGED_CODE()

Referenced by _NavigateToLeafNode(), RfsdDirectoryCallback(), RfsdLoadItem(), and RfsdScanDirCallback().

◆ RfsdFindItemHeaderInBlock()

NTSTATUS RfsdFindItemHeaderInBlock ( IN PRFSD_VCB  Vcb,
IN PRFSD_KEY_IN_MEMORY  pTargetKey,
IN PUCHAR  pBlockBuffer,
OUT PRFSD_ITEM_HEAD ppMatchingItemHeader,
IN RFSD_KEY_COMPARISON(*)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY fpComparisonFunction 
)

Finds the item header inside a given leaf node block that matches a given key.

STATUS_INVALID_HANDLE if the block given to search is invalid STATUS_NO_SUCH_MEMBER if the key is not found in the block given

Definition at line 61 of file rfsdblock.c.

68 {
69  // Read the block header
70  PRFSD_BLOCK_HEAD pBlockHeader = (PRFSD_BLOCK_HEAD) pBlockBuffer;
71  PUCHAR pItemHeaderListBuffer = (PUCHAR) pBlockBuffer + sizeof(RFSD_BLOCK_HEAD);
72 
73  PAGED_CODE();
74 
75  *ppMatchingItemHeader = NULL;
76 
77  // Sanity check that the block (and therefore its header) is there
78  if (!pBlockHeader) { return STATUS_INVALID_HANDLE; }
79  ASSERT(pBlockHeader->blk_level == 1);
80 
81  // Search through the item headers to find one with a key matching pTargetKey
82  {
83  ULONG idxCurrentItemHeader = 0;
84  PRFSD_ITEM_HEAD pCurrentItemHeader = NULL;
85  RFSD_KEY_IN_MEMORY CurrentItemKey;
86 
87  for(idxCurrentItemHeader = 0; idxCurrentItemHeader < pBlockHeader->blk_nr_item; idxCurrentItemHeader++)
88  {
89  // Grab the item header, and its key
90  pCurrentItemHeader = (PRFSD_ITEM_HEAD) (pItemHeaderListBuffer + idxCurrentItemHeader * sizeof(RFSD_ITEM_HEAD));
91 
93  &( pCurrentItemHeader->ih_key ), pCurrentItemHeader->ih_version,
94  &( CurrentItemKey ) ); // <
95 
96  // Check if this item is the one being searched for
97  if ( RFSD_KEYS_MATCH == (*fpComparisonFunction)( pTargetKey , &CurrentItemKey ) )
98  {
99  *ppMatchingItemHeader = pCurrentItemHeader;
100  return STATUS_SUCCESS;
101  }
102  }
103 
104  // If a matching key was never found, simply return
105  return STATUS_NO_SUCH_MEMBER;
106  }
107 }
void FillInMemoryKey(IN PRFSD_KEY_ON_DISK pKeyOnDisk, IN RFSD_KEY_VERSION KeyVersion, IN OUT PRFSD_KEY_IN_MEMORY pKeyInMemory)
Definition: rfsd.c:2777
#define STATUS_NO_SUCH_MEMBER
Definition: ntstatus.h:597
unsigned char * PUCHAR
Definition: retypes.h:3
struct item_head * PRFSD_ITEM_HEAD
Definition: rfsd.h:40
__u16 blk_level
Definition: reiserfs_fs.h:679
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
__u16 blk_nr_item
Definition: reiserfs_fs.h:680
smooth NULL
Definition: ftsmooth.c:416
#define RFSD_KEYS_MATCH
Definition: rfsd.h:63
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__u16 ih_version
Definition: reiserfs_fs.h:538
struct reiserfs_key ih_key
Definition: reiserfs_fs.h:522
struct block_head * PRFSD_BLOCK_HEAD
Definition: rfsd.h:38
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Referenced by RfsdDirectoryCallback(), RfsdLoadItem(), and RfsdScanDirCallback().

◆ RfsdLoadItem()

NTSTATUS RfsdLoadItem ( IN PRFSD_VCB  Vcb,
IN PRFSD_KEY_IN_MEMORY  pItemKey,
OUT PRFSD_ITEM_HEAD ppMatchingItemHeader,
OUT PUCHAR ppItemBuffer,
OUT PUCHAR ppBlockBuffer,
OPTIONAL OUT PULONG  pBlockNumber,
IN RFSD_KEY_COMPARISON(*)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY fpComparisonFunction 
)

Given an item's key, load the block, the item header, and the item buffer associated with the key.

STATUS_INTERNAL_ERROR if leaf node could not be reached STATUS_NO_SUCH_MEMBER if the item header could not be located STATUS_INSUFFICIENT_RESOURCES if the leaf node buffer could not be allocated

Definition at line 118 of file rfsdblock.c.

127 {
129  ULONG LeafNodeBlockNumber;
130 
131  PAGED_CODE();
132 
133  // Clear the output pointers
134  *ppItemBuffer = *ppBlockBuffer = NULL;
135  *ppMatchingItemHeader = NULL;
136  if (pBlockNumber) *pBlockNumber = 0;
137 
138 
139  // Find the block number of the leaf node bock (on disk), that should contain the item w/ pItemKey
141  Vcb, pItemKey, Vcb->SuperBlock->s_root_block,
142  &(LeafNodeBlockNumber)
143  );
144  if (!NT_SUCCESS(Status)){ DbgBreak(); return STATUS_INTERNAL_ERROR; }
145  if (pBlockNumber) *pBlockNumber = LeafNodeBlockNumber;
146 
147 
148  // Load the block (which the caller must later free)
149  *ppBlockBuffer = RfsdAllocateAndLoadBlock(Vcb, LeafNodeBlockNumber);
150  if (!*ppBlockBuffer) { return STATUS_INSUFFICIENT_RESOURCES; }
151 
152 
153  // Get the item header and its information
155  Vcb, pItemKey, *ppBlockBuffer,
156  ( ppMatchingItemHeader ), //<
157  fpComparisonFunction
158  );
160  if (!*ppMatchingItemHeader) { return STATUS_INTERNAL_ERROR; }
161 
162  // Setup the item buffer
163  *ppItemBuffer = (PUCHAR) *ppBlockBuffer + (*ppMatchingItemHeader)->ih_item_location;
164 
165  return STATUS_SUCCESS;
166 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_NO_SUCH_MEMBER
Definition: ntstatus.h:597
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
PUCHAR RfsdAllocateAndLoadBlock(IN PRFSD_VCB Vcb, IN ULONG BlockIndex)
Definition: rfsdblock.c:34
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
Status
Definition: gdiplustypes.h:24
NTSTATUS RfsdFindItemHeaderInBlock(IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY pTargetKey, IN PUCHAR pBlockBuffer, OUT PRFSD_ITEM_HEAD *ppMatchingItemHeader, IN RFSD_KEY_COMPARISON(*fpComparisonFunction)(PRFSD_KEY_IN_MEMORY, PRFSD_KEY_IN_MEMORY))
Definition: rfsdblock.c:61
unsigned int ULONG
Definition: retypes.h:1
#define DbgBreak()
Definition: ext2fs.h:46
NTSTATUS NavigateToLeafNode(IN PRFSD_VCB Vcb, IN PRFSD_KEY_IN_MEMORY Key, IN ULONG StartingBlockNumber, OUT PULONG out_NextBlockNumber)
Definition: rfsd.c:2896
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define PAGED_CODE()

Variable Documentation

◆ RfsdGlobal

PRFSD_GLOBAL RfsdGlobal

Definition at line 17 of file init.c.