homepage

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 <1447742363.69.0.138177880196.issue25639@psf.upfronthosting.co.za>
In-reply-to
Content
As a workaround you can open a file descriptor via os.open:
 >>> import os
 >>> fd = os.open(r'\\.\PhysicalDrive0', os.O_RDONLY | os.O_BINARY)
 >>> os.read(fd, 512)[:8]
 b'3\xc0\x8e\xd0\xbc\x00|\x8e'
> _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.
History
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: <1447742363.69.0.138177880196.issue25639@psf.upfronthosting.co.za>
2015年11月17日 06:39:23eryksunlinkissue25639 messages
2015年11月17日 06:39:22eryksuncreate

AltStyle によって変換されたページ (->オリジナル) /