DeviceIOControl using IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS fails with 'Incorrect function.'

Doug Campbell <[email protected]>
Newsgroups gmane.comp.python.windows
Message-ID <BLAPR20MB41802B59F5950A74FCB9C28FC78E9@BLAPR20MB4180.namprd20.prod.outlook.com>
I am trying to get the disk extents given a disk number but I am getting back the following error.

Traceback (most recent call last):
  File "test2.py", line 29, in <module>
    win32file.DeviceIoControl(hDevice,winioctlcon.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, None, extents, None)
pywintypes.error: (1, 'DeviceIoControl', 'Incorrect function.')

I have tried with all three of the disks on my system:  \\.\PhysicalDrive0, \\.\PhysicalDrive1, and \\.\PhyscialDrive2 but the results are always the same.

Thanks for any insights as to why I am getting this "Incorrect function" error and how to resolve it.

Doug


Here is the code that I am using.

import ctypes
import winioctlcon
import win32file
import win32con

disk = r'\\.\PhysicalDrive1'

hDevice = win32file.CreateFile(
            disk, win32con.GENERIC_READ,
            win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
            None, win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL,  None)

class DISK_EXTENT(ctypes.Structure):
    _fields_ = (
                ('DiskNumber', ctypes.c_ulong),
                ('StartingOffset', ctypes.c_longlong),
                ('ExtentLength', ctypes.c_longlong))

ANYSIZE_ARRAY = 1

class VOLUME_DISK_EXTENTS(ctypes.Structure):
    _fields_ = (
                ('NumberOfDiskExtents', ctypes.c_ulong),
                ('Extents', DISK_EXTENT * ANYSIZE_ARRAY))

extents = VOLUME_DISK_EXTENTS()

try:
    win32file.DeviceIoControl(hDevice,winioctlcon.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, None, extents, None)
finally:
    hDevice.close()

_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.