[PATCH] Compile and works on OpenSolaris (tested on BeleniX)
diff --git a/Makefile.solaris b/Makefile.solaris
new file mode 100644
index 0000000..295928c
--- /dev/null
+++ b/Makefile.solaris
@@ -0,0 +1,28 @@
+CC	= gcc
+CFLAGS	= -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+PROGS	= fio
+SCRIPTS = fio_generate_plots
+
+OBJS = fio.o ioengines.o init.o stat.o log.o time.o md5.o crc32.o
+
+all: depend $(PROGS) $(SCRIPTS)
+
+fio: fio.o ioengines.o init.o stat.o log.o time.o md5.o crc32.o
+	$(CC) $(CFLAGS) -o $@ $(OBJS) -lc -lpthread -lm -laio -lrt
+
+clean:
+	-rm -f *.o .depend cscope.out $(PROGS)
+
+depend:
+	@$(CC) -MM $(ALL_CFLAGS) *.c 1> .depend
+
+cscope:
+	@cscope -b
+
+INSTALL = install
+prefix = /usr/local
+bindir = $(prefix)/bin
+
+install: $(PROGS) $(SCRIPTS)
+	$(INSTALL) -m755 -d $(DESTDIR)$(bindir)
+	$(INSTALL) $(PROGS) $(SCRIPTS) $(DESTDIR)$(bindir)
diff --git a/fio.c b/fio.c
index 7aef822..1248971 100644
--- a/fio.c
+++ b/fio.c
@@ -1173,7 +1173,7 @@
 	}
 
 	if (td->odirect)
-		flags |= O_DIRECT;
+		flags |= OS_O_DIRECT;
 
 	if (td_write(td) || td_rw(td)) {
 		if (td->filetype == FIO_TYPE_FILE) {
diff --git a/init.c b/init.c
index 0ec8e9d..3117d60 100644
--- a/init.c
+++ b/init.c
@@ -1013,7 +1013,7 @@
 	struct shmid_ds sbuf;
 
 	if (threads) {
-		shmdt(threads);
+		shmdt((void *) threads);
 		threads = NULL;
 		shmctl(shm_id, IPC_RMID, &sbuf);
 	}
diff --git a/os-freebsd.h b/os-freebsd.h
index 41672d4..6a4c11b 100644
--- a/os-freebsd.h
+++ b/os-freebsd.h
@@ -9,6 +9,7 @@
 #undef FIO_HAVE_CPU_AFFINITY
 #undef FIO_HAVE_DISK_UTIL
 #undef FIO_HAVE_SGIO
+#define FIO_HAVE_ODIRECT
 
 #define OS_MAP_ANON		(MAP_ANON)
 
diff --git a/os-linux.h b/os-linux.h
index f9094cb..5f0ef82 100644
--- a/os-linux.h
+++ b/os-linux.h
@@ -16,6 +16,7 @@
 #define FIO_HAVE_IOPRIO
 #define FIO_HAVE_SPLICE
 #define FIO_HAVE_IOSCHED_SWITCH
+#define FIO_HAVE_ODIRECT
 
 #define OS_MAP_ANON		(MAP_ANONYMOUS)
 
diff --git a/os-solaris.h b/os-solaris.h
new file mode 100644
index 0000000..e7f4e4e
--- /dev/null
+++ b/os-solaris.h
@@ -0,0 +1,60 @@
+#ifndef FIO_OS_SOLARIS_H
+#define FIO_OS_SOLARIS_H
+
+#undef FIO_HAVE_LIBAIO
+#define FIO_HAVE_POSIXAIO
+#undef FIO_HAVE_FADVISE
+#undef FIO_HAVE_CPU_AFFINITY
+#undef FIO_HAVE_DISK_UTIL
+#undef FIO_HAVE_SGIO
+#undef FIO_HAVE_ODIRECT
+
+#define OS_MAP_ANON		(MAP_ANON)
+
+typedef unsigned long os_cpu_mask_t;
+typedef unsigned int os_random_state_t;
+
+/*
+ * FIXME
+ */
+static inline int blockdev_size(int fd, unsigned long long *bytes)
+{
+	return 1;
+}
+
+static inline unsigned long long os_phys_mem(void)
+{
+#if 0
+	int mib[2] = { CTL_HW, HW_PHYSMEM };
+	unsigned long long mem;
+	size_t len = sizeof(mem);
+
+	sysctl(mib, 2, &mem, &len, NULL, 0);
+	return mem;
+#else
+	return 0;
+#endif
+}
+
+static inline void os_random_seed(unsigned long seed, os_random_state_t *rs)
+{
+	srand(seed);
+}
+
+static inline long os_random_long(os_random_state_t *rs)
+{
+	long val;
+
+	val = rand_r(rs);
+	return val;
+}
+
+static inline double os_random_double(os_random_state_t *rs)
+{
+	double val;
+
+	val = (double) rand_r(rs);
+	return val;
+}
+
+#endif
diff --git a/os.h b/os.h
index 093a722..1160f44 100644
--- a/os.h
+++ b/os.h
@@ -5,6 +5,8 @@
 #include "os-linux.h"
 #elif defined(__FreeBSD__)
 #include "os-freebsd.h"
+#elif defined(__sun__)
+#include "os-solaris.h"
 #else
 #error "unsupported os"
 #endif
@@ -39,6 +41,10 @@
 #define ioprio_set(which, who, prio)	(0)
 #endif
 
+#ifndef FIO_HAVE_ODIRECT
+#define OS_O_DIRECT			(0)
+#endif
+
 struct thread_data;
 extern int fio_libaio_init(struct thread_data *);
 extern int fio_posixaio_init(struct thread_data *);