From 77adf4cd648dce41f89469dd185deec6b6b53a0b Mon Sep 17 00:00:00 2001 From: Vikas Gorur Date: Wed, 18 Feb 2009 17:36:07 +0530 Subject: Added all files --- libglusterfs/src/compat.h | 356 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 356 insertions(+) create mode 100644 libglusterfs/src/compat.h (limited to 'libglusterfs/src/compat.h') diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h new file mode 100644 index 000000000..1e8ccaab1 --- /dev/null +++ b/libglusterfs/src/compat.h @@ -0,0 +1,356 @@ +/* + Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ + +#ifndef __COMPAT_H__ +#define __COMPAT_H__ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include +#include "dict.h" + +#ifndef LLONG_MAX +#define LLONG_MAX LONG_LONG_MAX /* compat with old gcc */ +#endif /* LLONG_MAX */ + + +#ifdef GF_LINUX_HOST_OS + +#define UNIX_PATH_MAX 108 + +#include +#include +#include +#include + + +#ifndef HAVE_LLISTXATTR + +/* This part is valid only incase of old glibc which doesn't support + * 'llistxattr()' system calls. + */ + +#define lremovexattr(path,key) removexattr(path,key) +#define llistxattr(path,key,size) listxattr(path,key,size) +#define lgetxattr(path, key, value, size) getxattr(path,key,value,size) +#define lsetxattr(path,key,value,size,flags) setxattr(path,key,value,size,flags) + +#endif /* HAVE_LLISTXATTR */ +#endif /* GF_LINUX_HOST_OS */ + +#ifdef GF_BSD_HOST_OS +/* In case of FreeBSD */ + +#define UNIX_PATH_MAX 104 +#include + +#include +#include +#include +#include + +#include + +enum { + ATTR_CREATE = 1, +#define XATTR_CREATE ATTR_CREATE + ATTR_REPLACE = 2 +#define XATTR_REPLACE ATTR_REPLACE +}; + + +#ifndef sighandler_t +#define sighandler_t sig_t +#endif + +#ifndef ino64_t +#define ino64_t ino_t +#endif + +#ifndef EUCLEAN +#define EUCLEAN 0 +#endif + +#include +#ifndef s6_addr16 +#define s6_addr16 __u6_addr.__u6_addr16 +#endif +#ifndef s6_addr32 +#define s6_addr32 __u6_addr.__u6_addr32 +#endif + +/* Posix dictates NAME_MAX to be used */ +# ifndef NAME_MAX +# ifdef MAXNAMLEN +# define NAME_MAX MAXNAMLEN +# else +# define NAME_MAX 255 +# endif +# endif + +#define lremovexattr(path,key) extattr_delete_link(path, EXTATTR_NAMESPACE_USER, key) +#define llistxattr(path,key,size) extattr_list_link(path, EXTATTR_NAMESPACE_USER, key, size) +#define lgetxattr(path, key, value, size) extattr_get_link(path, EXTATTR_NAMESPACE_USER, key, value, size) +#define lsetxattr(path,key,value,size,flags) extattr_set_link(path, EXTATTR_NAMESPACE_USER, key, value, size) +#define fgetxattr(fd,key,value,size) extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, key, value, size) +#define fsetxattr(fd,key,value,size,flag) extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, key, value, size) + + +#define F_GETLK64 F_GETLK +#define F_SETLK64 F_SETLK +#define F_SETLKW64 F_SETLKW + +#endif /* GF_BSD_HOST_OS */ + +#ifdef GF_DARWIN_HOST_OS + +#define UNIX_PATH_MAX 104 +#include + +#include +#include +#include +#include + +#include + + +#if __DARWIN_64_BIT_INO_T == 0 +# error '64 bit ino_t is must for GlusterFS to work, Compile with "CFLAGS=-D__DARWIN_64_BIT_INO_T"' +#endif /* __DARWIN_64_BIT_INO_T */ + + +#if __DARWIN_64_BIT_INO_T == 0 +# error '64 bit ino_t is must for GlusterFS to work, Compile with "CFLAGS=-D__DARWIN_64_BIT_INO_T"' +#endif /* __DARWIN_64_BIT_INO_T */ + +#ifndef sighandler_t +#define sighandler_t sig_t +#endif + +#ifndef EUCLEAN +#define EUCLEAN 0 +#endif + +#include +#ifndef s6_addr16 +#define s6_addr16 __u6_addr.__u6_addr16 +#endif +#ifndef s6_addr32 +#define s6_addr32 __u6_addr.__u6_addr32 +#endif + +/* Posix dictates NAME_MAX to be used */ +# ifndef NAME_MAX +# ifdef MAXNAMLEN +# define NAME_MAX MAXNAMLEN +# else +# define NAME_MAX 255 +# endif +# endif + +#define llistxattr(path,key,size) listxattr(path,key,size,XATTR_NOFOLLOW) +#define lgetxattr(path,key,value,size) getxattr(path,key,value,size,0,XATTR_NOFOLLOW) +#define lsetxattr(path,key,value,size,flags) setxattr(path,key,value,size,0,flags|XATTR_NOFOLLOW) +#define lremovexattr(path,key) removexattr(path,key,XATTR_NOFOLLOW) +#define fgetxattr(path,key,value,size) fgetxattr(path,key,value,size,0,0) +#define fsetxattr(path,key,value,size,flag) fsetxattr(path,key,value,size,0,flag) + +#define F_GETLK64 F_GETLK +#define F_SETLK64 F_SETLK +#define F_SETLKW64 F_SETLKW + +int32_t gf_darwin_compat_listxattr (int len, dict_t *dict, int size); +int32_t gf_darwin_compat_getxattr (const char *key, dict_t *dict); +int32_t gf_darwin_compat_setxattr (dict_t *dict); + +#endif /* GF_DARWIN_HOST_OS */ + +#ifdef GF_SOLARIS_HOST_OS + +#define UNIX_PATH_MAX 108 +#define EUCLEAN 117 + +#include +#include +#include +#include +#include +#include +#include + +#ifndef lchmod +#define lchmod chmod +#endif + +enum { + ATTR_CREATE = 1, +#define XATTR_CREATE ATTR_CREATE + ATTR_REPLACE = 2 +#define XATTR_REPLACE ATTR_REPLACE +}; + +/* This patch is not present in Solaris 10 and before */ +#ifndef dirfd +#define dirfd(dirp) ((dirp)->dd_fd) +#endif + +/* Posix dictates NAME_MAX to be used */ +# ifndef NAME_MAX +# ifdef MAXNAMLEN +# define NAME_MAX MAXNAMLEN +# else +# define NAME_MAX 255 +# endif +# endif + +#include +#ifndef s6_addr16 +#define S6_ADDR16(x) ((uint16_t*) ((char*)&(x).s6_addr)) +#endif +#ifndef s6_addr32 +#define s6_addr32 _S6_un._S6_u32 +#endif + +#define lremovexattr(path,key) solaris_removexattr(path,key) +#define llistxattr(path,key,size) solaris_listxattr(path,key,size) +#define lgetxattr(path,key,value,size) solaris_getxattr(path,key,value,size) +#define lsetxattr(path,key,value,size,flags) solaris_setxattr(path,key,value,size,flags) +#define fgetxattr(fd,key,value,size) solaris_fgetxattr(fd,key,value,size) +#define fsetxattr(fd,key,value,size,flags) solaris_fsetxattr(fd,key,value,size,flags) +#define lutimes(filename,times) utimes(filename,times) + +int asprintf(char **string_ptr, const char *format, ...); +char* strsep(char** str, const char* delims); +int solaris_listxattr(const char *path, char *list, size_t size); +int solaris_removexattr(const char *path, const char* key); +int solaris_getxattr(const char *path, const char* key, + char *value, size_t size); +int solaris_setxattr(const char *path, const char* key, const char *value, + size_t size, int flags); +int solaris_fgetxattr(int fd, const char* key, + char *value, size_t size); +int solaris_fsetxattr(int fd, const char* key, const char *value, + size_t size, int flags); + +#endif /* GF_SOLARIS_HOST_OS */ + +#ifndef HAVE_ARGP +#include "argp.h" +#else +#include +#endif /* HAVE_ARGP */ + +#ifndef HAVE_STRNLEN +size_t strnlen(const char *string, size_t maxlen); +#endif /* STRNLEN */ + +#ifndef strdupa +#define strdupa(s) \ + (__extension__ \ + ({ \ + __const char *__old = (s); \ + size_t __len = strlen (__old) + 1; \ + char *__new = (char *) __builtin_alloca (__len); \ + (char *) memcpy (__new, __old, __len); \ + })) +#endif + +#define ALIGN(x) (((x) + sizeof (uint64_t) - 1) & ~(sizeof (uint64_t) - 1)) + +#include +#include + +static inline int32_t +dirent_size (struct dirent *entry) +{ +#ifdef GF_BSD_HOST_OS + return ALIGN (24 /* FIX MEEEE!!! */ + entry->d_namlen); +#endif +#ifdef GF_DARWIN_HOST_OS + return ALIGN (24 /* FIX MEEEE!!! */ + entry->d_namlen); +#endif +#ifdef GF_LINUX_HOST_OS + return ALIGN (24 /* FIX MEEEE!!! */ + entry->d_reclen); +#endif +#ifdef GF_SOLARIS_HOST_OS + return ALIGN (24 /* FIX MEEEE!!! */ + entry->d_reclen); +#endif +} + + +static inline int32_t +gf_compat_getxattr (const char *key, dict_t *dict) +{ +#ifdef GF_DARWIN_HOST_OS + return gf_darwin_compat_getxattr (key, dict); +#endif + return -1; +} + + +static inline int32_t +gf_compat_setxattr (dict_t *dict) +{ +#ifdef GF_DARWIN_HOST_OS + return gf_darwin_compat_setxattr (dict); +#endif + return -1; +} + + +static inline int32_t +gf_compat_listxattr (int len, dict_t *dict, int size) +{ +#ifdef GF_DARWIN_HOST_OS + return gf_darwin_compat_listxattr (len, dict, size); +#endif + return len; +} + + +#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC +/* Linux, Solaris, Cygwin */ +#define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atim.tv_nsec) +#define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctim.tv_nsec) +#define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtim.tv_nsec) +#define ST_ATIM_NSEC_SET(stbuf, val) ((stbuf)->st_atim.tv_nsec = (val)) +#define ST_MTIM_NSEC_SET(stbuf, val) ((stbuf)->st_mtim.tv_nsec = (val)) +#define ST_CTIM_NSEC_SET(stbuf, val) ((stbuf)->st_ctim.tv_nsec = (val)) +#elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC) +/* FreeBSD, NetBSD */ +#define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atimespec.tv_nsec) +#define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctimespec.tv_nsec) +#define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtimespec.tv_nsec) +#define ST_ATIM_NSEC_SET(stbuf, val) ((stbuf)->st_atimespec.tv_nsec = (val)) +#define ST_MTIM_NSEC_SET(stbuf, val) ((stbuf)->st_mtimespec.tv_nsec = (val)) +#define ST_CTIM_NSEC_SET(stbuf, val) ((stbuf)->st_ctimespec.tv_nsec = (val)) +#else +#define ST_ATIM_NSEC(stbuf) (0) +#define ST_CTIM_NSEC(stbuf) (0) +#define ST_MTIM_NSEC(stbuf) (0) +#define ST_ATIM_NSEC_SET(stbuf, val) do { } while (0); +#define ST_MTIM_NSEC_SET(stbuf, val) do { } while (0); +#define ST_CTIM_NSEC_SET(stbuf, val) do { } while (0); +#endif + +#endif /* __COMPAT_H__ */ -- cgit