-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in read_capacity (pull request #5)
Impl Read Capacity SCSI command. fixes issue #9.
- Loading branch information
Showing
3 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/src/main/java/net/alphadev/usbstorage/scsi/answer/ReadCapacityResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.alphadev.usbstorage.scsi.answer; | ||
|
||
import static net.alphadev.usbstorage.util.BitStitching.convertToInt; | ||
|
||
/** | ||
* @author Jan Seeger <[email protected]> | ||
*/ | ||
public class ReadCapacityResponse { | ||
public static final int LENGTH = 8; | ||
|
||
private int mBlockSize; | ||
private int mNumberOfBlocks; | ||
|
||
public ReadCapacityResponse(byte[] answer) { | ||
mNumberOfBlocks = convertToInt(answer, 0); | ||
mBlockSize = convertToInt(answer, 4); | ||
} | ||
|
||
public int getBlockSize() { | ||
return mBlockSize; | ||
} | ||
|
||
public int getNumberOfBlocks() { | ||
return mNumberOfBlocks; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
lib/src/main/java/net/alphadev/usbstorage/scsi/command/ReadCapacity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.alphadev.usbstorage.scsi.command; | ||
|
||
import net.alphadev.usbstorage.bbb.CommandBlockWrapper; | ||
import net.alphadev.usbstorage.scsi.answer.ReadCapacityResponse; | ||
|
||
import static net.alphadev.usbstorage.util.BitStitching.setBytesFromInt; | ||
|
||
/** | ||
* @author Jan Seeger <[email protected]> | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ReadCapacity extends ScsiCommand { | ||
public static final byte READ_CAPACITY = 0x25; | ||
|
||
private int mLogicalBlockAddress; | ||
private byte mControl; | ||
|
||
public ReadCapacity() { | ||
super(READ_CAPACITY); | ||
} | ||
|
||
@Override | ||
public CommandBlockWrapper.Direction getDirection() { | ||
return CommandBlockWrapper.Direction.DEVICE_TO_HOST; | ||
} | ||
|
||
@Override | ||
public byte[] asBytes() { | ||
byte[] retval = new byte[10]; | ||
retval[0] = READ_CAPACITY; // opcode | ||
// retval[1] is reserved | ||
setBytesFromInt(mLogicalBlockAddress, retval, 2); | ||
// retval[6-8] is reserved | ||
retval[9] = mControl; | ||
return retval; | ||
} | ||
|
||
|
||
@Override | ||
public int getExpectedAnswerLength() { | ||
return ReadCapacityResponse.LENGTH; | ||
} | ||
|
||
public int getLogicalBlockAddress() { | ||
return mLogicalBlockAddress; | ||
} | ||
|
||
public void setLogicalBlockAddress(int logicalBlockAddress) { | ||
this.mLogicalBlockAddress = logicalBlockAddress; | ||
} | ||
|
||
public void setControl(byte control) { | ||
this.mControl = control; | ||
} | ||
} |