Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get device instance for empty CD drive on Windows #20

Open
RibShark opened this issue Nov 4, 2024 · 6 comments
Open

Cannot get device instance for empty CD drive on Windows #20

RibShark opened this issue Nov 4, 2024 · 6 comments

Comments

@RibShark
Copy link

RibShark commented Nov 4, 2024

When attempting to run get_device on Windows with an empty CD drive, the CreateFileA call returns a "device not ready" error:

Traceback (most recent call last):
  File "X:\PycharmProjects\DriveExperiments\main.py", line 6, in <module>
    with get_device('E:') as device:
         ^^^^^^^^^^^^^^^^
  File "X:\PycharmProjects\DriveExperiments\.venv\Lib\site-packages\smartie\scsi\windows.py", line 33, in __enter__
    raise ctypes.WinError(ctypes.get_last_error())
PermissionError: [WinError 21] The device is not ready.

A drive shouldn't need to have media inserted in order to send/receive SCSI commands.

@TkTech
Copy link
Owner

TkTech commented Nov 4, 2024

Huh, that's surprising. This is failing on the initial device open, which means we're going to need to handle CD drives differently on Windows.

I don't have any physical hardware with a CD drive anymore, if anyone wants to take a crack at it.

@TkTech
Copy link
Owner

TkTech commented Nov 5, 2024

@RibShark Is this CD drive connected via USB?

@RibShark
Copy link
Author

RibShark commented Nov 5, 2024

@RibShark Is this CD drive connected via USB?

Yes, it is.

@jackeichen
Copy link
Contributor

jackeichen commented Nov 7, 2024

@RibShark refer to https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-device-namespaces

I prefer to use a Win32 device namespace instead of the Win32 file namespace, and smartie could detect and return it with function get_all_device.

In my test, the CdRom device is not an empty CD drive and could be opened, but the ATA or SCSi commands should be incompatible with CdRom device type.

>>> with get_device("\\\\.\\CdRom1") as d:
...     d.inquiry()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "D:\software\python3.12.3\Lib\site-packages\smartie\scsi\__init__.py", line 126, in inquiry
    response = self.issue_command(Direction.FROM, inquiry_command, inquiry)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\python3.12.3\Lib\site-packages\smartie\scsi\windows.py", line 92, in issue_command
    self.parse_sense(bytearray(header_with_buffer.sense))
  File "D:\software\python3.12.3\Lib\site-packages\smartie\scsi\__init__.py", line 87, in parse_sense
    raise SenseError(sense.sense_key, sense=sense)
smartie.scsi.errors.SenseError: <SenseError(error_code=0x05, err='Illegal Request')>
>>>

@TkTech
Copy link
Owner

TkTech commented Nov 16, 2024

I've tested on both Windows 10 and 11, enumeration picked up both empty and in-use CD-ROM drives without issue. Something else going on here, might be related to the USB bridge (which smartmontools also has issues with)

@jackeichen
Copy link
Contributor

@TkTech Maybe something different between your device and me.
Here is my deivce:
http://iodd.kr/wordpress/product/iodd-2541/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants