org.blinkenbyte.io
Interface BlockDevice

All Known Implementing Classes:
BadBlockEmulator, BlockDeviceFilter, NormalBlockDevice, WindowsBlockDevice

public interface BlockDevice

This interface models a block device, providing methods for random reads and writes, and querying device geometry.


Nested Class Summary
static class BlockDevice.DriveGeometry
          Class representing the geometry of a device
 
Method Summary
 void close()
          Close the device.
 boolean getAutoSectorAlign()
          Returns whether the device is set to automatically align reads/writes to sector boundaries.
 BlockDevice.DriveGeometry getDriveGeometry()
          Returns an object describing the geometry of the device.
 long getFilePointer()
          Returns the current pointer for read and write operations.
 int getSectorSize()
          Returns the sector size of the device.
 int getSectorSizeLog()
          Returns the base 2 logarithm of the sector size of the device.
 long length()
          Returns the size in bytes of the device.
 void open(java.lang.String filename, boolean allowWrite, boolean syncWriteData, boolean syncWriteMetaData, boolean sectorMode)
          Open the device.
 int read()
          Reads and returns a single byte.
 int read(byte[] b)
          Reads bytes into the array.
 int read(byte[] b, int offset, int len)
          Reads bytes into the array.
 void seek(long pos)
          Seeks the read/write pointer to the specified position.
 void setAutoSectorAlign(boolean _autoSectorAlign)
          Sets whether the device should automatically align read/write requests.
 void setSectorSize(int sectorSize)
          Sets the sector size of the device.
 int skipBytes(int n)
          Advances the read/write pointer n bytes.
 void write(byte[] b)
          Writes the contents of b to the device.
 void write(byte[] b, int offset, int len)
          Writes len bytes to the device starting from b[offset].
 void write(int b)
          Writes one byte to the device.
 

Method Detail

close

void close()
           throws java.io.IOException
Close the device.

Throws:
java.io.IOException

open

void open(java.lang.String filename,
          boolean allowWrite,
          boolean syncWriteData,
          boolean syncWriteMetaData,
          boolean sectorMode)
          throws java.lang.Exception
Open the device.

Parameters:
filename - The filename or device name to open
allowWrite - If true, allow write access to the device.
syncWriteData - If true, always flush writes to the device.
syncWriteMetaData - If true, always flush writes of the device's metadata.
sectorMode - If true, all reads and writes should be on sector boundaries, and exceptions should be thrown if a request is not aligned.
Throws:
java.lang.Exception

getFilePointer

long getFilePointer()
                    throws java.io.IOException
Returns the current pointer for read and write operations.

Throws:
java.io.IOException

length

long length()
            throws java.io.IOException
Returns the size in bytes of the device.

Throws:
java.io.IOException

read

int read()
         throws java.io.IOException
Reads and returns a single byte.

Throws:
java.io.IOException

read

int read(byte[] b)
         throws java.io.IOException
Reads bytes into the array. Unless the end of the device has been reached, at least one byte will be read, and at most b.length bytes.

Throws:
java.io.IOException

read

int read(byte[] b,
         int offset,
         int len)
         throws java.io.IOException
Reads bytes into the array. Unless the end of the device has been reached, at least one byte will be read, and at most len bytes.

Throws:
java.io.IOException

seek

void seek(long pos)
          throws java.io.IOException
Seeks the read/write pointer to the specified position. Position is 0-based.

Throws:
java.io.IOException

skipBytes

int skipBytes(int n)
              throws java.io.IOException
Advances the read/write pointer n bytes.

Throws:
java.io.IOException

write

void write(byte[] b)
           throws java.io.IOException
Writes the contents of b to the device.

Throws:
java.io.IOException

write

void write(byte[] b,
           int offset,
           int len)
           throws java.io.IOException
Writes len bytes to the device starting from b[offset].

Throws:
java.io.IOException

write

void write(int b)
           throws java.io.IOException
Writes one byte to the device.

Throws:
java.io.IOException

getDriveGeometry

BlockDevice.DriveGeometry getDriveGeometry()
                                           throws java.lang.Exception
Returns an object describing the geometry of the device.

Throws:
java.lang.Exception

getSectorSize

int getSectorSize()
Returns the sector size of the device.


setSectorSize

void setSectorSize(int sectorSize)
                   throws java.lang.Exception
Sets the sector size of the device.

Throws:
java.lang.Exception

getSectorSizeLog

int getSectorSizeLog()
Returns the base 2 logarithm of the sector size of the device.


getAutoSectorAlign

boolean getAutoSectorAlign()
Returns whether the device is set to automatically align reads/writes to sector boundaries. If an unaligned read is performed, an aligned read should be performed and the relevant part of the data copied to the buffer. If an unaligned write is performed, an aligned read should be performed to get the values of the bytes not being written, after which an aligned write should be performed.


setAutoSectorAlign

void setAutoSectorAlign(boolean _autoSectorAlign)
Sets whether the device should automatically align read/write requests.