rossi.fstools.fs.reiserfs
Class FBlock

java.lang.Object
  extended byrossi.fstools.fs.reiserfs.FBlock
All Implemented Interfaces:
DiskStructure
Direct Known Subclasses:
InternalNode, LeafNode

public class FBlock
extends java.lang.Object
implements DiskStructure

Representation of a formated block. This is one of 2 types, either an InternalNode or a LeafNode. This base class handles the block header.

Both InternalNode and Leaf node have a common header which is represented here.

  On disk the block header looks like this:

        31        24        16       8       0
        --------------------------------------
  0000  |        Level     |  Num Items      |
        --------------------------------------
  0004  |     Free Space   |  Reserved       |
        --------------------------------------
  0008  |            Right Key               |
        --------------------------------------
  000C  |            Right Key               |
        --------------------------------------
  0010  |            Right Key               |
        --------------------------------------
  0014  |            Right Key               |
        --------------------------------------
 


Field Summary
protected  int blocknum
           
protected  int freeSpace
           
protected  int level
           
protected  int numItems
           
protected  FBlock parent
           
protected  int reserved
           
protected  Key rightKey
           
protected  ReiserSuperBlock sb
           
 
Constructor Summary
FBlock(ReiserSuperBlock sb, int blocknum)
          Create a new formated block.
 
Method Summary
static FBlock createFromBuffer(ReiserSuperBlock sb, int blocknum, byte[] buffer, int blkoffset)
          Create a formatted block instance.
 int getBlockHeaderSize()
          Get the size of the header for this formatted block.
 int getBlockNum()
           
 int getDataSize()
          Get size of this structure.
 int getFreeSpace()
          Get the amount of free space within this block.
 int getLevel()
          Get the level of this block in the B+tree.
 int getNumItems()
          Get the number of items or keys within this block.
 FBlock getParent()
          Get the parent of this block.
 int getReserved()
           
 Key getRightKey()
          Get the right most (hightest in sort order) key contained within this block.
 ReiserSuperBlock getSuperBlock()
          Get the superblock for this filesystem.
 void loadFromBuffer(byte[] buffer, int offset)
          Load this structure from disk.
 void setFreeSpace(int aFreeSpace)
           
 void setLevel(int aLevel)
           
 void setNumItems(int aNumItems)
           
 void setParent(FBlock aParent)
          Set the parent of this block.
 void setReserved(int aReserved)
           
 void setRightKey(Key aRightKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

level

protected int level

numItems

protected int numItems

freeSpace

protected int freeSpace

reserved

protected int reserved

rightKey

protected Key rightKey

sb

protected ReiserSuperBlock sb

blocknum

protected int blocknum

parent

protected FBlock parent
Constructor Detail

FBlock

public FBlock(ReiserSuperBlock sb,
              int blocknum)
Create a new formated block.

Parameters:
sb - a ReiserSuperBlock
blocknum - a int
Method Detail

getBlockHeaderSize

public int getBlockHeaderSize()
Get the size of the header for this formatted block.

Returns:
block header size.

getDataSize

public int getDataSize()
Get size of this structure.

Specified by:
getDataSize in interface DiskStructure
Returns:
size
See Also:
DiskStructure.getDataSize()

getSuperBlock

public ReiserSuperBlock getSuperBlock()
Get the superblock for this filesystem.

Returns:
superblock

getBlockNum

public int getBlockNum()

getParent

public FBlock getParent()
Get the parent of this block. This is to allow walking back up the tree.

Returns:
parent block.

setParent

public void setParent(FBlock aParent)
Set the parent of this block. This is to allow walking back up the tree.


getLevel

public int getLevel()
Get the level of this block in the B+tree. A level of 1 indicates a Leaf block. Greater than one indicates a node block. A level of zero indicates a free block.

Returns:
level.

setLevel

public void setLevel(int aLevel)

getNumItems

public int getNumItems()
Get the number of items or keys within this block. Leaf blocks contain items, node blocks contain keys.

Returns:
int
See Also:
LeafNode, InternalNode

setNumItems

public void setNumItems(int aNumItems)

getFreeSpace

public int getFreeSpace()
Get the amount of free space within this block.

Returns:
number of bytes of free space.

setFreeSpace

public void setFreeSpace(int aFreeSpace)

getReserved

public int getReserved()

setReserved

public void setReserved(int aReserved)

getRightKey

public Key getRightKey()
Get the right most (hightest in sort order) key contained within this block.

Returns:
the rightmost Key

setRightKey

public void setRightKey(Key aRightKey)

createFromBuffer

public static FBlock createFromBuffer(ReiserSuperBlock sb,
                                      int blocknum,
                                      byte[] buffer,
                                      int blkoffset)
                               throws FsException
Create a formatted block instance. This is a factory method that reads the supplied buffer and creates the appropriate subclass.

Parameters:
sb - a ReiserSuperBlock for this filesystem
blocknum - block number of the block to be processed.
buffer - a byte[] buffer containing the block
blkoffset - a int offset into the buffer to the start of the block
Returns:
FBlock subclass -- either an InternalNode or LeafNode
Throws:
FsException

loadFromBuffer

public void loadFromBuffer(byte[] buffer,
                           int offset)
                    throws FsException
Load this structure from disk.

Specified by:
loadFromBuffer in interface DiskStructure
Parameters:
buffer - a byte[] containing data to be read in populating the object
offset - a int indicating the offset within the buffer to start parsing.
Throws:
FsException - if a parse error occurs
See Also:
DiskStructure.loadFromBuffer(byte[], int)