This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients benjamin.peterson, eryksun, paul.moore, pitrou, rokozh, steve.dower, stutzbach, tim.golden, vstinner, zach.ware
Date 2015-11-17.06:39:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
As a workaround you can open a file descriptor via

    >>> import os
    >>> fd ='\\.\PhysicalDrive0', os.O_RDONLY | os.O_BINARY)
    >>>, 512)[:8]

> _Py_fstat result not used on windows in this place. 

While it's pretty much useless, it is possible to open a CRT file descriptor for a directory handle:

    >>> h = _winapi.CreateFile('C:\\', 0x80000000, 3, 0, 3, 0x02000000, 0)
    >>> fd = msvcrt.open_osfhandle(h, os.O_RDONLY)
    >>> open(fd)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IsADirectoryError: [Errno 21] Is a directory: 3

So calling _Py_fstat shouldn't be skipped on Windows.

The issue is that a raw disk device doesn't support querying information (IRP_MJ_QUERY_INFORMATION), as shown in this local kernel debugging session:

    lkd> !object \GLOBAL??\PhysicalDrive0
        Target String is '\Device\Harddisk0\DR0'

    lkd> !object \Device\Harddisk0\DR0
    Object: ffffe001c4fa4500  Type: (ffffe001c3d7bd30) Device

    lkd> !devobj ffffe001c4fa4500
    Device object (ffffe001c4fa4500) is for:
     DR0 \Driver\disk DriverObject ffffe001c4fa3310

    lkd> !drvobj \Driver\disk 2
    Dispatch routines:
    [05] IRP_MJ_QUERY_INFORMATION  fffff8037251a06c  nt!IopInvalidDeviceRequest
    [06] IRP_MJ_SET_INFORMATION    fffff8037251a06c  nt!IopInvalidDeviceRequest

Specifically WinAPI GetFileInformationByHandle calls the system function NtQueryInformationFile. The system call makes an IRP_MJ_QUERY_INFORMATION I/O request of the driver, which for a raw disk device is handled by IopInvalidDeviceRequest. This fails the request with STATUS_INVALID_DEVICE_REQUEST (0xC0000010), which translates to WinAPI ERROR_INVALID_FUNCTION (0x0001). 

Possibly in the case of ERROR_INVALID_FUNCTION, FileIO can just call PyErr_Clear and skip the code that uses fdfstat.
Date User Action Args
2015-11-17 06:39:23eryksunsetrecipients: + eryksun, paul.moore, pitrou, vstinner, tim.golden, benjamin.peterson, stutzbach, zach.ware, steve.dower, rokozh
2015-11-17 06:39:23eryksunsetmessageid: <>
2015-11-17 06:39:23eryksunlinkissue25639 messages
2015-11-17 06:39:22eryksuncreate