summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/syscall.c
diff options
context:
space:
mode:
authorHarshavardhana <harsha@harshavardhana.net>2014-04-17 15:54:34 -0700
committerAnand Avati <avati@redhat.com>2014-04-24 14:41:48 -0700
commita3cb38e3edf005bef73da4c9cfd958474a14d50f (patch)
treea406029332a9eb096c14d441160bb670a42df8cb /libglusterfs/src/syscall.c
parent9c13471b109587a639662fc690384285bee02bc6 (diff)
build: MacOSX Porting fixes
git@forge.gluster.org:~schafdog/glusterfs-core/osx-glusterfs Working functionality on MacOSX - GlusterD (management daemon) - GlusterCLI (management cli) - GlusterFS FUSE (using OSXFUSE) - GlusterNFS (without NLM - issues with rpc.statd) Change-Id: I20193d3f8904388e47344e523b3787dbeab044ac BUG: 1089172 Signed-off-by: Harshavardhana <harsha@harshavardhana.net> Signed-off-by: Dennis Schafroth <dennis@schafroth.com> Tested-by: Harshavardhana <harsha@harshavardhana.net> Tested-by: Dennis Schafroth <dennis@schafroth.com> Reviewed-on: http://review.gluster.org/7503 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs/src/syscall.c')
-rw-r--r--libglusterfs/src/syscall.c99
1 files changed, 88 insertions, 11 deletions
diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c
index d1b9ef84c96..7236958677d 100644
--- a/libglusterfs/src/syscall.c
+++ b/libglusterfs/src/syscall.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <utime.h>
#include <sys/time.h>
+#include <fcntl.h>
int
sys_lstat (const char *path, struct stat *buf)
@@ -41,12 +42,58 @@ sys_fstat (int fd, struct stat *buf)
}
+int
+sys_fstatat(int dirfd, const char *pathname, struct stat *buf, int flags)
+{
+#ifdef GF_DARWIN_HOST_OS
+ if (fchdir(dirfd) < 0)
+ return -1;
+ if(flags & AT_SYMLINK_NOFOLLOW)
+ return lstat(pathname, buf);
+ else
+ return stat(pathname, buf);
+#else
+ return fstatat (dirfd, pathname, buf, flags);
+#endif
+}
+
+
+int
+sys_openat(int dirfd, const char *pathname, int flags, ...)
+{
+ mode_t mode = 0;
+ if (flags & O_CREAT) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, int);
+ va_end(ap);
+ }
+
+#ifdef GF_DARWIN_HOST_OS
+ if (fchdir(dirfd) < 0)
+ return -1;
+ return open (pathname, flags, mode);
+#else
+ return openat (dirfd, pathname, flags, mode);
+#endif
+}
+
DIR *
sys_opendir (const char *name)
{
return opendir (name);
}
+int sys_mkdirat(int dirfd, const char *pathname, mode_t mode)
+{
+#ifdef GF_DARWIN_HOST_OS
+ if(fchdir(dirfd) < 0)
+ return -1;
+ return mkdir(pathname, mode);
+#else
+ return mkdirat (dirfd, pathname, mode);
+#endif
+}
struct dirent *
sys_readdir (DIR *dir)
@@ -262,13 +309,43 @@ sys_fsync (int fd)
int
sys_fdatasync (int fd)
{
-#ifdef HAVE_FDATASYNC
- return fdatasync (fd);
+#ifdef GF_DARWIN_HOST_OS
+ return fcntl (fd, F_FULLFSYNC);
#else
- return 0;
+ return fdatasync (fd);
#endif
}
+void
+gf_add_prefix(const char *ns, const char *key, char **newkey)
+{
+ /* if we dont have any namespace, append USER NS */
+ if (strncmp(key, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
+ strncmp(key, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
+ strncmp(key, XATTR_SECURITY_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
+ strncmp(key, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) {
+ int ns_length = strlen(ns);
+ *newkey = GF_MALLOC(ns_length + strlen(key) + 10,
+ gf_common_mt_char);
+ strcpy(*newkey, ns);
+ strcat(*newkey, key);
+ } else {
+ *newkey = gf_strdup(key);
+ }
+}
+
+void
+gf_remove_prefix(const char *ns, const char *key, char **newkey)
+{
+ int ns_length = strlen(ns);
+ if (strncmp(key, ns, ns_length) == 0) {
+ *newkey = GF_MALLOC(-ns_length + strlen(key) + 10,
+ gf_common_mt_char);
+ strcpy(*newkey, key + ns_length);
+ } else {
+ *newkey = gf_strdup(key);
+ }
+}
int
sys_lsetxattr (const char *path, const char *name, const void *value,
@@ -289,8 +366,11 @@ sys_lsetxattr (const char *path, const char *name, const void *value,
#endif
#ifdef GF_DARWIN_HOST_OS
+ /* OS X clients will carry other flags, which will be used on a
+ OS X host, but masked out on others. GF assume NOFOLLOW on Linux,
+ enforcing */
return setxattr (path, name, value, size, 0,
- flags|XATTR_NOFOLLOW);
+ (flags & ~XATTR_NOSECURITY) | XATTR_NOFOLLOW);
#endif
}
@@ -313,12 +393,10 @@ sys_llistxattr (const char *path, char *list, size_t size)
#endif
#ifdef GF_DARWIN_HOST_OS
- return listxattr (path, list, size, XATTR_NOFOLLOW);
+ return listxattr (path, list, size, XATTR_NOFOLLOW);
#endif
-
}
-
ssize_t
sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
{
@@ -337,7 +415,7 @@ sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
#endif
#ifdef GF_DARWIN_HOST_OS
- return getxattr (path, name, value, size, 0, XATTR_NOFOLLOW);
+ return getxattr (path, name, value, size, 0, XATTR_NOFOLLOW);
#endif
}
@@ -412,7 +490,7 @@ sys_fsetxattr (int filedes, const char *name, const void *value,
#endif
#ifdef GF_DARWIN_HOST_OS
- return fsetxattr (filedes, name, value, size, 0, flags);
+ return fsetxattr (filedes, name, value, size, 0, flags & ~XATTR_NOSECURITY);
#endif
}
@@ -435,7 +513,7 @@ sys_flistxattr (int filedes, char *list, size_t size)
#endif
#ifdef GF_DARWIN_HOST_OS
- return flistxattr (filedes, list, size, XATTR_NOFOLLOW);
+ return flistxattr (filedes, list, size, XATTR_NOFOLLOW);
#endif
}
@@ -491,4 +569,3 @@ sys_fallocate(int fd, int mode, off_t offset, off_t len)
errno = ENOSYS;
return -1;
}
-