rossi.fstools.fs.ext2fs
Class Ext2Inode

java.lang.Object
  extended byrossi.fstools.fs.ext2fs.Ext2Inode
All Implemented Interfaces:
DiskStructure, Inode

public class Ext2Inode
extends java.lang.Object
implements DiskStructure, Inode

Representation of ext2/3 inode.

  On disk the superblock looks like this:

        31        24        16       8       0
        --------------------------------------
  0000  |  Mode         |     UID            |
        --------------------------------------
  0004  |          Size                      |
        --------------------------------------
  0008  |          ATime                     |
        --------------------------------------
  000C  |          CTime                     |
        --------------------------------------
  0010  |          MTime                     |
        --------------------------------------
  0014  |          DTime                     |
        --------------------------------------
  0018  |  GID         |  Num Links          |
        --------------------------------------
  001C  |          Block Count               |
        --------------------------------------
  0020  |          Flags                     |
        --------------------------------------
  0024  |          Reserved                  |
        --------------------------------------
  0028  |          Direct Block 0            |
        --------------------------------------
                        :                     
        --------------------------------------
  0054  |          Direct Block 11           |
        --------------------------------------
  0058  |          Indirect Block            |
        --------------------------------------
  005C  |      Double Indirect Block         |
        --------------------------------------
  0060  |      Triple Indirect Block         |
        --------------------------------------
  0064  |      File version                  |
        --------------------------------------
  0068  |      File ACL                      |
        --------------------------------------
  006C  |      Dir ACL                       |
        --------------------------------------
  0070  |      Fragment address              |
        --------------------------------------
  0074  | Frag | fsize   |    pad            |
        --------------------------------------
  0078  |   UID high     |    GID High       |
        --------------------------------------
  007C  |          Reserved                  |
        --------------------------------------
 


Field Summary
protected  long accessTime
           
protected  byte[] blockData
           
protected  long blocks
           
protected  long changedTime
           
protected  long deletedTime
           
protected  long dirACL
           
protected  long[] directBlocks
           
protected  long doubleIndirectBlock
           
static int EXT2_GOOD_OLD_INODE_SIZE
           
static int EXT2_N_BLOCKS
           
static int EXT2_NDIR_BLOCKS
           
protected  long fileACL
           
protected  long fileVersion
           
protected  long flags
           
protected  long fragAddr
           
protected  int fragNum
           
protected  int fragSize
           
protected  int gidHigh
           
protected  int gidLow
           
protected  long indirectBlock
           
protected  int mode
           
protected  long modifyTime
           
protected  int numLinks
           
protected  long sizeLow
           
protected  long tripleIndirectBlock
           
protected  int uidHigh
           
protected  int uidLow
           
 
Fields inherited from interface rossi.fstools.fs.Inode
BLOCKDEV_MODE, CHARDEV_MODE, DIRECTORY_MODE, FIFO_MODE, FILE_MODE, FILETYPE_MASK, SOCKET_MODE, SYMLINK_MODE
 
Constructor Summary
Ext2Inode()
           
 
Method Summary
 long getAccessTime()
          Get the time the data was last accessed.
 byte[] getBlockData()
          Get the block data as a byte array.
 long getBlocks()
          This field is really the number of SECTORS the file takes up on disk.
 long getChangedTime()
          Get the time this Inode metadata was last changed.
 int getDataSize()
          Get the size in bytes of the structure.
 long getDeletedTime()
           
 long getDirACL()
          This field is overloaded so that it contains the most significant 32 bits of the file size when mode == FILE_MODE
 long getDirectBlock(int blocknum)
          Get a direct block given its index.
 long[] getDirectBlocks()
          Get the direct block pointers as an array.
 long getDoubleIndirectBlock()
          Get the double indirect block pointer.
 long getFileACL()
           
 long getFileVersion()
           
 long getFlags()
           
 long getFragAddr()
           
 int getFragNum()
           
 int getFragSize()
           
 int getGidHigh()
           
 int getGidLow()
           
 long getGroupId()
          Get the group id of the object's owner.
 long getIndirectBlock()
          Get the indirect block pointer.
 int getMode()
          Get the mode of the file.
 long getModifyTime()
          Get the time the data was last modified.
 long getNumLinks()
          Get the number of hard links to this file.
 long getSize()
          Get the size of the data associated with the object.
 long getSizeLow()
          Get the low 32 bits of the file size.
 long getTripleIndirectBlock()
          Get the triple indirect block pointer.
 int getUidHigh()
           
 int getUidLow()
          Get the low 16 bits of the user id.
 long getUserId()
          Get the user id of the object's owner.
 void loadFromBuffer(byte[] buffer, int offset)
          Loads the object from a memory buffer
 void setAccessTime(long aAccessTime)
           
 void setBlockData(byte[] aBlockData)
           
 void setBlocks(long aBlocks)
           
 void setChangedTime(long aChangedTime)
           
 void setDeletedTime(long aDeletedTime)
           
 void setDirACL(long aDirACL)
           
 void setDirectBlocks(long[] aDirectBlocks)
           
 void setDoubleIndirectBlock(long aDoubleIndirectBlock)
           
 void setFileACL(long aFileACL)
           
 void setFileVersion(long aFileVersion)
           
 void setFlags(long aFlags)
           
 void setFragAddr(long aFragAddr)
           
 void setFragNum(int aFragNum)
           
 void setFragSize(int aFragSize)
           
 void setGidHigh(int aGidHigh)
           
 void setGidLow(int aGidLow)
           
 void setGroupId(long gid)
           
 void setIndirectBlock(long aIndirectBlock)
           
 void setMode(int aMode)
          Set the mode.
 void setModifyTime(long aModifyTime)
           
 void setNumLinks(long aNumLinks)
           
 void setSize(long s)
           
 void setSizeLow(long aSizeLow)
           
 void setTripleIndirectBlock(long aTripleIndirectBlock)
           
 void setUidHigh(int aUidHigh)
           
 void setUidLow(int aUidLow)
           
 void setUserId(long uid)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mode

protected int mode

uidLow

protected int uidLow

sizeLow

protected long sizeLow

accessTime

protected long accessTime

modifyTime

protected long modifyTime

changedTime

protected long changedTime

deletedTime

protected long deletedTime

gidLow

protected int gidLow

numLinks

protected int numLinks

blocks

protected long blocks

flags

protected long flags

directBlocks

protected long[] directBlocks

indirectBlock

protected long indirectBlock

doubleIndirectBlock

protected long doubleIndirectBlock

tripleIndirectBlock

protected long tripleIndirectBlock

blockData

protected byte[] blockData

fileVersion

protected long fileVersion

fileACL

protected long fileACL

dirACL

protected long dirACL

fragAddr

protected long fragAddr

fragNum

protected int fragNum

fragSize

protected int fragSize

uidHigh

protected int uidHigh

gidHigh

protected int gidHigh

EXT2_NDIR_BLOCKS

public static int EXT2_NDIR_BLOCKS

EXT2_N_BLOCKS

public static int EXT2_N_BLOCKS

EXT2_GOOD_OLD_INODE_SIZE

public static int EXT2_GOOD_OLD_INODE_SIZE
Constructor Detail

Ext2Inode

public Ext2Inode()
Method Detail

getDataSize

public int getDataSize()
Description copied from interface: DiskStructure
Get the size in bytes of the structure. For variable length sturctures this may represent the minimum length rather than the actual length.

Specified by:
getDataSize in interface DiskStructure
Returns:
the size of the structure.

getMode

public int getMode()
Get the mode of the file. This includes permission and type information.

Specified by:
getMode in interface Inode
Returns:
mode

setMode

public void setMode(int aMode)
Description copied from interface: Inode
Set the mode.

Specified by:
setMode in interface Inode
Parameters:
aMode - the mode.
See Also:
Inode.getMode()

getUidLow

public int getUidLow()
Get the low 16 bits of the user id.

Returns:
userid

setUidLow

public void setUidLow(int aUidLow)

getSizeLow

public long getSizeLow()
Get the low 32 bits of the file size.

Returns:
filesize

setSizeLow

public void setSizeLow(long aSizeLow)

getAccessTime

public long getAccessTime()
Description copied from interface: Inode
Get the time the data was last accessed.

Specified by:
getAccessTime in interface Inode
Returns:
the access time.

setAccessTime

public void setAccessTime(long aAccessTime)
Specified by:
setAccessTime in interface Inode

getModifyTime

public long getModifyTime()
Description copied from interface: Inode
Get the time the data was last modified.

Specified by:
getModifyTime in interface Inode
Returns:
the access time.

setModifyTime

public void setModifyTime(long aModifyTime)
Specified by:
setModifyTime in interface Inode

getChangedTime

public long getChangedTime()
Description copied from interface: Inode
Get the time this Inode metadata was last changed.

Specified by:
getChangedTime in interface Inode
Returns:
long

setChangedTime

public void setChangedTime(long aChangedTime)
Specified by:
setChangedTime in interface Inode

getDeletedTime

public long getDeletedTime()

setDeletedTime

public void setDeletedTime(long aDeletedTime)

getGidLow

public int getGidLow()

setGidLow

public void setGidLow(int aGidLow)

getNumLinks

public long getNumLinks()
Description copied from interface: Inode
Get the number of hard links to this file. A value of zero indicates that the object is deleted. A hard link is a directory entry pointing directly at this object (not via symlinks).

Specified by:
getNumLinks in interface Inode
Returns:
the number of links

setNumLinks

public void setNumLinks(long aNumLinks)
Specified by:
setNumLinks in interface Inode

getBlocks

public long getBlocks()
This field is really the number of SECTORS the file takes up on disk. That is the number of 512 byte sectors. This is completely unrelated to the blocksize set in the superblock. Also, this field is tested to determine if a symlink is a "fast symlink" or not.

Returns:
number of sectors.

setBlocks

public void setBlocks(long aBlocks)

getFlags

public long getFlags()

setFlags

public void setFlags(long aFlags)

getDirectBlocks

public long[] getDirectBlocks()
Get the direct block pointers as an array.

Returns:
long[] for direct pointers.
See Also:
getDirectBlock(int)

setDirectBlocks

public void setDirectBlocks(long[] aDirectBlocks)

getDirectBlock

public long getDirectBlock(int blocknum)
Get a direct block given its index.

Parameters:
blocknum - which of the 12 direct blocks to return
Returns:
long the block pointer

getIndirectBlock

public long getIndirectBlock()
Get the indirect block pointer. This is a pointer to a block of pointers.

Returns:
long

setIndirectBlock

public void setIndirectBlock(long aIndirectBlock)

getDoubleIndirectBlock

public long getDoubleIndirectBlock()
Get the double indirect block pointer. This is a pointer to a block of pointers that point to a block of pointers, which finally point to data blocks.

Returns:
long

setDoubleIndirectBlock

public void setDoubleIndirectBlock(long aDoubleIndirectBlock)

getTripleIndirectBlock

public long getTripleIndirectBlock()
Get the triple indirect block pointer.

Returns:
long

setTripleIndirectBlock

public void setTripleIndirectBlock(long aTripleIndirectBlock)

getBlockData

public byte[] getBlockData()
Get the block data as a byte array. Sometime data is stored in here such as fast symlinks.

Returns:
byte[] overlaid on the block pointers.

setBlockData

public void setBlockData(byte[] aBlockData)

getFileVersion

public long getFileVersion()

setFileVersion

public void setFileVersion(long aFileVersion)

getFileACL

public long getFileACL()

setFileACL

public void setFileACL(long aFileACL)

getDirACL

public long getDirACL()
This field is overloaded so that it contains the most significant 32 bits of the file size when mode == FILE_MODE

Returns:
directory ACL or high 32 bits of file size

setDirACL

public void setDirACL(long aDirACL)

getFragAddr

public long getFragAddr()

setFragAddr

public void setFragAddr(long aFragAddr)

getFragNum

public int getFragNum()

setFragNum

public void setFragNum(int aFragNum)

getFragSize

public int getFragSize()

setFragSize

public void setFragSize(int aFragSize)

getUidHigh

public int getUidHigh()

setUidHigh

public void setUidHigh(int aUidHigh)

getGidHigh

public int getGidHigh()

setGidHigh

public void setGidHigh(int aGidHigh)

getUserId

public long getUserId()
Description copied from interface: Inode
Get the user id of the object's owner.

Specified by:
getUserId in interface Inode
Returns:
the user id

setUserId

public void setUserId(long uid)
Specified by:
setUserId in interface Inode

setGroupId

public void setGroupId(long gid)
Specified by:
setGroupId in interface Inode

getGroupId

public long getGroupId()
Description copied from interface: Inode
Get the group id of the object's owner.

Specified by:
getGroupId in interface Inode
Returns:
the group id

getSize

public long getSize()
Description copied from interface: Inode
Get the size of the data associated with the object. This is mostly meaningful with normal files.

Specified by:
getSize in interface Inode
Returns:
the size

setSize

public void setSize(long s)
Specified by:
setSize in interface Inode

loadFromBuffer

public void loadFromBuffer(byte[] buffer,
                           int offset)
                    throws FsException
Description copied from interface: DiskStructure
Loads the object from a memory buffer

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.