(SIGAR-194) sigar_file_system_t.dev_name on Windows should be the network path for remote drives

This commit is contained in:
Doug MacEachern 2010-01-04 13:48:20 -08:00
parent 46897838f6
commit 3e98f20197
2 changed files with 36 additions and 0 deletions

View File

@ -448,6 +448,11 @@ typedef BOOLEAN (CALLBACK *winsta_query_info)(HANDLE,
/* kernel32.dll */ /* kernel32.dll */
typedef BOOL (CALLBACK *kernel_memory_status)(MEMORYSTATUSEX *); typedef BOOL (CALLBACK *kernel_memory_status)(MEMORYSTATUSEX *);
/* mpr.dll */
typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
LPTSTR,
LPDWORD);
#define SIGAR_DLLFUNC(api, name) \ #define SIGAR_DLLFUNC(api, name) \
struct { \ struct { \
const char *name; \ const char *name; \
@ -528,6 +533,14 @@ typedef struct {
sigar_dll_func_t end; sigar_dll_func_t end;
} sigar_kernel_t; } 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 { struct sigar_t {
SIGAR_T_BASE; SIGAR_T_BASE;
char *machine; char *machine;
@ -543,6 +556,7 @@ struct sigar_t {
sigar_psapi_t psapi; sigar_psapi_t psapi;
sigar_winsta_t winsta; sigar_winsta_t winsta;
sigar_kernel_t kernel; sigar_kernel_t kernel;
sigar_mpr_t mpr;
sigar_win32_pinfo_t pinfo; sigar_win32_pinfo_t pinfo;
sigar_cache_t *netif_adapters; sigar_cache_t *netif_adapters;
sigar_cache_t *netif_mib_rows; sigar_cache_t *netif_mib_rows;

View File

@ -358,6 +358,13 @@ static sigar_psapi_t sigar_kernel = {
{ NULL, NULL } { NULL, NULL }
}; };
static sigar_mpr_t sigar_mpr = {
"mpr.dll",
NULL,
{ "WNetGetConnectionA", NULL },
{ NULL, NULL }
};
#define DLLMOD_COPY(name) \ #define DLLMOD_COPY(name) \
memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##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(psapi);
DLLMOD_COPY(winsta); DLLMOD_COPY(winsta);
DLLMOD_COPY(kernel); DLLMOD_COPY(kernel);
DLLMOD_COPY(mpr);
sigar->log_level = -1; /* else below segfaults */ sigar->log_level = -1; /* else below segfaults */
/* XXX init early for use by javasigar.c */ /* XXX init early for use by javasigar.c */
@ -576,6 +584,7 @@ int sigar_os_close(sigar_t *sigar)
DLLMOD_FREE(psapi); DLLMOD_FREE(psapi);
DLLMOD_FREE(winsta); DLLMOD_FREE(winsta);
DLLMOD_FREE(kernel); DLLMOD_FREE(kernel);
DLLMOD_FREE(mpr);
if (sigar->perfbuf) { if (sigar->perfbuf) {
free(sigar->perfbuf); free(sigar->perfbuf);
@ -1770,6 +1779,9 @@ static void get_fs_options(char *opts, int osize, long flags)
#endif #endif
} }
#define sigar_WNetGetConnection \
sigar->mpr.get_net_connection.func
SIGAR_DECLARE(int) sigar_file_system_list_get(sigar_t *sigar, SIGAR_DECLARE(int) sigar_file_system_list_get(sigar_t *sigar,
sigar_file_system_list_t *fslist) 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 */ /* XXX: hmm, Find{First,Next}Volume not available in my sdk */
DWORD len = GetLogicalDriveStringsA(sizeof(name), name); DWORD len = GetLogicalDriveStringsA(sizeof(name), name);
DLLMOD_INIT(mpr, TRUE);
if (len == 0) { if (len == 0) {
return GetLastError(); 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->dir_name, ptr);
SIGAR_SSTRCPY(fsp->dev_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] */ /* we set fsp->type, just looking up sigar.c:fstype_names[type] */
sigar_fs_type_get(fsp); sigar_fs_type_get(fsp);