Fix some issues with the OSX port

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/compiler/compiler.h b/compiler/compiler.h
index 0a08bb1..c1923dd 100644
--- a/compiler/compiler.h
+++ b/compiler/compiler.h
@@ -15,6 +15,8 @@
 
 #define uninitialized_var(x) x = x
 
+#ifndef __weak
 #define __weak	__attribute__((weak))
+#endif
 
 #endif
diff --git a/helpers.c b/helpers.c
index 9c76d30..098195c 100644
--- a/helpers.c
+++ b/helpers.c
@@ -32,8 +32,8 @@
 
 	ret = gettimeofday(&tv, NULL);
 
-	ts->ts_sec = tv.tv_sec;
-	ts->ts_nsec = tv.tv_usec * 1000;
+	ts->tv_sec = tv.tv_sec;
+	ts->tv_nsec = tv.tv_usec * 1000;
 
 	return ret;
 }
diff --git a/helpers.h b/helpers.h
index 61a3f2b..4f8cc0c 100644
--- a/helpers.h
+++ b/helpers.h
@@ -1,6 +1,8 @@
 #ifndef FIO_HELPERS_H
 #define FIO_HELPERS_H
 
+#include "compiler/compiler.h"
+
 struct in_addr;
 
 extern int __weak posix_memalign(void **ptr, size_t align, size_t size);
diff --git a/mutex.c b/mutex.c
index a447437..e148430 100644
--- a/mutex.c
+++ b/mutex.c
@@ -11,6 +11,7 @@
 #include "mutex.h"
 #include "arch/arch.h"
 #include "os/os.h"
+#include "helpers.h"
 
 void fio_mutex_remove(struct fio_mutex *mutex)
 {
diff --git a/options.c b/options.c
index f628062..1543eb9 100644
--- a/options.c
+++ b/options.c
@@ -1809,16 +1809,15 @@
 
 void fio_keywords_init(void)
 {
-	unsigned long mb_memory;
+	unsigned long long mb_memory;
 	char buf[128];
 	long l;
 
 	sprintf(buf, "%lu", page_size);
 	fio_keywords[0].replace = strdup(buf);
 
-	l = sysconf(_SC_PHYS_PAGES);
-	mb_memory = l * (page_size / 1024UL);
-	sprintf(buf, "%lu", mb_memory);
+	mb_memory = os_phys_mem() / page_size;
+	sprintf(buf, "%llu", mb_memory);
 	fio_keywords[1].replace = strdup(buf);
 
 	l = sysconf(_SC_NPROCESSORS_ONLN);
diff --git a/os/os.h b/os/os.h
index bed1281..a14c485 100644
--- a/os/os.h
+++ b/os/os.h
@@ -111,8 +111,11 @@
 #ifdef FIO_USE_GENERIC_BDEV_SIZE
 static inline int blockdev_size(int fd, unsigned long long *bytes)
 {
-	off_t end = lseek(fd, 0, SEEK_END);
+	off_t end;
 
+	*bytes = 0;
+
+	end = lseek(fd, 0, SEEK_END);
 	if (end < 0)
 		return errno;