-
- All Implemented Interfaces:
-
com.github.mjdev.libaums.driver.BlockDeviceDriver
public class ByteBlockDevice implements BlockDeviceDriver
Simple class which wraps around an existing BlockDeviceDriver to enable byte addressing of content. Uses byte offsets instead of device oddsets in ByteBlockDevice.write and ByteBlockDevice.read. Uses BlockDeviceDriver.getBlockSize to calculate device offsets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classByteBlockDevice.Companion
-
Constructor Summary
Constructors Constructor Description ByteBlockDevice(BlockDeviceDriver targetBlockDevice, Integer logicalOffsetToAdd)ByteBlockDevice(BlockDeviceDriver targetBlockDevice)
-
Method Summary
Modifier and Type Method Description IntegergetBlockSize()Returns the block size of the block device. LonggetBlocks()The size of the block device, in blocks of blockSize bytes, Unitinit()Initializes the block device for further use. Unitread(Long byteOffset, ByteBuffer dest)Reads from the block device at a certain offset into the given buffer. Unitwrite(Long byteOffset, ByteBuffer src)Writes to the block device at a certain offset from the given buffer. -
-
Constructor Detail
-
ByteBlockDevice
ByteBlockDevice(BlockDeviceDriver targetBlockDevice, Integer logicalOffsetToAdd)
-
ByteBlockDevice
ByteBlockDevice(BlockDeviceDriver targetBlockDevice)
-
-
Method Detail
-
getBlockSize
Integer getBlockSize()
Returns 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 whole blocks!
-
init
Unit init()
Initializes the block device for further use. This method should be called before doing anything else on the block device.
-
read
Unit read(Long byteOffset, ByteBuffer dest)
Reads from the block device at a certain offset into the given buffer. The amount of bytes to be read are determined by java.nio.ByteBuffer.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 * .getBlockSize).
- Parameters:
byteOffset- The offset where the reading should begin.dest- The buffer where the data should be read into.
-
write
Unit write(Long byteOffset, ByteBuffer src)
Writes to the block device at a certain offset from the given buffer. The amount of bytes to be written are determined by java.nio.ByteBuffer.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 * .getBlockSize).
- Parameters:
byteOffset- The offset where the writing should begin.src- The buffer with the data to be transferred.
-
-
-
-