[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread miss-islington


miss-islington  added the comment:


New changeset cad7abf8abe657b696b9c8deb4b727e0cefaf36d by Miss Islington (bot) 
in branch '3.8':
bpo-38030: Fix os.stat failures on block devices on Windows (GH-15681)
https://github.com/python/cpython/commit/cad7abf8abe657b696b9c8deb4b727e0cefaf36d


--
nosy: +miss-islington

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread Steve Dower


Change by Steve Dower :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread miss-islington


Change by miss-islington :


--
pull_requests: +15342
pull_request: https://github.com/python/cpython/pull/15682

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread Steve Dower


Steve Dower  added the comment:


New changeset 772ec0fad57412daa53d16d7019b6b2fe6e94942 by Steve Dower in branch 
'master':
bpo-38030: Fix os.stat failures on block devices on Windows (GH-15681)
https://github.com/python/cpython/commit/772ec0fad57412daa53d16d7019b6b2fe6e94942


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread Steve Dower


Change by Steve Dower :


--
keywords: +patch
pull_requests: +15341
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/15681

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread Steve Dower


Change by Steve Dower :


--
assignee:  -> steve.dower

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38030] os.stat fails for block devices such as //./PhysicalDrive0

2019-09-04 Thread Eryk Sun


New submission from Eryk Sun :

In issue 37834, I posted a suggest implementation of win32_xstat_impl that 
included the following snippet of code:

if (!GetFileInformationByHandle(hFile, &fileInfo)) {
error = GetLastError();
if (error != ERROR_INVALID_PARAMETER &&
error != ERROR_INVALID_FUNCTION &&
error != ERROR_NOT_SUPPORTED) {
retval = -1;
goto cleanup;
}
/* Volumes and physical disks are block devices, e.g.
   \\.\C: and \\.\PhysicalDrive0. */
memset(result, 0, sizeof(*result));
result->st_mode = 0x6000; /* S_IFBLK */
goto cleanup;
}

This is meant to handle the above errors. We know we have FILE_TYPE_DISK. If 
GetFileInformationByHandle fails with one of the above error codes, then we 
must have a disk or volume device without a mounted file-system device. This 
should be reported as a block device.

However it was changed in the final version as follows:

if (!GetFileInformationByHandle(hFile, &fileInfo)) {
switch (GetLastError()) {
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_FUNCTION:
case ERROR_NOT_SUPPORTED:
retval = -1;
goto cleanup;
}
/* Volumes and physical disks are block devices, e.g.
   \\.\C: and \\.\PhysicalDrive0. */
memset(result, 0, sizeof(*result));
result->st_mode = 0x6000; /* S_IFBLK */
goto cleanup;
}

Now it's failing on the errors that should be handled, and succeeding on all 
other errors that should fail. If we want to use a switch statement here, I 
suggest the following:

if (!GetFileInformationByHandle(hFile, &fileInfo)) {
switch (GetLastError()) {
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_FUNCTION:
case ERROR_NOT_SUPPORTED:
/* Volumes and physical disks are block devices, e.g.
   \\.\C: and \\.\PhysicalDrive0. */
memset(result, 0, sizeof(*result));
result->st_mode = 0x6000; /* S_IFBLK */
goto cleanup;
}
retval = -1;
goto cleanup;
}

--
components: IO, Windows
messages: 351149
nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware
priority: high
severity: normal
stage: needs patch
status: open
title: os.stat fails for block devices such as //./PhysicalDrive0
type: behavior
versions: Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com