rossi.fstools.fs.fatfs
Class FatSuperBlock

java.lang.Object
  extended byrossi.fstools.fs.fatfs.FatSuperBlock
All Implemented Interfaces:
DiskStructure, SuperBlock

public class FatSuperBlock
extends java.lang.Object
implements SuperBlock

Representation of FAT superblock.

  On disk the superblock looks like this:

        31        24        16       8       0
        --------------------------------------
  0000  |    Bootstrap               | SysID |
        --------------------------------------
  0004  |         System ID                  |
        --------------------------------------
  0008  |         System ID          |SectSze|
        --------------------------------------
  000C  |SectSze |SecPerClus| Reserved Sects |
        --------------------------------------
  0010  |NumFats | Root Dir Entries  |sectors|
        --------------------------------------
  0014  |sectors | Media    | Fat Length     |
        --------------------------------------
  0018  |Sectors per Track  | Heads          |
        --------------------------------------
  001C  |        Hidden Sectors              |
        --------------------------------------
  0020  |        Total Sectors               |
        --------------------------------------
  0024  |        Fat32 length                |
        --------------------------------------
  0028  | Flags             |  Version       |
        --------------------------------------
  002C  |        Root cluster                |
        --------------------------------------
  0030  | Info Sector       |  backup boot   |
        --------------------------------------
  0034  |        Reserved                    |
        --------------------------------------

 


Field Summary
protected  int backupBootSector
           
protected  byte[] bootStrap
           
protected  long fat32Length
           
protected  int fatLength
           
protected  int flags
           
protected  int heads
           
protected  long hiddenSectors
           
protected  int infoSector
           
static int MAX_FAT12
          Max number of clusters for FAT12.
static int MAX_FAT16
          Max number of clusters for FAT16.
static int MAX_FAT32
          Max number of clusters for FAT32.
protected  byte media
           
protected  int numFATs
           
protected  int reservedSectors
           
protected  long rootCluster
           
protected  int rootDirEntries
           
protected  int sectors
           
protected  int sectorSize
           
protected  int sectorsPerCluster
           
protected  int sectorsPerTrack
           
protected  java.lang.String systemId
           
protected  long totalSectors
           
protected  int version
           
 
Constructor Summary
FatSuperBlock()
          Default constructor.
 
Method Summary
 int getBackupBootSector()
          Get the sector address of the backup boot sector.
 byte[] getBootStrap()
          Return the first 3 bytes of the filesystem.
 int getDataSize()
          Get the size in bytes of the structure.
 long getFat32Length()
          Get the length of the FAT in sectors for a FAT32 system.
 int getFatBits()
          Get the number bits per entry in the FAT.
 int getFatLength()
          FAT length in sectors.
 int getFirstDataSector()
          Get the sector address of the first data sector (cluster 2).
 int getFlags()
          Not sure what this is for.
 int getHeads()
          Number of heads.
 long getHiddenSectors()
          Number of hidden sectors.
 int getInfoSector()
          Get the sector address of the FAT32 info block.
 byte getMedia()
          Media descriptor byte.
 long getNumClusters()
          Get the number of clusters.
 int getNumFATs()
          Get the number of FAT tables.
 long getNumSectors()
          Get the number of sectors in the filesystem.
 int getReservedSectors()
          Get the number of reserved sectors.
 long getRootCluster()
          Get the first cluster of the root directory.
 int getRootDirEntries()
          Get the number of root directory entries.
 int getSectors()
          Get the count of sectors in the FS.
 int getSectorSize()
          Sector size.
 int getSectorsPerCluster()
          Get number of sectors per cluster.
 int getSectorsPerTrack()
          Number of sectors per track.
 java.lang.String getSystemId()
          Get the system identifier.
 long getTotalSectors()
          Total sectors in the filesystem.
 int getVersion()
          Get the filesystem version.
 void loadFromBuffer(byte[] buffer, int offset)
          Loads the object from a memory buffer
 void setBackupBootSector(int aBackupBootSector)
           
 void setBootStrap(byte[] aBootStrap)
           
 void setFat32Length(long aFat32Length)
           
 void setFatLength(int aFatLength)
           
 void setFlags(int aFlags)
           
 void setHeads(int aHeads)
           
 void setHiddenSectors(long aHiddenSectors)
           
 void setInfoSector(int aInfoSector)
           
 void setMedia(byte aMedia)
           
 void setNumFATs(int aNumFATs)
           
 void setReservedSectors(int aReservedSectors)
           
 void setRootCluster(long aRootCluster)
           
 void setRootDirEntries(int aRootDirEntries)
           
 void setSectors(int aSectors)
           
 void setSectorSize(int aSectorSize)
           
 void setSectorsPerCluster(int aSectorsPerCluster)
           
 void setSectorsPerTrack(int aSectorsPerTrack)
           
 void setSystemId(java.lang.String aSystemId)
           
 void setTotalSectors(long aTotalSectors)
           
 void setVersion(int aVersion)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bootStrap

protected byte[] bootStrap

systemId

protected java.lang.String systemId

sectorSize

protected int sectorSize

sectorsPerCluster

protected int sectorsPerCluster

reservedSectors

protected int reservedSectors

numFATs

protected int numFATs

rootDirEntries

protected int rootDirEntries

sectors

protected int sectors

media

protected byte media

fatLength

protected int fatLength

sectorsPerTrack

protected int sectorsPerTrack

heads

protected int heads

hiddenSectors

protected long hiddenSectors

totalSectors

protected long totalSectors

fat32Length

protected long fat32Length

flags

protected int flags

version

protected int version

rootCluster

protected long rootCluster

infoSector

protected int infoSector

backupBootSector

protected int backupBootSector

MAX_FAT12

public static final int MAX_FAT12
Max number of clusters for FAT12.

See Also:
Constant Field Values

MAX_FAT16

public static final int MAX_FAT16
Max number of clusters for FAT16.

See Also:
Constant Field Values

MAX_FAT32

public static final int MAX_FAT32
Max number of clusters for FAT32.

See Also:
Constant Field Values
Constructor Detail

FatSuperBlock

public FatSuperBlock()
Default constructor.

Method Detail

getBootStrap

public byte[] getBootStrap()
Return the first 3 bytes of the filesystem. This typically contains a jump instruction to the bootstrap loader.

Returns:
bootStrap instruction.

setBootStrap

public void setBootStrap(byte[] aBootStrap)

getSystemId

public java.lang.String getSystemId()
Get the system identifier.

Returns:
system id

setSystemId

public void setSystemId(java.lang.String aSystemId)

getSectorSize

public int getSectorSize()
Sector size. Should be 512 bytes.

Returns:
sector size.

setSectorSize

public void setSectorSize(int aSectorSize)

getSectorsPerCluster

public int getSectorsPerCluster()
Get number of sectors per cluster. A cluster is the minimum allocation unit for files.


setSectorsPerCluster

public void setSectorsPerCluster(int aSectorsPerCluster)

getReservedSectors

public int getReservedSectors()
Get the number of reserved sectors. The FAT tables begin this many sectors into the filesystem.

Returns:
reservedSectors.

setReservedSectors

public void setReservedSectors(int aReservedSectors)

getNumFATs

public int getNumFATs()
Get the number of FAT tables. Usually 2.

Returns:
numFATs.

setNumFATs

public void setNumFATs(int aNumFATs)

getRootDirEntries

public int getRootDirEntries()
Get the number of root directory entries. This is only valid in FAT16 and FAT12, it will be zero in FAT32.


setRootDirEntries

public void setRootDirEntries(int aRootDirEntries)

getSectors

public int getSectors()
Get the count of sectors in the FS. Note that this is a 16 bit number and will be set to zero if the FS contains more than 65535 sectors. Unused in FAT32.

Returns:
numSectors.
See Also:
getTotalSectors()

setSectors

public void setSectors(int aSectors)

getMedia

public byte getMedia()
Media descriptor byte.

Returns:
media

setMedia

public void setMedia(byte aMedia)

getFatLength

public int getFatLength()
FAT length in sectors. Not used in FAT32.

Returns:
fat length
See Also:
getFat32Length()

setFatLength

public void setFatLength(int aFatLength)

getSectorsPerTrack

public int getSectorsPerTrack()
Number of sectors per track.

Returns:
sectors per track.

setSectorsPerTrack

public void setSectorsPerTrack(int aSectorsPerTrack)

getHeads

public int getHeads()
Number of heads.

Returns:
heads

setHeads

public void setHeads(int aHeads)

getHiddenSectors

public long getHiddenSectors()
Number of hidden sectors. Unused.

Returns:
hidden

setHiddenSectors

public void setHiddenSectors(long aHiddenSectors)

getTotalSectors

public long getTotalSectors()
Total sectors in the filesystem. This 32 bit value is only used if the 16 bit sectors value is zero.

Returns:
long
See Also:
getSectors()

setTotalSectors

public void setTotalSectors(long aTotalSectors)

getFat32Length

public long getFat32Length()
Get the length of the FAT in sectors for a FAT32 system. This overrides getFatLength() that is used in FAT12/16 systems.

Returns:
fat length in sectors;
See Also:
getFatLength()

setFat32Length

public void setFat32Length(long aFat32Length)

getFlags

public int getFlags()
Not sure what this is for. Unused here. Only valid for FAT32.

Returns:
flags.

setFlags

public void setFlags(int aFlags)

getVersion

public int getVersion()
Get the filesystem version. Only valid for FAT32.

Returns:
version

setVersion

public void setVersion(int aVersion)

getRootCluster

public long getRootCluster()
Get the first cluster of the root directory. This is only used for FAT32. In FAT12 and FAT16, the root directory isn't allocated via the FAT table. Rather it is of fixed size and resides between the end of the FAT tables and the start of the data area.

Returns:
root cluster

setRootCluster

public void setRootCluster(long aRootCluster)

getInfoSector

public int getInfoSector()
Get the sector address of the FAT32 info block.

Returns:
fat 32 info block location

setInfoSector

public void setInfoSector(int aInfoSector)

getBackupBootSector

public int getBackupBootSector()
Get the sector address of the backup boot sector. Only valid in FAT32.

Returns:
backup boot sector address.

setBackupBootSector

public void setBackupBootSector(int aBackupBootSector)

getNumSectors

public long getNumSectors()
Get the number of sectors in the filesystem. This handles figuring out which fields from the disk to use to arrive at the correct result.

Returns:
total number of sectors in the filesystem

getNumClusters

public long getNumClusters()
Get the number of clusters. The number of clusters is computed from the number of sectors less the reserved sectors, the root directory sectors (if any), and the FAT sectors.

Returns:
number of clusters.

getFatBits

public int getFatBits()
Get the number bits per entry in the FAT.

Returns:
number of fat bits.

getFirstDataSector

public int getFirstDataSector()
Get the sector address of the first data sector (cluster 2).


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.

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.