[stgt] [PATCH 09/11] usr/bsd: emulates some Linuxism in BSD

Boaz Harrosh bharrosh at panasas.com
Thu Mar 12 12:03:22 CET 2009


These Headers do not exist on BSD but are used in tgt or osd code:
  usr/bsd/byteswap.h
  usr/bsd/endian.h
  usr/bsd/linux/fs.h
Included  only definitions used by code which are Linux specific.

This file is broken on FreeBSD in regard to ipv6
and needs a fixup:
  usr/bsd/netinet/in.h

Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
---
 usr/bsd/byteswap.h   |   10 ++++++++++
 usr/bsd/endian.h     |   26 ++++++++++++++++++++++++++
 usr/bsd/linux/fs.h   |   43 +++++++++++++++++++++++++++++++++++++++++++
 usr/bsd/netinet/in.h |   11 +++++++++++
 4 files changed, 90 insertions(+), 0 deletions(-)
 create mode 100644 usr/bsd/byteswap.h
 create mode 100644 usr/bsd/endian.h
 create mode 100644 usr/bsd/linux/fs.h
 create mode 100644 usr/bsd/netinet/in.h

diff --git a/usr/bsd/byteswap.h b/usr/bsd/byteswap.h
new file mode 100644
index 0000000..c24ad87
--- /dev/null
+++ b/usr/bsd/byteswap.h
@@ -0,0 +1,10 @@
+#ifndef __TGTBSD_BYTESWAP_H__
+#define __TGTBSD_BYTESWAP_H__
+
+#include <sys/endian.h>
+
+#define bswap_16(x) __bswap16(x)
+#define bswap_32(x) __bswap32(x)
+#define bswap_64(x) __bswap64(x)
+
+#endif /* __TGTBSD_BYTESWAP_H__ */
diff --git a/usr/bsd/endian.h b/usr/bsd/endian.h
new file mode 100644
index 0000000..e5b6437
--- /dev/null
+++ b/usr/bsd/endian.h
@@ -0,0 +1,26 @@
+#ifndef __TGTBSD_ENDIAN_H__
+#define __TGTBSD_ENDIAN_H__
+
+#include <machine/endian.h>
+
+#define __BYTE_ORDER _BYTE_ORDER
+#define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#define __BIG_ENDIAN _BIG_ENDIAN
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+
+#define htonl(x)        __htonl(x)
+#define htons(x)        __htons(x)
+#define ntohl(x)        __ntohl(x)
+#define ntohs(x)        __ntohs(x)
+
+#else /* _BYTE_ORDER == _LITTLE_ENDIAN */
+
+#define htonl(x)
+#define htons(x)
+#define ntohl(x)
+#define ntohs(x)
+
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
+
+#endif /* __TGTBSD_ENDIAN_H__ */
diff --git a/usr/bsd/linux/fs.h b/usr/bsd/linux/fs.h
new file mode 100644
index 0000000..46a8186
--- /dev/null
+++ b/usr/bsd/linux/fs.h
@@ -0,0 +1,43 @@
+#ifndef __TGTBSD__LINUX_FS_H__
+#define __TGTBSD__LINUX_FS_H__
+
+#include <sys/stat.h>
+#include <limits.h>
+
+#define st_atim st_atimespec
+#define st_mtim st_mtimespec
+#define st_ctim st_ctimespec
+#define st_birthtim st_birthtimespec
+
+typedef off_t __off64_t;
+#define off64_t __off64_t
+#define loff_t __off64_t
+
+#define O_LARGEFILE 0
+
+#ifndef SYNC_FILE_RANGE_WAIT_BEFORE
+#define SYNC_FILE_RANGE_WAIT_BEFORE	1
+#define SYNC_FILE_RANGE_WRITE		2
+#define SYNC_FILE_RANGE_WAIT_AFTER	4
+#endif
+
+static inline int sync_file_range(int fd, __off64_t offset, __off64_t nbytes,
+				  int flags)
+{
+	return fsync(fd);
+}
+
+static inline int fdatasync(int fd)
+{
+	return fsync(fd);
+}
+
+#define pwrite64 pwrite
+#define pread64 pread
+
+#define stat64 stat
+#define fstat64 fstat
+
+#define lseek64 lseek
+
+#endif /* ndef __TGTBSD__LINUX_FS_H__ */
diff --git a/usr/bsd/netinet/in.h b/usr/bsd/netinet/in.h
new file mode 100644
index 0000000..c43d350
--- /dev/null
+++ b/usr/bsd/netinet/in.h
@@ -0,0 +1,11 @@
+#ifndef __TGTBSD_NETINET_IN_H__
+#define __TGTBSD_NETINET_IN_H__
+
+/*FIXME: define _KERNEL is needed in BSD for some of the ipv6 stuff in
+ *       usr/iscsi/target.c
+ */
+
+#define _KERNEL
+#include <../include/netinet/in.h>
+
+#endif /* __TGTBSD_NETINET_IN_H__ */
-- 
1.6.0.6

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list