"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/libglusterfs/src/glusterfs/compat.h" (16 Sep 2020, 14199 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "compat.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2   Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
    3   This file is part of GlusterFS.
    4 
    5   This file is licensed to you under your choice of the GNU Lesser
    6   General Public License, version 3 or any later version (LGPLv3 or
    7   later), or the GNU General Public License, version 2 (GPLv2), in all
    8   cases as published by the Free Software Foundation.
    9 */
   10 
   11 #ifndef __COMPAT_H__
   12 #define __COMPAT_H__
   13 
   14 #include <stdint.h>
   15 
   16 #ifndef LLONG_MAX
   17 #define LLONG_MAX __LONG_LONG_MAX__ /* compat with old gcc */
   18 #endif                              /* LLONG_MAX */
   19 
   20 #ifdef GF_LINUX_HOST_OS
   21 
   22 #define UNIX_PATH_MAX 108
   23 
   24 #include <sys/un.h>
   25 #include <linux/limits.h>
   26 #include <sys/xattr.h>
   27 #include <linux/xattr.h>
   28 #include <endian.h>
   29 #ifdef HAVE_LINUX_FALLOC_H
   30 #include <linux/falloc.h>
   31 #endif
   32 
   33 #ifdef HAVE_ENDIAN_H
   34 #include <endian.h>
   35 #endif
   36 
   37 #ifndef _PATH_UMOUNT
   38 #define _PATH_UMOUNT "/bin/umount"
   39 #endif
   40 #define GF_XATTR_NAME_MAX XATTR_NAME_MAX
   41 #endif /* GF_LINUX_HOST_OS */
   42 
   43 /*
   44  * Define the fallocate flags in case we do not have the header. This also
   45  * accounts for older systems that do not define FALLOC_FL_PUNCH_HOLE.
   46  */
   47 
   48 #ifndef FALLOC_FL_KEEP_SIZE
   49 #define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */
   50 #endif
   51 #ifndef FALLOC_FL_PUNCH_HOLE
   52 #define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */
   53 #endif
   54 #ifndef FALLOC_FL_ZERO_RANGE
   55 #define FALLOC_FL_ZERO_RANGE 0x10 /* zeroes out range */
   56 #endif
   57 #ifndef FALLOC_FL_COLLAPSE_RANGE
   58 #define FALLOC_FL_COLLAPSE_RANGE 0x08 /* reduces the size */
   59 #endif
   60 #ifndef FALLOC_FL_INSERT_RANGE
   61 #define FALLOC_FL_INSERT_RANGE 0x20 /* expands the size */
   62 #endif
   63 
   64 #ifndef HAVE_LLISTXATTR
   65 
   66 /* This part is valid only in case of old glibc which doesn't support
   67  * 'llistxattr()' system calls.
   68  */
   69 
   70 #define lremovexattr(path, key) removexattr(path, key)
   71 #define llistxattr(path, key, size) listxattr(path, key, size)
   72 #define lgetxattr(path, key, value, size) getxattr(path, key, value, size)
   73 #define lsetxattr(path, key, value, size, flags)                               \
   74     setxattr(path, key, value, size, flags)
   75 
   76 #endif /* HAVE_LLISTXATTR */
   77 
   78 #ifdef GF_DARWIN_HOST_OS
   79 #include <machine/endian.h>
   80 #include <libkern/OSByteOrder.h>
   81 #include <sys/xattr.h>
   82 
   83 #define htobe16(x) OSSwapHostToBigInt16(x)
   84 #define htole16(x) OSSwapHostToLittleInt16(x)
   85 #define be16toh(x) OSSwapBigToHostInt16(x)
   86 #define le16toh(x) OSSwapLittleToHostInt16(x)
   87 
   88 #define htobe32(x) OSSwapHostToBigInt32(x)
   89 #define htole32(x) OSSwapHostToLittleInt32(x)
   90 #define be32toh(x) OSSwapBigToHostInt32(x)
   91 #define le32toh(x) OSSwapLittleToHostInt32(x)
   92 
   93 #define htobe64(x) OSSwapHostToBigInt64(x)
   94 #define htole64(x) OSSwapHostToLittleInt64(x)
   95 #define be64toh(x) OSSwapBigToHostInt64(x)
   96 #define le64toh(x) OSSwapLittleToHostInt64(x)
   97 
   98 #endif
   99 
  100 #ifdef GF_BSD_HOST_OS
  101 /* In case of FreeBSD and NetBSD */
  102 
  103 #define UNIX_PATH_MAX 104
  104 #include <sys/types.h>
  105 
  106 #include <sys/un.h>
  107 #include <sys/endian.h>
  108 #include <sys/extattr.h>
  109 #ifdef HAVE_SYS_XATTR_H
  110 #include <sys/xattr.h>
  111 #endif /* HAVE_SYS_XATTR_H */
  112 #include <limits.h>
  113 
  114 #include <libgen.h>
  115 /*
  116  * This is where things like off64_t are defined.
  117  * So include it before declaring _OFF64_T_DECLARED.
  118  * If the freebsd version has support for off64_t
  119  * including stdio.h should be sufficient.
  120  */
  121 #include <stdio.h>
  122 
  123 #ifndef _OFF64_T_DECLARED
  124 /*
  125  * Including <stdio.h> (done above) should actually define
  126  * _OFF64_T_DECLARED with off64_t data type being available
  127  * for consumption. But, off64_t data type is not recognizable
  128  * for FreeBSD versions less than 11. Hence, int64_t is typedefed
  129  * to off64_t.
  130  */
  131 #define _OFF64_T_DECLARED
  132 typedef int64_t off64_t;
  133 #endif /* _OFF64_T_DECLARED */
  134 
  135 #ifndef XATTR_CREATE
  136 enum {
  137     ATTR_CREATE = 1,
  138 #define XATTR_CREATE ATTR_CREATE
  139     ATTR_REPLACE = 2
  140 #define XATTR_REPLACE ATTR_REPLACE
  141 };
  142 #endif /* XATTR_CREATE */
  143 
  144 #ifndef sighandler_t
  145 #define sighandler_t sig_t
  146 #endif
  147 
  148 #ifdef __FreeBSD__
  149 #undef ino_t
  150 #define ino_t uint64_t
  151 #include <sys/types.h>
  152 #include <sys/extattr.h>
  153 /* Using NAME_MAX since EXTATTR_MAXNAMELEN is inside a preprocessor conditional
  154  * for the kernel
  155  */
  156 #define GF_XATTR_NAME_MAX NAME_MAX
  157 #endif /* __FreeBSD__ */
  158 
  159 #ifdef __NetBSD__
  160 #define GF_XATTR_NAME_MAX XATTR_NAME_MAX
  161 #endif
  162 
  163 #ifndef ino64_t
  164 #define ino64_t ino_t
  165 #endif
  166 
  167 #ifndef EUCLEAN
  168 #define EUCLEAN 0
  169 #endif
  170 
  171 #include <netinet/in.h>
  172 #ifndef s6_addr16
  173 #define s6_addr16 __u6_addr.__u6_addr16
  174 #endif
  175 #ifndef s6_addr32
  176 #define s6_addr32 __u6_addr.__u6_addr32
  177 #endif
  178 
  179 #ifndef LOGIN_NAME_MAX
  180 #define LOGIN_NAME_MAX 256
  181 #endif
  182 
  183 /* Posix dictates NAME_MAX to be used */
  184 #ifndef NAME_MAX
  185 #ifdef MAXNAMLEN
  186 #define NAME_MAX MAXNAMLEN
  187 #else
  188 #define NAME_MAX 255
  189 #endif
  190 #endif
  191 
  192 #define F_GETLK64 F_GETLK
  193 #define F_SETLK64 F_SETLK
  194 #define F_SETLKW64 F_SETLKW
  195 #define FALLOC_FL_KEEP_SIZE 0x01      /* default is extend size */
  196 #define FALLOC_FL_PUNCH_HOLE 0x02     /* de-allocates range */
  197 #define FALLOC_FL_ZERO_RANGE 0x10     /* zeroes out range */
  198 #define FALLOC_FL_INSERT_RANGE 0x20   /* Expands the size */
  199 #define FALLOC_FL_COLLAPSE_RANGE 0x08 /* Reduces the size */
  200 
  201 #ifndef _PATH_UMOUNT
  202 #define _PATH_UMOUNT "/sbin/umount"
  203 #endif
  204 
  205 void
  206 gf_extattr_list_reshape(char *list, ssize_t size);
  207 
  208 #endif /* GF_BSD_HOST_OS */
  209 
  210 #ifdef GF_DARWIN_HOST_OS
  211 #include <machine/endian.h>
  212 #include <libkern/OSByteOrder.h>
  213 
  214 #define htobe16(x) OSSwapHostToBigInt16(x)
  215 #define htole16(x) OSSwapHostToLittleInt16(x)
  216 #define be16toh(x) OSSwapBigToHostInt16(x)
  217 #define le16toh(x) OSSwapLittleToHostInt16(x)
  218 
  219 #define htobe32(x) OSSwapHostToBigInt32(x)
  220 #define htole32(x) OSSwapHostToLittleInt32(x)
  221 #define be32toh(x) OSSwapBigToHostInt32(x)
  222 #define le32toh(x) OSSwapLittleToHostInt32(x)
  223 
  224 #define htobe64(x) OSSwapHostToBigInt64(x)
  225 #define htole64(x) OSSwapHostToLittleInt64(x)
  226 #define be64toh(x) OSSwapBigToHostInt64(x)
  227 #define le64toh(x) OSSwapLittleToHostInt64(x)
  228 
  229 #define UNIX_PATH_MAX 104
  230 /* OSX Yosemite now has this defined */
  231 #ifndef AT_SYMLINK_NOFOLLOW
  232 #define AT_SYMLINK_NOFOLLOW 0x100
  233 #endif
  234 #include <sys/types.h>
  235 
  236 #include <sys/un.h>
  237 #include <sys/xattr.h>
  238 #include <limits.h>
  239 
  240 #include <libgen.h>
  241 
  242 #if __DARWIN_64_BIT_INO_T == 0
  243 #error '64 bit ino_t is must for GlusterFS to work, Compile with "CFLAGS=-D__DARWIN_64_BIT_INO_T"'
  244 #endif /* __DARWIN_64_BIT_INO_T */
  245 
  246 #if __DARWIN_64_BIT_INO_T == 0
  247 #error '64 bit ino_t is must for GlusterFS to work, Compile with "CFLAGS=-D__DARWIN_64_BIT_INO_T"'
  248 #endif /* __DARWIN_64_BIT_INO_T */
  249 
  250 #ifndef sighandler_t
  251 #define sighandler_t sig_t
  252 #endif
  253 
  254 #ifndef EUCLEAN
  255 #define EUCLEAN 0
  256 #endif
  257 
  258 #include <netinet/in.h>
  259 #ifndef s6_addr16
  260 #define s6_addr16 __u6_addr.__u6_addr16
  261 #endif
  262 #ifndef s6_addr32
  263 #define s6_addr32 __u6_addr.__u6_addr32
  264 #endif
  265 
  266 /* Posix dictates NAME_MAX to be used */
  267 #ifndef NAME_MAX
  268 #ifdef MAXNAMLEN
  269 #define NAME_MAX MAXNAMLEN
  270 #else
  271 #define NAME_MAX 255
  272 #endif
  273 #endif
  274 
  275 #define F_GETLK64 F_GETLK
  276 #define F_SETLK64 F_SETLK
  277 #define F_SETLKW64 F_SETLKW
  278 
  279 #ifndef FTW_CONTINUE
  280 #define FTW_CONTINUE 0
  281 #endif
  282 
  283 #ifndef _PATH_UMOUNT
  284 #define _PATH_UMOUNT "/sbin/umount"
  285 #endif
  286 #endif /* GF_DARWIN_HOST_OS */
  287 
  288 #ifdef GF_SOLARIS_HOST_OS
  289 
  290 #define UNIX_PATH_MAX 108
  291 #define EUCLEAN 117
  292 
  293 #include <sys/un.h>
  294 #include <limits.h>
  295 #include <sys/stat.h>
  296 #include <unistd.h>
  297 #include <sys/fcntl.h>
  298 #include <libgen.h>
  299 #include <sys/mkdev.h>
  300 
  301 #ifndef lchmod
  302 #define lchmod chmod
  303 #endif
  304 
  305 #define lgetxattr(path, key, value, size)                                      \
  306     solaris_getxattr(path, key, value, size)
  307 enum {
  308     ATTR_CREATE = 1,
  309 #define XATTR_CREATE ATTR_CREATE
  310     ATTR_REPLACE = 2
  311 #define XATTR_REPLACE ATTR_REPLACE
  312 };
  313 
  314 /* This patch is not present in Solaris 10 and before */
  315 #ifndef dirfd
  316 #define dirfd(dirp) ((dirp)->dd_fd)
  317 #endif
  318 
  319 /* Posix dictates NAME_MAX to be used */
  320 #ifndef NAME_MAX
  321 #ifdef MAXNAMLEN
  322 #define NAME_MAX MAXNAMLEN
  323 #else
  324 #define NAME_MAX 255
  325 #endif
  326 #endif
  327 
  328 #include <netinet/in.h>
  329 #ifndef s6_addr16
  330 #define S6_ADDR16(x) ((uint16_t *)((char *)&(x).s6_addr))
  331 #endif
  332 #ifndef s6_addr32
  333 #define s6_addr32 _S6_un._S6_u32
  334 #endif
  335 
  336 #define lutimes(filename, times) utimes(filename, times)
  337 
  338 #ifndef SEEK_SET
  339 #define SEEK_SET 0
  340 #endif
  341 
  342 enum {
  343     DT_UNKNOWN = 0,
  344 #define DT_UNKNOWN DT_UNKNOWN
  345     DT_FIFO = 1,
  346 #define DT_FIFO DT_FIFO
  347     DT_CHR = 2,
  348 #define DT_CHR DT_CHR
  349     DT_DIR = 4,
  350 #define DT_DIR DT_DIR
  351     DT_BLK = 6,
  352 #define DT_BLK DT_BLK
  353     DT_REG = 8,
  354 #define DT_REG DT_REG
  355     DT_LNK = 10,
  356 #define DT_LNK DT_LNK
  357     DT_SOCK = 12,
  358 #define DT_SOCK DT_SOCK
  359     DT_WHT = 14
  360 #define DT_WHT DT_WHT
  361 };
  362 
  363 #ifndef _PATH_MOUNTED
  364 #define _PATH_MOUNTED "/etc/mtab"
  365 #endif
  366 #ifndef _PATH_UMOUNT
  367 #define _PATH_UMOUNT "/sbin/umount"
  368 #endif
  369 
  370 #ifndef O_ASYNC
  371 #ifdef FASYNC
  372 #define O_ASYNC FASYNC
  373 #else
  374 #define O_ASYNC 0
  375 #endif
  376 #endif
  377 
  378 #ifndef FTW_CONTINUE
  379 #define FTW_CONTINUE 0
  380 #endif
  381 
  382 int
  383 asprintf(char **string_ptr, const char *format, ...);
  384 
  385 int
  386 vasprintf(char **result, const char *format, va_list args);
  387 char *
  388 strsep(char **str, const char *delims);
  389 int
  390 solaris_listxattr(const char *path, char *list, size_t size);
  391 int
  392 solaris_removexattr(const char *path, const char *key);
  393 int
  394 solaris_getxattr(const char *path, const char *key, char *value, size_t size);
  395 int
  396 solaris_setxattr(const char *path, const char *key, const char *value,
  397                  size_t size, int flags);
  398 int
  399 solaris_fgetxattr(int fd, const char *key, char *value, size_t size);
  400 int
  401 solaris_fsetxattr(int fd, const char *key, const char *value, size_t size,
  402                   int flags);
  403 int
  404 solaris_flistxattr(int fd, char *list, size_t size);
  405 
  406 int
  407 solaris_rename(const char *oldpath, const char *newpath);
  408 
  409 int
  410 solaris_unlink(const char *pathname);
  411 
  412 char *
  413 mkdtemp(char *temp);
  414 
  415 #define GF_SOLARIS_XATTR_DIR ".glusterfs_xattr_inode"
  416 
  417 int
  418 solaris_xattr_resolve_path(const char *real_path, char **path);
  419 
  420 #endif /* GF_SOLARIS_HOST_OS */
  421 
  422 #ifndef HAVE_ARGP
  423 #include "argp.h"
  424 #else
  425 #include <argp.h>
  426 #endif /* HAVE_ARGP */
  427 
  428 #ifndef HAVE_STRNLEN
  429 size_t
  430 strnlen(const char *string, size_t maxlen);
  431 #endif /* STRNLEN */
  432 
  433 #ifndef strdupa
  434 #define strdupa(s)                                                             \
  435     (__extension__({                                                           \
  436         __const char *__old = (s);                                             \
  437         size_t __len = strlen(__old) + 1;                                      \
  438         char *__new = (char *)__builtin_alloca(__len);                         \
  439         (char *)memcpy(__new, __old, __len);                                   \
  440     }))
  441 #endif
  442 
  443 #define GF_DIR_ALIGN(x) (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1))
  444 
  445 #include <sys/types.h>
  446 #include <dirent.h>
  447 
  448 static inline int32_t
  449 dirent_size(struct dirent *entry)
  450 {
  451     int32_t size = -1;
  452 
  453 #ifdef GF_BSD_HOST_OS
  454     size = GF_DIR_ALIGN(24 /* FIX MEEEE!!! */ + entry->d_namlen);
  455 #endif
  456 #ifdef GF_DARWIN_HOST_OS
  457     size = GF_DIR_ALIGN(24 /* FIX MEEEE!!! */ + entry->d_namlen);
  458 #endif
  459 #ifdef GF_LINUX_HOST_OS
  460     size = GF_DIR_ALIGN(24 /* FIX MEEEE!!! */ + entry->d_reclen);
  461 #endif
  462 #ifdef GF_SOLARIS_HOST_OS
  463     size = GF_DIR_ALIGN(24 /* FIX MEEEE!!! */ + entry->d_reclen);
  464 #endif
  465     return size;
  466 }
  467 
  468 #ifdef THREAD_UNSAFE_BASENAME
  469 char *
  470 basename_r(const char *);
  471 #define basename(path) basename_r(path)
  472 #endif /* THREAD_UNSAFE_BASENAME */
  473 
  474 #ifdef THREAD_UNSAFE_DIRNAME
  475 char *
  476 dirname_r(char *path);
  477 #define dirname(path) dirname_r(path)
  478 #endif /* THREAD_UNSAFE_DIRNAME */
  479 
  480 #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
  481 /* Linux, Solaris, Cygwin */
  482 #define ST_ATIM_SEC(stbuf) ((stbuf)->st_atim.tv_sec)
  483 #define ST_CTIM_SEC(stbuf) ((stbuf)->st_ctim.tv_sec)
  484 #define ST_MTIM_SEC(stbuf) ((stbuf)->st_mtim.tv_sec)
  485 #define ST_ATIM_SEC_SET(stbuf, val) ((stbuf)->st_atim.tv_sec = (val))
  486 #define ST_MTIM_SEC_SET(stbuf, val) ((stbuf)->st_mtim.tv_sec = (val))
  487 #define ST_CTIM_SEC_SET(stbuf, val) ((stbuf)->st_ctim.tv_sec = (val))
  488 #define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atim.tv_nsec)
  489 #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctim.tv_nsec)
  490 #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtim.tv_nsec)
  491 #define ST_ATIM_NSEC_SET(stbuf, val) ((stbuf)->st_atim.tv_nsec = (val))
  492 #define ST_MTIM_NSEC_SET(stbuf, val) ((stbuf)->st_mtim.tv_nsec = (val))
  493 #define ST_CTIM_NSEC_SET(stbuf, val) ((stbuf)->st_ctim.tv_nsec = (val))
  494 #elif defined(HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
  495 /* FreeBSD, NetBSD */
  496 #define ST_ATIM_SEC(stbuf) ((stbuf)->st_atimespec.tv_sec)
  497 #define ST_CTIM_SEC(stbuf) ((stbuf)->st_ctimespec.tv_sec)
  498 #define ST_MTIM_SEC(stbuf) ((stbuf)->st_mtimespec.tv_sec)
  499 #define ST_ATIM_SEC_SET(stbuf, val) ((stbuf)->st_atimespec.tv_sec = (val))
  500 #define ST_MTIM_SEC_SET(stbuf, val) ((stbuf)->st_mtimespec.tv_sec = (val))
  501 #define ST_CTIM_SEC_SET(stbuf, val) ((stbuf)->st_ctimespec.tv_sec = (val))
  502 #define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atimespec.tv_nsec)
  503 #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctimespec.tv_nsec)
  504 #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtimespec.tv_nsec)
  505 #define ST_ATIM_NSEC_SET(stbuf, val) ((stbuf)->st_atimespec.tv_nsec = (val))
  506 #define ST_MTIM_NSEC_SET(stbuf, val) ((stbuf)->st_mtimespec.tv_nsec = (val))
  507 #define ST_CTIM_NSEC_SET(stbuf, val) ((stbuf)->st_ctimespec.tv_nsec = (val))
  508 #else
  509 #define ST_ATIM_NSEC(stbuf) (0)
  510 #define ST_CTIM_NSEC(stbuf) (0)
  511 #define ST_MTIM_NSEC(stbuf) (0)
  512 #define ST_ATIM_NSEC_SET(stbuf, val)                                           \
  513     do {                                                                       \
  514     } while (0);
  515 #define ST_MTIM_NSEC_SET(stbuf, val)                                           \
  516     do {                                                                       \
  517     } while (0);
  518 #define ST_CTIM_NSEC_SET(stbuf, val)                                           \
  519     do {                                                                       \
  520     } while (0);
  521 #endif
  522 
  523 #ifdef GF_BSD_HOST_OS
  524 #define CLOCK_REALTIME_COARSE CLOCK_REALTIME
  525 #endif
  526 
  527 #if defined(__GNUC__) && !defined(RELAX_POISONING)
  528 /* Use run API, see run.h */
  529 #include <stdlib.h> /* system(), mkostemp() */
  530 #include <stdio.h>  /* popen() */
  531 #ifdef GF_LINUX_HOST_OS
  532 #include <sys/sysmacros.h>
  533 #endif
  534 #pragma GCC poison system mkostemp popen
  535 #endif
  536 
  537 int
  538 gf_umount_lazy(char *xlname, char *path, int rmdir);
  539 
  540 #ifndef GF_XATTR_NAME_MAX
  541 #error 'Please define GF_XATTR_NAME_MAX for your OS distribution.'
  542 #endif
  543 
  544 #endif /* __COMPAT_H__ */