Package com.github.mjdev.libaums.driver
Class ByteBlockDevice
- java.lang.Object
-
- com.github.mjdev.libaums.driver.ByteBlockDevice
-
- All Implemented Interfaces:
BlockDeviceDriver
- Direct Known Subclasses:
Partition
public class ByteBlockDevice extends java.lang.Object implements BlockDeviceDriver
Simple class which wraps around an existingBlockDeviceDriverto enable byte addressing of content. Uses byte offsets instead of device oddsets inwrite(long, ByteBuffer)andread(long, ByteBuffer). UsesBlockDeviceDriver.getBlockSize()to calculate device offsets.
-
-
Constructor Summary
Constructors Constructor Description ByteBlockDevice(BlockDeviceDriver targetBlockDevice)ByteBlockDevice(BlockDeviceDriver targetBlockDevice, int logicalOffsetToAdd)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetBlockSize()Returns the block size of the block device.voidinit()Initializes the block device for further use.voidread(long byteOffset, java.nio.ByteBuffer dest)Reads from the block device at a certain offset into the given buffer.voidwrite(long byteOffset, java.nio.ByteBuffer src)Writes to the block device at a certain offset from the given buffer.
-
-
-
Constructor Detail
-
ByteBlockDevice
public ByteBlockDevice(BlockDeviceDriver targetBlockDevice, int logicalOffsetToAdd)
-
ByteBlockDevice
public ByteBlockDevice(BlockDeviceDriver targetBlockDevice)
-
-
Method Detail
-
init
public void init() throws java.io.IOExceptionDescription copied from interface:BlockDeviceDriverInitializes the block device for further use. This method should be called before doing anything else on the block device.- Specified by:
initin interfaceBlockDeviceDriver- Throws:
java.io.IOException- If initializing fails
-
read
public void read(long byteOffset, java.nio.ByteBuffer dest) throws java.io.IOExceptionDescription copied from interface:BlockDeviceDriverReads from the block device at a certain offset into the given buffer. The amount of bytes to be read are determined byBuffer.remaining().The deviceOffset can either be the amount of bytes or a logical block addressing using the block size. To get the bytes in the last case you have to multiply the lba with the block size (offset *
BlockDeviceDriver.getBlockSize()).- Specified by:
readin interfaceBlockDeviceDriver- Parameters:
byteOffset- The offset where the reading should begin.dest- The buffer where the data should be read into.- Throws:
java.io.IOException- If reading fails.
-
write
public void write(long byteOffset, java.nio.ByteBuffer src) throws java.io.IOExceptionDescription copied from interface:BlockDeviceDriverWrites to the block device at a certain offset from the given buffer. The amount of bytes to be written are determined byBuffer.remaining().The deviceOffset can either be the amount of bytes or a logical block addressing using the block size. To get the bytes in the last case you have to multiply the lba with the block size (offset *
BlockDeviceDriver.getBlockSize()).- Specified by:
writein interfaceBlockDeviceDriver- Parameters:
byteOffset- The offset where the writing should begin.src- The buffer with the data to be transferred.- Throws:
java.io.IOException- If writing fails.
-
getBlockSize
public int getBlockSize()
Description copied from interface:BlockDeviceDriverReturns the block size of the block device. Every block device can only read and store bytes in a specific block with a certain size.That means that it is only possible to read or write hole blocks!
- Specified by:
getBlockSizein interfaceBlockDeviceDriver- Returns:
- The block size in bytes, mostly 512 bytes.
-
-