Index: include/zbxtypes.h
===================================================================
--- include/zbxtypes.h	(revision 56585)
+++ include/zbxtypes.h	(working copy)
@@ -129,4 +129,7 @@
 }
 zbx_uint128_t;
 
+/* macro to test if a signed value has been assigned to unsigned type (char, short, int, long long) */
+#define ZBX_IS_TOP_BIT_SET(x)	(0 != ((__UINT64_C(1) << ((sizeof(x) << 3) - 1)) & (x)))
+
 #endif
Index: src/libs/zbxdbcache/dbcache.c
===================================================================
--- src/libs/zbxdbcache/dbcache.c	(revision 56585)
+++ src/libs/zbxdbcache/dbcache.c	(working copy)
@@ -451,7 +451,7 @@
 			}
 			else
 			{
-				zbx_uint128_t avg;
+				zbx_uint128_t	avg;
 
 				ZBX_STR2UINT64(value_min.ui64, row[2]);
 				ZBX_STR2UINT64(value_avg.ui64, row[3]);
Index: src/libs/zbxsysinfo/aix/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/aix/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/aix/diskspace.c	(working copy)
@@ -48,6 +48,11 @@
 		return SYSINFO_RET_FAIL;
 	}
 
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
 	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
 
@@ -60,8 +65,7 @@
 	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
@@ -69,8 +73,7 @@
 	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -124,7 +127,6 @@
 	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
 static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
@@ -162,7 +164,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret = SYSINFO_RET_FAIL;
 
 	if (2 < request->nparam)
 	{
@@ -179,32 +180,29 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
 
 static const char	*zbx_get_vfs_name_by_type(int type)
 {
 	extern struct vfs_ent	*getvfsbytype(int type);
 
-	struct vfs_ent	*vfs;
-	static char	**vfs_names = NULL;
-	static size_t	vfs_names_alloc = 0;
+	struct vfs_ent		*vfs;
+	static char		**vfs_names = NULL;
+	static size_t		vfs_names_alloc = 0;
 
 	if (type + 1 > vfs_names_alloc)
 	{
Index: src/libs/zbxsysinfo/freebsd/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/freebsd/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/freebsd/diskspace.c	(working copy)
@@ -40,25 +40,32 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -112,7 +119,6 @@
 	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
 static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
@@ -150,7 +156,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret = SYSINFO_RET_FAIL;
 
 	if (2 < request->nparam)
 	{
@@ -167,24 +172,20 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	/* default parameter */
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
 
 int	VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
Index: src/libs/zbxsysinfo/hpux/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/hpux/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/hpux/diskspace.c	(working copy)
@@ -40,25 +40,32 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -112,7 +119,6 @@
 	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
 static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
@@ -150,7 +156,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret = SYSINFO_RET_FAIL;
 
 	if (2 < request->nparam)
 	{
@@ -167,23 +172,20 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
 
 int	VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
Index: src/libs/zbxsysinfo/linux/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/linux/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/linux/diskspace.c	(working copy)
@@ -22,7 +22,7 @@
 #include "zbxjson.h"
 #include "log.h"
 
-static int	get_fs_size_stat(const char *fsname, zbx_uint64_t *total, zbx_uint64_t *free,
+static int	get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
 		zbx_uint64_t *used, double *pfree, double *pused, char **error)
 {
 #ifdef HAVE_SYS_STATVFS_H
@@ -34,37 +34,44 @@
 #endif
 	struct ZBX_STATFS	s;
 
-	if (NULL == fsname || '\0' == *fsname)
+	if (NULL == fs || '\0' == *fs)
 	{
 		*error = zbx_strdup(NULL, "Filesystem name cannot be empty.");
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (0 != ZBX_STATFS(fsname, &s))
+	if (0 != ZBX_STATFS(fs, &s))
 	{
 		*error = zbx_dsprintf(NULL, "Cannot obtain filesystem information: %s", zbx_strerror(errno));
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
Index: src/libs/zbxsysinfo/netbsd/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/netbsd/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/netbsd/diskspace.c	(working copy)
@@ -40,25 +40,32 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -112,7 +119,6 @@
 	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
 static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
@@ -150,7 +156,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret = SYSINFO_RET_FAIL;
 
 	if (2 < request->nparam)
 	{
@@ -167,21 +172,18 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
 	return SYSINFO_RET_FAIL;
 }
Index: src/libs/zbxsysinfo/openbsd/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/openbsd/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/openbsd/diskspace.c	(working copy)
@@ -40,25 +40,32 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -112,7 +119,6 @@
 	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
 static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
@@ -150,7 +156,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret = SYSINFO_RET_FAIL;
 
 	if (2 < request->nparam)
 	{
@@ -167,23 +172,20 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
 
 int	VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
Index: src/libs/zbxsysinfo/osf/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/osf/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/osf/diskspace.c	(working copy)
@@ -39,25 +39,32 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -148,7 +155,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret = SYSINFO_RET_FAIL;
 
 	if (2 < request->nparam)
 	{
@@ -156,8 +162,8 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	fsname = get_nparam(request, 0);
-	mode = get_nparam(request, 1);
+	fsname = get_rparam(request, 0);
+	mode = get_rparam(request, 1);
 
 	if (NULL == fsname || '\0' == *fsname)
 	{
@@ -165,21 +171,18 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
Index: src/libs/zbxsysinfo/osx/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/osx/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/osx/diskspace.c	(working copy)
@@ -22,10 +22,8 @@
 #include "zbxjson.h"
 #include "log.h"
 
-static int	get_fs_size_stat(const char *fs, zbx_uint64_t *total,
-		zbx_uint64_t *used, double *pused,
-		zbx_uint64_t *free, double *pfree,
-		char **error)
+static int	get_fs_size_stat(const char *fs, zbx_uint64_t *total, zbx_uint64_t *free,
+		zbx_uint64_t *used, double *pfree, double *pused, char **error)
 {
 #ifdef HAVE_SYS_STATVFS_H
 #	define ZBX_STATFS	statvfs
@@ -42,111 +40,115 @@
 		return SYSINFO_RET_FAIL;
 	}
 
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
 	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
 
+	if (NULL != free)
+		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
+
 	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
 
-	if (NULL != pused)
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
-			*pused = 0;
+			*pfree = 0;
 	}
 
-	if (NULL != free)
-		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-
-	if (NULL != pfree)
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
-			*pfree = 0;
+			*pused = 0;
 	}
 
 	return SYSINFO_RET_OK;
 }
 
-static int	VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
+static int	VFS_FS_USED(const char *fs, AGENT_RESULT *result)
 {
-	zbx_uint64_t	total;
+	zbx_uint64_t	value;
 	char		*error;
 
-	if (SYSINFO_RET_OK != get_fs_size_stat(fs, &total, NULL, NULL, NULL, NULL, &error))
+	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, &value, NULL, NULL, &error))
 	{
 		SET_MSG_RESULT(result, error);
 		return SYSINFO_RET_FAIL;
 	}
 
-	SET_UI64_RESULT(result, total);
+	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
-static int	VFS_FS_USED(const char *fs, AGENT_RESULT *result)
+static int	VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
 {
-	zbx_uint64_t	used;
+	zbx_uint64_t	value;
 	char		*error;
 
-	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, &used, NULL, NULL, NULL, &error))
+	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, &value, NULL, NULL, NULL, &error))
 	{
 		SET_MSG_RESULT(result, error);
 		return SYSINFO_RET_FAIL;
 	}
 
-	SET_UI64_RESULT(result, used);
+	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
 }
 
-static int	VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
+static int	VFS_FS_TOTAL(const char *fs, AGENT_RESULT *result)
 {
-	double	pused;
-	char	*error;
+	zbx_uint64_t	value;
+	char		*error;
 
-	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, &pused, NULL, NULL, &error))
+	if (SYSINFO_RET_OK != get_fs_size_stat(fs, &value, NULL, NULL, NULL, NULL, &error))
 	{
 		SET_MSG_RESULT(result, error);
 		return SYSINFO_RET_FAIL;
 	}
 
-	SET_DBL_RESULT(result, pused);
+	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
 }
 
-static int	VFS_FS_FREE(const char *fs, AGENT_RESULT *result)
+static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
 {
-	zbx_uint64_t	free;
-	char		*error;
+	double	value;
+	char	*error;
 
-	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, &free, NULL, &error))
+	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, &value, NULL, &error))
 	{
 		SET_MSG_RESULT(result, error);
 		return SYSINFO_RET_FAIL;
 	}
 
-	SET_UI64_RESULT(result, free);
+	SET_DBL_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
 }
 
-static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
+static int	VFS_FS_PUSED(const char *fs, AGENT_RESULT *result)
 {
-	double	pfree;
+	double	value;
 	char	*error;
 
-	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, NULL, &pfree, &error))
+	if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, NULL, &value, &error))
 	{
 		SET_MSG_RESULT(result, error);
 		return SYSINFO_RET_FAIL;
 	}
 
-	SET_DBL_RESULT(result, pfree);
+	SET_DBL_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
 }
@@ -154,7 +156,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret;
 
 	if (2 < request->nparam)
 	{
@@ -171,23 +172,20 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
 
 int	VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
Index: src/libs/zbxsysinfo/solaris/diskspace.c
===================================================================
--- src/libs/zbxsysinfo/solaris/diskspace.c	(revision 56585)
+++ src/libs/zbxsysinfo/solaris/diskspace.c	(working copy)
@@ -44,25 +44,32 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (total)
+	/* Available space could be negative (top bit set) if we hit disk space */
+	/* reserved for non-privileged users. Treat it as 0.                    */
+	if (0 != ZBX_IS_TOP_BIT_SET(s.f_bavail))
+		s.f_bavail = 0;
+
+	if (NULL != total)
 		*total = (zbx_uint64_t)s.f_blocks * s.ZBX_BSIZE;
-	if (free)
+
+	if (NULL != free)
 		*free = (zbx_uint64_t)s.f_bavail * s.ZBX_BSIZE;
-	if (used)
+
+	if (NULL != used)
 		*used = (zbx_uint64_t)(s.f_blocks - s.f_bfree) * s.ZBX_BSIZE;
-	if (pfree)
+
+	if (NULL != pfree)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pfree = (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pfree = (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pfree = 0;
 	}
-	if (pused)
+
+	if (NULL != pused)
 	{
 		if (0 != s.f_blocks - s.f_bfree + s.f_bavail)
-			*pused = 100.0 - (double)(100.0 * s.f_bavail) /
-					(s.f_blocks - s.f_bfree + s.f_bavail);
+			*pused = 100.0 - (double)(100.0 * s.f_bavail) / (s.f_blocks - s.f_bfree + s.f_bavail);
 		else
 			*pused = 0;
 	}
@@ -116,7 +123,6 @@
 	SET_UI64_RESULT(result, value);
 
 	return SYSINFO_RET_OK;
-
 }
 
 static int	VFS_FS_PFREE(const char *fs, AGENT_RESULT *result)
@@ -154,7 +160,6 @@
 int	VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result)
 {
 	char	*fsname, *mode;
-	int	ret;
 
 	if (2 < request->nparam)
 	{
@@ -171,23 +176,20 @@
 		return SYSINFO_RET_FAIL;
 	}
 
-	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))
-		ret = VFS_FS_TOTAL(fsname, result);
-	else if (0 == strcmp(mode, "free"))
-		ret = VFS_FS_FREE(fsname, result);
-	else if (0 == strcmp(mode, "used"))
-		ret = VFS_FS_USED(fsname, result);
-	else if (0 == strcmp(mode, "pfree"))
-		ret = VFS_FS_PFREE(fsname, result);
-	else if (0 == strcmp(mode, "pused"))
-		ret = VFS_FS_PUSED(fsname, result);
-	else
-	{
-		SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
-		return SYSINFO_RET_FAIL;
-	}
+	if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total"))	/* default parameter */
+		return VFS_FS_TOTAL(fsname, result);
+	if (0 == strcmp(mode, "free"))
+		return VFS_FS_FREE(fsname, result);
+	if (0 == strcmp(mode, "pfree"))
+		return VFS_FS_PFREE(fsname, result);
+	if (0 == strcmp(mode, "used"))
+		return VFS_FS_USED(fsname, result);
+	if (0 == strcmp(mode, "pused"))
+		return VFS_FS_PUSED(fsname, result);
+
+	SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter."));
 
-	return ret;
+	return SYSINFO_RET_FAIL;
 }
 
 int	VFS_FS_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
