diff --git a/smartie/scsi/__init__.py b/smartie/scsi/__init__.py index 59abdd2..5fdf1a2 100644 --- a/smartie/scsi/__init__.py +++ b/smartie/scsi/__init__.py @@ -140,7 +140,7 @@ def identify( command16 = Command16( operation_code=OperationCode.COMMAND_16, - protocol=ATAProtocol.PIO_DATA_IN << 1, + protocol=ATAProtocol.PIO_DATA_IN, flags=CommandFlags( t_length=CommandFlags.Length.IN_SECTOR_COUNT, byt_blok=True, @@ -227,7 +227,7 @@ def smart_thresholds(self) -> Tuple[SmartThresholdResponse, SCSIResponse]: command16 = Command16( operation_code=OperationCode.COMMAND_16, - protocol=ATAProtocol.PIO_DATA_IN << 1, + protocol=ATAProtocol.PIO_DATA_IN, command=ATACommands.SMART, flags=CommandFlags( t_length=CommandFlags.Length.IN_SECTOR_COUNT, @@ -236,7 +236,8 @@ def smart_thresholds(self) -> Tuple[SmartThresholdResponse, SCSIResponse]: ck_cond=True, ), features=ATASmartFeature.SMART_READ_THRESHOLDS, - ).set_lba(0xC24F00) + ) + command16.lba = 0xC24F00 response = self.issue_command(Direction.FROM, command16, thresholds) return thresholds, response @@ -249,7 +250,7 @@ def smart(self) -> Tuple[SmartDataResponse, SCSIResponse]: command16 = Command16( operation_code=OperationCode.COMMAND_16, - protocol=ATAProtocol.PIO_DATA_IN << 1, + protocol=ATAProtocol.PIO_DATA_IN, command=ATACommands.SMART, flags=CommandFlags( t_length=CommandFlags.Length.IN_SECTOR_COUNT, @@ -258,7 +259,8 @@ def smart(self) -> Tuple[SmartDataResponse, SCSIResponse]: ck_cond=True, ), features=ATASmartFeature.SMART_READ_DATA, - ).set_lba(0xC24F00) + ) + command16.lba = 0xC24F00 response = self.issue_command(Direction.FROM, command16, smart) return smart, response diff --git a/smartie/scsi/structures.py b/smartie/scsi/structures.py index e548546..0cf5ddd 100644 --- a/smartie/scsi/structures.py +++ b/smartie/scsi/structures.py @@ -273,23 +273,30 @@ class Command12(ctypes.Structure): _pack_ = 1 _fields_ = [ ("operation_code", ctypes.c_ubyte), - ("protocol", ctypes.c_ubyte), + ("reserved_1", ctypes.c_ubyte, 1), + ("protocol", ctypes.c_ubyte, 4), + ("multiple_count", ctypes.c_ubyte, 3), ("flags", CommandFlags), ("features", ctypes.c_ubyte), - ("reserved_1", ctypes.c_ubyte, 1), - ("sector_count", ctypes.c_ubyte, 7), - ("reserved_2", ctypes.c_ubyte, 1), - ("lba_low", ctypes.c_ubyte, 7), - ("reserved_3", ctypes.c_ubyte, 1), - ("lba_mid", ctypes.c_ubyte, 7), - ("reserved_4", ctypes.c_ubyte, 1), - ("lba_high", ctypes.c_ubyte, 7), + ("sector_count", ctypes.c_ubyte), + ("lba_low", ctypes.c_ubyte), + ("lba_mid", ctypes.c_ubyte), + ("lba_high", ctypes.c_ubyte), ("device", ctypes.c_ubyte), ("command", ctypes.c_ubyte), - ("reserved_5", ctypes.c_ubyte), + ("reserved_2", ctypes.c_ubyte), ("control", ctypes.c_ubyte), ] + @property + def lba(self): + return self.lba_low | (self.lba_mid << 8) | (self.lba_high << 16) + + @lba.setter + def lba(self, lba: int): + self.lba_low, self.lba_mid, self.lba_high = \ + lba.to_bytes(3, byteorder="little") + class Command16(ctypes.BigEndianStructure): """ @@ -304,7 +311,9 @@ class Command16(ctypes.BigEndianStructure): _pack_ = 1 _fields_ = [ ("operation_code", ctypes.c_ubyte), - ("protocol", ctypes.c_ubyte), + ("extend", ctypes.c_ubyte, 1), + ("protocol", ctypes.c_ubyte, 4), + ("multiple_count", ctypes.c_ubyte, 3), ("flags", CommandFlags), ("features", ctypes.c_ushort), ("sector_count", ctypes.c_ushort), @@ -319,16 +328,22 @@ class Command16(ctypes.BigEndianStructure): ("control", ctypes.c_ubyte), ] - def set_lba(self, lba: int): - lba = lba.to_bytes(6, byteorder="little") - self.lba_high_low = lba[3] - self.lba_low = lba[0] - self.lba_high_mid = lba[4] - self.lba_mid = lba[1] - self.lba_high_high = lba[5] - self.lba_high = lba[2] - - return self + @property + def lba(self): + lba = self.lba_low | (self.lba_mid << 8) | (self.lba_high << 16) + if not self.extend: + return lba + lba = lba | (self.lba_high_low << 24) | (self.lba_high_mid << 32) | \ + (self.lba_high_high << 40) + return lba + + @lba.setter + def lba(self, lba: int): + self.lba_low, self.lba_mid, self.lba_high, \ + self.lba_high_low, self.lba_high_mid, self.lba_high_high = \ + lba.to_bytes(6, byteorder="little") + + self.extend = lba > 0xFFFFFF class SGIOHeader(ctypes.Structure):