diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index 537cdd0d..fd060e39 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -448,6 +448,11 @@ typedef BOOLEAN (CALLBACK *winsta_query_info)(HANDLE, /* kernel32.dll */ typedef BOOL (CALLBACK *kernel_memory_status)(MEMORYSTATUSEX *); +/* mpr.dll */ +typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR, + LPTSTR, + LPDWORD); + #define SIGAR_DLLFUNC(api, name) \ struct { \ const char *name; \ @@ -528,6 +533,14 @@ typedef struct { sigar_dll_func_t end; } sigar_kernel_t; +typedef struct { + sigar_dll_handle_t handle; + + SIGAR_DLLFUNC(mpr, get_net_connection); + + sigar_dll_func_t end; +} sigar_mpr_t; + struct sigar_t { SIGAR_T_BASE; char *machine; @@ -543,6 +556,7 @@ struct sigar_t { sigar_psapi_t psapi; sigar_winsta_t winsta; sigar_kernel_t kernel; + sigar_mpr_t mpr; sigar_win32_pinfo_t pinfo; sigar_cache_t *netif_adapters; sigar_cache_t *netif_mib_rows; diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index fed8e0d3..bbca0321 100755 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -358,6 +358,13 @@ static sigar_psapi_t sigar_kernel = { { NULL, NULL } }; +static sigar_mpr_t sigar_mpr = { + "mpr.dll", + NULL, + { "WNetGetConnectionA", NULL }, + { NULL, NULL } +}; + #define DLLMOD_COPY(name) \ memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##name)) @@ -539,6 +546,7 @@ int sigar_os_open(sigar_t **sigar_ptr) DLLMOD_COPY(psapi); DLLMOD_COPY(winsta); DLLMOD_COPY(kernel); + DLLMOD_COPY(mpr); sigar->log_level = -1; /* else below segfaults */ /* XXX init early for use by javasigar.c */ @@ -576,6 +584,7 @@ int sigar_os_close(sigar_t *sigar) DLLMOD_FREE(psapi); DLLMOD_FREE(winsta); DLLMOD_FREE(kernel); + DLLMOD_FREE(mpr); if (sigar->perfbuf) { free(sigar->perfbuf); @@ -1770,6 +1779,9 @@ static void get_fs_options(char *opts, int osize, long flags) #endif } +#define sigar_WNetGetConnection \ + sigar->mpr.get_net_connection.func + SIGAR_DECLARE(int) sigar_file_system_list_get(sigar_t *sigar, sigar_file_system_list_t *fslist) { @@ -1778,6 +1790,8 @@ SIGAR_DECLARE(int) sigar_file_system_list_get(sigar_t *sigar, /* XXX: hmm, Find{First,Next}Volume not available in my sdk */ DWORD len = GetLogicalDriveStringsA(sizeof(name), name); + DLLMOD_INIT(mpr, TRUE); + if (len == 0) { return GetLastError(); } @@ -1831,6 +1845,14 @@ SIGAR_DECLARE(int) sigar_file_system_list_get(sigar_t *sigar, SIGAR_SSTRCPY(fsp->dir_name, ptr); SIGAR_SSTRCPY(fsp->dev_name, ptr); + if ((drive_type == DRIVE_REMOTE) && sigar_WNetGetConnection) { + DWORD len = sizeof(fsp->dev_name); + char drive[3] = {'\0', ':', '\0'}; /* e.g. "X:" w/o trailing "\" */ + drive[0] = fsp->dir_name[0]; + sigar_WNetGetConnection(drive, fsp->dev_name, &len); + /* ignoring failure, leaving dev_name as dir_name */ + } + /* we set fsp->type, just looking up sigar.c:fstype_names[type] */ sigar_fs_type_get(fsp);