Make it work on opensolaris

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/Makefile.solaris b/Makefile.solaris
index 2f088b5..fbdef12 100644
--- a/Makefile.solaris
+++ b/Makefile.solaris
@@ -1,5 +1,5 @@
 CC	= gcc
-CFLAGS	= -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+CFLAGS	= -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DFIO_INC_DEBUG
 PROGS	= fio
 SCRIPTS = fio_generate_plots
 OBJS = gettime.o fio.o ioengines.o init.o stat.o log.o time.o filesetup.o \
@@ -21,23 +21,25 @@
 OBJS += engines/null.o
 OBJS += engines/net.o
 
-all: depend $(PROGS) $(SCRIPTS)
-
-fio: $(OBJS)
-	$(CC) $(CFLAGS) -o $@ $(OBJS) -lc -lpthread -lm -laio -lrt -ldl
-
-clean:
-	-rm -f *.o .depend cscope.out $(PROGS)
-
-depend:
-	@$(CC) -MM $(ALL_CFLAGS) *.c engines/*.c 1> .depend
-
-cscope:
-	@cscope -b
+OBJS += lib/strsep.o
 
 INSTALL = install
 prefix = /usr/local
 bindir = $(prefix)/bin
+mandir = $(prefix)/man
+
+%.o: %.c
+	$(CC) -o $*.o -c $(CFLAGS) $<
+fio: $(OBJS)
+	$(CC) $(CFLAGS) -o $@ $(OBJS) $(EXTLIBS) -lpthread -lm -ldl -laio -lrt -lnsl -lsocket
+
+all: $(PROGS) $(SCRIPTS)
+
+clean:
+	-rm -f *.o .depend cscope.out $(PROGS) engines/*.o crc/*.o lib/*.o core.* core
+
+cscope:
+	@cscope -b
 
 install: $(PROGS) $(SCRIPTS)
 	$(INSTALL) -m755 -d $(DESTDIR)$(bindir)
diff --git a/arch/arch.h b/arch/arch.h
index 745bf3a..3962c92 100644
--- a/arch/arch.h
+++ b/arch/arch.h
@@ -37,6 +37,4 @@
 #error "Unsupported arch"
 #endif
 
-#define BITS_PER_LONG	(__WORDSIZE)
-
 #endif
diff --git a/crc/sha256.c b/crc/sha256.c
index 8ec2943..fe08ab3 100644
--- a/crc/sha256.c
+++ b/crc/sha256.c
@@ -18,13 +18,21 @@
  */
 #include <string.h>
 #include <inttypes.h>
-#include <byteswap.h>
-#include <endian.h>
 
 #include "sha256.h"
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-#define	__be32_to_cpu(x)	__bswap_32(x)
+static int __be32_to_cpu(uint32_t val)
+{
+	uint32_t c1, c2, c3, c4;
+
+	c1 = (val >> 24) & 0xff;
+	c2 = (val >> 16) & 0xff;
+	c3 = (val >> 8) & 0xff;
+	c4 = val & 0xff;
+
+	return c1 | c2 << 8 | c3 << 16 | c4 << 24;
+}
 #else
 #define __be32_to_cpu(x)	(x)
 #endif
diff --git a/crc/sha512.c b/crc/sha512.c
index 1f9ebb4..d9069e3 100644
--- a/crc/sha512.c
+++ b/crc/sha512.c
@@ -13,13 +13,25 @@
 
 #include <string.h>
 #include <inttypes.h>
-#include <byteswap.h>
-#include <endian.h>
 
 #include "sha512.h"
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-#define	__be64_to_cpu(x)	__bswap_64(x)
+static int __be64_to_cpu(uint64_t val)
+{
+	uint64_t c1, c2, c3, c4, c5, c6, c7, c8;
+
+	c1 = (val >> 56) & 0xff;
+	c2 = (val >> 48) & 0xff;
+	c3 = (val >> 40) & 0xff;
+	c4 = (val >> 32) & 0xff;
+	c5 = (val >> 24) & 0xff;
+	c6 = (val >> 16) & 0xff;
+	c7 = (val >> 8) & 0xff;
+	c8 = val & 0xff;
+
+	return c1 | c2 << 8 | c3 << 16 | c4 << 24 | c5 << 32 | c6 << 40 | c7 << 48 | c8 << 56;
+}
 #else
 #define __be64_to_cpu(x)	(x)
 #endif
diff --git a/debug.h b/debug.h
index 883628d..160f48c 100644
--- a/debug.h
+++ b/debug.h
@@ -39,7 +39,7 @@
 		    && pid != *fio_debug_jobp)			\
 			break;					\
 		log_info("%-8s ", debug_levels[(type)].name);	\
-		log_info("%-5u ", pid);				\
+		log_info("%-5u ", (int) pid);			\
 		log_info(str, ##args);				\
 	} while (0)
 
diff --git a/engines/mmap.c b/engines/mmap.c
index 3e1e6c8..5b55a81 100644
--- a/engines/mmap.c
+++ b/engines/mmap.c
@@ -9,7 +9,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
-#include <assert.h>
 #include <sys/mman.h>
 
 #include "../fio.h"
diff --git a/engines/net.c b/engines/net.c
index 137c579..0efd336 100644
--- a/engines/net.c
+++ b/engines/net.c
@@ -41,6 +41,7 @@
 	return 0;
 }
 
+#ifdef FIO_HAVE_SPLICE
 static int splice_io_u(int fdin, int fdout, unsigned int len)
 {
 	int bytes = 0;
@@ -161,6 +162,19 @@
 
 	return ret;
 }
+#else
+static int fio_netio_splice_in(struct thread_data *td, struct io_u *io_u)
+{
+	errno = -EOPNOTSUPP;
+	return -1;
+}
+
+static int fio_netio_splice_out(struct thread_data *td, struct io_u *io_u)
+{
+	errno = -EOPNOTSUPP;
+	return -1;
+}
+#endif
 
 static int fio_netio_send(struct thread_data *td, struct io_u *io_u)
 {
@@ -169,8 +183,10 @@
 	/*
 	 * if we are going to write more, set MSG_MORE
 	 */
+#ifdef MSG_MORE
 	if (td->this_io_bytes[DDIR_WRITE] + io_u->xfer_buflen < td->o.size)
 		flags = MSG_MORE;
+#endif
 
 	return send(io_u->file->fd, io_u->xfer_buf, io_u->xfer_buflen, flags);
 }
@@ -430,6 +446,7 @@
 	return 0;
 }
 
+#ifdef FIO_HAVE_SPLICE
 static int fio_netio_setup_splice(struct thread_data *td)
 {
 	struct netio_data *nd;
@@ -448,6 +465,21 @@
 	return 1;
 }
 
+static struct ioengine_ops ioengine_splice = {
+	.name		= "netsplice",
+	.version	= FIO_IOOPS_VERSION,
+	.prep		= fio_netio_prep,
+	.queue		= fio_netio_queue,
+	.setup		= fio_netio_setup_splice,
+	.init		= fio_netio_init,
+	.cleanup	= fio_netio_cleanup,
+	.open_file	= fio_netio_open_file,
+	.close_file	= generic_close_file,
+	.flags		= FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
+			  FIO_SIGQUIT,
+};
+#endif
+
 static struct ioengine_ops ioengine_rw = {
 	.name		= "net",
 	.version	= FIO_IOOPS_VERSION,
@@ -462,28 +494,18 @@
 			  FIO_SIGQUIT,
 };
 
-static struct ioengine_ops ioengine_splice = {
-	.name		= "netsplice",
-	.version	= FIO_IOOPS_VERSION,
-	.prep		= fio_netio_prep,
-	.queue		= fio_netio_queue,
-	.setup		= fio_netio_setup_splice,
-	.init		= fio_netio_init,
-	.cleanup	= fio_netio_cleanup,
-	.open_file	= fio_netio_open_file,
-	.close_file	= generic_close_file,
-	.flags		= FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR |
-			  FIO_SIGQUIT,
-};
-
 static void fio_init fio_netio_register(void)
 {
 	register_ioengine(&ioengine_rw);
+#ifdef FIO_HAVE_SPLICE
 	register_ioengine(&ioengine_splice);
+#endif
 }
 
 static void fio_exit fio_netio_unregister(void)
 {
 	unregister_ioengine(&ioengine_rw);
+#ifdef FIO_HAVE_SPLICE
 	unregister_ioengine(&ioengine_splice);
+#endif
 }
diff --git a/engines/sync.c b/engines/sync.c
index e966846..561e77b 100644
--- a/engines/sync.c
+++ b/engines/sync.c
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/uio.h>
 #include <errno.h>
 #include <assert.h>
 
diff --git a/filesetup.c b/filesetup.c
index c98bf0c..d57a327 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -307,7 +307,7 @@
 	if (td->o.sync_io)
 		flags |= O_SYNC;
 	if (f->filetype != FIO_TYPE_FILE)
-		flags |= O_NOATIME;
+		flags |= FIO_O_NOATIME;
 
 open_again:
 	if (td_write(td)) {
@@ -337,8 +337,8 @@
 		char buf[FIO_VERROR_SIZE];
 		int __e = errno;
 
-		if (errno == EPERM && (flags & O_NOATIME)) {
-			flags &= ~O_NOATIME;
+		if (errno == EPERM && (flags & FIO_O_NOATIME)) {
+			flags &= ~FIO_O_NOATIME;
 			goto open_again;
 		}
 
diff --git a/fio.c b/fio.c
index 37a425e..c592628 100644
--- a/fio.c
+++ b/fio.c
@@ -65,8 +65,8 @@
 	if (td->runstate == runstate)
 		return;
 
-	dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", td->pid, td->runstate,
-								runstate);
+	dprint(FD_PROCESS, "pid=%d: runstate %d -> %d\n", (int) td->pid,
+						td->runstate, runstate);
 	td->runstate = runstate;
 }
 
@@ -80,7 +80,7 @@
 	for_each_td(td, i) {
 		if (group_id == TERMINATE_ALL || groupid == td->groupid) {
 			dprint(FD_PROCESS, "setting terminate on %s/%d\n",
-							td->o.name, td->pid);
+						td->o.name, (int) td->pid);
 			td->terminate = 1;
 			td->o.start_delay = 0;
 
@@ -823,7 +823,7 @@
 
 	td->pid = getpid();
 
-	dprint(FD_PROCESS, "jobs pid=%d started\n", td->pid);
+	dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
 	INIT_LIST_HEAD(&td->io_u_freelist);
 	INIT_LIST_HEAD(&td->io_u_busylist);
@@ -975,7 +975,7 @@
 
 err:
 	if (td->error)
-		printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error,
+		printf("fio: pid=%d, err=%d/%s\n", (int) td->pid, td->error,
 							td->verror);
 	close_and_free_files(td);
 	close_ioengine(td);
@@ -1063,8 +1063,8 @@
 		ret = waitpid(td->pid, &status, flags);
 		if (ret < 0) {
 			if (errno == ECHILD) {
-				log_err("fio: pid=%d disappeared %d\n", td->pid,
-								td->runstate);
+				log_err("fio: pid=%d disappeared %d\n",
+						(int) td->pid, td->runstate);
 				td_set_runstate(td, TD_REAPED);
 				goto reaped;
 			}
@@ -1075,7 +1075,7 @@
 
 				if (sig != SIGQUIT)
 					log_err("fio: pid=%d, got signal=%d\n",
-								td->pid, sig);
+							(int) td->pid, sig);
 				td_set_runstate(td, TD_REAPED);
 				goto reaped;
 			}
@@ -1161,8 +1161,8 @@
 		if (setup_files(td)) {
 			exit_value++;
 			if (td->error)
-				log_err("fio: pid=%d, err=%d/%s\n", td->pid,
-							td->error, td->verror);
+				log_err("fio: pid=%d, err=%d/%s\n",
+					(int) td->pid, td->error, td->verror);
 			td_set_runstate(td, TD_REAPED);
 			todo--;
 		} else {
diff --git a/fio.h b/fio.h
index 472fe93..b8847a5 100644
--- a/fio.h
+++ b/fio.h
@@ -1006,7 +1006,8 @@
 	struct fio_file *f = io_u->file;
 
 	dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
-					io_u->offset, io_u->buflen, io_u->ddir);
+					(unsigned long long) io_u->offset,
+					io_u->buflen, io_u->ddir);
 	if (fio_debug & (1 << FD_IO)) {
 		if (f)
 			log_info("/%s", f->file_name);
diff --git a/hash.h b/hash.h
index acf17bb..3e7854b 100644
--- a/hash.h
+++ b/hash.h
@@ -13,6 +13,13 @@
  * them can use shifts and additions instead of multiplications for
  * machines where multiplications are slow.
  */
+
+#ifdef __WORDSIZE
+#define BITS_PER_LONG	__WORDSIZE
+#else
+#define BITS_PER_LONG	32
+#endif
+
 #if BITS_PER_LONG == 32
 /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
 #define GOLDEN_RATIO_PRIME 0x9e370001UL
diff --git a/init.c b/init.c
index 56a1d33..00eb592 100644
--- a/init.c
+++ b/init.c
@@ -307,7 +307,7 @@
 	}
 
 	if (o->fill_device && !o->size)
-		o->size = ULONG_LONG_MAX;
+		o->size = -1ULL;
 
 	if (td_rw(td) && td->o.verify != VERIFY_NONE)
 		log_info("fio: mixed read/write workload with verify. May not "
diff --git a/log.c b/log.c
index 8f92e93..191f806 100644
--- a/log.c
+++ b/log.c
@@ -4,6 +4,7 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <libgen.h>
 #include <assert.h>
 #include "list.h"
 #include "fio.h"
diff --git a/memory.c b/memory.c
index 257914b..3bf31d7 100644
--- a/memory.c
+++ b/memory.c
@@ -1,6 +1,9 @@
 /*
  * Memory helpers
  */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <sys/shm.h>
 #include <sys/mman.h>
diff --git a/mutex.c b/mutex.c
index e6fb3f0..414e553 100644
--- a/mutex.c
+++ b/mutex.c
@@ -12,7 +12,7 @@
 void fio_mutex_remove(struct fio_mutex *mutex)
 {
 	close(mutex->mutex_fd);
-	munmap(mutex, sizeof(*mutex));
+	munmap((void *) mutex, sizeof(*mutex));
 }
 
 struct fio_mutex *fio_mutex_init(int value)
@@ -34,8 +34,8 @@
 		goto err;
 	}
 
-	mutex = mmap(NULL, sizeof(struct fio_mutex), PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, 0);
+	mutex = (void *) mmap(NULL, sizeof(struct fio_mutex),
+				PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	if (mutex == MAP_FAILED) {
 		perror("mmap mutex");
 		close(fd);
diff --git a/options.c b/options.c
index b8df1da..5aad005 100644
--- a/options.c
+++ b/options.c
@@ -6,6 +6,9 @@
 #include <getopt.h>
 #include <assert.h>
 #include <libgen.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include "fio.h"
 #include "parse.h"
@@ -1275,7 +1278,7 @@
 
 	o = &options[0];
 	while (o->name) {
-		long_options[i].name = o->name;
+		long_options[i].name = (char *) o->name;
 		long_options[i].val = FIO_GETOPT_JOB;
 		if (o->type == FIO_OPT_STR_SET)
 			long_options[i].has_arg = no_argument;
diff --git a/os/os-linux.h b/os/os-linux.h
index e7c0e47..6f2372b 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -25,6 +25,7 @@
 #define FIO_HAVE_HUGETLB
 #define FIO_HAVE_RAWBIND
 #define FIO_HAVE_BLKTRACE
+#define FIO_HAVE_STRSEP
 
 #define OS_MAP_ANON		(MAP_ANONYMOUS)
 
@@ -227,4 +228,6 @@
 	return 0;
 }
 
+#define FIO_O_NOATIME	O_NOATIME
+
 #endif
diff --git a/os/os.h b/os/os.h
index 42cd63d..b1ed1bb 100644
--- a/os/os.h
+++ b/os/os.h
@@ -24,6 +24,10 @@
 #include <scsi/sg.h>
 #endif
 
+#ifndef FIO_HAVE_STRSEP
+#include "../lib/lib.h"
+#endif
+
 #ifndef FIO_HAVE_FADVISE
 #define fadvise(fd, off, len, advice)	(0)
 
@@ -36,7 +40,7 @@
 
 #ifndef FIO_HAVE_CPU_AFFINITY
 #define fio_setaffinity(td)		(0)
-#define fio_getaffinity(pid, mask)	(0)
+#define fio_getaffinity(pid, mask)	do { } while(0)
 #endif
 
 #ifndef FIO_HAVE_IOPRIO
@@ -60,6 +64,10 @@
 #endif
 #endif
 
+#ifndef FIO_O_NOATIME
+#define FIO_O_NOATIME			0
+#endif
+
 #ifndef FIO_HAVE_RAWBIND
 #define fio_lookup_raw(dev, majdev, mindev)	1
 #endif
@@ -69,6 +77,7 @@
 {
 	return 0;
 }
+struct thread_data;
 static inline int load_blktrace(struct thread_data *td, const char *fname)
 {
 	return 1;
diff --git a/stat.c b/stat.c
index fe6acb8..5fecbd0 100644
--- a/stat.c
+++ b/stat.c
@@ -320,11 +320,11 @@
 	if (!ts->error) {
 		log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n",
 					ts->name, ts->groupid, ts->members,
-					ts->error, ts->pid);
+					ts->error, (int) ts->pid);
 	} else {
 		log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n",
 					ts->name, ts->groupid, ts->members,
-					ts->error, ts->verror, ts->pid);
+					ts->error, ts->verror, (int) ts->pid);
 	}
 
 	if (ts->description)
diff --git a/verify.c b/verify.c
index 0bb348f..d602534 100644
--- a/verify.c
+++ b/verify.c
@@ -112,7 +112,7 @@
  */
 static inline unsigned int __hdr_size(int verify_type)
 {
-	unsigned int len;
+	unsigned int len = len;
 
 	switch (verify_type) {
 	case VERIFY_NONE: