При попытке извлечь специфичную для поставщика функцию c для одного из моих дисков (cmd = 0x89) я получаю ошибку переполнения: OverflowError: signed integer is greater than maximum
. Ошибка выдается сразу после вызова ioctl. Трассировка также не очень информативна:
Traceback (most recent call last):
File "lockbx/atacmd.py", line 148, in <module>
GetDriveIdSgIo("/dev/sda")
File "lockbx/atacmd.py", line 134, in GetDriveIdSgIo
ret = fcntl.ioctl(fd.fileno(), SG_IO, ctypes.addressof(sgio))
OverflowError: signed integer is greater than maximum
Справочник по сквозным командам ATA: http://www.t10.org/ftp/t10/document.04/04-262r8.pdf
class AtaCmd(ctypes.Structure):
_fields_ = [
('opcode', ctypes.c_ubyte),
('protocol', ctypes.c_ubyte),
('flags', ctypes.c_ubyte),
('features', ctypes.c_ubyte),
('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', ctypes.c_ubyte),
('control', ctypes.c_ubyte)]
class SgioHdr(ctypes.Structure):
"""<scsi/sg.h> sg_io_hdr_t."""
_fields_ = [
('interface_id', ctypes.c_int),
('dxfer_direction', ctypes.c_int),
('cmd_len', ctypes.c_ubyte),
('mx_sb_len', ctypes.c_ubyte),
('iovec_count', ctypes.c_ushort),
('dxfer_len', ctypes.c_uint),
('dxferp', ctypes.c_void_p),
('cmdp', ctypes.c_void_p),
('sbp', ctypes.c_void_p),
('timeout', ctypes.c_uint),
('flags', ctypes.c_uint),
('pack_id', ctypes.c_int),
('usr_ptr', ctypes.c_void_p),
('status', ctypes.c_ubyte),
('masked_status', ctypes.c_ubyte),
('msg_status', ctypes.c_ubyte),
('sb_len_wr', ctypes.c_ubyte),
('host_status', ctypes.c_ushort),
('driver_status', ctypes.c_ushort),
('resid', ctypes.c_int),
('duration', ctypes.c_uint),
('info', ctypes.c_uint)]
def GetDriveIdSgIo(dev):
ata_cmd = AtaCmd(opcode=0xA1, # ATA PASS-THROUGH (12)
protocol=3 << 1, # PIO Data-In
flags=0x06,
features=0xF5,
sector_count=1,
lba_low=0, lba_mid=0, lba_high=0,
device=0,
command=0x89, # IDENTIFY
reserved=0,
control=0)
SG_DXFER_FROM_DEV = -3
sense = ctypes.c_buffer(64)
identify = ctypes.c_buffer(512)
sgio = SgioHdr(
interface_id=ord('S'),
dxfer_direction=SG_DXFER_FROM_DEV,
cmd_len=ctypes.sizeof(ata_cmd),
mx_sb_len=ctypes.sizeof(sense),
iovec_count=0,
dxfer_len=ctypes.sizeof(identify),
dxferp=0,
cmdp=ctypes.addressof(ata_cmd),
sbp=ctypes.addressof(sense),
timeout=3000,
flags=0,
pack_id=0,
usr_ptr=None,
# Set values
status=0, masked_status=0, msg_status=0, sb_len_wr=0, host_status=0,
driver_status=0, resid=0, duration=0, info=0
)
SG_IO = 0x2285 # <scsi/sg.h>
with open(dev, 'r') as fd:
ret = fcntl.ioctl(fd.fileno(), SG_IO, ctypes.addressof(sgio)) # fails here
# some other stuff returns endian swapped buffer info but not relevant
GetDriveIdSgIo("/dev/sda")
Где я ошибся?