TkTech / smartie

Pure-python ATA/SATA/ATAPI/SCSI and disk enumeration library for Linux/Windows/OS X.
https://tkte.ch/smartie/
MIT License
11 stars 5 forks source link

Windows SPTI timeout value is in seconds, not milliseconds. #11

Closed ZakDanger closed 5 months ago

ZakDanger commented 5 months ago

Windows SPTI timeout value is in seconds, not milliseconds.. So changed 3000 to 3.

from: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddscsi/ns-ntddscsi-_scsi_pass_through_direct

""" TimeOutValue Indicates the interval in seconds that the request can execute before the OS-specific port driver might consider it timed out. """

TkTech commented 5 months ago

Great catch! Since we kind of want to keep the SCSIDevice interface consistent, what do you think about doing this instead?

Index: smartie/scsi/windows.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/smartie/scsi/windows.py b/smartie/scsi/windows.py
--- a/smartie/scsi/windows.py   (revision 0a30edfee9e15907cb2a14bc52479291f7f99249)
+++ b/smartie/scsi/windows.py   (date 1717773398837)
@@ -63,7 +63,10 @@
                 data_buffer=ctypes.addressof(data),
                 cdb_length=ctypes.sizeof(command),
                 cdb=cdb,
-                timeout_value=timeout,
+                # While most platforms use a timeout in milliseconds, Windows
+                # uses a timeout in seconds. A timeout of 0 makes little
+                # sense, so we set a minimum of 1 second.
+                timeout_value=max(timeout // 1000, 1),
                 sense_info_length=SCSIPassThroughDirectWithBuffer.sense.size,
                 sense_info_offset=(
                     SCSIPassThroughDirectWithBuffer.sense.offset
ZakDanger commented 5 months ago

Your changed fix looks good