[stgt] [PATCH 13/14] tgt: bsd_include/ headers, emulates some Linuxism in BSD

Boaz Harrosh bharrosh at panasas.com
Mon Feb 23 19:06:58 CET 2009


These Headers do not exist on BSD but are used in tgt osd code:
  bsd_include/byteswap.h
  bsd_include/endian.h
  bsd_include/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:
  bsd_include/netinet/in.h

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

diff --git a/bsd_include/byteswap.h b/bsd_include/byteswap.h
new file mode 100644
index 0000000..9cc2723
--- /dev/null
+++ b/bsd_include/byteswap.h
@@ -0,0 +1,10 @@
+#ifndef _BSD_BYTESWAP_H
+#define _BSD_BYTESWAP_H	1
+
+#include <sys/endian.h>
+
+#define bswap_16(x) __bswap16(x)
+#define bswap_32(x) __bswap32(x)
+#define bswap_64(x) __bswap64(x)
+
+#endif /* _BSD_BYTESWAP_H */
diff --git a/bsd_include/endian.h b/bsd_include/endian.h
new file mode 100644
index 0000000..9ccc631
--- /dev/null
+++ b/bsd_include/endian.h
@@ -0,0 +1,26 @@
+#ifndef __BSD_ENDIAN_H__
+#define __BSD_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 /* __BSD_ENDIAN_H__ */
diff --git a/bsd_include/linux/fs.h b/bsd_include/linux/fs.h
new file mode 100644
index 0000000..42d5449
--- /dev/null
+++ b/bsd_include/linux/fs.h
@@ -0,0 +1,40 @@
+#ifndef __FOR_BSD__LINUX_FS_H__
+#define __FOR_BSD__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 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
+
+#endif /* ndef __FOR_BSD__LINUX_FS_H__ */
diff --git a/bsd_include/netinet/in.h b/bsd_include/netinet/in.h
new file mode 100644
index 0000000..5bcb0ab
--- /dev/null
+++ b/bsd_include/netinet/in.h
@@ -0,0 +1,11 @@
+#ifndef _BSD_IN_H
+#define _BSD_IN_H	1
+
+/*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 /* _BSD_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