Fix Windows build warnings.
[fio.git] / os / os-windows.h
index 98f9030530ef23db3536d67ae38f4f6abcedeebd..4f4e2bb38e74994e4c42a8c5e3c38885174b8a7a 100644 (file)
@@ -7,6 +7,7 @@
 #include <sys/shm.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <winsock2.h>
 #include <windows.h>
 #include <psapi.h>
 #include <stdlib.h>
@@ -112,6 +113,9 @@ static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
 {
        int rc = 0;
        HANDLE hFile;
+       GET_LENGTH_INFORMATION info;
+       DWORD outBytes;
+       LARGE_INTEGER size;
 
        if (f->hFile == NULL) {
                hFile = CreateFile(f->file_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
@@ -120,9 +124,6 @@ static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
                hFile = f->hFile;
        }
 
-       GET_LENGTH_INFORMATION info;
-       DWORD outBytes;
-       LARGE_INTEGER size;
        size.QuadPart = 0;
        if (DeviceIoControl(hFile, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &info, sizeof(info), &outBytes, NULL))
                *bytes = info.Length.QuadPart;
@@ -151,12 +152,14 @@ static inline int blockdev_invalidate_cache(struct fio_file *f)
 
 static inline unsigned long long os_phys_mem(void)
 {
-       SYSTEM_INFO sysInfo;
-       uintptr_t addr;
+       long pagesize, pages;
+
+       pagesize = sysconf(_SC_PAGESIZE);
+       pages = sysconf(_SC_PHYS_PAGES);
+       if (pages == -1 || pagesize == -1)
+               return 0;
 
-       GetSystemInfo(&sysInfo);
-       addr = (uintptr_t)sysInfo.lpMaximumApplicationAddress;
-       return (unsigned long long)addr;
+       return (unsigned long long) pages * (unsigned long long) pagesize;
 }
 
 static inline void os_get_tmpdir(char *path, int len)