Message351149
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;
} |
|
Date |
User |
Action |
Args |
2019-09-04 20:26:32 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower |
2019-09-04 20:26:32 | eryksun | set | messageid: <1567628792.17.0.732081344869.issue38030@roundup.psfhosted.org> |
2019-09-04 20:26:32 | eryksun | link | issue38030 messages |
2019-09-04 20:26:31 | eryksun | create | |
|