#include "zbxsysinfo.h"
#include "../sysinfo.h"
#include "zbxstr.h"
#include "zbxjson.h"
#include "zbxalgo.h"
#include "log.h"
typedef struct
{
char *fsname;
char *fstype;
char *fslabel;
char *fsdrivetype;
zbx_uint64_t total;
zbx_uint64_t not_used;
zbx_uint64_t used;
double pfree;
double pused;
}
zbx_wmpoint_t;
static wchar_t *zbx_wcsdup2(const char *filename, int line, wchar_t *old, const wchar_t *str)
{
int retry;
wchar_t *ptr = NULL;
zbx_free(old);
for (retry = 10; 0 < retry && NULL == ptr; ptr = wcsdup(str), retry--)
;
if (NULL != ptr)
return ptr;
zabbix_log(LOG_LEVEL_CRIT, "[file:%s,line:%d] zbx_wcsdup: out of memory. Requested " ZBX_FS_SIZE_T " bytes.",
filename, line, (zbx_fs_size_t)((wcslen(str) + 1) * sizeof(wchar_t)));
exit(EXIT_FAILURE);
}
static int wmpoint_compare_func(const void *d1, const void *d2)
{
const zbx_wmpoint_t *m1 = *(const zbx_wmpoint_t **)d1;
const zbx_wmpoint_t *m2 = *(const zbx_wmpoint_t **)d2;
return strcmp(m1->fsname, m2->fsname);
}
static int get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *not_used,
zbx_uint64_t *used, double *pfree, double *pused, char **error)
{
wchar_t *wpath;
ULARGE_INTEGER freeBytes, totalBytes;
wpath = zbx_utf8_to_unicode(fs);
if (0 == GetDiskFreeSpaceEx(wpath, &freeBytes, &totalBytes, NULL))
{
zbx_free(wpath);
*error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s",
strerror_from_system(GetLastError()));
zabbix_log(LOG_LEVEL_DEBUG,"%s failed with error: %s",__func__, *error);
return SYSINFO_RET_FAIL;
}
zbx_free(wpath);
*total = totalBytes.QuadPart;
*not_used = freeBytes.QuadPart;
*used = totalBytes.QuadPart - freeBytes.QuadPart;
*pfree = (double)(__int64)freeBytes.QuadPart * 100. / (double)(__int64)totalBytes.QuadPart;
*pused = (double)((__int64)totalBytes.QuadPart - (__int64)freeBytes.QuadPart) * 100. /