-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows] Ignore permissions errors on disk_io_counters
#1974
Comments
Hmm. I understand the pain, but I'm not thrilled at the idea of returning different results depending on what user is logged in. Have you tried searching if there are workarounds? With a quick search I found this (but didn't investigate any further): |
I suspect we may avoid access denied if we change the permissions passed to for (devNum = 0; devNum <= 32; ++devNum) {
py_tuple = NULL;
sprintf_s(szDevice, MAX_PATH, "\\\\.\\PhysicalDrive%d", devNum);
hDevice = CreateFile(szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
continue;
// DeviceIoControl() sucks!
i = 0;
ioctrlSize = sizeof(diskPerformance);
while (1) {
i += 1;
ret = DeviceIoControl(
hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, &diskPerformance,
ioctrlSize, &dwSize, NULL);
if (ret != 0) |
Another possible solution: https://community.osr.com/discussion/65313/deviceiocontrol-from-user-mode Another possibility is conducting tests by trying passing different parameters to Question: for what drive do you get ERROR_ACCESS_DENIED? Is it a regular disk? A usb key...? |
Thanks for having a look, I will try to loop back with the person who reported this on our end (we use psutil on the Datadog Agent) and get the answer to those |
Hey there @giampaolo, so I haven't been able to get back to the person who originally reported this to us, but I did take a look at your suggestions and generally considered the problem, and I have some comments:
|
Related: #1977. |
Similar issue affecting |
Related proposal: #2329. |
Summary
Description
On some Windows disk configurations
psutil.disk_io_counters
can raise aPermissionError: [WinError 5]
due to aDeviceIoControl
trying to access a disk for which it does not have permissions. To be able to access the rest of the disks info, I see two ways out of thispsutil/psutil/arch/windows/disk.c
Lines 137 to 142 in a096704
ignore_errors
flag todisk_io_counters
to ignore the errors fromDeviceIOControl
on Windows (and no-op on other platforms).I am happy to do a PR for either of these but I would love to know what maintainers and contributors think is the best option first.
cc @giampaolo, could you give me some feedback as to what would be preferable?
The text was updated successfully, but these errors were encountered: