Skip to content
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

Add mount points to disk_partitions() in Windows (#775) #1192

Merged
merged 3 commits into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ E: [email protected]
I: 823

N: Jake Omann
E: https://github.com/jhomann
I: 816
E: https://github.com/jomann09
I: 816, 775

N: Jeremy Humble
W: https://github.com/jhumble
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

*XXXX-XX-XX*

**Enhancements**

- 775_: disk_partitions() on Windows return mount points.

**Bug fixes**

- 1193_: pids() may return False on OSX.
Expand Down
39 changes: 39 additions & 0 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,7 @@ static char *psutil_get_drive_type(int type) {
#define _ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
#endif


/*
* Return disk partitions as a list of tuples such as
* (drive_letter, drive_letter, type, "")
Expand All @@ -2498,11 +2499,15 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
DWORD num_bytes;
char drive_strings[255];
char *drive_letter = drive_strings;
char mp_buf[MAX_PATH];
char mp_path[MAX_PATH];
int all;
int type;
int ret;
unsigned int old_mode = 0;
char opts[20];
HANDLE mp_h;
BOOL mp_flag= TRUE;
LPTSTR fs_type[MAX_PATH + 1] = { 0 };
DWORD pflags = 0;
PyObject *py_all;
Expand Down Expand Up @@ -2573,6 +2578,40 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
strcat_s(opts, _countof(opts), "rw");
if (pflags & FILE_VOLUME_IS_COMPRESSED)
strcat_s(opts, _countof(opts), ",compressed");

// Check for mount points on this volume and add/get info
// (checks first to know if we can even have mount points)
if (pflags & FILE_SUPPORTS_REPARSE_POINTS) {

mp_h = FindFirstVolumeMountPoint(drive_letter, mp_buf, MAX_PATH);
if (mp_h != INVALID_HANDLE_VALUE) {
while (mp_flag) {

// Append full mount path with drive letter
strcpy_s(mp_path, _countof(mp_path), drive_letter);
strcat_s(mp_path, _countof(mp_path), mp_buf);

py_tuple = Py_BuildValue(
"(ssss)",
drive_letter,
mp_path,
fs_type, // Typically NTFS
opts);

if (!py_tuple || PyList_Append(py_retlist, py_tuple) == -1) {
FindVolumeMountPointClose(mp_h);
goto error;
}

Py_DECREF(py_tuple);

// Continue looking for more mount points
mp_flag = FindNextVolumeMountPoint(mp_h, mp_buf, MAX_PATH);
}
FindVolumeMountPointClose(mp_h);
}

}
}

if (strlen(opts) > 0)
Expand Down